allow remote management of wifi as user has cli permission

This commit is contained in:
liamcottle
2026-09-08 18:33:37 +12:00
parent bf64fafe90
commit 87a05e1589
+43 -47
View File
@@ -2161,54 +2161,50 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
} }
#ifdef WIFI_SSID #ifdef WIFI_SSID
// not accepted from the remote mesh CLI (timestamp != 0): these are credentials. The app if (memcmp(command, "set wifi.ssid ", 14) == 0) {
// over USB/BLE/WiFi and the serial console (timestamp 0) may set them. StrHelper::strncpy(_prefs.wifi_ssid, &command[14], sizeof(_prefs.wifi_ssid));
if (sender_timestamp == 0) { savePrefs();
if (memcmp(command, "set wifi.ssid ", 14) == 0) { sprintf(reply, "> wifi.ssid is now %s (set wifi.pwd too, then reboot)", _prefs.wifi_ssid);
StrHelper::strncpy(_prefs.wifi_ssid, &command[14], sizeof(_prefs.wifi_ssid)); return true;
savePrefs(); }
sprintf(reply, "> wifi.ssid is now %s (set wifi.pwd too, then reboot)", _prefs.wifi_ssid); if (memcmp(command, "set wifi.pwd ", 13) == 0) {
return true; StrHelper::strncpy(_prefs.wifi_pwd, &command[13], sizeof(_prefs.wifi_pwd));
} savePrefs();
if (memcmp(command, "set wifi.pwd ", 13) == 0) { strcpy(reply, "> wifi.pwd updated (reboot to apply)");
StrHelper::strncpy(_prefs.wifi_pwd, &command[13], sizeof(_prefs.wifi_pwd)); return true;
savePrefs(); }
strcpy(reply, "> wifi.pwd updated (reboot to apply)"); if (strcmp(command, "set wifi.clear") == 0) {
return true; _prefs.wifi_ssid[0] = 0;
} _prefs.wifi_pwd[0] = 0;
if (strcmp(command, "set wifi.clear") == 0) { savePrefs();
_prefs.wifi_ssid[0] = 0; strcpy(reply, "> wifi config cleared (reboot to apply)");
_prefs.wifi_pwd[0] = 0; return true;
savePrefs(); }
strcpy(reply, "> wifi config cleared (reboot to apply)"); if (strcmp(command, "get wifi.ssid") == 0) { // no 'get wifi.pwd', by design
return true; sprintf(reply, "> %s", _prefs.wifiSSID()[0] ? _prefs.wifiSSID() : "(not set)");
} return true;
if (strcmp(command, "get wifi.ssid") == 0) { // no 'get wifi.pwd', by design }
sprintf(reply, "> %s", _prefs.wifiSSID()[0] ? _prefs.wifiSSID() : "(not set)"); if (memcmp(command, "set wifi.enabled ", 17) == 0) {
return true; _prefs.wifi_enabled = atoi(&command[17]) ? 1 : 0;
} savePrefs();
if (memcmp(command, "set wifi.enabled ", 17) == 0) { sprintf(reply, "> wifi.enabled is now %d (reboot to apply)", _prefs.wifi_enabled);
_prefs.wifi_enabled = atoi(&command[17]) ? 1 : 0; return true;
savePrefs(); }
sprintf(reply, "> wifi.enabled is now %d (reboot to apply)", _prefs.wifi_enabled); if (strcmp(command, "get wifi.enabled") == 0) {
return true; sprintf(reply, "> %d", _prefs.wifiEnabled() ? 1 : 0);
} return true;
if (strcmp(command, "get wifi.enabled") == 0) { }
sprintf(reply, "> %d", _prefs.wifiEnabled() ? 1 : 0); if (strcmp(command, "get wifi.status") == 0) {
return true; strcpy(reply, WiFi.status() == WL_CONNECTED ? "> connected" : "> disconnected");
} return true;
if (strcmp(command, "get wifi.status") == 0) { }
strcpy(reply, WiFi.status() == WL_CONNECTED ? "> connected" : "> disconnected"); if (strcmp(command, "get wifi.ip") == 0) {
return true; if (WiFi.status() == WL_CONNECTED) {
} sprintf(reply, "> %s", WiFi.localIP().toString().c_str());
if (strcmp(command, "get wifi.ip") == 0) { } else {
if (WiFi.status() == WL_CONNECTED) { strcpy(reply, "> (not connected)");
sprintf(reply, "> %s", WiFi.localIP().toString().c_str());
} else {
strcpy(reply, "> (not connected)");
}
return true;
} }
return true;
} }
#endif #endif