2021-12-30 16:18:32 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
function now()
|
|
|
|
{
|
|
|
|
return new DateTime("now");
|
|
|
|
}
|
|
|
|
|
|
|
|
function signalHandler($signal)
|
|
|
|
{
|
|
|
|
endMoha();
|
|
|
|
}
|
|
|
|
|
2022-01-02 13:47:41 +01:00
|
|
|
function notify($message)
|
|
|
|
{
|
2022-01-02 18:14:13 +01:00
|
|
|
global $notificationMethods;
|
|
|
|
$result = false;
|
2022-01-02 13:47:41 +01:00
|
|
|
foreach($notificationMethods as $value)
|
|
|
|
{
|
2022-01-03 21:11:52 +01:00
|
|
|
$result = $result | $value->send($message);
|
2022-01-02 13:47:41 +01:00
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2022-01-03 21:11:52 +01:00
|
|
|
function logger($level, $log, $notif = true)
|
2022-01-02 13:47:41 +01:00
|
|
|
{
|
2022-01-02 18:14:13 +01:00
|
|
|
global $logFh, $logLevel, $notificationLevel;
|
2022-01-03 21:11:52 +01:00
|
|
|
echo "=====>>>> $level => $logLevel => $notificationLevel" . EOL ;
|
|
|
|
echo $log .EOL;
|
|
|
|
$test = $level & $logLevel;
|
|
|
|
if ($test != 0)
|
2022-01-02 13:47:41 +01:00
|
|
|
{
|
|
|
|
fwrite($logFh, "$level : $log" . EOL);
|
|
|
|
print ("$level : $log" . EOL);
|
|
|
|
}
|
2022-01-03 21:11:52 +01:00
|
|
|
$test = $level & $notificationLevel;
|
|
|
|
echo "test => " . $test . "notif =>" .$notif . EOL;
|
|
|
|
if (($test != 0) and ($notif === true))
|
2022-01-02 13:47:41 +01:00
|
|
|
{
|
2022-01-03 21:11:52 +01:00
|
|
|
if(notify("Moha\n" . $log) === false)
|
2022-01-02 13:47:41 +01:00
|
|
|
{
|
2022-01-03 21:11:52 +01:00
|
|
|
logger(INFO, _("Notification not sent"), false);
|
2022-01-02 13:47:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-30 16:18:32 +01:00
|
|
|
|
2022-01-03 21:11:52 +01:00
|
|
|
function mktopic($device)
|
|
|
|
{
|
|
|
|
return $device->topic . "/" . $device->friendlyName;
|
|
|
|
}
|
2021-12-30 16:18:32 +01:00
|
|
|
?>
|