diff options
author | Minteck <contact@minteck.org> | 2022-08-10 00:04:25 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-08-10 00:04:25 +0200 |
commit | 0417260bf158c5d7b62888dae2e202b0de115a05 (patch) | |
tree | 7f54ee56da118813f2d1b3a324d322d0c74fa51b /api/save.php | |
download | pluralconnect-0417260bf158c5d7b62888dae2e202b0de115a05.tar.gz pluralconnect-0417260bf158c5d7b62888dae2e202b0de115a05.tar.bz2 pluralconnect-0417260bf158c5d7b62888dae2e202b0de115a05.zip |
Initial commit
Diffstat (limited to 'api/save.php')
-rw-r--r-- | api/save.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/api/save.php b/api/save.php new file mode 100644 index 0000000..ef8a07d --- /dev/null +++ b/api/save.php @@ -0,0 +1,43 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $isLoggedIn; +if (!$isLoggedIn) header("Location: /login") and die(); + +$request_raw = file_get_contents('php://input'); +$json_object = json_decode($request_raw, true); + +$system = $_GET['system'] ?? null; +$member = $_GET['member'] ?? null; +$subsystem = $_GET['subsystem'] ?? null; +$content = $json_object['content'] ?? null; + +if (!isset($system) || trim($system) === "" || strlen($system) !== 5 || !preg_match("/[a-z]/i", $system)) + header("Location: /?error=System not found") and die(); + +if (!isset($member) || trim($member) === "" || strlen($member) !== 5 || !preg_match("/[a-z]/i", $member)) + if ($member !== null && $member !== "null") header("Location: /?error=System member not found") and die(); + +if (!isset($subsystem) || trim($subsystem) === "" || !preg_match("/[a-z\d]/i", $subsystem)) + if ($subsystem !== null && $subsystem !== "null") header("Location: /?error=Subsystem not found") and die(); + +if (!isset($content)) + header("Location: /?error=No content") and die(); + +if ($member !== null && $member !== "null") { + $file = $_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $system . "-" . $member . "-disclaimers.html"; +} else { + if ($subsystem !== null && $subsystem !== "null") { + $file = $_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $system . "-subsystem-" . $subsystem . ".html"; + } else { + $file = $_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $system . "-disclaimers.html"; + } +} + +if (trim($content) === "") { + if (file_exists($file)) { + unlink($file); + } + die(); +} + +file_put_contents($file, $content);
\ No newline at end of file |