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
+56
View File
@@ -0,0 +1,56 @@
<?php
header('Content-Type: application/json');
require("../../inc/connect.php");
require("../session.php");
$session = $_GET['session'];
$device = $_GET['device'];
if($session == "")
{
JError("no session");
}
if($device == "")
{
JError("no device");
}
if(strlen($device) != 6)
{
JError("device id invalid");
}
//check session
verify_session($mysqli, $session);
//verify device
$sql = "SELECT `id` FROM `device` WHERE `dev_id`='" . $device . "' AND `user`=0";
$query = ExecQuery($mysqli, $sql);
if($query->num_rows < 1)
{
JError("device id invalid");
}
//get email address and username
$sql = "SELECT `username`, `email` FROM `user` WHERE `id`=$user";
$query = ExecQuery($mysqli, $sql);
$result = $query->fetch_assoc();
$email = $result['email'];
$username = $result['username'];
$code = $email . "~" . $device . "~";
$code .= RandomString(96 - strlen($code));
$code = str_rot13($code);
$sql = "UPDATE `user` SET `code`='$code' WHERE `id`=$user";
ExecQuery($mysqli, $sql);
$msg = "Hello " . $username . ",\n\n";
$msg .= "Please verify your new device by clicking the link below.\n";
$msg .= "<a href='http://lipa.kvewijk.nl/manage/php/session/verify.php?code=" . urlencode($code) . "'>Verify</a>";
sendMail($email, "Verify Device", $msg);
JSuccess("true");
?>
+39
View File
@@ -0,0 +1,39 @@
<?php
header('Content-Type: application/json');
require("../../inc/connect.php");
require("../session.php");
$session = $_GET['session'];
$dev_id = $_GET['device'];
if($session == "")
{
JError("session not set");
}
if($dev_id == "")
{
JError("device not set");
}
$name = $_GET['name'];
$location = $_GET['location'];
$description = $_GET['description'];
//check session
verify_session($mysqli, $session);
//Check if you own the device
$sql = "SELECT `id` FROM `device` WHERE `dev_id`='$dev_id' AND `user`=$user";
$query = ExecQuery($mysqli, $sql);
if($query->num_rows < 1)
{
JError("you cannot edit that device");
}
//update
$sql = "UPDATE `device` SET `name`='$name', `location`='$location', `description`='$description' WHERE `dev_id`='$dev_id'";
ExecQuery($mysqli, $sql);
JSuccess("true");
?>
+54
View File
@@ -0,0 +1,54 @@
<?php
header('Content-Type: application/json');
require("../../inc/connect.php");
require("../session.php");
$session = $_GET['session'];
if($session == "")
{
echo '{"error":"No session"}';
exit;
}
//check session
verify_session($mysqli, $session);
//Check devices
$sql = "SELECT device.dev_id AS dev_id, device.id AS id, `name`, `description`, `location` FROM `device`, `session` WHERE device.user = session.user AND `session`='$session'";
$query = ExecQuery($mysqli, $sql);
if($query->num_rows < 1)
{
echo '{"error":"No devices found"}';
exit;
}
$str = '{"succes":true, "devices":[';
$count = 1;
while($result = $query->fetch_assoc())
{
$str .= '{"device":"' . $result['dev_id'] . '",';
$str .= '"name":"' . $result['name'] . '",';
$str .= '"description":"' . $result['description'] . '",';
$str .= '"location":"' . $result['location'] . '"';
if($deviceid == $result['id'])
$str .= ', "selected":true';
if($count == $query->num_rows)
$str .= '}';
else
$str .= '},';
$count++;
}
$str .= ']}';
echo $str;
?>
+44
View File
@@ -0,0 +1,44 @@
<?php
header('Content-Type: application/json');
require("../../inc/connect.php");
require("../session.php");
$session = $_GET['session'];
$selected_device = $_GET['device'];
if($session == "")
{
echo '{"error":"No session"}';
exit;
}
if($selected_device == "")
{
echo '{"error":"No new device to select"}';
exit;
}
//check session
verify_session($mysqli, $session);
//check if own device
$sql = "SELECT `id` FROM `device` WHERE `dev_id`='$selected_device' AND `user`=$user";
$query = ExecQuery($mysqli, $sql);
if($query->num_rows < 1)
{
echo '{"error":"Cannot select device"}';
exit;
}
$result = $query->fetch_assoc();
$id = $result['id'];
//Select the device
$sql = "UPDATE `session` SET `dev_id`=$id WHERE `session`='$session'";
ExecQuery($mysqli, $sql);
echo '{"success":true, "device": "' . $selected_device . '"}';
?>