From 9b72c30dbc230847ca7cd1fd8430a797bd7d01a5 Mon Sep 17 00:00:00 2001 From: kanoi Date: Wed, 3 Sep 2014 21:51:43 +1000 Subject: [PATCH] ckdb/php - add users settings plus various changes in the php --- pool/base.php | 50 ++++- pool/db.php | 34 +++- pool/page.php | 52 +++-- pool/page_blocks.php | 4 +- pool/page_ckp.php | 4 +- pool/page_help.php | 4 +- pool/page_index.php | 4 +- pool/page_payments.php | 4 +- pool/page_payout.php | 4 +- pool/page_pplns.php | 8 +- pool/page_reg.php | 38 +--- pool/page_settings.php | 155 +++++++++++++++ pool/page_stats.php | 4 +- pool/page_workers.php | 4 +- sql/initid.sh | 1 + src/ckdb.c | 441 +++++++++++++++++++++++++++++++++++++++-- 16 files changed, 708 insertions(+), 103 deletions(-) create mode 100644 pool/page_settings.php diff --git a/pool/base.php b/pool/base.php index ba3ed601..860de7c6 100644 --- a/pool/base.php +++ b/pool/base.php @@ -65,9 +65,38 @@ function emailStr($str) return preg_replace(array($all,$beg,$fin), '', $str); } # +function safepass($pass) +{ + if (strlen($pass) < 6) + return false; + + # Invalid characters + $p2 = preg_replace('/[\011]/', '', $pass); + if ($p2 != $pass) + return false; + + # At least one lowercase + $p2 = preg_replace('/[a-z]/', '', $pass); + if ($p2 == $pass) + return false; + + # At least one uppercase + $p2 = preg_replace('/[A-Z]/', '', $pass); + if ($p2 == $pass) + return false; + + # At least one digit + $p2 = preg_replace('/[0-9]/', '', $pass); + if ($p2 == $pass) + return false; + + return true; +} +# function loginStr($str) { - $all = '/[^!-~]/'; // no spaces + // Anything but . _ / Tab + $all = '/[\._\/\011]/'; return preg_replace($all, '', $str); } # @@ -137,34 +166,34 @@ function safetext($txt, $len = 1024) # function dbd($data, $user) { - return "
Web site is currently down
"; + return "
Web site is currently down
"; } # function dbdown() { - gopage(NULL, 'dbd', NULL, '', false, true, false); + gopage(NULL, 'dbd', 'dbd', NULL, '', '', true, false, false); } # function f404($data) { - return "
404
"; + return "
404
"; } # function do404() { - gopage(NULL, 'f404', NULL, '', false, true, false); + gopage(NULL, 'f404', 'f404', NULL, '', '', true, false, false); } # function showPage($page, $menu, $name, $user) { # If you are doing development, use without '@' # Then switch to '@' when finished -# @include_once("page_$page.php"); - include_once("page_$page.php"); +# include_once("page_$page.php"); + @include_once("page_$page.php"); $fun = 'show_' . $page; if (function_exists($fun)) - $fun($menu, $name, $user); + $fun($page, $menu, $name, $user); else do404(); } @@ -179,8 +208,9 @@ function offline() if (file_exists('./maintenance.txt')) { $ip = $_SERVER['REMOTE_ADDR']; - if ($ip != '192.168.7.74') - gopage(NULL, file_get_contents('./maintenance.txt'), NULL, '', false, false, false, false); + if ($ip != '192.168.1.666') + gopage(NULL, file_get_contents('./maintenance.txt'), + 'offline', NULL, '', '', false, false, false); } } # diff --git a/pool/db.php b/pool/db.php index acff4e98..14688111 100644 --- a/pool/db.php +++ b/pool/db.php @@ -59,7 +59,7 @@ function repDecode($rep) if (isset($major[3])) $ans['ERROR'] = $major[3]; else - $ans['ERROR'] = 'unknown'; + $ans['ERROR'] = 'system error'; } return $ans; @@ -121,18 +121,46 @@ function checkPass($user, $pass) $passhash = myhash($pass); $flds = array('username' => $user, 'passwordhash' => $passhash); $msg = msgEncode('chkpass', 'log', $flds); - $rep = sendsockreply('checkpass', $msg); + $rep = sendsockreply('checkPass', $msg); if (!$rep) dbdown(); return $rep; } # +function setPass($user, $oldpass, $newpass) +{ + $oldhash = myhash($oldpass); + $newhash = myhash($newpass); + $flds = array('username' => $user, 'oldhash' => $oldhash, 'newhash' => $newhash); + $msg = msgEncode('newpass', 'log', $flds); + $rep = sendsockreply('setPass', $msg); + if (!$rep) + dbdown(); + return repDecode($rep); +} +# function userReg($user, $email, $pass) { $passhash = myhash($pass); $flds = array('username' => $user, 'emailaddress' => $email, 'passwordhash' => $passhash); $msg = msgEncode('adduser', 'reg', $flds); - $rep = sendsockreply('adduser', $msg); + $rep = sendsockreply('userReg', $msg); + if (!$rep) + dbdown(); + return repDecode($rep); +} +# +function userSettings($user, $email = null, $addr = null, $pass = null) +{ + $flds = array('username' => $user); + if ($email != null) + $flds['email'] = $email; + if ($addr != null) + $flds['address'] = $addr; + if ($pass != null) + $flds['passwordhash'] = myhash($pass); + $msg = msgEncode('usersettings', 'userset', $flds); + $rep = sendsockreply('userSettings', $msg); if (!$rep) dbdown(); return repDecode($rep); diff --git a/pool/page.php b/pool/page.php index a9c1f727..5d65f19b 100644 --- a/pool/page.php +++ b/pool/page.php @@ -52,6 +52,14 @@ function makeLink($page, $rest = '') return $href; } # +function makeForm($page) +{ + $form = '
'; + if (strlen($page) > 0) + $form .= ""; + return $form; +} +# function dotrm($html, $dontdoit) { if ($dontdoit === true) @@ -82,7 +90,7 @@ function pghead($script_marker, $name) $head .= "