Browse Source

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

master
Con Kolivas 10 years ago
parent
commit
995d4f3d04
  1. 16
      pool/base.php
  2. 46
      pool/page.php
  3. 26
      pool/page_reg.php
  4. 56
      pool/page_stats.php
  5. 22
      pool/page_workers.php
  6. 2
      src/ckdb.h
  7. 29
      src/ckdb_cmd.c
  8. 1
      src/ckdb_dbio.c

16
pool/base.php

@ -87,6 +87,22 @@ function siprefmt($amt)
return number_format($amt, $dot).$sipre[$pref];
}
#
function dsprate($hr)
{
$hr /= 10000000;
if ($hr < 100000)
{
if ($hr < 0.01)
$hr = '0GHs';
else
$hr = number_format(round($hr)/100, 2).'GHs';
}
else
$hr = number_format(round($hr/1000)/100, 2).'THs';
return $hr;
}
#
function difffmt($amt)
{
return siprefmt($amt);

46
pool/page.php

@ -145,11 +145,10 @@ h1 {margin-top: 20px; float:middle; font-size: 20px;}
return $head;
}
#
function pgtop($dotop, $user, $douser)
function pgtop($info, $dotop, $user, $douser)
{
global $site_title;
$info = homeInfo($user);
$phr = '?THs';
$plb = '?';
$nlb = '?';
@ -164,21 +163,15 @@ function pgtop($dotop, $user, $douser)
if (isset($info['p_hashrate5m']))
$phr = $info['p_hashrate5m'];
if (isset($info['p_elapsed'])
and isset($info['p_hashrate1hr'])
and $info['p_elapsed'] > 3600)
$phr = $info['p_hashrate1hr'];
// if (isset($info['p_elapsed'])
// and isset($info['p_hashrate1hr'])
// and $info['p_elapsed'] > 3600)
// $phr = $info['p_hashrate1hr'];
if ($phr == '?')
$phr = '?THs';
else
{
$phr /= 10000000;
if ($phr < 100000)
$phr = (round($phr)/100).'GHs';
else
$phr = (round($phr/1000)/100).'THs';
}
$phr = dsprate($phr);
if (isset($info['lastblock']))
{
@ -254,13 +247,7 @@ function pgtop($dotop, $user, $douser)
if ($uhr == '?')
$uhr = '?GHs';
else
{
$uhr /= 10000000;
if ($uhr < 100000)
$uhr = (round($uhr)/100).'GHs';
else
$uhr = (round($uhr/1000)/100).'THs';
}
$uhr = dsprate($uhr);
}
if (isset($info['u_hashrate1hr'])
@ -272,11 +259,7 @@ function pgtop($dotop, $user, $douser)
$u1hr = '';
else
{
$u1hr /= 10000000;
if ($u1hr < 100000)
$u1hr = '/'.(round($u1hr)/100).'GHs';
else
$u1hr = '/'.(round($u1hr/1000)/100).'THs';
$u1hr = dsprate($u1hr);
if (substr($u1hr, -3) == substr($uhr, -3))
$uhr = substr($uhr, 0, -3);
@ -395,7 +378,7 @@ function pgmenu($menus)
return $ret;
}
#
function pgbody($page, $menu, $dotop, $user, $douser)
function pgbody($info, $page, $menu, $dotop, $user, $douser)
{
$body = '<body onload="jst()"';
if ($page == 'index')
@ -407,7 +390,7 @@ function pgbody($page, $menu, $dotop, $user, $douser)
$body .= '<table border=0 cellpadding=0 cellspacing=0 width=94%>';
$body .= '<tr><td>';
$body .= pgtop($dotop, $user, $douser);
$body .= pgtop($info, $dotop, $user, $douser);
$body .= '</td></tr>';
$body .= '<tr><td>';
@ -449,8 +432,13 @@ function gopage($data, $pagefun, $page, $menu, $name, $user, $ispage = true, $do
else
$pg = '';
$info = homeInfo($user);
if ($ispage == true)
$pg .= $pagefun($data, $user);
{
$both = array('info' => $info, 'data' => $data);
$pg .= $pagefun($both, $user);
}
else
$pg .= $pagefun;
@ -458,7 +446,7 @@ function gopage($data, $pagefun, $page, $menu, $name, $user, $ispage = true, $do
// unset($_SESSION['logkey']);
$head = pghead($script_marker, $name);
$body = pgbody($page, $menu, $dotop, $user, $douser);
$body = pgbody($info, $page, $menu, $dotop, $user, $douser);
$foot = pgfoot();
if ($dbg === true)

26
pool/page_reg.php

@ -5,21 +5,21 @@ include_once('email.php');
#
function doregres($data, $u)
{
if (isset($data['user']))
$user = htmlspecialchars($data['user']);
if (isset($data['data']['user']))
$user = htmlspecialchars($data['data']['user']);
else
$user = '';
if (isset($data['mail']))
$mail = htmlspecialchars($data['mail']);
if (isset($data['data']['mail']))
$mail = htmlspecialchars($data['data']['mail']);
else
$mail = '';
$pg = '<br><br><table cellpadding=5 cellspacing=0 border=1><tr><td class=dc>';
$pg .= '<h1>Register</h1>';
if (isset($data['error']))
$pg .= "<br><b>".$data['error']." - please try again</b><br><br>";
if (isset($data['data']['error']))
$pg .= "<br><b>".$data['data']['error']." - please try again</b><br><br>";
$pg .= makeForm('');
$pg .= "
<table>
@ -65,8 +65,8 @@ An Email will be sent to you, to let you reset your password</font></td></tr>
#
function doreg2($data)
{
if (isset($data['user']))
$user = htmlspecialchars($data['user']);
if (isset($data['data']['user']))
$user = htmlspecialchars($data['data']['user']);
else
$user = '';
@ -74,8 +74,8 @@ function doreg2($data)
// $pg .= '<br>You will receive an email shortly to verify your account';
$pg .= '<br>Your account is registered and ready to mine.';
$pg .= '<br>Choose your own worker names in cgminer.';
$pg .= '<br>Worker names must start with your username like';
$pg .= ": <span class=hil>${user}_</span> or <span class=hil>${user}.</span>";
$pg .= '<br>Worker names must start with your username and a dot or an underscore';
$pg .= "<br>e.g. <span class=hil>${user}_worker1</span> or <span class=hil>${user}.worker7</span>";
return $pg;
}
#
@ -138,8 +138,8 @@ function try_reg($page, $menu, $name, $u)
#
function doreset2($data)
{
$user = $data['user'];
$email = $data['email'];
$user = $data['data']['user'];
$email = $data['data']['email'];
$emailinfo = getOpts($user, emailOptList());
if ($emailinfo['STATUS'] != 'ok')
@ -154,7 +154,7 @@ function doreset2($data)
{
// This line $code = isn't an attempt at security -
// it's simply to ensure the username is readable when we get it back
$code = bin2hex($data['user']). '_';
$code = bin2hex($data['data']['user']). '_';
// A code that's large enough to not be worth guessing
$ran = $ans['STAMP'].$user.$email.rand(100000000,999999999);

56
pool/page_stats.php

@ -12,6 +12,50 @@ function dostats($data, $user)
{
$pg = '<h1>Pool Stats</h1>';
if (isset($data['info']) && $data['info'] !== false)
{
$info = $data['info'];
$dsp = '?THs';
$dsp5m = '?THs';
$dsp1hr = '?THs';
$dsp24hr = '?THs';
if (isset($info['p_hashrate']))
{
$hr = $info['p_hashrate'];
if ($hr != '?')
$dsp = dsprate($hr);
}
if (isset($info['p_hashrate5m']))
{
$hr = $info['p_hashrate5m'];
if ($hr != '?')
$dsp5m = dsprate($hr);
}
if (isset($info['p_hashrate1hr']))
{
$hr = $info['p_hashrate1hr'];
if ($hr != '?')
$dsp1hr = dsprate($hr);
}
if (isset($info['p_hashrate24hr']))
{
$hr = $info['p_hashrate24hr'];
if ($hr != '?')
$dsp24hr = dsprate($hr);
}
$pg .= '<table cellpadding=8 cellspacing=0 border=0><tr>';
$pg .= "<td>Pool Hashrate: $dsp</td>";
$pg .= "<td>5m: $dsp5m</td>";
$pg .= "<td>1hr: $dsp1hr</td>";
$pg .= "<td>24hr: $dsp24hr</td>";
$pg .= '</tr></table><br>';
}
$ans = getAllUsers($user);
$pg .= "<table callpadding=0 cellspacing=0 border=0>\n";
@ -45,17 +89,7 @@ function dostats($data, $user)
if ($uhr == '?')
$dsp = '?GHs';
else
{
$uhr /= 10000000;
if ($uhr < 100000)
$rate = 'G';
else
{
$rate = 'T';
$uhr /= 1000;
}
$dsp = number_format($uhr/100, 2).$rate.'Hs';
}
$dsp = dsprate($uhr);
$pg .= "<td class=dr>$dsp</td>";
$pg .= "</tr>\n";
}

22
pool/page_workers.php

@ -82,16 +82,7 @@ function workuser($data, $user, &$offset, &$totshare, &$totdiff,
else
{
$totrate += $uhr;
$uhr /= 10000000;
if ($uhr < 0.01)
$uhr = '0GHs';
else
{
if ($uhr < 100000)
$uhr = number_format(round($uhr)/100,2).'GHs';
else
$uhr = number_format(round($uhr/1000)/100,2).'THs';
}
$uhr = dsprate($uhr);
}
$pg .= "<td class=dr>$uhr</td>";
@ -106,16 +97,7 @@ function workuser($data, $user, &$offset, &$totshare, &$totdiff,
function worktotal($offset, $totshare, $totdiff, $totinvalid, $totrate, $blockacc, $blockreward)
{
$pg = '';
$totrate /= 10000000;
if ($totrate < 0.01)
$totrate = '0GHs';
else
{
if ($totrate < 100000)
$totrate = number_format(round($totrate)/100,2).'GHs';
else
$totrate = number_format(round($totrate/1000)/100,2).'THs';
}
$totrate = dsprate($totrate);
if (($offset % 2) == 0)
$row = 'even';
else

2
src/ckdb.h

@ -52,7 +52,7 @@
#define DB_VLOCK "1"
#define DB_VERSION "0.9.2"
#define CKDB_VERSION DB_VERSION"-0.402"
#define CKDB_VERSION DB_VERSION"-0.405"
#define WHERE_FFL " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__

29
src/ckdb_cmd.c

@ -9,7 +9,6 @@
#include "ckdb.h"
static char *cmd_adduser(PGconn *conn, char *cmd, char *id, tv_t *now, char *by,
char *code, char *inet, __maybe_unused tv_t *notcd,
K_TREE *trf_root)
@ -53,7 +52,7 @@ static char *cmd_newpass(__maybe_unused PGconn *conn, char *cmd, char *id,
K_ITEM *i_username, *i_oldhash, *i_newhash, *u_item;
char reply[1024] = "";
size_t siz = sizeof(reply);
bool ok = false;
bool ok = true;
char *oldhash;
LOGDEBUG("%s(): cmd '%s'", __func__, cmd);
@ -2007,6 +2006,10 @@ static char *cmd_homepage(__maybe_unused PGconn *conn, char *cmd, char *id,
snprintf(tmp, sizeof(tmp), "workers=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
double_to_buf(poolstats->hashrate, reply, siz);
snprintf(tmp, sizeof(tmp), "p_hashrate=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
double_to_buf(poolstats->hashrate5m, reply, siz);
snprintf(tmp, sizeof(tmp), "p_hashrate5m=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
@ -2015,13 +2018,24 @@ static char *cmd_homepage(__maybe_unused PGconn *conn, char *cmd, char *id,
snprintf(tmp, sizeof(tmp), "p_hashrate1hr=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
double_to_buf(poolstats->hashrate24hr, reply, siz);
snprintf(tmp, sizeof(tmp), "p_hashrate24hr=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
bigint_to_buf(poolstats->elapsed, reply, siz);
snprintf(tmp, sizeof(tmp), "p_elapsed=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
tvs_to_buf(&(poolstats->createdate), reply, siz);
snprintf(tmp, sizeof(tmp), "p_statsdate=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
} else {
snprintf(tmp, sizeof(tmp), "users=?%cworkers=?%cp_hashrate5m=?%c"
"p_hashrate1hr=?%cp_elapsed=?%c",
FLDSEP, FLDSEP, FLDSEP, FLDSEP, FLDSEP);
snprintf(tmp, sizeof(tmp), "users=?%cworkers=?%cp_hashrate=?%c"
"p_hashrate5m=?%cp_hashrate1hr=?%c"
"p_hashrate24hr=?%cp_elapsed=?%c"
"p_statsdate=?%c",
FLDSEP, FLDSEP, FLDSEP, FLDSEP,
FLDSEP, FLDSEP, FLDSEP, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
}
@ -3292,7 +3306,12 @@ static char *cmd_stats(__maybe_unused PGconn *conn, char *cmd, char *id,
* loglevel.ID
* sets the loglevel to atoi(ID)
* Without an ID, it just reports the current value
*
* createdate = true
* means that the data sent must contain a fld or json fld called createdate
*/
// cmd_val cmd_str noid createdate func access
struct CMDS ckdb_cmds[] = {
{ CMD_SHUTDOWN, "shutdown", true, false, NULL, ACCESS_SYSTEM },
{ CMD_PING, "ping", true, false, NULL, ACCESS_SYSTEM ACCESS_POOL ACCESS_WEB },

1
src/ckdb_dbio.c

@ -4456,6 +4456,7 @@ unparam:
return ok;
}
// This is to RAM. The summariser calls the DB I/O functions for userstats
bool userstats_add(char *poolinstance, char *elapsed, char *username,
char *workername, char *hashrate, char *hashrate5m,
char *hashrate1hr, char *hashrate24hr, bool idle,

Loading…
Cancel
Save