Previous admin session data will be destroyed while first admin registration process
[mailer.git] / inc / modules / admin.php
index 083009f303cfaac823b7ad6dfc62bd85afcd8cc9..ad94f73f267ba03ca83d9788381c53f0ecf0c27e 100644 (file)
@@ -49,25 +49,25 @@ require_once(PATH."inc/modules/admin/admin-inc.php");
 // Fix "deleted" cookies in PHP4 (PHP5 does remove them, PHP4 sets them to deleted!)
 FIX_DELETED_COOKIES(array('admin_login', 'admin_md5', 'admin_last', 'admin_to'));
 
-// Is the logout empty?
-if (empty($_GET['logout'])) $_GET['logout'] = "";
-
 if (!isBooleanConstantAndTrue('admin_registered')) {
        // Admin is not registered so we have to inform the user
        if ((isset($_POST['ok'])) && ((empty($_POST['login'])) || (empty($_POST['pass'])) || (strlen($_POST['pass']) < 4))) $_POST['ok'] = "***";
        if ((isset($_POST['ok'])) && ($_POST['ok'] != "***")) {
-               // Hash the password with our new generateHash() function
-               $hashedPass = generateHash($_POST['pass']);
+               // Hash the password with the old function because we are here in install mode
+               $hashedPass = md5($_POST['pass']);
 
-               // If the password has not been hashed we have to fall-back to md5()
-               if ($hashedPass == $_POST['pass']) $hashedPass = md5($hashedPass);
+               // Kill maybe existing session variables
+               set_session('admin_login'       , "");
+               set_session('admin_md5'         , "");
+               set_session('admin_last'        , "");
+               set_session('admin_to'          , "");
 
                // Do registration
                $ret = REGISTER_ADMIN($_POST['login'], $hashedPass);
                switch ($ret)
                {
                case "done":
-                       admin_WriteData(PATH."inc/config.php", "ADMIN-SETUP", "define ('admin_registered', ", ");", "true", 0);
+                       admin_WriteData(PATH."inc/config.php", "ADMIN-SETUP", "define('admin_registered', ", ");", "true", 0);
                        if (!_FATAL) {
                                // Registering is done
                                LOAD_URL(URL."/modules.php?module=admin&amp;action=login&register=done");
@@ -89,9 +89,10 @@ if (!isBooleanConstantAndTrue('admin_registered')) {
                                // Any other kind
                                $ret = "done";
                        }
+
                        if (!isBooleanConstantAndTrue('admin_registered')) {
                                // Write to config that registration is done
-                               admin_WriteData(PATH."inc/config.php", "ADMIN-SETUP", "define ('admin_registered', ", ");", "true", 0);
+                               admin_WriteData(PATH."inc/config.php", "ADMIN-SETUP", "define('admin_registered', ", ");", "true", 0);
 
                                // Load URL for login
                                $URL = URL."/modules.php?module=admin&amp;action=login";
@@ -100,6 +101,8 @@ if (!isBooleanConstantAndTrue('admin_registered')) {
                        break;
                }
        }
+
+       // Whas that action okay?
        if ($ret != "done") {
                // Fixes another "Notice"
                if (!empty($_POST['login'])) {
@@ -137,9 +140,9 @@ if (!isBooleanConstantAndTrue('admin_registered')) {
                // Load register template
                LOAD_TEMPLATE("admin_reg_form");
        }
-} elseif ((empty($_SESSION['admin_login'])) || (empty($_SESSION['admin_md5'])) || (empty($_SESSION['admin_last'])) || (empty($_SESSION['admin_to'])) || (($_SESSION['admin_last'] + bigintval($_SESSION['admin_to']) * 3600 * 24) < time())) {
+} elseif ((!isSessionVariableSet('admin_login')) || (!isSessionVariableSet('admin_md5')) || (!isSessionVariableSet('admin_last')) || (!isSessionVariableSet('admin_to')) || ((get_session('admin_last') + bigintval(get_session('admin_to')) * 3600 * 24) < time())) {
        // At leat one administrator account was created
-       if ((!empty($_SESSION['admin_login'])) && (!empty($_SESSION['admin_md5'])) && (!empty($_SESSION['admin_last'])) && (!empty($_SESSION['admin_to']))) {
+       if ((isSessionVariableSet('admin_login')) && (isSessionVariableSet('admin_md5')) && (isSessionVariableSet('admin_last')) && (isSessionVariableSet('admin_to'))) {
                // Timeout for last login, we have to logout first!
                $URL = URL."/modules.php?module=admin&amp;action=login&amp;logout=1";
                LOAD_URL($URL);
@@ -253,20 +256,26 @@ if (!isBooleanConstantAndTrue('admin_registered')) {
                // Load login form template
                LOAD_TEMPLATE("admin_login_form", false, $content);
        }
-} elseif ($_GET['logout'] == "1") {
+} elseif (isset($_GET['logout'])) {
        // Only try to remove cookies
        if (set_session("admin_login", "") && set_session("admin_md5", "") && set_session("admin_last", "") && set_session("admin_to", "")) {
                // Also remove array elements
-               unset($_SESSION['admin_login']);
-               unset($_SESSION['admin_md5']);
-               unset($_SESSION['admin_last']);
-               unset($_SESSION['admin_to']);
+               set_session('admin_login'       , "");
+               set_session('admin_md5'         , "");
+               set_session('admin_last'        , "");
+               set_session('admin_to'          , "");
 
                // Destroy session
                @session_destroy();
 
                // Load logout template
-               LOAD_TEMPLATE("admin_logout");
+               if (isset($_GET['sql_patches'])) {
+                       // Special logout redirect for sql_patchrs
+                       LOAD_TEMPLATE("admin_logout_sql_patches");
+               } else {
+                       // Logged out normally
+                       LOAD_TEMPLATE("admin_logout");
+               }
        } else {
                // Something went wrong here...
                OUTPUT_HTML("<STRONG class=\"admin_fatal\">".ADMIN_LOGOUT_FAILED."</STRONG>");
@@ -276,11 +285,12 @@ if (!isBooleanConstantAndTrue('admin_registered')) {
        }
 } else {
        // Maybe an Admin want's to login?
-       $ret = CHECK_ADMIN_COOKIES(SQL_ESCAPE($_SESSION['admin_login']), SQL_ESCAPE($_SESSION['admin_md5']));
-       switch ($ret) {
+       $ret = CHECK_ADMIN_COOKIES(SQL_ESCAPE(get_session('admin_login')), SQL_ESCAPE(get_session('admin_md5')));
+       switch ($ret)
+       {
        case "done":
                // Cookie-Data accepted
-               if ((set_session("admin_md5", SQL_ESCAPE($_SESSION['admin_md5']))) && (set_session("admin_login", SQL_ESCAPE($_SESSION['admin_login']))) && (set_session("admin_last", time())) && (set_session("admin_to", bigintval($_SESSION['admin_to'])))) {
+               if ((set_session("admin_md5", SQL_ESCAPE(get_session('admin_md5')))) && (set_session("admin_login", SQL_ESCAPE(get_session('admin_login')))) && (set_session("admin_last", time())) && (set_session("admin_to", bigintval(get_session('admin_to'))))) {
                        // Ok, Cookie-Update done
                        if ((EXT_IS_ACTIVE("admins")) && (GET_EXT_VERSION("admins") > "0.2")) {
                                // Check if action GET variable was set