|
83 | 83 | * The actual user is NOT a admin or reseller, but maybe he |
84 | 84 | * has logged in as "normal" user before... |
85 | 85 | */ |
86 | | - |
| 86 | + |
87 | 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 | 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"]); |
95 | 95 | $old_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 = ?", $old_client_group_id); |
96 | | - |
| 96 | + |
97 | 97 | /* this is the reseller, that shall be re-logged in */ |
98 | 98 | $sql = "SELECT * FROM sys_user WHERE USERNAME = ? and PASSWORT = ?"; |
99 | 99 | $tmp = $app->db->queryOneRecord($sql, $username, $password); |
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 | 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 | } |
|
115 | 115 | /* a reseller wants to 'login as', we need to check if he is allowed to */ |
116 | 116 | $res_client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); |
117 | 117 | $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); |
118 | | - |
| 118 | + |
119 | 119 | /* this is the user the reseller wants to 'login as' */ |
120 | 120 | $sql = "SELECT * FROM sys_user WHERE USERNAME = ? and PASSWORT = ?"; |
121 | 121 | $tmp = $app->db->queryOneRecord($sql, $username, $password); |
122 | 122 | $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 | | - |
| 123 | + |
124 | 124 | if(!$tmp || $tmp_client["parent_client_id"] != $res_client["client_id"]) { |
125 | 125 | die("You don't have the right to login as this user!"); |
126 | 126 | } |
|
129 | 129 | unset($tmp_client); |
130 | 130 | } |
131 | 131 | $loginAs = true; |
132 | | - |
| 132 | + |
133 | 133 | } else { |
134 | 134 | /* normal login */ |
135 | 135 | $loginAs = false; |
136 | 136 | } |
137 | | - |
| 137 | + |
138 | 138 | //* Check if there are already wrong logins |
139 | 139 | $sql = "SELECT * FROM `attempts_login` WHERE `ip`= ? AND `login_time` > (NOW() - INTERVAL 1 MINUTE) LIMIT 1"; |
140 | 140 | $alreadyfailed = $app->db->queryOneRecord($sql, $ip); |
141 | | - |
| 141 | + |
142 | 142 | //* too many failedlogins |
143 | 143 | if($alreadyfailed['times'] > 5) { |
144 | 144 | $error = $app->lng('error_user_too_many_logins'); |
|
148 | 148 | $sql = "SELECT * FROM sys_user WHERE USERNAME = ? and PASSWORT = ?"; |
149 | 149 | $user = $app->db->queryOneRecord($sql, $username, $password); |
150 | 150 | } else { |
151 | | - |
| 151 | + |
152 | 152 | if(stristr($username, '@')) { |
153 | 153 | //* mailuser login |
154 | 154 | $sql = "SELECT * FROM mail_user WHERE login = ? or email = ?"; |
|
160 | 160 | if(crypt(stripslashes($password), $saved_password) == $saved_password) { |
161 | 161 | //* Get the sys_user language of the client of the mailuser |
162 | 162 | $sys_user_lang = $app->db->queryOneRecord("SELECT language FROM sys_user WHERE default_group = ?", $mailuser['sys_groupid'] ); |
163 | | - |
| 163 | + |
164 | 164 | //* we build a fake user here which has access to the mailuser module only and userid 0 |
165 | 165 | $user = array(); |
166 | 166 | $user['userid'] = 0; |
|
196 | 196 | //* The password is md5 encrypted |
197 | 197 | if(md5($password) != $saved_password) { |
198 | 198 | $user = false; |
| 199 | + } else { |
| 200 | + // update password with secure algo |
| 201 | + $sql = 'UPDATE `sys_user` SET `passwort` = ? WHERE `username` = ?'; |
| 202 | + $app->db->query($sql, $app->auth->crypt_password($password), $username); |
199 | 203 | } |
200 | 204 | } |
201 | 205 | } else { |
202 | 206 | $user = false; |
203 | 207 | } |
204 | 208 | } |
205 | 209 | } |
206 | | - |
| 210 | + |
207 | 211 | if($user) { |
208 | 212 | if($user['active'] == 1) { |
209 | 213 | // Maintenance mode - allow logins only when maintenance mode is off or if the user is admin |
210 | 214 | if(!$app->is_under_maintenance() || $user['typ'] == 'admin'){ |
211 | | - |
| 215 | + |
212 | 216 | // User login right, so attempts can be deleted |
213 | 217 | $sql = "DELETE FROM `attempts_login` WHERE `ip`=?"; |
214 | 218 | $app->db->query($sql, $ip); |
215 | 219 | $user = $app->db->toLower($user); |
216 | | - |
| 220 | + |
217 | 221 | if ($loginAs) $oldSession = $_SESSION['s']; |
218 | | - |
| 222 | + |
219 | 223 | // Session regenerate causes login problems on some systems, see Issue #3827 |
220 | 224 | // Set session_regenerate_id to no in security settings, it you encounter |
221 | 225 | // this problem. |
|
231 | 235 | $_SESSION['s']['language'] = $app->functions->check_language($user['language']); |
232 | 236 | $_SESSION["s"]['theme'] = $_SESSION['s']['user']['theme']; |
233 | 237 | if ($loginAs) $_SESSION['s']['plugin_cache'] = $_SESSION['s_old']['plugin_cache']; |
234 | | - |
| 238 | + |
235 | 239 | if(is_file(ISPC_WEB_PATH . '/' . $_SESSION['s']['user']['startmodule'].'/lib/module.conf.php')) { |
236 | 240 | include_once $app->functions->check_include_path(ISPC_WEB_PATH . '/' . $_SESSION['s']['user']['startmodule'].'/lib/module.conf.php'); |
237 | 241 | $menu_dir = ISPC_WEB_PATH.'/' . $_SESSION['s']['user']['startmodule'] . '/lib/menu.d'; |
|
257 | 261 | $_SESSION['show_error_msg'] = $app->lng('theme_not_compatible'); |
258 | 262 | } |
259 | 263 | } |
260 | | - |
| 264 | + |
261 | 265 | $app->plugin->raiseEvent('login', $username); |
262 | | - |
| 266 | + |
263 | 267 | //* Save successfull login message to var |
264 | | - $authlog = 'Successful login for user \''. $username .'\' from '. $_SERVER['REMOTE_ADDR'] .' at '. date('Y-m-d H:i:s') . ' with session ID ' .session_id(); |
| 268 | + $authlog = 'Successful login for user \''. $username .'\' from '. $_SERVER['REMOTE_ADDR'] .' at '. date('Y-m-d H:i:s') . ' with session ID ' .session_id(); |
265 | 269 | $authlog_handle = fopen($conf['ispconfig_log_dir'].'/auth.log', 'a'); |
266 | 270 | fwrite($authlog_handle, $authlog ."\n"); |
267 | 271 | fclose($authlog_handle); |
268 | | - |
| 272 | + |
269 | 273 | /* |
270 | 274 | * We need LOGIN_REDIRECT instead of HEADER_REDIRECT to load the |
271 | 275 | * new theme, if the logged-in user has another |
272 | 276 | */ |
273 | | - |
| 277 | + |
274 | 278 | if ($loginAs){ |
275 | 279 | echo 'LOGIN_REDIRECT:'.$_SESSION['s']['module']['startpage']; |
276 | 280 | exit; |
|
327 | 331 | } else { |
328 | 332 | $app->tpl->setVar('pw_lost_show', 0); |
329 | 333 | } |
330 | | - |
| 334 | + |
331 | 335 | $app->tpl->setVar('error', $error); |
332 | 336 | $app->tpl->setVar('error_txt', $app->lng('error_txt')); |
333 | 337 | $app->tpl->setVar('login_txt', $app->lng('login_txt')); |
|
0 commit comments