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 +
+ +
+
+