-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgeohopper.php
executable file
·64 lines (51 loc) · 1.42 KB
/
geohopper.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
57
58
59
60
61
62
63
64
<?php
require_once('config.php');
#ini_set('display_startup_errors',1);
#ini_set('display_errors',1);
#error_reporting(-1);
$auth=0;
$event=-1;
$location=0;
if ($_REQUEST['auth'] && (!preg_match('/^[a-zA-Z0-9]+$/',$_REQUEST['auth']))) {
exit;
}
$token=$_REQUEST['auth'];
if ($token) {
$conn = new mysqli($db_server, $db_username, $db_password, $db_database);
$stmt = $conn->prepare("select count(uid),week,admin,user from users where authkey=? and enabled=1");
$stmt->bind_param("s", $token);
$stmt->execute();
$stmt->bind_result($auth,$week,$is_admin,$user);
$stmt->fetch();
}
if ($auth<1) {
exit;
}
$data = json_decode(file_get_contents('php://input'));
if (preg_match('/Home/',$data->location)) {
$location = 1;
if ($data->event == "LocationEnter") {
$event = "1";
} else {
$event= "0";
}
}
if (!$data && $_REQUEST['fix'] == 1) {
$location=1;
$event = 1;
}
if ($event >= 0) {
$conn = new mysqli($db_server, $db_username, $db_password, $db_database);
$stmt = $conn->prepare("update users set isHome=?,homeTime=NOW() where authkey=?");
$stmt->bind_param("ss", $event,$token);
$stmt->execute();
if ($location === 1) { # if event impacts Home..
$conn = new mysqli($db_server, $db_username, $db_password, $db_database);
$stmt = $conn->prepare("select sum(isHome) from users where enabled=1");
$stmt->execute();
$stmt->bind_result($count);
$stmt->fetch();
#echo "$count:$event:$location";
}
}
?>