diff --git a/src/rest/api/api_network.lua b/src/rest/api/api_network.lua index 2c4992a..e265a5d 100644 --- a/src/rest/api/api_network.lua +++ b/src/rest/api/api_network.lua @@ -218,4 +218,18 @@ function M.alive(request, response) response:setSuccess("alive") end +function M.reset(request, response) + response:setSuccess("Resetting networks") + + log:info(MOD_ABBR, "Resetting networks") + for _, net in ipairs(wifi.getConfigs()) do + print(net.ssid) + wifi.removeConfig(net.ssid) + end + + local ssid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid')) + netconf.setupAccessPoint(ssid) + netconf.enableAccessPoint(ssid) +end + return M diff --git a/src/script/wifi-switch-netconfig.sh b/src/script/wifi-switch-netconfig.sh index 78f72b6..a516308 100755 --- a/src/script/wifi-switch-netconfig.sh +++ b/src/script/wifi-switch-netconfig.sh @@ -4,60 +4,9 @@ . /lib/functions.sh -count_networks() { - local config="$1" - logger $config - count=$((count + 1)) - # run commands for every interface section -} -find_network() { - local config="$1" - succes=false - #logger $(uci get wireless.$config.ssid) - network_name=$(uci get wireless.$config.ssid) - if [ ${network_name:0:8} != "Doodle3D" ] - then - logger "deleting network $network_name" - uci delete wireless.$config - else - $succes=true - logger "enabled $network_name" - uci set wireless.$config.disabled=0 - fi -} - logger "$BUTTON pressed for $SEEN seconds" if [ "$SEEN" -gt 4 ] then - #count number of networks - config_load wireless - config_foreach count_networks wifi-iface - logger $count - #if number of networks is less than 1 (or 1) do nothing - if [ $count -gt 1 ] - then - logger "switching to AP" - config_foreach find_network wifi-iface - if [ $succes != false ] - then - logger "wireless somehow not found" - fi - #configure dhcp - uci delete network.wlan - uci set network.wlan=interface - uci set network.wlan.netmask=$(uci get wifibox.general.network_ap_netmask) - uci set network.wlan.proto=static - uci set network.wlan.ipaddr=$(uci get wifibox.general.network_ap_address) - - uci set dhcp.wlan=dhcp - uci set dhcp.wlan.start=100 - uci set dhcp.wlan.leasetime=12h - uci set dhcp.wlan.limit=150 - uci set dhcp.wlan.interface=wlan - - uci commit #commit changes - /etc/init.d/network reload #reload network module so changes become effective - logger "setting status flag in /tmp/networkstatus.txt" - echo "4|" > /tmp/networkstatus.txt - fi + logger "Resetting Wireless" + /usr/share/lua/wifibox/script/d3dapi p=/network/reset r=GET fi