summaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-08-10 00:04:25 +0200
committerMinteck <contact@minteck.org>2022-08-10 00:04:25 +0200
commit0417260bf158c5d7b62888dae2e202b0de115a05 (patch)
tree7f54ee56da118813f2d1b3a324d322d0c74fa51b /api
downloadpluralconnect-0417260bf158c5d7b62888dae2e202b0de115a05.tar.gz
pluralconnect-0417260bf158c5d7b62888dae2e202b0de115a05.tar.bz2
pluralconnect-0417260bf158c5d7b62888dae2e202b0de115a05.zip
Initial commit
Diffstat (limited to 'api')
-rw-r--r--api/emergency-real.php19
-rw-r--r--api/emergency.php19
-rw-r--r--api/fronter.php82
-rw-r--r--api/save.php43
4 files changed, 163 insertions, 0 deletions
diff --git a/api/emergency-real.php b/api/emergency-real.php
new file mode 100644
index 0000000..20a918f
--- /dev/null
+++ b/api/emergency-real.php
@@ -0,0 +1,19 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $isLoggedIn;
+if (!$isLoggedIn) header("Location: /login") and die();
+global $_PROFILE;
+
+file_get_contents('https://ntfy.sh/' . json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true)["ntfy"], false, stream_context_create([
+ 'http' => [
+ 'method' => 'POST',
+ 'header' =>
+ "Content-Type: text/plain\r\n" .
+ "Title: ⚠️🆘 EMERGENCY ⚠️🆘\r\n" .
+ "Priority: urgent\r\n" .
+ "Tags: emergency",
+ 'content' => "This is an emergency, " . $_PROFILE['name'] . " is in need of IMMEDIATE help. Please act now!"
+ ]
+]));
+
+die(); \ No newline at end of file
diff --git a/api/emergency.php b/api/emergency.php
new file mode 100644
index 0000000..eb2a054
--- /dev/null
+++ b/api/emergency.php
@@ -0,0 +1,19 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $isLoggedIn;
+if (!$isLoggedIn) header("Location: /login") and die();
+global $_PROFILE;
+
+file_get_contents('https://ntfy.sh/' . json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true)["ntfy"], false, stream_context_create([
+ 'http' => [
+ 'method' => 'POST',
+ 'header' =>
+ "Content-Type: text/plain\r\n" .
+ "Title: [Test] ⚠️🆘 EMERGENCY ⚠️🆘\r\n" .
+ "Priority: urgent\r\n" .
+ "Tags: emergency",
+ 'content' => "[This notification is test] This is an emergency, " . $_PROFILE['name'] . " is in need of IMMEDIATE help. Please act now! [This notification is test]"
+ ]
+]));
+
+die(); \ No newline at end of file
diff --git a/api/fronter.php b/api/fronter.php
new file mode 100644
index 0000000..44c2c76
--- /dev/null
+++ b/api/fronter.php
@@ -0,0 +1,82 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $isLoggedIn;
+if (!$isLoggedIn) header("Location: /login") and die();
+
+$system = $_GET['s'] ?? null;
+$member = $_GET['m'] ?? null;
+$index = (int)$_GET['i'] ?? null;
+$type = $_GET['t'] ?? null;
+$date = $_GET['d'] ?? null;
+
+if (!isset($system) || trim($system) === "" || strlen($system) !== 5 || !preg_match("/[a-z]/i", $system) || ($system !== "gdapd" && $system !== "ynmuc"))
+ header("Location: /?error=System not found") and die();
+
+if (!isset($type) || trim($type) === "")
+ header("Location: /?error=Type not found") and die();
+
+if (!isset($date) || trim($date) === "" || strlen($date) !== 10 || !preg_match("/[\d-]/i", $date))
+ header("Location: /?error=Date not found") and die();
+
+$list = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system-planner.json"), true);
+
+function moveElement(&$array, $a, $b) {
+ $out = array_splice($array, $a, 1);
+ array_splice($array, $b, 0, $out);
+}
+
+switch ($type) {
+ case "add":
+ 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($list[$date])) $list[$date] = [];
+ $list[$date][] = $member;
+ break;
+
+ case "delete":
+ if (!isset($index) || trim($index) === "" || is_integer($index))
+ if ($index !== null && $index !== "null") header("Location: /?error=Invalid index") and die();
+
+ $day = $list[$date];
+
+ if (!isset($day[$index]))
+ if ($index !== null && $index !== "null") header("Location: /?error=Index not found") and die();
+
+ unset($day[$index]);
+ $list[$date] = array_values($day);
+
+ break;
+
+ case "down":
+ if (!isset($index) || trim($index) === "" || is_integer($index))
+ if ($index !== null && $index !== "null") header("Location: /?error=Invalid index") and die();
+
+ if (!isset($day[$index]))
+ if ($index !== null && $index !== "null") header("Location: /?error=Index not found") and die();
+
+ $day = $list[$date];
+ moveElement($list[$date], $index, $index + 1 < count($list[$date]) ? $index + 1 : $index);
+
+ break;
+
+ case "up":
+ if (!isset($index) || trim($index) === "" || is_integer($index))
+ if ($index !== null && $index !== "null") header("Location: /?error=Invalid index") and die();
+
+ if (!isset($day[$index]))
+ if ($index !== null && $index !== "null") header("Location: /?error=Index not found") and die();
+
+ $day = $list[$date];
+ moveElement($list[$date], $index, $index - 1 > -1 ? $index - 1 : $index);
+
+ break;
+
+ default:
+ header("Location: /?error=Invalid type name") and die();
+ break;
+}
+
+file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system-planner.json", json_encode($list));
+
+die(); \ No newline at end of file
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