Skip to content

Commit 2d27353

Browse files
committed
Cosmetic: Code format.
1 parent d3f3b3e commit 2d27353

File tree

2 files changed

+62
-64
lines changed

2 files changed

+62
-64
lines changed

interface/web/capp.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,39 +37,39 @@
3737
$redirect = (isset($_REQUEST["redirect"]) ? $_REQUEST["redirect"] : '');
3838

3939
//* Check if user is logged in
40-
if($_SESSION["s"]["user"]['active'] != 1) {
40+
if ($_SESSION["s"]["user"]['active'] != 1) {
4141
die("URL_REDIRECT: /index.php");
4242
//die();
4343
}
4444

45-
if(!preg_match("/^[a-z]{2,20}$/i", $mod)) die('module name contains unallowed chars.');
46-
if($redirect != '' && !preg_match("/^[a-z0-9]+\/[a-z0-9_\.\-]+\?id=[0-9]{1,9}(\&type=[a-z0-9_\.\-]+)?$/i", $redirect)) die('redirect contains unallowed chars.');
45+
if (!preg_match("/^[a-z]{2,20}$/i", $mod)) die('module name contains unallowed chars.');
46+
if ($redirect != '' && !preg_match("/^[a-z0-9]+\/[a-z0-9_\.\-]+\?id=[0-9]{1,9}(\&type=[a-z0-9_\.\-]+)?$/i", $redirect)) die('redirect contains unallowed chars.');
4747

4848
//* Check if user may use the module.
4949
$user_modules = explode(",", $_SESSION["s"]["user"]["modules"]);
5050

51-
if(!in_array($mod, $user_modules)) $app->error($app->lng(301));
51+
if (!in_array($mod, $user_modules)) $app->error($app->lng(301));
5252

5353
//* Load module configuration into the session.
54-
if(is_file($mod."/lib/module.conf.php")) {
54+
if (is_file($mod."/lib/module.conf.php")) {
5555
include_once $mod."/lib/module.conf.php";
5656

57-
$menu_dir = ISPC_WEB_PATH.'/' . $mod . '/lib/menu.d';
57+
$menu_dir = ISPC_WEB_PATH.'/'.$mod.'/lib/menu.d';
5858

5959
if (is_dir($menu_dir)) {
6060
if ($dh = opendir($menu_dir)) {
6161
//** Go through all files in the menu dir
6262
while (($file = readdir($dh)) !== false) {
6363
if ($file != '.' && $file != '..' && substr($file, -9, 9) == '.menu.php' && $file != 'dns_resync.menu.php') {
64-
include_once $menu_dir . '/' . $file;
64+
include_once $menu_dir.'/'.$file;
6565
}
6666
}
6767
}
6868
}
6969

7070
$_SESSION["s"]["module"] = $module;
7171
session_write_close();
72-
if($redirect == ''){
72+
if ($redirect == '') {
7373
echo "HEADER_REDIRECT:".$_SESSION["s"]["module"]["startpage"];
7474
} else {
7575
//* If we click on a search result, load that one instead of the module's start page

interface/web/login/index.php

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
require_once '../../lib/app.inc.php';
3333

3434
// 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) {
3636
header('Location: /index.php');
3737
die();
3838
}
@@ -49,30 +49,30 @@
4949
$maintenance_mode = false;
5050
$maintenance_mode_error = '';
5151
$server_config_array = $app->getconf->get_global_config('misc');
52-
if($app->is_under_maintenance()) {
52+
if ($app->is_under_maintenance()) {
5353
$maintenance_mode = true;
5454
$maintenance_mode_error = $app->lng('error_maintenance_mode');
5555
}
5656

5757
//* Login Form was sent
58-
if(count($_POST) > 0) {
58+
if (count($_POST) > 0) {
5959

6060
//** 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');
6363

6464
//** importing variables
6565
$ip = md5($_SERVER['REMOTE_ADDR']);
6666
$username = $_POST['username'];
6767
$password = $_POST['password'];
68-
$loginAs = false;
68+
$loginAs = false;
6969
$time = time();
7070

71-
if($username != '' && $password != '' && $error == '') {
71+
if ($username != '' && $password != '' && $error == '') {
7272
/*
7373
* Check, if there is a "login as" instead of a "normal" login
7474
*/
75-
if (isset($_SESSION['s']['user']) && $_SESSION['s']['user']['active'] == 1){
75+
if (isset($_SESSION['s']['user']) && $_SESSION['s']['user']['active'] == 1) {
7676
/*
7777
* only the admin or reseller can "login as" so if the user is NOT an admin or reseller, we
7878
* open the startpage (after killing the old session), so the user
@@ -84,11 +84,11 @@
8484
* has logged in as "normal" user before...
8585
*/
8686

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']))) {
8888
/* The "old" user is admin or reseller, so everything is ok
8989
* if he is reseller, we need to check if he logs in to one of his clients
9090
*/
91-
if($_SESSION['s_old']['user']['typ'] != 'admin') {
91+
if ($_SESSION['s_old']['user']['typ'] != 'admin') {
9292

9393
/* this is the one currently logged in (normal user) */
9494
$old_client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
@@ -100,18 +100,17 @@
100100
$client_group_id = $app->functions->intval($tmp['default_group']);
101101
$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);
102102

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"]) {
104104
die("You don't have the right to 'login as' this user!");
105105
}
106106
unset($old_client);
107107
unset($tmp_client);
108108
unset($tmp);
109109
}
110-
}
111-
else {
110+
} else {
112111
die("You don't have the right to 'login as'!");
113112
}
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')) {
115114
/* a reseller wants to 'login as', we need to check if he is allowed to */
116115
$res_client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
117116
$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,7 +120,7 @@
121120
$tmp = $app->db->queryOneRecord($sql, (string)$username, (string)$password);
122121
$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"]);
123122

124-
if(!$tmp || $tmp_client["parent_client_id"] != $res_client["client_id"]) {
123+
if (!$tmp || $tmp_client["parent_client_id"] != $res_client["client_id"]) {
125124
die("You don't have the right to login as this user!");
126125
}
127126
unset($res_client);
@@ -140,26 +139,26 @@
140139
$alreadyfailed = $app->db->queryOneRecord($sql, $ip);
141140

142141
//* too many failed logins
143-
if($alreadyfailed['times'] > 5) {
142+
if ($alreadyfailed['times'] > 5) {
144143
$error = $app->lng('error_user_too_many_logins');
145144
} else {
146145

147-
if ($loginAs){
146+
if ($loginAs) {
148147
$sql = "SELECT * FROM sys_user WHERE USERNAME = ? and PASSWORT = ?";
149148
$user = $app->db->queryOneRecord($sql, (string)$username, (string)$password);
150149
} else {
151150

152-
if(stristr($username, '@')) {
151+
if (stristr($username, '@')) {
153152
//* mailuser login
154153
$sql = "SELECT * FROM mail_user WHERE login = ? or email = ?";
155154
$mailuser = $app->db->queryOneRecord($sql, (string)$username, $app->functions->idn_encode($username));
156155
$user = false;
157-
if($mailuser) {
156+
if ($mailuser) {
158157
$saved_password = stripslashes($mailuser['password']);
159158
//* Check if mailuser password is correct
160-
if(crypt(stripslashes($password), $saved_password) == $saved_password) {
159+
if (crypt(stripslashes($password), $saved_password) == $saved_password) {
161160
//* 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']);
163162

164163
//* we build a fake user here which has access to the mailuser module only and userid 0
165164
$user = array();
@@ -170,7 +169,7 @@
170169
$user['typ'] = 'user';
171170
$user['email'] = $mailuser['email'];
172171
$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'] != '') {
174173
$user['language'] = $sys_user_lang['language'];
175174
} else {
176175
$user['language'] = $conf['language'];
@@ -185,16 +184,16 @@
185184
//* normal cp user login
186185
$sql = "SELECT * FROM sys_user WHERE USERNAME = ?";
187186
$user = $app->db->queryOneRecord($sql, (string)$username);
188-
if($user) {
187+
if ($user) {
189188
$saved_password = stripslashes($user['passwort']);
190-
if(substr($saved_password, 0, 1) == '$') {
189+
if (substr($saved_password, 0, 1) == '$') {
191190
//* The password is encrypted with crypt
192-
if(crypt(stripslashes($password), $saved_password) != $saved_password) {
191+
if (crypt(stripslashes($password), $saved_password) != $saved_password) {
193192
$user = false;
194193
}
195194
} else {
196195
//* The password is md5 encrypted
197-
if(md5($password) != $saved_password) {
196+
if (md5($password) != $saved_password) {
198197
$user = false;
199198
} else {
200199
// update password with secure algo
@@ -208,10 +207,10 @@
208207
}
209208
}
210209

211-
if($user) {
212-
if($user['active'] == 1) {
210+
if ($user) {
211+
if ($user['active'] == 1) {
213212
// 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') {
215214

216215
// User login right, so attempts can be deleted
217216
$sql = "DELETE FROM `attempts_login` WHERE `ip`=?";
@@ -225,7 +224,7 @@
225224
// this problem.
226225
$app->uses('getconf');
227226
$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') {
229228
if (!$loginAs) session_regenerate_id(true);
230229
}
231230
$_SESSION = array();
@@ -236,25 +235,25 @@
236235
$_SESSION["s"]['theme'] = $_SESSION['s']['user']['theme'];
237236
if ($loginAs) $_SESSION['s']['plugin_cache'] = $_SESSION['s_old']['plugin_cache'];
238237

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)) {
243242
if ($dh = opendir($menu_dir)) {
244243
//** Go through all files in the menu dir
245244
while (($file = readdir($dh)) !== false) {
246245
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;
248247
}
249248
}
250249
}
251250
}
252251
$_SESSION['s']['module'] = $module;
253252
}
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') {
256255
$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) {
258257
// fall back to default theme if this one is not compatible with current ispc version
259258
$_SESSION['s']['user']['theme'] = 'default';
260259
$_SESSION['s']['theme'] = 'default';
@@ -265,17 +264,17 @@
265264
$app->plugin->raiseEvent('login', $username);
266265

267266
//* 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();
269268
$authlog_handle = fopen($conf['ispconfig_log_dir'].'/auth.log', 'a');
270-
fwrite($authlog_handle, $authlog ."\n");
269+
fwrite($authlog_handle, $authlog."\n");
271270
fclose($authlog_handle);
272271

273272
/*
274273
* We need LOGIN_REDIRECT instead of HEADER_REDIRECT to load the
275274
* new theme, if the logged-in user has another
276275
*/
277276

278-
if ($loginAs){
277+
if ($loginAs) {
279278
echo 'LOGIN_REDIRECT:'.$_SESSION['s']['module']['startpage'];
280279
exit;
281280
} else {
@@ -287,46 +286,45 @@
287286
$error = $app->lng('error_user_blocked');
288287
}
289288
} else {
290-
if(!$alreadyfailed['times'] )
291-
{
289+
if (!$alreadyfailed['times']) {
292290
//* user login the first time wrong
293291
$sql = "INSERT INTO `attempts_login` (`ip`, `times`, `login_time`) VALUES (?, 1, NOW())";
294292
$app->db->query($sql, $ip);
295-
} elseif($alreadyfailed['times'] >= 1) {
293+
} elseif ($alreadyfailed['times'] >= 1) {
296294
//* update times wrong
297295
$sql = "UPDATE `attempts_login` SET `times`=`times`+1, `login_time`=NOW() WHERE `ip` = ? AND `login_time` < NOW() ORDER BY `login_time` DESC LIMIT 1";
298296
$app->db->query($sql, $ip);
299297
}
300298
//* Incorrect login - Username and password incorrect
301299
$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 != '';
303301

304302
$app->plugin->raiseEvent('login_failed', $username);
305303
//* 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');
307305
$authlog_handle = fopen($conf['ispconfig_log_dir'].'/auth.log', 'a');
308-
fwrite($authlog_handle, $authlog ."\n");
306+
fwrite($authlog_handle, $authlog."\n");
309307
fclose($authlog_handle);
310308
}
311309
}
312-
} else {
310+
} else {
313311
//* 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);
316314
}
317315
}
318316

319317
// 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 != '') {
322320
$error = '<div class="box box_error">'.$error.'</div>';
323321
}
324322

325323
$app->load('getconf');
326324
$sys_config = $app->getconf->get_global_config('misc');
327325

328326
$security_config = $app->getconf->get_security_config('permissions');
329-
if($security_config['password_reset_allowed'] == 'yes') {
327+
if ($security_config['password_reset_allowed'] == 'yes') {
330328
$app->tpl->setVar('pw_lost_show', 1);
331329
} else {
332330
$app->tpl->setVar('pw_lost_show', 0);
@@ -348,7 +346,7 @@
348346

349347
// Logo
350348
$logo = $app->db->queryOneRecord("SELECT * FROM sys_ini WHERE sysini_id = 1");
351-
if($logo['custom_logo'] != ''){
349+
if ($logo['custom_logo'] != '') {
352350
$base64_logo_txt = $logo['custom_logo'];
353351
} else {
354352
$base64_logo_txt = $logo['default_logo'];
@@ -361,12 +359,12 @@
361359

362360
// Title
363361
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'].' :: ');
365363
}
366364

367365
// Custom Login
368366
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'];
370368
}
371369
$app->tpl->setVar('custom_login', $custom_login);
372370

0 commit comments

Comments
 (0)