Some modificatio and repair

This commit is contained in:
Haitem 2020-09-03 22:15:59 +02:00
parent fc3d3d5930
commit ca5b221bc1
5 changed files with 27 additions and 21 deletions

View File

@ -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);

View File

@ -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";

View File

@ -1,7 +1,7 @@
<?php
if (!empty ($_POST)){
$deviceManager = new DeviceManager ();
if (!empty ($_FILES['deviceFirmware']) && !empty ($_FILES['deviceFirmware']['tmp_name']) && !empty ($_POST['deviceId'])) {
$deviceManager = new DeviceManager ();
$file = $_FILES['deviceFirmware'];
$deviceMac = $deviceManager->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();

View File

@ -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);
}
}

View File

@ -29,7 +29,12 @@
<th>Room</th>
<th>Firmware</th>
<th>IP Address<br>(Mac)</th>
<th>Action</th>
<th>Action
<form method="post" action="">
<button class="fa custom-file-input" type="submit" name="deviceCommand" value="reset" title="Reset All"><b>&#xf01e;</b></button>
<div style="float: clear;"></div>
</form>
</th>
</tr>
</thead>
<tbody>