From ca5b221bc15d3f24b0cacff2cc8ebb2d82826b2b Mon Sep 17 00:00:00 2001 From: Haitem Date: Thu, 3 Sep 2020 22:15:59 +0200 Subject: [PATCH 01/11] 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 +
+ +
+
+ From b0514c1f3aa0108e5f96a7274e15c90bb1b59919 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Mon, 7 Sep 2020 11:05:47 +0200 Subject: [PATCH 02/11] Some Fixes --- app/api/UpdatesApi.php | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/app/api/UpdatesApi.php b/app/api/UpdatesApi.php index 11d9933..0b72bf6 100644 --- a/app/api/UpdatesApi.php +++ b/app/api/UpdatesApi.php @@ -12,37 +12,38 @@ 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; } return false; + } public function default(){ $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"]." 404 Not Found"); - die(); - } + + // 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)) { - 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"; From 50e161e1ceeea05aaae6d17b382d3d39fcaa5896 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Mon, 7 Sep 2020 11:18:17 +0200 Subject: [PATCH 03/11] Icons Color and Icon CHanges --- app/views/templates/device.phtml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/views/templates/device.phtml b/app/views/templates/device.phtml index cadd925..1cd7d48 100644 --- a/app/views/templates/device.phtml +++ b/app/views/templates/device.phtml @@ -46,7 +46,23 @@ Room - " style="float: center; "> + + +
From 6945d58eb6eadba7da30d8a956fcee0d8d9b1037 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Mon, 7 Sep 2020 11:33:24 +0200 Subject: [PATCH 04/11] Device Room Select --- app/views/Device.php | 4 ++++ app/views/templates/device.phtml | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/views/Device.php b/app/views/Device.php index fd586e5..203e7c7 100644 --- a/app/views/Device.php +++ b/app/views/Device.php @@ -6,6 +6,7 @@ class Device extends Template function __construct () { $userManager = new UserManager (); $deviceManager = new DeviceManager (); + $roomManager = new RoomManager (); $langMng = new LanguageManager ('en'); if (!$userManager->isLogin ()) { @@ -31,9 +32,12 @@ class Device extends Template } } + $rooms = $roomManager->getAllRooms(); + $template->prepare ('baseDir', BASEDIR); $template->prepare ('debugMod', DEBUGMOD); $template->prepare ('logToLiveTime', LOGTIMOUT); + $template->prepare ('rooms', $rooms); $template->prepare ('devices', $devices); $template->prepare ('langMng', $langMng); diff --git a/app/views/templates/device.phtml b/app/views/templates/device.phtml index 1cd7d48..c2b6e92 100644 --- a/app/views/templates/device.phtml +++ b/app/views/templates/device.phtml @@ -43,7 +43,15 @@ &#x - Room + + + Date: Mon, 7 Sep 2020 12:52:30 +0200 Subject: [PATCH 05/11] Minor Changes --- app/views/templates/device.phtml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/templates/device.phtml b/app/views/templates/device.phtml index c2b6e92..66ea919 100644 --- a/app/views/templates/device.phtml +++ b/app/views/templates/device.phtml @@ -28,7 +28,7 @@ Name Room Firmware - IP Address
(Mac) + IP Address
(Mac)
Token Action @@ -80,7 +80,9 @@
-
+
+
+ From 2c6e7e2eccbeea0537812372231836d3552182de Mon Sep 17 00:00:00 2001 From: Haitem Date: Tue, 8 Sep 2020 18:00:44 +0200 Subject: [PATCH 06/11] Add function on change room --- app/controllers/deviceController.php | 5 ++++- app/views/templates/device.phtml | 23 ++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/controllers/deviceController.php b/app/controllers/deviceController.php index cb47edf..bc367f3 100644 --- a/app/controllers/deviceController.php +++ b/app/controllers/deviceController.php @@ -15,12 +15,15 @@ if (!empty ($_POST)){ } if (isset ($_POST['deviceCommand']) && !empty ($_POST['deviceId'])) { $deviceManager->edit ($_POST['deviceId'], array ('command' => $_POST['deviceCommand'])); - }else if (!empty ($_POST['deviceCommand'])) { + } else if (!empty ($_POST['deviceCommand'])) { $devices = $deviceManager->getAllDevices(); foreach ($devices as $key => $device) { $deviceManager->edit ($device['device_id'], array ('command' => $_POST['deviceCommand'])); } } + if (!empty ($_POST['deviceRoomId']) && !empty ($_POST['deviceId'])) { + $deviceManager->edit ($_POST['deviceId'], array ('room_id' => $_POST['deviceRoomId'])); + } header('Location: ./device'); die(); } diff --git a/app/views/templates/device.phtml b/app/views/templates/device.phtml index 66ea919..b0396ca 100644 --- a/app/views/templates/device.phtml +++ b/app/views/templates/device.phtml @@ -44,17 +44,22 @@ &#x - + + "> + + - - + From ed732e125a7f6e6b2c63545eb412d486ef7e24a8 Mon Sep 17 00:00:00 2001 From: Haitem Date: Tue, 8 Sep 2020 18:47:58 +0200 Subject: [PATCH 07/11] Add name changer and repair need icon --- app/controllers/deviceController.php | 3 +++ app/views/templates/device.phtml | 36 ++++++++++++++++------------ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/app/controllers/deviceController.php b/app/controllers/deviceController.php index bc367f3..0958618 100644 --- a/app/controllers/deviceController.php +++ b/app/controllers/deviceController.php @@ -24,6 +24,9 @@ if (!empty ($_POST)){ if (!empty ($_POST['deviceRoomId']) && !empty ($_POST['deviceId'])) { $deviceManager->edit ($_POST['deviceId'], array ('room_id' => $_POST['deviceRoomId'])); } + if (!empty ($_POST['deviceName']) && !empty ($_POST['deviceId'])) { + $deviceManager->edit ($_POST['deviceId'], array ('name' => $_POST['deviceName'])); + } header('Location: ./device'); die(); } diff --git a/app/views/templates/device.phtml b/app/views/templates/device.phtml index b0396ca..db37436 100644 --- a/app/views/templates/device.phtml +++ b/app/views/templates/device.phtml @@ -42,9 +42,14 @@ &#x - -
+ + "> + "> +
+ + +
"> "> - "> -
- - + + # + Name + Room + Firmware + + IP Address
+ (Mac)
+ Token + + Action +
+ +
+
+ + + + + + &#x +
"> - "> +
+ + +
+ "> + +
+ + + $room) { - echo ''; + $icon = "fa-circle"; + $color = "yellow"; + if (!empty($device['firmware_hash'])) { + if ($device['firmware_hash'] == "true") { + $icon = "fa-check-circle"; + $color = "green"; + } else if ($device['firmware_hash'] == "need") { + $icon = "fa-arrow-circle-up"; + $color = "#6495ED"; + } else { + $icon = "fa-times-circle"; + $color = "red"; } } ?> - - - - - - - - - -
- "> - -
- -
- -
-
- - - -
- "> - - -
-
- - - - - - + + + +
+ "> + +
+ +
+ +
+
+ + + +
+ "> + + +
+
+ + + + + @@ -117,6 +117,12 @@ $partial->render(); //TODO js do main.js ?> + From 30da6e162b7ffc4e07dd71a51eb57adbde60f5fb Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Mon, 14 Sep 2020 15:15:47 +0200 Subject: [PATCH 09/11] Few Fixes After infrastructure migration --- .htaccess | 6 +++--- app/Bootstrap.php | 20 +++++++++++--------- app/api/WidgetApi.php | 2 +- app/views/Device.php | 6 ++++++ app/views/templates/device.phtml | 2 ++ 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/.htaccess b/.htaccess index b0a8024..289a0f5 100644 --- a/.htaccess +++ b/.htaccess @@ -1,9 +1,9 @@ RewriteEngine On # require https -RewriteCond %{HTTPS} off -RewriteCond %{REQUEST_URI} !^/api/update -RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] +#RewriteCond %{HTTPS} off +#RewriteCond %{REQUEST_URI} !^/api/update +#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] #token to HTTP_AUTHORIZATION RewriteCond %{HTTP:Authorization} ^(.*) diff --git a/app/Bootstrap.php b/app/Bootstrap.php index 9faf5db..b45c175 100644 --- a/app/Bootstrap.php +++ b/app/Bootstrap.php @@ -1,4 +1,15 @@ write("[API] request body\n" . json_encode($obj, JSON_PRETTY_PRI $apiLogManager->write("[API] POST body\n" . json_encode($_POST, JSON_PRETTY_PRINT), LogRecordTypes::INFO); $apiLogManager->write("[API] GET body\n" . json_encode($_GET, JSON_PRETTY_PRINT), LogRecordTypes::INFO); -//Debug -error_reporting(E_ALL); -ini_set( 'display_errors','1'); -//setup -ini_set ('session.cookie_httponly', '1'); -ini_set('session.cookie_domain', $_SERVER['HTTP_HOST']); -ini_set('session.cookie_path', str_replace("login", "", str_replace('https://' . $_SERVER['HTTP_HOST'], "", $_SERVER['REQUEST_URI']))); -ini_set('session.cookie_secure', '1'); -mb_internal_encoding ("UTF-8"); Debugger::flag('dbconnect'); //D B Conector diff --git a/app/api/WidgetApi.php b/app/api/WidgetApi.php index 2734d9f..65e5950 100644 --- a/app/api/WidgetApi.php +++ b/app/api/WidgetApi.php @@ -12,7 +12,7 @@ class WidgetApi extends ApiController{ $subDeviceData = SubDeviceManager::getSubDevice($subDeviceId); if ($subDeviceData['type'] == 'on/off'){ $lastValue = RecordManager::getLastRecord($subDeviceData['subdevice_id'])['value']; - RecordManager::create($subDeviceData['device_id'], 'on/off', !$lastValue); + RecordManager::create($subDeviceData['device_id'], 'on/off', (int) !$lastValue); $response = !$lastValue; } else { throw new Exception("Bad Request", 403); diff --git a/app/views/Device.php b/app/views/Device.php index 203e7c7..0c5a6a8 100644 --- a/app/views/Device.php +++ b/app/views/Device.php @@ -30,6 +30,12 @@ class Device extends Template } else { $devices[$key]['firmware_hash'] = "false"; } + + $wifi = SubDeviceManager::getSubDeviceByMaster($device['device_id'], 'wifi'); + if ($wifi) { + $signalStrenght = RecordManager::getLastRecordNotNull($wifi['subdevice_id']); + $devices[$key]['signal'] = (!$signalStrenght ? 0 : $signalStrenght['value']); + } } $rooms = $roomManager->getAllRooms(); diff --git a/app/views/templates/device.phtml b/app/views/templates/device.phtml index 66ea919..910bc68 100644 --- a/app/views/templates/device.phtml +++ b/app/views/templates/device.phtml @@ -26,6 +26,7 @@ # Name + Signal Room Firmware IP Address
(Mac)
Token @@ -43,6 +44,7 @@ &#x + "> - -
- "> - "> + -
+ ?> + + + - +
"> - +

-
- +
+
@@ -121,11 +122,11 @@ //TODO js do main.js ?> - + \ No newline at end of file