1
0
moha/utils.php

51 lines
929 B
PHP

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