From 02799a635934bf07a39e3ce2a07f87810105caf9 Mon Sep 17 00:00:00 2001 From: Jason Hawks Date: Wed, 15 Nov 2023 12:50:13 -0500 Subject: [PATCH] First pass fixing set apmode --- luasrc/model/cbi/easymesh.lua | 6 +- root/easymesh/dumbap.sh | 107 --------------------------------- root/easymesh/easymesh.sh | 110 ++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 110 deletions(-) delete mode 100755 root/easymesh/dumbap.sh diff --git a/luasrc/model/cbi/easymesh.lua b/luasrc/model/cbi/easymesh.lua index 2af730a..92f954e 100755 --- a/luasrc/model/cbi/easymesh.lua +++ b/luasrc/model/cbi/easymesh.lua @@ -206,7 +206,7 @@ o:depends("role", "off") btnAPMode = s:taboption("apmode", Button, "_btn_apmode", translate("Join Mesh Network"), translate("WARNING: THIS WILL CHANGE THIS NODE'S IP ADDRESS, YOU WILL LOOSE ACCESS TO THIS UI")) function btnAPMode.write() - luci.sys.call("bash /easymesh/dumbap.sh") + io.popen("/easymesh/easymesh.sh dumbap &") end btnAPMode:depends("role", "off") ---- ip address @@ -234,9 +234,9 @@ ctrl.addremove = false function m.on_after_commit(self) local enabled = m:formvalue("cbid.easymesh.easymesh.enabled") if enabled and enabled == "1" then - luci.sys.call("bash /easymesh/easymesh.sh start &") + luci.sys.call("/easymesh/easymesh.sh &") else - luci.sys.call("bash /easymesh/easymesh.sh stop &") + luci.sys.call("/easymesh/easymesh.sh &") end end diff --git a/root/easymesh/dumbap.sh b/root/easymesh/dumbap.sh deleted file mode 100755 index e70f3cf..0000000 --- a/root/easymesh/dumbap.sh +++ /dev/null @@ -1,107 +0,0 @@ -#!/bin/bash - -set_apmode() { - AP_MODE=$(uci -q get easymesh.config.ap_mode) - if [ "$AP_MODE" = 1 ]; then - # Set a flag to indicate that we are in AP mode - # When we go to disable easymesh, we will check this flag and if it was set we restore settings - uci set easymesh.config.ap_mode_enabled=1 - - # Backup our configs - rm /etc/config/*.meshbak - cp /etc/config/wireless /etc/config/wireless.meshbak - cp /etc/config/network /etc/config/network.meshbak - cp /etc/config/dhcp /etc/config/dhcp.meshbak - - # Disabling and stopping services not needed - for service in firewall dnsmasq odhcpd; do - if /etc/init.d/$service enabled; then - echo "Disabling and stopping $service..." - /etc/init.d/$service disable - /etc/init.d/$service stop - else - echo "$service is not enabled, skipping..." - fi - done - - # Set LAN interface to DHCP client - uci del network.lan.ipaddr - uci del network.lan.netmask - uci set network.lan.proto='dhcp' - uci del network.wan - uci del network.wan6 - - # Fix firewall to be disabled - uci del firewall.lan.network - uci del firewall.wan.network - - # Fix dhcp to be disabled - uci set dhcp.lan.ignore='1' - uci del dhcp.wan - - # Fix this for proper variable name - HOSTNAME=$(uci -q get easymesh.config.hostname) - # Set netmask and gateway (assuming $netmask and $dns didn't break more stuff) - uci set system.@system[0].hostname=$HOSTNAME - - # Retrieve the list of ports for network.@device[0] - LAN_PORTS=$(uci get network.@device[0].ports) - - # Check if 'wan' is already in the list of ports - if echo "$LAN_PORTS" | grep -q -w 'wan'; then - echo "'wan' is already in the list of ports for lan." - else - echo "'wan' is not in the list. Adding it to lan ports..." - uci add_list network.@device[0].ports='wan' - fi - - # Get the radio to be used for mesh from the config - AP_RADIO=$(uci -q get easymesh.config.apRadio) - - # # Loop through the selected radios - # for CURRENT_RADIO in $AP_RADIO; do - # echo "Multiple Radio Setup, Current Radio: $CURRENT_RADIO" - # # Extact the radio number from the radio name - # wifi_num="${cur_radio#CURRENT_RADIO}" - # uci set wireless.wifinet${wifi_num}.network="lan private_router_batman" - # done - - uci commit - # Tell openwrt to reload the configs - reload_config - /etc/init.d/network reload - else - # Set a flag to indicate that we are in AP mode - uci set easymesh.config.ap_mode_enabled=0 - - # Restore our configs - [ -f /etc/config/wireless.meshbak ] && { - mv /etc/config/wireless /etc/config/wireless.dumbap - cp /etc/config/wireless.meshbak /etc/config/wireless - } - [ -f /etc/config/network.meshbak ] && { - mv /etc/config/network /etc/config/network.dumbap - cp /etc/config/network.meshbak /etc/config/network - } - [ -f /etc/config/dhcp.meshbak ] && { - mv /etc/config/dhcp /etc/config/dhcp.dumbap - cp /etc/config/dhcp.meshbak /etc/config/dhcp - } - - # Enable and start services not needed - for service in firewall dnsmasq odhcpd; do - if /etc/init.d/$service disabled; then - echo "Enabling and starting $service..." - /etc/init.d/$service enable - /etc/init.d/$service start - else - echo "$service is not disabled, skipping..." - fi - done - - reload_config - /etc/init.d/network reload - fi -} - -set_apmode \ No newline at end of file diff --git a/root/easymesh/easymesh.sh b/root/easymesh/easymesh.sh index d1e2454..3569e36 100644 --- a/root/easymesh/easymesh.sh +++ b/root/easymesh/easymesh.sh @@ -1,5 +1,110 @@ #!/bin/bash +# Dumb AP Mode Block +set_apmode() { + AP_MODE=$(uci -q get easymesh.config.ap_mode) + if [ "$AP_MODE" = 1 ]; then + # Set a flag to indicate that we are in AP mode + # When we go to disable easymesh, we will check this flag and if it was set we restore settings + uci set easymesh.config.ap_mode_enabled=1 + + # Backup our configs + rm /etc/config/*.meshbak + cp /etc/config/wireless /etc/config/wireless.meshbak + cp /etc/config/network /etc/config/network.meshbak + cp /etc/config/dhcp /etc/config/dhcp.meshbak + + # Disabling and stopping services not needed + for service in firewall dnsmasq odhcpd; do + if /etc/init.d/$service enabled; then + echo "Disabling and stopping $service..." + /etc/init.d/$service disable + /etc/init.d/$service stop + else + echo "$service is not enabled, skipping..." + fi + done + + # Set LAN interface to DHCP client + uci del network.lan.ipaddr + uci del network.lan.netmask + uci set network.lan.proto='dhcp' + uci del network.wan + uci del network.wan6 + + # Fix firewall to be disabled + uci del firewall.lan.network + uci del firewall.wan.network + + # Fix dhcp to be disabled + uci set dhcp.lan.ignore='1' + uci del dhcp.wan + + # Fix this for proper variable name + HOSTNAME=$(uci -q get easymesh.config.hostname) + # Set netmask and gateway (assuming $netmask and $dns didn't break more stuff) + uci set system.@system[0].hostname=$HOSTNAME + + # Retrieve the list of ports for network.@device[0] + LAN_PORTS=$(uci get network.@device[0].ports) + + # Check if 'wan' is already in the list of ports + if echo "$LAN_PORTS" | grep -q -w 'wan'; then + echo "'wan' is already in the list of ports for lan." + else + echo "'wan' is not in the list. Adding it to lan ports..." + uci add_list network.@device[0].ports='wan' + fi + + # Get the radio to be used for mesh from the config + AP_RADIO=$(uci -q get easymesh.config.apRadio) + + # # Loop through the selected radios + # for CURRENT_RADIO in $AP_RADIO; do + # echo "Multiple Radio Setup, Current Radio: $CURRENT_RADIO" + # # Extact the radio number from the radio name + # wifi_num="${cur_radio#CURRENT_RADIO}" + # uci set wireless.wifinet${wifi_num}.network="lan private_router_batman" + # done + + uci commit + # Tell openwrt to reload the configs + reload_config + /etc/init.d/network reload + else + # Set a flag to indicate that we are in AP mode + uci set easymesh.config.ap_mode_enabled=0 + + # Restore our configs + [ -f /etc/config/wireless.meshbak ] && { + mv /etc/config/wireless /etc/config/wireless.dumbap + cp /etc/config/wireless.meshbak /etc/config/wireless + } + [ -f /etc/config/network.meshbak ] && { + mv /etc/config/network /etc/config/network.dumbap + cp /etc/config/network.meshbak /etc/config/network + } + [ -f /etc/config/dhcp.meshbak ] && { + mv /etc/config/dhcp /etc/config/dhcp.dumbap + cp /etc/config/dhcp.meshbak /etc/config/dhcp + } + + # Enable and start services not needed + for service in firewall dnsmasq odhcpd; do + if /etc/init.d/$service disabled; then + echo "Enabling and starting $service..." + /etc/init.d/$service enable + /etc/init.d/$service start + else + echo "$service is not disabled, skipping..." + fi + done + + reload_config + /etc/init.d/network reload + fi +} + clear_mesh_radio() { # Get the radio to be used for mesh from the config AP_RADIO=$(uci -q get easymesh.config.apRadio) @@ -304,6 +409,11 @@ disable_easymesh() { uci del easymesh.config.running } +if [ "$1" = "dumbap" ]; then + set_apmode + exit 0 +fi + # Check if enabled if [ "$(uci -q get easymesh.config.enabled)" = 1 ]; then enable_easymesh