Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web OTA: check authentication result before accepting payload #1812

Merged
merged 1 commit into from
Jul 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions code/espurna/web.ino
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ void _onPostConfig(AsyncWebServerRequest *request) {

void _onPostConfigData(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {

if (!webAuthenticate(request)) {
return request->requestAuthentication(getSetting("hostname").c_str());
}

// No buffer
if (final && (index == 0)) {
DynamicJsonBuffer jsonBuffer;
Expand Down Expand Up @@ -297,7 +301,11 @@ void _onUpgrade(AsyncWebServerRequest *request) {

}

void _onUpgradeData(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
void _onUpgradeFile(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {

if (!webAuthenticate(request)) {
return request->requestAuthentication(getSetting("hostname").c_str());
}

if (!index) {

Expand Down Expand Up @@ -455,7 +463,7 @@ void webSetup() {
_server->on("/reset", HTTP_GET, _onReset);
_server->on("/config", HTTP_GET, _onGetConfig);
_server->on("/config", HTTP_POST | HTTP_PUT, _onPostConfig, _onPostConfigData);
_server->on("/upgrade", HTTP_POST, _onUpgrade, _onUpgradeData);
_server->on("/upgrade", HTTP_POST, _onUpgrade, _onUpgradeFile);
_server->on("/discover", HTTP_GET, _onDiscover);

// Serve static files
Expand Down