1
0
mirror of git://projects.qi-hardware.com/openwrt-packages.git synced 2025-04-21 12:27:27 +03:00

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

@@ -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%>