Bether Loggig Class
This commit is contained in:
@@ -10,9 +10,10 @@ class UpdatesApi {
|
||||
}
|
||||
|
||||
public function default(){
|
||||
header('Content-type: text/plain; charset=utf8', true);
|
||||
header('Content-type: text/plain; charset=utf8', true);
|
||||
$logManager = new LogManager('../logs/ota/'. date("Y-m-d").'.log');
|
||||
$logManager->write("[Updater] Client Connected", LogRecordType::WARNING);
|
||||
$logManager->setLevel(LOGLEVEL);
|
||||
$logManager->write("[Updater] Client Connected", LogRecordTypes::WARNING);
|
||||
|
||||
|
||||
//Filtrování IP adress
|
||||
@@ -23,17 +24,17 @@ 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::INFO);
|
||||
$logManager->write("[Updater] acces denied from " . $_SERVER['REMOTE_ADDR'], LogRecordTypes::INFO);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
$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: " . md5_file($localBinary), LogRecordType::INFO);
|
||||
$logManager->write("[Updater] version PHP: " . md5_file($localBinary), LogRecordTypes::INFO);
|
||||
if ($_SERVER['HTTP_X_ESP8266_SKETCH_MD5'] != md5_file($localBinary)) {
|
||||
$this->sendFile($localBinary);
|
||||
//get device data
|
||||
@@ -41,8 +42,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: " . md5_file($localBinary), LogRecordType::INFO);
|
||||
$logManager->write("[Device] device_ID " . $deviceId . " was just updated to new version", LogRecordTypes::WARNING);
|
||||
$logManager->write("[Device] version hash: " . md5_file($localBinary), LogRecordTypes::INFO);
|
||||
//notification
|
||||
$notificationMng = new NotificationManager;
|
||||
$notificationData = [
|
||||
@@ -53,7 +54,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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user