-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenGarageControl.php
43 lines (35 loc) · 1.11 KB
/
openGarageControl.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
<?php
require_once "~/tools.php";
header("Content-type: text/plain");
date_default_timezone_set("America/Phoenix");
$tools = new Tools();
$tools->log_file = 'openGarageControl/log';
$slack_token = 'slack_token';
$secret = 'secret';
if (isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] == 'application/json') {
$HTTP_RAW_POST_DATA = file_get_contents("php://input");
if ($HTTP_RAW_POST_DATA) {
$_REQUEST = array_merge($_REQUEST, json_decode($HTTP_RAW_POST_DATA, true));
}
}
if (isset($_REQUEST['token']) && $_REQUEST['token'] == $slack_token) {
$_REQUEST['action'] = $_REQUEST['text'];
$tools->slack_url = $_REQUEST['response_url'];
} elseif (!isset($_REQUEST['scrt']) || $_REQUEST['scrt'] != $secret) {
exit('Permissions Denied');
}
switch ($_REQUEST['action']) {
case 'open':
$tools->triggerOpenGarage('open');
break;
case 'close':
$tools->triggerOpenGarage('close');
break;
case 'status':
list($status, $vehicle) = $tools->getOpenGarageStatus();
$status = ($status == 'close') ? 'closed' : $status;
$tools->postToSlack("Garage Door is {$status} {$vehicle}");
default:
exit;
break;
}