Skip to content

Commit

Permalink
fixes after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
crasu committed Mar 25, 2023
1 parent 349e312 commit 2e2858a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 25 deletions.
37 changes: 23 additions & 14 deletions code/components/jomjol_wlan/read_wlanini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,29 @@ int LoadWlanFromFile(std::string fn)
wlan_config.dns = tmp;
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "DNS: " + wlan_config.dns);
}

else if ((splitted.size() > 1) && (toUpper(splitted[0]) == "HTTP_USERNAME")){
tmp = splitted[1];
if ((tmp[0] == '"') && (tmp[tmp.length()-1] == '"')){
tmp = tmp.substr(1, tmp.length()-2);
}
wlan_config.http_username = tmp;
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "HTTP_USERNAME: " + wlan_config.http_username);
}

else if ((splitted.size() > 1) && (toUpper(splitted[0]) == "HTTP_PASSWORD")){
tmp = splitted[1];
if ((tmp[0] == '"') && (tmp[tmp.length()-1] == '"')){
tmp = tmp.substr(1, tmp.length()-2);
}
wlan_config.http_password = tmp;
#ifndef __HIDE_PASSWORD
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "HTTP_PASSWORD: " + wlan_config.http_password);
#else
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "HTTP_PASSWORD: XXXXXXXX");
#endif
}

#if (defined WLAN_USE_ROAMING_BY_SCANNING || (defined WLAN_USE_MESH_ROAMING && defined WLAN_USE_MESH_ROAMING_ACTIVATE_CLIENT_TRIGGERED_QUERIES))
else if ((splitted.size() > 1) && (toUpper(splitted[0]) == "RSSITHRESHOLD")){
tmp = trim(splitted[1]);
Expand All @@ -157,20 +180,6 @@ int LoadWlanFromFile(std::string fn)
#endif
}

if ((splitted.size() > 1) && (toUpper(splitted[0]) == "HTTP_USERNAME")){
http_username = splitted[1];
if ((http_username[0] == '"') && (http_username[http_username.length()-1] == '"')){
http_username = http_username.substr(1, http_username.length()-2);
}
}

if ((splitted.size() > 1) && (toUpper(splitted[0]) == "HTTP_PASSWORD")){
http_password = splitted[1];
if ((http_password[0] == '"') && (http_password[http_password.length()-1] == '"')){
http_password = http_password.substr(1, http_password.length()-2);
}
}

if (fgets(zw, 1024, pFile) == NULL)
{
line = "";
Expand Down
2 changes: 2 additions & 0 deletions code/components/jomjol_wlan/read_wlanini.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ struct wlan_config {
std::string gateway = "";
std::string netmask = "";
std::string dns = "";
std::string http_username = "";
std::string http_password = "";
int rssi_threshold = 0; // Default: 0 -> ROAMING disabled
};
extern struct wlan_config wlan_config;
Expand Down
8 changes: 3 additions & 5 deletions code/include/basic_auth.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#ifndef BASIC_AUTH_H
#define BASIC_AUTH_H
#pragma once

#include <esp_http_server.h>

void init_basic_auth(char *username, char *password);
void init_basic_auth();
esp_err_t basic_auth_request_filter(httpd_req_t *req, esp_err_t original_handler(httpd_req_t *));

#define APPLY_BASIC_AUTH_FILTER(method) [](httpd_req_t *req){ return basic_auth_request_filter(req, method); }
#endif
#define APPLY_BASIC_AUTH_FILTER(method) [](httpd_req_t *req){ return basic_auth_request_filter(req, method); }
14 changes: 9 additions & 5 deletions code/main/basic_auth.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
#include "basic_auth.h"
#include "read_wlanini.h"
#include <esp_tls_crypto.h>
#include <esp_log.h>


#define HTTPD_401 "401 UNAUTHORIZED"

static const char *TAG = "HTTPAUTH";

typedef struct {
char *username;
char *password;
const char *username;
const char *password;
} basic_auth_info_t;

basic_auth_info_t basic_auth_info = { NULL, NULL };

void init_basic_auth(char *username, char *password) {
basic_auth_info.username = username;
basic_auth_info.password = password;
void init_basic_auth() {
if (!wlan_config.http_username.empty() && !wlan_config.http_password.empty()) {
basic_auth_info.username = wlan_config.http_username.c_str();
basic_auth_info.password = wlan_config.http_password.c_str();
}
}

static char *http_auth_basic(const char *username, const char *password)
Expand Down
2 changes: 2 additions & 0 deletions code/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ extern "C" void app_main(void)
StatusLED(WLAN_INIT, 3, true);
return;
}

init_basic_auth();
}
else if (iWLANStatus == -1) { // wlan.ini not available, potentially empty or content not readable
StatusLED(WLAN_INIT, 1, true);
Expand Down
1 change: 0 additions & 1 deletion code/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ build_flags =
${flags:runtime.build_flags}
; ### Sofware options : (can be set in defines.h)
-D ENABLE_MQTT
-D ENABLE_INFLUXDB
-D ENABLE_SOFTAP
board_build.partitions = partitions.csv
monitor_speed = 115200
Expand Down

0 comments on commit 2e2858a

Please sign in to comment.