-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnest.php
37 lines (36 loc) · 1.04 KB
/
nest.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
<?php
if (isset($argv)) {
parse_str(implode('&', array_slice($argv, 1)), $_REQUEST);
} elseif($_SERVER['SERVER_PORT'] != '443') {
header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
exit();
}
require_once("nest-api/nest.class.php");
define('USERNAME', 'username');
define('PASSWORD', 'password');
$nest = new Nest();
$did = "";
$tmp_dir = "~/.nest_tmp";
$status = $_REQUEST['status'];
$person = $_REQUEST['person'];
if (!isset($person) || !isset($status)) exit();
exec("~/sendSlackMessage test web '{$person} {$status} home at {$_REQUEST['at']}'");
if ($status == 'entered') {
$home_already = (count(glob("{$tmp_dir}/*")) > 0);
if (!$home_already) {
$nest->setAway(false);
$did = "off";
}
touch("{$tmp_dir}/{$person}");
} elseif ($status == 'exited') {
$delte_file = "{$tmp_dir}/{$person}";
if (file_exists($delte_file)) unlink($delte_file);
}
if (count(glob("{$tmp_dir}/*")) === 0 ) {
$nest->setAway(true);
$did = "on";
}
if ($did) {
$msg = "turned away mode {$did}";
exec("~/sendSlackMessage general web '{$msg}'");
}