Store in GIT
This commit is contained in:
@@ -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