diff --git a/app/controllers/Account.php b/app/controllers/Account.php index fd8480cc..cad02613 100644 --- a/app/controllers/Account.php +++ b/app/controllers/Account.php @@ -40,8 +40,7 @@ public function index() // Check if posted data is logout if ($this->getPostValue('logout') !== null) { $this->session->deleteSession(); - header('Location: /manage/account/login'); - exit(); + redirect('/manage/account/login'); } } catch (Exception $e) { $this->view->renderMessage($e->getMessage()); @@ -102,10 +101,10 @@ public function login() if (strlen($user['secret']) === 16) { $user['password'] = $password; $this->session->createTempSession($user); - header('Location: /manage/account/mfa'); + redirect('/manage/account/mfa'); } else { $this->session->createSession($user); - header('Location: dashboard/index'); + redirect('dashboard/index'); } } catch (Exception $e) { $this->view->renderMessage($e->getMessage()); @@ -127,14 +126,14 @@ public function mfa() $this->view->renderTemplate('account/mfa'); if($this->session->data('temp') != true) { - header('Location: dashboard/index'); + redirect('dashboard/index'); exit(); } if ($this->isPOST()) { try { $this->validateCsrfToken(); - + $username = $this->session->data('username'); $password = $this->session->data('password'); $code = $this->getPostValue('code'); @@ -146,7 +145,7 @@ public function mfa() } $this->session->createSession($user); - header('Location: dashboard/index'); + redirect('dashboard/index'); } catch (Exception $e) { $this->view->renderMessage($e->getMessage()); } diff --git a/app/controllers/Install.php b/app/controllers/Install.php index 51622d5a..532029f3 100644 --- a/app/controllers/Install.php +++ b/app/controllers/Install.php @@ -15,8 +15,7 @@ public function index() // Make sure the platform is not already installed try { $this->model('Setting')->get('version'); - header('Location: dashboard/index'); - exit(); + redirect('dashboard/index'); } catch (Exception $e) {} if($this->isPOST()) { @@ -51,8 +50,7 @@ public function index() $this->model('User')->create($username, $password, 7); $user = $this->model('User')->login($username, $password); $this->session->createSession($user); - header('Location: dashboard/index'); - exit(); + redirect('dashboard/index'); } catch (Exception $e) { $this->view->renderMessage($e->getMessage()); } diff --git a/app/controllers/Payload.php b/app/controllers/Payload.php index b91f74e4..f0cffd8e 100644 --- a/app/controllers/Payload.php +++ b/app/controllers/Payload.php @@ -15,8 +15,7 @@ public function index() $payloadList = $this->payloadList(); if (!empty($this->payloadList())) { - header('Location: /manage/payload/edit/' . $payloadList[0]); - exit(); + redirect('/manage/payload/edit/' . $payloadList[0]); } return $this->showContent(); diff --git a/app/controllers/Reports.php b/app/controllers/Reports.php index 77f55a96..db88712a 100644 --- a/app/controllers/Reports.php +++ b/app/controllers/Reports.php @@ -18,8 +18,7 @@ public function index() { $this->isLoggedInOrExit(); - header('Location: /manage/reports/all'); - exit(); + redirect('/manage/reports/all/'); } /** diff --git a/app/controllers/Update.php b/app/controllers/Update.php index 9bf1e065..11062ff5 100644 --- a/app/controllers/Update.php +++ b/app/controllers/Update.php @@ -33,7 +33,7 @@ public function index() // Future updates come here! - header('Location: dashboard/index'); + redirect('dashboard/index'); exit(); } catch (Exception $e) { $this->view->renderMessage($e->getMessage()); diff --git a/app/controllers/Users.php b/app/controllers/Users.php index 69fe20c1..6c540cbd 100644 --- a/app/controllers/Users.php +++ b/app/controllers/Users.php @@ -168,7 +168,7 @@ public function delete($id) } $this->model('User')->deleteById($id); - header('Location: /manage/users'); + redirect('/manage/users'); } return $this->showContent(); diff --git a/system/Controller.php b/system/Controller.php index c64e018d..62cf1420 100644 --- a/system/Controller.php +++ b/system/Controller.php @@ -140,8 +140,7 @@ public function validateSession() } catch (Exception $e) { // If session failed to validate, clear the session $this->session->deleteSession(); - header('Location: /manage/account/login'); - exit(); + redirect('/manage/account/login'); } } @@ -154,8 +153,7 @@ public function isLoggedInOrExit() { $this->validateSession(); if (!$this->session->isLoggedIn()) { - header('Location: /manage/account/login'); - exit(); + redirect('/manage/account/login'); } } @@ -167,8 +165,7 @@ public function isLoggedInOrExit() public function isLoggedOutOrExit() { if ($this->session->isLoggedIn()) { - header('Location: /manage/dashboard/index'); - exit(); + redirect('/manage/dashboard/index'); } } @@ -181,8 +178,7 @@ public function isAdminOrExit() { $this->isLoggedInOrExit(); if (!$this->isAdmin()) { - header('Location: /manage/dashboard/my'); - exit(); + redirect('/manage/dashboard/my'); } } @@ -244,7 +240,7 @@ private function checkKillSwitch() if (!empty($killswitch)) { if ($this->getGetValue('pass') === $killswitch) { $this->model('Setting')->set('killswitch', ''); - header('Location: /'); + redirect('/'); } else { http_response_code(404); exit(); @@ -267,8 +263,7 @@ private function checkIfInstalled() $this->model('Setting')->get('version'); } } catch (Exception $e) { - header('Location: /manage/install'); - exit(); + redirect('/manage/install'); } } @@ -287,8 +282,7 @@ private function checkForUpdates() } } } catch (Exception $e) { - header('Location: /manage/update'); - exit(); + redirect('/manage/update'); } } } diff --git a/system/Helpers.php b/system/Helpers.php index 5c08b931..a4e42fdb 100644 --- a/system/Helpers.php +++ b/system/Helpers.php @@ -50,3 +50,15 @@ function baseDecode($data): string } return $result; } + +/** + * Rredirects to location + * + * @param string $location The location + * @return null + */ +function redirect($location) +{ + header('Location: ' . $location); + exit(); +} \ No newline at end of file diff --git a/system/Router.php b/system/Router.php index 89b5fffc..34d3150f 100644 --- a/system/Router.php +++ b/system/Router.php @@ -52,8 +52,7 @@ public function proccess($uri) throw new Exception('404'); } } catch (Exception $e) { - header('Location: /manage/dashboard'); - exit(); + redirect('/manage/dashboard'); } $args = isset($parts[4]) ? [$parts[4]] : []; } else {