mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-10-29 17:05:13 +08:00
update 2026-09-26 11:07:27
This commit is contained in:
1 parent
7b88b273d0
commit
97ae9f68da
4898 files changed
-1712274
No files matched your search
@@ -1 +0,0 @@
|
||||
config wizard 'default'
|
||||
@@ -1,150 +0,0 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=99
|
||||
USE_PROCD=1
|
||||
|
||||
# 清理历史已生成的快捷方式(防止改名或删除后遗留失效条目)
|
||||
clean_shortcuts() {
|
||||
local sec
|
||||
# 清理 nginx 中由 wizard 生成的 _sc_* server 节
|
||||
for sec in $(uci -q show nginx 2>/dev/null | sed -n 's/^nginx\.\(_sc_[^=.]*\)=server$/\1/p'); do
|
||||
uci -q delete nginx."$sec"
|
||||
done
|
||||
|
||||
# 清理 dhcp (dnsmasq) 中由 wizard 生成的 _sc_* domain 节
|
||||
for sec in $(uci -q show dhcp 2>/dev/null | sed -n 's/^dhcp\.\(_sc_[^=.]*\)=domain$/\1/p'); do
|
||||
uci -q delete dhcp."$sec"
|
||||
done
|
||||
}
|
||||
|
||||
# 处理单条 shortcut 节
|
||||
process_shortcut() {
|
||||
local shortcut to_url comments lanaddr
|
||||
local cfg="$1"
|
||||
|
||||
# 获取当前 LAN 口 IP,支持 DSA 列表与 CIDR 掩码剔除
|
||||
lanaddr="$(uci -q get network.lan.ipaddr | tr ' ' '\n' | head -n1)"
|
||||
lanaddr="${lanaddr%%/*}"
|
||||
[ -z "$lanaddr" ] && lanaddr="10.0.0.1"
|
||||
|
||||
config_get shortcut "$cfg" shortcut
|
||||
config_get to_url "$cfg" to_url
|
||||
config_get comments "$cfg" comments
|
||||
|
||||
# 校验必要参数
|
||||
if [ -z "$shortcut" ] || [ -z "$to_url" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# 1. 配置 Nginx 302 重定向 (仅在存在 /etc/nginx/uci.conf 时配置,仅监听80,禁止未配证书监听443)
|
||||
if [ -f /etc/nginx/uci.conf ]; then
|
||||
uci -q set nginx._sc_$shortcut=server
|
||||
uci -q set nginx._sc_$shortcut.server_name="$shortcut"
|
||||
uci -q add_list nginx._sc_$shortcut.listen="80"
|
||||
uci -q set nginx._sc_$shortcut.return="302 $to_url"
|
||||
|
||||
# 2. 配置 Dnsmasq (DHCP) 本地域名劫持
|
||||
uci -q set dhcp._sc_$shortcut=domain
|
||||
uci -q set dhcp._sc_$shortcut.name="$shortcut"
|
||||
uci -q set dhcp._sc_$shortcut.ip="$lanaddr"
|
||||
[ -n "$comments" ] && uci -q set dhcp._sc_$shortcut.comments="$comments"
|
||||
fi
|
||||
}
|
||||
|
||||
# 配置 HTTPS 访问重定向 (适配 Nginx / Lighttpd / uHTTPd)
|
||||
sethttps() {
|
||||
local cfg="${1:-default}"
|
||||
local https
|
||||
config_get https "$cfg" https 0
|
||||
|
||||
if [ -x /etc/init.d/nginx ] && [ -f /etc/nginx/uci.conf ]; then
|
||||
if [ "x${https}" = "x1" ]; then
|
||||
if [ -z "$(uci -q get nginx._redirect2ssl)" ]; then
|
||||
uci -q set nginx._redirect2ssl=server
|
||||
uci -q set nginx._redirect2ssl.server_name='_redirect2ssl'
|
||||
uci -q set nginx._redirect2ssl.return='302 https://$host$request_uri'
|
||||
uci -q set nginx._redirect2ssl.access_log='off; # logd openwrt'
|
||||
fi
|
||||
uci -q del nginx.default_server.listen
|
||||
uci -q add_list nginx.default_server.listen='80'
|
||||
uci -q add_list nginx.default_server.listen='[::]:80'
|
||||
uci -q del nginx._redirect2ssl.listen
|
||||
uci -q add_list nginx._redirect2ssl.listen='80 default_server'
|
||||
uci -q add_list nginx._redirect2ssl.listen='[::]:80 default_server'
|
||||
else
|
||||
uci -q delete nginx._redirect2ssl
|
||||
uci -q del nginx.default_server.listen
|
||||
uci -q add_list nginx.default_server.listen='80 default_server'
|
||||
uci -q add_list nginx.default_server.listen='[::]:80 default_server'
|
||||
fi
|
||||
uci -q commit nginx
|
||||
/etc/init.d/nginx reload >/dev/null 2>&1
|
||||
elif [ -x /etc/init.d/lighttpd ] && [ -f /etc/lighttpd/conf.d/82-https.conf ]; then
|
||||
if [ "x${https}" = "x1" ]; then
|
||||
sed -i "s/^[ \t]*#*[ \t]*url\.redirect[ \t]*=.*/\turl.redirect =/" /etc/lighttpd/conf.d/82-https.conf 2>/dev/null
|
||||
else
|
||||
sed -i "s/^[ \t]*url\.redirect[ \t]*=.*/\t# url.redirect =/" /etc/lighttpd/conf.d/82-https.conf 2>/dev/null
|
||||
fi
|
||||
/etc/init.d/lighttpd reload >/dev/null 2>&1
|
||||
elif [ -x /etc/init.d/uhttpd ]; then
|
||||
if [ "x${https}" = "x1" ]; then
|
||||
uci -q set uhttpd.main.redirect_https='1'
|
||||
else
|
||||
uci -q set uhttpd.main.redirect_https='0'
|
||||
fi
|
||||
uci -q commit uhttpd
|
||||
/etc/init.d/uhttpd reload >/dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
# 提交配置并平滑重载底层服务
|
||||
reload_services() {
|
||||
uci -q commit dhcp
|
||||
if [ -x /etc/init.d/dnsmasq ]; then
|
||||
/etc/init.d/dnsmasq reload >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
if [ -f /etc/nginx/uci.conf ] && [ -x /etc/init.d/nginx ]; then
|
||||
uci -q commit nginx
|
||||
/etc/init.d/nginx reload >/dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
start_service() {
|
||||
config_load wizard
|
||||
|
||||
# 1. 开机 CoreMark 跑分处理 (后台异步执行,杜绝阻塞系统启动与前端保存卡死)
|
||||
local coremark
|
||||
config_get coremark default coremark 0
|
||||
if [ "$coremark" = "1" ] && [ -x /bin/coremark ] && [ -x /sbin/coremark ] && [ ! -f /etc/bench.log ] && [ ! -f /var/lock/opkg.lock ]; then
|
||||
(sleep 5;/sbin/coremark >/dev/null 2>&1) &
|
||||
fi
|
||||
|
||||
# 2. 持久 Cookie 会话配置同步到 LuCI 底层系统
|
||||
local cookie_p
|
||||
config_get cookie_p default persistent_cookies 1
|
||||
if [ -n "$cookie_p" ]; then
|
||||
[ -z "$(uci -q get luci.sgi)" ] && uci -q set luci.sgi=sgi
|
||||
uci -q set luci.sgi.persistent_cookies="$cookie_p"
|
||||
uci -q commit luci
|
||||
fi
|
||||
|
||||
# 3. 清理并重新配置所有 Shortcuts
|
||||
clean_shortcuts
|
||||
config_foreach process_shortcut shortcuts
|
||||
|
||||
# 4. 设置 HTTPS 重定向
|
||||
sethttps default
|
||||
|
||||
# 5. 提交并重载生效服务
|
||||
reload_services
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
clean_shortcuts
|
||||
reload_services
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "wizard"
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"admin/system/wizard": {
|
||||
"title": "Setup Wizard",
|
||||
"order": 10,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "wizard/initsetup"
|
||||
},
|
||||
"depends": {
|
||||
"acl": [ "luci-app-wizard" ],
|
||||
"uci": { "wizard": true }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
{
|
||||
"luci-app-wizard": {
|
||||
"description": "Grant UCI and filesystem access for LuCI Setup Wizard",
|
||||
"read": {
|
||||
"uci": [
|
||||
"network",
|
||||
"wireless",
|
||||
"dhcp",
|
||||
"uhttpd",
|
||||
"firewall",
|
||||
"luci",
|
||||
"wizard"
|
||||
],
|
||||
"file": {
|
||||
"/etc/nginx/uci.conf": [ "stat" ]
|
||||
}
|
||||
},
|
||||
"write": {
|
||||
"uci": [
|
||||
"network",
|
||||
"wireless",
|
||||
"dhcp",
|
||||
"uhttpd",
|
||||
"firewall",
|
||||
"luci",
|
||||
"wizard"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user