summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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();
}