#!/bin/ash # Function to display menu options with color coding menu() { echo -e "\e[96mLAN Configuration Menu:\e[0m" # Cyan echo -e "\e[92m1) Enable/Disable Single IP DMZ Passthrough Mode\e[0m" # Green echo -e "\e[94m2) Set Gateway Address\e[0m" # Blue echo -e "\e[93m3) Set DHCP Start/Limit Range\e[0m" # Yellow echo -e "\e[96m4) Set Custom DNS\e[0m" # Cyan echo -e "\e[95m5) Use Provider's DNS (IPv4 only)\e[0m" # Magenta echo -e "\e[92m6) Enable/Disable IP Passthrough with NAT (Access to modem's LAN locally)\e[0m" # Green echo -e "\e[91m7) Exit\e[0m" # Red echo "" read -p "Select an option [1-7]: " choice } # Apply changes and restart services apply_changes() { uci commit network uci commit dhcp /etc/init.d/network restart /etc/init.d/dnsmasq restart echo -e "\e[92mChanges applied successfully.\e[0m" # Green } # Function to check if IPPT is enabled by inspecting the MPDN rules is_ippt_enabled() { local mpdn_output=$(atcmd 'AT+QMAP="mpdn_rule"') echo "$mpdn_output" # Check if any MPDN rule has IPPT enabled (non-zero second-to-last value) if echo "$mpdn_output" | grep -q "+QMAP: \"MPDN_rule\",.*,.*,.*,[1-9],.*"; then return 0 # IPPT is enabled else return 1 # IPPT is not enabled fi } # Function to check if MPDN rules are clear are_mpdn_rules_clear() { local mpdn_output=$(atcmd 'AT+QMAP="mpdn_rule"') echo "$mpdn_output" # Check if all MPDN rules are clear (all values are 0) if echo "$mpdn_output" | grep -q "+QMAP: \"MPDN_rule\",0,0,0,0,0"; then return 0 # MPDN rules are clear else return 1 # MPDN rules are not clear fi } # Function to check DMZ status using the AT+QMAP command is_dmz_enabled() { local lan_ip=$(uci get network.lan.ipaddr) local expected_dmz_ip=$(echo "$lan_ip" | awk -F. '{print $1"."$2"."$3"."$4+1}') local dhcp_start=$(uci get dhcp.lan.start) local dhcp_limit=$(uci get dhcp.lan.limit) # Check if DHCP start and limit are the same if [ "$dhcp_start" = "$dhcp_limit" ]; then # Get the DMZ status from the AT command local dmz_status=$(atcmd 'AT+QMAP="DMZ"') echo "$dmz_status" # Check if DMZ is enabled for IPv4 (1,4 means IPv4 DMZ is enabled) if echo "$dmz_status" | grep -q "\+QMAP: \"DMZ\",1,4,$expected_dmz_ip"; then return 0 # DMZ is enabled else return 1 # DMZ is disabled fi else return 1 # DMZ is disabled if start and limit are not the same fi } # Function to enable or disable IP Passthrough with NAT toggle_ippt_mode() { is_ippt_enabled ippt_status=$? if [ "$ippt_status" -eq 0 ]; then echo -e "\e[93mIP Passthrough is currently ENABLED. Would you like to DISABLE it? (y/n)\e[0m" # Yellow read -r disable_ippt if [ "$disable_ippt" = "y" ]; then are_mpdn_rules_clear mpdn_clear_status=$? if [ "$mpdn_clear_status" -ne 0 ]; then atcmd 'AT+QMAP="mpdn_rule",0' # Clear MPDN rule fi atcmd 'AT+QMAP="mpdn_rule",0,1,0,0,1' # Disable IPPT echo -e "\e[92mIP Passthrough disabled.\e[0m" # Green else echo -e "\e[93mIP Passthrough remains enabled.\e[0m" # Yellow fi else echo -e "\e[93mIP Passthrough is currently DISABLED. Would you like to ENABLE it? (y/n)\e[0m" # Yellow read -r enable_ippt if [ "$enable_ippt" = "y" ]; then local arp_output=$(arp -n) local device_count=0 local device_list="" while IFS= read -r line; do if echo "$line" | grep -q "br-lan"; then device_count=$((device_count + 1)) mac=$(echo "$line" | awk '{print $4}') ip=$(echo "$line" | awk '{print $2}' | tr -d '()') echo "$device_count) $mac current IP $ip" device_list="$device_list $device_count $mac" fi done </dev/null || echo "Not set") CURRENT_START=$(uci get dhcp.$interface.start 2>/dev/null || echo "Not set") CURRENT_LIMIT=$(uci get dhcp.$interface.limit 2>/dev/null || echo "Not set") CURRENT_DNS=$(uci get dhcp.$interface.dhcp_option | grep -oE '6,.*' | cut -d, -f2-) } # Main menu loop while true; do menu case $choice in 1) toggle_dmz_mode ;; 2) set_gateway ;; 3) set_dhcp_range ;; 4) toggle_custom_dns ;; 5) set_provider_dns ;; 6) toggle_ippt_mode ;; 7) echo -e "\e[92mGoodbye!\e[0m"; exit 0 ;; # Green *) echo -e "\e[91mInvalid option. Please try again.\e[0m" ;; # Red esac done