added username config for basic auth
This commit is contained in:
+30
-2
@@ -139,11 +139,29 @@ cgiSystemCfgSetParams(HttpdConnData *connData)
|
||||
break;
|
||||
}
|
||||
|
||||
cgi_dbg("Changing access PW!!!");
|
||||
if (strlen(buff) >= 64) {
|
||||
cgi_warn("Too long access_pw %s", buff);
|
||||
redir_url += sprintf(redir_url, "access_pw,");
|
||||
break;
|
||||
}
|
||||
|
||||
cgi_dbg("Changing access PW!");
|
||||
strncpy(sysconf->access_pw, buff, 64);
|
||||
}
|
||||
}
|
||||
|
||||
if (GET_ARG("access_name")) {
|
||||
cgi_dbg("access_name: %s", buff);
|
||||
|
||||
if (!strlen(buff) || strlen(buff) >= 32) {
|
||||
cgi_warn("Too long access_name %s", buff);
|
||||
redir_url += sprintf(redir_url, "access_name,");
|
||||
break;
|
||||
}
|
||||
|
||||
strncpy(sysconf->access_name, buff, 32);
|
||||
}
|
||||
|
||||
if (GET_ARG("admin_pw")) {
|
||||
cgi_dbg("admin_pw: %s", buff);
|
||||
|
||||
@@ -161,7 +179,13 @@ cgiSystemCfgSetParams(HttpdConnData *connData)
|
||||
break;
|
||||
}
|
||||
|
||||
cgi_dbg("Changing admin PW!!!");
|
||||
if (strlen(buff) >= 64) {
|
||||
cgi_warn("Too long admin_pw %s", buff);
|
||||
redir_url += sprintf(redir_url, "admin_pw,");
|
||||
break;
|
||||
}
|
||||
|
||||
cgi_dbg("Changing admin PW!");
|
||||
strncpy(persist.admin.pw, buff, 64);
|
||||
}
|
||||
}
|
||||
@@ -211,6 +235,10 @@ tplSystemCfg(HttpdConnData *connData, char *token, void **arg)
|
||||
sprintf(buff, "%d", sysconf->pwlock);
|
||||
}
|
||||
|
||||
if (streq(token, "access_name")) {
|
||||
sprintf(buff, "%s", sysconf->access_name);
|
||||
}
|
||||
|
||||
tplSend(connData, buff, -1);
|
||||
return HTTPD_CGI_DONE;
|
||||
}
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ static void ICACHE_FLASH_ATTR
|
||||
set_admin_block_defaults(void)
|
||||
{
|
||||
persist_info("[Persist] Initing admin config block");
|
||||
strcpy(persist.admin.pw, STR(ADMIN_PASSWORD));
|
||||
strcpy(persist.admin.pw, DEFAULT_ADMIN_PW);
|
||||
persist.admin.version = ADMINCONF_VERSION;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "screen.h"
|
||||
#include "syscfg.h"
|
||||
|
||||
#define DEFAULT_ADMIN_PW "adminpw"
|
||||
|
||||
// Changing this could be used to force-erase the config area
|
||||
// after a firmware upgrade
|
||||
#define CHECKSUM_SALT 5
|
||||
|
||||
+15
-2
@@ -13,6 +13,7 @@
|
||||
#include "cgi_term_cfg.h"
|
||||
#include "cgi_persist.h"
|
||||
#include "syscfg.h"
|
||||
#include "persist.h"
|
||||
|
||||
/**
|
||||
* Password for WiFi config
|
||||
@@ -20,10 +21,15 @@
|
||||
static int ICACHE_FLASH_ATTR wifiPassFn(HttpdConnData *connData, int no, char *user, int userLen, char *pass, int passLen)
|
||||
{
|
||||
if (no == 0) {
|
||||
os_strcpy(user, "admin");
|
||||
os_strcpy(user, sysconf->access_name);
|
||||
os_strcpy(pass, sysconf->access_pw);
|
||||
return 1;
|
||||
}
|
||||
if (no == 1) {
|
||||
os_strcpy(user, "admin");
|
||||
os_strcpy(pass, persist.admin.pw);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -31,6 +37,8 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiOptionalPwLock(HttpdConnData *connData)
|
||||
{
|
||||
bool protect = false;
|
||||
|
||||
http_dbg("Route, %s, pwlock=%d", connData->url, sysconf->pwlock);
|
||||
|
||||
switch (sysconf->pwlock) {
|
||||
case PWLOCK_ALL:
|
||||
protect = true;
|
||||
@@ -63,12 +71,17 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiOptionalPwLock(HttpdConnData *connData)
|
||||
if (strstarts(connData->url, "/system/cls")) protect = true;
|
||||
}
|
||||
|
||||
if (sysconf->access_pw[0] == 0) protect = false;
|
||||
if (sysconf->access_pw[0] == 0) {
|
||||
http_dbg("Access PW is nil, no protection.");
|
||||
protect = false;
|
||||
}
|
||||
|
||||
if (protect) {
|
||||
http_dbg("Page is protected!");
|
||||
connData->cgiArg = wifiPassFn;
|
||||
return authBasic(connData);
|
||||
} else {
|
||||
http_dbg("Not protected");
|
||||
return HTTPD_CGI_NOTFOUND;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-1
@@ -15,9 +15,16 @@ sysconf_apply_settings(void)
|
||||
bool changed = false;
|
||||
if (sysconf->config_version < 1) {
|
||||
dbg("Upgrading syscfg to v 1");
|
||||
changed = true;
|
||||
sysconf->access_pw[0] = 0;
|
||||
sysconf->pwlock = PWLOCK_NONE;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (sysconf->config_version < 2) {
|
||||
dbg("Upgrading syscfg to v 2");
|
||||
strcpy(sysconf->access_pw, DEF_ACCESS_PW);
|
||||
strcpy(sysconf->access_name, DEF_ACCESS_NAME);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
sysconf->config_version = SYSCONF_VERSION;
|
||||
|
||||
+5
-1
@@ -10,7 +10,10 @@
|
||||
// Size designed for the wifi config structure
|
||||
// Must be constant to avoid corrupting user config after upgrade
|
||||
#define SYSCONF_SIZE 300
|
||||
#define SYSCONF_VERSION 1
|
||||
#define SYSCONF_VERSION 2
|
||||
|
||||
#define DEF_ACCESS_PW "1234"
|
||||
#define DEF_ACCESS_NAME "espterm"
|
||||
|
||||
enum pwlock {
|
||||
PWLOCK_NONE = 0,
|
||||
@@ -28,6 +31,7 @@ typedef struct {
|
||||
u8 config_version;
|
||||
enum pwlock pwlock : 8; // page access lock
|
||||
char access_pw[64]; // access password
|
||||
char access_name[32]; // access name
|
||||
} SystemConfigBundle;
|
||||
|
||||
extern SystemConfigBundle * const sysconf;
|
||||
|
||||
Reference in New Issue
Block a user