-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfobcheck.php
55 lines (46 loc) · 1.25 KB
/
fobcheck.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
/*
Dependencies: mosquitto-client, MySQL, PHP
Written By: John Rogers
License: GPL
Contact: john at wizworks dot net
Review: 14. Dec. 2019 - (martinius96)
*/
<?php
// DB Credentials
$servername = "127.0.0.1";
$username = "";
$password = "";
$dbname = "";
// MQTT Credentials
$pubHost = "";
$pubUser = "";
$pubPass = "";
$topic = "domoticz/in";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$search = mysqli_real_escape_string($conn, $_POST['search']);
$search = trim( $search );
$q1 = "SELECT active FROM tags WHERE tag = '$search' LIMIT 1;";
$result = mysqli_query($conn, $q1);
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysqli_error();
exit;
}
while ($row = mysqli_fetch_assoc($result)) {
foreach ($row as $field)
if ( $field == '1' ) {
echo shell_exec(`mosquitto_pub -h $pubHost -u $pubUser -P $pubPass -t $topic -m "{\"command\":\"switchlight\",\"idx\":123,\"switchcmd\":\"Off\"}"`);
echo "SPANK";
} elseif ( $field == '0' ) {
echo "INVALID";
} elseif ( $field == ' ' ) {
echo "INVALID";
}
}
mysqli_free_result($result);
?>