X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fmodules%2Fadmin.php;h=1807ee960f078b3e1f691302decddf6655442831;hp=75e43f401dfe1f14e873d82b0fcf4d931fe078fc;hb=e5527fd38a6585c8466dc28d013f12d21eb7c07a;hpb=e70705822fea03b38b81c919993070f574ad212b diff --git a/inc/modules/admin.php b/inc/modules/admin.php index 75e43f401d..1807ee960f 100644 --- a/inc/modules/admin.php +++ b/inc/modules/admin.php @@ -16,7 +16,7 @@ * $Author:: $ * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009 - 2012 by Mailer Developer Team * + * Copyright (c) 2009 - 2013 by Mailer Developer Team * * For more information visit: http://mxchange.org * * * * This program is free software; you can redistribute it and/or modify * @@ -51,133 +51,8 @@ $ret = 'init'; // Is no admin registered? if (!isAdminRegistered()) { - // Admin is not registered so we have to inform the user - if ((isFormSent()) && ((!isPostRequestElementSet('admin_login')) || (!isPostRequestElementSet('admin_pass1')) || (strlen(postRequestElement('admin_pass1')) < getConfig('minium_admin_pass_length')) || (!isPostRequestElementSet('admin_pass2')) || (strlen(postRequestElement('admin_pass2')) < getConfig('minium_admin_pass_length')) || (postRequestElement('admin_pass1') != postRequestElement('admin_pass2')))) { - setPostRequestElement('ok', '***'); - } // END - if - - // Clear error message - $errorMessage = ''; - - if ((isFormSent()) && (postRequestElement('ok') != '***')) { - // Hash the password with the old function because we are here in install mode - $hashedPass = md5(postRequestElement('admin_pass1')); - - // Kill maybe existing session variables - destroyAdminSession(FALSE); - - // Do registration - $ret = addAdminAccount(postRequestElement('admin_login'), $hashedPass, getWebmaster()); - - // Check if registration wents fine - switch ($ret) { - case 'done': - // Change ADMIN_REGISTERED entry - $done = changeDataInLocalConfigurationFile('ADMIN-SETUP', "setConfigEntry('ADMIN_REGISTERED', '", "');", 'Y', 0); - - // Was it successfull? - if ($done === TRUE) { - // Registering is done - redirectToUrl('modules.php?module=admin&register=done'); - } else { - // Registration incomplete - $errorMessage = '{--ADMIN_CANNOT_COMPLETE--}'; - - // Set this to have our error message displayed - setPostRequestElement('ok', '***'); - } - break; - - case 'failed': // Registration has failed - $errorMessage = '{--ADMIN_REGISTER_FAILED--}'; - - // Set this to have our error message displayed - setPostRequestElement('ok', '***'); - break; - - case 'already': // Admin does already exists! - $errorMessage = '{--ADMIN_LOGIN_ALREADY_REG--}'; - - // Set this to have our error message displayed - setPostRequestElement('ok', '***'); - break; - - default: - // Any other kind will be logged - $errorMessage = sprintf("Unknown return code %s from ifAdminLoginDataIsValid().", $ret); - logDebugMessage(__FILE__, __LINE__, $errorMessage); - - // Set this to have our error message displayed - setPostRequestElement('ok', '***'); - break; - } // END - switch - } // END - if - - // Whas that action okay? - if ($ret != 'done') { - // Init login name - $content['admin_login'] = ''; - if (isPostRequestElementSet('admin_login')) { - $content['admin_login'] = postRequestElement('admin_login'); - } // END - if - - // Init array elements - $content['login_message'] = ''; - $content['pass1_message'] = ''; - $content['pass2_message'] = ''; - $content['error_message'] = ''; - - // Yet-another notice-fix - if ((isFormSent()) && (postRequestElement('ok') == '***')) { - // Init variables - $loginMessage = ''; - $pass1Message = ''; - $pass2Message = ''; - - // No login entered? - if (empty($content['admin_login'])) { - $loginMessage = '{--ADMIN_NO_LOGIN--}'; - } // END - if - - // An error comes back from registration? - if ((!empty($ret)) && ($ret != 'init')) { - $loginMessage = $errorMessage; - } // END - if - - // No password 1 entered or to short? - if (!isPostRequestElementSet('admin_pass1')) { - $pass1Message = '{--ADMIN_NO_PASSWORD1--}'; - } elseif (strlen(postRequestElement('admin_pass1')) < getConfig('minium_admin_pass_length')) { - $pass1Message = '{--ADMIN_SHORT_PASSWORD1--}'; - } - - // No password 2 entered or to short? - if (!isPostRequestElementSet('admin_pass2')) { - $pass2Message = '{--ADMIN_NO_PASSWORD2--}'; - } elseif (strlen(postRequestElement('admin_pass2')) < getConfig('minium_admin_pass_length')) { - $pass2Message = '{--ADMIN_SHORT_PASSWORD2--}'; - } - - // Both didn't match? - if (postRequestElement('admin_pass1') != postRequestElement('admin_pass2')) { - // No match - if (empty($pass1Message)) $pass1Message = '{--ADMIN_PASSWORD1_MISMATCH--}'; - if (empty($pass2Message)) $pass2Message = '{--ADMIN_PASSWORD2_MISMATCH--}'; - } // END - if - - // Output error messages - $content['login_message'] = loadTemplate('admin_login_msg', TRUE, $loginMessage); - $content['pass1_message'] = loadTemplate('admin_login_msg', TRUE, $pass1Message); - $content['pass2_message'] = loadTemplate('admin_login_msg', TRUE, $pass2Message); - $content['error_message'] = loadTemplate('admin_login_msg', TRUE, $errorMessage); - } // END - if - - // Output message in seperate template - displayMessage('{--ADMIN_ACCOUNT_NOT_REGISTERED_YET--}'); - - // Load register template - loadTemplate('admin_reg_form', FALSE, $content); - } // END - if + // Register first admin + registerFirstAdmin(); } elseif (isGetRequestElementSet('reset_pass')) { // Is the form submitted? if ((isPostRequestElementSet('send_link')) && (isPostRequestElementSet('email'))) { @@ -204,11 +79,11 @@ if (!isAdminRegistered()) { // Cannot validate the login data and hash displayMessage('{--ADMIN_VALIDATION_RESET_LOGIN_HASH_FAILED--}'); } - } elseif ((isPostRequestElementSet('reset_pass')) && (isPostRequestElementSet('hash')) && (isPostRequestElementSet('admin_login')) && (isPostRequestElementSet('admin_pass1')) && (postRequestElement('admin_pass1') == postRequestElement('admin_pass2'))) { + } elseif ((isPostRequestElementSet('reset_pass')) && (isPostRequestElementSet('hash')) && (isPostRequestElementSet('admin_login')) && (isPostRequestElementSet('admin_password1')) && (postRequestElement('admin_password1') == postRequestElement('admin_password2'))) { // Okay, we shall the admin password here. So first revalidate the hash if (adminResetValidateHashLogin(postRequestElement('hash'), postRequestElement('admin_login'))) { // Output result - loadTemplate('admin_reset_password_done', FALSE, doResetAdminPassword(postRequestElement('admin_login'), postRequestElement('admin_pass1'))); + loadTemplate('admin_reset_password_done', FALSE, doResetAdminPassword(postRequestElement('admin_login'), postRequestElement('admin_password1'))); } else { // Validation failed displayMessage('{--ADMIN_VALIDATION_RESET_LOGIN_HASH_FAILED2--}'); @@ -224,9 +99,9 @@ if (!isAdminRegistered()) { redirectToUrl('modules.php?module=admin&logout=1'); } // END - if - if (isGetRequestElementSet('register')) { + if (isGetRequestElementSet('setup')) { // Registration of first admin is done - if (getRequestElement('register') == 'done') { + if (getRequestElement('setup') == 'done') { // Regisration done! displayMessage('{--ADMIN_REGISTER_DONE--}'); } // END - if @@ -251,17 +126,17 @@ if (!isAdminRegistered()) { case '404': // Administrator login not found setPostRequestElement('login', $ret); $ret = '{%message,ADMIN_ACCOUNT_404=' . postRequestElement('admin_login') . '%}'; - destroyAdminSession(); + destroyAdminSession(TRUE); break; case 'password': // Wrong password setPostRequestElement('login', $ret); $ret = '{--WRONG_PASS--} [{--ADMIN_RESET_PASS--}]'; - destroyAdminSession(); + destroyAdminSession(TRUE); break; default: // Others will be logged - logDebugMessage(__FILE__, __LINE__, sprintf("Unknown return code %s from ifAdminLoginDataIsValid()", $ret)); + logDebugMessage(__FILE__, __LINE__, sprintf('Unknown return code %s from ifAdminLoginDataIsValid()', $ret)); break; } // END - switch } // END - if @@ -294,10 +169,7 @@ if (!isAdminRegistered()) { // Check for password if (!isPostRequestElementSet('admin_password')) { // No password entered? - $passwdMessage = '{--ADMIN_NO_PASS--}'; - } elseif (strlen(postRequestElement('admin_password')) < getConfig('minium_admin_pass_length')) { - // Or password too short? - $passwdMessage = '{--ADMIN_SHORT_PASS--}'; + $passwdMessage = '{--ADMIN_NO_PASSWORD--}'; } elseif ((!empty($ret)) && (postRequestElement('login') == 'password')) { // An error comes back from login? $passwdMessage = $ret; @@ -320,27 +192,27 @@ if (!isAdminRegistered()) { } // END - if } elseif (isGetRequestElementSet('logout')) { // Only try to remove cookies - if (destroyAdminSession()) { + if (destroyAdminSession(TRUE)) { // Load logout template - if (isGetRequestElementSet('register')) { + if (isGetRequestElementSet('setup')) { // Secure input - $register = getRequestElement('register'); + $register = getRequestElement('setup'); // Special logout redirect for installation of given extension - loadTemplate(sprintf("admin_logout_%s_install", $register)); + loadTemplate(sprintf('admin_logout_%s_install', $register)); } elseif (isGetRequestElementSet('remove')) { // Secure input $remove = getRequestElement('remove'); // Special logout redirect for removal of given extension - loadTemplate(sprintf("admin_logout_%s_remove", $remove)); + loadTemplate(sprintf('admin_logout_%s_remove', $remove)); } else { // Logged out normally loadTemplate('admin_logout'); } } else { // Something went wrong here... - loadTemplate('admin_settings_unsaved', FALSE, '{--ADMIN_LOGOUT_FAILED--}'); + displayErrorMessage('{--ADMIN_LOGOUT_FAILED--}'); // Add fatal message addFatalMessage(__FILE__, __LINE__, '{--CANNOT_UNREG_SESS--}'); @@ -374,23 +246,23 @@ if (!isAdminRegistered()) { case '404': // Administrator login not found setPostRequestElement('login', $ret); displayMessage('{%message,ADMIN_ACCOUNT_404=' . getCurrentAdminId() . '%}'); - destroyAdminSession(); + destroyAdminSession(TRUE); break; case 'password': // Wrong password setPostRequestElement('login', $ret); displayMessage('{--WRONG_PASS--}'); - destroyAdminSession(); + destroyAdminSession(TRUE); break; case 'session': // Invalid admin session setPostRequestElement('login', $ret); displayMessage('{--INVALID_ADMIN_SESSION--}'); - destroyAdminSession(); + destroyAdminSession(TRUE); break; default: // Others will be logged - logDebugMessage(__FILE__, __LINE__, sprintf("Unknown return code %s from ifAdminCookiesAreValid()", $ret)); + logDebugMessage(__FILE__, __LINE__, sprintf('Unknown return code %s from ifAdminCookiesAreValid()', $ret)); break; } // END - switch }