From 2151bd95d34176dde2bf62e84daa5fb3f4391a88 Mon Sep 17 00:00:00 2001 From: Stefanie Eckner Date: Sat, 30 Dec 2023 13:51:53 +0100 Subject: server soweit fertig --- computer-time-limit.php | 57 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file 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 @@ &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(); } -- cgit v1.2.3-70-g09d2