2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 08/31/2003 *
4 * =================== Last change: 07/02/2004 *
6 * -------------------------------------------------------------------- *
8 * -------------------------------------------------------------------- *
9 * Short description : Administration module *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Administrationsmodul *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
44 loadIncludeOnce('inc/modules/admin/admin-inc.php');
46 // Fix "deleted" cookies in PHP4 (PHP5 does remove them, PHP4 sets them to deleted!)
47 fixDeletedCookies(array('admin_id', 'admin_md5', 'admin_last'));
52 // Is no admin registered?
53 if (!isAdminRegistered()) {
54 // Admin is not registered so we have to inform the user
55 if ((isFormSent()) && ((!isPostRequestParameterSet('login')) || (!isPostRequestParameterSet('pass1')) || (strlen(postRequestParameter('pass1')) < getConfig('minium_admin_pass_length')) || (!isPostRequestParameterSet('pass2')) || (strlen(postRequestParameter('pass2')) < getConfig('minium_admin_pass_length')) || (postRequestParameter('pass1') != postRequestParameter('pass2')))) {
56 setPostRequestParameter('ok', '***');
59 // Clear error message
62 if ((isFormSent()) && (postRequestParameter('ok') != '***')) {
63 // Hash the password with the old function because we are here in install mode
64 $hashedPass = md5(postRequestParameter('pass1'));
66 // Kill maybe existing session variables
67 destroyAdminSession(false);
70 $ret = addAdminAccount(postRequestParameter('login'), $hashedPass, getWebmaster());
72 // Check if registration wents fine
75 // Change ADMIN_REGISTERED entry
76 $done = changeDataInLocalConfigurationFile('ADMIN-SETUP', "setConfigEntry('ADMIN_REGISTERED', '", "');", 'Y', 0);
78 // Was it successfull?
80 // Registering is done
81 redirectToUrl('modules.php?module=admin&register=done');
83 // Registration incomplete
84 $errorMessage = '{--ADMIN_CANNOT_COMPLETE--}';
86 // Set this to have our error message displayed
87 setPostRequestParameter('ok', '***');
91 case 'failed': // Registration has failed
92 $errorMessage = '{--ADMIN_REGISTER_FAILED--}';
94 // Set this to have our error message displayed
95 setPostRequestParameter('ok', '***');
98 case 'already': // Admin does already exists!
99 $errorMessage = '{--ADMIN_LOGIN_ALREADY_REG--}';
101 // Set this to have our error message displayed
102 setPostRequestParameter('ok', '***');
106 // Any other kind will be logged
107 $errorMessage = sprintf("Unknown return code %s from ifAdminLoginDataIsValid().", $ret);
108 logDebugMessage(__FILE__, __LINE__, $errorMessage);
110 // Set this to have our error message displayed
111 setPostRequestParameter('ok', '***');
116 // Whas that action okay?
117 if ($ret != 'done') {
119 $content['login'] = '';
120 if (isPostRequestParameterSet('login')) {
121 $content['login'] = postRequestParameter('login');
124 // Init array elements
125 $content['login_message'] = '';
126 $content['pass1_message'] = '';
127 $content['pass2_message'] = '';
128 $content['error_message'] = '';
130 // Yet-another notice-fix
131 if ((isFormSent()) && (postRequestParameter('ok') == '***')) {
138 if (empty($content['login'])) {
139 $loginMessage = '{--ADMIN_NO_LOGIN--}';
142 // An error comes back from registration?
143 if ((!empty($ret)) && ($ret != 'init')) {
144 $loginMessage = $errorMessage;
147 // No password 1 entered or to short?
148 if (!isPostRequestParameterSet('pass1')) {
149 $pass1Message = '{--ADMIN_NO_PASS1--}';
150 } elseif (strlen(postRequestParameter('pass1')) < getConfig('minium_admin_pass_length')) {
151 $pass1Message = '{--ADMIN_SHORT_PASS1--}';
154 // No password 2 entered or to short?
155 if (!isPostRequestParameterSet('pass2')) {
156 $pass2Message = '{--ADMIN_NO_PASS2--}';
157 } elseif (strlen(postRequestParameter('pass2')) < getConfig('minium_admin_pass_length')) {
158 $pass2Message = '{--ADMIN_SHORT_PASS2--}';
161 // Both didn't match?
162 if (postRequestParameter('pass1') != postRequestParameter('pass2')) {
164 if (empty($pass1Message)) $pass1Message = '{--ADMIN_PASS1_MISMATCH--}';
165 if (empty($pass2Message)) $pass2Message = '{--ADMIN_PASS2_MISMATCH--}';
168 // Output error messages
169 $content['login_message'] = loadTemplate('admin_login_msg', true, $loginMessage);
170 $content['pass1_message'] = loadTemplate('admin_login_msg', true, $pass1Message);
171 $content['pass2_message'] = loadTemplate('admin_login_msg', true, $pass2Message);
172 $content['error_message'] = loadTemplate('admin_login_msg', true, $errorMessage);
175 // Output message in seperate template
176 displayMessage('{--ADMIN_ACCOUNT_NOT_REGISTERED_YET--}');
178 // Load register template
179 loadTemplate('admin_reg_form', false, $content);
181 } elseif (isGetRequestParameterSet('reset_pass')) {
182 // Is the form submitted?
183 if ((isPostRequestParameterSet('send_link')) && (isPostRequestParameterSet('email'))) {
185 displayMessage(sendAdminPasswordResetLink(postRequestParameter('email')));
186 } elseif (isGetRequestParameterSet('hash')) {
187 // Output form for hash validation
188 loadTemplate('admin_validate_reset_hash_form', false, getRequestParameter('hash'));
189 } elseif ((isPostRequestParameterSet('validate_hash')) && (isPostRequestParameterSet('login')) && (isPostRequestParameterSet('hash'))) {
190 // Validate the login data and hash
191 $valid = adminResetValidateHashLogin(postRequestParameter('hash'), postRequestParameter('login'));
194 if ($valid === true) {
195 // Prepare content first
197 'hash' => postRequestParameter('hash'),
198 'login' => postRequestParameter('login')
201 // Validation okay so display form for final password change
202 loadTemplate('admin_reset_password_form', false, $content);
204 // Cannot validate the login data and hash
205 displayMessage('{--ADMIN_VALIDATION_RESET_LOGIN_HASH_FAILED--}');
207 } elseif ((isPostRequestParameterSet('reset_pass')) && (isPostRequestParameterSet('hash')) && (isPostRequestParameterSet('login')) && (isPostRequestParameterSet('pass1')) && (postRequestParameter('pass1') == postRequestParameter('pass2'))) {
208 // Okay, we shall the admin password here. So first revalidate the hash
209 if (adminResetValidateHashLogin(postRequestParameter('hash'), postRequestParameter('login'))) {
211 loadTemplate('admin_reset_password_done', false, doResetAdminPassword(postRequestParameter('login'), postRequestParameter('pass1')));
214 displayMessage('{--ADMIN_VALIDATION_RESET_LOGIN_HASH_FAILED2--}');
217 // Output reset password form
218 loadTemplate('admin_reset_password_send_link');
220 } elseif ((!isSessionVariableSet('admin_id')) || (!isSessionVariableSet('admin_md5')) || (!isSessionVariableSet('admin_last'))) {
221 // At leat one administrator account was created
222 if ((isSessionVariableSet('admin_id')) && (isSessionVariableSet('admin_md5')) && (isSessionVariableSet('admin_last'))) {
223 // Timeout for last login, we have to logout first!
224 redirectToUrl('modules.php?module=admin&logout=1');
227 if (isGetRequestParameterSet('register')) {
228 // Registration of first admin is done
229 if (getRequestParameter('register') == 'done') {
231 displayMessage('{--ADMIN_REGISTER_DONE--}');
235 // Check if the admin has submitted data or not
236 if ((isFormSent()) && ((!isPostRequestParameterSet('login')) || (!isPostRequestParameterSet('password')) || (strlen(postRequestParameter('password')) < getConfig('minium_admin_pass_length')))) {
237 setPostRequestParameter('ok', '***');
240 if ((isFormSent()) && (postRequestParameter('ok') != '***')) {
241 // All required data was entered so we check his account
242 $ret = ifAdminLoginDataIsValid(postRequestParameter('login'), postRequestParameter('password'));
244 // Which status do we have?
246 case 'done': // Admin and password are okay, so we log in now
247 // Construct URL and redirect
248 $url = 'modules.php?module=admin&';
250 // Rewrite overview module
251 if (getWhat() == 'overview') {
252 setAction(getActionFromModuleWhat(getModule(), getWhat()));
257 $url .= 'what=' . getWhat();
258 } elseif (isActionSet()) {
259 $url .= 'action=' . getAction();
260 } elseif (isGetRequestParameterSet('area')) {
261 $url .= 'area=' . getRequestParameter('area');
268 case '404': // Administrator login not found
269 setPostRequestParameter('ok', $ret);
270 $ret = '{%message,ADMIN_ACCOUNT_404=' . postRequestParameter('login') . '%}';
271 destroyAdminSession();
274 case 'password': // Wrong password
275 setPostRequestParameter('ok', $ret);
276 $ret = '{--WRONG_PASS--} [<a href="{%url=modules.php?module=admin&reset_pass=1%}">{--ADMIN_RESET_PASS--}</a>]';
277 destroyAdminSession();
280 default: // Others will be logged
281 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown return code %s from ifAdminLoginDataIsValid()", $ret));
287 if ($ret != 'done') {
288 $content['login'] = '';
289 if (isPostRequestParameterSet('login')) {
290 $content['login'] = postRequestParameter('login');
293 // Init array elements
294 $content['login_message'] = '';
295 $content['pass_message'] = '';
298 // Set messages to zero
303 if (!isPostRequestParameterSet('login')) {
305 $loginMessage = '{--ADMIN_NO_LOGIN--}';
306 } elseif ((!empty($ret)) && (postRequestParameter('ok') == '404')) {
307 // An error comes back from login?
308 $loginMessage = $ret;
311 // Check for password
312 if (!isPostRequestParameterSet('password')) {
313 // No password entered?
314 $passwdMessage = '{--ADMIN_NO_PASS--}';
315 } elseif (strlen(postRequestParameter('password')) < getConfig('minium_admin_pass_length')) {
316 // Or password too short?
317 $passwdMessage = '{--ADMIN_SHORT_PASS--}';
318 } elseif ((!empty($ret)) && (postRequestParameter('ok') == 'password')) {
319 // An error comes back from login?
320 $passwdMessage = $ret;
323 // Load message templates if the messages have been set
324 if (!empty($loginMessage)) {
325 $content['login_message'] = loadTemplate('admin_login_msg', true, $loginMessage);
327 if (!empty($passwdMessage)) {
328 $content['pass_message'] = loadTemplate('admin_login_msg', true, $passwdMessage);
334 // Restore old what value
335 $content = merge_array($content, array('target' => 'what', 'value' => getWhat()));
336 } elseif (isActionSet()) {
337 if (getAction() != 'logout') {
338 // Restore old action value
339 $content = merge_array($content, array('target' => 'action', 'value' => getAction()));
341 // Set default values
342 $content = merge_array($content, array('target' => 'action', 'value' => 'login'));
344 } elseif (isGetRequestParameterSet('area')) {
345 // Restore old area value
346 $content = merge_array(
350 'value' => getRequestParameter('area')
354 // Set default values
355 $content = merge_array($content, array('target' => 'action', 'value' => 'login'));
358 // Load login form template
359 loadTemplate('admin_login_form', false, $content);
361 } elseif (isGetRequestParameterSet('logout')) {
362 // Only try to remove cookies
363 if (destroyAdminSession()) {
364 // Load logout template
365 if (isGetRequestParameterSet('register')) {
367 $register = getRequestParameter('register');
369 // Special logout redirect for installation of given extension
370 loadTemplate(sprintf("admin_logout_%s_install", $register));
371 } elseif (isGetRequestParameterSet('remove')) {
373 $remove = getRequestParameter('remove');
375 // Special logout redirect for removal of given extension
376 loadTemplate(sprintf("admin_logout_%s_remove", $remove));
378 // Logged out normally
379 loadTemplate('admin_logout');
382 // Something went wrong here...
383 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_LOGOUT_FAILED--}');
386 addFatalMessage(__FILE__, __LINE__, '{--CANNOT_UNREG_SESS--}');
389 // Maybe an Admin want's to login?
390 $ret = ifAdminCookiesAreValid(getCurrentAdminId(), getAdminMd5());
395 // Check for access control line of current menu entry
396 runFilterChain('check_admin_acl');
398 // Check for version and switch between old menu system and new intelligent menu system
399 if ((adminGetMenuMode() == 'NEW') && (isIncludeReadable('inc/modules/admin/lasys-inc.php'))) {
400 // Default area is the entrance, of course
403 // Check for similar URL variable
404 if (isGetRequestParameterSet('area')) $area = getRequestParameter('area');
406 // Load logical-area menu-system file
407 loadIncludeOnce('inc/modules/admin/lasys-inc.php');
409 // Create new-style menu system will logical areas
410 doAdminLogicalArea($area, $action, getWhat());
412 // This little call constructs the whole default old and lacky menu system
413 // on left side. It also renders the content on right side
418 case '404': // Administrator login not found
419 setPostRequestParameter('ok', $ret);
420 displayMessage('{%message,ADMIN_ACCOUNT_404=' . getCurrentAdminId() . '%}');
421 destroyAdminSession();
424 case 'password': // Wrong password
425 setPostRequestParameter('ok', $ret);
426 displayMessage('{--WRONG_PASS--}');
427 destroyAdminSession();
430 default: // Others will be logged
431 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown return code %s from ifAdminCookiesAreValid()", $ret));