Skip to content

Commit e760969

Browse files
authored
Merge pull request wavelog#173 from HB9HIL/maintenance_mode
Maintenance mode
2 parents cc8a375 + d063afd commit e760969

File tree

6 files changed

+62
-15
lines changed

6 files changed

+62
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ sync.sh
2020
*.p12
2121
*.swp
2222
.debug
23+
.maintenance
2324
.htaccess

application/controllers/User.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,13 @@ function login() {
707707
$this->input->set_cookie($cookie);
708708
redirect('dashboard');
709709
} else {
710-
$this->session->set_flashdata('error', 'Incorrect username or password!');
711-
redirect('user/login');
710+
if(ENVIRONMENT == 'maintenance') {
711+
$this->session->set_flashdata('notice', 'Sorry. This instance is currently in maintenance mode. If this message appears unexpectedly or keeps showing up, please contact an administrator. Only administrators are currently allowed to log in.');
712+
redirect('user/login');
713+
} else {
714+
$this->session->set_flashdata('error', 'Incorrect username or password!');
715+
redirect('user/login');
716+
}
712717
}
713718
}
714719
}

application/models/User_model.php

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,29 @@ function validate_session() {
397397
$user_type = $this->session->userdata('user_type');
398398
$user_hash = $this->session->userdata('user_hash');
399399

400-
if($this->_auth($user_id."-".$user_type, $user_hash)) {
401-
// Freshen the session
402-
$this->update_session($user_id);
403-
return 1;
404-
} else {
405-
$this->clear_session();
406-
return 0;
400+
if(ENVIRONMENT != 'maintenance') {
401+
if($this->_auth($user_id."-".$user_type, $user_hash)) {
402+
// Freshen the session
403+
$this->update_session($user_id);
404+
return 1;
405+
} else {
406+
$this->clear_session();
407+
return 0;
408+
}
409+
} else { // handle the maintenance mode and kick out user on page reload if not an admin
410+
if($user_type == '99') {
411+
if($this->_auth($user_id."-".$user_type, $user_hash)) {
412+
// Freshen the session
413+
$this->update_session($user_id);
414+
return 1;
415+
} else {
416+
$this->clear_session();
417+
return 0;
418+
}
419+
} else {
420+
$this->clear_session();
421+
return 0;
422+
}
407423
}
408424
} else {
409425
return 0;
@@ -417,7 +433,15 @@ function authenticate($username, $password) {
417433
if($u->num_rows() != 0)
418434
{
419435
if($this->_auth($password, $u->row()->user_password)) {
420-
return 1;
436+
if (ENVIRONMENT != "maintenance") {
437+
return 1;
438+
} else {
439+
if($u->row()->user_type != 99){
440+
return 0;
441+
} else {
442+
return 1;
443+
}
444+
}
421445
}
422446
}
423447
return 0;

application/views/interface_assets/header.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@
6969
<body>
7070
<nav class="navbar navbar-expand-lg navbar-light bg-light main-nav" id="header-menu">
7171
<div class="container">
72-
<a class="navbar-brand" href="<?php echo site_url(); ?>"><img class="headerLogo" src="<?php echo base_url(); ?>assets/logo/<?php echo $this->optionslib->get_logo('header_logo'); ?>.png" alt="Logo" /></a> <?php if (ENVIRONMENT == "development") { ?><span class="badge text-bg-danger"><?php echo lang('menu_badge_developer_mode'); ?></span><?php } ?>
72+
<a class="navbar-brand" href="<?php echo site_url(); ?>"><img class="headerLogo" src="<?php echo base_url(); ?>assets/logo/<?php echo $this->optionslib->get_logo('header_logo'); ?>.png" alt="Logo" /></a>
73+
<?php if (ENVIRONMENT == "development") { ?>
74+
<span class="badge text-bg-danger"><?php echo lang('menu_badge_developer_mode'); ?></span>
75+
<?php } ?>
76+
<?php if (ENVIRONMENT == "maintenance") { ?>
77+
<span class="badge text-bg-info">Maintenance</span>
78+
<?php } ?>
7379

7480
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
7581

application/views/user/login.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
</style>
3232
<main class="form-signin">
3333
<img src="<?php echo base_url(); ?>assets/logo/<?php echo $this->optionslib->get_logo('main_logo'); ?>.png" class="mx-auto d-block mainLogo" alt="">
34+
<?php if (ENVIRONMENT == 'maintenance') { ?>
35+
<div class="d-flex justify-content-center align-items-center">
36+
<span class="badge text-bg-warning mb-4 pt-2 pb-2">MAINTENANCE MODE</span>
37+
</div>
38+
<?php } ?>
3439
<div class="my-2 rounded-0 shadow-sm card mb-2 shadow-sm">
3540
<div class="card-body">
3641
<form method="post" action="<?php echo site_url('user/login'); ?>" name="users">

index.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@
4747
*
4848
* This can be set to anything, but default usage is:
4949
*
50-
* development
51-
* testing
52-
* production
50+
* development Developer Mode - Shows for example PHP errors in frontend
51+
* maintenance Maintenance Mode - Only Admin's are allowed to login
52+
* production Production Mode - Regular Mode
5353
*
5454
* NOTE: If you change these, also change the error_reporting() code below
5555
*/
5656
#define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
5757
if (file_exists('.debug')) {
5858
define('ENVIRONMENT', 'development');
59+
} else if (file_exists('.maintenance')) {
60+
define('ENVIRONMENT', 'maintenance');
5961
} else {
6062
define('ENVIRONMENT', 'production');
6163
}
@@ -75,7 +77,11 @@
7577
ini_set('display_errors', 1);
7678
break;
7779

78-
case 'testing':
80+
case 'maintenance':
81+
error_reporting(-1);
82+
ini_set('display_errors', 1);
83+
break;
84+
7985
case 'production':
8086
ini_set('display_errors', 0);
8187
if (version_compare(PHP_VERSION, '5.3', '>='))

0 commit comments

Comments
 (0)