147 lines
4.4 KiB
Bash
147 lines
4.4 KiB
Bash
#!/bin/sh /etc/rc.common
|
|
|
|
START=19
|
|
|
|
extra_command "reconfig" ""
|
|
|
|
boot() {
|
|
XBOOT=1 start
|
|
}
|
|
|
|
add_wizard() {
|
|
[ "x$XBOOT" = "x1" ] && return 0
|
|
local cfg="$1"
|
|
local wan_proto wan_ipaddr wan_netmask wan_gateway wan_pppoe_user wan_pppoe_pass
|
|
local lan_ipaddr lan_netmask lan_dns lan_gateway dhcp
|
|
local device ipv6 old_ipv6
|
|
|
|
config_get wan_proto "$cfg" wan_proto
|
|
|
|
device=$(uci get network.wan.device 2>/dev/null)
|
|
case "${wan_proto}" in
|
|
dhcp)
|
|
uci delete network.wan
|
|
uci set network.wan=interface
|
|
uci set network.wan.device="$device"
|
|
uci set network.wan.proto='dhcp'
|
|
;;
|
|
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 delete network.wan
|
|
uci set network.wan=interface
|
|
uci set network.wan.proto='static'
|
|
uci set network.wan.device="$device"
|
|
uci set network.wan.ipaddr="${wan_ipaddr}"
|
|
uci set network.wan.netmask="${wan_netmask}"
|
|
uci set network.wan.gateway="${wan_gateway}"
|
|
uci set dhcp.wan.start='100'
|
|
uci set dhcp.wan.limit='150'
|
|
uci set dhcp.wan.leasetime='12h'
|
|
}
|
|
;;
|
|
pppoe)
|
|
config_get wan_pppoe_user "$cfg" wan_pppoe_user
|
|
config_get wan_pppoe_pass "$cfg" wan_pppoe_pass
|
|
[[ -n "${wan_pppoe_user} != $(uci -q get network.wan.username)" || -n "${wan_pppoe_pass} != $(uci -q get network.wan.password)" ]] && {
|
|
uci delete network.wan
|
|
uci set network.wan=interface
|
|
uci set network.wan.proto='pppoe'
|
|
uci set network.wan.device="$device"
|
|
uci set network.wan.username="${wan_pppoe_user}"
|
|
uci set network.wan.password="${wan_pppoe_pass}"
|
|
}
|
|
;;
|
|
esac
|
|
|
|
config_get lan_ipaddr "$cfg" lan_ipaddr
|
|
config_get lan_netmask "$cfg" lan_netmask
|
|
test -n "${lan_ipaddr}" && test -n "${lan_netmask}" && {
|
|
uci set network.lan.ipaddr="${lan_ipaddr}"
|
|
uci set network.lan.netmask="${lan_netmask}"
|
|
}
|
|
|
|
config_get siderouter "$cfg" siderouter
|
|
config_get old_siderouter "$cfg" old_siderouter
|
|
config_get lan_gateway "$cfg" lan_gateway
|
|
config_get dhcp "$cfg" dhcp
|
|
config_get lan_dns "$cfg" lan_dns
|
|
|
|
[ -n "$lan_dns" ] && {
|
|
uci -q set network.wan.peerdns='0'
|
|
uci -q set network.lan.dns="${lan_dns}"
|
|
} || {
|
|
uci -q del network.wan.peerdns
|
|
uci -q del network.lan.dns
|
|
}
|
|
|
|
[ "$dhcp" == "0" ] && dhcp="1"
|
|
if [[ -n "${lan_gateway} != $(uci -q get network.lan.gateway)" || -n "${dhcp} != $(uci -q get dhcp.lan.ignore)" ]]; then
|
|
if [ -n "${siderouter}" ]; then
|
|
uci -q set network.lan.gateway="${lan_gateway}"
|
|
[ -n "$lan_dns" ] || uci -q set network.lan.dns='223.5.5.5'
|
|
[ -n "$dhcp" ] && uci -q set dhcp.lan.ignore="1" || uci -q del dhcp.lan.ignore
|
|
else
|
|
uci -q del network.lan.gateway
|
|
uci -q del dhcp.lan.ignore
|
|
fi
|
|
fi
|
|
|
|
config_get ipv6 "$cfg" ipv6
|
|
config_get old_ipv6 "$cfg" old_ipv6
|
|
|
|
if [ "${ipv6}" != "${old_ipv6}" ]; then
|
|
if [ -n "${ipv6}" ]; then
|
|
uci -q delete dhcp.lan.ra
|
|
uci -q delete dhcp.lan.dhcpv6
|
|
uci -q set network.lan.delegate='0'
|
|
uci -q set network.wan.ipv6='0'
|
|
uci -q delete network.globals.ula_prefix
|
|
uci commit dhcp
|
|
/etc/init.d/odhcpd disable
|
|
/etc/init.d/odhcpd stop
|
|
else
|
|
uci -q set dhcp.lan.ra='hybrid'
|
|
uci -q set dhcp.lan.dhcpv6='hybrid'
|
|
uci -q del network.lan.delegate
|
|
uci -q set network.wan.ipv6='auto'
|
|
uci commit dhcp
|
|
/etc/init.d/odhcpd enable
|
|
/etc/init.d/odhcpd start
|
|
fi
|
|
uci -q set wizard.default.old_ipv6="${ipv6}"
|
|
fi
|
|
|
|
uci commit wizard
|
|
uci commit network
|
|
uci commit wireless
|
|
(
|
|
/etc/init.d/network reload
|
|
/etc/init.d/dnsmasq reload)&
|
|
}
|
|
|
|
reconfig() {
|
|
uci -q set wizard.default.wan_proto="$(uci -q get network.wan.proto)"
|
|
uci -q set wizard.default.wan_netmask="$(uci -q get network.wan.netmask)"
|
|
uci -q set wizard.default.wan_gateway="$(uci -q get network.wan.gateway)"
|
|
uci -q set wizard.default.wan_pppoe_user="$(uci -q get network.wan.username)"
|
|
uci -q set wizard.default.wan_pppoe_pass="$(uci -q get network.wan.password)"
|
|
uci -q set wizard.default.lan_ipaddr="$(uci -q get network.lan.ipaddr)"
|
|
uci -q set wizard.default.lan_netmask="$(uci -q get network.lan.netmask)"
|
|
uci -q set wizard.default.lan_gateway="$(uci -q get network.lan.gateway)"
|
|
uci -q set wizard.default.lan_dns="$(uci -q get network.lan.dns)"
|
|
[ "$(uci -q get dhcp.lan.ignore)" ] && uci -q set wizard.default.dhcp="0" || uci -q del wizard.default.dhcp
|
|
uci commit wizard
|
|
}
|
|
|
|
start() {
|
|
config_load wizard
|
|
config_foreach add_wizard wizard
|
|
}
|
|
|
|
restart() {
|
|
XRELOAD=1 start
|
|
}
|