X-Git-Url: https://git.rvb.name/esp-clock.git/blobdiff_plain/dab14a20e37e760a82b72f50f765caa26fff556e..e1b7c70070cda97937a405a2c9e48d190b4391ef:/web.cpp diff --git a/web.cpp b/web.cpp index 7632250..7b7f1bc 100644 --- a/web.cpp +++ b/web.cpp @@ -129,13 +129,11 @@ void setupWeb() { isWebStarted = true; - Serial.println("Setting authentication..."); strncpy(auth_user,cfg.getCharValue(F("auth_user")),31); strncpy(auth_pwd,cfg.getCharValue(F("auth_pwd")),31); server.on("/action", HTTP_GET, [](AsyncWebServerRequest* request) { if (auth_user && auth_pwd && auth_user[0] && auth_pwd[0] && !request->authenticate(auth_user, auth_pwd)) { - Serial.print("Failed auth as user: "); Serial.print(auth_user); Serial.print(':'); Serial.print(auth_pwd); Serial.println('!'); return request-> requestAuthentication(); } if(request->hasParam("name")) { @@ -279,9 +277,9 @@ void setupWeb() { } }); - server.serveStatic("ui", LittleFS, "/ui.json"); + server.serveStatic("ui", LittleFS, "/ui.json").setAuthentication(auth_user,auth_pwd); - server.serveStatic("/", LittleFS, "/web/").setDefaultFile("index.html"); + server.serveStatic("/", LittleFS, "/web/").setDefaultFile("index.html").setAuthentication(auth_user,auth_pwd); server.onNotFound([](AsyncWebServerRequest *request){ request->send(404,"text/plain","Not found"); @@ -291,6 +289,8 @@ void setupWeb() { sendInitial(client); }); + events.setAuthentication(auth_user,auth_pwd); + server.addHandler(&events); server.begin(); @@ -307,18 +307,18 @@ void tickWeb() { static bool connectInProgress = false; static unsigned long connectMillis = 0; if (actionScheduled && millis()>millisScheduled+300) { - Serial.print(F("Scheduled action ")); Serial.println(actionScheduled); + Serial.print(F("Запланированная операция ")); Serial.println(actionScheduled); // if (strcmp(actionScheduled,"restart") == 0) { server.end(); reboot(); } else if (strcmp(actionScheduled,"auth") == 0) { - Serial.println("New authentication credentials"); + Serial.println("Логин/пароль изменены"); strncpy(auth_user,cfg.getCharValue(F("auth_user")),31); strncpy(auth_pwd,cfg.getCharValue(F("auth_pwd")),31); pendingAuth = false; } else if (strcmp(actionScheduled,"wifi") == 0) { - Serial.println("New wifi credentials"); + Serial.println("Применяю настройки сети"); strcpy(storedSSID,WiFi.SSID().c_str()); strcpy(storedPSK,WiFi.psk().c_str()); WiFi.mode(WIFI_STA);