From ec1dc12332841ace164f312b5eb01db2557c7c8c Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 21 Aug 2014 13:50:03 +1000 Subject: [PATCH 1/9] ckdb - update username pattern and docs --- src/ckdb.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/ckdb.c b/src/ckdb.c index 3c183a21..94bced6b 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -253,6 +253,7 @@ static POOLSTATUS pool; // TAB #define FLDSEP 0x09 +#define FLDSEPSTR "\011" // Ensure long long and int64_t are both 8 bytes (and thus also the same) #define ASSERT1(condition) __maybe_unused static char sizeof_longlong_must_be_8[(condition)?1:-1] @@ -652,7 +653,7 @@ static cklock_t fpm_lock; static char *first_pool_message; static sem_t socketer_sem; -static const char *userpatt = "^[^/\\._ ]*$"; // disallow: '/' '.' '_' +static const char *userpatt = "^[^/\\._"FLDSEPSTR"]*$"; // disallow: '/' '.' '_' and FLDSEP static const char *mailpatt = "^[A-Za-z0-9_-][A-Za-z0-9_\\.-]*@[A-Za-z0-9][A-Za-z0-9\\.-]*[A-Za-z0-9]$"; static const char *idpatt = "^[_A-Za-z][_A-Za-z0-9]*$"; static const char *intpatt = "^[0-9][0-9]*$"; @@ -7583,14 +7584,14 @@ static char *cmd_stats(__maybe_unused PGconn *conn, char *cmd, char *id, /* The socket command format is as follows: * Basic structure: - * cmd.id.fld1=value1 FLD_SEP fld2=value2 FLD_SEP fld3=... + * cmd.id.fld1=value1 FLDSEP fld2=value2 FLDSEP fld3=... * cmd is the cmd_str from the table below * id is a string of anything but '.' - preferably just digits and/or letters - * FLD_SEP is a single character macro - defined in the code near the top - * no spaces around FLD_SEP - they are added above for readability - * i.e. it's really: cmd.id.fld1=value1FLD_SEPfld2... - * fldN names cannot contain '=' or FLD_SEP - * valueN values cannot contain FLD_SEP except for the json field (see below) + * FLDSEP is a single character macro - defined in the code near the top + * no spaces around FLDSEP - they are added above for readability + * i.e. it's really: cmd.id.fld1=value1FLDSEPfld2... + * fldN names cannot contain '=' or FLDSEP + * valueN values cannot contain FLDSEP except for the json field (see below) * * The reply will be id.timestamp.status.information... * Status 'ok' means it succeeded From fbdfb06074d88e610f99e63fa5c4ecb4cdf33b0c Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 21 Aug 2014 14:50:27 +1000 Subject: [PATCH 2/9] php - add a blank payout help page --- pool/page_payout.php | 13 +++++++++++++ pool/prime.php | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 pool/page_payout.php diff --git a/pool/page_payout.php b/pool/page_payout.php new file mode 100644 index 00000000..ae40f73e --- /dev/null +++ b/pool/page_payout.php @@ -0,0 +1,13 @@ +PayoutsDescription'; +} +# +function show_payout($menu, $name, $user) +{ + gopage(NULL, 'dopayout', $menu, $name, $user); +} +# +?> diff --git a/pool/prime.php b/pool/prime.php index 7066cc99..a6df124d 100644 --- a/pool/prime.php +++ b/pool/prime.php @@ -19,7 +19,8 @@ function process($p, $user) ), 'gap' => NULL, 'Help' => array( - 'Help' => 'help' + 'Help' => 'help', + 'Payout' => 'payout' ) ); $page = ''; From b883f0297786aa71cd91d49922423e8bcc34317d Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 21 Aug 2014 14:52:58 +1000 Subject: [PATCH 3/9] php - add an 's' --- pool/prime.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pool/prime.php b/pool/prime.php index a6df124d..e06205a4 100644 --- a/pool/prime.php +++ b/pool/prime.php @@ -20,7 +20,7 @@ function process($p, $user) 'gap' => NULL, 'Help' => array( 'Help' => 'help', - 'Payout' => 'payout' + 'Payouts' => 'payout' ) ); $page = ''; From dea3640846746f8ea1cbb95364482b0821a7f84b Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 21 Aug 2014 15:53:34 +1000 Subject: [PATCH 4/9] php - add restricted ckdb stats --- pool/page.php | 2 ++ pool/page_ckp.php | 71 +++++++++++++++++++++++++++++++++++++++++++++++ pool/prime.php | 2 ++ 3 files changed, 75 insertions(+) create mode 100644 pool/page_ckp.php diff --git a/pool/page.php b/pool/page.php index 1ac1a8bb..a8750b86 100644 --- a/pool/page.php +++ b/pool/page.php @@ -91,6 +91,8 @@ span.topwho {color:black; font-weight: bold; margin-right: 8px;} span.topdat {margin-left: 8px; margin-right: 24px; color:green; font-weight: bold;} span.login {float: right; margin-left: 8px; margin-right: 24px;} span.hil {color:blue;} +span.warn {color:orange; font-weight:bold;} +span.urg {color:red; font-weight:bold;} #n42 {margin:0; position: relative; color:#fff; background:#07e;} #n42 a {color:#fff; text-decoration:none; margin: 4px;} #n42 td {min-width: 100px; float: left; vertical-align: top; padding: 2px;} diff --git a/pool/page_ckp.php b/pool/page_ckp.php new file mode 100644 index 00000000..ae03d288 --- /dev/null +++ b/pool/page_ckp.php @@ -0,0 +1,71 @@ + 99999999) + $b4 = ''; + else if ($num > 9999999) + $b4 = ''; + if ($b4 != '') + $af = ''; + return $b4.$fmt.$af; +} +# +function dockp($data, $user) +{ + $pg = '

CKPool

'; + + $msg = msgEncode('stats', 'stats', array()); + $rep = sendsockreply('stats', $msg); + if ($rep == false) + $ans = array(); + else + $ans = repDecode($rep); + + $pg .= 'TotalRAM: '.stnum($ans['totalram']).'
'; + $pg .= "\n"; + $pg .= ''; + $pg .= ''; + $pg .= ''; + $pg .= ''; + $pg .= ''; + $pg .= "\n"; + if ($ans['STATUS'] == 'ok') + { + for ($i = 0; $i < 999; $i++) + { + if ($i == 0) + $name = 'stats.name'; + else + $name = 'name'; + + if (!isset($ans[$name.$i])) + break; + + if (($i % 2) == 0) + $row = 'even'; + else + $row = 'odd'; + + $pg .= ""; + $pg .= ''; + $pg .= ''; + $pg .= ''; + $pg .= ''; + $pg .= "\n"; + } + } + $pg .= "
NameAllocatedStoreRAM
'.$ans[$name.$i].''.stnum($ans['allocated'.$i]).''.stnum($ans['store'.$i]).''.stnum($ans['ram'.$i]).'
\n"; + + return $pg; +} +# +function show_ckp($menu, $name, $user) +{ + gopage(NULL, 'dockp', $menu, $name, $user); +} +# +?> diff --git a/pool/prime.php b/pool/prime.php index e06205a4..ae6e5069 100644 --- a/pool/prime.php +++ b/pool/prime.php @@ -23,6 +23,8 @@ function process($p, $user) 'Payouts' => 'payout' ) ); + if ($user == 'Kano' || $user == 'ckolivas') + $menu['Help']['ckp'] = 'ckp'; $page = ''; $n = ''; foreach ($menu as $item => $options) From 8e2d94baf6f3f069884b20480b9883913307255a Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 21 Aug 2014 17:49:13 +1000 Subject: [PATCH 5/9] php - clarify the pool user stats hash rate --- pool/page_stats.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pool/page_stats.php b/pool/page_stats.php index 363813c0..bc469389 100644 --- a/pool/page_stats.php +++ b/pool/page_stats.php @@ -18,7 +18,7 @@ function dostats($data, $user) $pg .= "\n"; $pg .= ""; $pg .= ""; - $pg .= ""; + $pg .= ""; $pg .= "\n"; if ($ans['STATUS'] == 'ok') { From f8725a3a69a83d558e49065b25cadc8696805a24 Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 21 Aug 2014 18:16:01 +1000 Subject: [PATCH 6/9] ckdb/php - add 5m hashrate to allusers and use it --- pool/page_stats.php | 8 ++++---- src/ckdb.c | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pool/page_stats.php b/pool/page_stats.php index bc469389..2e5c108f 100644 --- a/pool/page_stats.php +++ b/pool/page_stats.php @@ -2,7 +2,7 @@ # function allusersort($a, $b) { - $cmp = $a['u_hashrate1hr'] != $b['u_hashrate1hr']; + $cmp = $a['u_hashrate5m'] != $b['u_hashrate5m']; if ($cmp != 0) return $cmp; return $a['userid'] - $b['userid']; @@ -18,7 +18,7 @@ function dostats($data, $user) $pg .= "
UsernameHash RateHash Rate 1hr
\n"; $pg .= ""; $pg .= ""; - $pg .= ""; + $pg .= ""; $pg .= "\n"; if ($ans['STATUS'] == 'ok') { @@ -28,7 +28,7 @@ function dostats($data, $user) { $all[] = array('username' => $ans['username'.$i], 'userid' => $ans['userid'.$i], - 'u_hashrate1hr' => $ans['u_hashrate1hr'.$i]); + 'u_hashrate5m' => $ans['u_hashrate5m'.$i]); } usort($all, 'allusersort'); @@ -42,7 +42,7 @@ function dostats($data, $user) $pg .= ""; $pg .= ''; - $uhr = $all[$i]['u_hashrate1hr']; + $uhr = $all[$i]['u_hashrate5m']; if ($uhr == '?') $uhr = '?GHs'; else diff --git a/src/ckdb.c b/src/ckdb.c index 94bced6b..9d8a4952 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -6797,6 +6797,7 @@ static char *cmd_allusers(__maybe_unused PGconn *conn, char *cmd, char *id, size_t len, off; int rows; int64_t userid = -1; + double u_hashrate5m = 0.0; double u_hashrate1hr = 0.0; LOGDEBUG("%s(): cmd '%s'", __func__, cmd); @@ -6812,6 +6813,7 @@ static char *cmd_allusers(__maybe_unused PGconn *conn, char *cmd, char *id, DATA_USERSTATS(usw_item)->userid = DATA_USERSTATS(us_item)->userid; strcpy(DATA_USERSTATS(usw_item)->workername, DATA_USERSTATS(us_item)->workername); + DATA_USERSTATS(usw_item)->hashrate5m = DATA_USERSTATS(us_item)->hashrate5m; DATA_USERSTATS(usw_item)->hashrate1hr = DATA_USERSTATS(us_item)->hashrate1hr; userstats_workername_root = add_to_ktree(userstats_workername_root, usw_item, cmp_userstats_workername); @@ -6842,6 +6844,10 @@ static char *cmd_allusers(__maybe_unused PGconn *conn, char *cmd, char *id, snprintf(tmp, sizeof(tmp), "userid%d=%s%c", rows, reply, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); + double_to_buf(u_hashrate5m, reply, sizeof(reply)); + snprintf(tmp, sizeof(tmp), "u_hashrate5m%d=%s%c", rows, reply, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + double_to_buf(u_hashrate1hr, reply, sizeof(reply)); snprintf(tmp, sizeof(tmp), "u_hashrate1hr%d=%s%c", rows, reply, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); @@ -6850,8 +6856,10 @@ static char *cmd_allusers(__maybe_unused PGconn *conn, char *cmd, char *id, } } userid = DATA_USERSTATS(usw_item)->userid; + u_hashrate5m = 0; u_hashrate1hr = 0; } + u_hashrate5m += DATA_USERSTATS(usw_item)->hashrate5m; u_hashrate1hr += DATA_USERSTATS(usw_item)->hashrate1hr; tmp_item = usw_item; @@ -6875,6 +6883,10 @@ static char *cmd_allusers(__maybe_unused PGconn *conn, char *cmd, char *id, snprintf(tmp, sizeof(tmp), "userid%d=%s%c", rows, reply, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); + double_to_buf(u_hashrate5m, reply, sizeof(reply)); + snprintf(tmp, sizeof(tmp), "u_hashrate5m%d=%s%c", rows, reply, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + double_to_buf(u_hashrate1hr, reply, sizeof(reply)); snprintf(tmp, sizeof(tmp), "u_hashrate1hr%d=%s%c", rows, reply, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); From 5cbbad7ac667931535ee9b50d3ec3a72df953a1a Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 21 Aug 2014 19:17:51 +1000 Subject: [PATCH 7/9] php - format stats numbers --- pool/page_stats.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pool/page_stats.php b/pool/page_stats.php index 2e5c108f..0b0ba88e 100644 --- a/pool/page_stats.php +++ b/pool/page_stats.php @@ -2,7 +2,7 @@ # function allusersort($a, $b) { - $cmp = $a['u_hashrate5m'] != $b['u_hashrate5m']; + $cmp = $b['u_hashrate5m'] - $a['u_hashrate5m']; if ($cmp != 0) return $cmp; return $a['userid'] - $b['userid']; @@ -44,16 +44,20 @@ function dostats($data, $user) $pg .= ''; $uhr = $all[$i]['u_hashrate5m']; if ($uhr == '?') - $uhr = '?GHs'; + $dsp = '?GHs'; else { $uhr /= 10000000; if ($uhr < 100000) - $uhr = (round($uhr)/100).'GHs'; + $rate = 'G'; else - $uhr = (round($uhr/1000)/100).'THs'; + { + $rate = 'T'; + $uhr /= 1000; + } + $dsp = number_format($urh/100, 2); } - $pg .= ""; + $pg .= ""; $pg .= "\n"; } } From b8a2eef73b115152826ae837946afd7eae74927a Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 21 Aug 2014 19:19:50 +1000 Subject: [PATCH 8/9] php - put back removed rate --- pool/page_stats.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pool/page_stats.php b/pool/page_stats.php index 0b0ba88e..1db00aa1 100644 --- a/pool/page_stats.php +++ b/pool/page_stats.php @@ -55,7 +55,7 @@ function dostats($data, $user) $rate = 'T'; $uhr /= 1000; } - $dsp = number_format($urh/100, 2); + $dsp = number_format($urh/100, 2).$rate.'Hs'; } $pg .= ""; $pg .= "\n"; From 2e39830d98598cc7ce4c97fe8c7b60c064ca070a Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 21 Aug 2014 19:26:24 +1000 Subject: [PATCH 9/9] php - typo --- pool/page_stats.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pool/page_stats.php b/pool/page_stats.php index 1db00aa1..fad0f4db 100644 --- a/pool/page_stats.php +++ b/pool/page_stats.php @@ -55,7 +55,7 @@ function dostats($data, $user) $rate = 'T'; $uhr /= 1000; } - $dsp = number_format($urh/100, 2).$rate.'Hs'; + $dsp = number_format($uhr/100, 2).$rate.'Hs'; } $pg .= ""; $pg .= "\n";
UsernameHash Rate 1hrHash Rate 5m
'.$all[$i]['username'].''.$all[$i]['username'].'$uhr$dsp
$dsp
$dsp