#!/usr/bin/php $mac) { $presence[$nom] = -1; } while (1) { $presenceTemp = array(); exec($command, $result); foreach ($result as $value) { //echo $value; if (str_contains($value, "MAC Address:")) { //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($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 " . $needle . EOL; $presenceTemp[$nom] = true; } } } function send($msg) { global $curlErr; $ch = curl_init(); $msg = "http://localhost:1025/present&" . $msg; // set url curl_setopt($ch, CURLOPT_URL, $msg ); // return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // $result contains the output string echo _("Curl sending message -") . $msg . __FILE__ . ":" . __LINE__ . EOL; if ($curlErr <= 5) { curl_exec($ch); if (curl_errno($ch) != 0) { $curlErr += 1; echo sprintf( _("Sleeping 1 minute because Curl return error %d: %s when sending notification - "), curl_errno($ch), curl_error($ch)) . __FILE__ . ":" . __LINE__ . EOL; sleep (60); }else { echo _("Curl return no error - ") . __FILE__ . ":" . __LINE__ . EOL; $curlErr = 0; } } } ?>