72 lines
1.8 KiB
PHP
72 lines
1.8 KiB
PHP
<?php
|
|
require_once "events.php";
|
|
|
|
class alerte_intrusion extends hook
|
|
{
|
|
public $hookName = "alerte_intrusion";
|
|
public $active = true;
|
|
|
|
protected $devicelist = array(
|
|
ENTREE_PORTE => "contact",
|
|
GARAGE_PORTE => "contact",
|
|
RDC_CHAMBRE_BAIE => "contact",
|
|
RDC_SALON_BAIE => "contact",
|
|
GARAGE_PORTAIL => "contact"
|
|
);
|
|
|
|
function installHooks(&$indexDevices)
|
|
{
|
|
return $this->installHooksFunction($indexDevices);
|
|
}
|
|
|
|
// callback fonction. Is called with these 4 parameters
|
|
public function callBack($device, $property, $value)
|
|
{
|
|
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
|
|
switch($property)
|
|
{
|
|
case "contact":
|
|
if ($value == false)
|
|
{
|
|
logger(ALERT, sprintf(_("%s vient de s'ouvrir alors que personne n'est présent"), $device->friendlyName), __FILE__ . ":" . __LINE__);
|
|
}else
|
|
{
|
|
logger(ALERT, sprintf(_("%s vient de se fermer alors que personne n'est présent"), $device->friendlyName), __FILE__ . ":" . __LINE__);
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function testPortes($send=true) :array
|
|
{
|
|
global $indexDevices;
|
|
$portes = array();
|
|
logger(DEBUG, _("Function alerte_intrusion->testPorte"), __FILE__ . ":" . __LINE__);
|
|
|
|
$msg = "";
|
|
foreach ($this->devicelist as $device => $property)
|
|
{
|
|
if($indexDevices[$device]->properties[$property] == false)
|
|
{
|
|
$portes[] = $indexDevices[$device]->friendlyName;
|
|
$msg .= $indexDevices[$device]->friendlyName . "\n";
|
|
}
|
|
}
|
|
if ($send)
|
|
{
|
|
logger(ALERT, _("doors opened :") . $msg, null ,$device);
|
|
}
|
|
return $portes;
|
|
}
|
|
}
|
|
|
|
$hooks["alerte_intrusion"] = new alerte_intrusion();
|
|
logger(DEBUG, _("Initializing event"), __FILE__ . ":" . __LINE__);
|
|
$function = array($hooks["alerte_intrusion"], "testPortes");
|
|
setRecurrentEvent($function, 0, 0, 0, 0, 0, 0, 21, 0, 0, 1, 0, 0, 0);
|
|
|
|
?>
|