Some Fixes

This commit is contained in:
Václav Španinger 2020-09-07 11:05:47 +02:00
parent 960859087a
commit b0514c1f3a

View File

@ -12,37 +12,38 @@ class UpdatesApi {
private function validateHeader($headers){ private function validateHeader($headers){
if ( if (
isset($_SERVER['HTTP_X_ESP8266_STA_MAC']) && isset($_SERVER['HTTP_X_ESP8266_STA_MAC']) &&
isset($_SERVER['HTTP_X_ESP8266_SKETCH_MD5']) isset($_SERVER['HTTP_X_ESP8266_SKETCH_MD5'])
) { ) {
return true; return true;
} }
return false; return false;
} }
public function default(){ public function default(){
$logManager = new LogManager('../logs/ota/'. date("Y-m-d").'.log'); $logManager = new LogManager('../logs/ota/'. date("Y-m-d").'.log');
$logManager->setLevel(LOGLEVEL); $logManager->setLevel(LOGLEVEL);
$logManager->write("[Updater] Client Connected", LogRecordTypes::INFO); $logManager->write("[Updater] Client Connected", LogRecordTypes::INFO);
if($this->validateHeader($_SERVER)){ // if($this->validateHeader($_SERVER)){
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); // header($_SERVER["SERVER_PROTOCOL"]." 400 Bad Header");
die(); // die();
} // }
header('Content-type: text/plain; charset=utf8', true); header('Content-type: text/plain; charset=utf8', true);
//Filtrování IP adress // //Filtrování IP adress
if (DEBUGMOD != 1) { // if (DEBUGMOD != 1) {
if (!in_array($_SERVER['REMOTE_ADDR'], HOMEIP)) { // if (!in_array($_SERVER['REMOTE_ADDR'], HOMEIP)) {
echo json_encode(array( // echo json_encode(array(
'state' => 'unsuccess', // 'state' => 'unsuccess',
'errorMSG' => "Using API from your IP insnt alowed!", // 'errorMSG' => "Using API from your IP insnt alowed!",
)); // ));
header($_SERVER["SERVER_PROTOCOL"]." 401 Unauthorized"); // header($_SERVER["SERVER_PROTOCOL"]." 401 Unauthorized");
$logManager->write("[Updater] acces denied from " . $_SERVER['REMOTE_ADDR'], LogRecordTypes::INFO); // $logManager->write("[Updater] acces denied from " . $_SERVER['REMOTE_ADDR'], LogRecordTypes::INFO);
exit(); // exit();
} // }
} // }
$macAddress = $_SERVER['HTTP_X_ESP8266_STA_MAC']; $macAddress = $_SERVER['HTTP_X_ESP8266_STA_MAC'];
$localBinary = "../updater/" . str_replace(':', '', $macAddress) . ".bin"; $localBinary = "../updater/" . str_replace(':', '', $macAddress) . ".bin";