debug presence
This commit is contained in:
parent
3e01933e13
commit
21e95ec286
@ -485,7 +485,7 @@ function PropertiesDashboard($argList)
|
|||||||
logger(INFO, _("propertiesDashboard function"), __FILE__ . ":" . __LINE__);
|
logger(INFO, _("propertiesDashboard function"), __FILE__ . ":" . __LINE__);
|
||||||
$response = insertJavascript();
|
$response = insertJavascript();
|
||||||
$property = $argList["property"];
|
$property = $argList["property"];
|
||||||
print_r($indexProperties[$property]);
|
//print_r($indexProperties[$property]);
|
||||||
foreach($indexProperties as $propertyName => $index)
|
foreach($indexProperties as $propertyName => $index)
|
||||||
{
|
{
|
||||||
if (str_contains($propertyName, $property ))
|
if (str_contains($propertyName, $property ))
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$macAddresses = array(
|
$macAddresses = array(
|
||||||
"Daniel" => "84:CF:BF:8E:E6:A6"
|
"Daniel" => "E8:78:29:C2:79:22",
|
||||||
|
"Maryclaire" => "D0:9C:7A:DA:8E:D8",
|
||||||
|
"Terence" => "26:4D:40:5F:1E:10"
|
||||||
);
|
);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -14,56 +14,54 @@ $result = array();
|
|||||||
$presence = array();
|
$presence = array();
|
||||||
$curlErr = 0;
|
$curlErr = 0;
|
||||||
$command = "sudo nmap -n -sP 192.168.1.*"; //need to configure /etc/sudo/sudoers to permit execution of nmap as superuser
|
$command = "sudo nmap -n -sP 192.168.1.*"; //need to configure /etc/sudo/sudoers to permit execution of nmap as superuser
|
||||||
|
|
||||||
echo "presenceDaemon is starting\n";
|
echo "presenceDaemon is starting\n";
|
||||||
|
// init du tableau des présences à -1
|
||||||
|
foreach($macAddresses as $nom => $mac)
|
||||||
|
{
|
||||||
|
$presence[$nom] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
//echo "presenceDaemon is testing\n";
|
$presenceTemp = array();
|
||||||
$msg = "";
|
|
||||||
exec($command, $result);
|
exec($command, $result);
|
||||||
|
|
||||||
foreach ($macAddresses as $name =>$value)
|
foreach ($result as $value)
|
||||||
{
|
{
|
||||||
if (!array_key_exists($name, $presence))
|
//echo $value;
|
||||||
|
if (str_contains($value, "MAC Address:"))
|
||||||
{
|
{
|
||||||
$presence[] = $name;
|
//echo " contient une adresse MAC" . EOL;
|
||||||
$presence[$name] = false;
|
search($value);
|
||||||
}
|
}
|
||||||
$r = search($value, $result);
|
}
|
||||||
|
foreach($presenceTemp as $nom => $status)
|
||||||
if ($r === true)
|
|
||||||
{
|
{
|
||||||
echo "présent\n";
|
$msg = "";
|
||||||
if ($presence[$name] === false)
|
if ($presence[$nom] != (int)$status)
|
||||||
{
|
{
|
||||||
$presence[$name] = true;
|
$msg .= "nom=" . $nom . "&presence=" . $status;
|
||||||
$msg .= "nom=" . $name . _("&presence=true");
|
|
||||||
send($msg);
|
|
||||||
echo $name . " est mis présent dans tableau\n";
|
|
||||||
}
|
|
||||||
}elseif ($presence[$name] === true)
|
|
||||||
{
|
|
||||||
$presence[$name] = false;
|
|
||||||
echo $name . " est mis absent dans tableau\n";
|
|
||||||
$msg .= "nom=" . $name . _("&presence=false");
|
|
||||||
send($msg);
|
send($msg);
|
||||||
|
echo $nom . " est modifié dans tableau\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function search($needle, $array)
|
function search($string)
|
||||||
{
|
{
|
||||||
foreach ($array as $string)
|
global $macAddresses, $presenceTemp;
|
||||||
|
//echo "searching in " . $string . EOL;
|
||||||
|
foreach ($macAddresses as $nom => $needle)
|
||||||
{
|
{
|
||||||
|
//echo $nom ." => " . $needle . EOL;
|
||||||
if (str_contains($string, $needle))
|
if (str_contains($string, $needle))
|
||||||
{
|
{
|
||||||
echo "found\n";
|
echo "found " . $needle . EOL;
|
||||||
return true;
|
$presenceTemp[$nom] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function send($msg)
|
function send($msg)
|
||||||
@ -78,11 +76,10 @@ function send($msg)
|
|||||||
// return the transfer as a string
|
// return the transfer as a string
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
// $result contains the output string
|
// $result contains the output string
|
||||||
echo _("Curl sending message -") . __FILE__ . ":" . __LINE__ . EOL;
|
echo _("Curl sending message -") . $msg . __FILE__ . ":" . __LINE__ . EOL;
|
||||||
|
|
||||||
if ($curlErr <= 5)
|
if ($curlErr <= 5)
|
||||||
{
|
{
|
||||||
echo $msg . EOL;
|
|
||||||
curl_exec($ch);
|
curl_exec($ch);
|
||||||
if (curl_errno($ch) != 0)
|
if (curl_errno($ch) != 0)
|
||||||
{
|
{
|
||||||
|
16
moha.php
16
moha.php
@ -35,7 +35,7 @@ $included = false; // flag indicate scripts are loaded
|
|||||||
$nSubscribed = 0; // Number of topics subsribed
|
$nSubscribed = 0; // Number of topics subsribed
|
||||||
$logFh = null; // filehandle of log file
|
$logFh = null; // filehandle of log file
|
||||||
$curlErr = 0; // Number of errors returned by curl
|
$curlErr = 0; // Number of errors returned by curl
|
||||||
$configDir = "./config"; // default config dir (production value is /etc/moha/)
|
//$configDir = "./config"; // default config dir (production value is /etc/moha/)
|
||||||
$hooksInitialized = 0; // are all hooks initialized ? false/true
|
$hooksInitialized = 0; // are all hooks initialized ? false/true
|
||||||
$flagHooks = false;
|
$flagHooks = false;
|
||||||
$devicesRequest = false; // set to true when publishing device request to zigbee2mqtt
|
$devicesRequest = false; // set to true when publishing device request to zigbee2mqtt
|
||||||
@ -59,11 +59,12 @@ if ($testMode)
|
|||||||
$httpServerIp = "127.0.0.1";
|
$httpServerIp = "127.0.0.1";
|
||||||
}
|
}
|
||||||
|
|
||||||
require "/etc/moha/liste_telephones.php";
|
|
||||||
|
|
||||||
if (!init()) exit(1);
|
if (!init()) exit(1);
|
||||||
|
|
||||||
// (re)démarre le démon de présence
|
// (re)démarre le démon de présence
|
||||||
system("systemctl restart presenceD");
|
system("sudo /usr/bin/systemctl restart presenceD.service");
|
||||||
|
|
||||||
// gettext
|
// gettext
|
||||||
bindtextdomain("moha", "./locale");
|
bindtextdomain("moha", "./locale");
|
||||||
@ -122,10 +123,6 @@ function init()
|
|||||||
echo _("error opening log file in ") . getcwd();
|
echo _("error opening log file in ") . getcwd();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
foreach($macAddresses as $key => $value)
|
|
||||||
{
|
|
||||||
$presence[$key] = false;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,6 +221,9 @@ require "config/liste_telephones.php";
|
|||||||
require "presence.php";
|
require "presence.php";
|
||||||
require "apiserver/apiserver.php";
|
require "apiserver/apiserver.php";
|
||||||
require "configWatch.php";
|
require "configWatch.php";
|
||||||
|
require $configDir . "/liste_telephones.php";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logger(DEBUG, _("Loading stored events datas from ") . $dataPath . "events.db", __FILE__ . ":" . __LINE__);
|
logger(DEBUG, _("Loading stored events datas from ") . $dataPath . "events.db", __FILE__ . ":" . __LINE__);
|
||||||
if (file_exists($dataPath . "events.db"))
|
if (file_exists($dataPath . "events.db"))
|
||||||
@ -390,9 +390,9 @@ while (true)
|
|||||||
{
|
{
|
||||||
foreach ($input as $event)
|
foreach ($input as $event)
|
||||||
{
|
{
|
||||||
logger(DEBUG, _("configWatch : inclus ") . $configDir . "/" . $event["name"], __FILE__ . ":" . __LINE__);
|
|
||||||
if (pathinfo($event["name"], PATHINFO_EXTENSION) == "php")
|
if (pathinfo($event["name"], PATHINFO_EXTENSION) == "php")
|
||||||
{
|
{
|
||||||
|
logger(DEBUG, _("configWatch : inclus ") . $configDir . "/" . $event["name"], __FILE__ . ":" . __LINE__);
|
||||||
include $configDir . "/" . $event["name"];
|
include $configDir . "/" . $event["name"];
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
|
13
presence.php
13
presence.php
@ -1,5 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
foreach($macAddresses as $nom => $mac)
|
||||||
|
{
|
||||||
|
$presence[$nom] = false;
|
||||||
|
}
|
||||||
|
|
||||||
function presence($argList)
|
function presence($argList)
|
||||||
{
|
{
|
||||||
global $presence;
|
global $presence;
|
||||||
@ -18,20 +23,22 @@ function presence($argList)
|
|||||||
{
|
{
|
||||||
return _("Le paramètre 'presence' est obligatoire<br>present&nom=<nom>&presence=<true/false>") . EOLH;
|
return _("Le paramètre 'presence' est obligatoire<br>present&nom=<nom>&presence=<true/false>") . EOLH;
|
||||||
}
|
}
|
||||||
|
var_dump($presence);
|
||||||
if (!array_key_exists($name, $presence))
|
if (!array_key_exists($name, $presence))
|
||||||
{
|
{
|
||||||
return sprintf(_("Ce nom (%s) n'existe pas dans la base."), $name) . EOLH;
|
return sprintf(_("Ce nom (%s) n'existe pas dans la base."), $name) . EOLH;
|
||||||
}
|
}
|
||||||
|
$key = strval($key);
|
||||||
if ($key == "true")
|
if ($key == 1)
|
||||||
{
|
{
|
||||||
|
echo "passed";
|
||||||
if ($presence[$name] == false)
|
if ($presence[$name] == false)
|
||||||
{
|
{
|
||||||
logger(ALERT, $name . _(" est présent"), __FILE__ . ":" . __LINE__);
|
logger(ALERT, $name . _(" est présent"), __FILE__ . ":" . __LINE__);
|
||||||
//echo $name . " est présent";
|
//echo $name . " est présent";
|
||||||
$presence[$name] = true;
|
$presence[$name] = true;
|
||||||
}
|
}
|
||||||
}elseif ($presence[$name] == true)
|
}elseif ($presence[$name] == true and $key == "0")
|
||||||
{
|
{
|
||||||
$presence[$name] = false;
|
$presence[$name] = false;
|
||||||
logger(ALERT, $name . _(" est présent"), __FILE__ . ":" . __LINE__);
|
logger(ALERT, $name . _(" est présent"), __FILE__ . ":" . __LINE__);
|
||||||
|
16
utils.php
16
utils.php
@ -208,6 +208,22 @@ function setValue($fn, $property, $value)
|
|||||||
$indexDevices[$ieeeAddress]->properties[$property]["value"] = $value;
|
$indexDevices[$ieeeAddress]->properties[$property]["value"] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function aliases($fn, $property)
|
||||||
|
{
|
||||||
|
global $aliases;
|
||||||
|
logger(DEBUG, "Function aliases " . $fn . "/" . $property, __FILE__ . ":" . __LINE__);
|
||||||
|
if (array_key_exists($fn . "/" . $property, $aliases))
|
||||||
|
{
|
||||||
|
logger(DEBUG, "exists " . $fn . "/" . $property, __FILE__ . ":" . __LINE__);
|
||||||
|
return "/" . $aliases[$fn . "/" . $property];
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
return "/" . _($property);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//logger(DEBUG, _("signal handling"), __FILE__ . ":" . __LINE__, false);
|
//logger(DEBUG, _("signal handling"), __FILE__ . ":" . __LINE__, false);
|
||||||
//signal handling
|
//signal handling
|
||||||
function signalHandler($signal)
|
function signalHandler($signal)
|
||||||
|
Loading…
Reference in New Issue
Block a user