This repository has been archived by the owner on Jan 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
status.py
80 lines (63 loc) · 1.43 KB
/
status.py
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
# Doorduino Status Script (Python)
# Revision 0.3.1
# Ben Woodruff <[email protected]>
# http://www.interlockroc.org/
interlockIP = "173.85.245.53";
word[1] = "open! :)";
word[0] = "closed. :(";
statusFile = "status.txt";
##### DO NOT EDIT BELOW THIS LINE #####
# (unless you know what you're doing) #
# enable debugging
import cgitb
cgitb.enable()
print "Content-Type: text/plain;charset=utf-8"
def checkFile():
fileCheck = 1;
try:
fh = open(statusFile, r+)
except IOError as e:
fileCheck = 0
fh.close()
return fileCheck;
if(isset($_GET['status'])) {
if($_SERVER['REMOTE_ADDR'] == $interlockIP) {
if(checkFile()) {
$file = fopen($statusFile, "w+");
if($_GET[status] == "1") {
fwrite($file, "1");
}
elseif($_GET[status] == "0") {
fwrite($file, "0");
}
else {
exit("5"); # 5 = problem with the request from the doorduino
}
fclose($file);
exit("0");
}
else {
exit("1"); # 1 = error reading from / writing to the file. check if it exists
}
}
else {
exit("2"); # 2 = request is not coming from Interlock
}
}
else {
if(checkFile()) {
$file = fopen($statusFile, "r");
$display = fread($file, 1);
fclose($file);
if(isset($word[$display])) {
exit($word[$display]);
}
else {
exit("4"); # 4 = problem with the script. we didn't properly define variables at the top
}
}
else {
exit("3"); # 3 = problem with data returned from file. check file
}
}
?>