cgmienr: add a webui, update to 2.10.5

This commit is contained in:
Xiangfu 2013-03-02 17:24:35 +08:00
parent b731d34ce1
commit 8b7a89168c
12 changed files with 4634 additions and 11 deletions

View File

@ -9,7 +9,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=cgminer
PKG_VERSION:=2.10.4
PKG_VERSION:=2.10.5
PKG_RELEASE:=1
PKG_INSTALL:=1

4201
cgminer/config Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,18 @@
#!/bin/sh
# This file is for cron job
if ! pidof cgminer; then
/etc/init.d/cgminer start
C=`pidof cgminer | wc -w`
if [ "$C" != "1" ]; then
/etc/init.d/cgminer stop
/etc/init.d/cgminer start
exit 0;
fi
A=`cat /tmp/cm.log`
B=`cgminer-api | grep "^ \[Accepted\]"`
cgminer-api | grep "^ \[Accepted\]" > /tmp/cm.log
if [ "$A" == "$B" ]; then
/etc/init.d/cgminer stop
/etc/init.d/cgminer start
exit 0;
fi

View File

@ -0,0 +1,12 @@
package 'cgminer'
config 'cgminer' 'default'
option 'pool1url' 'http://us.ozco.in:8331'
option 'pool1user' 'xiangfu.0'
option 'pool1pw' 'x'
option 'pool2url' 'http://pool.ABCPool.co:8332'
option 'pool2user' 'xiangfu.0'
option 'pool2pw' 'x'
option 'pool3url' 'http://pit.deepbit.net:8332'
option 'pool3user' 'xiangfu.z@gmail.com_0:x'
option 'pool3pw' 'x'

View File

@ -1,19 +1,52 @@
#!/bin/sh /etc/rc.common
START=99
POOL1="-o http://us.ozco.in:8331 -O xiangfu.0:x"
POOL2="-o http://pool.ABCPool.co:8332 -O xiangfu.0:x"
POOL3="-o http://pit.deepbit.net:8332 -O xiangfu.z@gmail.com_0:x"
POOLS="$POOL1 $POOL2 $POOL3"
APP=cgminer
PID_FILE=/var/run/$APP.pid
start() {
local _pool1url
local _pool1user
local _pool1pw
local _pool2url
local _pool2user
local _pool2pw
local _pool3url
local _pool3user
local _pool3pw
config_load cgminer
config_get _pool1url default pool1url
config_get _pool1user default pool1user
config_get _pool1pw default pool1pw
config_get _pool2url default pool2url
config_get _pool2user default pool2user
config_get _pool2pw default pool2pw
config_get _pool3url default pool3url
config_get _pool3user default pool3user
config_get _pool3pw default pool3pw
if [ "$_pool1url" != "" -a "$_pool1user" != "" -a "$_pool1pw" != "" ]; then
POOL1="-o $_pool1url -O $_pool1user:$_pool1pw"
fi
if [ "$_pool2url" != "" -a "$_pool2user" != "" -a "$_pool2pw" != "" ]; then
POOL2="-o $_pool2url -O $_pool2user:$_pool2pw"
fi
if [ "$_pool3url" != "" -a "$_pool3user" != "" -a "$_pool3pw" != "" ]; then
POOL3="-o $_pool3url -O $_pool3user:$_pool3pw"
fi
DEVS=`find /dev/ -type c -name "ttyUSB*" | sed 's/^/-S/' | sed ':a;N;$!ba;s/\n/ /g'`
PARAMS=" $DEVS $POOL1 $POOL2 $POOL3 -q --api-allow "W:0/0" --api-listen "
ntpd -d -n -q -N -p 0.openwrt.pool.ntp.org \
-p 1.openwrt.pool.ntp.org -p 2.openwrt.pool.ntp.org -p 3.openwrt.pool.ntp.org && \
cgminer -q --api-allow "W:0/0" --api-listen $POOLS $DEVS &
start-stop-daemon -S -x $APP -p $PID_FILE -m -b -- $PARAMS
}
stop() {
killall -s 9 cgminer
start-stop-daemon -K -n $APP -p $PID_FILE -s TERM
}

View File

@ -0,0 +1,69 @@
diff --git a/api-example.c b/api-example.c
index 13b8f2d..dd40545 100755
--- a/api-example.c
+++ b/api-example.c
@@ -145,6 +145,7 @@
static const char SEPARATOR = '|';
static const char COMMA = ',';
static const char EQ = '=';
+static int ONLY = 0;
void display(char *buf)
{
@@ -242,9 +243,13 @@ int callapi(char *command, char *host, short int port)
buf[p] = '\0';
}
- printf("Reply was '%s'\n", buf);
+ if (!ONLY)
+ printf("Reply was '%s'\n", buf);
+ else
+ printf("%s\n", buf);
- display(buf);
+ if (!ONLY)
+ display(buf);
}
CLOSESOCKET(sock);
@@ -274,6 +279,7 @@ int main(int argc, char *argv[])
char *host = "127.0.0.1";
short int port = 4028;
char *ptr;
+ int i = 1;
if (argc > 1)
if (strcmp(argv[1], "-?") == 0
@@ -283,20 +289,26 @@ int main(int argc, char *argv[])
return 1;
}
- if (argc > 1) {
- ptr = trim(argv[1]);
+ if (argc > 1)
+ if (strcmp(argv[1], "-o") == 0) {
+ ONLY = 1;
+ i = 2;
+ }
+
+ if (argc > i) {
+ ptr = trim(argv[i++]);
if (strlen(ptr) > 0)
command = ptr;
}
- if (argc > 2) {
- ptr = trim(argv[2]);
+ if (argc > i) {
+ ptr = trim(argv[i++]);
if (strlen(ptr) > 0)
host = ptr;
}
- if (argc > 3) {
- ptr = trim(argv[3]);
+ if (argc > i) {
+ ptr = trim(argv[i]);
if (strlen(ptr) > 0)
port = atoi(ptr);
}

View File

@ -0,0 +1,27 @@
kernel.panic=3
net.ipv4.conf.default.arp_ignore=1
net.ipv4.conf.all.arp_ignore=1
net.ipv4.ip_forward=1
net.ipv4.icmp_echo_ignore_broadcasts=1
net.ipv4.icmp_ignore_bogus_error_responses=1
net.ipv4.tcp_ecn=0
net.ipv4.tcp_fin_timeout=30
net.ipv4.tcp_keepalive_time=120
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_timestamps=1
net.ipv4.tcp_sack=1
net.ipv4.tcp_dsack=1
net.netfilter.nf_conntrack_acct=1
net.netfilter.nf_conntrack_checksum=0
net.netfilter.nf_conntrack_max=16384
net.netfilter.nf_conntrack_tcp_timeout_established=3600
net.netfilter.nf_conntrack_udp_timeout=60
net.netfilter.nf_conntrack_udp_timeout_stream=180
# disable bridge firewalling by default
net.bridge.bridge-nf-call-arptables=0
net.bridge.bridge-nf-call-ip6tables=0
net.bridge.bridge-nf-call-iptables=0
vm.overcommit_memory=1

View File

@ -0,0 +1,143 @@
--[[
LuCI - Lua Configuration Interface
Copyright 2013 Xiangfu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
$Id$
]]--
module("luci.controller.cgminer", package.seeall)
function index()
entry({"admin", "status", "cgminer"}, cbi("cgminer/cgminer"), _("Cgminer Configuration"))
entry({"admin", "status", "cgminerstatus"}, cbi("cgminer/cgminerstatus"), _("Cgminer Status"))
entry({"admin", "status", "cgminerapi"}, call("action_cgminerapi"), _("Cgminer API Log"))
end
function action_cgminerapi()
local pp = io.popen("/usr/bin/cgminer-api summary; /usr/bin/cgminer-api devs; /usr/bin/cgminer-api pools; /usr/bin/cgminer-api stats")
local data = pp:read("*a")
pp:close()
luci.template.render("cgminerapi", {api=data})
end
function summary()
local data = {}
local summary = luci.util.execi("/usr/bin/cgminer-api -o summary | sed \"s/|/\\n/g\" ")
if not summary then
return
end
for line in summary do
local elapsed, mhsav, foundblocks, getworks, accepted, rejected, hw, utility, discarded, stale, getfailures, localwork, remotefailures, networkblocks, totalmh, wu, diffaccepted, diffrejected, diffstale, bestshare = line:match("Elapsed=(%d+),MHS av=([%d%.]+),Found Blocks=(%d+),Getworks=(%d+),Accepted=(%d+),Rejected=(%d+),Hardware Errors=(%d+),Utility=([%d%.]+),Discarded=(%d+),Stale=(%d+),Get Failures=(%d+),Local Work=(%d+),Remote Failures=(%d+),Network Blocks=(%d+),Total MH=([%d%.]+),Work Utility=([%d%.]+),Difficulty Accepted=([%d]+)%.%d+,Difficulty Rejected=([%d]+)%.%d+,Difficulty Stale=([%d]+)%.%d+,Best Share=(%d+)")
if elapsed then
local str
local days
local h
local m
local s = elapsed % 60;
elapsed = elapsed - s
elapsed = elapsed / 60
if elapsed == 0 then
str = string.format("%ds", s)
else
m = elapsed % 60;
elapsed = elapsed - m
elapsed = elapsed / 60
if elapsed == 0 then
str = string.format("%dm %ds", m, s);
else
h = elapsed % 24;
elapsed = elapsed - h
elapsed = elapsed / 24
if elapsed == 0 then
str = string.format("%dh %dm %ds", h, m, s)
else
str = string.format("%dd %dh %dm %ds", elapsed, h, m, s);
end
end
end
data[#data+1] = {
['elapsed'] = str,
['mhsav'] = mhsav,
['foundblocks'] = foundblocks,
['getworks'] = getworks,
['accepted'] = accepted,
['rejected'] = rejected,
['hw'] = hw,
['utility'] = utility,
['discarded'] = discarded,
['stale'] = stale,
['getfailures'] = getfailures,
['localwork'] = localwork,
['remotefailures'] = remotefailures,
['networkblocks'] = networkblocks,
['totalmh'] = string.format("%e",totalmh),
['wu'] = wu,
['diffaccepted'] = diffaccepted,
['diffrejected'] = diffrejected,
['diffstale'] = diffstale,
['bestshare'] = bestshare
}
end
end
return data
end
function pools()
local data = {}
local pools = luci.util.execi("/usr/bin/cgminer-api -o pools | sed \"s/|/\\n/g\" ")
if not pools then
return
end
for line in pools do
local pi, url, st, pri, lp, gw, a, r, dc, sta, gf, rf, user, lst, ds, da, dr, dsta, lsd, hs, sa, su, hg = line:match(
"POOL=(%d+),URL=(.*),Status=(%a+),Priority=(%d+),Long Poll=(%a+),Getworks=(%d+),Accepted=(%d+),Rejected=(%d+),Discarded=(%d+),Stale=(%d+),Get Failures=(%d+),Remote Failures=(%d+),User=(.*),Last Share Time=(%d+),Diff1 Shares=(%d+),Proxy Type=.*,Proxy=.*,Difficulty Accepted=(%d+)[%.%d]+,Difficulty Rejected=(%d+)[%.%d]+,Difficulty Stale=(%d+)[%.%d]+,Last Share Difficulty=(%d+)[%.%d]+,Has Stratum=(%a+),Stratum Active=(%a+),Stratum URL=.*,Has GBT=(%a+)")
if pi then
if lst == "0" then
lst_date = "Never"
else
lst_date = os.date("%c", lst)
end
data[#data+1] = {
['pool'] = pi,
['url'] = url,
['status'] = st,
['priority'] = pri,
['longpoll'] = lp,
['getworks'] = gw,
['accepted'] = a,
['rejected'] = r,
['discarded'] = dc,
['stale'] = sta,
['getfailures'] = gf,
['remotefailures'] = rf,
['user'] = user,
['lastsharetime'] = lst_date,
['diff1shares'] = ds,
['diffaccepted'] = da,
['diffrejected'] = dr,
['diffstale'] = dsta,
['lastsharedifficulty'] = lsd,
['hasstratum'] = hs,
['stratumactive'] = sa,
['stratumurl'] = su,
['hasgbt'] = hg
}
end
end
return data
end

View File

@ -0,0 +1,19 @@
m = Map("cgminer", "Configuration", "")
conf = m:section(TypedSection, "cgminer", "")
conf.anonymous = true
conf.addremove = false
conf:tab("default", translate("General Settings"))
pool1url = conf:taboption("default", Value, "pool1url", translate("Pool 1"))
pool1user = conf:taboption("default", Value, "pool1user", translate("Pool1 worker"))
pool1pw = conf:taboption("default", Value, "pool1pw", translate("Pool1 password"))
pool2url = conf:taboption("default", Value, "pool2url", translate("Pool 2"))
pool2user = conf:taboption("default", Value, "pool2user", translate("Pool2 worker"))
pool2pw = conf:taboption("default", Value, "pool2pw", translate("Pool2 password"))
pool3url = conf:taboption("default", Value, "pool3url", translate("Pool 3"))
pool3user = conf:taboption("default", Value, "pool3user", translate("Pool3 worker"))
pool3pw = conf:taboption("default", Value, "pool3pw", translate("Pool3 password"))
return m

View File

@ -0,0 +1,67 @@
--[[
LuCI - Lua Configuration Interface
Copyright 2013 Xiangfu
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
$Id$
]]--
f = SimpleForm("cgminerstatus", translate("Cgminer Status"), translate("This list gives an overview over currently running cgminer."))
f.reset = false
f.submit = false
t = f:section(Table, luci.controller.cgminer.summary(), translate("Summary"))
t:option(DummyValue, "elapsed", translate("Elapsed"))
t:option(DummyValue, "mhsav", translate("MHSav"))
t:option(DummyValue, "foundblocks", translate("FoundBlocks"))
t:option(DummyValue, "getworks", translate("Getworks"))
t:option(DummyValue, "accepted", translate("Accepted"))
t:option(DummyValue, "rejected", translate("Rejected"))
t:option(DummyValue, "hw", translate("HW"))
t:option(DummyValue, "utility", translate("Utility"))
t:option(DummyValue, "discarded", translate("Discarded"))
t:option(DummyValue, "stale", translate("Stale"))
t:option(DummyValue, "getfailures", translate("GetFailures"))
t:option(DummyValue, "localwork", translate("LocalWork"))
t:option(DummyValue, "remotefailures", translate("RemoteFailures"))
t:option(DummyValue, "networkblocks", translate("NetworkBlocks"))
t:option(DummyValue, "totalmh", translate("TotalMH"))
t:option(DummyValue, "wu", translate("WU"))
t:option(DummyValue, "diffaccepted", translate("DiffA"))
t:option(DummyValue, "diffrejected", translate("DiffR"))
t:option(DummyValue, "diffstale", translate("DiffS"))
t:option(DummyValue, "bestshare", translate("BestShare"))
t2 = f:section(Table, luci.controller.cgminer.pools(), translate("Pools"))
t2:option(DummyValue, "pool", translate("Pool"))
t2:option(DummyValue, "url", translate("URL"))
t2:option(DummyValue, "status", translate("Status"))
t2:option(DummyValue, "priority", translate("Priority"))
t2:option(DummyValue, "longpoll", translate("LP"))
t2:option(DummyValue, "getworks", translate("GetWorks"))
t2:option(DummyValue, "accepted", translate("Accepted"))
t2:option(DummyValue, "rejected", translate("Rejected"))
t2:option(DummyValue, "discarded", translate("Discarded"))
t2:option(DummyValue, "stale", translate("Stale"))
t2:option(DummyValue, "getfailures", translate("GF"))
t2:option(DummyValue, "remotefailures", translate("RF"))
t2:option(DummyValue, "user", translate("User"))
t2:option(DummyValue, "lastsharetime", translate("LastShareTime"))
t2:option(DummyValue, "diff1shares", translate("Diff1Shares"))
t2:option(DummyValue, "diffaccepted", translate("DiffA"))
t2:option(DummyValue, "diffrejected", translate("DiffR"))
t2:option(DummyValue, "diffstale", translate("DiffS"))
t2:option(DummyValue, "lastsharedifficulty", translate("LSD"))
t2:option(DummyValue, "hasstratum", translate("HasStratum"))
t2:option(DummyValue, "stratumactive", translate("StratumActive"))
t2:option(DummyValue, "stratumurl", translate("StratumURL"))
t2:option(DummyValue, "hasgbt", translate("GBT"))
return f

View File

@ -0,0 +1,20 @@
<%#
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
$Id: syslog.htm 3622 2008-10-23 16:05:55Z jow $
-%>
<%+header%>
<h2><a id="content" name="content"><%:Cgminer API Log%></a></h2>
<div id="content_api">
<textarea readonly="readonly" wrap="off" rows="<%=api:cmatch("\n")+2%>" id="syslog"><%=api:pcdata()%></textarea>
</div>
<%+footer%>

View File

@ -0,0 +1,20 @@
<%#
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
$Id: syslog.htm 3622 2008-10-23 16:05:55Z jow $
-%>
<%+header%>
<h2><a id="content" name="content"><%:Cgminer Status%></a></h2>
<div id="content_syslog">
<textarea readonly="readonly" wrap="off" rows="<%=cstatus:cmatch("\n")+2%>" id="syslog"><%=cstatus:pcdata()%></textarea>
</div>
<%+footer%>