Store in GIT
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?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 `username`, `email` FROM `session`, `user` WHERE user.id = session.user AND `session`='$session'";
|
||||
$query = ExecQuery($mysqli, $sql);
|
||||
|
||||
$result = $query->fetch_assoc();
|
||||
|
||||
$str = '{"succes":true, "device":"' . $device . '",';
|
||||
$str.= '"username":"' . $result['username'] . '",';
|
||||
$str.= '"email":"' . $result['email'] . '"}';
|
||||
|
||||
echo $str;
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require("../../inc/connect.php");
|
||||
require("../session.php");
|
||||
|
||||
$session = $_GET['session'];
|
||||
|
||||
if($session == "")
|
||||
{
|
||||
JError("session not set");
|
||||
}
|
||||
|
||||
$name = $_GET['name'];
|
||||
$time = $_GET['time'];
|
||||
$stream = $_GET['stream'];
|
||||
|
||||
if($name == "")
|
||||
{
|
||||
JError("name not set");
|
||||
}
|
||||
if($time == "")
|
||||
{
|
||||
JError("time not set");
|
||||
}
|
||||
if($stream == "")
|
||||
{
|
||||
JError("stream not set");
|
||||
}
|
||||
|
||||
//check session
|
||||
verify_session($mysqli, $session);
|
||||
|
||||
//check if not too many alarms
|
||||
$sql = "SELECT `id` FROM `alarm` WHERE `dev_id`=$deviceid";
|
||||
$query = ExecQuery($mysqli, $sql);
|
||||
|
||||
if($query->num_rows >= 2)
|
||||
{
|
||||
JError("you cannot have more than 2 alarms");
|
||||
}
|
||||
|
||||
//Check if stream is allowed
|
||||
$sql = "SELECT `name` FROM `stream` WHERE `dev_id`=$deviceid AND `id`=$stream";
|
||||
$query = ExecQuery($mysqli, $sql);
|
||||
|
||||
if($query->num_rows < 1)
|
||||
{
|
||||
JError("you cannot use that stream");
|
||||
}
|
||||
|
||||
//Remove seconds
|
||||
$time = substr($time, 0, 5);
|
||||
|
||||
//Check time
|
||||
if(!preg_match("/(2[0-3]|[01][0-9]):([0-5][0-9])/", $time))
|
||||
{
|
||||
JError("invalid time");
|
||||
}
|
||||
|
||||
$time .= ":00";
|
||||
|
||||
//update
|
||||
$sql = "INSERT INTO `alarm` (`name`, `time`, `stream`, `dev_id`) VALUES ('$name', '$time', $stream, $deviceid)";
|
||||
ExecQuery($mysqli, $sql);
|
||||
|
||||
JSuccess("true");
|
||||
?>
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require("../../inc/connect.php");
|
||||
require("../session.php");
|
||||
|
||||
$session = $_GET['session'];
|
||||
$id = $_GET['id'];
|
||||
|
||||
if($session == "")
|
||||
{
|
||||
JError("session not set");
|
||||
}
|
||||
if($id == "")
|
||||
{
|
||||
JError("id not set");
|
||||
}
|
||||
|
||||
//check session
|
||||
verify_session($mysqli, $session);
|
||||
|
||||
$sql = "SELECT `id` FROM `alarm` WHERE `dev_id`=$deviceid AND `id`=$id";
|
||||
$query = ExecQuery($mysqli, $sql);
|
||||
|
||||
if($query->num_rows < 1)
|
||||
{
|
||||
JError("you cannot delete that alarm");
|
||||
}
|
||||
|
||||
//update
|
||||
$sql = "DELETE FROM `alarm` WHERE `id`=$id";
|
||||
ExecQuery($mysqli, $sql);
|
||||
|
||||
JSuccess("true");
|
||||
?>
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require("../../inc/connect.php");
|
||||
require("../session.php");
|
||||
|
||||
$session = $_GET['session'];
|
||||
$id = $_GET['id'];
|
||||
|
||||
if($session == "")
|
||||
{
|
||||
JError("session not set");
|
||||
}
|
||||
if($id == "")
|
||||
{
|
||||
JError("id not set");
|
||||
}
|
||||
|
||||
$name = $_GET['name'];
|
||||
$time = $_GET['time'];
|
||||
$stream = $_GET['stream'];
|
||||
|
||||
if($name == "")
|
||||
{
|
||||
JError("name not set");
|
||||
}
|
||||
if($time == "")
|
||||
{
|
||||
JError("time not set");
|
||||
}
|
||||
if($stream == "")
|
||||
{
|
||||
JError("stream not set");
|
||||
}
|
||||
|
||||
//check session
|
||||
verify_session($mysqli, $session);
|
||||
|
||||
$sql = "SELECT `id` FROM `alarm` WHERE `dev_id`=$deviceid AND `id`=$id";
|
||||
$query = ExecQuery($mysqli, $sql);
|
||||
|
||||
if($query->num_rows < 1)
|
||||
{
|
||||
JError("you cannot edit that alarm");
|
||||
}
|
||||
|
||||
//Check if stream is allowed
|
||||
$sql = "SELECT `name` FROM `stream` WHERE `dev_id`=$deviceid AND `id`=$stream";
|
||||
$query = ExecQuery($mysqli, $sql);
|
||||
|
||||
if($query->num_rows < 1)
|
||||
{
|
||||
JError("you cannot use that stream");
|
||||
}
|
||||
|
||||
//Remove seconds
|
||||
$time = substr($time, 0, 5);
|
||||
|
||||
//Check time
|
||||
if(!preg_match("/(2[0-3]|[01][0-9]):([0-5][0-9])/", $time))
|
||||
{
|
||||
JError("invalid time");
|
||||
}
|
||||
|
||||
$time .= ":00";
|
||||
|
||||
//update
|
||||
$sql = "UPDATE `alarm` SET `name`='$name', `time`='$time', `stream`=$stream WHERE `id`=$id";
|
||||
ExecQuery($mysqli, $sql);
|
||||
|
||||
JSuccess("true");
|
||||
?>
|
||||
@@ -0,0 +1,49 @@
|
||||
<?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 alarm.id AS `id`, alarm.name AS `name`, alarm.time AS `time`, stream.name AS `stream` FROM `alarm`, `session`, `stream` WHERE alarm.stream = stream.id AND alarm.dev_id = session.dev_id AND `session`='$session'";
|
||||
$query = ExecQuery($mysqli, $sql);
|
||||
|
||||
if($query->num_rows < 1)
|
||||
{
|
||||
echo '{"error":"No alarms found"}';
|
||||
exit;
|
||||
}
|
||||
|
||||
$str = '{"succes":true, "device":"' . $device . '", "alarms":[';
|
||||
|
||||
$count = 1;
|
||||
|
||||
while($result = $query->fetch_assoc())
|
||||
{
|
||||
$str .= '{"id":' . $result['id'] . ',';
|
||||
$str .= '"name":"' . $result['name'] . '",';
|
||||
$str .= '"time":"' . $result['time'] . '",';
|
||||
$str .= '"stream":"' . $result['stream'] . '"';
|
||||
|
||||
if($count == $query->num_rows)
|
||||
$str .= '}';
|
||||
else
|
||||
$str .= '},';
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
$str .= ']}';
|
||||
|
||||
echo $str;
|
||||
?>
|
||||
@@ -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");
|
||||
?>
|
||||
@@ -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");
|
||||
?>
|
||||
@@ -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;
|
||||
|
||||
|
||||
?>
|
||||
@@ -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 . '"}';
|
||||
?>
|
||||
@@ -0,0 +1 @@
|
||||
This api is not available to the public.
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require("../inc/connect.php");
|
||||
require("../inc/crypt.php");
|
||||
|
||||
$username = $_GET['username'];
|
||||
$password = $_GET['password'];
|
||||
|
||||
if($username == "")
|
||||
{
|
||||
echo '{"error":"No username"}';
|
||||
exit;
|
||||
}
|
||||
|
||||
if($password == "")
|
||||
{
|
||||
echo '{"error":"No password"}';
|
||||
exit;
|
||||
}
|
||||
|
||||
//Check if user exists
|
||||
$sql = "SELECT `id`, `password`, `verified` FROM `user` WHERE `username`='" . $username . "'";
|
||||
$query = ExecQuery($mysqli, $sql);
|
||||
|
||||
if($query->num_rows < 1){
|
||||
echo '{"error": "Username or password incorrect"}';
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Check if password is correct
|
||||
$result = $query->fetch_assoc();
|
||||
$verified = $result['verified'];
|
||||
$password_hash = $result['password'];
|
||||
|
||||
if(!password_verify($password, $password_hash)){
|
||||
echo '{"error": "Username or password incorrect"}';
|
||||
exit;
|
||||
}
|
||||
else if($verified == 0)
|
||||
{
|
||||
echo '{"error": "Your email address has not yet been verified"}';
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Get user ID, IP
|
||||
$id = $result['id'];
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
|
||||
//Set default device
|
||||
$sql = "SELECT `id` FROM `device` WHERE `user`=$id LIMIT 0,1";
|
||||
$query = ExecQuery($mysqli, $sql);
|
||||
|
||||
if($query->num_rows < 1)
|
||||
{
|
||||
$deviceid = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $query->fetch_assoc();
|
||||
$deviceid = $result['id'];
|
||||
}
|
||||
|
||||
$sessionid = RandomString(60);
|
||||
|
||||
//Update Session ID, Last Login, IP in database
|
||||
$sql = "INSERT INTO session (`user`, `session`, `time`, `remember`, `ip`, `dev_id`, `dev_type`) VALUES ($id, '$sessionid', NOW(), 1, '$ip', $deviceid, 'Android')";
|
||||
ExecQuery($mysqli, $sql);
|
||||
|
||||
//Show session id
|
||||
echo '{"success": true, "session": "' . $sessionid . '"}';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?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
|
||||
$user = verify_session($mysqli, $session);
|
||||
|
||||
//Logout
|
||||
$sql = "DELETE FROM `session` WHERE `session`='$session'";
|
||||
ExecQuery($mysqli, $sql);
|
||||
|
||||
echo '{"success": true}';
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require("../../inc/connect.php");
|
||||
require("../session.php");
|
||||
|
||||
$session = $_GET['session'];
|
||||
|
||||
if($session == "")
|
||||
{
|
||||
JError("no session");
|
||||
}
|
||||
|
||||
//check session
|
||||
verify_session($mysqli, $session);
|
||||
|
||||
JError("not implemented");
|
||||
?>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require("../../inc/connect.php");
|
||||
require("../session.php");
|
||||
|
||||
$session = $_GET['session'];
|
||||
|
||||
if($session == "")
|
||||
{
|
||||
JError("no session");
|
||||
}
|
||||
|
||||
//check session
|
||||
verify_session($mysqli, $session);
|
||||
|
||||
JError("not implemented");
|
||||
?>
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require("../../inc/connect.php");
|
||||
require("../session.php");
|
||||
|
||||
$session = $_GET['session'];
|
||||
|
||||
if($session == "")
|
||||
{
|
||||
JError("no session");
|
||||
}
|
||||
|
||||
$schedule = $_GET['id'];
|
||||
$name = $_GET['name'];
|
||||
$time = $_GET['time'];
|
||||
$duration = $_GET['duration'];
|
||||
$stream = $_GET['stream'];
|
||||
|
||||
if($schedule == "")
|
||||
{
|
||||
JError("no id");
|
||||
}
|
||||
if($name == "")
|
||||
{
|
||||
JError("no name");
|
||||
}
|
||||
if($time == "")
|
||||
{
|
||||
JError("no time");
|
||||
}
|
||||
if($duration == "")
|
||||
{
|
||||
JError("no duration");
|
||||
}
|
||||
if($stream == "")
|
||||
{
|
||||
JError("no stream");
|
||||
}
|
||||
|
||||
//check session
|
||||
verify_session($mysqli, $session);
|
||||
|
||||
//Check if alarms editing is allowed
|
||||
$sql = "SELECT `name` FROM `schedule` WHERE `dev_id`=$deviceid AND `id`=$schedule";
|
||||
$query = ExecQuery($mysqli, $sql);
|
||||
|
||||
if($query->num_rows < 1)
|
||||
{
|
||||
JError("cannot edit schedule");
|
||||
}
|
||||
|
||||
//Check if stream is allowed
|
||||
$sql = "SELECT `name` FROM `stream` WHERE `dev_id`=$deviceid AND `id`=$stream";
|
||||
$query = ExecQuery($mysqli, $sql);
|
||||
|
||||
if($query->num_rows < 1)
|
||||
{
|
||||
JERROR("cannot use stream");
|
||||
}
|
||||
|
||||
//Remove seconds
|
||||
$time = substr($time, 0, 5);
|
||||
|
||||
//Check time
|
||||
if(!preg_match("/(2[0-3]|[01][0-9]):([0-5][0-9])/", $time))
|
||||
{
|
||||
JError("invalid time");
|
||||
}
|
||||
|
||||
$time .= ":00";
|
||||
|
||||
|
||||
//Remove seconds
|
||||
$duration = substr($duration, 0, 5);
|
||||
|
||||
//Check duration
|
||||
if(!preg_match("/(2[0-3]|[01][0-9]):([0-5][0-9])/", $duration))
|
||||
{
|
||||
JError("invalid duration");
|
||||
}
|
||||
|
||||
$duration .= ":00";
|
||||
|
||||
//Add schedule
|
||||
$sql = "UPDATE `schedule` SET `name`='$name', `time`='$time', `duration`='$duration', `stream`=$stream WHERE `id`=$schedule";
|
||||
ExecQuery($mysqli, $sql);
|
||||
|
||||
JSuccess("true");
|
||||
?>
|
||||
@@ -0,0 +1,52 @@
|
||||
<?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 schedule.id AS `id`, schedule.name AS `name`, schedule.time AS `time`, schedule.duration AS `duration`, stream.name AS `stream` FROM `schedule`, `session`, `stream` WHERE schedule.stream = stream.id AND schedule.dev_id = session.dev_id AND `session`='$session'";
|
||||
$query = ExecQuery($mysqli, $sql);
|
||||
|
||||
if($query->num_rows < 1)
|
||||
{
|
||||
echo '{"error":"No schedules found"}';
|
||||
exit;
|
||||
}
|
||||
|
||||
$str = '{"succes":true, "device":"' . $device . '", "schedules":[';
|
||||
|
||||
$count = 1;
|
||||
|
||||
while($result = $query->fetch_assoc())
|
||||
{
|
||||
$str .= '{"id":' . $result['id'] . ',';
|
||||
$str .= '"name":"' . $result['name'] . '",';
|
||||
$str .= '"time":"' . $result['time'] . '",';
|
||||
$str .= '"duration":"' . $result['duration'] . '",';
|
||||
$str .= '"stream":"' . $result['stream'] . '"';
|
||||
|
||||
if($count == $query->num_rows)
|
||||
$str .= '}';
|
||||
else
|
||||
$str .= '},';
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
$str .= ']}';
|
||||
|
||||
echo $str;
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
if(!isset($connected) || !$connected)
|
||||
{
|
||||
echo '{"error":"An error occured"}';
|
||||
exit;
|
||||
}
|
||||
|
||||
function verify_session($mysqli, $session)
|
||||
{
|
||||
global $user;
|
||||
global $deviceid;
|
||||
global $device;
|
||||
|
||||
$sql = "SELECT session.user AS `user`, `remember`, session.dev_id AS `id`, device.dev_id AS `dev_id` FROM `session`, `device`WHERE device.id = session.dev_id AND `session`='$session'";
|
||||
$query = ExecQuery($mysqli, $sql);
|
||||
|
||||
if($query->num_rows < 1)
|
||||
{
|
||||
echo '{"error":"You are not logged in"}';
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $query->fetch_assoc();
|
||||
|
||||
if($result['remember'] != 1)
|
||||
{
|
||||
echo '{"error": "Invalid android session"}';
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE `session` SET `time`=NOW() WHERE `session`='$session'";
|
||||
ExecQuery($mysqli, $sql);
|
||||
|
||||
$user = $result['user'];
|
||||
$deviceid = $result['id'];
|
||||
$device = $result['dev_id'];
|
||||
}
|
||||
|
||||
function JError($str)
|
||||
{
|
||||
echo '{"error":"' . $str . '"}';
|
||||
exit;
|
||||
}
|
||||
|
||||
function JSuccess($str)
|
||||
{
|
||||
echo '{"success":"' . $str . '"}';
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require("../../inc/connect.php");
|
||||
require("../session.php");
|
||||
|
||||
$session = $_GET['session'];
|
||||
|
||||
if($session == "")
|
||||
{
|
||||
JError("no session");
|
||||
}
|
||||
|
||||
//check session
|
||||
verify_session($mysqli, $session);
|
||||
|
||||
JError("not implemented");
|
||||
?>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require("../../inc/connect.php");
|
||||
require("../session.php");
|
||||
|
||||
$session = $_GET['session'];
|
||||
|
||||
if($session == "")
|
||||
{
|
||||
JError("no session");
|
||||
}
|
||||
|
||||
//check session
|
||||
verify_session($mysqli, $session);
|
||||
|
||||
JError("not implemented");
|
||||
?>
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require("../../inc/connect.php");
|
||||
require("../session.php");
|
||||
require("verify.php");
|
||||
|
||||
$session = $_GET['session'];
|
||||
|
||||
if($session == "")
|
||||
{
|
||||
JError("No session");
|
||||
}
|
||||
|
||||
$stream = $_GET['id'];
|
||||
$name = $_GET['name'];
|
||||
$ip = $_GET['ip'];
|
||||
$port = $_GET['port'];
|
||||
$path = $_GET['path'];
|
||||
|
||||
if($stream == "")
|
||||
{
|
||||
JError("No id");
|
||||
}
|
||||
if($name == "")
|
||||
{
|
||||
JError("No name");
|
||||
}
|
||||
if($ip == "")
|
||||
{
|
||||
JError("No ip");
|
||||
}
|
||||
if($port == "")
|
||||
{
|
||||
JError("No port");
|
||||
}
|
||||
if($path == "")
|
||||
{
|
||||
JError("No path");
|
||||
}
|
||||
|
||||
//check session
|
||||
verify_session($mysqli, $session);
|
||||
|
||||
//Check if stream editing is allowed
|
||||
$sql = "SELECT `name` FROM `stream` WHERE `dev_id`=$deviceid AND `id`=$stream";
|
||||
$query = ExecQuery($mysqli, $sql);
|
||||
|
||||
if($query->num_rows < 1)
|
||||
{
|
||||
JError("cannot edit stream");
|
||||
}
|
||||
|
||||
//Fix input
|
||||
$ip = rtrim($ip, "/");
|
||||
$ip = ltrim($ip, "http://");
|
||||
$ip = ltrim($ip, "https://");
|
||||
$path = ltrim($path, "/");
|
||||
|
||||
//Check if stream is valid
|
||||
$resp = stream_verify($ip, $port, $path);
|
||||
|
||||
if($resp === false)
|
||||
{
|
||||
JError("invalid stream");
|
||||
}
|
||||
$ip = $resp;
|
||||
|
||||
//Update stream
|
||||
$sql = "UPDATE `stream` SET `name`='$name', `ip`='$ip', `port`='$port', `path`='$path' WHERE `id`=$stream";
|
||||
ExecQuery($mysqli, $sql);
|
||||
|
||||
JSuccess("true");
|
||||
?>
|
||||
@@ -0,0 +1,52 @@
|
||||
<?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 stream.id AS `id`, stream.name AS `name`, stream.ip AS `ip`, `port`, `path` FROM `stream`, `session` WHERE stream.dev_id = session.dev_id AND `session`='$session'";
|
||||
$query = ExecQuery($mysqli, $sql);
|
||||
|
||||
if($query->num_rows < 1)
|
||||
{
|
||||
echo '{"error":"No streams found"}';
|
||||
exit;
|
||||
}
|
||||
|
||||
$str = '{"succes":true, "device":"' . $device . '", "streams":[';
|
||||
|
||||
$count = 1;
|
||||
|
||||
while($result = $query->fetch_assoc())
|
||||
{
|
||||
$str .= '{"id":' . $result['id'] . ',';
|
||||
$str .= '"name":"' . $result['name'] . '",';
|
||||
$str .= '"ip":"' . $result['ip'] . '",';
|
||||
$str .= '"port":' . $result['port'] . ',';
|
||||
$str .= '"path":"' . $result['path'] . '"';
|
||||
|
||||
if($count == $query->num_rows)
|
||||
$str .= '}';
|
||||
else
|
||||
$str .= '},';
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
$str .= ']}';
|
||||
|
||||
echo $str;
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
function stream_verify($ip, $port, $path)
|
||||
{
|
||||
if(filter_var($ip, FILTER_VALIDATE_IP) === false) {
|
||||
$temp = getAddresses_www( $ip);
|
||||
|
||||
if(count($temp) == 0)
|
||||
return false;
|
||||
else
|
||||
$ip = $temp[0];
|
||||
}
|
||||
|
||||
$response = get_headers("http://" . $ip . ":" . $port . "/" . $path);
|
||||
|
||||
if(get_http_response_code($response) != 200 && !if_http_audio($response))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $ip;
|
||||
}
|
||||
}
|
||||
|
||||
function get_http_response_code($headers) {
|
||||
return substr($headers[0], 9, 3);
|
||||
}
|
||||
|
||||
function if_http_audio($headers) {
|
||||
$type = substr($headers[3], 14);
|
||||
$arr = explode("/", $type);
|
||||
return $arr[0] == "audio";
|
||||
}
|
||||
|
||||
function getAddresses($domain) {
|
||||
$records = dns_get_record($domain);
|
||||
$res = array();
|
||||
foreach ($records as $r) {
|
||||
if ($r['host'] != $domain) continue; // glue entry
|
||||
if (!isset($r['type'])) continue; // DNSSec
|
||||
|
||||
if ($r['type'] == 'A') $res[] = $r['ip'];
|
||||
if ($r['type'] == 'AAAA') $res[] = $r['ipv6'];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
function getAddresses_www($domain) {
|
||||
$res = getAddresses($domain);
|
||||
if (count($res) == 0) {
|
||||
$res = getAddresses('www.' . $domain);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user