From 5647bb21a7b81f51667b18d48b86bc222a7630e2 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Wed, 2 Sep 2020 19:44:40 +0200 Subject: [PATCH 1/4] Little Tweeks --- app/api/UpdatesApi.php | 11 +++-- app/controllers/deviceController.php | 12 +++--- app/views/templates/device.phtml | 63 ++++++++++++++-------------- 3 files changed, 47 insertions(+), 39 deletions(-) diff --git a/app/api/UpdatesApi.php b/app/api/UpdatesApi.php index f44f4dd..2656f44 100644 --- a/app/api/UpdatesApi.php +++ b/app/api/UpdatesApi.php @@ -12,7 +12,7 @@ class UpdatesApi { private function validateHeader($headers){ if ( isset($_SERVER['HTTP_X_ESP8266_STA_MAC']) && - isset($_SERVER['HTTP_X_ESP8266_SKETCH_MD5']) + isset($_SERVER['HTTP_X_ESP8266_SKETCH_MD5']) ) { return true; } @@ -23,9 +23,14 @@ class UpdatesApi { $logManager = new LogManager('../logs/ota/'. date("Y-m-d").'.log'); $logManager->setLevel(LOGLEVEL); $logManager->write("[Updater] Client Connected", LogRecordTypes::INFO); - + + // if($this->validateHeader($_SERVER)){ + // header($_SERVER["SERVER_PROTOCOL"]." 400 Bad Header"); + // die(); + // } + header('Content-type: text/plain; charset=utf8', true); - + //Filtrování IP adress if (DEBUGMOD != 1) { if (!in_array($_SERVER['REMOTE_ADDR'], HOMEIP)) { diff --git a/app/controllers/deviceController.php b/app/controllers/deviceController.php index 035b2ab..75c3b00 100644 --- a/app/controllers/deviceController.php +++ b/app/controllers/deviceController.php @@ -5,11 +5,13 @@ if (!empty ($_POST)){ $file = $_FILES['deviceFirmware']; $deviceMac = $deviceManager->getDeviceById ($_POST['deviceId'])['mac']; $fileName = (!empty ($deviceMac) ? str_replace (":", "", $deviceMac) . ".bin" : ""); - if ($fileName != "" && file_exists ("../app/updater/" . $fileName)) { - unlink("../app/updater/" . $fileName); + + if ($fileName != "" && file_exists ("../updater/" . $fileName)) { + unlink("../updater/" . $fileName); } if ($fileName != "") { - copy ($file['tmp_name'], "../app/updater/" . $fileName); + echo 'coping file'.$fileName .copy ($file['tmp_name'], "../updater/" . $fileName);; + } else { } @@ -18,6 +20,6 @@ if (!empty ($_POST)){ $deviceManager = new DeviceManager (); $deviceManager->edit ($_POST['deviceId'], array ('command' => $_POST['deviceCommand'])); } - header('Location: ./'); - die(); + //header('Location: ./'); + //die(); } diff --git a/app/views/templates/device.phtml b/app/views/templates/device.phtml index 011b62d..367f930 100644 --- a/app/views/templates/device.phtml +++ b/app/views/templates/device.phtml @@ -15,8 +15,8 @@ prepare('item', 'device'); - $partial->prepare('langMng',$LANGMNG); - $partial->prepare('debugMod',$DEBUGMOD); + $partial->prepare('langMng', $LANGMNG); + $partial->prepare('debugMod', $DEBUGMOD); $partial->render(); ?> @@ -26,41 +26,41 @@ # Name + Room Firmware - Mac - IP Address + IP Address
(Mac) Action - - + + - &#x - + &#x + + Room - - " - style="float: center; " - > - + + " style="float: center; "> + +
- "> - + "> +
- - +
-
- "> - - -
-
+ +
+ "> + + +
+
+ @@ -69,11 +69,12 @@ - prepare('baseDir', BASEDIR); - $partial->render(); - //TODO js do main.js - ?> - + prepare('baseDir', BASEDIR); + $partial->render(); + //TODO js do main.js + ?> + + From 3c456caeca37ab221ba7c3ae17aad6252eca2ac8 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Wed, 2 Sep 2020 19:45:08 +0200 Subject: [PATCH 2/4] Update othervise reload redo restart --- app/controllers/deviceController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/deviceController.php b/app/controllers/deviceController.php index 75c3b00..43ce0d0 100644 --- a/app/controllers/deviceController.php +++ b/app/controllers/deviceController.php @@ -20,6 +20,6 @@ if (!empty ($_POST)){ $deviceManager = new DeviceManager (); $deviceManager->edit ($_POST['deviceId'], array ('command' => $_POST['deviceCommand'])); } - //header('Location: ./'); - //die(); + header('Location: ./device'); + die(); } From fc3d3d59305c79c4fe5b00e89f07ebc0e145c3f7 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Wed, 2 Sep 2020 21:15:00 +0200 Subject: [PATCH 3/4] Sync --- app/views/templates/device.phtml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/views/templates/device.phtml b/app/views/templates/device.phtml index 28b18e2..367f930 100644 --- a/app/views/templates/device.phtml +++ b/app/views/templates/device.phtml @@ -1,9 +1,5 @@ -<<<<<<< HEAD -======= - ->>>>>>> 5cb6f0b... Some Fixes Date: Thu, 3 Sep 2020 22:15:59 +0200 Subject: [PATCH 4/4] Some modificatio and repair --- app/api/EndpointsApi.php | 2 +- app/api/UpdatesApi.php | 24 ++++++++++++------------ app/controllers/deviceController.php | 13 +++++++------ app/models/managers/LogManager.php | 2 +- app/views/templates/device.phtml | 7 ++++++- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/app/api/EndpointsApi.php b/app/api/EndpointsApi.php index 834a584..05a4558 100644 --- a/app/api/EndpointsApi.php +++ b/app/api/EndpointsApi.php @@ -76,7 +76,7 @@ class EndpointsApi extends ApiController{ //Log Data Save if (isset($obj['logs'])){ - foreach ($deviceLogs as $log) { + foreach ($obj['logs'] as $log) { $logManager = new LogManager('../logs/devices/'. date("Y-m-d").'.log'); $logManager->setLevel(LOGLEVEL); $logManager->write("[Device Log Msg] Device_ID " . $deviceId . "->" . $log, LogRecordTypes::ERROR); diff --git a/app/api/UpdatesApi.php b/app/api/UpdatesApi.php index 2656f44..7b984d5 100644 --- a/app/api/UpdatesApi.php +++ b/app/api/UpdatesApi.php @@ -31,18 +31,18 @@ class UpdatesApi { header('Content-type: text/plain; charset=utf8', true); - //Filtrování IP adress - if (DEBUGMOD != 1) { - if (!in_array($_SERVER['REMOTE_ADDR'], HOMEIP)) { - echo json_encode(array( - 'state' => 'unsuccess', - 'errorMSG' => "Using API from your IP insnt alowed!", - )); - header($_SERVER["SERVER_PROTOCOL"]." 401 Unauthorized"); - $logManager->write("[Updater] acces denied from " . $_SERVER['REMOTE_ADDR'], LogRecordTypes::INFO); - exit(); - } - } + // //Filtrování IP adress + // if (DEBUGMOD != 1) { + // if (!in_array($_SERVER['REMOTE_ADDR'], HOMEIP)) { + // echo json_encode(array( + // 'state' => 'unsuccess', + // 'errorMSG' => "Using API from your IP insnt alowed!", + // )); + // header($_SERVER["SERVER_PROTOCOL"]." 401 Unauthorized"); + // $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"; diff --git a/app/controllers/deviceController.php b/app/controllers/deviceController.php index 43ce0d0..cb47edf 100644 --- a/app/controllers/deviceController.php +++ b/app/controllers/deviceController.php @@ -1,7 +1,7 @@ getDeviceById ($_POST['deviceId'])['mac']; $fileName = (!empty ($deviceMac) ? str_replace (":", "", $deviceMac) . ".bin" : ""); @@ -10,15 +10,16 @@ if (!empty ($_POST)){ unlink("../updater/" . $fileName); } if ($fileName != "") { - echo 'coping file'.$fileName .copy ($file['tmp_name'], "../updater/" . $fileName);; - - } else { - + copy ($file['tmp_name'], "../updater/" . $fileName); } } if (isset ($_POST['deviceCommand']) && !empty ($_POST['deviceId'])) { - $deviceManager = new DeviceManager (); $deviceManager->edit ($_POST['deviceId'], array ('command' => $_POST['deviceCommand'])); + }else if (!empty ($_POST['deviceCommand'])) { + $devices = $deviceManager->getAllDevices(); + foreach ($devices as $key => $device) { + $deviceManager->edit ($device['device_id'], array ('command' => $_POST['deviceCommand'])); + } } header('Location: ./device'); die(); diff --git a/app/models/managers/LogManager.php b/app/models/managers/LogManager.php index 082c646..edae6e8 100644 --- a/app/models/managers/LogManager.php +++ b/app/models/managers/LogManager.php @@ -35,7 +35,7 @@ class LogManager } public function __destruct(){ - if (isset($this->logFile)) { + if (isset($this->logFile) && $this->logFile != "Unable to open file!") { fclose($this->logFile); } } diff --git a/app/views/templates/device.phtml b/app/views/templates/device.phtml index 367f930..cadd925 100644 --- a/app/views/templates/device.phtml +++ b/app/views/templates/device.phtml @@ -29,7 +29,12 @@ Room Firmware IP Address
(Mac) - Action + Action +
+ +
+
+