mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Exposed sketch MD5 through HTTP headers (#2236)
* Exposed sketch MD5 through HTTP headers * Updated spacing, docs, example
This commit is contained in:
parent
0d996ab75e
commit
edba2d2829
@ -371,6 +371,7 @@ Example header data:
|
|||||||
[HTTP_X_ESP8266_AP_MAC] => 1A:FE:AA:AA:AA:AA
|
[HTTP_X_ESP8266_AP_MAC] => 1A:FE:AA:AA:AA:AA
|
||||||
[HTTP_X_ESP8266_FREE_SPACE] => 671744
|
[HTTP_X_ESP8266_FREE_SPACE] => 671744
|
||||||
[HTTP_X_ESP8266_SKETCH_SIZE] => 373940
|
[HTTP_X_ESP8266_SKETCH_SIZE] => 373940
|
||||||
|
[HTTP_X_ESP8266_SKETCH_MD5] => a56f8ef78a0bebd812f62067daf1408a
|
||||||
[HTTP_X_ESP8266_CHIP_SIZE] => 4194304
|
[HTTP_X_ESP8266_CHIP_SIZE] => 4194304
|
||||||
[HTTP_X_ESP8266_SDK_VERSION] => 1.3.0
|
[HTTP_X_ESP8266_SDK_VERSION] => 1.3.0
|
||||||
[HTTP_X_ESP8266_VERSION] => DOOR-7-g14f53a19
|
[HTTP_X_ESP8266_VERSION] => DOOR-7-g14f53a19
|
||||||
@ -415,9 +416,9 @@ if(
|
|||||||
!check_header('HTTP_X_ESP8266_AP_MAC') ||
|
!check_header('HTTP_X_ESP8266_AP_MAC') ||
|
||||||
!check_header('HTTP_X_ESP8266_FREE_SPACE') ||
|
!check_header('HTTP_X_ESP8266_FREE_SPACE') ||
|
||||||
!check_header('HTTP_X_ESP8266_SKETCH_SIZE') ||
|
!check_header('HTTP_X_ESP8266_SKETCH_SIZE') ||
|
||||||
|
!check_header('HTTP_X_ESP8266_SKETCH_MD5') ||
|
||||||
!check_header('HTTP_X_ESP8266_CHIP_SIZE') ||
|
!check_header('HTTP_X_ESP8266_CHIP_SIZE') ||
|
||||||
!check_header('HTTP_X_ESP8266_SDK_VERSION') ||
|
!check_header('HTTP_X_ESP8266_SDK_VERSION')
|
||||||
!check_header('HTTP_X_ESP8266_VERSION')
|
|
||||||
) {
|
) {
|
||||||
header($_SERVER["SERVER_PROTOCOL"].' 403 Forbidden', true, 403);
|
header($_SERVER["SERVER_PROTOCOL"].' 403 Forbidden', true, 403);
|
||||||
echo "only for ESP8266 updater! (header)\n";
|
echo "only for ESP8266 updater! (header)\n";
|
||||||
@ -429,13 +430,20 @@ $db = array(
|
|||||||
"18:FE:AA:AA:AA:BB" => "TEMP-1.0.0"
|
"18:FE:AA:AA:AA:BB" => "TEMP-1.0.0"
|
||||||
);
|
);
|
||||||
|
|
||||||
if(isset($db[$_SERVER['HTTP_X_ESP8266_STA_MAC']])) {
|
if(!isset($db[$_SERVER['HTTP_X_ESP8266_STA_MAC']])) {
|
||||||
if($db[$_SERVER['HTTP_X_ESP8266_STA_MAC']] != $_SERVER['HTTP_X_ESP8266_VERSION']) {
|
header($_SERVER["SERVER_PROTOCOL"].' 500 ESP MAC not configured for updates', true, 500);
|
||||||
sendFile("./bin/".$db[$_SERVER['HTTP_X_ESP8266_STA_MAC']]."bin");
|
}
|
||||||
} else {
|
|
||||||
header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified', true, 304);
|
$localBinary = "./bin/".$db[$_SERVER['HTTP_X_ESP8266_STA_MAC']].".bin";
|
||||||
}
|
|
||||||
exit();
|
// Check if version has been set and does not match, if not, check if
|
||||||
|
// MD5 hash between local binary and ESP8266 binary do not match if not.
|
||||||
|
// then no update has been found.
|
||||||
|
if((!check_header('HTTP_X_ESP8266_SDK_VERSION') && $db[$_SERVER['HTTP_X_ESP8266_STA_MAC']] != $_SERVER['HTTP_X_ESP8266_VERSION'])
|
||||||
|
|| $_SERVER["HTTP_X_ESP8266_SKETCH_MD5"] != md5_file($localBinary)) {
|
||||||
|
sendFile($localBinary);
|
||||||
|
} else {
|
||||||
|
header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified', true, 304);
|
||||||
}
|
}
|
||||||
|
|
||||||
header($_SERVER["SERVER_PROTOCOL"].' 500 no version for ESP MAC', true, 500);
|
header($_SERVER["SERVER_PROTOCOL"].' 500 no version for ESP MAC', true, 500);
|
||||||
|
@ -175,6 +175,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
|
|||||||
http.addHeader(F("x-ESP8266-AP-MAC"), WiFi.softAPmacAddress());
|
http.addHeader(F("x-ESP8266-AP-MAC"), WiFi.softAPmacAddress());
|
||||||
http.addHeader(F("x-ESP8266-free-space"), String(ESP.getFreeSketchSpace()));
|
http.addHeader(F("x-ESP8266-free-space"), String(ESP.getFreeSketchSpace()));
|
||||||
http.addHeader(F("x-ESP8266-sketch-size"), String(ESP.getSketchSize()));
|
http.addHeader(F("x-ESP8266-sketch-size"), String(ESP.getSketchSize()));
|
||||||
|
http.addHeader(F("x-ESP8266-sketch-md5"), String(ESP.getSketchMD5()));
|
||||||
http.addHeader(F("x-ESP8266-chip-size"), String(ESP.getFlashChipRealSize()));
|
http.addHeader(F("x-ESP8266-chip-size"), String(ESP.getFlashChipRealSize()));
|
||||||
http.addHeader(F("x-ESP8266-sdk-version"), ESP.getSdkVersion());
|
http.addHeader(F("x-ESP8266-sdk-version"), ESP.getSdkVersion());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user