Bether Loggig Class

This commit is contained in:
2020-07-28 09:02:46 +02:00
parent 6d44750804
commit 70ef954b64
9 changed files with 84 additions and 50 deletions

View File

@@ -12,6 +12,7 @@ class UpdatesApi {
public function default(){
header('Content-type: text/plain; charset=utf8', true);
$logManager = new LogManager('../logs/ota/'. date("Y-m-d").'.log');
$logManager->setLevel(LOGLEVEL);
//Filtrování IP adress
/* if (DEBUGMOD != 1) {
@@ -21,7 +22,7 @@ class UpdatesApi {
'errorMSG' => "Using API from your IP insnt alowed!",
));
header($_SERVER["SERVER_PROTOCOL"]." 401 Unauthorized");
$logManager->write("[Updater] acces denied from " . $_SERVER['REMOTE_ADDR'], LogRecordType::WARNING);
$logManager->write("[Updater] acces denied from " . $_SERVER['REMOTE_ADDR'], LogRecordTypes::WARNING);
exit();
}
}*/
@@ -29,10 +30,10 @@ class UpdatesApi {
$macAddress = $_SERVER['HTTP_X_ESP8266_STA_MAC'];
$localBinary = "../updater/" . str_replace(':', '', $macAddress) . ".bin";
$logManager->write("[Updater] url: " . $localBinary, LogRecordType::INFO);
$logManager->write("[Updater] version: " . $_SERVER['HTTP_X_ESP8266_SKETCH_MD5'], LogRecordType::INFO);
$logManager->write("[Updater] url: " . $localBinary, LogRecordTypes::INFO);
$logManager->write("[Updater] version: " . $_SERVER['HTTP_X_ESP8266_SKETCH_MD5'], LogRecordTypes::INFO);
if (file_exists($localBinary)) {
$logManager->write("[Updater] version PHP: \n" . md5_file($localBinary), LogRecordType::INFO);
$logManager->write("[Updater] version PHP: \n" . md5_file($localBinary), LogRecordTypes::INFO);
if ($_SERVER['HTTP_X_ESP8266_SKETCH_MD5'] != md5_file($localBinary)) {
$this->sendFile($localBinary);
//get device data
@@ -40,8 +41,8 @@ class UpdatesApi {
$deviceName = $device['name'];
$deviceId = $device['device_id'];
//logfile write
$logManager->write("[Device] device_ID " . $deviceId . " was just updated to new version", LogRecordType::WARNING);
$logManager->write("[Device] version hash: \n" . md5_file($localBinary), LogRecordType::INFO);
$logManager->write("[Device] device_ID " . $deviceId . " was just updated to new version", LogRecordTypes::WARNING);
$logManager->write("[Device] version hash: \n" . md5_file($localBinary), LogRecordTypes::INFO);
//notification
$notificationMng = new NotificationManager;
$notificationData = [
@@ -52,7 +53,7 @@ class UpdatesApi {
if ($notificationData != []) {
$subscribers = $notificationMng->getSubscription();
foreach ($subscribers as $key => $subscriber) {
$logManager->write("[NOTIFICATION] SENDING TO " . $subscriber['id'] . " ", LogRecordType::INFO);
$logManager->write("[NOTIFICATION] SENDING TO " . $subscriber['id'] . " ", LogRecordTypes::INFO);
$answer = $notificationMng->sendSimpleNotification(SERVERKEY, $subscriber['token'], $notificationData);
}
}