apply credentials to wifimanager configuration portal
This commit is contained in:
@@ -212,8 +212,19 @@ WiFiManager::WiFiManager(Print& consolePort):_debugPort(consolePort){
|
|||||||
WiFiManagerInit();
|
WiFiManagerInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WiFiManager::WiFiManager(const char* user, const char* password) {
|
||||||
|
WiFiManagerInit();
|
||||||
|
|
||||||
|
if(strlen(user) > 0)
|
||||||
|
{
|
||||||
|
strcpy(_credUser, user);
|
||||||
|
strcpy(_credPassword, password);
|
||||||
|
_hasCredentials = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WiFiManager::WiFiManager() {
|
WiFiManager::WiFiManager() {
|
||||||
WiFiManagerInit();
|
WiFiManagerInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiFiManager::WiFiManagerInit(){
|
void WiFiManager::WiFiManagerInit(){
|
||||||
@@ -1329,6 +1340,9 @@ void WiFiManager::handleRoot() {
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Root"));
|
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Root"));
|
||||||
#endif
|
#endif
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
if (captivePortal()) return; // If captive portal redirect instead of displaying the page
|
if (captivePortal()) return; // If captive portal redirect instead of displaying the page
|
||||||
handleRequest();
|
handleRequest();
|
||||||
String page = getHTTPHead(_title); // @token options @todo replace options with title
|
String page = getHTTPHead(_title); // @token options @todo replace options with title
|
||||||
@@ -1355,6 +1369,11 @@ void WiFiManager::handleWifi(boolean scan) {
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Wifi"));
|
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Wifi"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
|
|
||||||
handleRequest();
|
handleRequest();
|
||||||
String page = getHTTPHead(FPSTR(S_titlewifi)); // @token titlewifi
|
String page = getHTTPHead(FPSTR(S_titlewifi)); // @token titlewifi
|
||||||
if (scan) {
|
if (scan) {
|
||||||
@@ -1411,6 +1430,11 @@ void WiFiManager::handleParam(){
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Param"));
|
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Param"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
|
|
||||||
handleRequest();
|
handleRequest();
|
||||||
String page = getHTTPHead(FPSTR(S_titleparam)); // @token titlewifi
|
String page = getHTTPHead(FPSTR(S_titleparam)); // @token titlewifi
|
||||||
|
|
||||||
@@ -1790,6 +1814,11 @@ void WiFiManager::handleWiFiStatus(){
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP WiFi status "));
|
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP WiFi status "));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
|
|
||||||
handleRequest();
|
handleRequest();
|
||||||
String page;
|
String page;
|
||||||
// String page = "{\"result\":true,\"count\":1}";
|
// String page = "{\"result\":true,\"count\":1}";
|
||||||
@@ -1807,6 +1836,11 @@ void WiFiManager::handleWifiSave() {
|
|||||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP WiFi save "));
|
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP WiFi save "));
|
||||||
DEBUG_WM(DEBUG_DEV,F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST));
|
DEBUG_WM(DEBUG_DEV,F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
|
|
||||||
handleRequest();
|
handleRequest();
|
||||||
|
|
||||||
//SAVE/connect here
|
//SAVE/connect here
|
||||||
@@ -1882,6 +1916,11 @@ void WiFiManager::handleParamSave() {
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(DEBUG_DEV,F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST));
|
DEBUG_WM(DEBUG_DEV,F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
|
|
||||||
handleRequest();
|
handleRequest();
|
||||||
|
|
||||||
doParamSave();
|
doParamSave();
|
||||||
@@ -1951,6 +1990,11 @@ void WiFiManager::handleInfo() {
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Info"));
|
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Info"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
|
|
||||||
handleRequest();
|
handleRequest();
|
||||||
String page = getHTTPHead(FPSTR(S_titleinfo)); // @token titleinfo
|
String page = getHTTPHead(FPSTR(S_titleinfo)); // @token titleinfo
|
||||||
reportStatus(page);
|
reportStatus(page);
|
||||||
@@ -2296,6 +2340,11 @@ void WiFiManager::handleExit() {
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Exit"));
|
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Exit"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
|
|
||||||
handleRequest();
|
handleRequest();
|
||||||
String page = getHTTPHead(FPSTR(S_titleexit)); // @token titleexit
|
String page = getHTTPHead(FPSTR(S_titleexit)); // @token titleexit
|
||||||
page += FPSTR(S_exiting); // @token exiting
|
page += FPSTR(S_exiting); // @token exiting
|
||||||
@@ -2313,6 +2362,11 @@ void WiFiManager::handleReset() {
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Reset"));
|
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Reset"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
|
|
||||||
handleRequest();
|
handleRequest();
|
||||||
String page = getHTTPHead(FPSTR(S_titlereset)); //@token titlereset
|
String page = getHTTPHead(FPSTR(S_titlereset)); //@token titlereset
|
||||||
page += FPSTR(S_resetting); //@token resetting
|
page += FPSTR(S_resetting); //@token resetting
|
||||||
@@ -2338,6 +2392,11 @@ void WiFiManager::handleErase(boolean opt) {
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(DEBUG_NOTIFY,F("<- HTTP Erase"));
|
DEBUG_WM(DEBUG_NOTIFY,F("<- HTTP Erase"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
|
|
||||||
handleRequest();
|
handleRequest();
|
||||||
String page = getHTTPHead(FPSTR(S_titleerase)); // @token titleerase
|
String page = getHTTPHead(FPSTR(S_titleerase)); // @token titleerase
|
||||||
|
|
||||||
@@ -2424,6 +2483,11 @@ void WiFiManager::stopCaptivePortal(){
|
|||||||
// HTTPD CALLBACK, handle close, stop captive portal, if not enabled undefined
|
// HTTPD CALLBACK, handle close, stop captive portal, if not enabled undefined
|
||||||
void WiFiManager::handleClose(){
|
void WiFiManager::handleClose(){
|
||||||
DEBUG_WM(DEBUG_VERBOSE,F("Disabling Captive Portal"));
|
DEBUG_WM(DEBUG_VERBOSE,F("Disabling Captive Portal"));
|
||||||
|
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
|
|
||||||
stopCaptivePortal();
|
stopCaptivePortal();
|
||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP close"));
|
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP close"));
|
||||||
@@ -3815,6 +3879,11 @@ void WiFiManager::handleUpdate() {
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(DEBUG_VERBOSE,F("<- Handle update"));
|
DEBUG_WM(DEBUG_VERBOSE,F("<- Handle update"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
|
|
||||||
if (captivePortal()) return; // If captive portal redirect instead of displaying the page
|
if (captivePortal()) return; // If captive portal redirect instead of displaying the page
|
||||||
String page = getHTTPHead(_title); // @token options
|
String page = getHTTPHead(_title); // @token options
|
||||||
String str = FPSTR(HTTP_ROOT_MAIN);
|
String str = FPSTR(HTTP_ROOT_MAIN);
|
||||||
@@ -3926,6 +3995,10 @@ void WiFiManager::handleUpdateDone() {
|
|||||||
DEBUG_WM(DEBUG_VERBOSE, F("<- Handle update done"));
|
DEBUG_WM(DEBUG_VERBOSE, F("<- Handle update done"));
|
||||||
// if (captivePortal()) return; // If captive portal redirect instead of displaying the page
|
// if (captivePortal()) return; // If captive portal redirect instead of displaying the page
|
||||||
|
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
|
|
||||||
String page = getHTTPHead(FPSTR(S_options)); // @token options
|
String page = getHTTPHead(FPSTR(S_options)); // @token options
|
||||||
String str = FPSTR(HTTP_ROOT_MAIN);
|
String str = FPSTR(HTTP_ROOT_MAIN);
|
||||||
str.replace(FPSTR(T_t),_title);
|
str.replace(FPSTR(T_t),_title);
|
||||||
|
|||||||
@@ -239,6 +239,7 @@ class WiFiManager
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WiFiManager(Print& consolePort);
|
WiFiManager(Print& consolePort);
|
||||||
|
WiFiManager(const char* user, const char* password);
|
||||||
WiFiManager();
|
WiFiManager();
|
||||||
~WiFiManager();
|
~WiFiManager();
|
||||||
void WiFiManagerInit();
|
void WiFiManagerInit();
|
||||||
@@ -820,6 +821,10 @@ class WiFiManager
|
|||||||
std::function<void()> _preotaupdatecallback;
|
std::function<void()> _preotaupdatecallback;
|
||||||
std::function<void()> _configportaltimeoutcallback;
|
std::function<void()> _configportaltimeoutcallback;
|
||||||
|
|
||||||
|
bool _hasCredentials = false;
|
||||||
|
char _credUser[31] = {0};
|
||||||
|
char _credPassword[31] = {0};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
auto optionalIPFromString(T *obj, const char *s) -> decltype( obj->fromString(s) ) {
|
auto optionalIPFromString(T *obj, const char *s) -> decltype( obj->fromString(s) ) {
|
||||||
return obj->fromString(s);
|
return obj->fromString(s);
|
||||||
|
|||||||
@@ -8,16 +8,17 @@
|
|||||||
|
|
||||||
RTC_NOINIT_ATTR char WiFiDevice_reconfdetect[17];
|
RTC_NOINIT_ATTR char WiFiDevice_reconfdetect[17];
|
||||||
|
|
||||||
WifiDevice::WifiDevice(const String& hostname, Preferences* _preferences, const IPConfiguration* ipConfiguration)
|
WifiDevice::WifiDevice(const String& hostname, Preferences* preferences, const IPConfiguration* ipConfiguration)
|
||||||
: NetworkDevice(hostname, ipConfiguration)
|
: NetworkDevice(hostname, ipConfiguration),
|
||||||
|
_wm(preferences->getString(preference_cred_user).c_str(), preferences->getString(preference_cred_password).c_str())
|
||||||
{
|
{
|
||||||
_startAp = strcmp(WiFiDevice_reconfdetect, "reconfigure_wifi") == 0;
|
_startAp = strcmp(WiFiDevice_reconfdetect, "reconfigure_wifi") == 0;
|
||||||
|
|
||||||
_restartOnDisconnect = _preferences->getBool(preference_restart_on_disconnect);
|
_restartOnDisconnect = preferences->getBool(preference_restart_on_disconnect);
|
||||||
|
|
||||||
size_t caLength = _preferences->getString(preference_mqtt_ca,_ca,TLS_CA_MAX_SIZE);
|
size_t caLength = preferences->getString(preference_mqtt_ca, _ca, TLS_CA_MAX_SIZE);
|
||||||
size_t crtLength = _preferences->getString(preference_mqtt_crt,_cert,TLS_CERT_MAX_SIZE);
|
size_t crtLength = preferences->getString(preference_mqtt_crt, _cert, TLS_CERT_MAX_SIZE);
|
||||||
size_t keyLength = _preferences->getString(preference_mqtt_key,_key,TLS_KEY_MAX_SIZE);
|
size_t keyLength = preferences->getString(preference_mqtt_key, _key, TLS_KEY_MAX_SIZE);
|
||||||
|
|
||||||
_useEncryption = caLength > 1; // length is 1 when empty
|
_useEncryption = caLength > 1; // length is 1 when empty
|
||||||
|
|
||||||
@@ -41,12 +42,12 @@ WifiDevice::WifiDevice(const String& hostname, Preferences* _preferences, const
|
|||||||
_mqttClient = new espMqttClient(espMqttClientTypes::UseInternalTask::NO);
|
_mqttClient = new espMqttClient(espMqttClientTypes::UseInternalTask::NO);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_preferences->getBool(preference_mqtt_log_enabled))
|
if(preferences->getBool(preference_mqtt_log_enabled))
|
||||||
{
|
{
|
||||||
_path = new char[200];
|
_path = new char[200];
|
||||||
memset(_path, 0, sizeof(_path));
|
memset(_path, 0, sizeof(_path));
|
||||||
|
|
||||||
String pathStr = _preferences->getString(preference_mqtt_lock_path);
|
String pathStr = preferences->getString(preference_mqtt_lock_path);
|
||||||
pathStr.concat(mqtt_topic_log);
|
pathStr.concat(mqtt_topic_log);
|
||||||
strcpy(_path, pathStr.c_str());
|
strcpy(_path, pathStr.c_str());
|
||||||
Log = new MqttLogger(this, _path, MqttLoggerMode::MqttAndSerial);
|
Log = new MqttLogger(this, _path, MqttLoggerMode::MqttAndSerial);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
class WifiDevice : public NetworkDevice
|
class WifiDevice : public NetworkDevice
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WifiDevice(const String& hostname, Preferences* _preferences, const IPConfiguration* ipConfiguration);
|
WifiDevice(const String& hostname, Preferences* preferences, const IPConfiguration* ipConfiguration);
|
||||||
|
|
||||||
const String deviceName() const override;
|
const String deviceName() const override;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user