From b508b72999818d06662d3cf0c748686fc84a40a0 Mon Sep 17 00:00:00 2001 From: kanoi Date: Sun, 21 Sep 2014 12:31:50 +1000 Subject: [PATCH] php - api in json (if required) --- pool/page_api.php | 14 +++++++++++++- pool/page_userset.php | 2 +- pool/param.php | 8 ++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pool/page_api.php b/pool/page_api.php index 8b193af8..a4cd94ae 100644 --- a/pool/page_api.php +++ b/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); } # diff --git a/pool/page_userset.php b/pool/page_userset.php index 407020a6..2959e3c0 100644 --- a/pool/page_userset.php +++ b/pool/page_userset.php @@ -30,7 +30,7 @@ function uset($data, $user, $api, $err) $pg .= ' '; $pg .= 'You can access the API via:'; $pg .= ''; - $pg .= "/index.php?k=api&username=$user&api=$api"; + $pg .= "/index.php?k=api&username=$user&api=$api&json=y
"; $pg .= ''; } $pg .= ''; diff --git a/pool/param.php b/pool/param.php index 26c39c48..594be090 100644 --- a/pool/param.php +++ b/pool/param.php @@ -1,5 +1,13 @@