Browse Source

php - allow workers via the API

master
kanoi 10 years ago
parent
commit
cc73b72363
  1. 65
      pool/page_api.php
  2. 6
      pool/page_userset.php

65
pool/page_api.php

@ -1,8 +1,11 @@
<?php
#
function no_api()
function no_api($json = "")
{
echo 'nil';
if (nuem($json))
echo 'nil';
else
echo '{"nil":"0"}';
exit(0);
}
#
@ -16,27 +19,51 @@ function show_api($page, $menu, $name, $user)
if (nutem($api))
no_api();
$jfu = getparam('json', true);
$work = getparam('work', true);
$ans = getAtts($u, 'KAPIKey.str');
if ($ans['STATUS'] != 'ok')
no_api();
no_api($jfu);
if (!isset($ans['KAPIKey.str']))
no_api();
no_api($jfu);
if ($ans['KAPIKey.str'] != $api)
no_api();
$ans = homeInfo($u);
if ($ans === false)
no_api();
$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);
no_api($jfu);
if (nuem($work))
{
$ans = homeInfo($u);
if ($ans === 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);
}
else
{
$ans = getWorkers($u);
if ($ans === false)
no_api($jfu);
$rep .= fldEncode($ans, 'rows', true);
$rows = $ans['rows'];
$flds = explode(',', $ans['flds']);
$zeflds = '';
for ($i = 0; $i < $rows; $i++)
foreach ($flds as $fld)
if (substr($fld, 0, 7) != 'idlenot')
{
$rep .= fldEncode($ans, $fld.':'.$i, false);
if ($i == 0)
$zeflds .= "$fld,";
}
$rep .= fldEncode(array(), 'flds', false);
$rep .= substr($zeflds, 0, -1);
}
if (nuem($jfu))
echo $rep;
else

6
pool/page_userset.php

@ -34,6 +34,12 @@ function uset($data, $user, $api, $err)
$pg .= htmlspecialchars(urlencode($user));
$pg .= "&api=$api&json=y</span><br>";
$pg .= '</td></tr>';
$pg .= '<tr class=dc><td>You can get your workers via:';
$pg .= '</td></tr><tr class=dc><td>';
$pg .= "<span class=hil>/index.php?k=api&username=";
$pg .= htmlspecialchars(urlencode($user));
$pg .= "&api=$api&json=y&work=y</span><br>";
$pg .= '</td></tr>';
}
$pg .= '</table></form>';

Loading…
Cancel
Save