summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefanie Eckner <stefanie@eckner.net>2023-12-30 13:51:53 +0100
committerStefanie Eckner <stefanie@eckner.net>2023-12-30 13:51:53 +0100
commit2151bd95d34176dde2bf62e84daa5fb3f4391a88 (patch)
tree62c46a39e6f0727c60cdc8a17f2906bf628d7abc
parent07727b30c8e779ba43cc99e5d7597811c4d601c0 (diff)
downloadcomputer-time-limit-2151bd95d34176dde2bf62e84daa5fb3f4391a88.tar.xz
server soweit fertig
-rw-r--r--computer-time-limit.php57
1 files changed, 55 insertions, 2 deletions
diff --git a/computer-time-limit.php b/computer-time-limit.php
index a6372a1..0ed38da 100644
--- a/computer-time-limit.php
+++ b/computer-time-limit.php
@@ -1,9 +1,62 @@
<?php
-$db = new SQLite3('../backstage/computer-time-limit.sqlite');
+$db = new SQLite3('../backstage/computer-time-limit/computer-time-limit.sqlite');
+
+if (array_key_exists('key', $_POST)) {
+ print(shell_exec('echo "' . base64_encode($_POST['key']) . '" | base64 -d | base64 -d | gpg --import'));
+}
if (array_key_exists('gpg', $_POST)) {
- print(shell_exec('echo "' . base64_encode($_POST['gpg']) .'" | base64 -d | gpg --verify 2>&1'));
+ $sig = shell_exec('echo "' . base64_encode($_POST['gpg']) . '" | base64 -d | base64 -d | gpg --verify --with-colons --status-fd 1 2>/dev/null | grep -wFm1 VALIDSIG');
+ $sig = explode(' ', $sig);
+ if (abs(time() - $sig[4]) > 1200) {
+ die();
+ };
+ if ($sig[1] != 'VALIDSIG') {
+ die();
+ }
+ $key = $sig[2];
+ $cnt = shell_exec('echo "' . base64_encode($_POST['gpg']) . '" | base64 -d | base64 -d | gpg --output - 2>/dev/null');
+
+ $result = $db->query('SELECT * FROM `computer_time` WHERE `fingerprint`="' . $key . '"');
+ $row = $result->fetchArray();
+ if (!$row) {
+ die();
+ }
+ $bis = strtotime($row['bis']);
+ $von = strtotime($row['von']);
+ $bis = $bis + 30*60*(floor(time()/60/60/24) - floor($von/60/60/24));
+ if ($row['aktiv']) {
+ $von = time();
+ }
+ $noch = $bis - $von;
+ if ($noch < 0) {
+ $noch = 0;
+ }
+ if ($noch > 4*60*60) {
+ $noch = 4*60*60;
+ }
+
+ print($noch . "\n");
+ switch (trim($cnt)) {
+ case 'start':
+ $aktiv = 1;
+ break;
+ ;;
+ case 'stop':
+ $aktiv = 0;
+ break;
+ ;;
+ default:
+ die();
+ ;;
+ }
+ $db -> exec(
+ 'UPDATE `computer_time`' .
+ ' SET `aktiv`=' . $aktiv . ',' .
+ '`von`="' . date('Y-m-d H:i:s', time()) . '",' .
+ '`bis`="' . date('Y-m-d H:i:s', time() + $noch) . '"' .
+ ' WHERE `fingerprint`="' . $key . '"');
die();
}