...
This commit is contained in:
@@ -6,6 +6,10 @@ error_reporting(E_ALL);
|
||||
class spamhasiApi {
|
||||
private $api_keys;
|
||||
|
||||
function __construct() {
|
||||
header("Content-Type: application/json");
|
||||
}
|
||||
|
||||
public function getConf() {
|
||||
$env = parse_ini_file(__DIR__ . "/../.env");
|
||||
return $env;
|
||||
|
||||
50
api/login/getcookies.php
Normal file
50
api/login/getcookies.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
ini_set("display_errors", 1);
|
||||
ini_set("display_startup_errors", 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require "../api.php";
|
||||
|
||||
$api = new spamhasiApi();
|
||||
$db = $api->getDB();
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
if (!isset($_POST["username"]) || !isset($_POST["passwd"])) {
|
||||
die("Username or Password are missing");
|
||||
}
|
||||
|
||||
$user = $_POST["username"];
|
||||
$passwd = hash("sha256", $_POST["passwd"]);
|
||||
|
||||
$sql = "SELECT username, passwd FROM users WHERE username = :username AND passwd = :passwd";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->execute([
|
||||
':username' => $user,
|
||||
':passwd' => $passwd
|
||||
]);
|
||||
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($result) {
|
||||
$config = $api->getConf();
|
||||
|
||||
$session["session_id"] = $api->generateSessionID();
|
||||
$device_id = rand(1, 999);
|
||||
|
||||
$json[$device_id] = $session;
|
||||
|
||||
file_put_contents($config["PATH"] . "/tmp/user_sessions/" . $user . ".json", json_encode($json));
|
||||
|
||||
setcookie("session_id", $session["session_id"], time() + 3600, "/");
|
||||
setcookie("device_id", $device_id, time() + 3600, "/");
|
||||
setcookie("username", $user, time() + 3600, "/");
|
||||
|
||||
header("Location: /opfer.html");
|
||||
exit;
|
||||
|
||||
}else{
|
||||
header("Location: /login.php?passwdIsFalse=true");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
?>
|
||||
19
api/login/isauth.php
Normal file
19
api/login/isauth.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
require "../api.php";
|
||||
|
||||
$api = new spamhasiApi();
|
||||
|
||||
if ($api->checkAuth()) {
|
||||
$json["auth"] = true;
|
||||
|
||||
if ($api->checkLogin()) {
|
||||
$json["method"] = "cookie";
|
||||
}else{
|
||||
$json["method"] = "api_key";
|
||||
}
|
||||
}else{
|
||||
$json["auth"] = false;
|
||||
}
|
||||
|
||||
die(json_encode($json));
|
||||
?>
|
||||
4
api/opfer/add.php
Normal file
4
api/opfer/add.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
require "../api.php";
|
||||
|
||||
$api = new spamhasiApi()
|
||||
@@ -21,12 +21,18 @@ if ($result) {
|
||||
$opfer["mail"] = $opfer_res["mail"];
|
||||
$opfer["number"] = $opfer_res["number"];
|
||||
|
||||
if ($opfer_res["status"] == 1) {
|
||||
$opfer["enabled"] = true;
|
||||
}else{
|
||||
$opfer["enabled"] = false;
|
||||
}
|
||||
|
||||
$all_opfer[] = $opfer;
|
||||
}
|
||||
|
||||
$json["servers"] = $all_opfer;
|
||||
$json["opfer"] = $all_opfer;
|
||||
}else{
|
||||
$json["servers"] = [];
|
||||
$json["opfer"] = [];
|
||||
}
|
||||
|
||||
$json["status"] = 200;
|
||||
|
||||
Reference in New Issue
Block a user