|
32 | 32 | require_once '../../lib/app.inc.php'; |
33 | 33 |
|
34 | 34 | // Check if we have an active users session and no login_as. |
35 | | -if($_SESSION['s']['user']['active'] == 1 && @$_POST['login_as'] != 1) { |
| 35 | +if ($_SESSION['s']['user']['active'] == 1 && @$_POST['login_as'] != 1) { |
36 | 36 | header('Location: /index.php'); |
37 | 37 | die(); |
38 | 38 | } |
|
49 | 49 | $maintenance_mode = false; |
50 | 50 | $maintenance_mode_error = ''; |
51 | 51 | $server_config_array = $app->getconf->get_global_config('misc'); |
52 | | -if($app->is_under_maintenance()) { |
| 52 | +if ($app->is_under_maintenance()) { |
53 | 53 | $maintenance_mode = true; |
54 | 54 | $maintenance_mode_error = $app->lng('error_maintenance_mode'); |
55 | 55 | } |
56 | 56 |
|
57 | 57 | //* Login Form was sent |
58 | | -if(count($_POST) > 0) { |
| 58 | +if (count($_POST) > 0) { |
59 | 59 |
|
60 | 60 | //** Check variables |
61 | | - if(!preg_match("/^[\w\.\-\_\@]{1,128}$/", $app->functions->idn_encode($_POST['username']))) $error = $app->lng('user_regex_error'); |
62 | | - if(!preg_match("/^.{1,256}$/i", $_POST['password'])) $error = $app->lng('pw_error_length'); |
| 61 | + if (!preg_match("/^[\w\.\-\_\@]{1,128}$/", $app->functions->idn_encode($_POST['username']))) $error = $app->lng('user_regex_error'); |
| 62 | + if (!preg_match("/^.{1,256}$/i", $_POST['password'])) $error = $app->lng('pw_error_length'); |
63 | 63 |
|
64 | 64 | //** importing variables |
65 | 65 | $ip = md5($_SERVER['REMOTE_ADDR']); |
66 | 66 | $username = $_POST['username']; |
67 | 67 | $password = $_POST['password']; |
68 | | - $loginAs = false; |
| 68 | + $loginAs = false; |
69 | 69 | $time = time(); |
70 | 70 |
|
71 | | - if($username != '' && $password != '' && $error == '') { |
| 71 | + if ($username != '' && $password != '' && $error == '') { |
72 | 72 | /* |
73 | 73 | * Check, if there is a "login as" instead of a "normal" login |
74 | 74 | */ |
75 | | - if (isset($_SESSION['s']['user']) && $_SESSION['s']['user']['active'] == 1){ |
| 75 | + if (isset($_SESSION['s']['user']) && $_SESSION['s']['user']['active'] == 1) { |
76 | 76 | /* |
77 | 77 | * only the admin or reseller can "login as" so if the user is NOT an admin or reseller, we |
78 | 78 | * open the startpage (after killing the old session), so the user |
|
84 | 84 | * has logged in as "normal" user before... |
85 | 85 | */ |
86 | 86 |
|
87 | | - if (isset($_SESSION['s_old'])&& ($_SESSION['s_old']['user']['typ'] == 'admin' || $app->auth->has_clients($_SESSION['s_old']['user']['userid']))){ |
| 87 | + if (isset($_SESSION['s_old']) && ($_SESSION['s_old']['user']['typ'] == 'admin' || $app->auth->has_clients($_SESSION['s_old']['user']['userid']))) { |
88 | 88 | /* The "old" user is admin or reseller, so everything is ok |
89 | 89 | * if he is reseller, we need to check if he logs in to one of his clients |
90 | 90 | */ |
91 | | - if($_SESSION['s_old']['user']['typ'] != 'admin') { |
| 91 | + if ($_SESSION['s_old']['user']['typ'] != 'admin') { |
92 | 92 |
|
93 | 93 | /* this is the one currently logged in (normal user) */ |
94 | 94 | $old_client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); |
|
100 | 100 | $client_group_id = $app->functions->intval($tmp['default_group']); |
101 | 101 | $tmp_client = $app->db->queryOneRecord("SELECT client.client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); |
102 | 102 |
|
103 | | - if(!$tmp_client || $old_client["parent_client_id"] != $tmp_client["client_id"] || $tmp["default_group"] != $_SESSION["s_old"]["user"]["default_group"] ) { |
| 103 | + if (!$tmp_client || $old_client["parent_client_id"] != $tmp_client["client_id"] || $tmp["default_group"] != $_SESSION["s_old"]["user"]["default_group"]) { |
104 | 104 | die("You don't have the right to 'login as' this user!"); |
105 | 105 | } |
106 | 106 | unset($old_client); |
107 | 107 | unset($tmp_client); |
108 | 108 | unset($tmp); |
109 | 109 | } |
110 | | - } |
111 | | - else { |
| 110 | + } else { |
112 | 111 | die("You don't have the right to 'login as'!"); |
113 | 112 | } |
114 | | - } elseif($_SESSION['s']['user']['typ'] != 'admin' && (!isset($_SESSION['s_old']['user']) || $_SESSION['s_old']['user']['typ'] != 'admin')) { |
| 113 | + } elseif ($_SESSION['s']['user']['typ'] != 'admin' && (!isset($_SESSION['s_old']['user']) || $_SESSION['s_old']['user']['typ'] != 'admin')) { |
115 | 114 | /* a reseller wants to 'login as', we need to check if he is allowed to */ |
116 | 115 | $res_client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); |
117 | 116 | $res_client = $app->db->queryOneRecord("SELECT client.client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $res_client_group_id); |
|
121 | 120 | $tmp = $app->db->queryOneRecord($sql, (string)$username, (string)$password); |
122 | 121 | $tmp_client = $app->db->queryOneRecord("SELECT client.client_id, client.parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $tmp["default_group"]); |
123 | 122 |
|
124 | | - if(!$tmp || $tmp_client["parent_client_id"] != $res_client["client_id"]) { |
| 123 | + if (!$tmp || $tmp_client["parent_client_id"] != $res_client["client_id"]) { |
125 | 124 | die("You don't have the right to login as this user!"); |
126 | 125 | } |
127 | 126 | unset($res_client); |
|
140 | 139 | $alreadyfailed = $app->db->queryOneRecord($sql, $ip); |
141 | 140 |
|
142 | 141 | //* too many failed logins |
143 | | - if($alreadyfailed['times'] > 5) { |
| 142 | + if ($alreadyfailed['times'] > 5) { |
144 | 143 | $error = $app->lng('error_user_too_many_logins'); |
145 | 144 | } else { |
146 | 145 |
|
147 | | - if ($loginAs){ |
| 146 | + if ($loginAs) { |
148 | 147 | $sql = "SELECT * FROM sys_user WHERE USERNAME = ? and PASSWORT = ?"; |
149 | 148 | $user = $app->db->queryOneRecord($sql, (string)$username, (string)$password); |
150 | 149 | } else { |
151 | 150 |
|
152 | | - if(stristr($username, '@')) { |
| 151 | + if (stristr($username, '@')) { |
153 | 152 | //* mailuser login |
154 | 153 | $sql = "SELECT * FROM mail_user WHERE login = ? or email = ?"; |
155 | 154 | $mailuser = $app->db->queryOneRecord($sql, (string)$username, $app->functions->idn_encode($username)); |
156 | 155 | $user = false; |
157 | | - if($mailuser) { |
| 156 | + if ($mailuser) { |
158 | 157 | $saved_password = stripslashes($mailuser['password']); |
159 | 158 | //* Check if mailuser password is correct |
160 | | - if(crypt(stripslashes($password), $saved_password) == $saved_password) { |
| 159 | + if (crypt(stripslashes($password), $saved_password) == $saved_password) { |
161 | 160 | //* Get the sys_user language of the client of the mailuser |
162 | | - $sys_user_lang = $app->db->queryOneRecord("SELECT language FROM sys_user WHERE default_group = ?", $mailuser['sys_groupid'] ); |
| 161 | + $sys_user_lang = $app->db->queryOneRecord("SELECT language FROM sys_user WHERE default_group = ?", $mailuser['sys_groupid']); |
163 | 162 |
|
164 | 163 | //* we build a fake user here which has access to the mailuser module only and userid 0 |
165 | 164 | $user = array(); |
|
170 | 169 | $user['typ'] = 'user'; |
171 | 170 | $user['email'] = $mailuser['email']; |
172 | 171 | $user['username'] = $username; |
173 | | - if(is_array($sys_user_lang) && $sys_user_lang['language'] != '') { |
| 172 | + if (is_array($sys_user_lang) && $sys_user_lang['language'] != '') { |
174 | 173 | $user['language'] = $sys_user_lang['language']; |
175 | 174 | } else { |
176 | 175 | $user['language'] = $conf['language']; |
|
185 | 184 | //* normal cp user login |
186 | 185 | $sql = "SELECT * FROM sys_user WHERE USERNAME = ?"; |
187 | 186 | $user = $app->db->queryOneRecord($sql, (string)$username); |
188 | | - if($user) { |
| 187 | + if ($user) { |
189 | 188 | $saved_password = stripslashes($user['passwort']); |
190 | | - if(substr($saved_password, 0, 1) == '$') { |
| 189 | + if (substr($saved_password, 0, 1) == '$') { |
191 | 190 | //* The password is encrypted with crypt |
192 | | - if(crypt(stripslashes($password), $saved_password) != $saved_password) { |
| 191 | + if (crypt(stripslashes($password), $saved_password) != $saved_password) { |
193 | 192 | $user = false; |
194 | 193 | } |
195 | 194 | } else { |
196 | 195 | //* The password is md5 encrypted |
197 | | - if(md5($password) != $saved_password) { |
| 196 | + if (md5($password) != $saved_password) { |
198 | 197 | $user = false; |
199 | 198 | } else { |
200 | 199 | // update password with secure algo |
|
208 | 207 | } |
209 | 208 | } |
210 | 209 |
|
211 | | - if($user) { |
212 | | - if($user['active'] == 1) { |
| 210 | + if ($user) { |
| 211 | + if ($user['active'] == 1) { |
213 | 212 | // Maintenance mode - allow logins only when maintenance mode is off or if the user is admin |
214 | | - if(!$app->is_under_maintenance() || $user['typ'] == 'admin'){ |
| 213 | + if (!$app->is_under_maintenance() || $user['typ'] == 'admin') { |
215 | 214 |
|
216 | 215 | // User login right, so attempts can be deleted |
217 | 216 | $sql = "DELETE FROM `attempts_login` WHERE `ip`=?"; |
|
225 | 224 | // this problem. |
226 | 225 | $app->uses('getconf'); |
227 | 226 | $security_config = $app->getconf->get_security_config('permissions'); |
228 | | - if(isset($security_config['session_regenerate_id']) && $security_config['session_regenerate_id'] == 'yes') { |
| 227 | + if (isset($security_config['session_regenerate_id']) && $security_config['session_regenerate_id'] == 'yes') { |
229 | 228 | if (!$loginAs) session_regenerate_id(true); |
230 | 229 | } |
231 | 230 | $_SESSION = array(); |
|
236 | 235 | $_SESSION["s"]['theme'] = $_SESSION['s']['user']['theme']; |
237 | 236 | if ($loginAs) $_SESSION['s']['plugin_cache'] = $_SESSION['s_old']['plugin_cache']; |
238 | 237 |
|
239 | | - if(is_file(ISPC_WEB_PATH . '/' . $_SESSION['s']['user']['startmodule'].'/lib/module.conf.php')) { |
240 | | - include_once $app->functions->check_include_path(ISPC_WEB_PATH . '/' . $_SESSION['s']['user']['startmodule'].'/lib/module.conf.php'); |
241 | | - $menu_dir = ISPC_WEB_PATH.'/' . $_SESSION['s']['user']['startmodule'] . '/lib/menu.d'; |
242 | | - if (is_dir($menu_dir)) { |
| 238 | + if (is_file(ISPC_WEB_PATH.'/'.$_SESSION['s']['user']['startmodule'].'/lib/module.conf.php')) { |
| 239 | + include_once $app->functions->check_include_path(ISPC_WEB_PATH.'/'.$_SESSION['s']['user']['startmodule'].'/lib/module.conf.php'); |
| 240 | + $menu_dir = ISPC_WEB_PATH.'/'.$_SESSION['s']['user']['startmodule'].'/lib/menu.d'; |
| 241 | + if (is_dir($menu_dir)) { |
243 | 242 | if ($dh = opendir($menu_dir)) { |
244 | 243 | //** Go through all files in the menu dir |
245 | 244 | while (($file = readdir($dh)) !== false) { |
246 | 245 | if ($file != '.' && $file != '..' && substr($file, -9, 9) == '.menu.php' && $file != 'dns_resync.menu.php') { |
247 | | - include_once $menu_dir . '/' . $file; |
| 246 | + include_once $menu_dir.'/'.$file; |
248 | 247 | } |
249 | 248 | } |
250 | 249 | } |
251 | 250 | } |
252 | 251 | $_SESSION['s']['module'] = $module; |
253 | 252 | } |
254 | | - // check if the user theme is valid |
255 | | - if($_SESSION['s']['user']['theme'] != 'default') { |
| 253 | + // check if the user theme is valid |
| 254 | + if ($_SESSION['s']['user']['theme'] != 'default') { |
256 | 255 | $tmp_path = ISPC_THEMES_PATH."/".$_SESSION['s']['user']['theme']; |
257 | | - if(!@is_dir($tmp_path) || !@file_exists($tmp_path."/ispconfig_version") || trim(file_get_contents($tmp_path."/ispconfig_version")) != ISPC_APP_VERSION) { |
| 256 | + if (!@is_dir($tmp_path) || !@file_exists($tmp_path."/ispconfig_version") || trim(file_get_contents($tmp_path."/ispconfig_version")) != ISPC_APP_VERSION) { |
258 | 257 | // fall back to default theme if this one is not compatible with current ispc version |
259 | 258 | $_SESSION['s']['user']['theme'] = 'default'; |
260 | 259 | $_SESSION['s']['theme'] = 'default'; |
|
265 | 264 | $app->plugin->raiseEvent('login', $username); |
266 | 265 |
|
267 | 266 | //* Save successful login message to var |
268 | | - $authlog = 'Successful login for user \''. $username .'\' from '. $_SERVER['REMOTE_ADDR'] .' at '. date('Y-m-d H:i:s') . ' with session ID ' .session_id(); |
| 267 | + $authlog = 'Successful login for user \''.$username.'\' from '.$_SERVER['REMOTE_ADDR'].' at '.date('Y-m-d H:i:s').' with session ID '.session_id(); |
269 | 268 | $authlog_handle = fopen($conf['ispconfig_log_dir'].'/auth.log', 'a'); |
270 | | - fwrite($authlog_handle, $authlog ."\n"); |
| 269 | + fwrite($authlog_handle, $authlog."\n"); |
271 | 270 | fclose($authlog_handle); |
272 | 271 |
|
273 | 272 | /* |
274 | 273 | * We need LOGIN_REDIRECT instead of HEADER_REDIRECT to load the |
275 | 274 | * new theme, if the logged-in user has another |
276 | 275 | */ |
277 | 276 |
|
278 | | - if ($loginAs){ |
| 277 | + if ($loginAs) { |
279 | 278 | echo 'LOGIN_REDIRECT:'.$_SESSION['s']['module']['startpage']; |
280 | 279 | exit; |
281 | 280 | } else { |
|
287 | 286 | $error = $app->lng('error_user_blocked'); |
288 | 287 | } |
289 | 288 | } else { |
290 | | - if(!$alreadyfailed['times'] ) |
291 | | - { |
| 289 | + if (!$alreadyfailed['times']) { |
292 | 290 | //* user login the first time wrong |
293 | 291 | $sql = "INSERT INTO `attempts_login` (`ip`, `times`, `login_time`) VALUES (?, 1, NOW())"; |
294 | 292 | $app->db->query($sql, $ip); |
295 | | - } elseif($alreadyfailed['times'] >= 1) { |
| 293 | + } elseif ($alreadyfailed['times'] >= 1) { |
296 | 294 | //* update times wrong |
297 | 295 | $sql = "UPDATE `attempts_login` SET `times`=`times`+1, `login_time`=NOW() WHERE `ip` = ? AND `login_time` < NOW() ORDER BY `login_time` DESC LIMIT 1"; |
298 | 296 | $app->db->query($sql, $ip); |
299 | 297 | } |
300 | 298 | //* Incorrect login - Username and password incorrect |
301 | 299 | $error = $app->lng('error_user_password_incorrect'); |
302 | | - if($app->db->errorMessage != '') $error .= '<br />'.$app->db->errorMessage != ''; |
| 300 | + if ($app->db->errorMessage != '') $error .= '<br />'.$app->db->errorMessage != ''; |
303 | 301 |
|
304 | 302 | $app->plugin->raiseEvent('login_failed', $username); |
305 | 303 | //* Save failed login message to var |
306 | | - $authlog = 'Failed login for user \''. $username .'\' from '. $_SERVER['REMOTE_ADDR'] .' at '. date('Y-m-d H:i:s'); |
| 304 | + $authlog = 'Failed login for user \''.$username.'\' from '.$_SERVER['REMOTE_ADDR'].' at '.date('Y-m-d H:i:s'); |
307 | 305 | $authlog_handle = fopen($conf['ispconfig_log_dir'].'/auth.log', 'a'); |
308 | | - fwrite($authlog_handle, $authlog ."\n"); |
| 306 | + fwrite($authlog_handle, $authlog."\n"); |
309 | 307 | fclose($authlog_handle); |
310 | 308 | } |
311 | 309 | } |
312 | | - } else { |
| 310 | + } else { |
313 | 311 | //* Username or password empty |
314 | | - if($error == '') $error = $app->lng('error_user_password_empty'); |
315 | | - $app->plugin->raiseEvent('login_empty', $username); |
| 312 | + if ($error == '') $error = $app->lng('error_user_password_empty'); |
| 313 | + $app->plugin->raiseEvent('login_empty', $username); |
316 | 314 | } |
317 | 315 | } |
318 | 316 |
|
319 | 317 | // Maintenance mode - show message when people try to log in and also when people are forcibly logged off |
320 | | -if($maintenance_mode_error != '') $error = '<strong>'.$maintenance_mode_error.'</strong><br><br>'.$error; |
321 | | -if($error != ''){ |
| 318 | +if ($maintenance_mode_error != '') $error = '<strong>'.$maintenance_mode_error.'</strong><br><br>'.$error; |
| 319 | +if ($error != '') { |
322 | 320 | $error = '<div class="box box_error">'.$error.'</div>'; |
323 | 321 | } |
324 | 322 |
|
325 | 323 | $app->load('getconf'); |
326 | 324 | $sys_config = $app->getconf->get_global_config('misc'); |
327 | 325 |
|
328 | 326 | $security_config = $app->getconf->get_security_config('permissions'); |
329 | | -if($security_config['password_reset_allowed'] == 'yes') { |
| 327 | +if ($security_config['password_reset_allowed'] == 'yes') { |
330 | 328 | $app->tpl->setVar('pw_lost_show', 1); |
331 | 329 | } else { |
332 | 330 | $app->tpl->setVar('pw_lost_show', 0); |
|
348 | 346 |
|
349 | 347 | // Logo |
350 | 348 | $logo = $app->db->queryOneRecord("SELECT * FROM sys_ini WHERE sysini_id = 1"); |
351 | | -if($logo['custom_logo'] != ''){ |
| 349 | +if ($logo['custom_logo'] != '') { |
352 | 350 | $base64_logo_txt = $logo['custom_logo']; |
353 | 351 | } else { |
354 | 352 | $base64_logo_txt = $logo['default_logo']; |
|
361 | 359 |
|
362 | 360 | // Title |
363 | 361 | if (!empty($sys_config['company_name'])) { |
364 | | - $app->tpl->setVar('company_name', $sys_config['company_name']. ' :: '); |
| 362 | + $app->tpl->setVar('company_name', $sys_config['company_name'].' :: '); |
365 | 363 | } |
366 | 364 |
|
367 | 365 | // Custom Login |
368 | 366 | if ($sys_config['custom_login_text'] != '') { |
369 | | - $custom_login = @($sys_config['custom_login_link'] != '')?'<a href="'.$sys_config['custom_login_link'].'" target="_blank">'.$sys_config['custom_login_text'].'</a>':$sys_config['custom_login_text']; |
| 367 | + $custom_login = @($sys_config['custom_login_link'] != '') ? '<a href="'.$sys_config['custom_login_link'].'" target="_blank">'.$sys_config['custom_login_text'].'</a>' : $sys_config['custom_login_text']; |
370 | 368 | } |
371 | 369 | $app->tpl->setVar('custom_login', $custom_login); |
372 | 370 |
|
|
0 commit comments