From 5378a141ee8d112457f32da8fd962aacec8ec264 Mon Sep 17 00:00:00 2001 From: taamarin <71506581+taamarin@users.noreply.github.com> Date: Thu, 21 Aug 2025 13:04:16 +0700 Subject: [PATCH] fix(network-switch): improve WiFi SSID list handling - Changed log file path from Networkswitch_debug.log to netswitch.log - Updated WiFi SSID check to properly handle array values from settings.ini - Modified is_allowed_wifi to accept array arguments instead of comma-separated strings - Adjusted calls to is_allowed_wifi in ctr.inotify to pass array correctly --- box/scripts/ctr.inotify | 10 +++++----- box/scripts/ctr.utils | 18 +++++++++++------- box/settings.ini | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/box/scripts/ctr.inotify b/box/scripts/ctr.inotify index 96c43b3..118fcfe 100755 --- a/box/scripts/ctr.inotify +++ b/box/scripts/ctr.inotify @@ -10,7 +10,7 @@ export PATH="/data/adb/magisk:/data/adb/ksu/bin:/data/adb/ap/bin:$PATH:/data/dat module_dir="/data/adb/modules/box_for_root" base_dir="/data/adb/box" variab_dir="${base_dir}/run/variab" -log_file="${base_dir}/run/Networkswitch_debug.log" +log_file="${base_dir}/run/netswitch.log" log_file_path="/data/local/tmp/" temp_log_file="${log_file_path}debug.log.tmp" last_check_file="${variab_dir}/last_check_time" @@ -131,8 +131,8 @@ check_module_service() { else if [ "$use_ssid_matching" = "true" ]; then if [ "$use_wifi_list_mode" = "blacklist" ]; then - log_msg "Policy: WiFi blacklist mode, list: ${wifi_ssids_list}" - if is_allowed_wifi "$ssid" "$wifi_ssids_list"; then + log_msg "Policy: WiFi blacklist mode, list: ${wifi_ssids_list[*]}" + if is_allowed_wifi "$ssid" "${wifi_ssids_list[@]}"; then log_msg "Result: ${ssid} is in blacklist" if [ "$current_state" != "disabled" ]; then "$iptables_script" disable @@ -152,8 +152,8 @@ check_module_service() { fi fi elif [ "$use_wifi_list_mode" = "whitelist" ]; then - log_msg "Policy: WiFi whitelist mode, list: ${wifi_ssids_list}" - if is_allowed_wifi "$ssid" "$wifi_ssids_list"; then + log_msg "Policy: WiFi whitelist mode, list: ${wifi_ssids_list[*]}" + if is_allowed_wifi "$ssid" "${wifi_ssids_list[@]}"; then log_msg "Result: ${ssid} is in whitelist" if [ "$current_state" != "enabled" ]; then "$service_script" start diff --git a/box/scripts/ctr.utils b/box/scripts/ctr.utils index 1d8aad0..9ebded3 100755 --- a/box/scripts/ctr.utils +++ b/box/scripts/ctr.utils @@ -23,12 +23,16 @@ is_wifi_connected() { echo "not_wifi" fi } + +# Definisi array di settings.ini is_allowed_wifi() { local ssid=$1 - local allowed_ssids=$2 - if echo " $allowed_ssids " | tr ',' ' ' | grep -q " $ssid "; then - return 0 - else - return 1 - fi -} \ No newline at end of file + shift + local allowed_list=("$@") + for allowed in "${allowed_list[@]}"; do + if [ "$ssid" = "$allowed" ]; then + return 0 + fi + done + return 1 +} diff --git a/box/settings.ini b/box/settings.ini index 96d7bb0..7e0143a 100755 --- a/box/settings.ini +++ b/box/settings.ini @@ -198,7 +198,7 @@ use_ssid_matching=false use_wifi_list_mode="blacklist" # Wi-Fi SSID list to match (multiple SSIDs separated by spaces or commas) -wifi_ssids_list="WiFi1 WiFi2" +wifi_ssids_list=("WiFi1" "WiFi-2" "WiFi 3") # Enable inotify debug logging for network switching inotify_log_enabled="true"