Preserve admin password input and clarify reconnect guidance
This commit is contained in:
1 parent
ad4124b055
commit
5d741318f5
15 files changed
+2858
-2334
No files matched your search
@@ -244,8 +244,11 @@ class LightweightOTAServer {
|
||||
static const char throttled[] = "too many failed logins; wait 30 seconds";
|
||||
sendResponse(client, 429, "Too Many Requests", "text/plain", throttled, sizeof(throttled) - 1);
|
||||
} else {
|
||||
client.print("HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: Basic realm=\"MeshCore admin\", charset=\"UTF-8\"\r\n"
|
||||
"Content-Length: 0\r\nConnection: close\r\nCache-Control: no-store\r\n\r\n");
|
||||
static const char login_help[] = "Sign in with username admin and this node's admin password.";
|
||||
client.printf("HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: Basic realm=\"MeshCore (username: admin)\", charset=\"UTF-8\"\r\n"
|
||||
"Content-Type: text/plain; charset=utf-8\r\nContent-Length: %u\r\n"
|
||||
"Connection: close\r\nCache-Control: no-store\r\n\r\n%s",
|
||||
static_cast<unsigned>(sizeof(login_help) - 1), login_help);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -375,11 +378,11 @@ bool ESP32Board::startOTAUpdate(const char* id, char reply[], bool force_ap) {
|
||||
const char* network = !use_ap ? "Use same WiFi/LAN"
|
||||
: mesh::esp32::managementPassword::apPasswordEligible(credential.password)
|
||||
? "Join WiFi MeshCore-OTA (admin password)"
|
||||
: "Join WiFi MeshCore-OTA (OPEN compatibility; HTTP admin login)";
|
||||
: "Join WiFi MeshCore-OTA (OPEN compatibility)";
|
||||
if (LIGHTWEIGHT_OTA_PORT == 80) {
|
||||
snprintf(reply, 160, "Started: http://%s/update - WiFi on; %s", ip.toString().c_str(), network);
|
||||
snprintf(reply, 160, "Started: http://%s/update; %s; Login: admin / node admin password", ip.toString().c_str(), network);
|
||||
} else {
|
||||
snprintf(reply, 160, "Started: http://%s:%u/update - WiFi on; %s", ip.toString().c_str(),
|
||||
snprintf(reply, 160, "Started: http://%s:%u/update; %s; Login: admin / node admin password", ip.toString().c_str(),
|
||||
static_cast<unsigned>(LIGHTWEIGHT_OTA_PORT), network);
|
||||
}
|
||||
MESH_DEBUG_PRINTLN("startOTAUpdate: %s", reply);
|
||||
@@ -478,8 +481,8 @@ bool ESP32Board::startOTAUpdate(const char* id, char reply[], bool force_ap) {
|
||||
const char* network = !use_ap ? "Use same WiFi/LAN"
|
||||
: mesh::esp32::managementPassword::apPasswordEligible(credential.password)
|
||||
? "Join WiFi MeshCore-OTA (admin password)"
|
||||
: "Join WiFi MeshCore-OTA (OPEN compatibility; HTTP admin login)";
|
||||
snprintf(reply, 160, "Started: http://%s/update - WiFi on; %s", ip.toString().c_str(), network);
|
||||
: "Join WiFi MeshCore-OTA (OPEN compatibility)";
|
||||
snprintf(reply, 160, "Started: http://%s/update; %s; Login: admin / node admin password", ip.toString().c_str(), network);
|
||||
MESH_DEBUG_PRINTLN("startOTAUpdate: %s", reply);
|
||||
|
||||
// Select the requested network even when the HTTP listener already exists.
|
||||
|
||||
@@ -317,7 +317,9 @@ static void portalTask(void* arg) {
|
||||
if (!mesh::wifi::startManagementAccessPoint(impl->ap_name, false)) break;
|
||||
impl->ap_password_generation = current.generation;
|
||||
impl->rekey_generation = 0;
|
||||
mesh::usbLoggingPort().println("Setup WiFi updated; reconnect using the admin password");
|
||||
mesh::usbLoggingPort().println(apPasswordEligible(current.password)
|
||||
? "Setup WiFi updated; reconnect using the admin password"
|
||||
: "Setup WiFi updated; join the open network, then sign in as admin with the node admin password");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2321
-2282
File diff suppressed because it is too large.
Load diff
@@ -275,7 +275,14 @@ static const char* wcCliUnavailable(const char* cmd, bool streamed = false) {
|
||||
// are served to the client over the open setup AP. The config path overwrites it
|
||||
// by key; a CLI entry has no key, so match on the command itself.
|
||||
static inline bool wcCliEchoesSecret(const char* cmd) {
|
||||
return strncmp(cmd, "password ", 9) == 0;
|
||||
static const char verb[] = "password ";
|
||||
if (!cmd) return false;
|
||||
for (size_t i = 0; i < sizeof(verb) - 1; ++i) {
|
||||
char c = cmd[i];
|
||||
if (c >= 'A' && c <= 'Z') c = static_cast<char>(c - 'A' + 'a');
|
||||
if (c != verb[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// CLI requests require LAN mode and authentication. Explicit getters have
|
||||
@@ -3048,12 +3055,13 @@ void WebConfigServer::handleCliPost(AsyncWebServerRequest* req) {
|
||||
req->send(413, "application/json", out);
|
||||
return;
|
||||
}
|
||||
// Strip CR/LF so one entry cannot smuggle a second command past the
|
||||
// operator's confirmation, and skip whatever is left blank.
|
||||
// Keep ordinary command normalization compatible, but a password is an
|
||||
// exact value: preserve its suffix and reject line breaks, never strip them.
|
||||
BatchEntry& e = _batch[count];
|
||||
int pos = 0;
|
||||
bool line_break = false;
|
||||
for (const char* p = raw; *p; p++) {
|
||||
if (*p == '\r' || *p == '\n') continue;
|
||||
if (*p == '\r' || *p == '\n') { line_break = true; continue; }
|
||||
if (pos == 0 && (*p == ' ' || *p == '\t')) continue; // leading space
|
||||
if (pos >= (int)sizeof(e.cmd) - 1) {
|
||||
req->send(400, "application/json", "{\"error\":\"command too long\"}");
|
||||
@@ -3061,8 +3069,17 @@ void WebConfigServer::handleCliPost(AsyncWebServerRequest* req) {
|
||||
}
|
||||
e.cmd[pos++] = *p;
|
||||
}
|
||||
while (pos > 0 && (e.cmd[pos - 1] == ' ' || e.cmd[pos - 1] == '\t')) pos--;
|
||||
e.cmd[pos] = 0;
|
||||
if (wcCliEchoesSecret(e.cmd)) {
|
||||
if (line_break) {
|
||||
req->send(400, "application/json", "{\"error\":\"admin password must not contain line breaks\"}");
|
||||
return;
|
||||
}
|
||||
mesh::cli::normalizeCommandVerb(e.cmd);
|
||||
} else {
|
||||
while (pos > 0 && (e.cmd[pos - 1] == ' ' || e.cmd[pos - 1] == '\t')) pos--;
|
||||
e.cmd[pos] = 0;
|
||||
}
|
||||
if (pos == 0) continue;
|
||||
// Reject before anything runs, so a sequence never half-applies and then
|
||||
// stops on a command that was never going to work here.
|
||||
@@ -3077,7 +3094,7 @@ void WebConfigServer::handleCliPost(AsyncWebServerRequest* req) {
|
||||
}
|
||||
e.key[0] = 0; // CLI entries have no config key
|
||||
if (wcIsDeferredReboot(e.cmd)) defer_reboot = true;
|
||||
if (strncmp(e.cmd, "password ", 9) == 0) seq_sets_pwd = true;
|
||||
if (wcCliEchoesSecret(e.cmd)) seq_sets_pwd = true;
|
||||
if (strncmp(e.cmd, "set wifi.ssid ", 14) == 0) seq_sets_ssid = true;
|
||||
count++;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user