diff --git a/components/utils/CMakeLists.txt b/components/utils/CMakeLists.txt index ee751e2..c249938 100644 --- a/components/utils/CMakeLists.txt +++ b/components/utils/CMakeLists.txt @@ -1,4 +1,4 @@ -idf_component_register(SRCS utils.c initialization.c nvm.c mac_generator.c +idf_component_register(SRCS utils.c initialization.c nvm.c mac_generator.c mac_filter.c INCLUDE_DIRS include REQUIRES cmd_router cmd_nvs nvs_flash json esp_http_server) \ No newline at end of file diff --git a/components/utils/include/initialization.h b/components/utils/include/initialization.h index 2e72624..9bc0266 100644 --- a/components/utils/include/initialization.h +++ b/components/utils/include/initialization.h @@ -24,7 +24,7 @@ extern "C" #define DEFAULT_SSID "ESP32_NAT_Router +" bool IsLedEnable, IsWebServerEnable, IsCustomDnsEnable, - IsRandomizeMacEnable, IsDarkModeEnable, IsWifiAuthFail; + IsRandomizeMacEnable, IsDarkModeEnable, IsWifiAuthFail, IsMacFilterEnable, IsAllowList; char *customDNSip, *authUsername, *authPass, *macAp, *dnsIP, *cache; diff --git a/components/utils/include/mac_filter.h b/components/utils/include/mac_filter.h new file mode 100644 index 0000000..9ab6800 --- /dev/null +++ b/components/utils/include/mac_filter.h @@ -0,0 +1,32 @@ +/** + * @author Jaya Satish + * + *@copyright Copyright (c) 2023 + *Licensed under MIT + * + */ + +#pragma once + +#ifdef __cplusplus +extern "C" +{ +#endif +#include +#include +#include + +#define MAX_MAC_ADDRESSES 10 +#define NVS_KEY "stored_macs" + + +esp_err_t store_mac_address_in_nvs(const char *macAddress); +esp_err_t remove_mac_address_from_nvs(const char *macAddress); +bool check_mac_address_in_nvs(const char *macAddress); +cJSON *retrieve_mac_addresses_as_json(); +void mac_filter(const uint8_t mac[6],uint8_t aid); +void refresh_mac_filter(); + +#ifdef __cplusplus +} +#endif diff --git a/components/utils/initialization.c b/components/utils/initialization.c index 0eb7242..0e81fe8 100644 --- a/components/utils/initialization.c +++ b/components/utils/initialization.c @@ -16,7 +16,8 @@ static const char *TAG = "utils/initialization"; bool IsLedEnable = true, IsWebServerEnable = true, IsCustomDnsEnable = false, IsRandomizeMacEnable = false, - IsDarkModeEnable = false, IsWifiAuthFail = false; + IsDarkModeEnable = false, IsWifiAuthFail = false, + IsMacFilterEnable = false, IsAllowList = false; char *ssid, *ent_username, *ent_identity, *passwd, *static_ip, *subnet_mask, *gateway_addr, @@ -29,7 +30,7 @@ char currentMAC[18]; esp_err_t IRAM_ATTR parms_init() { int webServer = 1, ledEnable = 1, customDnsEnable = 0, - darkModeEnable = 0, randomizeMac = 0; + darkModeEnable = 0, randomizeMac = 0, isMacFilterEnable = 0, isAllowList = 0; // ESP_LOGW(TAG, "initialization Started"); get_config_param_str("ssid", &ssid); @@ -54,6 +55,8 @@ esp_err_t IRAM_ATTR parms_init() get_config_param_int("randomize_mac", &randomizeMac); get_config_param_int("max_login_attempts", &max_login_attempts); get_config_param_int("lock_out_time_minutes", &lock_out_time_minutes); + get_config_param_int("mac_Filter", &isMacFilterEnable); + get_config_param_int("Is_allow_list", &isAllowList); ap_ssid = (ap_ssid != NULL) ? ap_ssid : DEFAULT_SSID; ap_passwd = (ap_passwd != NULL) ? ap_passwd : ""; @@ -79,6 +82,8 @@ esp_err_t IRAM_ATTR parms_init() IsCustomDnsEnable = (customDnsEnable != 0); IsDarkModeEnable = (darkModeEnable != 0); IsRandomizeMacEnable = (randomizeMac != 0); + IsMacFilterEnable = (isMacFilterEnable != 0); + IsAllowList = (isAllowList != 0); auth_info.username = authUsername; auth_info.password = authPass; diff --git a/components/utils/mac_filter.c b/components/utils/mac_filter.c new file mode 100644 index 0000000..f9e0981 --- /dev/null +++ b/components/utils/mac_filter.c @@ -0,0 +1,82 @@ +/** + * @author Jaya Satish + * @license + * this software licensed under MIT + * + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mac_filter.h" +#include "initialization.h" + + +bool check_mac_address_in_nvs(const char *macAddress) { + cJSON *json = retrieve_mac_addresses_as_json(); + if (json == NULL) return false; + + int numMacs = cJSON_GetArraySize(json); + for (int i = 0; i < numMacs; i++) { + if (strcmp(cJSON_GetArrayItem(json, i)->valuestring, macAddress) == 0) { + cJSON_Delete(json); + return true; + } + } + + cJSON_Delete(json); + return false; +} + +//----------------------------------------------------------------------------- +void mac_filter(const uint8_t mac[6], uint8_t aid) { + char mac_address[18]; + sprintf(mac_address, MACSTR, MAC2STR(mac)); + if (IsMacFilterEnable) { + if ((IsAllowList && !check_mac_address_in_nvs(mac_address)) || + (!IsAllowList && check_mac_address_in_nvs(mac_address))) { + ESP_LOGI("MAC Filter","MAC Address %s not allowed, disconnecting...\n", IsAllowList ? "NOT found in Allow List" : "found in Deny List"); + esp_wifi_deauth_sta(aid); + } + } +} + +//----------------------------------------------------------------------------- +esp_err_t check_in_filter_list(const uint8_t mac[6]) { + uint16_t aid; + esp_err_t err = esp_wifi_ap_get_sta_aid(mac, &aid); + if (err == ESP_OK) { + mac_filter(mac, aid); + } else { + printf("Failed to get AID for MAC address\n"); + } + return err; +} + +//----------------------------------------------------------------------------- +void refresh_mac_filter() { + wifi_sta_list_t wifi_sta_list; + tcpip_adapter_sta_list_t adapter_sta_list; + memset(&wifi_sta_list, 0, sizeof(wifi_sta_list)); + memset(&adapter_sta_list, 0, sizeof(adapter_sta_list)); + ESP_ERROR_CHECK(esp_wifi_ap_get_sta_list(&wifi_sta_list)); + ESP_ERROR_CHECK(tcpip_adapter_get_sta_list(&wifi_sta_list, &adapter_sta_list)); + + for (int i = 0; i < adapter_sta_list.num; i++) { + tcpip_adapter_sta_info_t station = adapter_sta_list.sta[i]; + esp_err_t result = check_in_filter_list(station.mac); + if (result != ESP_OK) { + //printf("Error processing MAC address at index %d\n", i); + } + + } +} + +//----------------------------------------------------------------------------- \ No newline at end of file diff --git a/components/utils/nvm.c b/components/utils/nvm.c index 679f21e..13ab2ff 100644 --- a/components/utils/nvm.c +++ b/components/utils/nvm.c @@ -11,9 +11,12 @@ #include #include #include "esp_err.h" +#include + #include "nvm.h" #include "router_globals.h" #include "utils.h" +#include "mac_filter.h" static const char *TAG = "utils/nvm"; @@ -66,3 +69,113 @@ esp_err_t nvm_erase(void) nvs_close(nvs_handle); return ESP_OK; } + +//----------------------------------------------------------------------------- +cJSON *retrieve_mac_addresses_as_json() { + nvs_handle_t handle; + esp_err_t err = nvs_open(PARAM_NAMESPACE, NVS_READONLY, &handle); + if (err != ESP_OK) { + return NULL; + } + + size_t required_size; + err = nvs_get_str(handle, NVS_KEY, NULL, &required_size); + if (err != ESP_OK || required_size == 0) { + nvs_close(handle); + return NULL; + } + + char *buffer = malloc(required_size); + if (buffer == NULL) { + nvs_close(handle); + return NULL; + } + + err = nvs_get_str(handle, NVS_KEY, buffer, &required_size); + if (err != ESP_OK) { + free(buffer); + nvs_close(handle); + return NULL; + } + + cJSON *json = cJSON_Parse(buffer); + free(buffer); + nvs_close(handle); + return json; +} + +//----------------------------------------------------------------------------- +esp_err_t save_mac_addresses_as_json(cJSON *json) { + nvs_handle_t handle; + esp_err_t err = nvs_open(PARAM_NAMESPACE, NVS_READWRITE, &handle); + if (err != ESP_OK) { + cJSON_Delete(json); + return err; + } + + char *serialized = cJSON_Print(json); + if (serialized == NULL) { + cJSON_Delete(json); + nvs_close(handle); + return ESP_ERR_NO_MEM; + } + + err = nvs_set_str(handle, NVS_KEY, serialized); + + ESP_LOGI("MACS ARE","%s",serialized); + free(serialized); + nvs_close(handle); + return err; +} + +//----------------------------------------------------------------------------- +esp_err_t store_mac_address_in_nvs(const char *macAddress) { + cJSON *json = retrieve_mac_addresses_as_json(); + if (json == NULL) { + json = cJSON_CreateArray(); + } + + int numMacs = cJSON_GetArraySize(json); + if (numMacs >= MAX_MAC_ADDRESSES) { + cJSON_Delete(json); + return ESP_ERR_NO_MEM; + } + + for (int i = 0; i < numMacs; i++) { + const char *storedMac = cJSON_GetArrayItem(json, i)->valuestring; + if (strcmp(storedMac, macAddress) == 0) { + cJSON_Delete(json); + return ESP_OK; + } + } + + cJSON_AddItemToArray(json, cJSON_CreateString(macAddress)); + + esp_err_t err = save_mac_addresses_as_json(json); + cJSON_Delete(json); + return err; +} + +//----------------------------------------------------------------------------- +esp_err_t remove_mac_address_from_nvs(const char *macAddress) { + cJSON *json = retrieve_mac_addresses_as_json(); + if (json == NULL) { + return ESP_ERR_NVS_NOT_FOUND; + } + + int numMacs = cJSON_GetArraySize(json); + for (int i = 0; i < numMacs; i++) { + const char *storedMac = cJSON_GetArrayItem(json, i)->valuestring; + if (strcmp(storedMac, macAddress) == 0) { + cJSON_DeleteItemFromArray(json, i); + + esp_err_t err = save_mac_addresses_as_json(json); + cJSON_Delete(json); + return err; + } + } + cJSON_Delete(json); + return ESP_ERR_NOT_FOUND; +} + +//----------------------------------------------------------------------------- \ No newline at end of file diff --git a/components/web_server/get_data_handler.c b/components/web_server/get_data_handler.c index 1fa90af..5c66637 100644 --- a/components/web_server/get_data_handler.c +++ b/components/web_server/get_data_handler.c @@ -50,6 +50,7 @@ esp_err_t get_settings_data_handler(httpd_req_t *req) cJSON_AddBoolToObject(root, "ledEnable", IsLedEnable); cJSON_AddBoolToObject(root, "darkMode", IsDarkModeEnable); cJSON_AddBoolToObject(root, "webServer", IsWebServerEnable); + cJSON_AddBoolToObject(root, "macFilterEnabled", IsMacFilterEnable); cJSON_AddStringToObject(root, "authUsername", authUsername); cJSON_AddStringToObject(root, "authPassword", authPass); cJSON_AddNumberToObject(root, "maxLoginAttempts", max_login_attempts); diff --git a/components/web_server/storage_handler.c b/components/web_server/storage_handler.c index 79d9709..0358254 100644 --- a/components/web_server/storage_handler.c +++ b/components/web_server/storage_handler.c @@ -15,6 +15,7 @@ #include "request_handler.h" #include "initialization.h" #include "utils.h" +#include "mac_filter.h" static const char *TAG = "url_handler/get_data_handler"; @@ -185,6 +186,36 @@ esp_err_t save_settings_data_handler(httpd_req_t *req) IsDarkModeEnable = str_to_bool(html_escape(strdup(param_buf))); err = nvs_set_i32(handle, "dark_mode", bool_to_int(IsDarkModeEnable)); } + if (httpd_query_key_value(query_buf, "macFilterEnable", param_buf, sizeof(param_buf)) == ESP_OK) + { + IsMacFilterEnable = str_to_bool(html_escape(strdup(param_buf))); + err = nvs_set_i32(handle, "mac_Filter", bool_to_int(IsMacFilterEnable)); + printf("Commit failed! (%s)\n", esp_err_to_name(err)); + + } + /////////////////// + if (httpd_query_key_value(query_buf, "add_mac_address", param_buf, sizeof(param_buf)) == ESP_OK) + { + store_mac_address_in_nvs(html_escape(strdup(param_buf))); + refresh_mac_filter(); + + } + + if (httpd_query_key_value(query_buf, "remove_mac_address", param_buf, sizeof(param_buf)) == ESP_OK) + { + remove_mac_address_from_nvs(html_escape(strdup(param_buf))); + refresh_mac_filter(); + } + + if (httpd_query_key_value(query_buf, "filter_list_type", param_buf, sizeof(param_buf)) == ESP_OK) + { + IsAllowList = word_check(html_escape(strdup(param_buf)),"Allow"); + err = nvs_set_i32(handle, "Is_allow_list", bool_to_int(IsAllowList)); + refresh_mac_filter(); + } + + +///////////////// valid_query = (err == ESP_OK); diff --git a/components/web_server/www/html/_config.yml b/components/web_server/www/html/_config.yml index b9d29c7..675821f 100644 --- a/components/web_server/www/html/_config.yml +++ b/components/web_server/www/html/_config.yml @@ -22,6 +22,7 @@ sass: jekyll-minifier: + compress_javascript: false exclude: "*.json" uglifier_args: harmony: true diff --git a/components/web_server/www/html/_i18n/english.yml b/components/web_server/www/html/_i18n/english.yml index b012086..ff9f6cd 100644 --- a/components/web_server/www/html/_i18n/english.yml +++ b/components/web_server/www/html/_i18n/english.yml @@ -67,6 +67,7 @@ settings: toggle-1: "Enable dark mode" toggle-2: "Enable LED indicator" toggle-3: "Enable Web server" + toggle-4: "Enable MAC filter" card-2: header: "Admin Settings" field-1: "Username" @@ -113,11 +114,17 @@ info: card-2: header: "Connected Users ($$)" table: - A: "ID" - B: "IP Address" - C: "MAC Adress" + A: "IP Address" + B: "MAC Address" + C: "Add" card-3: header: "Acknowledgements" + card-4: + header: "MAC Filter($$)" + table: + A: "ID" + B: "MAC Address" + C: "Remove" strings: B: "OTA update" C: "upload" @@ -127,8 +134,11 @@ info: messages: message-1: "file uploading Status: $$" message-2: "OTA Update Success - Restarting" + message-3: "Settings have been saved." E0: "ERROR: Failed to load sysinfo.json" - E1: "ERROR: OTA update ERROR" + E1: "ERROR: OTA update ERROR" + E2: "Failed to save settings!" + E3: "ERROR: Failed to save settings!" error: title: "404" diff --git a/components/web_server/www/html/info.html b/components/web_server/www/html/info.html index 232059a..d66a015 100644 --- a/components/web_server/www/html/info.html +++ b/components/web_server/www/html/info.html @@ -34,22 +34,29 @@
+
+
{{site.translations[site.lang].info.card-4.header | replace_first: '$$', + ''}}
+
+
+
+
{% t info.card-3.header %}
@martin-ger(martin-ger)
@samdenty (Sam Denty)
- @kevinwolfe(Kevin Wolfe)
+ @kevinwolfe(Kevin Wolfe)
@nopnop2002
@dchristl
- - + +
-

- This software is based upon the work of martin-ger(ESP32 NAT Router). UI is based on the work of Sam Denty(Wi-PWN).
- +

+ This software is based upon the work of martin-ger(ESP32 NAT Router). UI is based on the work of Sam Denty(Wi-PWN).
+

-
\ No newline at end of file + \ No newline at end of file diff --git a/components/web_server/www/html/js/info.js b/components/web_server/www/html/js/info.js index 7f0bbcb..02c177f 100644 --- a/components/web_server/www/html/js/info.js +++ b/components/web_server/www/html/js/info.js @@ -8,11 +8,15 @@ var versionCell = getE("version"), connection = getE("connection"), connectedUserCount = getE('clientsFound'), connectedUsers = getE('users'), + filterList = getE("filterList"), + filterListCount = getE("filterListCount"), ap_rss = 0, wifiAuthFail, tableHeaderHTML, otaProgress = false, - clients = []; + filterListType, + clients = [], + filterListData = []; function getData() { if (otaProgress) return; @@ -35,9 +39,12 @@ function getData() { wifiAuthFail = res.wifiAuthFail; clients = res.clients; versionCell.innerHTML = version; + filterListData = res.filterList; + filterListType = res.filterListType; fadeIn(); users(); ap_connection(); + filter_list(); }, function () { notify('{% t info.messages.E0 %} (E0)'); @@ -148,8 +155,67 @@ function users() { for (var i = 0; i < clients.length; i++) { var id = i + 1; - tr += '' + id + '' + clients[i].ipAddress + ' ' + clients[i].macAddress + ''; + tr += '' + clients[i].ipAddress + ' ' + clients[i].macAddress + ''; connectedUsers.innerHTML = tr; } } -} \ No newline at end of file +} + + +function filter_list() { + console.log("clients: ", filterListData.length) + filterListCount.innerHTML = filterListData.length; + var tr = ''; + tableHeaderHTML = '{% t info.card-4.table.A %}{% t info.card-4.table.B %}{% t info.card-4.table.C %}'; + tr += tableHeaderHTML; + filterList.innerHTML = tr; + if (filterListData.length > 0) { + + for (var i = 0; i < filterListData.length; i++) { + var id = i + 1; + tr += '' + id + '' + filterListData[i] + ' '; + filterList.innerHTML = tr; + } + } + var IsAllowList = (filterListType === "Allow"); + tr += '' + tr += ''; + tr += ''; + tr += '' + filterList.innerHTML = tr; +} + + +function saveSettings(data) { + var url = '{% if jekyll.environment == "development" %}settingsSave.json{% else %}data/settingsSave.json{% endif %}'; + url += data; + showLoading(); + getResponse(url, function (responseText) { + if (responseText == "true") { + indicate(true); + notify("{% t info.messages.message-3 %} (M3)", 2000); + } else { + indicate(false); + notify("{% t info.messages.E2 %} (E2)"); + } + }, function () { + indicate(false); + notify("{% t info.messages.E3 %} (E3)"); + }, null, "POST"); + } + + +function add_mac_to_filter_list(num){ + var data = "?add_mac_address=" + encodeURI(clients[num].macAddress); + saveSettings(data); +} + +function remove_mac_to_filter_list(num){ + var data = "?remove_mac_address=" + encodeURI(filterListData[num]); + saveSettings(data); +} + +function filter_list_type(){ + var data = "?filter_list_type="+ encodeURI(getE("Allow").checked ? "Allow":"Deny") + saveSettings(data); +} diff --git a/components/web_server/www/html/js/settings.js b/components/web_server/www/html/js/settings.js index a22264e..ab010ad 100644 --- a/components/web_server/www/html/js/settings.js +++ b/components/web_server/www/html/js/settings.js @@ -16,6 +16,7 @@ var ssid = getE('ssid'), darkMode = getE('darkMode'), ledEnable = getE('useLed'), webServer = getE('webServer'), + macFilter = getE('macFilter'), apIP = getE('apIP'), macContainer = getE('macContainer'), dnsIpContainer = getE('dnsIpContainer'), @@ -69,6 +70,7 @@ function getData() { ledEnable.checked = res.ledEnable; darkMode.checked = res.darkMode; webServer.checked = res.webServer; + macFilter.checked = res.macFilterEnabled; adminUsername.value = res.authUsername; adminPassword.value = res.authPassword maxLoginAttempts.value = res.maxLoginAttempts @@ -107,6 +109,7 @@ function saveSettings() { url += "&CustomDns=" + CustomDns.checked; url += "&darkMode=" + darkMode.checked; url += "&webServer=" + webServer.checked; + url += "&macFilterEnable=" + macFilter.checked; getResponse(url, function (responseText) { diff --git a/components/web_server/www/html/main.scss b/components/web_server/www/html/main.scss index ac1851e..c485fd9 100644 --- a/components/web_server/www/html/main.scss +++ b/components/web_server/www/html/main.scss @@ -739,7 +739,7 @@ hr.small { } -/**************************** Buttons & checkboxes ****************************/ +/**************************** Buttons, checkboxes & radio button ****************************/ .button, button, input[type='submit'] { font-size: 14px; font-weight: 500; @@ -985,6 +985,97 @@ label.checkbox:active:before, .checkboxContainer:active label.checkbox:before { line-height: 18px; } + + +.radioContainer { + display: inline-block; + width: 100%; + cursor: pointer; +} + +input[type='radio'] { + display: none; +} + +input[type='radio']:checked + label { + border-color: #6d6d6d; + background: #6d6d6d; +} + +input[type='radio']:checked + label:after { + transform: scale(1.3); +} + +label.radio { + position: relative; + z-index: 1; + display: inline-block; + box-sizing: border-box; + width: 18px; + height: 18px; + cursor: pointer; + transition: 0.2s; + border: 2px solid #6d6d6d; + border-radius: 10%; + background: none; +} + +label.radio:before { + position: absolute; + z-index: 0; + top: 0; + left: 0; + display: block; + width: 200%; + height: 200%; + content: ''; + transition: 0.3s ease; + transform: translate(-27%, -27%); + pointer-events: none; + border-radius: 50%; +} + +label.radio:after { + display: block; + width: 100%; + height: 100%; + content: ''; + transition: 0.1s ease; + transform: scale(0); + background: url(data:image/svg+xml;base64,PHN2ZyBmaWxsPSIjRkZGRkZGIiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiIHdpZHRoPSIyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KICAgIDxwYXRoIGQ9Ik0wIDBoMjR2MjRIMHoiIGZpbGw9Im5vbmUiLz4KICAgIDxwYXRoIGQ9Ik05IDE2LjE3TDQuODMgMTJsLTEuNDIgMS40MUw5IDE5IDIxIDdsLTEuNDEtMS40MXoiLz4KPC9zdmc+) center center no-repeat; + background-size: contain; +} + +label.radio:active:before, +.radioContainer:active label.radio:before { + width: 300%; + height: 300%; + transform: translate(-34%, -34%); + background: rgba(0, 0, 0, 0.15); +} + +/* Additional styles for labels associated with radio buttons */ +.row.inputRadio .radio { + float: left; + margin-right: 10px; +} + +.row.inputRadio label:not(.radio) { + line-height: 18px; +} + +/* Adjustments specific to your layout */ +.row.inputRadio .col-6:nth-child(2) { + margin-top: 26px; +} + +.row.inputRadio .col-6:nth-child(2) { + margin-bottom: 20px; +} + + + + /*********************************** Footer ***********************************/ footer { height: 120px; diff --git a/components/web_server/www/html/settings.html b/components/web_server/www/html/settings.html index f77dce0..0ed4d76 100644 --- a/components/web_server/www/html/settings.html +++ b/components/web_server/www/html/settings.html @@ -29,6 +29,12 @@ +
+ +
diff --git a/components/web_server/www/html/sysinfo.json b/components/web_server/www/html/sysinfo.json index f711777..a5fe82c 100644 --- a/components/web_server/www/html/sysinfo.json +++ b/components/web_server/www/html/sysinfo.json @@ -1,7 +1,7 @@ { "ipAddress": "192.168.1.128", "dns": "192.168.1.1", - "rss": -70, + "rss": -70, "wifiAuthFail" : false, "clients": [ { @@ -16,5 +16,11 @@ "ipAddress": "192.168.4.2", "macAddress": "4c:bb:58:f0:94:de" } - ] + ], + "filterList": [ + "4c:bb:58:f0:94:de", + "4c:bb:58:f0:94:de", + "4c:bb:58:f0:94:de" + ], + "filterListType": "Allow" } diff --git a/components/web_server/www/output/gzip/functions.js.gz b/components/web_server/www/output/gzip/functions.js.gz index 6dc5db9..0944646 100644 Binary files a/components/web_server/www/output/gzip/functions.js.gz and b/components/web_server/www/output/gzip/functions.js.gz differ diff --git a/components/web_server/www/output/gzip/info.html.gz b/components/web_server/www/output/gzip/info.html.gz index fc50af7..80c5341 100644 Binary files a/components/web_server/www/output/gzip/info.html.gz and b/components/web_server/www/output/gzip/info.html.gz differ diff --git a/components/web_server/www/output/gzip/info.js.gz b/components/web_server/www/output/gzip/info.js.gz index 72ad7e3..fe68dbc 100644 Binary files a/components/web_server/www/output/gzip/info.js.gz and b/components/web_server/www/output/gzip/info.js.gz differ diff --git a/components/web_server/www/output/gzip/main.css.gz b/components/web_server/www/output/gzip/main.css.gz index 4a4344b..cc76aa1 100644 Binary files a/components/web_server/www/output/gzip/main.css.gz and b/components/web_server/www/output/gzip/main.css.gz differ diff --git a/components/web_server/www/output/gzip/settings.html.gz b/components/web_server/www/output/gzip/settings.html.gz index 4abe0e9..efb3a9b 100644 Binary files a/components/web_server/www/output/gzip/settings.html.gz and b/components/web_server/www/output/gzip/settings.html.gz differ diff --git a/components/web_server/www/output/gzip/settings.js.gz b/components/web_server/www/output/gzip/settings.js.gz index 93ce338..fcc4246 100644 Binary files a/components/web_server/www/output/gzip/settings.js.gz and b/components/web_server/www/output/gzip/settings.js.gz differ diff --git a/components/wifi_handler/wifi_event_handler.c b/components/wifi_handler/wifi_event_handler.c index a57fa1a..d48cc26 100644 --- a/components/wifi_handler/wifi_event_handler.c +++ b/components/wifi_handler/wifi_event_handler.c @@ -25,6 +25,7 @@ #include "wifi_event_handler.h" #include "router_handler.h" #include "wifi_handler.h" +#include "mac_filter.h" static const char *TAG = "wifi_event_handler"; EventGroupHandle_t wifi_event_group; @@ -124,6 +125,9 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base, } else if (WIFI_EVENT == event_base && WIFI_EVENT_AP_STACONNECTED == event_id) { + + wifi_event_ap_staconnected_t *event = (wifi_event_ap_staconnected_t *)event_data; + mac_filter(event->mac, event->aid); connect_count++; ESP_LOGI(TAG, "%d. station connected", connect_count); } diff --git a/components/wifi_handler/wifi_handler.c b/components/wifi_handler/wifi_handler.c index e4c8c4c..453dc2f 100644 --- a/components/wifi_handler/wifi_handler.c +++ b/components/wifi_handler/wifi_handler.c @@ -16,6 +16,7 @@ #include "initialization.h" #include "wifi_handler.h" #include "wifi_event_handler.h" +#include "mac_filter.h" bool is_scanning_progress = false; //----------------------------------------------------------------------------- @@ -125,9 +126,12 @@ char* IRAM_ATTR wifi_info_handler(void) cJSON_AddStringToObject(root, "gatewayAddress", gateway_address); cJSON_AddStringToObject(root, "ipAddress", ip_address); cJSON_AddStringToObject(root, "dns", (has_static_ip || IsCustomDnsEnable) ? customDNSip : dns); + cJSON_AddStringToObject(root, "filterListType", (IsAllowList ? "Allow":"Deny")); cJSON_AddNumberToObject(root, "rss", rssi); cJSON_AddBoolToObject(root, "wifiAuthFail", IsWifiAuthFail); cJSON *clients = cJSON_AddArrayToObject(root, "clients"); + cJSON *json = retrieve_mac_addresses_as_json(); + for (int i = 0; i < adapter_sta_list.num; i++) { tcpip_adapter_sta_info_t station = adapter_sta_list.sta[i]; @@ -137,6 +141,10 @@ char* IRAM_ATTR wifi_info_handler(void) sprintf(mac_address, MACSTR, MAC2STR(station.mac)); cJSON_AddStringToObject(client, "macAddress", mac_address); cJSON_AddItemToArray(clients, client); + + } + if(json != NULL){ + cJSON_AddItemToObject(root,"filterList",json); } char *my_json_string = cJSON_Print(root); cJSON_Delete(root); diff --git a/docs/Advanced_topics.md b/docs/Advanced_topics.md index d04c770..bc837d9 100644 --- a/docs/Advanced_topics.md +++ b/docs/Advanced_topics.md @@ -68,6 +68,7 @@ They are several settings are provided to manage router insections : - Enable LED indicator: Enables or disables the onboard LED - Enable web server: Enables the web interface to access settings and other features. +- Enable MAC filter: Enables the MAC filter features. #### AP Sertings : The AP settings refer to the configuration of the access point. - SSID: diff --git a/platformio.ini b/platformio.ini index 07e210c..28bf39b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,7 +10,7 @@ [extra_script_settings] -version = 1.1.4 ; Set the version to the project +version = 1.2.0 ; Set the version to the project merge_to_single_bin = 1 ; (0 = disable) Enable the conversion of a multiple bins to single bin file of 0x0 format