diff --git a/pool/db.php b/pool/db.php index 9bff93f2..302b9dae 100644 --- a/pool/db.php +++ b/pool/db.php @@ -71,6 +71,19 @@ function zeip() return $_SERVER['REMOTE_ADDR']; } # +function fldEncode($flds, $name, $first) +{ + global $fld_sep, $val_sep; + if ($first) + $rep = ''; + else + $rep = $fld_sep; + $rep .= $name . $val_sep; + if (isset($flds[$name])) + $rep .= $flds[$name]; + return $rep; +} +# function msgEncode($cmd, $id, $fields, $user) { global $send_sep, $fld_sep, $val_sep; diff --git a/pool/page_api.php b/pool/page_api.php new file mode 100644 index 00000000..8b193af8 --- /dev/null +++ b/pool/page_api.php @@ -0,0 +1,38 @@ + diff --git a/pool/page_userset.php b/pool/page_userset.php new file mode 100644 index 00000000..407020a6 --- /dev/null +++ b/pool/page_userset.php @@ -0,0 +1,92 @@ +User Settings'; + + if ($err != '') + $pg .= "$err

"; + + $pg .= ''; + $pg .= ''; + $pg .= '
'; + + $pg .= makeForm('userset'); + $pg .= ''; + $pg .= ''; + if ($api !== false) + { + $pg .= ''; + $pg .= ''; + } + $pg .= '
'; + if ($api === false) + $pg .= "You don't have an API Key setup yet"; + else + { + $pg .= 'Your current API Key is:'; + $pg .= '
'; + $pg .= "$api"; + } + $pg .= '
'; + $pg .= 'Click to generate a new API key'; + $pg .= ": "; + $pg .= '
 
You can access the API via:'; + $pg .= '
'; + $pg .= "/index.php?k=api&username=$user&api=$api"; + $pg .= '
'; + + $pg .= '
'; + + return $pg; +} +# +function douserset($data, $user) +{ + $err = ''; + $chg = getparam('Change', false); + $api = false; + switch ($chg) + { + case 'API Key': + $ans = getAtts($user, 'KAPIKey.str,KAPIKey.dateexp'); + if ($ans['STATUS'] != 'ok') + dbdown(); // Should be no other reason? + if (isset($ans['KAPIKey.dateexp']) && $ans['KAPIKey.dateexp'] == 'N') + { + $err = 'You can only change it once a day'; + if (isset($ans['KAPIKey.str'])) + $api = $ans['KAPIKey.str']; + } + else + { + $ran = $ans['STAMP'].$user.rand(100000000,999999999); + $api = hash('md4', $ran); + + $day = 60 * 60 * 24; + $ans = setAtts($user, array('ua_KAPIKey.str' => $api, + 'ua_KAPIKey.date' => "now+$day")); + if ($ans['STATUS'] != 'ok') + syserror(); + + } + break; + } + if ($api === false) + { + $ans = getAtts($user, 'KAPIKey.str'); + if ($ans['STATUS'] != 'ok') + dbdown(); // Should be no other reason? + if (isset($ans['KAPIKey.str'])) + $api = $ans['KAPIKey.str']; + } + $pg = uset($data, $user, $api, $err); + return $pg; +} +# +function show_userset($page, $menu, $name, $user) +{ + gopage(NULL, 'douserset', $page, $menu, $name, $user); +} +# +?> diff --git a/pool/prime.php b/pool/prime.php index cdcea841..1ef7c2e3 100644 --- a/pool/prime.php +++ b/pool/prime.php @@ -34,7 +34,8 @@ function process($p, $user, $menu) function def_menu() { $dmenu = array('Home' => array('Home' => ''), - 'gap' => NULL, + 'gap' => array( # options not shown + 'API' => 'api'), 'Help' => array('Help' => 'help', 'Payouts' => 'payout')); return $dmenu; @@ -50,14 +51,17 @@ function check() 'Account' => array( 'Workers' => 'workers', 'Payments' => 'payments', - 'Settings' => 'settings' + 'Settings' => 'settings', + 'User Settings' => 'userset' ), 'Pool' => array( 'Stats' => 'stats', 'Blocks' => 'blocks' ), 'Admin' => NULL, - 'gap' => NULL, + 'gap' => array( # options not shown + 'API' => 'api' + ), 'Help' => array( 'Help' => 'help', 'Payouts' => 'payout'