Browse Source

ckdb/php - selectively support multiple payout addresses - still needs pplns changes

master
kanoi 10 years ago
parent
commit
573285dd7e
  1. 14
      pool/base.php
  2. 3
      pool/page.php
  3. 133
      pool/page_addrmgt.php
  4. 4
      pool/page_allwork.php
  5. 29
      pool/page_api.php
  6. 4
      pool/page_blocks.php
  7. 4
      pool/page_ckp.php
  8. 4
      pool/page_help.php
  9. 4
      pool/page_index.php
  10. 4
      pool/page_payments.php
  11. 4
      pool/page_payout.php
  12. 4
      pool/page_pblocks.php
  13. 4
      pool/page_pplns.php
  14. 18
      pool/page_reg.php
  15. 4
      pool/page_reset.php
  16. 10
      pool/page_settings.php
  17. 4
      pool/page_stats.php
  18. 4
      pool/page_userset.php
  19. 4
      pool/page_workers.php
  20. 4
      pool/page_workmgt.php
  21. 14
      pool/prime.php
  22. 2
      src/ckdb.h
  23. 46
      src/ckdb_cmd.c

14
pool/base.php

@ -238,7 +238,7 @@ function dbd($data, $user)
#
function dbdown()
{
gopage(NULL, 'dbd', 'dbd', def_menu(), '', '', true, false, false);
gopage(NULL, NULL, 'dbd', 'dbd', def_menu(), '', '', true, false, false);
}
#
function syse($data, $user)
@ -248,7 +248,7 @@ function syse($data, $user)
#
function syserror()
{
gopage(NULL, 'syse', 'syse', def_menu(), '', '', true, false, false);
gopage(NULL, NULL, 'syse', 'syse', def_menu(), '', '', true, false, false);
}
#
function f404($data)
@ -258,10 +258,10 @@ function f404($data)
#
function do404()
{
gopage(NULL, 'f404', 'f404', def_menu(), '', '', true, false, false);
gopage(NULL, NULL, 'f404', 'f404', def_menu(), '', '', true, false, false);
}
#
function showPage($page, $menu, $name, $user)
function showPage($info, $page, $menu, $name, $user)
{
# If you are doing development, use without '@'
# Then switch to '@' when finished
@ -270,14 +270,14 @@ function showPage($page, $menu, $name, $user)
$fun = 'show_' . $page;
if (function_exists($fun))
$fun($page, $menu, $name, $user);
$fun($info, $page, $menu, $name, $user);
else
do404();
}
#
function showIndex()
{
showPage('index', def_menu(), '', false);
showPage(NULL, 'index', def_menu(), '', false);
}
#
function offline()
@ -286,7 +286,7 @@ function offline()
{
$ip = $_SERVER['REMOTE_ADDR'];
if ($ip != '192.168.1.666')
gopage(NULL, file_get_contents('./maintenance.txt'),
gopage(NULL, NULL, file_get_contents('./maintenance.txt'),
'offline', NULL, '', '', false, false, false);
}
}

3
pool/page.php

@ -436,7 +436,7 @@ function pgfoot()
return $foot;
}
#
function gopage($data, $pagefun, $page, $menu, $name, $user, $ispage = true, $dotop = true, $douser = true)
function gopage($info, $data, $pagefun, $page, $menu, $name, $user, $ispage = true, $dotop = true, $douser = true)
{
global $dbg, $stt;
global $page_scripts;
@ -449,6 +449,7 @@ function gopage($data, $pagefun, $page, $menu, $name, $user, $ispage = true, $do
else
$pg = '';
if ($info === NULL)
$info = homeInfo($user);
if ($ispage == true)

133
pool/page_addrmgt.php

@ -0,0 +1,133 @@
<?php
#
function addrmgtuser($data, $user, $err)
{
$pg = '<h1>Address Management</h1>';
if ($err != '')
$pg .= "<span class=err>$err<br><br></span>";
$pg .= makeForm('addrmgt');
$pg .= "<table callpadding=0 cellspacing=0 border=0>\n";
$pg .= '<tr class=title>';
$pg .= '<td class=dl>Address</td>';
$pg .= '<td class=dr>Ratio</td>';
$pg .= '<td class=dr>%</td>';
$pg .= '</tr>';
$ans = userSettings($user);
$offset = 0;
$count = 0;
if ($ans['STATUS'] == 'ok')
{
$count = $ans['rows'];
for ($i = 0; $i < $count; $i++)
{
if ((($offset) % 2) == 0)
$row = 'even';
else
$row = 'odd';
$pg .= "<tr class=$row";
if ($i == 0)
$pg .= ' id=bs';
$pg .= '>';
$addr = $ans['addr:'.$i];
$pg .= '<td class=dl>';
$pg .= "<input type=text size=42 name='addr:$i' value='$addr'>";
$pg .= '</td>';
$ratio = intval($ans['ratio:'.$i]);
$pg .= '<td class=dr>';
$pg .= "<input type=text size=6 name='ratio:$i' value='$ratio' id=rat$i onchange='repc()'>";
$pg .= '</td>';
$pg .= '<td class=dr>';
$pg .= "<span id=per$i>%</span>";
$pg .= '</td>';
$pg .= "</tr>\n";
$offset++;
}
if ((($offset++) % 2) == 0)
$row = 'even';
else
$row = 'odd';
$pg .= "<tr class=$row id=plus>";
$pg .= '<td colspan=3 class=dl>';
$pg .= "<input type=button value='+' onclick='return adrw();'>";
$pg .= '</td></tr>';
if ((($offset++) % 2) == 0)
$row = 'even';
else
$row = 'odd';
$pg .= "<tr class=$row>";
$pg .= '<td colspan=3 class=dc>';
$pg .= 'Password: <input type=password name=pass size=20>';
$pg .= '&nbsp;<input type=submit name=OK value=OK></td></tr>';
}
$pg .= '<tr><td colspan=3 class=dc><font size=-1><span class=st1>*</span>';
$pg .= ' You must enter your password<br>';
$pg .= 'A ratio of 0, will remove the address from the payouts</font></td></tr>';
$pg .= "</table><input type=hidden name=rows value=$count id=rows></form>\n";
$pg .= "<script type='text/javascript'>\n";
$pg .= "function adrw(){var p=document.getElementById('plus');";
$pg .= "var r=document.getElementById('rows');var c=parseInt(r.value);";
$pg .= "var bs=document.getElementById('bs');var n=bs.cloneNode(true);";
$pg .= "var ia=n.childNodes[0].firstChild;ia.name='addr:'+c;ia.value='';";
$pg .= "var ir=n.childNodes[1].firstChild;ir.id='rat'+c;ir.name='ratio:'+c;ir.value='0';";
$pg .= "var ip=n.childNodes[2].firstChild;ip.id='per'+c;ip.innerHTML='0.00%';";
$pg .= "p.parentNode.insertBefore(n, p);";
$pg .= "c++;r.value=c;return true}\n";
$pg .= "function repc(){var c=parseInt(document.getElementById('rows').value);";
$pg .= "if(!isNaN(c)&&c>0&&c<1000){var v=[],tot=0;for(i=0;i<c;i++){";
$pg .= "var o=document.getElementById('rat'+i);var ov=parseInt(o.value);if(!isNaN(ov)&&ov>0)";
$pg .= "{tot+=ov;v[i]=ov}else{o.value='0';v[i]=0}";
$pg .= "}for(i=0;i<c;i++){var p;var r=document.getElementById('per'+i);if(tot<=0)";
$pg .= "{p=0}else{p=v[i]*100/tot};r.innerHTML=p.toFixed(2)+'%';";
$pg .= "}}};\nrepc();</script>";
return $pg;
}
#
function doaddrmgt($data, $user)
{
$err = '';
$OK = getparam('OK', false);
$count = getparam('rows', false);
$pass = getparam('pass', false);
if ($OK == 'OK' && !nuem($count) && !nuem($pass))
{
if ($count > 0 && $count < 1000)
{
$addrarr = array();
for ($i = 0; $i < $count; $i++)
{
$addr = getparam('addr:'.$i, false);
$ratio = getparam('ratio:'.$i, false);
if (!nuem($addr) && !nuem($ratio))
$addrarr[] = array('addr' => $addr, 'ratio' => $ratio);
}
$ans = userSettings($user, null, $addrarr, $pass);
if ($ans['STATUS'] != 'ok')
$err = $ans['ERROR'];
#$err = print_r($addrarr, true).$pass;
}
}
$pg = addrmgtuser($data, $user, $err);
return $pg;
}
#
function show_addrmgt($info, $page, $menu, $name, $user)
{
gopage($info, NULL, 'doaddrmgt', $page, $menu, $name, $user);
}
#
?>

4
pool/page_allwork.php

@ -39,9 +39,9 @@ function doallwork($data, $user)
return $pg;
}
#
function show_allwork($page, $menu, $name, $user)
function show_allwork($info, $page, $menu, $name, $user)
{
gopage(NULL, 'doallwork', $page, $menu, $name, $user);
gopage($info, NULL, 'doallwork', $page, $menu, $name, $user);
}
#
?>

29
pool/page_api.php

@ -9,7 +9,7 @@ function no_api($json = "")
exit(0);
}
#
function show_api($page, $menu, $name, $user)
function show_api($info, $page, $menu, $name, $user)
{
global $fld_sep;
$u = getparam('username', true);
@ -29,20 +29,21 @@ function show_api($page, $menu, $name, $user)
no_api($jfu);
if (nuem($work))
{
$ans = homeInfo($u);
if ($ans === false)
if ($info === NULL)
$info = homeInfo($u);
if ($info === false)
no_api($jfu);
$rep = fldEncode($ans, 'lastbc', true);
$rep .= fldEncode($ans, 'lastheight', false);
$rep .= fldEncode($ans, 'currndiff', false);
$rep .= fldEncode($ans, 'lastblock', false);
$rep .= fldEncode($ans, 'lastblockheight', false);
$rep .= fldEncode($ans, 'blockacc', false);
$rep .= fldEncode($ans, 'blockerr', false);
$rep .= fldEncode($ans, 'p_hashrate5m', false);
$rep .= fldEncode($ans, 'p_hashrate1hr', false);
$rep .= fldEncode($ans, 'u_hashrate5m', false);
$rep .= fldEncode($ans, 'u_hashrate1hr', false);
$rep = fldEncode($info, 'lastbc', true);
$rep .= fldEncode($info, 'lastheight', false);
$rep .= fldEncode($info, 'currndiff', false);
$rep .= fldEncode($info, 'lastblock', false);
$rep .= fldEncode($info, 'lastblockheight', false);
$rep .= fldEncode($info, 'blockacc', false);
$rep .= fldEncode($info, 'blockerr', false);
$rep .= fldEncode($info, 'p_hashrate5m', false);
$rep .= fldEncode($info, 'p_hashrate1hr', false);
$rep .= fldEncode($info, 'u_hashrate5m', false);
$rep .= fldEncode($info, 'u_hashrate1hr', false);
}
else
{

4
pool/page_blocks.php

@ -182,9 +182,9 @@ function doblocks($data, $user)
return $pg;
}
#
function show_blocks($page, $menu, $name, $user)
function show_blocks($info, $page, $menu, $name, $user)
{
gopage(NULL, 'doblocks', $page, $menu, $name, $user);
gopage($info, NULL, 'doblocks', $page, $menu, $name, $user);
}
#
?>

4
pool/page_ckp.php

@ -62,9 +62,9 @@ function dockp($data, $user)
return $pg;
}
#
function show_ckp($page, $menu, $name, $user)
function show_ckp($info, $page, $menu, $name, $user)
{
gopage(NULL, 'dockp', $page, $menu, $name, $user);
gopage($info, NULL, 'dockp', $page, $menu, $name, $user);
}
#
?>

4
pool/page_help.php

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

4
pool/page_index.php

@ -2,9 +2,9 @@
#
@include_once('myindex.php');
#
function show_index($page, $menu, $name, $user)
function show_index($info, $page, $menu, $name, $user)
{
gopage(NULL, 'doindex', $page, $menu, $name, $user);
gopage($info, NULL, 'doindex', $page, $menu, $name, $user);
}
#
?>

4
pool/page_payments.php

@ -34,9 +34,9 @@ function dopayments($data, $user)
return $pg;
}
#
function show_payments($page, $menu, $name, $user)
function show_payments($info, $page, $menu, $name, $user)
{
gopage(NULL, 'dopayments', $page, $menu, $name, $user);
gopage($info, NULL, 'dopayments', $page, $menu, $name, $user);
}
#
?>

4
pool/page_payout.php

@ -13,9 +13,9 @@ function dopayout($data, $user)
return $pg;
}
#
function show_payout($page, $menu, $name, $user)
function show_payout($info, $page, $menu, $name, $user)
{
gopage(NULL, 'dopayout', $page, $menu, $name, $user);
gopage($info, NULL, 'dopayout', $page, $menu, $name, $user);
}
#
?>

4
pool/page_pblocks.php

@ -7,9 +7,9 @@ function dopblocks($data, $user)
return doblocks($data, null);
}
#
function show_pblocks($page, $menu, $name, $user)
function show_pblocks($info, $page, $menu, $name, $user)
{
gopage(NULL, 'dopblocks', $page, $menu, $name, $user);
gopage($info, NULL, 'dopblocks', $page, $menu, $name, $user);
}
#
?>

4
pool/page_pplns.php

@ -281,9 +281,9 @@ Block: <input type=text name=blk size=10 value='$blkuse'>
return $pg;
}
#
function show_pplns($page, $menu, $name, $user)
function show_pplns($info, $page, $menu, $name, $user)
{
gopage(NULL, 'dopplns', $page, $menu, $name, $user);
gopage($info, NULL, 'dopplns', $page, $menu, $name, $user);
}
#
?>

18
pool/page_reg.php

@ -79,7 +79,7 @@ function doreg2($data)
return $pg;
}
#
function try_reg($page, $menu, $name, $u)
function try_reg($info, $page, $menu, $name, $u)
{
$user = getparam('user', false);
$mail = trim(getparam('mail', false));
@ -128,12 +128,12 @@ function try_reg($page, $menu, $name, $u)
{
$ans = userReg($user, $mail, $pass);
if ($ans['STATUS'] == 'ok')
gopage($data, 'doreg2', $page, $menu, $name, $u, true, true, false);
gopage($info, $data, 'doreg2', $page, $menu, $name, $u, true, true, false);
else
$data['error'] = "Invalid username, password or email address";
}
gopage($data, 'doregres', $page, $menu, $name, $u, true, true, false);
gopage($info, $data, 'doregres', $page, $menu, $name, $u, true, true, false);
}
#
function doreset2($data)
@ -179,7 +179,7 @@ function doreset2($data)
return $pg;
}
#
function try_reset($page, $menu, $name, $u)
function try_reset($info, $page, $menu, $name, $u)
{
$user = getparam('user', false);
$mail = trim(getparam('mail', false));
@ -199,20 +199,20 @@ function try_reset($page, $menu, $name, $u)
{
$data = array('user' => $user, 'email' => $mail);
gopage($data, 'doreset2', $page, $menu, $name, $u, true, true, false);
gopage($info, $data, 'doreset2', $page, $menu, $name, $u, true, true, false);
}
}
gopage($data, 'doregres', $page, $menu, $name, $u, true, true, false);
gopage($info, $data, 'doregres', $page, $menu, $name, $u, true, true, false);
}
#
function show_reg($page, $menu, $name, $u)
function show_reg($info, $page, $menu, $name, $u)
{
$reg = getparam('Register', false);
if ($reg !== NULL)
try_reg($page, $menu, $name, $u);
try_reg($info, $page, $menu, $name, $u);
else
try_reset($page, $menu, $name, $u);
try_reset($info, $page, $menu, $name, $u);
}
#
?>

4
pool/page_reset.php

@ -158,9 +158,9 @@ function doreset($data, $u)
return resetfail();
}
#
function show_reset($page, $menu, $name, $u)
function show_reset($info, $page, $menu, $name, $u)
{
gopage(array(), 'doreset', $page, $menu, $name, $u, true, true, false);
gopage($info, array(), 'doreset', $page, $menu, $name, $u, true, true, false);
}
#
?>

10
pool/page_settings.php

@ -33,6 +33,8 @@ function settings($data, $user, $email, $addr, $err)
$pg .= '</center></td></tr>';
$pg .= '<tr class=dc><td><center>';
if (!isset($data['info']['u_multiaddr']))
{
$pg .= makeForm('settings');
$pg .= '<table cellpadding=5 cellspacing=0 border=0>';
$pg .= '<tr class=dc><td class=dr colspan=2>';
@ -55,6 +57,7 @@ function settings($data, $user, $email, $addr, $err)
$pg .= '</center></td></tr>';
$pg .= '<tr class=dc><td><center>';
}
$pg .= makeForm('settings');
$pg .= '<table cellpadding=5 cellspacing=0 border=0>';
@ -101,11 +104,14 @@ function dosettings($data, $user)
$check = true;
break;
case 'Address':
if (!isset($data['info']['u_multiaddr']))
{
$addr = getparam('baddr', false);
$addrarr = array(array('addr' => $addr));
$pass = getparam('pass', false);
$ans = userSettings($user, null, $addrarr, $pass);
$check = true;
}
break;
case 'Password':
$oldpass = getparam('oldpass', false);
@ -149,9 +155,9 @@ function dosettings($data, $user)
return $pg;
}
#
function show_settings($page, $menu, $name, $user)
function show_settings($info, $page, $menu, $name, $user)
{
gopage(NULL, 'dosettings', $page, $menu, $name, $user);
gopage($info, NULL, 'dosettings', $page, $menu, $name, $user);
}
#
?>

4
pool/page_stats.php

@ -99,9 +99,9 @@ function dostats($data, $user)
return $pg;
}
#
function show_stats($page, $menu, $name, $user)
function show_stats($info, $page, $menu, $name, $user)
{
gopage(NULL, 'dostats', $page, $menu, $name, $user);
gopage($info, NULL, 'dostats', $page, $menu, $name, $user);
}
#
?>

4
pool/page_userset.php

@ -92,9 +92,9 @@ function douserset($data, $user)
return $pg;
}
#
function show_userset($page, $menu, $name, $user)
function show_userset($info, $page, $menu, $name, $user)
{
gopage(NULL, 'douserset', $page, $menu, $name, $user);
gopage($info, NULL, 'douserset', $page, $menu, $name, $user);
}
#
?>

4
pool/page_workers.php

@ -188,9 +188,9 @@ function doworkers($data, $user)
return $pg;
}
#
function show_workers($page, $menu, $name, $user)
function show_workers($info, $page, $menu, $name, $user)
{
gopage(NULL, 'doworkers', $page, $menu, $name, $user);
gopage($info, NULL, 'doworkers', $page, $menu, $name, $user);
}
#
?>

4
pool/page_workmgt.php

@ -86,9 +86,9 @@ function doworkmgt($data, $user)
return $pg;
}
#
function show_workmgt($page, $menu, $name, $user)
function show_workmgt($info, $page, $menu, $name, $user)
{
gopage(NULL, 'doworkmgt', $page, $menu, $name, $user);
gopage($info, NULL, 'doworkmgt', $page, $menu, $name, $user);
}
#
?>

14
pool/prime.php

@ -8,6 +8,12 @@ include_once('base.php');
#
function process($p, $user, $menu)
{
$info = homeInfo($user);
if (is_array($info) && isset($info['u_multiaddr']))
{
if (isset($menu['Account']))
$menu['Account']['Addresses'] = 'addrmgt';
}
if ($user == 'Kano' || $user == 'ckolivas' || $user == 'wvr2' || $user == 'aphorise')
{
$menu['Admin']['ckp'] = 'ckp';
@ -26,9 +32,9 @@ function process($p, $user, $menu)
}
if ($page === '')
showPage('index', $menu, '', $user);
showPage($info, 'index', $menu, '', $user);
else
showPage($page, $menu, $n, $user);
showPage($info, $page, $menu, $n, $user);
}
#
function def_menu()
@ -80,11 +86,11 @@ function check()
{
$p = getparam('k', true);
if ($p == 'reset')
showPage('reset', $dmenu, '', $who);
showPage(NULL, 'reset', $dmenu, '', $who);
else
{
if (requestRegister() == true)
showPage('reg', $dmenu, '', $who);
showPage(NULL, 'reg', $dmenu, '', $who);
else
{
$p = getparam('k', true);

2
src/ckdb.h

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

46
src/ckdb_cmd.c

@ -163,11 +163,11 @@ static char *cmd_userset(PGconn *conn, char *cmd, char *id,
{
K_ITEM *i_username, *i_passwordhash, *i_rows, *i_address, *i_ratio;
K_ITEM *i_email, *u_item, *pa_item;
char *email;
char *email, *address;
char reply[1024] = "";
size_t siz = sizeof(reply);
char tmp[1024];
PAYMENTADDRESSES *paymentaddresses;
PAYMENTADDRESSES *row;
K_STORE *pa_store = NULL;
K_TREE_CTX ctx[1];
USERS *users;
@ -212,26 +212,24 @@ static char *cmd_userset(PGconn *conn, char *cmd, char *id,
K_RLOCK(paymentaddresses_free);
pa_item = find_paymentaddresses(users->userid, ctx);
rows = 0;
if (pa_item) {
DATA_PAYMENTADDRESSES(paymentaddresses, pa_item);
while (pa_item && CURRENT(&(paymentaddresses->expirydate)) &&
paymentaddresses->userid == users->userid) {
DATA_PAYMENTADDRESSES(row, pa_item);
while (pa_item && CURRENT(&(row->expirydate)) &&
row->userid == users->userid) {
snprintf(tmp, sizeof(tmp), "addr:%d=%s%c",
rows, paymentaddresses->payaddress, FLDSEP);
rows, row->payaddress, FLDSEP);
APPEND_REALLOC(answer, off, len, tmp);
snprintf(tmp, sizeof(tmp), "ratio:%d=%d%c",
rows, paymentaddresses->payratio, FLDSEP);
rows, row->payratio, FLDSEP);
APPEND_REALLOC(answer, off, len, tmp);
rows++;
pa_item = prev_in_ktree(ctx);
DATA_PAYMENTADDRESSES_NULL(paymentaddresses, pa_item);
DATA_PAYMENTADDRESSES_NULL(row, pa_item);
}
K_RUNLOCK(paymentaddresses_free);
} else {
K_RUNLOCK(paymentaddresses_free);
rows = 0;
}
K_RUNLOCK(paymentaddresses_free);
snprintf(tmp, sizeof(tmp), "rows=%d%cflds=%s%c",
rows, FLDSEP,
@ -306,12 +304,22 @@ static char *cmd_userset(PGconn *conn, char *cmd, char *id,
reason = "Invalid address";
goto struckout;
}
address = transfer_data(i_address);
pa_item = pa_store->head;
while (pa_item) {
DATA_PAYMENTADDRESSES(row, pa_item);
if (strcmp(row->payaddress, address) == 0) {
K_WUNLOCK(paymentaddresses_free);
reason = "Duplicate address";
goto struckout;
}
pa_item = pa_item->next;
}
pa_item = k_unlink_head(paymentaddresses_free);
DATA_PAYMENTADDRESSES(paymentaddresses, pa_item);
bzero(paymentaddresses, sizeof(*paymentaddresses));
STRNCPY(paymentaddresses->payaddress,
transfer_data(i_address));
paymentaddresses->payratio = ratio;
DATA_PAYMENTADDRESSES(row, pa_item);
bzero(row, sizeof(*row));
STRNCPY(row->payaddress, address);
row->payratio = ratio;
k_add_head(pa_store, pa_item);
}
K_WUNLOCK(paymentaddresses_free);
@ -328,8 +336,8 @@ static char *cmd_userset(PGconn *conn, char *cmd, char *id,
if (pa_store && pa_store->count > 0) {
pa_item = pa_store->head;
while (pa_item) {
DATA_PAYMENTADDRESSES(paymentaddresses, pa_item);
if (!btc_valid_address(paymentaddresses->payaddress)) {
DATA_PAYMENTADDRESSES(row, pa_item);
if (!btc_valid_address(row->payaddress)) {
reason = "Invalid BTC address";
goto struckout;
}

Loading…
Cancel
Save