diff options
Diffstat (limited to 'admin/api')
-rw-r--r-- | admin/api/_demo.php | 5 | ||||
-rw-r--r-- | admin/api/getUbuntuUpgrades.php | 10 | ||||
-rw-r--r-- | admin/api/getUpdates.php | 26 | ||||
-rw-r--r-- | admin/api/refreshUpdates.php | 4 | ||||
-rw-r--r-- | admin/api/serverLogSummary.php | 8 | ||||
-rw-r--r-- | admin/api/serverTemp.php | 20 | ||||
-rw-r--r-- | admin/api/serverTime.php | 12 | ||||
-rw-r--r-- | admin/api/terminateAllSessions.php | 34 | ||||
-rw-r--r-- | admin/api/terminateGameSessions.php | 23 | ||||
-rw-r--r-- | admin/api/terminateWebSessions.php | 23 |
10 files changed, 165 insertions, 0 deletions
diff --git a/admin/api/_demo.php b/admin/api/_demo.php new file mode 100644 index 0000000..e4651f1 --- /dev/null +++ b/admin/api/_demo.php @@ -0,0 +1,5 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/private/header.api.php"; + +// Do your API stuff here!
\ No newline at end of file diff --git a/admin/api/getUbuntuUpgrades.php b/admin/api/getUbuntuUpgrades.php new file mode 100644 index 0000000..dcf06ce --- /dev/null +++ b/admin/api/getUbuntuUpgrades.php @@ -0,0 +1,10 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/private/header.api.php"; + +exec("bash -c \"sudo do-release-upgrade -c | grep 'New release'\"", $ret); +if (count($ret) === 1) { + echo("<b>Ubuntu " . explode("'", $ret[0])[1] . "</b> is available, use <code>do-release-upgrade</code> to upgrade"); +} else { + echo("This server is running the latest version of Ubuntu"); +}
\ No newline at end of file diff --git a/admin/api/getUpdates.php b/admin/api/getUpdates.php new file mode 100644 index 0000000..57ce275 --- /dev/null +++ b/admin/api/getUpdates.php @@ -0,0 +1,26 @@ +<?php + +header("Content-Type: application/json"); +require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/private/header.api.php"; + +exec("bash -c \"sudo apt-get upgrade -s| grep ^Inst\"", $ret); +$data = []; +$data["count"] = count($ret); +$data["packages"] = []; + +foreach ($ret as $package) { + $parts = explode(" ", trim($package)); + $pkg = [ + "name" => trim($parts[1]), + "version" => [ + "local" => trim(explode("]", explode("[", $parts[2])[1])[0]), + "remote" => trim(explode("(", $parts[3])[1]), + ], + "repos" => trim(explode(":", explode("(", explode("[", trim($package))[1])[1])[1]), + "architecture" => trim(explode("]", explode("[", trim($package))[2])[0]) + ]; + + $data["packages"][] = $pkg; +} + +echo(json_encode($data, JSON_PRETTY_PRINT));
\ No newline at end of file diff --git a/admin/api/refreshUpdates.php b/admin/api/refreshUpdates.php new file mode 100644 index 0000000..ea6f991 --- /dev/null +++ b/admin/api/refreshUpdates.php @@ -0,0 +1,4 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/private/header.api.php"; +exec("bash -c \"sudo apt-get update", $ret);
\ No newline at end of file diff --git a/admin/api/serverLogSummary.php b/admin/api/serverLogSummary.php new file mode 100644 index 0000000..2d90fe1 --- /dev/null +++ b/admin/api/serverLogSummary.php @@ -0,0 +1,8 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/private/header.api.php"; + +exec("journalctl -b --quiet", $ret); +$cnt = count($ret); + +echo("<b>" . $cnt . "</b> system log messages since last system startup");
\ No newline at end of file diff --git a/admin/api/serverTemp.php b/admin/api/serverTemp.php new file mode 100644 index 0000000..19e383a --- /dev/null +++ b/admin/api/serverTemp.php @@ -0,0 +1,20 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/private/header.api.php"; + +echo("Server running at <b>"); +exec("sensors -j", $out); +$outp = implode("\n", $out); +$outd = json_decode($outp, true); + +echo(round($outd["cpu_thermal-virtual-0"]["temp1"]["temp1_input"], 1)); + +?>°C</b>, <?php + +if ($outd["cpu_thermal-virtual-0"]["temp1"]["temp1_input"] > 90) { + echo("completely overheating!"); +} else if ($outd["cpu_thermal-virtual-0"]["temp1"]["temp1_input"] > 60) { + echo("starting to throttle!"); +} else { + echo("under normal temperatures"); +}
\ No newline at end of file diff --git a/admin/api/serverTime.php b/admin/api/serverTime.php new file mode 100644 index 0000000..d0db5e3 --- /dev/null +++ b/admin/api/serverTime.php @@ -0,0 +1,12 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/private/header.api.php"; + +$str = file_get_contents('/proc/uptime'); +$num = floatval($str); +$secs = fmod($num, 60); $num = intdiv($num, 60); +$mins = $num % 60; $num = intdiv($num, 60); +$hours = $num % 24; $num = intdiv($num, 24); +$days = $num; + +echo($days . " day·s, " . $hours . " hour·s, " . $mins . " minute·s, " . ceil($secs) . " second·s");
\ No newline at end of file diff --git a/admin/api/terminateAllSessions.php b/admin/api/terminateAllSessions.php new file mode 100644 index 0000000..2aa5c5f --- /dev/null +++ b/admin/api/terminateAllSessions.php @@ -0,0 +1,34 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/private/header.api.php"; + +if (isset($_GET['_']) && strpos($_GET['_'], "/") === false) { + $arg = $_GET['_']; +} else { + die(); +} + +$webs = scandir("/mnt/kartik/online/private/tokens"); + +foreach ($webs as $webt) { + if (!is_dir("/mnt/kartik/online/private/tokens/" . $webt)) { + $d = json_decode(file_get_contents("/mnt/kartik/online/private/tokens/" . $webt), true); + if ($d["id"] === $arg) { + unlink("/mnt/kartik/online/private/tokens/" . $webt); + } + } +} + +$webs = scandir("/mnt/kartik/online/private/gametokens"); + +foreach ($webs as $webt) { + if (!is_dir("/mnt/kartik/online/private/gametokens/" . $webt)) { + $d = json_decode(file_get_contents("/mnt/kartik/online/private/gametokens/" . $webt), true); + if ($d["id"] === $arg) { + unlink("/mnt/kartik/online/private/gametokens/" . $webt); + } + } +} + +header("Location: /admin/panes/kartik.php"); +die();
\ No newline at end of file diff --git a/admin/api/terminateGameSessions.php b/admin/api/terminateGameSessions.php new file mode 100644 index 0000000..2f895b1 --- /dev/null +++ b/admin/api/terminateGameSessions.php @@ -0,0 +1,23 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/private/header.api.php"; + +if (isset($_GET['_']) && strpos($_GET['_'], "/") === false) { + $arg = $_GET['_']; +} else { + die(); +} + +$webs = scandir("/mnt/kartik/online/private/gametokens"); + +foreach ($webs as $webt) { + if (!is_dir("/mnt/kartik/online/private/gametokens/" . $webt)) { + $d = json_decode(file_get_contents("/mnt/kartik/online/private/gametokens/" . $webt), true); + if ($d["id"] === $arg) { + unlink("/mnt/kartik/online/private/gametokens/" . $webt); + } + } +} + +header("Location: /admin/panes/kartik.php"); +die(); diff --git a/admin/api/terminateWebSessions.php b/admin/api/terminateWebSessions.php new file mode 100644 index 0000000..956782f --- /dev/null +++ b/admin/api/terminateWebSessions.php @@ -0,0 +1,23 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/private/header.api.php"; + +if (isset($_GET['_']) && strpos($_GET['_'], "/") === false) { + $arg = $_GET['_']; +} else { + die(); +} + +$webs = scandir("/mnt/kartik/online/private/tokens"); + +foreach ($webs as $webt) { + if (!is_dir("/mnt/kartik/online/private/tokens/" . $webt)) { + $d = json_decode(file_get_contents("/mnt/kartik/online/private/tokens/" . $webt), true); + if ($d["id"] === $arg) { + unlink("/mnt/kartik/online/private/tokens/" . $webt); + } + } +} + +header("Location: /admin/panes/kartik.php"); +die();
\ No newline at end of file |