From 398bb2583c00648ebb64e6eca8ab55bac7fa918d Mon Sep 17 00:00:00 2001 From: SirPdboy <63764630+sirpdboy@users.noreply.github.com> Date: Sun, 25 Jun 2023 14:48:15 +0800 Subject: [PATCH] Update netwizard 1.8.3 --- luasrc/controller/netwizard.lua | 1 - luasrc/model/cbi/netwizard/netwizard.lua | 80 +++-- po/zh-cn/netwizard.po | 16 +- root/etc/config/netwizard | 7 + root/etc/init.d/netwizard | 277 ++++++++++++++++++ root/etc/uci-defaults/luci-netwizard | 12 + root/etc/uci-defaults/luci-netwizard-defaults | 14 + 7 files changed, 352 insertions(+), 55 deletions(-) create mode 100644 root/etc/config/netwizard create mode 100644 root/etc/init.d/netwizard create mode 100644 root/etc/uci-defaults/luci-netwizard create mode 100644 root/etc/uci-defaults/luci-netwizard-defaults diff --git a/luasrc/controller/netwizard.lua b/luasrc/controller/netwizard.lua index 1e208bf..bd71d45 100644 --- a/luasrc/controller/netwizard.lua +++ b/luasrc/controller/netwizard.lua @@ -12,7 +12,6 @@ function index() if not nixio.fs.access("/etc/config/netwizard_hide") then e = entry({"admin","system", "netwizard"}, alias("admin","system", "netwizard","settings"), _("Inital Setup"), -1) e.dependent = true - -- e.acl_depends = { "luci-app-netwizard" } end entry({"admin","system", "netwizard","settings"}, cbi("netwizard/netwizard"), _("Inital Setup"), 1).dependent = true end diff --git a/luasrc/model/cbi/netwizard/netwizard.lua b/luasrc/model/cbi/netwizard/netwizard.lua index 8dfdabf..37f1f45 100644 --- a/luasrc/model/cbi/netwizard/netwizard.lua +++ b/luasrc/model/cbi/netwizard/netwizard.lua @@ -10,11 +10,14 @@ local lan_gateway = uci:get("netwizard", "default", "lan_gateway") if lan_gateway ~= "" then lan_gateway = sys.exec("ipaddr=`uci -q get network.lan.ipaddr`;echo ${ipaddr%.*}") end -local network_info = uci:get_all("network", "wan") -local wizard_info = uci:get_all("netwizard", "default") - +local lan_ip = uci:get("network", "lan", "ipaddr") +local lan_dhcp = uci:get("dhcp", "lan", "ignore") +local wan_face = sys.exec(" [ `uci -q get network.wan.ifname` ] && uci -q get network.wan.ifname || uci -q get network.wan.device ") +local wanproto = uci:get("netwizard", "default", "wan_proto") +if wanproto == "" then + wanproto = sys.exec("uci -q get network.wan.proto || echo 'siderouter'") +end local validation = require "luci.cbi.datatypes" - local has_wifi = false uci:foreach("wireless", "wifi-device", function(s) @@ -35,7 +38,7 @@ end s:tab("othersetup", translate("Other setting")) local e = s:taboption("wansetup", Value, "lan_ipaddr", translate("Lan IPv4 address") ,translate("You must specify the IP address of this machine, which is the IP address of the web access route")) -e.default = "" .. uci:get("network", "lan", "ipaddr") +e.default = lan_ip e.datatype = "ip4addr" e = s:taboption("wansetup", Value, "lan_netmask", translate("Lan IPv4 netmask")) @@ -45,26 +48,27 @@ e:value("255.255.0.0") e:value("255.0.0.0") e.default = '255.255.255.0' -e = s:taboption("wansetup", ListValue, "ipv6",translate('Select IPv6 mode'),translate("Caution: If you delete IPV6 related plug-ins completely, you will not be able to recover")) +e = s:taboption("wansetup", ListValue, "ipv6",translate('Select IPv6 mode'),translate("Default to use IPV6 hybrid mode")) e:value('0', translate('Disable IPv6')) e:value('1', translate('IPv6 Server mode')) e:value('2', translate('IPv6 Relay mode')) e:value('3', translate('IPv6 Hybird mode')) -e:value('4', translate('Remove IPv6')) e.default = '3' wan_proto = s:taboption("wansetup", ListValue, "wan_proto", translate("Network protocol mode selection"), translate("Four different ways to access the Internet, please choose according to your own situation.
")) +wan_proto.default = wanproto wan_proto:value("dhcp", translate("DHCP client")) wan_proto:value("static", translate("Static address")) wan_proto:value("pppoe", translate("PPPoE dialing")) wan_proto:value("siderouter", translate("SideRouter")) -e = s:taboption("wansetup",Value, "wan_interface",translate("interface(*)"), translate("Allocate the physical interface of WAN port")) -e:depends({wan_proto="pppoe"}) -e:depends({wan_proto="dhcp"}) -e:depends({wan_proto="static"}) +wan_interface = s:taboption("wansetup",Value, "wan_interface",translate("interface(*)"), translate("Allocate the physical interface of WAN port")) +wan_interface:depends({wan_proto="pppoe"}) +wan_interface:depends({wan_proto="dhcp"}) +wan_interface:depends({wan_proto="static"}) + for _, iface in ipairs(ifaces) do -if not (iface:match("_ifb$") or iface:match("^ifb*")) then + if not (iface:match("_ifb$") or iface:match("^ifb*")) then if ( iface:match("^eth*") or iface:match("^wlan*") or iface:match("^usb*")) then local nets = net:get_interface(iface) nets = nets and nets:get_networks() or {} @@ -72,31 +76,22 @@ if not (iface:match("_ifb$") or iface:match("^ifb*")) then nets[k] = nets[k].sid end nets = table.concat(nets, ",") - e:value(iface, ((#nets > 0) and "%s (%s)" % {iface, nets} or iface)) + wan_interface:value(iface, ((#nets > 0) and "%s (%s)" % {iface, nets} or iface)) end + end end -end +wan_interface.default = wan_face wan_pppoe_user = s:taboption("wansetup", Value, "wan_pppoe_user", translate("PAP/CHAP username")) wan_pppoe_user:depends({wan_proto="pppoe"}) -if wizard_info.wan_pppoe_user == "" and network_info.username ~= "" then - wan_pppoe_user.default = network_info.username -end - wan_pppoe_pass = s:taboption("wansetup", Value, "wan_pppoe_pass", translate("PAP/CHAP password")) wan_pppoe_pass:depends({wan_proto="pppoe"}) -if wizard_info.wan_pppoe_pass == "" and network_info.password ~= "" then - wan_pppoe_pass.default = network_info.password -end -e.password = true +wan_pppoe_pass.password = true wan_ipaddr = s:taboption("wansetup", Value, "wan_ipaddr", translate("Wan IPv4 address")) wan_ipaddr:depends({wan_proto="static"}) wan_ipaddr.datatype = "ip4addr" -if wizard_info.wan_ipaddr == "" and network_info.ipaddr ~= "" then - wan_ipaddr.default = network_info.ipaddr -end wan_netmask = s:taboption("wansetup", Value, "wan_netmask", translate("Wan IPv4 netmask")) wan_netmask:depends({wan_proto="static"}) @@ -106,14 +101,9 @@ wan_netmask:value("255.255.0.0") wan_netmask:value("255.0.0.0") wan_netmask.default = "255.255.255.0" - - wan_gateway = s:taboption("wansetup", Value, "wan_gateway", translate("Wan IPv4 gateway")) wan_gateway:depends({wan_proto="static"}) wan_gateway.datatype = "ip4addr" -if wizard_info.wan_gateway == "" and network_info.gateway ~= "" then - wan_gateway.default = network_info.gateway -end wan_dns = s:taboption("wansetup", DynamicList, "wan_dns", translate("Use custom Wan DNS")) wan_dns:value("223.5.5.5", translate("Ali DNS:223.5.5.5")) @@ -125,31 +115,29 @@ wan_dns.default = "223.5.5.5" wan_dns:depends({wan_proto="static"}) wan_dns:depends({wan_proto="pppoe"}) wan_dns.datatype = "ip4addr" -wan_dns.cast = "string" e = s:taboption("wansetup", Value, "lan_gateway", translate("Lan IPv4 gateway"), translate( "Please enter the main routing IP address. The bypass gateway is not the same as the login IP of this bypass WEB and is in the same network segment")) e.default = lan_gateway e:depends({wan_proto = "siderouter"}) e.datatype = "ip4addr" -e = s:taboption("wansetup", DynamicList, "lan_dns", translate("Use custom Siderouter DNS")) -e:value("223.5.5.5", translate("Ali DNS:223.5.5.5")) -e:value("180.76.76.76", translate("Baidu dns:180.76.76.76")) -e:value("114.114.114.114", translate("114 DNS:114.114.114.114")) -e:value("8.8.8.8", translate("Google DNS:8.8.8.8")) -e:value("1.1.1.1", translate("Cloudflare DNS:1.1.1.1")) -e.default = "223.5.5.5" -e:depends({wan_proto="siderouter"}) -e.datatype = "ip4addr" -e.cast = "string" - -lan_dhcp = s:taboption("wansetup", Flag, "lan_dhcp", translate("Enable DHCP Server"), translate("The default selection is to enable the DHCP server. In a network, only one DHCP server is needed to allocate and manage client IP. If it is a side route, it is recommended to turn off the main routing DHCP server.")) -lan_dhcp.default = 1 +lan_dns = s:taboption("wansetup", DynamicList, "lan_dns", translate("Use custom Siderouter DNS")) +lan_dns:value("223.5.5.5", translate("Ali DNS:223.5.5.5")) +lan_dns:value("180.76.76.76", translate("Baidu dns:180.76.76.76")) +lan_dns:value("114.114.114.114", translate("114 DNS:114.114.114.114")) +lan_dns:value("8.8.8.8", translate("Google DNS:8.8.8.8")) +lan_dns:value("1.1.1.1", translate("Cloudflare DNS:1.1.1.1")) +lan_dns:depends({wan_proto="siderouter"}) +lan_dns.datatype = "ip4addr" +lan_dns.default = "223.5.5.5" + +lan_dhcp = s:taboption("wansetup", Flag, "lan_dhcp", translate("Disable DHCP Server"), translate("Selecting means that the DHCP server is not enabled. In a network, only one DHCP server is needed to allocate and manage client IPs. If it is a secondary route, it is recommended to turn off the primary routing DHCP server.")) +lan_dhcp.default = lan_dhcp lan_dhcp.anonymous = false - e = s:taboption("wansetup", Flag, "dnsset", translate("Enable DNS notifications (ipv4/ipv6)"),translate("Force the DNS server in the DHCP server to be specified as the IP for this route")) -e:depends("lan_dhcp", true) +e:depends("lan_dhcp", false) +e.default = "0" e = s:taboption("wansetup", Value, "dns_tables", translate(" ")) e:value("1", translate("Use local IP for DNS (default)")) diff --git a/po/zh-cn/netwizard.po b/po/zh-cn/netwizard.po index d2419bc..1de1287 100644 --- a/po/zh-cn/netwizard.po +++ b/po/zh-cn/netwizard.po @@ -35,7 +35,7 @@ msgid "Wireless Settings" msgstr "无线设置" msgid "Allocate the physical interface of WAN port" -msgstr "分配Wan口的物理接口" +msgstr "必须指定正确的接光猫(或接上线路由)的物理口" msgid "interface(*)" msgstr "接口(*)" @@ -64,8 +64,8 @@ msgstr "旁路模式" msgid "Please enter the main routing IP address. The bypass gateway is not the same as the login IP of this bypass WEB and is in the same network segment" msgstr "请输入主路由IP地址,旁路网关与此旁路WEB登陆IP不相同并且必须在一个网段." -msgid "The default selection is to enable the DHCP server. In a network, only one DHCP server is needed to allocate and manage client IP. If it is a side route, it is recommended to turn off the main routing DHCP server." -msgstr "默认选择开启DHCP服务器。一个网络中只需要一个DHCP服务器分配管理客户机IP,如果是旁路由建议关闭主路由DHCP服务器。" +msgid "Selecting means that the DHCP server is not enabled. In a network, only one DHCP server is needed to allocate and manage client IPs. If it is a secondary route, it is recommended to turn off the primary routing DHCP server." +msgstr "选择表示不开启DHCP服务器。在一个网络中,只需要一个DHCP服务器来分配和管理客户端IP。如旁路由开DHCP服务器,须关闭主路由DHCP服务器。" msgid "Disable IPv6" msgstr "禁用IPv6" @@ -85,8 +85,8 @@ msgstr "IPv6混合模式" msgid "Remove IPv6" msgstr "移除IPv6" -msgid "Caution: If you delete IPV6 related plug-ins completely, you will not be able to recover" -msgstr "慎重:彻底删除IPV6相关插件,删除后无法恢复" +msgid "Default to use IPV6 hybrid mode" +msgstr "默认使用IPV6混合模式" msgid "Lan IPv4 address" msgstr "内网IP地址" @@ -113,7 +113,7 @@ msgid "Use iptables to force all TCP/UDP DNS 53ports in IPV4/IPV6 to be forwarde msgstr "用iptables强制IPV4/IPV6所有TCP/UDP DNS 53端口走此路由解析[建议打开]" msgid "Custom firewall" -msgstr "自定义防火墙" +msgstr "启用自定义规则" msgid "Use custom Wan DNS" msgstr "自定义Wan口的DNS" @@ -121,8 +121,8 @@ msgstr "自定义Wan口的DNS" msgid "Use custom Siderouter DNS" msgstr "自定义旁路由DNS" -msgid "Enable DHCP Server" -msgstr "启用DHCP服务" +msgid "Disable DHCP Server" +msgstr "禁用DHCP服务器" msgid "Force the DNS server in the DHCP server to be specified as the IP for this route" msgstr "强制指定DHCP服务器中DNS服务器为此路由的IP" diff --git a/root/etc/config/netwizard b/root/etc/config/netwizard new file mode 100644 index 0000000..75cef8c --- /dev/null +++ b/root/etc/config/netwizard @@ -0,0 +1,7 @@ +config netwizard 'default' + option lan_netmask '255.255.255.0' + option redirectdns '1' + option synflood '1' + option lan_snat '1' + option masq '1' + diff --git a/root/etc/init.d/netwizard b/root/etc/init.d/netwizard new file mode 100644 index 0000000..8dd6974 --- /dev/null +++ b/root/etc/init.d/netwizard @@ -0,0 +1,277 @@ +#!/bin/sh /etc/rc.common + +LOCK=/var/lock/netwizard-boot.lock +START=99 + +boot() { + XBOOT=1 +} + +setipv6() { + case $1 in + 0) + uci -q delete network.wan6 + uci -q set dhcp.lan.ra='' + uci -q set dhcp.lan.dhcpv6='' + uci -q set dhcp.lan.ndp='' + uci -q set dhcp.@dnsmasq[0].filter_aaaa="1" + uci -q set dhcp.lan.force='1' + uci -q set network.wan.ipv6='0' + uci -q set network.wan.delegate='0' + uci -q set network.lan.delegate='0' + # uci -q delete network.globals.ula_prefix + ;; + 1) + uci -q set dhcp.lan.ra='server' + uci -q set dhcp.lan.dhcpv6='server' + uci -q delete dhcp.@dnsmasq[0].filter_aaaa + uci -q set dhcp.lan.ndp='' + uci -q set dhcp.lan.ra_management='1' + uci -q set dhcp.lan.ra_default='1' + uci -q set dhcp.lan.force='1' + uci -q set network.wan.ipv6='auto' + uci -q set network.wan.delegate='0' + uci -q set network.lan.delegate='0' + ;; + 2) + uci -q set dhcp.lan.ra='relay' + uci -q set dhcp.lan.dhcpv6='relay' + uci -q set dhcp.lan.ndp='relay' + uci -q delete dhcp.@dnsmasq[0].filter_aaaa + uci -q set dhcp.lan.ndp='' + uci -q set dhcp.lan.ra_management='1' + uci -q set dhcp.lan.ra_default='1' + uci -q set dhcp.lan.force='1' + uci -q set network.wan.ipv6='auto' + uci -q set network.wan.delegate='0' + uci -q set network.lan.delegate='0' + ;; + 3) + uci -q set dhcp.lan.ra='hybrid' + uci -q set dhcp.lan.dhcpv6='hybrid' + uci -q set dhcp.lan.ndp='hybrid' + uci -q delete dhcp.@dnsmasq[0].filter_aaaa + uci -q set dhcp.lan.ndp='' + uci -q set dhcp.lan.ra_management='1' + uci -q set dhcp.lan.ra_default='1' + uci -q set dhcp.lan.force='1' + uci -q set network.wan.ipv6='auto' + uci -q set network.wan.delegate='0' + uci -q set network.lan.delegate='0' + ;; + 4) + opkg update + opkg remove --force-depends kmod-nf-reject6 kmod-nf-nat6 kmod-nf-ipt6 kmod-ip6tables odhcp6c luci-proto-ipv6 ip6tables kmod-ipt-nat6 ip6tables-mod-nat odhcpd-ipv6only ipv6helper + uci -q delete dhcp.lan.dhcpv6 + uci -q delete dhcp.lan.ndp + uci -q delete dhcp.lan.ra + uci -q delete dhcp.lan.ra_management + uci -q delete dhcp.lan.ra_default + uci -q delete network.wan6 + # Enable IPV6 ula prefix + sed -i 's/#.*\toption ula/\toption ula/g' /etc/config/network + # Enable IPV6 dns resolution + uci -q set dhcp.@dnsmasq[0].filter_aaaa=1 + ;; + esac +} +add_netwizard() { + [ "x$XBOOT" = "x1" ] && exit 0 + local cfg="$1" + local wan_proto wan_ipaddr wan_netmask wan_gateway wan_dns wan_pppoe_user wan_pppoe_pass + local ipv6 wifi_ssid wifi_key old_wifi_ssid old_wifi_key showhide + local lan_ipaddr lan_netmask lan_gateway lan_dns lan_dhcp wan_interface + local ifname lannet a b i + config_get showhide "$cfg" showhide '0' + config_get wan_proto "$cfg" wan_proto 'dhcp' + config_get ipv6 "$cfg" ipv6 '0' + config_get dnsset "$cfg" dnsset '223.5.5.5' + config_get wan_interface "$cfg" wan_interface 'eth1' + config_get lan_dhcp "$cfg" lan_dhcp '0' + config_get synflood "$cfg" synflood '1' + config_get redirectdns "$cfg" redirectdns '1' + config_get lan_ipaddr "$cfg" lan_ipaddr + config_get lan_netmask "$cfg" lan_netmask '255.255.255.0' + config_get dns_tables "$cfg" dns_tables 'iptables -t nat -I POSTROUTING -o br-lan -j MASQUERADE' + if [ "x$showhide" = "x1" ] ; then + [ -s /etc/config/netwizard_hide ] || touch /etc/config/netwizard_hide + exit + else + [ -s /etc/config/netwizard_hide ] && rm -rf /etc/config/netwizard_hide + fi + touch $LOCK + ifname=$(uci -q get network.lan.ifname ) + [ "x$ifname" = "x" ] && ifname="device" || ifname="ifname" + [ -n "$wan_interface" ] || wan_interface=$(uci -q get network.wan.$ifname 2>/dev/null) + uci -q delete network.lan.gateway + uci -q delete dhcp.lan.ignore + uci -q delete network.lan.dns + uci -q delete firewall.@zone[0].masq + [ `uci -q get network.wan` ] && uci -q delete network.wan + [ `uci -q get network.wan6` ] && uci -q delete network.wan6 + [ `uci -q get network.lan6` ] && uci -q delete network.lan6 + uci -q set network.wan=interface + uci -q set network.wan6=interface + uci -q set network.wan6.proto='dhcpv6' + uci -q set network.wan6.delegate='1' + sed -i '/j MASQUERADE/d' /etc/firewall.user + a=$(ip address | awk -F ': ' '/eth[0-9]+/ {print $2}' ) + b=$(echo "$a" | wc -l) + [ ${b} -gt 1 ] && { + lannet="" + for i in $(seq 1 $b) ; do [ "${wan_interface}" = "$(echo "$a" | sed -n ${i}p)" ] || lannet="${lannet} $(echo "$a" | sed -n ${i}p)" ;done + [ "x$ifname" = "xdevice" ] && uci -q set network.@$ifname[0].ports="${lannet}" || uci -q set network.lan.$ifname="${lannet}" + } + uci -q set network.wan.$ifname="${wan_interface}" + uci -q set network.wan6.$ifname="${wan_interface}" + case "${wan_proto}" in + dhcp) + uci -q set network.wan.proto='dhcp' + #uci -q set network.wan.metric='40' + uci -q set network.wan.delegate='0' + setipv6 $ipv6 + ;; + static) + config_get wan_ipaddr "$cfg" wan_ipaddr + config_get wan_netmask "$cfg" wan_netmask + config_get wan_gateway "$cfg" wan_gateway + test -n "${wan_ipaddr}" && test -n "${wan_netmask}" && { + uci -q set network.wan.proto='static' + #uci -q set network.wan.metric='40' + uci -q set network.wan.ipaddr="${wan_ipaddr}" + uci -q set network.wan.netmask="${wan_netmask}" + uci -q set network.wan.gateway="${wan_gateway}" + config_get wan_dns "$cfg" wan_dns + test -n "${wan_dns}" && { + uci set network.wan.peerdns='0' + uci set network.wan.dns="${wan_dns}" + } + } + setipv6 $ipv6 + ;; + pppoe) + config_get wan_pppoe_user "$cfg" wan_pppoe_user + config_get wan_pppoe_pass "$cfg" wan_pppoe_pass + [[ "${wan_pppoe_user} != $(uci get network.wan.username)" || "${wan_pppoe_pass} != $(uci get network.wan.password)" ]] && { + uci -q set network.wan.proto='pppoe' + #uci -q set network.wan.metric='40' + uci -q set network.wan.username="${wan_pppoe_user}" + uci -q set network.wan.password="${wan_pppoe_pass}" + uci -q set network.wan.keepalive='5 5' + uci -q set network.wan.mtu='1480' + config_get wan_dns "$cfg" wan_dns + test -n "${wan_dns}" && { + uci -q set network.wan.peerdns='0' + uci -q set network.wan.dns="${wan_dns}" + } + } + setipv6 $ipv6 + ;; + siderouter) + config_get lan_gateway "$cfg" lan_gateway + config_get lan_dns "$cfg" lan_dns + config_get lan_snat "$cfg" lan_snat + config_get masq "$cfg" masq + config_get snat_tables "$cfg" snat_tables + test -n "${lan_gateway}" && { + [ `uci get network.wan` ] && uci -q delete network.wan + [ `uci get network.wan6` ] && uci -q delete network.wan6 + uci -q set network.lan.gateway="${lan_gateway}" + [ -n "$lan_dns" ] || lan_dns='223.5.5.5' + uci -q set network.lan.dns="${lan_dns}" + if [ ${b} -gt 1 ] ; then + [ "x$ifname" = "xdevice" ] && uci -q set network.@$ifname[0].ports="${lannet} ${wan_interface}" || uci -q set network.lan.$ifname="${lannet} ${wan_interface}" + fi + [ "x$masq" = "x1" ] && uci -q set firewall.@zone[0].masq='1' || uci -q delete firewall.@zone[0].masq + + [ "x$lan_snat" = "x1" ] && echo "${snat_tables}" >> /etc/firewall.user + } + setipv6 $ipv6 + [[ $ipv6 = '1' || $ipv6 = '2' || $ipv6 = '3' ]] && { + uci -q set network.lan6=interface + uci -q set network.lan6.proto='dhcpv6' + uci -q set network.lan6.delegate='1' + uci -q set network.lan6.$ifname="@lan" + netzone=`uci -q get firewall.@zone[0].network` + [ $netzone = 'lan lan6' ] || uci -q set firewall.@zone[0].network='lan lan6' + # uci -q delete firewall.@zone[1] + # uci -q set firewall.@zone[1] + } + ;; + esac + test -n "${lan_ipaddr}" && test -n "${lan_netmask}" && { + uci -q set network.lan.ipaddr="${lan_ipaddr}" + uci -q set network.lan.netmask="${lan_netmask}" + } + + sed -i '/--dport 53 -j REDIRECT --to-ports 53/d' /etc/firewall.user + [ "x$redirectdns" = "x1" ] && { + echo "iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 53" >> /etc/firewall.user + echo "iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 53" >> /etc/firewall.user + echo "[ -n "$(command -v ip6tables)" ] && ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 53" >> /etc/firewall.user + echo "[ -n "$(command -v ip6tables)" ] && ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 53" >> /etc/firewall.user + } + [ "x$synflood" = "x1" ] && uci -q set firewall.@defaults[0].syn_flood='1' || uci -q delete firewall.@defaults[0].syn_flood + sed -i "/dhcp_option '6/d" /etc/config/dhcp + sed -i "/list dns/d" /etc/config/dhcp + if [ "x$lan_dhcp" = "x0" ] ; then + # uci -q set dhcp.lan.dynamicdhcp="1" + uci -q set dhcp.lan.ignore="0" + [ "x$dnsset" = "x1" ] && { + [ "${dns_tables}" = "1" ] && uci -q add_list dhcp.lan.dhcp_option="6,${lan_ipaddr}" || uci -q add_list dhcp.lan.dhcp_option="6,${dns_tables}" + uci -q add_list dhcp.lan.dns="fd00::1" + } + else + # uci -q set dhcp.lan.dynamicdhcp="0" + uci -q set dhcp.lan.ignore="1" + fi + wifi_setup_radio(){ + local radio=$1 + uci get wireless.${radio} >/dev/null 2>&1 && { + if [ "$(uci get wireless.${radio}.band)" = "5g" ]; then + uci -q set wireless.default_${radio}.ssid="${wifi_ssid}_5G" + else + uci -q set wireless.default_${radio}.ssid="${wifi_ssid}_2.4G" + fi + uci -q set wireless.default_${radio}.device="${radio}" + if [ "${wifi_key}" ]; then + uci -q set wireless.default_${radio}.encryption='psk2' + uci -q set wireless.default_${radio}.key="${wifi_key}" + else + uci -q set wireless.default_${radio}.encryption='none' + fi + } + } + config_get wifi_ssid "$cfg" wifi_ssid + config_get wifi_key "$cfg" wifi_key + config_get old_wifi_ssid "$cfg" old_wifi_ssid + config_get old_wifi_key "$cfg" old_wifi_key + if [[ "${wifi_ssid}" != "${old_wifi_ssid}" || "${wifi_key}" != "${old_wifi_key}" ]]; then + test -n "${wifi_ssid}" && { + for radio in radio0 radio1 radio2 radio3; do + wifi_setup_radio ${radio} + done + uci commit wireless + } + uci -q set netwizard.default.old_wifi_ssid="${wifi_ssid}" + uci -q set netwizard.default.old_wifi_key="${wifi_ssid}" + fi + uci commit netwizard + uci commit dhcp + uci commit firewall + uci commit network + (sleep 3 + /etc/init.d/network restart + /etc/init.d/dnsmasq reload)& +} + +start() { + [ -f $LOCK ] && exit + config_load netwizard + config_foreach add_netwizard netwizard + rm -f $LOCK 2>/dev/null +} + +stop() { + rm -f $LOCK 2>/dev/null +} \ No newline at end of file diff --git a/root/etc/uci-defaults/luci-netwizard b/root/etc/uci-defaults/luci-netwizard new file mode 100644 index 0000000..c6ff3cd --- /dev/null +++ b/root/etc/uci-defaults/luci-netwizard @@ -0,0 +1,12 @@ +#!/bin/sh +chmod +x /etc/init.d/netwizard 2>/dev/null + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@netwizard[-1] + add ucitrack netwizard + set ucitrack.@netwizard[-1].init="netwizard" + commit ucitrack +EOF + +rm -f /tmp/luci-indexcache +exit 0 diff --git a/root/etc/uci-defaults/luci-netwizard-defaults b/root/etc/uci-defaults/luci-netwizard-defaults new file mode 100644 index 0000000..ac814ee --- /dev/null +++ b/root/etc/uci-defaults/luci-netwizard-defaults @@ -0,0 +1,14 @@ +#!/bin/sh +ipaddr=$(uci -q get network.lan.ipaddr) +[ -n "$(uci -q get netwizard.default=netwizard)" ] && uci set netwizard.default=netwizard +uci -q set netwizard.default.wifi_ssid="$(uci -q get wireless.@wifi-iface[0].ssid)" +uci -q set netwizard.default.wifi_key="$(uci -q get wireless.@wifi-iface[0].key)" +[ "$(uci -q get network.wan.proto)" ] && uci -q set netwizard.default.wan_proto="$(uci -q get network.wan.proto)" || uci -q set netwizard.default.wan_proto="siderouter" +uci -q set netwizard.default.lan_ipaddr="${ipaddr}" +uci -q set netwizard.default.lan_netmask="$(uci -q get network.lan.netmask)" +uci -q set netwizard.default.lan_gateway="${ipaddr%.*}" +uci -q set netwizard.default.lan_dns="$(uci -q get network.lan.dns)" +uci -q set netwizard.default.wan_interface=`uci -q get network.wan.ifname || uci -q get network.wan.device` +[ "$(uci -q get dhcp.lan.ignore)" ] && uci -q set netwizard.default.lan_dhcp="0" || uci -q set netwizard.default.lan_dhcp="1" +uci commit netwizard +exit 0