1
0
moha/utils.php

50 lines
893 B
PHP
Raw Normal View History

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