Browse Source

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

master
Con Kolivas 10 years ago
parent
commit
8b32ebf74c
  1. BIN
      html/BTC.png
  2. 57
      pool/base.php
  3. 53
      pool/db.php
  4. 105
      pool/page.php
  5. 22
      pool/page_blocks.php
  6. 23
      pool/page_ckp.php
  7. 4
      pool/page_help.php
  8. 4
      pool/page_index.php
  9. 13
      pool/page_payments.php
  10. 4
      pool/page_payout.php
  11. 14
      pool/page_pplns.php
  12. 51
      pool/page_reg.php
  13. 155
      pool/page_settings.php
  14. 13
      pool/page_stats.php
  15. 27
      pool/page_workers.php
  16. 1
      sql/initid.sh
  17. 2583
      src/ckdb.c

BIN
html/BTC.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

57
pool/base.php

@ -65,9 +65,38 @@ function emailStr($str)
return preg_replace(array($all,$beg,$fin), '', $str); return preg_replace(array($all,$beg,$fin), '', $str);
} }
# #
function safepass($pass)
{
if (strlen($pass) < 6)
return false;
# Invalid characters
$p2 = preg_replace('/[\011]/', '', $pass);
if ($p2 != $pass)
return false;
# At least one lowercase
$p2 = preg_replace('/[a-z]/', '', $pass);
if ($p2 == $pass)
return false;
# At least one uppercase
$p2 = preg_replace('/[A-Z]/', '', $pass);
if ($p2 == $pass)
return false;
# At least one digit
$p2 = preg_replace('/[0-9]/', '', $pass);
if ($p2 == $pass)
return false;
return true;
}
#
function loginStr($str) function loginStr($str)
{ {
$all = '/[^!-~]/'; // no spaces // Anything but . _ / Tab
$all = '/[\._\/\011]/';
return preg_replace($all, '', $str); return preg_replace($all, '', $str);
} }
# #
@ -137,34 +166,34 @@ function safetext($txt, $len = 1024)
# #
function dbd($data, $user) function dbd($data, $user)
{ {
return "<font color=red size=+10><br>Web site is currently down</font>"; return "<span class=alert><br>Web site is currently down</span>";
} }
# #
function dbdown() function dbdown()
{ {
gopage(NULL, 'dbd', NULL, '', false, true, false); gopage(NULL, 'dbd', 'dbd', NULL, '', '', true, false, false);
} }
# #
function f404($data) function f404($data)
{ {
return "<font color=red size=+10><br>404</font>"; return "<span class=alert><br>404</span>";
} }
# #
function do404() function do404()
{ {
gopage(NULL, 'f404', NULL, '', false, true, false); gopage(NULL, 'f404', 'f404', NULL, '', '', true, false, false);
} }
# #
function showPage($page, $menu, $name, $user) function showPage($page, $menu, $name, $user)
{ {
# If you are doing development, use without '@' # If you are doing development, use without '@'
# Then switch to '@' when finished # Then switch to '@' when finished
# @include_once("page_$page.php"); # include_once("page_$page.php");
include_once("page_$page.php"); @include_once("page_$page.php");
$fun = 'show_' . $page; $fun = 'show_' . $page;
if (function_exists($fun)) if (function_exists($fun))
$fun($menu, $name, $user); $fun($page, $menu, $name, $user);
else else
do404(); do404();
} }
@ -179,8 +208,9 @@ function offline()
if (file_exists('./maintenance.txt')) if (file_exists('./maintenance.txt'))
{ {
$ip = $_SERVER['REMOTE_ADDR']; $ip = $_SERVER['REMOTE_ADDR'];
if ($ip != '192.168.7.74') if ($ip != '192.168.1.666')
gopage(NULL, file_get_contents('./maintenance.txt'), NULL, '', false, false, false, false); gopage(NULL, file_get_contents('./maintenance.txt'),
'offline', NULL, '', '', false, false, false);
} }
} }
# #
@ -192,10 +222,11 @@ include_once('db.php');
# #
function validUserPass($user, $pass) function validUserPass($user, $pass)
{ {
$rep = checkpass($user, $pass); $rep = checkPass($user, $pass);
$ans = repDecode($rep); if ($rep != null)
$ans = repDecode($rep);
usleep(100000); // Max 10x per second usleep(100000); // Max 10x per second
if ($ans['STATUS'] == 'ok') if ($rep != null && $ans['STATUS'] == 'ok')
{ {
$key = 'ckp'.rand(1000000,9999999); $key = 'ckp'.rand(1000000,9999999);
$_SESSION['ckpkey'] = $key; $_SESSION['ckpkey'] = $key;

53
pool/db.php

@ -59,7 +59,7 @@ function repDecode($rep)
if (isset($major[3])) if (isset($major[3]))
$ans['ERROR'] = $major[3]; $ans['ERROR'] = $major[3];
else else
$ans['ERROR'] = 'unknown'; $ans['ERROR'] = 'system error';
} }
return $ans; return $ans;
@ -116,17 +116,56 @@ function homeInfo($user)
return $ans; return $ans;
} }
# #
function checkpass($user, $pass) function checkPass($user, $pass)
{ {
$passhash = myhash($pass); $passhash = myhash($pass);
$flds = array('username' => $user, 'passwordhash' => $passhash); $flds = array('username' => $user, 'passwordhash' => $passhash);
$msg = msgEncode('chkpass', 'log', $flds); $msg = msgEncode('chkpass', 'log', $flds);
$rep = sendsockreply('checkpass', $msg); $rep = sendsockreply('checkPass', $msg);
if (!$rep) if (!$rep)
dbdown(); dbdown();
return $rep; return $rep;
} }
# #
function setPass($user, $oldpass, $newpass)
{
$oldhash = myhash($oldpass);
$newhash = myhash($newpass);
$flds = array('username' => $user, 'oldhash' => $oldhash, 'newhash' => $newhash);
$msg = msgEncode('newpass', 'log', $flds);
$rep = sendsockreply('setPass', $msg);
if (!$rep)
dbdown();
return repDecode($rep);
}
#
function userReg($user, $email, $pass)
{
$passhash = myhash($pass);
$flds = array('username' => $user, 'emailaddress' => $email, 'passwordhash' => $passhash);
$msg = msgEncode('adduser', 'reg', $flds);
$rep = sendsockreply('userReg', $msg);
if (!$rep)
dbdown();
return repDecode($rep);
}
#
function userSettings($user, $email = null, $addr = null, $pass = null)
{
$flds = array('username' => $user);
if ($email != null)
$flds['email'] = $email;
if ($addr != null)
$flds['address'] = $addr;
if ($pass != null)
$flds['passwordhash'] = myhash($pass);
$msg = msgEncode('usersettings', 'userset', $flds);
$rep = sendsockreply('userSettings', $msg);
if (!$rep)
dbdown();
return repDecode($rep);
}
#
function getAllUsers() function getAllUsers()
{ {
$flds = array(); $flds = array();
@ -134,7 +173,7 @@ function getAllUsers()
$rep = sendsockreply('getAllUsers', $msg); $rep = sendsockreply('getAllUsers', $msg);
if (!$rep) if (!$rep)
dbdown(); dbdown();
return $rep; return repDecode($rep);
} }
# #
function getWorkers($user) function getWorkers($user)
@ -146,7 +185,7 @@ function getWorkers($user)
$rep = sendsockreply('getWorkers', $msg); $rep = sendsockreply('getWorkers', $msg);
if (!$rep) if (!$rep)
dbdown(); dbdown();
return $rep; return repDecode($rep);
} }
# #
function getPayments($user) function getPayments($user)
@ -158,7 +197,7 @@ function getPayments($user)
$rep = sendsockreply('getPayments', $msg); $rep = sendsockreply('getPayments', $msg);
if (!$rep) if (!$rep)
dbdown(); dbdown();
return $rep; return repDecode($rep);
} }
# #
function getBlocks($user) function getBlocks($user)
@ -170,7 +209,7 @@ function getBlocks($user)
$rep = sendsockreply('getBlocks', $msg); $rep = sendsockreply('getBlocks', $msg);
if (!$rep) if (!$rep)
dbdown(); dbdown();
return $rep; return repDecode($rep);
} }
# #
?> ?>

105
pool/page.php

@ -52,6 +52,14 @@ function makeLink($page, $rest = '')
return $href; return $href;
} }
# #
function makeForm($page)
{
$form = '<form action=index.php method=POST>';
if (strlen($page) > 0)
$form .= "<input type=hidden name=k value=$page>";
return $form;
}
#
function dotrm($html, $dontdoit) function dotrm($html, $dontdoit)
{ {
if ($dontdoit === true) if ($dontdoit === true)
@ -82,17 +90,20 @@ function pghead($script_marker, $name)
$head .= "<style type='text/css'> $head .= "<style type='text/css'>
form {display: inline-block;} form {display: inline-block;}
html, body {height: 100%; font-family:Arial, Verdana, sans-serif; font-size:12pt; background-color:#eff; text-align: center;} html, body {height: 100%; font-family:Arial, Verdana, sans-serif; font-size:12pt; background-color:#eff; text-align: center; background-repeat: no-repeat; background-position: center; }
.page {min-height: 100%; height: auto !important; height: 100%; margin: 0 auto -50px; position: relative;} .page {min-height: 100%; height: auto !important; height: 100%; margin: 0 auto -50px; position: relative;}
div.jst {color:red; background-color: #ffa; font-weight: font-size: 8; bold; border-style: solid; border-width: 2px; vertical-align: top;} div.jst {color:red; font-weight: bold; font-size: 8; text-align: center; vertical-align: top;}
div.topd {background-color:#cff; border-color: #cff; border-style: solid; border-width: 9px;} div.topd {background-color:#cff; border-color: #cff; border-style: solid; border-width: 9px;}
span.topdes {color:blue;} .topdes {color:blue; text-align: right;}
span.topwho {color:black; font-weight: bold; margin-right: 8px;} .topwho {color:black; font-weight: bold; margin-right: 8px;}
span.topdat {margin-left: 8px; margin-right: 24px; color:green; font-weight: bold;} .topdat {margin-left: 8px; margin-right: 24px; color:green; font-weight: bold;}
span.login {float: right; margin-left: 8px; margin-right: 24px;} span.login {float: right; margin-left: 8px; margin-right: 24px;}
span.hil {color:blue;} span.hil {color:blue;}
span.warn {color:orange; font-weight:bold;} span.warn {color:orange; font-weight:bold;}
span.urg {color:red; font-weight:bold;} span.urg {color:red; font-weight:bold;}
span.err {color:red; font-weight:bold; font-size:120%;}
span.alert {color:red; font-weight:bold; font-size:250%;}
input.tiny {width: 0px; height: 0px; margin: 0px; padding: 0px; outline: none; border: 0px;}
#n42 {margin:0; position: relative; color:#fff; background:#07e;} #n42 {margin:0; position: relative; color:#fff; background:#07e;}
#n42 a {color:#fff; text-decoration:none; margin: 4px;} #n42 a {color:#fff; text-decoration:none; margin: 4px;}
#n42 td {min-width: 100px; float: left; vertical-align: top; padding: 2px;} #n42 td {min-width: 100px; float: left; vertical-align: top; padding: 2px;}
@ -187,6 +198,9 @@ function pgtop($dotop, $user, $douser)
} }
} }
if (isset($info['lastblockheight']))
$plb .= ' ('.$info['lastblockheight'].')';
if (isset($info['lastbc'])) if (isset($info['lastbc']))
{ {
$nlb = $info['lastbc']; $nlb = $info['lastbc'];
@ -201,6 +215,9 @@ function pgtop($dotop, $user, $douser)
} }
} }
if (isset($info['lastheight']))
$nlb .= ' ('.$info['lastheight'].')';
if (isset($info['blockacc'])) if (isset($info['blockacc']))
{ {
$acc = $info['blockacc']; $acc = $info['blockacc'];
@ -214,7 +231,12 @@ function pgtop($dotop, $user, $douser)
} }
if (isset($info['blockerr'])) if (isset($info['blockerr']))
{
$rej = $info['blockerr'];
$per = number_format($info['blockerr'], 0); $per = number_format($info['blockerr'], 0);
if (isset($info['blockacc']) && ($acc+$rej) > 0)
$per .= ' ('.number_format(100.0*$rej/($acc+$rej), 3).'%)';
}
if (isset($info['u_hashrate5m'])) if (isset($info['u_hashrate5m']))
{ {
@ -260,23 +282,25 @@ function pgtop($dotop, $user, $douser)
if ($dotop === true) if ($dotop === true)
{ {
$top .= '<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td>'; $top .= '<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td>';
$top .= '<span class=topdes>CKPool:</span>'; $top .= '<table cellpadding=1 cellspacing=0 border=0 width=100%>';
$top .= "<span class=topdat>$phr</span>"; $top .= '<tr><td class=topdes>CKPool:&nbsp;</td>';
$top .= '<br>'; $top .= "<td class=topdat>&nbsp;$phr</td></tr>";
$top .= '<span class=topdes>Shares:</span>'; $top .= '<tr><td class=topdes>Shares:&nbsp;</td>';
$top .= "<span class=topdat>$pac</span>"; $top .= "<td class=topdat>&nbsp;$pac</td></tr>";
$top .= '<tr><td class=topdes>Invalid:&nbsp;</td>';
$top .= "<td class=topdat>&nbsp;$per</td></tr></table>";
$top .= '</td><td>'; $top .= '</td><td>';
$top .= '<span class=topdes>Pool, Last Block:</span>'; $top .= '<table cellpadding=1 cellspacing=0 border=0 width=100%>';
$top .= "<span class=topdat>$plb</span>"; $top .= '<tr><td class=topdes>Pool, Last Block:&nbsp;</td>';
$top .= '<br>'; $top .= "<td class=topdat>&nbsp;$plb</td></tr>";
$top .= '<span class=topdes>Network, Last Block:</span>'; $top .= '<tr><td class=topdes>Network, Last Block:&nbsp;</td>';
$top .= "<span class=topdat>$nlb</span>"; $top .= "<td class=topdat>&nbsp;$nlb</td></tr></table>";
$top .= '</td><td>'; $top .= '</td><td>';
$top .= '<span class=topdes>Users:</span>'; $top .= '<table cellpadding=1 cellspacing=0 border=0 width=100%>';
$top .= '<span class=topdat>'.$info['users'].'</span>'; $top .= '<tr><td class=topdes>Users:</td>';
$top .= '<br>'; $top .= '<td class=topdat>'.$info['users'].'</td></tr>';
$top .= '<span class=topdes>Workers:</span>'; $top .= '<tr><td class=topdes>Workers:</td>';
$top .= '<span class=topdat>'.$info['workers'].'</span>'; $top .= '<td class=topdat>'.$info['workers'].'</td></tr></table>';
$top .= '</td><td>'; $top .= '</td><td>';
if ($douser === true) if ($douser === true)
@ -285,33 +309,38 @@ function pgtop($dotop, $user, $douser)
list($who, $whoid) = validate(); list($who, $whoid) = validate();
if ($who == false) if ($who == false)
{ {
$top .= " $top .= makeForm('')."
<form action=index.php method=POST> <table cellpadding=0 cellspacing=0 border=0><tr><td>
<table cellpadding=0 cellspacing=0 border=0><tr> <table cellpadding=0 cellspacing=0 border=0><tr>
<td>User:</td><td><input type=text name=User size=10 value=''></td> <td>User:</td><td><input type=text name=User size=10 value=''></td>
<td>&nbsp;<input type=submit name=Login value=Login></td></tr><tr> </tr><tr>
<td>Pass:</td><td><input type=password name=Pass size=10 value=''></td> <td>Pass:</td><td><input type=password name=Pass size=10 value=''></td>
<td>&nbsp;&nbsp;<input type=submit name=Register value=Register></td></tr></table> </tr></table></td><td>
</form>"; <table cellpadding=0 cellspacing=0 border=0><tr>
<td>&nbsp;<input type=submit name=Login value=Login></td></tr><tr>
<td>&nbsp;&nbsp;
<input type=submit name=Register value=Register></td></tr></table>
</td></tr></table></form>";
} }
else else
{ {
$top .= " $top .= "
<span class=topwho>$who&nbsp;</span> <span class=topwho>$who&nbsp;</span>
<span class=topdes>Hash Rate:</span> <span class=topdes>Hash Rate:</span>
<span class=topdat>$uhr$u1hr</span> <span class=topdat>$uhr$u1hr</span>";
<form action=index.php method=POST> $top .= makeForm('')."
&nbsp;<input type=submit name=Logout value=Logout> &nbsp;<input type=submit name=Logout value=Logout>
</form>"; </form>";
} }
$top .= '</span>'; $top .= '</span>';
} }
$top .= '</td></tr></table>';
} }
else else
$top .= '&nbsp;'; $top .= '&nbsp;';
$top .= '</td></tr></table></div>'; $top .= '</div>';
return $top; return $top;
} }
# #
@ -351,16 +380,20 @@ function pgmenu($menus)
} }
$ret .= "<tr><td class=ts>".makeLink($item,'class=as')."$submenu</a></td></tr>"; $ret .= "<tr><td class=ts>".makeLink($item,'class=as')."$submenu</a></td></tr>";
} }
$ret .= '</table></div></td></tr></table></td>'; if ($first == false)
$ret .= '</table></div></td></tr></table>';
$ret .= '</td>';
} }
$ret .= "</tr></table></td></tr></table>\n"; $ret .= "</tr></table></td></tr></table>\n";
return $ret; return $ret;
} }
# #
function pgbody($menu, $dotop, $user, $douser) function pgbody($page, $menu, $dotop, $user, $douser)
{ {
$body = '<body onload="jst()">'; $body = '<body onload="jst()"';
$body .= '<div class=page>'; if ($page == 'index')
$body .= ' background=/BTC.png';
$body .= '><div class=page>';
$body .= '<table border=0 cellpadding=0 cellspacing=0 width=100%>'; $body .= '<table border=0 cellpadding=0 cellspacing=0 width=100%>';
$body .= '<tr><td><center>'; $body .= '<tr><td><center>';
@ -396,7 +429,7 @@ function pgfoot()
return $foot; return $foot;
} }
# #
function gopage($data, $page, $menu, $name, $user, $ispage = true, $dotop = true, $douser = true) function gopage($data, $pagefun, $page, $menu, $name, $user, $ispage = true, $dotop = true, $douser = true)
{ {
global $dbg; global $dbg;
global $page_scripts; global $page_scripts;
@ -410,15 +443,15 @@ function gopage($data, $page, $menu, $name, $user, $ispage = true, $dotop = true
$pg = ''; $pg = '';
if ($ispage == true) if ($ispage == true)
$pg .= $page($data, $user); $pg .= $pagefun($data, $user);
else else
$pg .= $page; $pg .= $pagefun;
// if (isset($_SESSION['logkey'])) // if (isset($_SESSION['logkey']))
// unset($_SESSION['logkey']); // unset($_SESSION['logkey']);
$head = pghead($script_marker, $name); $head = pghead($script_marker, $name);
$body = pgbody($menu, $dotop, $user, $douser); $body = pgbody($page, $menu, $dotop, $user, $douser);
$foot = pgfoot(); $foot = pgfoot();
if ($dbg === true) if ($dbg === true)

22
pool/page_blocks.php

@ -2,10 +2,11 @@
# #
function doblocks($data, $user) function doblocks($data, $user)
{ {
$blink = '<a href=https://blockchain.info/block-height/';
$pg = '<h1>Blocks</h1>'; $pg = '<h1>Blocks</h1>';
$rep = getBlocks($user); $ans = getBlocks($user);
$ans = repDecode($rep);
$pg .= "<table callpadding=0 cellspacing=0 border=0>\n"; $pg .= "<table callpadding=0 cellspacing=0 border=0>\n";
$pg .= "<tr class=title>"; $pg .= "<tr class=title>";
@ -26,17 +27,20 @@ function doblocks($data, $user)
$row = 'odd'; $row = 'odd';
$ex = ''; $ex = '';
$stat = $ans['status'.$i]; $stat = $ans['status:'.$i];
if ($stat == 'Orphan') if ($stat == 'Orphan')
$ex = 's'; $ex = 's';
if ($stat == '1-Confirm') if ($stat == '1-Confirm')
$stat = 'Conf'; $stat = 'Conf';
$hi = $ans['height:'.$i];
$hifld = "$blink$hi>$hi</a>";
$pg .= "<tr class=$row>"; $pg .= "<tr class=$row>";
$pg .= "<td class=dl$ex>".$ans['height'.$i].'</td>'; $pg .= "<td class=dl$ex>$hifld</td>";
$pg .= "<td class=dl$ex>".$ans['workername'.$i].'</td>'; $pg .= "<td class=dl$ex>".$ans['workername:'.$i].'</td>';
$pg .= "<td class=dr$ex>".btcfmt($ans['reward'.$i]).'</td>'; $pg .= "<td class=dr$ex>".btcfmt($ans['reward:'.$i]).'</td>';
$pg .= "<td class=dl$ex>".gmdate('Y-m-d H:i:s+00', $ans['firstcreatedate'.$i]).'</td>'; $pg .= "<td class=dl$ex>".gmdate('Y-m-d H:i:s+00', $ans['firstcreatedate:'.$i]).'</td>';
$pg .= "<td class=dr$ex>".$stat.'</td>'; $pg .= "<td class=dr$ex>".$stat.'</td>';
$pg .= "</tr>\n"; $pg .= "</tr>\n";
} }
@ -46,9 +50,9 @@ function doblocks($data, $user)
return $pg; return $pg;
} }
# #
function show_blocks($menu, $name, $user) function show_blocks($page, $menu, $name, $user)
{ {
gopage(NULL, 'doblocks', $menu, $name, $user); gopage(NULL, 'doblocks', $page, $menu, $name, $user);
} }
# #
?> ?>

23
pool/page_ckp.php

@ -35,26 +35,19 @@ function dockp($data, $user)
$pg .= "</tr>\n"; $pg .= "</tr>\n";
if ($ans['STATUS'] == 'ok') if ($ans['STATUS'] == 'ok')
{ {
for ($i = 0; $i < 999; $i++) $count = $ans['rows'];
for ($i = 0; $i < $count; $i++)
{ {
if ($i == 0)
$name = 'stats.name';
else
$name = 'name';
if (!isset($ans[$name.$i]))
break;
if (($i % 2) == 0) if (($i % 2) == 0)
$row = 'even'; $row = 'even';
else else
$row = 'odd'; $row = 'odd';
$pg .= "<tr class=$row>"; $pg .= "<tr class=$row>";
$pg .= '<td class=dl>'.$ans[$name.$i].'</td>'; $pg .= '<td class=dl>'.$ans['name:'.$i].'</td>';
$pg .= '<td class=dr>'.stnum($ans['allocated'.$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['store:'.$i]).'</td>';
$pg .= '<td class=dr>'.stnum($ans['ram'.$i]).'</td>'; $pg .= '<td class=dr>'.stnum($ans['ram:'.$i]).'</td>';
$pg .= "</tr>\n"; $pg .= "</tr>\n";
} }
} }
@ -63,9 +56,9 @@ function dockp($data, $user)
return $pg; return $pg;
} }
# #
function show_ckp($menu, $name, $user) function show_ckp($page, $menu, $name, $user)
{ {
gopage(NULL, 'dockp', $menu, $name, $user); gopage(NULL, 'dockp', $page, $menu, $name, $user);
} }
# #
?> ?>

4
pool/page_help.php

@ -5,9 +5,9 @@ function dohelp($data, $user)
return '<h1>Helpless</h1>Helpless'; return '<h1>Helpless</h1>Helpless';
} }
# #
function show_help($menu, $name, $user) function show_help($page, $menu, $name, $user)
{ {
gopage(NULL, 'dohelp', $menu, $name, $user); gopage(NULL, 'dohelp', $page, $menu, $name, $user);
} }
# #
?> ?>

4
pool/page_index.php

@ -9,9 +9,9 @@ Welcome to CKPool
return $pg; return $pg;
} }
# #
function show_index($menu, $name, $user) function show_index($page, $menu, $name, $user)
{ {
gopage(NULL, 'doindex', $menu, $name, $user); gopage(NULL, 'doindex', $page, $menu, $name, $user);
} }
# #
?> ?>

13
pool/page_payments.php

@ -4,8 +4,7 @@ function dopayments($data, $user)
{ {
$pg = '<h1>Payments</h1>'; $pg = '<h1>Payments</h1>';
$rep = getPayments($user); $ans = getPayments($user);
$ans = repDecode($rep);
$pg .= "<table callpadding=0 cellspacing=0 border=0>\n"; $pg .= "<table callpadding=0 cellspacing=0 border=0>\n";
$pg .= "<tr class=title>"; $pg .= "<tr class=title>";
@ -24,9 +23,9 @@ function dopayments($data, $user)
$row = 'odd'; $row = 'odd';
$pg .= "<tr class=$row>"; $pg .= "<tr class=$row>";
$pg .= '<td class=dl>'.$ans['paydate'.$i].'</td>'; $pg .= '<td class=dl>'.$ans['paydate:'.$i].'</td>';
$pg .= '<td class=dl>'.$ans['payaddress'.$i].'</td>'; $pg .= '<td class=dl>'.$ans['payaddress:'.$i].'</td>';
$pg .= '<td class=dr>'.btcfmt($ans['amount'.$i]).'</td>'; $pg .= '<td class=dr>'.btcfmt($ans['amount:'.$i]).'</td>';
$pg .= "</tr>\n"; $pg .= "</tr>\n";
} }
} }
@ -35,9 +34,9 @@ function dopayments($data, $user)
return $pg; return $pg;
} }
# #
function show_payments($menu, $name, $user) function show_payments($page, $menu, $name, $user)
{ {
gopage(NULL, 'dopayments', $menu, $name, $user); gopage(NULL, 'dopayments', $page, $menu, $name, $user);
} }
# #
?> ?>

4
pool/page_payout.php

@ -22,9 +22,9 @@ A flat rate of 0.5% is reserved for further development, with an initial focus o
return $pg; return $pg;
} }
# #
function show_payout($menu, $name, $user) function show_payout($page, $menu, $name, $user)
{ {
gopage(NULL, 'dopayout', $menu, $name, $user); gopage(NULL, 'dopayout', $page, $menu, $name, $user);
} }
# #
?> ?>

14
pool/page_pplns.php

@ -23,9 +23,7 @@ function dopplns($data, $user)
$blk = getparam('blk', true); $blk = getparam('blk', true);
if (nuem($blk)) if (nuem($blk))
{ {
$pg = "<br> $pg = '<br>'.makeForm('pplns')."
<form action=index.php method=POST>
<input type=hidden name=k value=pplns>
Block: <input type=text name=blk size=10 value=''> Block: <input type=text name=blk size=10 value=''>
&nbsp;<input type=submit name=Calc value=Calc> &nbsp;<input type=submit name=Calc value=Calc>
</form>"; </form>";
@ -100,9 +98,9 @@ Block: <input type=text name=blk size=10 value=''>
$reward = $ans['block_reward'] / pow(10,8); $reward = $ans['block_reward'] / pow(10,8);
$elapsed = $ans['pplns_elapsed']; $elapsed = $ans['pplns_elapsed'];
$count = $ans['rows']; $count = $ans['rows'];
for ($i = 1; $i <= $count; $i++) for ($i = 0; $i < $count; $i++)
{ {
$diffacc_user = $ans['diffacc_user'.$i]; $diffacc_user = $ans['diffacc_user:'.$i];
$diffacc_percent = number_format(100.0 * $diffacc_user / $diffacc_total, 2).'%'; $diffacc_percent = number_format(100.0 * $diffacc_user / $diffacc_total, 2).'%';
$diffacc_btc = number_format($reward * $diffacc_user / $diffacc_total, 8); $diffacc_btc = number_format($reward * $diffacc_user / $diffacc_total, 8);
$avg_hash = number_format($diffacc_user / $elapsed * pow(2,32), 0); $avg_hash = number_format($diffacc_user / $elapsed * pow(2,32), 0);
@ -113,7 +111,7 @@ Block: <input type=text name=blk size=10 value=''>
$row = 'odd'; $row = 'odd';
$pg .= "<tr class=$row>"; $pg .= "<tr class=$row>";
$pg .= '<td class=dl>'.$ans['user'.$i].'</td>'; $pg .= '<td class=dl>'.$ans['user:'.$i].'</td>';
$pg .= "<td class=dr>$diffacc_user</td>"; $pg .= "<td class=dr>$diffacc_user</td>";
$pg .= "<td class=dr>$diffacc_percent</td>"; $pg .= "<td class=dr>$diffacc_percent</td>";
$pg .= "<td class=dr>$diffacc_btc</td>"; $pg .= "<td class=dr>$diffacc_btc</td>";
@ -126,9 +124,9 @@ Block: <input type=text name=blk size=10 value=''>
return $pg; return $pg;
} }
# #
function show_pplns($menu, $name, $user) function show_pplns($page, $menu, $name, $user)
{ {
gopage(NULL, 'dopplns', $menu, $name, $user); gopage(NULL, 'dopplns', $page, $menu, $name, $user);
} }
# #
?> ?>

51
pool/page_reg.php

@ -17,8 +17,8 @@ function doreg($data, $u)
$pg = '<h1>Register</h1>'; $pg = '<h1>Register</h1>';
if (isset($data['error'])) if (isset($data['error']))
$pg .= "<br><b>".$data['error']." - please try again</b><br><br>"; $pg .= "<br><b>".$data['error']." - please try again</b><br><br>";
$pg .= makeForm('');
$pg .= " $pg .= "
<form action=index.php method=POST>
<table> <table>
<tr><td class=dr>Username:</td> <tr><td class=dr>Username:</td>
<td class=dl><input name=user value=\"$user\"></td></tr> <td class=dl><input name=user value=\"$user\"></td></tr>
@ -53,35 +53,7 @@ function doreg2($data)
return $pg; return $pg;
} }
# #
function safepass($pass) function show_reg($page, $menu, $name, $u)
{
if (strlen($pass) < 6)
return false;
# Invalid characters
$p2 = preg_replace('/[\011]/', '', $pass);
if ($p2 != $pass)
return false;
# At least one lowercase
$p2 = preg_replace('/[a-z]/', '', $pass);
if ($p2 == $pass)
return false;
# At least one uppercase
$p2 = preg_replace('/[A-Z]/', '', $pass);
if ($p2 == $pass)
return false;
# At least one digit
$p2 = preg_replace('/[0-9]/', '', $pass);
if ($p2 == $pass)
return false;
return true;
}
#
function show_reg($menu, $name, $u)
{ {
$user = getparam('user', false); $user = getparam('user', false);
$mail = trim(getparam('mail', false)); $mail = trim(getparam('mail', false));
@ -118,7 +90,7 @@ function show_reg($menu, $name, $u)
} }
$orig = $user; $orig = $user;
$user = preg_replace('/[\._\/\011]/', '', $orig); $user = loginStr($orig);
if ($user != $orig) if ($user != $orig)
{ {
$ok = false; $ok = false;
@ -129,23 +101,14 @@ function show_reg($menu, $name, $u)
if ($ok === true) if ($ok === true)
{ {
$passhash = myhash($pass); $ans = userReg($user, $mail, $pass);
$flds = array('username' => $user,
'emailaddress' => $mail,
'passwordhash' => $passhash);
$msg = msgEncode('adduser', 'reg', $flds);
$rep = sendsockreply('show_reg', $msg);
if (!$rep)
dbdown();
$ans = repDecode($rep);
if ($ans['STATUS'] == 'ok') if ($ans['STATUS'] == 'ok')
gopage($data, 'doreg2', $menu, $name, $u, true, true, false); gopage($data, 'doreg2', $page, $menu, $name, $u, true, true, false);
else else
$data['error'] = "Invalid details"; $data['error'] = "Invalid username, password or email address";
} }
gopage($data, 'doreg', $menu, $name, $u, true, true, false); gopage($data, 'doreg', $page, $menu, $name, $u, true, true, false);
} }
# #
?> ?>

155
pool/page_settings.php

@ -0,0 +1,155 @@
<?php
#
function settings($data, $user, $email, $addr, $err)
{
$pg = '<h1>Account Settings</h1>';
if ($err != '')
$pg .= "<span class=err>$err<br><br></span>";
$pg .= '<table cellpadding=20 cellspacing=0 border=1>';
$pg .= '<tr class=dc><td><center>';
$pg .= makeForm('settings');
$pg .= '<table cellpadding=5 cellspacing=0 border=0>';
$pg .= '<tr class=dc><td class=dr colspan=2>';
$pg .= 'To change your email, enter a new email address and your password';
$pg .= '</td></tr>';
$pg .= '<tr class=dc><td class=dr>';
$pg .= 'EMail:';
$pg .= '</td><td class=dl>';
$pg .= "<input type=text name=email value='$email' size=20>";
$pg .= '</td></tr>';
$pg .= '<tr class=dc><td class=dr>';
$pg .= 'Password:';
$pg .= '</td><td class=dl>';
$pg .= '<input type=password name=pass size=20>';
$pg .= '</td></tr>';
$pg .= '<tr class=dc><td class=dr colspan=2>';
$pg .= 'Change: <input type=submit name=Change value=EMail>';
$pg .= '</td></tr>';
$pg .= '</table></form>';
$pg .= '</center></td></tr>';
$pg .= '<tr class=dc><td><center>';
$pg .= makeForm('settings');
$pg .= '<table cellpadding=5 cellspacing=0 border=0>';
$pg .= '<tr class=dc><td class=dr colspan=2>';
$pg .= 'To change your payout address, enter a new address and your password';
$pg .= '</td></tr>';
$pg .= '<tr class=dc><td class=dr>';
$pg .= 'BTC Address:';
$pg .= '</td><td class=dl>';
$pg .= "<input type=text name=baddr value='$addr' size=42>";
$pg .= '</td></tr>';
$pg .= '<tr class=dc><td class=dr>';
$pg .= 'Password:';
$pg .= '</td><td class=dl>';
$pg .= '<input type=password name=pass size=20>';
$pg .= '</td></tr>';
$pg .= '<tr class=dc><td class=dr colspan=2>';
$pg .= 'Change: <input type=submit name=Change value=Address>';
$pg .= '</td></tr>';
$pg .= '</table></form>';
$pg .= '</center></td></tr>';
$pg .= '<tr class=dc><td><center>';
$pg .= makeForm('settings');
$pg .= '<table cellpadding=5 cellspacing=0 border=0>';
$pg .= '<tr class=dc><td class=dr colspan=2>';
$pg .= 'To change your password, enter your old password and new password twice';
$pg .= '</td></tr>';
$pg .= '<tr class=dc><td class=dr nowrap>';
$pg .= 'Old Password:';
$pg .= '</td><td class=dl>';
$pg .= "<input type=password name=oldpass size=20>";
$pg .= '</td></tr>';
$pg .= '<tr class=dc><td class=dr nowrap>';
$pg .= 'New Password:';
$pg .= '</td><td class=dl>';
$pg .= '<input type=password name=pass1 size=20>';
$pg .= '</td></tr>';
$pg .= '<tr class=dc><td class=dr nowrap>';
$pg .= 'New Password again:';
$pg .= '</td><td class=dl>';
$pg .= '<input type=password name=pass2 size=20>';
$pg .= '</td></tr>';
$pg .= '<tr class=dc><td class=dr colspan=2>';
$pg .= 'Change: <input type=submit name=Change value=Password>';
$pg .= '</td></tr>';
$pg .= '</table></form>';
$pg .= '</center></td></tr>';
$pg .= '</table>';
return $pg;
}
#
function dosettings($data, $user)
{
$err = '';
$chg = getparam('Change', false);
$check = false;
switch ($chg)
{
case 'EMail':
$email = getparam('email', false);
$pass = getparam('pass', false);
$ans = userSettings($user, $email, null, $pass);
$check = true;
break;
case 'Address':
$addr = getparam('baddr', false);
$pass = getparam('pass', false);
$ans = userSettings($user, null, $addr, $pass);
$check = true;
break;
case 'Password':
$oldpass = getparam('oldpass', false);
$pass1 = getparam('pass1', false);
$pass2 = getparam('pass2', false);
if (!safepass($pass1))
{
$err = "Password is unsafe - requires 6 or more characters, including<br>" .
"at least one of each uppercase, lowercase and digits, but not Tab";
}
elseif ($pass1 != $pass2)
$err = "Passwords don't match";
else
{
$ans = setPass($user, $oldpass, $pass1);
$err = 'Password changed';
$check = true;
}
break;
}
if ($check === true)
if ($ans['STATUS'] != 'ok')
{
$err = $ans['STATUS'];
if ($ans['ERROR'] != '')
$err .= ': '.$ans['ERROR'];
}
$ans = userSettings($user);
if ($ans['STATUS'] != 'ok')
dbdown(); // Should be no other reason?
if (isset($ans['email']))
$email = $ans['email'];
else
$email = '';
if (isset($ans['addr']))
$addr = $ans['addr'];
else
$addr = '';
$pg = settings($data, $user, $email, $addr, $err);
return $pg;
}
#
function show_settings($page, $menu, $name, $user)
{
gopage(NULL, 'dosettings', $page, $menu, $name, $user);
}
#
?>

13
pool/page_stats.php

@ -12,8 +12,7 @@ function dostats($data, $user)
{ {
$pg = '<h1>Pool Stats</h1>'; $pg = '<h1>Pool Stats</h1>';
$rep = getAllUsers(); $ans = getAllUsers();
$ans = repDecode($rep);
$pg .= "<table callpadding=0 cellspacing=0 border=0>\n"; $pg .= "<table callpadding=0 cellspacing=0 border=0>\n";
$pg .= "<tr class=title>"; $pg .= "<tr class=title>";
@ -26,9 +25,9 @@ function dostats($data, $user)
$count = $ans['rows']; $count = $ans['rows'];
for ($i = 0; $i < $count; $i++) for ($i = 0; $i < $count; $i++)
{ {
$all[] = array('username' => $ans['username'.$i], $all[] = array('username' => $ans['username:'.$i],
'userid' => $ans['userid'.$i], 'userid' => $ans['userid:'.$i],
'u_hashrate5m' => $ans['u_hashrate5m'.$i]); 'u_hashrate5m' => $ans['u_hashrate5m:'.$i]);
} }
usort($all, 'allusersort'); usort($all, 'allusersort');
@ -66,9 +65,9 @@ function dostats($data, $user)
return $pg; return $pg;
} }
# #
function show_stats($menu, $name, $user) function show_stats($page, $menu, $name, $user)
{ {
gopage(NULL, 'dostats', $menu, $name, $user); gopage(NULL, 'dostats', $page, $menu, $name, $user);
} }
# #
?> ?>

27
pool/page_workers.php

@ -4,8 +4,7 @@ function doworker($data, $user)
{ {
$pg = '<h1>Workers</h1>'; $pg = '<h1>Workers</h1>';
$rep = getWorkers($user); $ans = getWorkers($user);
$ans = repDecode($rep);
$pg .= "<table callpadding=0 cellspacing=0 border=0>\n"; $pg .= "<table callpadding=0 cellspacing=0 border=0>\n";
$pg .= "<tr class=title>"; $pg .= "<tr class=title>";
@ -29,10 +28,10 @@ function doworker($data, $user)
$row = 'odd'; $row = 'odd';
$pg .= "<tr class=$row>"; $pg .= "<tr class=$row>";
$pg .= '<td class=dl>'.$ans['workername'.$i].'</td>'; $pg .= '<td class=dl>'.$ans['workername:'.$i].'</td>';
/* /*
$pg .= '<td class=dr>'.$ans['difficultydefault'.$i].'</td>'; $pg .= '<td class=dr>'.$ans['difficultydefault:'.$i].'</td>';
$nots = $ans['idlenotificationenabled'.$i]; $nots = $ans['idlenotificationenabled:'.$i];
switch ($nots) switch ($nots)
{ {
case 'Y': case 'Y':
@ -43,14 +42,14 @@ function doworker($data, $user)
$nots = 'N'; $nots = 'N';
} }
$pg .= '<td class=dc>'.$nots.'</td>'; $pg .= '<td class=dc>'.$nots.'</td>';
$pg .= '<td class=dr>'.$ans['idlenotificationtime'.$i].'</td>'; $pg .= '<td class=dr>'.$ans['idlenotificationtime:'.$i].'</td>';
*/ */
if ($ans['w_lastdiff'.$i] > 0) if ($ans['w_lastdiff:'.$i] > 0)
$ld = difffmt($ans['w_lastdiff'.$i]); $ld = difffmt($ans['w_lastdiff:'.$i]);
else else
$ld = '&nbsp;'; $ld = '&nbsp;';
$pg .= "<td class=dr>$ld</td>"; $pg .= "<td class=dr>$ld</td>";
$lst = $ans['STAMP'] - $ans['w_lastshare'.$i]; $lst = $ans['STAMP'] - $ans['w_lastshare:'.$i];
if ($lst < 60) if ($lst < 60)
$lstdes = $lst.'s'; $lstdes = $lst.'s';
else else
@ -82,10 +81,10 @@ function doworker($data, $user)
} }
} }
$pg .= "<td class=dr>$lstdes</td>"; $pg .= "<td class=dr>$lstdes</td>";
if ($ans['w_elapsed'.$i] > 3600) if ($ans['w_elapsed:'.$i] > 3600)
$uhr = $ans['w_hashrate1hr'.$i]; $uhr = $ans['w_hashrate1hr:'.$i];
else else
$uhr = $ans['w_hashrate5m'.$i]; $uhr = $ans['w_hashrate5m:'.$i];
if ($uhr == '?') if ($uhr == '?')
$uhr = '?GHs'; $uhr = '?GHs';
else else
@ -132,9 +131,9 @@ function doworkers($data, $user)
return $pg; return $pg;
} }
# #
function show_workers($menu, $name, $user) function show_workers($page, $menu, $name, $user)
{ {
gopage(NULL, 'doworkers', $menu, $name, $user); gopage(NULL, 'doworkers', $page, $menu, $name, $user);
} }
# #
?> ?>

1
sql/initid.sh

@ -34,3 +34,4 @@ addid paymentid ${now}200000
addid authid ${now}300000 addid authid ${now}300000
addid userid ${now}400000 addid userid ${now}400000
addid markerid ${now}500000 addid markerid ${now}500000
addid paymentaddressid ${now}600000

2583
src/ckdb.c

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save