<?php
$httpformat="http"; //hier angeben ob http oder https
$port="5000"; //port
$loginname="NAME"; //Loginname an der Surveillance Station
$passwd="PASSWORT"; //passwort an der Surveillance Station
$ip="IP-ADRESSE"; //ip adresse der Surveillance station im LAN
$cam_id="1"; // 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://IP_ADRESSE:PORT/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=3&account=NAME&passwd=PASSWORT&session=SurveillanceStation&format=sid');
$obj = json_decode($json, true);
$sid = $obj["data"]["sid"];
//GetList
$json = file_get_contents('http://IPADRESSE: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 ($surveillance && !$cam_activated) {
//Activate cam
$json = file_get_contents('http://IPADRESSE:PORT/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=Enable&version=3&cameraIds=1&_sid='.$sid);
echo "<div class=\"centered\"><img src=\"http://IPADRESSE:PORT/on_icon.png\" style=\"width:auto;height:auto;\" /></div>";
}else if(!$surveillance && $cam_activated) {
//Deactivate cam
$json = file_get_contents('http://IPADRESSE:PORT/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=Disable&version=3&cameraIds=1&_sid='.$sid);
echo "<div class=\"centered\"><img src=\"http://IPADRESSE:PORT/off_icon.png\" /></div>";
}
?>
Könntest du hierzu was schreiben, wie du das genau gemacht hast? Ich habe ja zwar auch die Spalte Zeit in der SQL-Tabelle, nutze diese aber noch nicht. Derzeit habe ich nur einen Cronjobs nachts stündlich, der aktiviert, und einen morgens, der deaktiviert. Das ist aber nicht gut, weil wenn morgens keiner da ist, soll die SS natürlich aktiviert sein. Bin da für Hinweise sehr dankbar.Um eine dauerhafte aktivierung im Nachtzeitraum zu schaffen habe ich im PHP script noch einen vergleich der Uhrzeit mit aktivierung / deaktivierung unabhängig von der Anwesenheit. Daz umuss aber ein Cronjob laufen der die PHP seite zum Beispiel alle 30 min aufruft damit der Uhrzeitvergleich stattfinden kann.
Mach ich. Sobald ich wieder daheim bin und Zeit habe...Könntest du hierzu was schreiben, wie du das genau gemacht hast? Ich habe ja zwar auch die Spalte Zeit in der SQL-Tabelle, nutze diese aber noch nicht. Derzeit habe ich nur einen Cronjobs nachts stündlich, der aktiviert, und einen morgens, der deaktiviert. Das ist aber nicht gut, weil wenn morgens keiner da ist, soll die SS natürlich aktiviert sein. Bin da für Hinweise sehr dankbar.
<?php
if (isset($_POST['cam_mode'])){$cam_mode=$_POST['cam_mode'];}else{ if (isset($_GET['cam_mode'])){$cam_mode=$_GET['cam_mode'];}else{unset($cam_mode);}}
if (isset($_POST['user'])){$user=$_POST['user'];}else{ if (isset($_GET['user'])){$user=$_GET['user'];}else{unset($user);}}
if (isset($_POST['pass'])){$pass=$_POST['pass'];}else{ if (isset($_GET['pass'])){$pass=$_GET['pass'];}else{unset($pass);}}
include ("xxxxx.php"); //Verbindung zu Kategorie Tabelle herstellen
//--------beginn settings
$httpformat="xxxxxxx"; //hier angeben ob http oder https
$port="xxxxxx"; //port
$loginname="xxxxxxx"; //Loginname an der Surveillance Station
$passwd="xxxxxxxx"; //passwort an der Surveillance Station
$ip="xxxxxxxxxx"; //ip adresse der Surveillance station
$cam_id="xxxxx"; // Kamera ID mit script "hole Kamera ID" abfragen, später automatisieren
$night_start="2100"; //Beginn Nachtmodus Format HHmm
$night_end="0620"; //Ende Nachtmodus Format HHmm
$uhrzeit = date("Hi",time());
$path="/webapi/_______________________________________________________entry.cgi";
//---------BEGINN USERSPERRE
if ((($user=="USERNAME2") and ($pass=="PASSWORD2")) or (($user=="USERNAME1") and ($pass=="PASSWORD1")))
{echo $user."<br>";} else {$user="USERNAMECRONJOB";$pass="PASSWORDCRONJOB";echo $user."<br>";}
//---------ENDE USERSPERRE
//---------BEGINN zeitsteuerung Nachtmodus
if (($uhrzeit > $night_end) AND ($uhrzeit < $night_start))
{
//Tagmodus
echo "Tagmodus aktiv<br>";
$presence=0;
}
else
{
//Nachtmodus
echo "Nachtmodus aktiv<br>";
$presence=1;
}
//---------Ende zeitteuerung Nachtmodus
//------BEGINN LOGFILE IN DATENBANK TABELLE 'logfile' SCHREIBEN
if ($cam_mode=="on")
{
$presence=0;
}
else
{
if ($cam_mode=="off")
{$presence=1;}
}
mysql_query("INSERT INTO logtable (TIME,USERNAME,PRESENT) VALUES (NOW(),'$user','$presence')");
//------ENDE LOGFILE SCHREIBEN
//------BEGINN ANWESENHEITSAUSWERTUNG
echo "Statusanzeige Anwesenheit:<br><br>";
$result_entry = mysql_query("SELECT * FROM `logtable` WHERE USERNAME like '%USERNAMECRONJOB%' ORDER BY ID DESC");
$result_entry_num = mysql_num_rows($result_entry);
if ($result_entry_num==0)
{echo "nichts gefunden";}
else
{
$presentA=mysql_result($result_entry,0,"PRESENT");
echo "Nachtmodus:".$presentA."<br>";
}
$result_entry = mysql_query("SELECT * FROM `logtable` WHERE USERNAME like '%USERNAME2%' ORDER BY ID DESC");
$result_entry_num = mysql_num_rows($result_entry);
if ($result_entry_num==0)
{echo "nichts gefunden";}
else
{
$presentB=mysql_result($result_entry,0,"PRESENT");
$timeB=mysql_result($result_entry,0,"TIME");
echo "USERNAME2 present ist:".$presentB." seit ".$timeB."<br>";
}
$result_entry = mysql_query("SELECT * FROM `logtable` WHERE USERNAME like '%USERNAME1%' ORDER BY ID DESC");
$result_entry_num = mysql_num_rows($result_entry);
if ($result_entry_num==0)
{echo "nichts gefunden";}
else
{
$presentC=mysql_result($result_entry,0,"PRESENT");
$timeC=mysql_result($result_entry,0,"TIME");
echo "USERNAME1 present ist:".$presentC." seit ".$timeC."<br>";
}
if (($presentB+$presentC)==0)
{$cam_mode="on";}
else
{$cam_mode="off";}
if ($presentA==1){$cam_mode="on";}
//------ENDE ANWESENHEITSAUSWERTUNG
//--------BEGINN SURVEILLANCE STATION LOGIN
$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"];
echo "Login sid:".$sid."<br>";
echo "Login cam_id:".$cam_id."<br>";
//--------ENDE SURVEILLANCE STATION LOGIN
//--------BEGINN SURVEILLANCE STATION Aktiviere Kamera
if ($cam_mode=="on")
{
$json = file_get_contents($httpformat."://".$ip.":".$port."/webapi/_______________________________________________________entry.cgi?api=SYNO.SurveillanceStation.Camera&method=Enable&version=3&cameraIds=".$cam_id."&_sid=".$sid);
echo $json."Kamera ist jetzt aktiviert <br>";
}
if ($cam_mode=="off")
{
$json = file_get_contents($httpformat."://".$ip.":".$port."/webapi/_______________________________________________________entry.cgi?api=SYNO.SurveillanceStation.Camera&method=Disable&version=3&cameraIds=".$cam_id."&_sid=".$sid);
echo $json."Kamera ist jetzt deaktiviert <br>";
}
//--------ENDE SURVEILLANCE STATION Aktiviere Kamera
//----BEGINN logout Surveillance Station
$out = file_get_contents($httpformat."://".$ip.":".$port."/webapi/auth.cgi?api=SYNO.API.Auth&version=3&method=Logout&session=SurveillanceStation");
//----ENDE logout Surveillance Station
/usr/bin/php /var/services/web/DEINEPHPSEITE.php
<?php
$P_TIME_START = time()+microtime();
$dbname="xxxxxxxxxxxxxxxxxxxxxx"; // hier Datenbankname eintragen
$dbhost="127.0.0.1"; // ip Adresse localhost
$dbuser="xxxxxxxxxxxxxxxxxxx"; // username SQL benutzer
$dbpass="xxxxxxxxxxxxxxxxxxx"; // passwort SQL Nutzer
if(@mysql_connect($dbhost,$dbuser,$dbpass)==0){die ("Die MySQL Verbindung an die gewünschte Datenbank wurde zurückgewiesen (MySQL läuft nicht)");}
mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);
?>
https://dnshostnameoderwasauchimmer:5001/webapi/entry.cgi?version="1"&schedule=[{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"0"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"},{"schedule":"1"}]&cameraIds=""&filter=1&api="SYNO.SurveillanceStation.Notification.Schedule"&cameraGroupIds="0"&eventTypes="5"&method="SetBatchSchedule"
Wenn du das Forum hilfreich findest oder uns unterstützen möchtest, dann gib uns doch einfach einen Kaffee aus.
Als Dankeschön schalten wir deinen Account werbefrei.