X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fmodules%2Fadmin%2Fadmin-inc.php;h=c43101826b69b249db598a5e4fd66fa428a6d43c;hb=c1671a3b6c02326b471916a28f4177c453871f51;hp=e8778670dd68e3641742ab9eec8a57e2c5b2e8a6;hpb=1ebf518b9552f71ee95de6f4b80e6de3a27716d1;p=mailer.git diff --git a/inc/modules/admin/admin-inc.php b/inc/modules/admin/admin-inc.php index e8778670dd..c43101826b 100644 --- a/inc/modules/admin/admin-inc.php +++ b/inc/modules/admin/admin-inc.php @@ -1,7 +1,7 @@ $adminId); // Is the cache valid? - if (isset($GLOBALS['cache_array']['admins']['password'][$adminId])) { + if (isAdminHashSet($admin)) { // Get password from cache - $data['password'] = $GLOBALS['cache_array']['admins']['password'][$adminId]; + $data['password'] = getAdminHash($admin); $ret = 'pass'; incrementStatsEntry('cache_hits'); // Include more admins data? - if (isExtensionInstalledAndNewer('admins', '0.7.2')) { + if ((isExtensionInstalledAndNewer('admins', '0.7.2')) && (isset($GLOBALS['cache_array']['admin']['login_failures'][$adminId]))) { // Load them here - $data['login_failures'] = $GLOBALS['cache_array']['admins']['login_failures'][$adminId]; - $data['last_failure'] = $GLOBALS['cache_array']['admins']['last_failure'][$adminId]; + $data['login_failures'] = $GLOBALS['cache_array']['admin']['login_failures'][$adminId]; + $data['last_failure'] = $GLOBALS['cache_array']['admin']['last_failure'][$adminId]; } // END - if } elseif (!isExtensionActive('cache')) { // Add extra data via filter now @@ -110,12 +116,13 @@ function ifAdminLoginDataIsValid ($admin_login, $password) { SQL_FREERESULT($result); } - //* DEBUG: */ outputHtml("*".$data['password'].'/'.md5($password).'/'.$ret."
"); + //* DEBUG: */ outputHtml('*' . $data['password'] . '/' . md5($password) .'/' . $ret . '*
'); if ((isset($data['password'])) && (strlen($data['password']) == 32) && ($data['password'] == md5($password))) { // Generate new hash $data['password'] = generateHash($password); // Is the sql_patches not installed, than we cannot have a valid hashed password here! + //* DEBUG: */ outputHtml($ret . ',' . intval(isExtensionInstalledAndOlder('sql_patches', '0.3.6')) . '/' . intval(!isExtensionInstalled('sql_patches')).'
'); if (($ret == 'pass') && ((isExtensionInstalledAndOlder('sql_patches', '0.3.6')) || (!isExtensionInstalled('sql_patches')))) $ret = 'done'; } elseif ((isExtensionInstalledAndOlder('sql_patches', '0.3.6')) || (!isExtensionInstalled('sql_patches'))) { // Old hashing way @@ -129,35 +136,35 @@ function ifAdminLoginDataIsValid ($admin_login, $password) { $salt = substr($data['password'], 0, -40); // Check if password is same - //* DEBUG: */ outputHtml("*".$ret.','.$data['password'].','.$password.','.$salt."*
"); - if (($ret == 'pass') && ($data['password'] == generateHash($password, $salt)) && ((!empty($salt))) || ($data['password'] == $password)) { + //* DEBUG: */ outputHtml('*' . $ret . ',' . $data['password'] . ',' . $password . ',' . $salt . '*
'); + if (($ret == 'pass') && ($data['password'] == generateHash($password, $salt)) && ((!empty($salt))) || ($data['password'] == md5($password))) { // Re-hash the plain passord with new random salt $data['password'] = generateHash($password); // Do we have 0.7.0 of admins or later? // Remmeber login failures if available - if (isExtensionInstalledAndNewer('admins', '0.7.2')) { + if ((isExtensionInstalledAndNewer('admins', '0.7.2')) && (isset($data['login_failures']))) { // Store it in session setSession('mxchange_admin_failures', $data['login_failures']); setSession('mxchange_admin_last_fail', $data['last_failure']); // Update password and reset login failures - SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins` SET password='%s',login_failures=0,last_failure='0000-00-00 00:00:00' WHERE `id`=%s LIMIT 1", + SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins` SET `password`='%s',`login_failures`=0,`last_failure`='0000-00-00 00:00:00' WHERE `id`=%s LIMIT 1", array($data['password'], $adminId), __FUNCTION__, __LINE__); } else { // Update password - SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins` SET password='%s' WHERE `id`=%s LIMIT 1", + SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins` SET `password`='%s' WHERE `id`=%s LIMIT 1", array($data['password'], $adminId), __FUNCTION__, __LINE__); } // Rebuild cache - rebuildCacheFile('admins', 'admin'); + rebuildCacheFile('admin', 'admin'); // Login has failed by default... ;-) $ret = 'failed1'; // Password matches so login here - if (doAdminLogin($admin_login, $data['password'])) { + if (doAdminLogin($admin, $data['password'])) { // All done now $ret = 'done'; } // END - if @@ -166,7 +173,7 @@ function ifAdminLoginDataIsValid ($admin_login, $password) { $ret = 'failed_salt'; } elseif ($ret == 'done') { // Try to login here if we have the old hashing way (sql_patches not installed?) - if (!doAdminLogin($admin_login, $data['password'])) { + if (!doAdminLogin($admin, $data['password'])) { // Something went wrong $ret = 'failed2'; } // END - if @@ -175,15 +182,15 @@ function ifAdminLoginDataIsValid ($admin_login, $password) { // Count login failure if admins extension version is 0.7.0+ if (($ret == 'pass') && (getExtensionVersion('admins') >= '0.7.0')) { // Update counter - SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins` SET login_failures=login_failures+1,last_failure=NOW() WHERE `id`=%s LIMIT 1", - array($adminId), __FUNCTION__, __LINE__); + SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins` SET login_failures`=`login_failures`+1,`last_failure`=NOW() WHERE `id`=%s LIMIT 1", + array($adminId), __FUNCTION__, __LINE__); // Rebuild cache - rebuildCacheFile('admins', 'admin'); + rebuildCacheFile('admin', 'admin'); } // END - if // Return the result - //* DEBUG: */ die("RETURN=".$ret); + //* DEBUG: */ die('RETURN=' . $ret); return $ret; } @@ -196,7 +203,7 @@ function doAdminLogin ($adminLogin, $passHash) { array($adminLogin), __FUNCTION__, __LINE__); // Rebuild cache - rebuildCacheFile('admins', 'admin'); + rebuildCacheFile('admin', 'admin'); } // END - if // Now set all session variables and return the result @@ -206,25 +213,23 @@ function doAdminLogin ($adminLogin, $passHash) { setSession('admin_login', $adminLogin) ) && ( setSession('admin_last', time()) - ) && ( - setSession('admin_to', bigintval(postRequestElement('timeout'))) )); } // Only be executed on cookie checking -function ifAdminCookiesAreValid ($admin_login, $password) { +function ifAdminCookiesAreValid ($admin, $password) { // By default no admin cookies are found $ret = '404'; $pass = ''; // Get hash - $pass = getAdminHash(getAdminId($admin_login)); + $pass = getAdminHash($admin); if ($pass != '-1') $ret = 'pass'; //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):".generatePassString($pass).'('.strlen($pass).")/".$password.'('.strlen($password).")
"); // Check if password matches - if (($ret == 'pass') && ((generatePassString($pass) == $password) || ($pass == $password) || ((strlen($pass) == 32) && (md5($password) == $pass)))) { + if (($ret == 'pass') && ((generatePassString($pass) == $password) || ($pass == $password) || ((strlen($pass) == 32) && (md5($password) == $pass))) && (isAdmin())) { // Passwords matches! $ret = 'done'; } // END - if @@ -234,7 +239,10 @@ function ifAdminCookiesAreValid ($admin_login, $password) { } // Do an admin action -function doAdminAction ($what) { +function doAdminAction () { + // Get default what + $what = getWhat(); + //* DEBUG: */ outputHtml(__LINE__."*".$what.'/'.getModule().'/'.getAction().'/'.getWhat()."*
"); // Remove any spaces from variable @@ -242,14 +250,14 @@ function doAdminAction ($what) { // Default admin action is the overview page $what = 'overview'; } else { - // Compile out some chars - $what = compileCode($what, false, false, false); + // Secure it + $what = secureString($what); } // Get action value $action = getModeAction(getModule(), $what); - // Define admin login name and ID number + // Define admin login name and id number $content['login'] = getSession('admin_login'); $content['id'] = getCurrentAdminId(); @@ -283,7 +291,14 @@ WHERE ) ) ) -LIMIT 1", array($action, $what, $what), __FUNCTION__, __LINE__); +LIMIT 1", + array( + $action, + $what, + $what + ), __FUNCTION__, __LINE__); + + // Do we have an entry? if (SQL_NUMROWS($result_action) == 1) { // Is valid but does the inlcude file exists? $inc = sprintf("inc/modules/admin/action-%s.php", $action); @@ -299,7 +314,7 @@ LIMIT 1", array($action, $what, $what), __FUNCTION__, __LINE__); } } else { // Invalid action/what pair found! - loadTemplate('admin_menu_failed', false, sprintf(getMessage('ADMIN_ACTION_INVALID'), $action.'/'.$what)); + loadTemplate('admin_menu_failed', false, sprintf(getMessage('ADMIN_ACTION_INVALID'), $action . '/' . $what)); } // Free memory @@ -329,6 +344,8 @@ WHERE ORDER BY `sort` ASC, `id` DESC", __FUNCTION__, __LINE__); + + // Do we have entries? if (SQL_NUMROWS($result_main) > 0) { $OUT = "
 
\n"; $OUT .= "