@@ -371,6 +371,7 @@ Example header data:
371371 [HTTP_X_ESP8266_AP_MAC] => 1A:FE:AA:AA:AA:AA
372372 [HTTP_X_ESP8266_FREE_SPACE] => 671744
373373 [HTTP_X_ESP8266_SKETCH_SIZE] => 373940
374+ [HTTP_X_ESP8266_SKETCH_MD5] => a56f8ef78a0bebd812f62067daf1408a
374375 [HTTP_X_ESP8266_CHIP_SIZE] => 4194304
375376 [HTTP_X_ESP8266_SDK_VERSION] => 1.3.0
376377 [HTTP_X_ESP8266_VERSION] => DOOR-7-g14f53a19
415416 !check_header('HTTP_X_ESP8266_AP_MAC') ||
416417 !check_header('HTTP_X_ESP8266_FREE_SPACE') ||
417418 !check_header('HTTP_X_ESP8266_SKETCH_SIZE') ||
419+ !check_header('HTTP_X_ESP8266_SKETCH_MD5') ||
418420 !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')
421422) {
422423 header($_SERVER["SERVER_PROTOCOL"].' 403 Forbidden', true, 403);
423424 echo "only for ESP8266 updater! (header)\n";
@@ -429,13 +430,20 @@ $db = array(
429430 "18:FE:AA:AA:AA:BB" => "TEMP-1.0.0"
430431);
431432
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);
439447}
440448
441449header($_SERVER["SERVER_PROTOCOL"].' 500 no version for ESP MAC', true, 500);
0 commit comments