Browse Source

php - api in json (if required)

master
kanoi 10 years ago
parent
commit
b508b72999
  1. 14
      pool/page_api.php
  2. 2
      pool/page_userset.php
  3. 8
      pool/param.php

14
pool/page_api.php

@ -8,8 +8,14 @@ function no_api()
#
function show_api($page, $menu, $name, $user)
{
global $fld_sep;
$u = getparam('username', true);
if (nutem($u))
no_api();
$api = getparam('api', true);
if (nutem($api))
no_api();
$jfu = getparam('json', true);
$ans = getAtts($u, 'KAPIKey.str');
if ($ans['STATUS'] != 'ok')
no_api();
@ -31,7 +37,13 @@ function show_api($page, $menu, $name, $user)
$rep .= fldEncode($ans, 'p_hashrate1hr', false);
$rep .= fldEncode($ans, 'u_hashrate5m', false);
$rep .= fldEncode($ans, 'u_hashrate1hr', false);
echo $rep;
if (nuem($jfu))
echo $rep;
else
{
$j = preg_replace("/([^=]+)=([^$fld_sep]+)$fld_sep/", '"$1":"$2",', $rep.$fld_sep);
echo '{'.substr($j, 0, -1).'}';
}
exit(0);
}
#

2
pool/page_userset.php

@ -30,7 +30,7 @@ function uset($data, $user, $api, $err)
$pg .= '<tr class=dc><td>&nbsp;</td></tr>';
$pg .= '<tr class=dc><td>You can access the API via:';
$pg .= '</td></tr><tr class=dc><td>';
$pg .= "<span class=hil>/index.php?k=api&username=$user&api=$api</span>";
$pg .= "<span class=hil>/index.php?k=api&username=$user&api=$api&json=y</span><br>";
$pg .= '</td></tr>';
}
$pg .= '</table></form>';

8
pool/param.php

@ -1,5 +1,13 @@
<?php
#
function nutem($str)
{
if (($str === null) or trim($str) == '')
return true;
else
return false;
}
#
function nuem($str)
{
if (($str === null) or $str == '')

Loading…
Cancel
Save