Browse Source

Merge branch 'master' of bitbucket.org:ckolivas/ckpool

master
Con Kolivas 11 years ago
parent
commit
6a224caf1f
  1. 2
      pool/page.php
  2. 71
      pool/page_ckp.php
  3. 13
      pool/page_payout.php
  4. 20
      pool/page_stats.php
  5. 5
      pool/prime.php
  6. 27
      src/ckdb.c

2
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;}

71
pool/page_ckp.php

@ -0,0 +1,71 @@
<?php
#
function stnum($num)
{
$b4 = '';
$af = '';
$fmt = number_format($num, 0);
if ($num > 99999999)
$b4 = '<span class=urg>';
else if ($num > 9999999)
$b4 = '<span class=warn>';
if ($b4 != '')
$af = '</span>';
return $b4.$fmt.$af;
}
#
function dockp($data, $user)
{
$pg = '<h1>CKPool</h1>';
$msg = msgEncode('stats', 'stats', array());
$rep = sendsockreply('stats', $msg);
if ($rep == false)
$ans = array();
else
$ans = repDecode($rep);
$pg .= 'TotalRAM: '.stnum($ans['totalram']).'<br>';
$pg .= "<table callpadding=0 cellspacing=0 border=0>\n";
$pg .= '<tr class=title>';
$pg .= '<td class=dl>Name</td>';
$pg .= '<td class=dr>Allocated</td>';
$pg .= '<td class=dr>Store</td>';
$pg .= '<td class=dr>RAM</td>';
$pg .= "</tr>\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 .= "<tr class=$row>";
$pg .= '<td class=dl>'.$ans[$name.$i].'</td>';
$pg .= '<td class=dr>'.stnum($ans['allocated'.$i]).'</td>';
$pg .= '<td class=dr>'.stnum($ans['store'.$i]).'</td>';
$pg .= '<td class=dr>'.stnum($ans['ram'.$i]).'</td>';
$pg .= "</tr>\n";
}
}
$pg .= "</table>\n";
return $pg;
}
#
function show_ckp($menu, $name, $user)
{
gopage(NULL, 'dockp', $menu, $name, $user);
}
#
?>

13
pool/page_payout.php

@ -0,0 +1,13 @@
<?php
#
function dopayout($data, $user)
{
return '<h1>Payouts</h1>Description';
}
#
function show_payout($menu, $name, $user)
{
gopage(NULL, 'dopayout', $menu, $name, $user);
}
#
?>

20
pool/page_stats.php

@ -2,7 +2,7 @@
#
function allusersort($a, $b)
{
$cmp = $a['u_hashrate1hr'] != $b['u_hashrate1hr'];
$cmp = $b['u_hashrate5m'] - $a['u_hashrate5m'];
if ($cmp != 0)
return $cmp;
return $a['userid'] - $b['userid'];
@ -18,7 +18,7 @@ function dostats($data, $user)
$pg .= "<table callpadding=0 cellspacing=0 border=0>\n";
$pg .= "<tr class=title>";
$pg .= "<td class=dl>Username</td>";
$pg .= "<td class=dr>Hash Rate</td>";
$pg .= "<td class=dr>Hash Rate 5m</td>";
$pg .= "</tr>\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,18 +42,22 @@ function dostats($data, $user)
$pg .= "<tr class=$row>";
$pg .= '<td class=dl>'.$all[$i]['username'].'</td>';
$uhr = $all[$i]['u_hashrate1hr'];
$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($uhr/100, 2).$rate.'Hs';
}
$pg .= "<td class=dr>$uhr</td>";
$pg .= "<td class=dr>$dsp</td>";
$pg .= "</tr>\n";
}
}

5
pool/prime.php

@ -19,9 +19,12 @@ function process($p, $user)
),
'gap' => NULL,
'Help' => array(
'Help' => 'help'
'Help' => 'help',
'Payouts' => 'payout'
)
);
if ($user == 'Kano' || $user == 'ckolivas')
$menu['Help']['ckp'] = 'ckp';
$page = '';
$n = '';
foreach ($menu as $item => $options)

27
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]*$";
@ -6796,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);
@ -6811,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);
@ -6841,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);
@ -6849,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;
@ -6874,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);
@ -7583,14 +7596,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

Loading…
Cancel
Save