1
0

ajout de la détection de présence par présence de téléphone en Wifi

This commit is contained in:
Daniel Tartavel 2022-09-01 17:05:05 +02:00
parent 6a333acc9f
commit 373bb6c228
3 changed files with 72 additions and 10 deletions

View File

@ -9,6 +9,7 @@
$deviceTable = array( $deviceTable = array(
"0x00124b0022ebac5c" => "RDC_SALON_MVMT2", "0x00124b0022ebac5c" => "RDC_SALON_MVMT2",
"0x588e81fffe2cf695" => "RDC_SALON_MVMT", "0x588e81fffe2cf695" => "RDC_SALON_MVMT",
"0xe0798dfffe4ffa2c" => "RDC_SALON_PRESENCE",
"0x00124b001f900753" => "RDC_ENTREE_PORTE", "0x00124b001f900753" => "RDC_ENTREE_PORTE",
"0x00158d0001923c21" => "RDC_CHAMBRE_RADIATEUR", "0x00158d0001923c21" => "RDC_CHAMBRE_RADIATEUR",
"0x04cf8cdf3c78aff0" => "RDC_SALON_LUMINOSITE", "0x04cf8cdf3c78aff0" => "RDC_SALON_LUMINOSITE",

View File

@ -1,5 +1,6 @@
<?php <?php
macAdressses = array(
$macAddresses = array(
"Daniel" => "84:CF:BF:8E:E6:A6" "Daniel" => "84:CF:BF:8E:E6:A6"
); );

View File

@ -1,18 +1,78 @@
<?php require "config/liste_telephones.php"; <?php
function presence() function presence($argList)
{ {
$result = array(); global $presence;
$command = "sudo nmap -n -sP 192.168.1.*";
exec($command, $result); if(array_key_exists("nom", $argList))
var_dump($result);
foreach ($macAddresses as $name =>$value)
{ {
$key = array_search($value, $result); $name = $argList["nom"];
}else
{
return "Le paramètre 'nom' est obligatoire\npresent&nom=<nom>&presence=<true/false>" . EOLH;
}
if(array_key_exists("presence", $argList))
{
$key= $argList["presence"];
}else
{
return "Le paramètre 'presence' est obligatoire\npresent&nom=<nom>&presence=<true/false>" . EOLH;
}
$key = $argList["presence"];
if (!array_key_exists($name, $presence))
{
$presence[] = $name;
$presence[$name] = false;
}
if ($key === true)
{
if ($presence[$name] === false)
{
logger(ALERT, $name . _(" est présent"), null, $device);
//echo $name . " est présent";
$presence[$name] = true;
}
}elseif ($presence[$name] === true)
{
$presence[$name] = false;
logger(ALERT, $name . _(" est présent"), null, $device);
} }
} }
presence();
function isPresent($name = false, $returnNames = false)
{
global $presence;
$r = false;
$list = "";
if ($name === false)
{
foreach($presence as $name => $value)
{
if ($value === true)
{
$r &= true;
$liste .= $name . EOLH;
}
}
}elseif (array_key_exists($name, $presence))
{
$r = $presence[$name];
}else
{
return -1;
}
if ($returnNames and !empty($liste))
{
return $liste;
}else
{
return $r;
}
}
?> ?>