debug presence
This commit is contained in:
@ -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;
|
||||
}
|
||||
$r = search($value, $result);
|
||||
|
||||
if ($r === true)
|
||||
{
|
||||
echo "présent\n";
|
||||
if ($presence[$name] === false)
|
||||
{
|
||||
$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");
|
||||
send($msg);
|
||||
//echo " contient une adresse MAC" . EOL;
|
||||
search($value);
|
||||
}
|
||||
}
|
||||
foreach($presenceTemp as $nom => $status)
|
||||
{
|
||||
$msg = "";
|
||||
if ($presence[$nom] != (int)$status)
|
||||
{
|
||||
$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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user