Robert 2 months ago
parent 3b0d18c6f9
commit f76f5f99eb
  1. 2
      src/classes/app.php
  2. 15
      src/classes/http/kernel.php
  3. 8
      src/classes/http/request.php
  4. 8
      src/classes/http/response.php
  5. 12
      src/classes/traits/security/session_hijacking_functions.php

@ -175,7 +175,7 @@ class app {
$use_api = misc::is_api();
$test = $this->get_ctrl_dir();
$call_class = "\\Project\\" . $test . 'controllers\\' . $class;
$call_class = "\\Project\\" . $test . "controllers\\" . $class;
$controller = new $call_class($this->request, $this->response);
// Collect controller-level middleware Directly from the controller file, IE: public static array $middleware = [ \Project\classes\auth_middleware::class ];

@ -83,12 +83,25 @@ class kernel {
);
}
public static function wrap_errors(\Throwable $e): string {
if (PHP_SAPI === 'cli') {
$red = "\033[31m";
$cyan = "\033[36m";
$reset = "\033[0m";
$e_codes = "Server Error: $red".PHP_EOL. $e->getMessage() . PHP_EOL . "$cyan File:" . $e->getFile() . PHP_EOL ."\t On Line #" . $e->getLine() . PHP_EOL . $reset;
} else {
$e_codes = "Server Error: ".PHP_EOL."<br><blockquote style='color: blue;'>" . $e->getMessage() . "</blockquote>" . PHP_EOL . "<br>File:" . $e->getFile() . PHP_EOL ."<br>\t On Line #" . $e->getLine() . PHP_EOL . "<hr>";
}
return $e_codes;
}
protected function handle_exception(\Throwable $e): response {
// Basic exception handling - override in child class
$response = new response();
return $response
->set_status_code(500)
->set_content('Server Error: ' . $e->getMessage());
->set_content(self::wrap_errors($e));
}
public function run(): void {

@ -39,7 +39,13 @@ class request {
public static function create_from_globals(): self {
if (\CodeHydrater\console_app::is_cli()) {
return new self();
$get_vars = \CodeHydrater\bootstrap\site_helper::get_params();
if ($get_vars === null) {
return new self();
}
return new self(
$get_vars
);
}
return new self(
$_GET,

@ -21,7 +21,7 @@ class response
protected array $headers = []
) { }
public function send(bool $backtrace = false): void {
public function send(): void {
http_response_code($this->status_code);
foreach ($this->headers as $name => $value) {
@ -30,11 +30,7 @@ class response
if ($this->status_code > 499) {
if (is_string($this->content) && ! empty($this->content)) {
if ($backtrace) {
dd(debug_backtrace());
} else {
throw new \Exception($this->content);
}
throw new \Exception($this->content);
} else {
throw new \Exception("Status Code #" . $this->status_code);
}

@ -91,13 +91,15 @@ trait session_hijacking_functions {
}
// If session is not valid, end and redirect to login page.
public static function confirm_session_is_valid() {
public static function confirm_session_is_valid(
string $login = "login.php"
) {
if (!self::is_session_valid()) {
self::end_session();
// Note that header redirection requires output buffering
// to be turned on or requires nothing has been output
// (not even whitespace).
header("Location: login.php");
header("Location: " . $login );
exit;
}
}
@ -108,13 +110,15 @@ trait session_hijacking_functions {
}
// If user is not logged in, end and redirect to login page.
public static function confirm_user_logged_in() {
public static function confirm_user_logged_in(
string $login = "login.php"
) {
if (!self::is_logged_in()) {
self::end_session();
// Note that header redirection requires output buffering
// to be turned on or requires nothing has been output
// (not even whitespace).
header("Location: login.php");
header("Location: " . $login);
exit;
}
}

Loading…
Cancel
Save