Store in GIT

This commit is contained in:
2026-06-17 15:46:26 +02:00
parent 47150cc7ca
commit 876ad89e72
134 changed files with 31034 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
<?php
header('Content-Type: application/json');
require('../inc/connect.php');
$device_id = $_GET["id"];
if($device_id == "")
{
echo '{"error":"device-id not set"}';
exit;
}
// Get all the details for the ID
$sql = "SELECT alarm.id, alarm.name, alarm.time, stream.ip, stream.port, stream.path FROM alarm, device, stream WHERE alarm.dev_id=device.id AND alarm.stream=stream.id AND device.dev_id='" . $device_id . "'";
$query = ExecQuery($mysqli, $sql);
if ($query->num_rows === 0) {
echo '{"error":"device-id not found", "device-id":"' . $device_id . '"}';
exit;
}
$size = $query->num_rows;
$str = '{"alarms": [';
$count = 1;
while ($row = $query->fetch_assoc()) {
$time = $row['time'];
$timea = explode(":", $time);
$hour = $timea[0];
$minute = $timea[1];
$str .= '{"id":"' . $row["id"] . '", ';
$str .= '"name":"' . $row["name"] . '", ';
$str .= '"hour":"' . $hour . '", ';
$str .= '"minute":"' . $minute. '", ';
$str .= '"ip":"' . $row["ip"] . '", ';
$str .= '"port":"' . $row["port"] . '", ';
$str .= '"path":"/' . $row["path"] . '"';
if($count == $query->num_rows)
{
$str .= '}';
}
else
{
$str .= '}, ';
}
$count++;
}
$str .= ']}';
echo $str;
?>
+1
View File
@@ -0,0 +1 @@
This api is not available to the public.
+18
View File
@@ -0,0 +1,18 @@
Page loaded: Testing from site4 for device 61YAY2
Email sent successfully
Page loaded: Testing from site8 for device 61YAY2
Email sent successfully
Page loaded: for device 61YAY2
body/dev not set
Page loaded: for device 61YAY2
body/dev not set
Page loaded: for device 61YAY2
body/dev not set
Page loaded: for device 61YAY2
body/dev not set
Page loaded: for device 61YAY2
body/dev not set
Page loaded: for device 61YAY2
body/dev not set
Page loaded: Alarm at 20:05:00 for device 61YAY2
Email sent successfully
+38
View File
@@ -0,0 +1,38 @@
<?php
header('Content-Type: application/json');
require('../inc/connect.php');
function RandomID()
{
//Generate Session ID
$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$str = '';
for ($i = 0; $i < 6; $i++) {
$str .= $characters[rand(0, strlen($characters) - 1)];
}
return $str;
}
$valid = false;
while(!$valid)
{
$device = RandomID();
// Check if ID already exists
$sql = "SELECT `id` FROM device WHERE dev_id='" . $device . "'";
$query = ExecQuery($mysqli, $sql);
$valid = ($query->num_rows < 1);
}
// Register new ID
$ip = $_SERVER['REMOTE_ADDR'];
$sql = "INSERT INTO device (dev_id, ip) VALUES ('" . $device . "', '" . $ip . "')";
ExecQuery($mysqli, $sql);
echo '{"device":"' . $device . '"}';
?>
+48
View File
@@ -0,0 +1,48 @@
<?php
header('Content-Type: application/json');
require('../inc/connect.php');
$device_id = $_GET["id"];
$key = $_GET["key"];
if($device_id == "")
{
echo '{"error":"device-id not set"}';
exit;
}
if($key== "")
{
echo '{"error":"key not set"}';
exit;
}
if($key != "boef1239")
{
echo '{"error":"invalid key"}';
exit;
}
// Check if ID actually exists
$sql = "SELECT `id` FROM device WHERE dev_id='" . $device_id . "'";
$query = ExecQuery($mysqli, $sql);
if($query->num_rows < 1){
echo '{"error":"device-id does not exist", "device-id": "' . $device_id . '"}';
exit;
}
$result = $query->fetch_assoc();
$id = $result['id'];
//Delete all related data
$sql = "DELETE FROM device WHERE id=$id";
ExecQuery($mysqli, $sql);
$sql = "DELETE FROM alarm WHERE dev_id=$id";
ExecQuery($mysqli, $sql);
$sql = "DELETE FROM stream WHERE dev_id=$id";
ExecQuery($mysqli, $sql);
echo '{"success":"true"}';
?>
+66
View File
@@ -0,0 +1,66 @@
<?php
header('Content-Type: application/json');
require('../inc/connect.php');
$device_id = $_GET["id"];
if($device_id == "")
{
echo '{"error":"device-id not set"}';
exit;
}
// Get all the details for the ID
$sql = "SELECT schedule.id, schedule.name, schedule.time, schedule.duration, stream.ip, stream.port, stream.path FROM schedule, device, stream WHERE schedule.dev_id=device.id AND schedule.stream=stream.id AND device.dev_id='" . $device_id . "'";
$query = ExecQuery($mysqli, $sql);
if ($query->num_rows === 0) {
echo '{"error":"device-id not found", "device-id":"' . $device_id . '"}';
exit;
}
$size = $query->num_rows;
$str = '{"schedules": [';
$count = 1;
while ($row = $query->fetch_assoc()) {
$time = $row['time'];
$timea = explode(":", $time);
$hour = $timea[0];
$minute = $timea[1];
$duration = $row['duration'];
$durationa = explode(":", $duration);
$dhour = $durationa[0];
$dminute = $durationa[1];
$str .= '{"id":"' . $row["id"] . '", ';
$str .= '"name":"' . $row["name"] . '", ';
$str .= '"hour":"' . $hour . '", ';
$str .= '"minute":"' . $minute. '", ';
$str .= '"dhour":"' . $dhour . '", ';
$str .= '"dminute":"' . $dminute. '", ';
$str .= '"ip":"' . $row["ip"] . '", ';
$str .= '"port":"' . $row["port"] . '", ';
$str .= '"path":"/' . $row["path"] . '"';
if($count == $query->num_rows)
{
$str .= '}';
}
else
{
$str .= '}, ';
}
$count++;
}
$str .= ']}';
echo $str;
?>
+53
View File
@@ -0,0 +1,53 @@
<?php
header('Content-Type: application/json');
require('../inc/connect.php');
$device_id = $_GET["id"];
if($device_id == "")
{
echo '{"error":"device-id not set"}';
exit;
}
// Get all the details for the ID
$sql = "SELECT stream.id, stream.name, stream.ip, stream.port, stream.path FROM stream, device WHERE stream.dev_id=device.id AND device.dev_id='" . $device_id . "'";
$query = ExecQuery($mysqli, $sql);
if ($query->num_rows === 0) {
echo '{"error":"device-id not found", "device-id":"' . $device_id . '"}';
exit;
}
$size = $query->num_rows;
$str = '{"streams": [';
$count = 1;
while ($row = $query->fetch_assoc()) {
$str .= '{"id":"' . $row["id"] . '", ';
$str .= '"name":"' . $row["name"] . '", ';
$str .= '"ip":"' . $row["ip"] . '", ';
$str .= '"port":"' . $row["port"] . '", ';
$str .= '"path":"/' . $row["path"] . '"';
if($count == $query->num_rows)
{
$str .= '}';
}
else
{
$str .= '}, ';
}
$count++;
}
$str .= ']}';
echo $str;
?>
+42
View File
@@ -0,0 +1,42 @@
<?php
header('Content-Type: application/json');
$ip = $_SERVER['REMOTE_ADDR'];
$timezn = geoip_time_zone_by_country_and_region(geoip_country_code_by_name($ip));
if($timezn == "")
{
echo '{"timezone":"11"}';
exit;
}
$time = new DateTime('now', new DateTimeZone($timezn));
$timezoneOffset = $time->format('P');
$DST = $time->format('I');
if (strpos($timezoneOffset , '-') !== FALSE)
{
$str = intval(substr($timezoneOffset, 1, 2));
$arrayval = 11 - $str;
//check DST
if($DST)
$arrayval -= 1;
echo '{"timezone":"' . $arrayval . '"}';
}
else if (strpos($timezoneOffset , '+') !== FALSE)
{
$str = intval(substr($timezoneOffset, 1, 2));
$arrayval = 11 + $str;
//check DST
if($DST)
$arrayval -= 1;
echo '{"timezone":"' . $arrayval . '"}';
}
else
{
echo '{"timezone":"11"}';
}
?>
+51
View File
@@ -0,0 +1,51 @@
<?php
header('Content-Type: application/json');
require('../inc/connect.php');
// Twitter account login en email login:
// twitter username: avanstwitter
// ww twitter: Avans123!
// email: avanstwitter@gmail.com
// ww email: Avans123!
// tweets via https://ifttt.com/
//Declare get variables
$body = $_GET["body"];
$id = $_GET["id"];
error_log("Page loaded: $body for device $id\n", 3, "lipa.log");
//If a get variable is empty or missing
if($body == "" || $id == "")
{
echo '{"error":"body and/or device id not set"}';
error_log("body/dev not set\n", 3, "lipa.log");
exit;
}
//Check if device id exists
$valid = 0;
$sql = "SELECT `id` FROM `device` WHERE dev_id='" . $id . "'";
$query = ExecQuery($mysqli, $sql);
if($query->num_rows < 1)
{
echo '{"error":"device id does not exist"}';
error_log("Device id does not exist\n", 3, "lipa.log");
exit;
}
$to = 'trigger@recipe.ifttt.com';
$subject = '#send';
$headers = 'From: avanstwitter@gmail.com' . "\r\n";
$mailbody = $body . " - #" . $id;
//If body is too long (over 140 char's), only send first 140 characters
if(strlen($mailbody) > 140){
$mailbody = substr($mailbody, 0, 140);
}
mail($to, $subject, $mailbody, $headers);
error_log("Email sent successfully: $mailbody\n", 3, "lipa.log");
echo '{"success":"true"}';
?>