-
Notifications
You must be signed in to change notification settings - Fork 1
/
status.php
57 lines (46 loc) · 1.3 KB
/
status.php
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
<?php
/*
* The android application calls this URL and simply outputs any text
* to the android application.
* Shows the current door status.
* This status is also shown within open.php (the web app)
*/
require_once('includes/config.php');
if(is_banned()){
echo "Sorry, too many failed attempts. Wait a few minutes.";
exit;
}
$client_ip = $_SERVER['REMOTE_ADDR'];
// todo - check we can connect to door controller.
// look at the last history in our door log.
$sql = "SELECT * FROM `door_status` ORDER BY `door_status_id` DESC LIMIT 1";
$last_status = mysql_fetch_assoc(mysql_query($sql));
$door_active = false;
$door_open = false;
$last_status_time = false;
if($last_status){
$door_active = (int)$last_status['door_active'];
$door_open = (int)$last_status['door_open'];
$last_status_time = $last_status['time'];
}
$status = "The door is ";
if($door_active){
if($door_open){
$status .= "open";
}else{
$status .= "closed";
}
if(!isset($_REQUEST['os'])){
$status .= " as of ".date('d/m/Y H:i T',$last_status_time).".\n\n";
}
if(!isset($_REQUEST['os'])){
if(in_array($client_ip,$allowed_ips)){
$status .= "Please input your pin.";
}else{
$status .= "PLEASE CONNECT TO THE TECHSPACE WIFI !";
}
}
}else{
$status = "INACTIVE, sorry.";
}
echo $status;