<?php
//Authentication
$json = file_get_contents('http://IP:PORT/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=3&account=user&passwd=PASSWORD&session=SurveillanceStation&format=sid');
$obj = json_decode($json, true);
$sid = $obj["data"]["sid"];
//GetList
$json = file_get_contents('http://IP:PORT/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=List&version=3&_sid='.$sid);
$obj = json_decode($json, true);
$cam_activated = $obj["data"]["cameras"][0]["enabled"];
if($cam_activated == false){
//Deactivate cam
$json = file_get_contents('http://IP:PORT/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=Enable&version=3&cameraIds=2&_sid='.$sid);
echo "<div class=\"centered\"><img src=\"http://192.168.178.99:5000/on_icon.png\" style=\"width:auto;height:auto;\" /></div>";
}
else
{
//Deactivate cam
$json = file_get_contents('http://IP:PORT/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=Enable&version=3&cameraIds=2&_sid='.$sid);
echo "<div class=\"centered\"><img src=\"https://externeAdresse:Port/off_icon.png\" /></div>";
}
?>
<?php
$httpformat="http"; //hier angeben ob http oder https
$port="5000"; //port
$loginname="administrator"; //Loginname an der Surveillance Station
$passwd="Password"; //passwort an der Surveillance Station
$ip="IP"; //ip adresse der Surveillance station im LAN
$cam_id="2"; // Kamera ID mit script "hole Kamera ID" abfragen, später automatisieren
// db
$db_name = "root";
$db_pw = "Password";
$db_database = "Surveillance";
$db_table = "user";
$db_ip = "127.0.0.1";
// activate Surveillance
$surveillance = true;
// connect to db
$connection = mysql_connect(db_ip, $db_user,$db_pw) or die ("No connection. User or password is wrong");
// select table
mysql_select_db($db_database) or die ("The Database ". $db_database ." doesn't exist");
// update table
$query = "UPDATE ".$db_table." Set available = ".mysql_real_escape_string($_GET['available']).", time = NOW() WHERE id = ".mysql_real_escape_string($_GET['id'])." AND pw='".mysql_real_escape_string($_GET['pw'])."'";
$update = mysql_query($query);
if (!$update) {
die('Error: ' . mysql_error());
}
// select info
$query = "SELECT available FROM ".$db_table;
$result = mysql_query($query);
while($row = mysql_fetch_object($result)) {
if ($row->available == true)
$surveillance = false;
}
//Login an der Surveillance Station:
$json = file_get_contents($httpformat."://".$ip.":".$port."/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=3& account=".$loginname."&passwd=".$passwd."&session= SurveillanceStation&format=sid'");
$obj = json_decode($json, true);
$sid = $obj["data"]["sid"];
if ($surveillance) {
//Kamera aktivieren:
$json = file_get_contents($httpformat."://".$ip.":".$port."/webapi/_______________________________________________________entry.cgi?api=SYNO.SurveillanceStation.Camera&method=Enable&version=3&cameraIds=".$cam_id."&_sid=".$sid);
}else {
//Kamera deaktivieren:
}
//Logout Surveillance Station:
$out = file_get_contents($httpformat."://".$ip.":".$port."/webapi/auth.cgi?api=SYNO.API.Auth&version=3&method=Logout &session=SurveillanceStation");
?>
A $ was missing^^$connection = mysql_connect($db_ip, $db_user,$db_pw) or die ("No connection. User or password is wrong");
Tried that already, but this leads to:Haha easy error xD
A $ was missing^^$connection = mysql_connect($db_ip, $db_user,$db_pw) or die ("No connection. User or password is wrong");
Currently I think its not a DB-Problem, but an API-Problem. Even when I use only the snipplet to activate / deactivate the cam, it doesn't work.In you db you set available as int, but it should be boolean. Don't know if it makes a difference but could be hint
<?php
$httpformat="http"; //hier angeben ob http oder https
$port="5000"; //port
$loginname="administrator"; //Loginname an der Surveillance Station
$passwd="Password"; //passwort an der Surveillance Station
$ip="192.168.178.99"; //ip adresse der Surveillance station im LAN
$cam_id="2"; // Kamera ID mit script "hole Kamera ID" abfragen, später automatisieren
// db
$db_name = "root";
$db_pw = "Password";
$db_database = "Surveillance";
$db_table = "user";
$db_ip = "127.0.0.1";
// activate Surveillance
$surveillance = true;
// connect to db
$connection = mysql_connect($db_ip, $db_name,$db_pw) or die ("No connection. User or password is wrong");
// select table
mysql_select_db($db_database) or die ("The Database ". $db_database ." doesn't exist");
// update table
$query = "UPDATE ".$db_table." Set available = ".mysql_real_escape_string($_GET['available']).", time = NOW() WHERE id = ".mysql_real_escape_string($_GET['id'])." AND password='".mysql_real_escape_string($_GET['pw'])."'";
$update = mysql_query($query);
if (!$update) {
die('Error: ' . mysql_error());
}
// select info
$query = "SELECT available FROM ".$db_table;
$result = mysql_query($query);
while($row = mysql_fetch_object($result)) {
if ($row->available == true)
$surveillance = false;
}
//Login an der Surveillance Station:
$json = file_get_contents($httpformat."://".$ip.":".$port."/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=3& account=".$loginname."&passwd=".$passwd."&session= SurveillanceStation&format=sid'");
$obj = json_decode($json, true);
$sid = $obj["data"]["sid"];
if ($surveillance) {
//Kamera aktivieren:
$json = file_get_contents($httpformat."://".$ip.":".$port."/webapi/_______________________________________________________entry.cgi?api=SYNO.SurveillanceStation.Camera&method=Enable&version=3&cameraIds=".$cam_id."&_sid=".$sid);
}else {
//Kamera deaktivieren:
}
//Logout Surveillance Station:
$out = file_get_contents($httpformat."://".$ip.":".$port."/webapi/auth.cgi?api=SYNO.API.Auth&version=3&method=Logout &session=SurveillanceStation");
?>
<?php
//Authentication
$json = file_get_contents('http://192.168.178.99:5000/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=3&account=administrator&passwd=Password&session=SurveillanceStation&format=sid');
$obj = json_decode($json, true);
$sid = $obj["data"]["sid"];
//GetList
$json = file_get_contents('http://192.168.178.99:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=List&version=3&_sid='.$sid);
$obj = json_decode($json, true);
$cam_activated = $obj["data"]["cameras"][0]["enabled"];
if($cam_activated == false){
//Activate cam
$json = file_get_contents('http://192.168.178.99:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=Enable&version=3&cameraIds=2&_sid='.$sid);
echo "<div class=\"centered\"><img src=\"http://192.168.178.99:5000/on_icon.png\" style=\"width:auto;height:auto;\" /></div>";
}
else
{
//Activate cam
$json = file_get_contents('http://192.168.178.99:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=Enable&version=3&cameraIds=2&_sid='.$sid);
echo "<div class=\"centered\"><img src=\"http://192.168.178.99:5000/off_icon.png\" /></div>";
}
?>
Don't know how to do this. Do you see a possibility to combine the first db-script with the second working activating script?put some echo "xyz"; in the code and try to trace it down and use var_dump() to see whats in the vars^^
<?php
$httpformat="http"; //hier angeben ob http oder https
$port="5000"; //port
$loginname="administrator"; //Loginname an der Surveillance Station
$passwd="Password"; //passwort an der Surveillance Station
$ip="192.168.178.99"; //ip adresse der Surveillance station im LAN
$cam_id="2"; // Kamera ID mit script "hole Kamera ID" abfragen, später automatisieren
// db
$db_name = "root";
$db_pw = "Password";
$db_database = "Surveillance";
$db_table = "user";
$db_ip = "127.0.0.1";
// activate Surveillance
$surveillance = true;
// connect to db
$connection = mysql_connect($db_ip, $db_name,$db_pw) or die ("No connection. User or password is wrong");
// select table
mysql_select_db($db_database) or die ("The Database ". $db_database ." doesn't exist");
// update table
$query = "UPDATE ".$db_table." Set available = ".mysql_real_escape_string($_GET['available']).", time = NOW() WHERE id = ".mysql_real_escape_string($_GET['id'])." AND password='".mysql_real_escape_string($_GET['pw'])."'";
$update = mysql_query($query);
if (!$update) {
die('Error: ' . mysql_error());
}
// select info
$query = "SELECT available FROM ".$db_table;
$result = mysql_query($query);
while($row = mysql_fetch_object($result)) {
if ($row->available == true)
$surveillance = false;
}
//Authentication
$json = file_get_contents('http://192.168.178.99:5000/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=3&account=administrator&passwd=Password&session=SurveillanceStation&format=sid');
$obj = json_decode($json, true);
$sid = $obj["data"]["sid"];
//GetList
$json = file_get_contents('http://192.168.178.99:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=List&version=3&_sid='.$sid);
$obj = json_decode($json, true);
$cam_activated = $obj["data"]["cameras"][0]["enabled"];
if ($surveillance && !$cam_activated) {
//Activate cam
$json = file_get_contents('http://192.168.178.99:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=Enable&version=3&cameraIds=2&_sid='.$sid);
echo "<div class=\"centered\"><img src=\"http://192.168.178.99:5000/on_icon.png\" style=\"width:auto;height:auto;\" /></div>";
}else if(!$surveillance && $cam_activated) {
//Deactivate cam
$json = file_get_contents('http://192.168.178.99:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=Enable&version=3&cameraIds=2&_sid='.$sid);
echo "<div class=\"centered\"><img src=\"http://192.168.178.99:5000/off_icon.png\" /></div>";
}
?>