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){
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";