blob: 0ed38da1a55cbc341d9ad72c582ea8dd8f2a4aec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
<?php
$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)) {
$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();
}
$result = $db->query('select * from `computer_time`');
?><html><body><table><?php
while ($row = $result->fetchArray()) {
$bis = strtotime($row['bis']);
$von = strtotime($row['von']);
if ($row['aktiv']) {
$von = time();
}
$noch = $bis - $von;
?><tr><td><?php print($row['name']); ?></td><td><?php
print(date('Y-m-d H:i:s', $bis));
print(' (');
print($noch);
print(')');
?></td></tr>
<?php
}
?></table></body></html>
|