@@ -371,6 +371,7 @@ Example header data:
371
371
[HTTP_X_ESP8266_AP_MAC] => 1A:FE:AA:AA:AA:AA
372
372
[HTTP_X_ESP8266_FREE_SPACE] => 671744
373
373
[HTTP_X_ESP8266_SKETCH_SIZE] => 373940
374
+ [HTTP_X_ESP8266_SKETCH_MD5] => a56f8ef78a0bebd812f62067daf1408a
374
375
[HTTP_X_ESP8266_CHIP_SIZE] => 4194304
375
376
[HTTP_X_ESP8266_SDK_VERSION] => 1.3.0
376
377
[HTTP_X_ESP8266_VERSION] => DOOR-7-g14f53a19
415
416
!check_header('HTTP_X_ESP8266_AP_MAC') ||
416
417
!check_header('HTTP_X_ESP8266_FREE_SPACE') ||
417
418
!check_header('HTTP_X_ESP8266_SKETCH_SIZE') ||
419
+ !check_header('HTTP_X_ESP8266_SKETCH_MD5') ||
418
420
!check_header('HTTP_X_ESP8266_CHIP_SIZE') ||
419
- !check_header('HTTP_X_ESP8266_SDK_VERSION') ||
420
- !check_header('HTTP_X_ESP8266_VERSION')
421
+ !check_header('HTTP_X_ESP8266_SDK_VERSION')
421
422
) {
422
423
header($_SERVER["SERVER_PROTOCOL"].' 403 Forbidden', true, 403);
423
424
echo "only for ESP8266 updater! (header)\n";
@@ -429,13 +430,20 @@ $db = array(
429
430
"18:FE:AA:AA:AA:BB" => "TEMP-1.0.0"
430
431
);
431
432
432
- if(isset($db[$_SERVER['HTTP_X_ESP8266_STA_MAC']])) {
433
- if($db[$_SERVER['HTTP_X_ESP8266_STA_MAC']] != $_SERVER['HTTP_X_ESP8266_VERSION']) {
434
- sendFile("./bin/".$db[$_SERVER['HTTP_X_ESP8266_STA_MAC']]."bin");
435
- } else {
436
- header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified', true, 304);
437
- }
438
- exit();
433
+ if(!isset($db[$_SERVER['HTTP_X_ESP8266_STA_MAC']])) {
434
+ header($_SERVER["SERVER_PROTOCOL"].' 500 ESP MAC not configured for updates', true, 500);
435
+ }
436
+
437
+ $localBinary = "./bin/".$db[$_SERVER['HTTP_X_ESP8266_STA_MAC']].".bin";
438
+
439
+ // Check if version has been set and does not match, if not, check if
440
+ // MD5 hash between local binary and ESP8266 binary do not match if not.
441
+ // then no update has been found.
442
+ if((!check_header('HTTP_X_ESP8266_SDK_VERSION') && $db[$_SERVER['HTTP_X_ESP8266_STA_MAC']] != $_SERVER['HTTP_X_ESP8266_VERSION'])
443
+ || $_SERVER["HTTP_X_ESP8266_SKETCH_MD5"] != md5_file($localBinary)) {
444
+ sendFile($localBinary);
445
+ } else {
446
+ header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified', true, 304);
439
447
}
440
448
441
449
header($_SERVER["SERVER_PROTOCOL"].' 500 no version for ESP MAC', true, 500);
0 commit comments