-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremoteprocessor.php
33 lines (32 loc) · 1.35 KB
/
remoteprocessor.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
<?php
include 'config.inc.php';
//if (isset($_POST['username']) && isset($_POST['password']) && $_POST['username'] == $ORusername && $_POST['password'] == $ORpassword) {
if (isset($_POST['switch_id'])) {
$switch_id = $_POST['switch_id'];
if (isset($_POST['switch_status'])) {
$switch_status = $_POST['switch_status'];
$switch_status = $switch_status ? "on" : "off";
// Write Switch
$con = mysqli_connect($dbhost, $dbusername, $dbpassword, $dbname) or die();
$query = "UPDATE `$dbname`.`switches` SET `switch_state`=\"" . $switch_status . "\" WHERE `switch_id` = '$switch_id'";
$result = mysqli_query($con, $query) or die("on");
mysqli_close($con);
echo "1";
}
} else if (isset($_GET['switch_id'])) {
// Read Switch
$switch_id = $_GET['switch_id'];
$con = mysqli_connect($dbhost, $dbusername, $dbpassword, $dbname) or die();
$query = "SELECT `switch_state` FROM `$dbname`.`switches` WHERE `switch_id` = '$switch_id'";
$result = mysqli_query($con, $query) or die();
$row = mysqli_fetch_row($result);
$switch_status = $row[0];
mysqli_close($con);
echo $switch_status;
} else {
echo 'Error: 404 - Page not found!';
}
//} else {
// echo 'Error: 404 - Page not found!';
//}
?>