fix updater
This commit is contained in:
50
update.php
50
update.php
@@ -1,7 +1,31 @@
|
||||
<?PHP
|
||||
/** Includes **/
|
||||
include_once('./config.php');
|
||||
|
||||
//Autoloader
|
||||
$files = scandir('./app/class/');
|
||||
$files = array_diff($files, array(
|
||||
'.',
|
||||
'..',
|
||||
'app',
|
||||
'ChartJS.php',
|
||||
'ChartJS_Line.php',
|
||||
'ChartManager.php',
|
||||
'DashboardManager.php',
|
||||
'Partial.php',
|
||||
'Form.php',
|
||||
'Route.php',
|
||||
'Template.php',
|
||||
'Ajax.php',
|
||||
));
|
||||
|
||||
foreach($files as $file) {
|
||||
include './app/class/'. $file;
|
||||
}
|
||||
$logManager = new LogManager();
|
||||
header('Content-type: text/plain; charset=utf8', true);
|
||||
|
||||
/*
|
||||
function check_header($name, $value = false)
|
||||
{
|
||||
if (!isset($_SERVER[$name])) {
|
||||
@@ -11,7 +35,7 @@ function check_header($name, $value = false)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
|
||||
function sendFile($path)
|
||||
{
|
||||
@@ -23,7 +47,8 @@ function sendFile($path)
|
||||
readfile($path);
|
||||
}
|
||||
|
||||
if (!check_header('HTTP_USER_AGENT', 'ESP8266-http-Update')) {
|
||||
|
||||
/*if (!check_header('HTTP_USER_AGENT', 'ESP8266-http-Update')) {
|
||||
header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden', true, 403);
|
||||
echo "only for ESP8266 updater!\n";
|
||||
exit();
|
||||
@@ -41,7 +66,22 @@ if (
|
||||
header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden', true, 403);
|
||||
echo "only for ESP8266 updater! (header)\n";
|
||||
exit();
|
||||
}
|
||||
}*/
|
||||
|
||||
$localBinary = "./app/updater/" . $_SERVER['HTTP_X_ESP8266_STA_MAC'] . ".bin";
|
||||
sendFile($localBinary);
|
||||
|
||||
|
||||
|
||||
$localBinary = "./app/updater/" . str_replace(':', '', $_SERVER['HTTP_X_ESP8266_STA_MAC']) . ".bin";
|
||||
$logManager->write("[Update] url: " . $localBinary, LogRecordType::INFO);
|
||||
$logManager->write("[Update] version: " . $_SERVER['HTTP_X_ESP8266_SKETCH_MD5'], LogRecordType::INFO);
|
||||
if (file_exists($localBinary)) {
|
||||
$logManager->write("[Update] version PHP: " . md5_file($localBinary), LogRecordType::INFO);
|
||||
if ($_SERVER['HTTP_X_ESP8266_SKETCH_MD5'] != md5_file($localBinary)) {
|
||||
sendFile($localBinary);
|
||||
} else {
|
||||
header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified', true, 304);
|
||||
}
|
||||
} else {
|
||||
header("HTTP/1.1 404 Not Found");
|
||||
}
|
||||
die();
|
||||
|
Reference in New Issue
Block a user