X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fmodules%2Fadmin%2Fadmin-inc.php;h=6eee1eddf6e93996b89532899bfbb5c77fb54678;hp=8e3bd823adae8b7b4f1937b30d7d6d4f9603d80e;hb=49acdb7a7adbcf25a8e8683b5581bfcec72b23bd;hpb=e88e30c24737cf641f2e93f6a311e641ccbf5960 diff --git a/inc/modules/admin/admin-inc.php b/inc/modules/admin/admin-inc.php index 8e3bd823ad..6eee1eddf6 100644 --- a/inc/modules/admin/admin-inc.php +++ b/inc/modules/admin/admin-inc.php @@ -16,7 +16,7 @@ * $Author:: $ * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009 - 2012 by Mailer Developer Team * + * Copyright (c) 2009 - 2015 by Mailer Developer Team * * For more information visit: http://mxchange.org * * * * This program is free software; you can redistribute it and/or modify * @@ -41,30 +41,45 @@ if (!defined('__SECURITY')) { } // END - if // Register an administrator account -function addAdminAccount ($adminLogin, $passHash, $adminEmail) { +function addAdminAccount ($adminLogin, $passHash, $adminEmail, $accessLevel = 'deny') { + // Only let valid data pass + assert(in_array($accessLevel, array('allow', 'deny'))); + // Login does already exist $ret = 'already'; // Lookup the admin - $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `login`='%s' LIMIT 1", + $result = sqlQueryEscaped("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `login`='%s' LIMIT 1", array($adminLogin), __FUNCTION__, __LINE__); // Is the entry there? - if (SQL_HASZERONUMS($result)) { - // Ok, let's create the admin login - SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins` (`login`, `password`, `email`) VALUES ('%s', '%s', '%s')", - array( - $adminLogin, - $passHash, - $adminEmail - ), __FUNCTION__, __LINE__); + if (ifSqlHasZeroNumRows($result)) { + // Is ext-admins installed and version at least 0.3.0? + if (isExtensionInstalledAndNewer('admins', '0.3.0')) { + // Ok, let's create the admin login + sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_admins` (`login`, `password`, `email`, `default_acl`) VALUES ('%s', '%s', '%s', '%s')", + array( + $adminLogin, + $passHash, + $adminEmail, + $accessLevel + ), __FUNCTION__, __LINE__); + } else { + // Ok, let's create the admin login + sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_admins` (`login`, `password`, `email`) VALUES ('%s', '%s', '%s')", + array( + $adminLogin, + $passHash, + $adminEmail + ), __FUNCTION__, __LINE__); + } // All done $ret = 'done'; } // END - if // Free memory - SQL_FREERESULT($result); + sqlFreeResult($result); // Return result return $ret; @@ -80,7 +95,7 @@ function ifAdminLoginDataIsValid ($adminLogin, $adminPassword) { $adminId = getAdminId($adminLogin); // Continue only with found admin ids - if ($adminId > 0) { + if (isValidId($adminId)) { // Then we need to lookup the login name by getting the admin hash $adminHash = getAdminHash($adminId); @@ -120,6 +135,8 @@ function ifAdminLoginDataIsValid ($adminLogin, $adminPassword) { // Only be executed on cookie checking function ifAdminCookiesAreValid ($adminLogin, $passHash) { + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLogin=' . $adminLogin . ',passHash=' . $passHash . ' - CALLED!'); + // First of all, no admin login is found $ret = '404'; @@ -133,17 +150,20 @@ function ifAdminCookiesAreValid ($adminLogin, $passHash) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLogin=' . $adminLogin . ',passHash='.$passHash.',adminHash='.$adminHash.',testHash='.$testHash); // If they both match, the login data is valid - if ($testHash == $passHash) { + if ($testHash != $passHash) { + // Passwords don't match + $ret = 'password'; + } elseif (!isAdmin()) { + // Is not valid session + $ret = 'session'; + } else { // All fine $ret = 'done'; - } else { - // Set status - $ret = 'password'; } } // END - if // Return status - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret='.$ret); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . $ret . ' - EXIT!'); return $ret; } @@ -172,7 +192,7 @@ function doAdminAction () { loadTemplate('admin_main', FALSE, $content); // Check if action/what pair is valid - $result_action = SQL_QUERY_ESC("SELECT + $result_action = sqlQueryEscaped("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admin_menu` @@ -197,9 +217,9 @@ LIMIT 1", ), __FUNCTION__, __LINE__); // Is there an entry? - if (SQL_NUMROWS($result_action) == 1) { + if (sqlNumRows($result_action) == 1) { // Is valid but does the inlcude file exists? - $inc = sprintf("inc/modules/admin/action-%s.php", $action); + $inc = sprintf('inc/modules/admin/action-%s.php', $action); if ((isIncludeReadable($inc)) && (isMenuActionValid('admin', $action, $what)) && ($GLOBALS['acl_allow'] === TRUE)) { // Ok, we finally load the admin action module loadInclude($inc); @@ -216,7 +236,7 @@ LIMIT 1", } // Free memory - SQL_FREERESULT($result_action); + sqlFreeResult($result_action); // Tableset footer loadTemplate('admin_main_footer', FALSE, $content); @@ -249,7 +269,7 @@ function addAdminMenu ($action, $what) { $GLOBALS['menu']['title'] = array(); // Build main menu - $result_main = SQL_QUERY("SELECT + $result_main = sqlQuery("SELECT `action` AS `main_action`, `title` AS `main_title`, `descr` AS `main_descr` @@ -262,13 +282,13 @@ ORDER BY `id` DESC", __FUNCTION__, __LINE__); // Are there entries? - if (!SQL_HASZERONUMS($result_main)) { + if (!ifSqlHasZeroNumRows($result_main)) { $OUT .= ''; // Free memory - SQL_FREERESULT($result_main); + sqlFreeResult($result_main); } // END - if // Return content @@ -329,7 +349,7 @@ function addAdminSubMenu ($mainContent, $action, $what) { $OUT = ''; // Check for menu entries - $result_what = SQL_QUERY_ESC("SELECT + $result_what = sqlQueryEscaped("SELECT `what` AS `sub_what`, `title` AS `sub_title`, `descr` AS `sub_descr` @@ -345,7 +365,7 @@ ORDER BY array($mainContent['main_action']), __FUNCTION__, __LINE__); // Remember the count for later checks - setAdminMenuHasEntries($mainContent['main_action'], ((!SQL_HASZERONUMS($result_what)) && (($action == $mainContent['main_action']) || (isAdminMenuJavascriptEnabled())))); + setAdminMenuHasEntries($mainContent['main_action'], ((!ifSqlHasZeroNumRows($result_what)) && (($action == $mainContent['main_action']) || (isAdminMenuJavascriptEnabled())))); // Start li-tag for sub menu content $OUT .= '
  • '; @@ -356,14 +376,14 @@ ORDER BY $SUB = TRUE; // Are there entries? - if (!SQL_HASZERONUMS($result_what)) { + if (!ifSqlHasZeroNumRows($result_what)) { // Start HTML code $OUT .= '