update many stuff
This commit is contained in:
35
public_html/_incl/auth_redir.php
Executable file
35
public_html/_incl/auth_redir.php
Executable file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
session_start([ 'cookie_lifetime' => 604800 ]);
|
||||
session_regenerate_id();
|
||||
ini_set("session.use_only_cookies", "true");
|
||||
ini_set("session.use_trans_sid", "false");
|
||||
|
||||
$ua = $_SERVER['HTTP_USER_AGENT'];
|
||||
if (str_starts_with($ua, "SysAdminAuth/")) {
|
||||
$username = explode("/", $ua)[1];
|
||||
$userpass = explode("/", $ua)[2];
|
||||
$userdata = json_decode(file_get_contents("/DATA/Usuarios/$username.json"), true);
|
||||
if (!$userdata) {
|
||||
header("HTTP/1.1 403 Forbidden");
|
||||
die();
|
||||
}
|
||||
if ($userdata["password"] !== hash("sha256", $userpass)) {
|
||||
header("HTTP/1.1 403 Forbidden");
|
||||
die();
|
||||
}
|
||||
$_SESSION["auth_user"] = $username;
|
||||
$_SESSION["auth_data"] = $userdata;
|
||||
$_SESSION["auth_ok"] = true;
|
||||
}
|
||||
|
||||
// ¿Is user authenticated?
|
||||
if (!$_SESSION["auth_ok"]) {
|
||||
header("Location: /_login.php");
|
||||
die();
|
||||
}
|
||||
|
||||
// Check if "$APP_CODE" inside user's permissions
|
||||
if (!in_array("$APP_CODE:access", $_SESSION["auth_data"]["permissions"])) {
|
||||
header("Location: /index.php?_resultcolor=red&_result=" . urlencode("No tienes permisos para acceder a $APP_NAME."));
|
||||
die();
|
||||
}
|
||||
Reference in New Issue
Block a user