first commit

main
Ben 1 year ago
commit e465a41484

@ -0,0 +1,24 @@
#
# Copyright (C) 2017-2019 Chen Minqiang <ptpt52@gmail.com>
#
# This is free software, licensed under the GNU General Public License v3.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI Support for wizard
LUCI_DEPENDS:=
LUCI_PKGARCH:=all
PKG_NAME:=luci-app-wizard
PKG_MAINTAINER:=Chen Minqiang <ptpt52@gmail.com>
PKG_LICENSE:=GPLv3
define Package/luci-app-wizard/conffiles
/etc/config/wizard
endef
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

@ -0,0 +1,3 @@
# luci-app-wizard
修改自 https://github.com/x-wrt/com.x-wrt/tree/master/luci-app-wizard

@ -0,0 +1,108 @@
'use strict';
'require view';
'require dom';
'require poll';
'require uci';
'require rpc';
'require form';
'require fs';
return view.extend({
load: function() {
return Promise.all([
fs.exec('/etc/init.d/wizard', ['reconfig']),
uci.changes(),
uci.load('wireless'),
uci.load('wizard')
]);
},
render: function(data) {
var m, s, o;
var has_wifi = false;
if (uci.sections('wireless', 'wifi-device').length > 0) {
has_wifi = true;
}
m = new form.Map('wizard', [_('Initial Router Setup')],
_('If you are using this router for the first time, please configure it here.'));
s = m.section(form.NamedSection, 'default', 'wizard');
s.addremove = false;
s.tab('netsetup', _('Net Settings'), _('Three different ways to access the Internet, please choose according to your own situation.'));
o = s.taboption('netsetup', form.ListValue, 'wan_proto', _('Protocol'));
o.rmempty = false;
o.value('dhcp', _('DHCP client'));
o.value('pppoe', _('PPPoE'));
o = s.taboption('netsetup', form.Value, 'wan_pppoe_user', _('PAP/CHAP username'));
o.depends('wan_proto', 'pppoe');
o = s.taboption('netsetup', form.Value, 'wan_pppoe_pass', _('PAP/CHAP password'));
o.depends('wan_proto', 'pppoe');
o.password = true;
o = s.taboption('netsetup', form.Value, 'lan_ipaddr', _('IPv4 address'));
o.datatype = 'ip4addr';
o = s.taboption('netsetup', form.Value, 'lan_netmask', _('IPv4 netmask'));
o.datatype = 'ip4addr';
o.value('255.255.255.0');
o.value('255.255.0.0');
o.value('255.0.0.0');
o.default = '255.255.255.0';
o = s.taboption('netsetup', form.DynamicList, 'lan_dns', _('Use custom DNS servers'), _('Leave empty to use ISP DNS'));
o.datatype = 'ip4addr';
o.cast = 'string';
o = s.taboption('netsetup', form.Flag, 'siderouter', _('Siderouter'),
_('Use as downstream router i.e. it will work like a switch'));
o.rmempty = false;
o = s.taboption('netsetup', form.Value, 'lan_gateway', _('IPv4 gateway'));
o.depends('siderouter', '1');
o.datatype = 'ip4addr';
o.placeholder = _('Enter the main router IP');
o.rmempty = false;
o = s.taboption('netsetup', form.Flag, 'dhcp', _('DHCP Server'),
_('To turn on this DHCP, you need to turn off the DHCP of the main router, and to turn off this DHCP, you need to manually change the gateway and DNS of all Internet devices to the IP of this bypass router'));
o.depends('siderouter', '1');
o.default = o.enabled;
o = s.taboption('netsetup', form.Flag, 'ipv6', _('Enable IPv6'), _('Enable/Disable IPv6'));
o.default = o.enabled;
s.tab('firmware', _('Firmware Settings'));
// o = s.taboption('firmware', form.Flag, 'autoupgrade_pkg', _('Packages Auto Upgrade'),_('谨慎开启'));
// o.rmempty = false;
o = s.taboption('firmware', form.Flag, 'autoupgrade_fm', _('Firmware Upgrade Notice'));
o.rmempty = false;
o = s.taboption('firmware', form.Flag, 'coremark', _('CPU Benchmark'), _('Run Benchmark after boot.'));
o.rmempty = false;
o = s.taboption('firmware', form.Flag, 'cookie_p', _('Persistent cookies'),
_('Keep the background login state to avoid the need to log in again every time the browser is closed'));
o.default = o.enabled;
if (has_wifi) {
s.tab('wifisetup', _('Wireless Settings'), _('Set the router\'s wireless name and password. For more advanced settings, please go to the Network-Wireless page.'));
o = s.taboption('wifisetup', form.Value, 'wifi_ssid', _('<abbr title=\"Extended Service Set Identifier\">ESSID</abbr>'));
o.datatype = 'maxlength(32)';
o = s.taboption("wifisetup", form.Value, "wifi_key", _("Key"));
o.datatype = 'wpakey';
o.password = true;
}
setTimeout("document.getElementsByClassName('cbi-button-apply')[0].children[3].children[0].value='1'", 1000)
return m.render();
}
});

@ -0,0 +1,44 @@
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8\n"
msgid "Wizard"
msgstr "Мастер настройки"
msgid "Initial Router Setup"
msgstr "Мастер настройки маршрутизатора"
msgid "Net Settings"
msgstr "Сетевые настройки"
msgid "Wireless Settings"
msgstr "Настройки беспроводной связи"
msgid "If you are using this router for the first time, please configure it here."
msgstr "Если вы используете этот маршрутизатор в первый раз, пожалуйста, просто настройте его здесь."
msgid "Three different ways to access the Internet, please choose according to your own situation."
msgstr "Существует два различных способа серфинга в Интернете, пожалуйста, выбирайте в соответствии с вашей собственной ситуацией."
msgid "Set the router's wireless name and password. For more advanced settings, please go to the Network-Wireless page."
msgstr "Задайте имя беспроводной сети и пароль маршрутизатора. для получения более подробных настроек, пожалуйста, перейдите на страницу Cеть-Беспроводная связь."
msgid "Siderouter"
msgstr "Вторичный роутер"
msgid "Enable IPv6"
msgstr "Включить IPv6"
msgid "Enable/Disable IPv6"
msgstr "Включение/Отключение IPv6"
msgid "Firmware Settings"
msgstr "Настройки встроенного ПО"
msgid "Packages Auto Upgrade"
msgstr "Автоматическое обновление пакета"
msgid "Firmware Upgrade Notice"
msgstr "Напоминание об обновлении прошивки"
msgid "Persistent cookies"
msgstr "Постоянный вход в систему"

@ -0,0 +1 @@
zh_Hans

@ -0,0 +1,57 @@
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8\n"
msgid "Wizard"
msgstr "设置向导"
msgid "Initial Router Setup"
msgstr "路由器设置向导"
msgid "Net Settings"
msgstr "网络设置"
msgid "Wireless Settings"
msgstr "无线设置"
msgid "If you are using this router for the first time, please configure it here."
msgstr "如果你首次使用这个路由器,请在这里简单设置。"
msgid "Three different ways to access the Internet, please choose according to your own situation."
msgstr "二种不同的上网方式,请您根据自身情况进行选择。"
msgid "Set the router's wireless name and password. For more advanced settings, please go to the Network-Wireless page."
msgstr "设置路由器的无线名字和密码,更多高级设置请进入 网络-无线 页面。"
msgid "Leave empty to use ISP DNS"
msgstr "留空则使用阿里DNS"
msgid "Enter the main router IP"
msgstr "请输入主路由IP"
msgid "Siderouter"
msgstr "旁路由模式"
msgid "To turn on this DHCP, you need to turn off the DHCP of the main router, and to turn off this DHCP, you need to manually change the gateway and DNS of all Internet devices to the IP of this bypass router"
msgstr "开启此DHCP则需要关闭主路由的DHCP, 关闭此DHCP则需要手动将所有上网设备的网关和DNS改为此旁路由的IP"
msgid "Enable IPv6"
msgstr "启用IPv6"
msgid "Enable/Disable IPv6"
msgstr "一键开启/关闭 IPv6"
msgid "Firmware Settings"
msgstr "固件设置"
msgid "Packages Auto Upgrade"
msgstr "软件包自动更新"
msgid "Firmware Upgrade Notice"
msgstr "固件更新提醒"
msgid "Persistent cookies"
msgstr "持久化登录"
msgid "Keep the background login state to avoid the need to log in again every time the browser is closed"
msgstr "保持后台登录状态,避免每次关闭浏览器后都需要重新登录"

@ -0,0 +1 @@
config wizard 'default'

@ -0,0 +1,179 @@
#!/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_pppoe_user wan_pppoe_pass
local lan_ipaddr lan_netmask lan_dns lan_gateway dhcp
local device ipv6 old_ipv6 wifi_ssid wifi_key old_wifi_ssid old_wifi_key
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'
;;
pppoe)
config_get wan_pppoe_user "$cfg" wan_pppoe_user
config_get wan_pppoe_pass "$cfg" wan_pppoe_pass
[[ "${wan_pppoe_user} != $(uci -q get network.wan.username)" || "${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}"
[ -n "${ipv6}" ] && {
uci -q set network.wan.ipv6='0'
uci -q set network.wan.delegate='0'
}
}
;;
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
config_get ipv6 "$cfg" ipv6
config_get old_ipv6 "$cfg" old_ipv6
config_get autoupgrade_pkg "$cfg" autoupgrade_pkg
[ "$dhcp" == "0" ] && dhcp="1"
if [[ "${lan_gateway}" != "$(uci -q get network.lan.gateway)" || "${dhcp}" != "$(uci -q get dhcp.lan.ignore)" ]]; then
if [ "${siderouter}" == "1" ]; then
uci -q set network.lan.gateway="${lan_gateway}"
[ -n "$lan_dns" ] || lan_dns='223.5.5.5'
[ -n "$dhcp" ] && uci -q set dhcp.lan.ignore="1" || uci -q del dhcp.lan.ignore
uci -q set firewall.@zone[0].masq='1'
uci -q set network.wan.proto='none'
elif [ "${siderouter}" == "0" ]; then
uci -q del network.lan.gateway
uci -q del dhcp.lan.ignore
uci -q del network.lan.dns
uci -q del firewall.@zone[0].masq
uci -q set network.wan.proto='dhcp'
fi
fi
[ -n "$lan_dns" ] && {
[ "$(uci -q get dhcp.@dnsmasq[0].noresolv)" == 1 ] && {
uci -q del dhcp.@dnsmasq[0].noresolv
}
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
}
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 set network.wan.delegate='0'
uci -q delete network.globals.ula_prefix
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 -q del network.wan.delegate
fi
uci -q set wizard.default.old_ipv6="${ipv6}"
fi
wifi_setup_radio(){
local radio=$1
uci -q get wireless.${radio} >/dev/null 2>&1 && {
if [ "$(uci -q 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
}
fi
uci commit wizard
uci commit dhcp
uci commit firewall
uci commit network
(
/etc/init.d/network restart
/etc/init.d/dnsmasq reload)&
if [ "${autoupgrade_pkg}" != "1" ]; then
sed -i '/opkg-upgrade/d' /etc/crontabs/root
else
grep -q "opkg-upgrade" /etc/crontabs/root || {
hour="$(grep -m1 -ao '[4-6]' /dev/urandom | head -n1)"
min="$(grep -m1 -ao '[0-5][0-9]' /dev/urandom | head -n1)"
echo "$min $hour * * * . /etc/hotplug.d/online/51-opkg-upgrade >/dev/null 2>&1" >> /etc/crontabs/root
}
fi
}
reconfig() {
uci -q set wizard.default.wan_proto="$(uci -q get network.wan.proto)"
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
}

@ -0,0 +1,14 @@
touch /etc/config/wizard
touch /etc/config/wireless
uci -q batch <<-EOF >/dev/null
delete ucitrack.@wizard[-1]
add ucitrack wizard
set ucitrack.@wizard[-1].init=wizard
commit ucitrack
EOF
chmod +x /etc/init.d/wizard 2>/dev/null
rm -f /tmp/luci-indexcache
exit 0

@ -0,0 +1,12 @@
uci -q set wizard.default.wan_proto="$(uci -q get network.wan.proto)"
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
exit 0

@ -0,0 +1,14 @@
{
"admin/system/initsetup": {
"title": "Wizard",
"order": 1,
"action": {
"type": "view",
"path": "wizard/initsetup"
},
"depends": {
"acl": [ "luci-app-wizard" ],
"uci": { "wizard": true }
}
}
}

@ -0,0 +1,14 @@
{
"luci-app-wizard": {
"description": "Grant UCI access for luci-app-wizard",
"read": {
"file": {
"/etc/init.d/wizard reconfig": [ "exec" ]
},
"uci": [ "wizard", "wireless" ]
},
"write": {
"uci": [ "wizard" ]
}
}
}
Loading…
Cancel
Save