1
0

debug presence

This commit is contained in:
Daniel Tartavel 2022-09-03 21:10:38 +02:00
parent 3e01933e13
commit 21e95ec286
6 changed files with 68 additions and 46 deletions

View File

@ -485,7 +485,7 @@ function PropertiesDashboard($argList)
logger(INFO, _("propertiesDashboard function"), __FILE__ . ":" . __LINE__);
$response = insertJavascript();
$property = $argList["property"];
print_r($indexProperties[$property]);
//print_r($indexProperties[$property]);
foreach($indexProperties as $propertyName => $index)
{
if (str_contains($propertyName, $property ))

View File

@ -1,7 +1,9 @@
<?php
$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"
);
?>

View File

@ -14,56 +14,54 @@ $result = array();
$presence = array();
$curlErr = 0;
$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";
// init du tableau des présences à -1
foreach($macAddresses as $nom => $mac)
{
$presence[$nom] = -1;
}
while (1)
{
//echo "presenceDaemon is testing\n";
$msg = "";
$presenceTemp = array();
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;
$presence[$name] = false;
//echo " contient une adresse MAC" . EOL;
search($value);
}
$r = search($value, $result);
if ($r === true)
}
foreach($presenceTemp as $nom => $status)
{
echo "présent\n";
if ($presence[$name] === false)
$msg = "";
if ($presence[$nom] != (int)$status)
{
$presence[$name] = true;
$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");
$msg .= "nom=" . $nom . "&presence=" . $status;
send($msg);
echo $nom . " est modifié dans tableau\n";
}
}
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))
{
echo "found\n";
return true;
echo "found " . $needle . EOL;
$presenceTemp[$nom] = true;
}
}
return false;
}
function send($msg)
@ -78,11 +76,10 @@ function send($msg)
// return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $result contains the output string
echo _("Curl sending message -") . __FILE__ . ":" . __LINE__ . EOL;
echo _("Curl sending message -") . $msg . __FILE__ . ":" . __LINE__ . EOL;
if ($curlErr <= 5)
{
echo $msg . EOL;
curl_exec($ch);
if (curl_errno($ch) != 0)
{

View File

@ -35,7 +35,7 @@ $included = false; // flag indicate scripts are loaded
$nSubscribed = 0; // Number of topics subsribed
$logFh = null; // filehandle of log file
$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
$flagHooks = false;
$devicesRequest = false; // set to true when publishing device request to zigbee2mqtt
@ -59,11 +59,12 @@ if ($testMode)
$httpServerIp = "127.0.0.1";
}
require "/etc/moha/liste_telephones.php";
if (!init()) exit(1);
// (re)démarre le démon de présence
system("systemctl restart presenceD");
system("sudo /usr/bin/systemctl restart presenceD.service");
// gettext
bindtextdomain("moha", "./locale");
@ -122,10 +123,6 @@ function init()
echo _("error opening log file in ") . getcwd();
return false;
}
foreach($macAddresses as $key => $value)
{
$presence[$key] = false;
}
return true;
}
@ -224,6 +221,9 @@ require "config/liste_telephones.php";
require "presence.php";
require "apiserver/apiserver.php";
require "configWatch.php";
require $configDir . "/liste_telephones.php";
logger(DEBUG, _("Loading stored events datas from ") . $dataPath . "events.db", __FILE__ . ":" . __LINE__);
if (file_exists($dataPath . "events.db"))
@ -390,9 +390,9 @@ while (true)
{
foreach ($input as $event)
{
logger(DEBUG, _("configWatch : inclus ") . $configDir . "/" . $event["name"], __FILE__ . ":" . __LINE__);
if (pathinfo($event["name"], PATHINFO_EXTENSION) == "php")
{
logger(DEBUG, _("configWatch : inclus ") . $configDir . "/" . $event["name"], __FILE__ . ":" . __LINE__);
include $configDir . "/" . $event["name"];
}else
{

View File

@ -1,5 +1,10 @@
<?php
foreach($macAddresses as $nom => $mac)
{
$presence[$nom] = false;
}
function presence($argList)
{
global $presence;
@ -18,20 +23,22 @@ function presence($argList)
{
return _("Le paramètre 'presence' est obligatoire<br>present&nom=<nom>&presence=<true/false>") . EOLH;
}
var_dump($presence);
if (!array_key_exists($name, $presence))
{
return sprintf(_("Ce nom (%s) n'existe pas dans la base."), $name) . EOLH;
}
if ($key == "true")
$key = strval($key);
if ($key == 1)
{
echo "passed";
if ($presence[$name] == false)
{
logger(ALERT, $name . _(" est présent"), __FILE__ . ":" . __LINE__);
//echo $name . " est présent";
$presence[$name] = true;
}
}elseif ($presence[$name] == true)
}elseif ($presence[$name] == true and $key == "0")
{
$presence[$name] = false;
logger(ALERT, $name . _(" est présent"), __FILE__ . ":" . __LINE__);

View File

@ -208,6 +208,22 @@ function setValue($fn, $property, $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);
//signal handling
function signalHandler($signal)