-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetchURL.php
More file actions
78 lines (51 loc) · 1.73 KB
/
Copy pathfetchURL.php
File metadata and controls
78 lines (51 loc) · 1.73 KB
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
<?php
require_once('core.php');
/**
* Example URL: http://domain.no/fetchURL.php?key=<apikey>&deviceID=313&id=R4sdf423G
*
*/
/* Get parameters
--------------------------------------------------------------------------- */
if (isset($_GET['key'])) $api_key = clean($_GET['key']);
else die('Key missing');
/*if (isset($_GET['deviceID'])) $deviceID = clean($_GET['deviceID']);
else die('Device ID missing');*/
if (isset($_GET['id'])) $urlID = clean($_GET['id']);
else die('URL trigger ID missing');
// Check API key
$query = "SELECT * FROM msh_users WHERE apikey LIKE '$api_key'";
$result = $mysqli->query($query);
$numUsers = $result->num_rows;
if ($numUsers > 0) {
$userData = $result->fetch_array();
// Fetch URL data
$query = "SELECT * FROM msh_url_triggers WHERE url_id LIKE '$urlID'";
$result = $mysqli->query($query);
$numURLTriggers = $result->num_rows;
if ($numURLTriggers == 1) {
$urlTriggerData = $result->fetch_array();
// Add alert
$alertParams = array(
'user_id' => $userData['user_id'],
'device_int_id' => $urlTriggerData['device_int_id'],
'level' => $urlTriggerData['alert_level'],
'title' => $urlTriggerData['title'],
);
$result = $objCore->alerts_add($alertParams);
// Add log
$p = array(
'device_int_id' => $urlTriggerData['device_int_id'],
'unit_id' => 4,
'value' => $urlTriggerData['set_value'],
'state' => $urlTriggerData['set_value'],
);
$result = $objDevices->addLog($p);
// Run event
$disableLastRun = true;
$result = $objEvents->runEvent($urlTriggerData['trigger_event'], $disableLastRun);
echo "<pre>";
print_r($result);
echo "</pre>";
} else die('No trigger found');
} else die('No user found');
?>