Browse Source

Unify admin passwords

fastled
Xose Pérez 8 years ago
parent
commit
bf73da17d4
6 changed files with 21 additions and 19 deletions
  1. +3
    -3
      code/html/index.html
  2. +1
    -1
      code/platformio.ini
  3. +0
    -3
      code/src/defaults.h
  4. +7
    -3
      code/src/ota.ino
  5. +4
    -4
      code/src/web.ino
  6. +6
    -5
      code/src/wifi.ino

+ 3
- 3
code/html/index.html View File

@ -168,9 +168,9 @@
</div>
<div class="pure-u-1">
<label class="form-label" for="httpPassword">Web interface password</label>
<div class="hint">Change the password for the 'admin' user to access this web interface.</div>
<input name="httpPassword" type="text" class="pure-u-1-4" tabindex="3">
<label class="form-label" for="adminPass">Administrator password</label>
<div class="hint">The administrator password is used to access this web interface (user 'admin'), but also to connect to the device when in AP mode or to flash a new firmware over-the-air (OTA).</div>
<input name="adminPass" type="text" class="pure-u-1-4" tabindex="3">
</div>
</fieldset>


+ 1
- 1
code/platformio.ini View File

@ -1,5 +1,5 @@
[platformio]
env_default = sonoff-pow-debug
env_default = node-debug
[common]
lib_install = 19,31,44,64,305,306,346,727


+ 0
- 3
code/src/defaults.h View File

@ -74,16 +74,13 @@
#define WIFI_RECONNECT_INTERVAL 300000
#define WIFI_MAX_NETWORKS 3
#define ADMIN_PASS "fibonacci"
#define AP_PASS ADMIN_PASS
#define HTTP_USERNAME "admin"
#define HTTP_PASSWORD ADMIN_PASS
#define CSRF_BUFFER_SIZE 5
// -----------------------------------------------------------------------------
// OTA & NOFUSS
// -----------------------------------------------------------------------------
#define OTA_PASS ADMIN_PASS
#define OTA_PORT 8266
#define NOFUSS_SERVER "http://192.168.1.100"
#define NOFUSS_INTERVAL 3600000


+ 7
- 3
code/src/ota.ino View File

@ -13,11 +13,15 @@ Copyright (C) 2016 by Xose Pérez <xose dot perez at gmail dot com>
// OTA
// -----------------------------------------------------------------------------
void otaSetup() {
void otaConfigure() {
ArduinoOTA.setPort(OTA_PORT);
ArduinoOTA.setHostname(getSetting("hostname", HOSTNAME).c_str());
ArduinoOTA.setPassword((const char *) OTA_PASS);
ArduinoOTA.setPassword(getSetting("adminPass", ADMIN_PASS).c_str());
}
void otaSetup() {
otaConfigure();
ArduinoOTA.onStart([]() {
DEBUG_MSG("[OTA] Start\n");


+ 4
- 4
code/src/web.ino View File

@ -93,7 +93,7 @@ void webSocketParse(uint32_t client_id, uint8_t * payload, size_t length) {
#endif
// Do not change the password if empty
if (key == "httpPassword") {
if (key == "adminPass") {
if (value.length() == 0) continue;
}
@ -118,6 +118,7 @@ void webSocketParse(uint32_t client_id, uint8_t * payload, size_t length) {
saveSettings();
wifiConfigure();
otaConfigure();
buildTopics();
#if ENABLE_RF
@ -240,11 +241,10 @@ void webSocketEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsE
// WEBSERVER
// -----------------------------------------------------------------------------
void onHome(AsyncWebServerRequest *request){
String password = getSetting("httpPassword", HTTP_PASSWORD);
void onHome(AsyncWebServerRequest *request) {
String password = getSetting("adminPass", ADMIN_PASS);
char httpPassword[password.length() + 1];
password.toCharArray(httpPassword, password.length() + 1);
Serial.println(httpPassword);
if (!request->authenticate(HTTP_USERNAME, httpPassword)) {
return request->requestAuthentication();
}


+ 6
- 5
code/src/wifi.ino View File

@ -45,13 +45,13 @@ bool createAP() {
void wifiConfigure() {
jw.scanNetworks(true);
jw.setHostname((char *) getSetting("hostname", HOSTNAME).c_str());
jw.setSoftAP((char *) getSetting("hostname", HOSTNAME).c_str(), (char *) AP_PASS);
jw.setHostname(getSetting("hostname", HOSTNAME).c_str());
jw.setSoftAP(getSetting("hostname", HOSTNAME).c_str(), getSetting("adminPass", ADMIN_PASS).c_str());
jw.setAPMode(AP_MODE_ALONE);
jw.cleanNetworks();
if (getSetting("ssid0").length() > 0) jw.addNetwork((char *) getSetting("ssid0").c_str(), (char *) getSetting("pass0").c_str());
if (getSetting("ssid1").length() > 0) jw.addNetwork((char *) getSetting("ssid1").c_str(), (char *) getSetting("pass1").c_str());
if (getSetting("ssid2").length() > 0) jw.addNetwork((char *) getSetting("ssid2").c_str(), (char *) getSetting("pass2").c_str());
if (getSetting("ssid0").length() > 0) jw.addNetwork(getSetting("ssid0").c_str(), getSetting("pass0").c_str());
if (getSetting("ssid1").length() > 0) jw.addNetwork(getSetting("ssid1").c_str(), getSetting("pass1").c_str());
if (getSetting("ssid2").length() > 0) jw.addNetwork(getSetting("ssid2").c_str(), getSetting("pass2").c_str());
}
void wifiSetup() {
@ -110,6 +110,7 @@ void wifiSetup() {
if (code == MESSAGE_ACCESSPOINT_CREATED) {
DEBUG_MSG("[WIFI] MODE AP --------------------------------------\n");
DEBUG_MSG("[WIFI] SSID %s\n", jw.getAPSSID().c_str());
DEBUG_MSG("[WIFI] PASS %s\n", getSetting("adminPass", ADMIN_PASS).c_str());
DEBUG_MSG("[WIFI] IP %s\n", WiFi.softAPIP().toString().c_str());
DEBUG_MSG("[WIFI] MAC %s\n", WiFi.softAPmacAddress().c_str());
DEBUG_MSG("[WIFI] ----------------------------------------------\n");


Loading…
Cancel
Save