Merge pull request #1181 from sofia-riese/redesign-1

feat: redesign static text menu
This commit is contained in:
juewuy
2026-01-25 13:10:35 +08:00
committed by GitHub
6 changed files with 292 additions and 208 deletions

View File

@@ -16,7 +16,7 @@ URI_EXP='ss|vmess|vless|trojan|tuic|anytls|shadowtls|hysteria(2)?'
# 配置文件主界面 # 配置文件主界面
set_core_config() { set_core_config() {
while true; do while true; do
format_box "\033[30;47m配置文件管理\033[0m" comp_box "\033[30;47m配置文件管理\033[0m"
[ -s "$CRASHDIR"/configs/providers.cfg ] || [ -s "$CRASHDIR"/configs/providers_uri.cfg ] && { [ -s "$CRASHDIR"/configs/providers.cfg ] || [ -s "$CRASHDIR"/configs/providers_uri.cfg ] && {
echo -e "\033[36m输入数字可管理对应提供者\033[0m" echo -e "\033[36m输入数字可管理对应提供者\033[0m"
cat "$CRASHDIR"/configs/providers.cfg "$CRASHDIR"/configs/providers_uri.cfg 2>/dev/null | cat "$CRASHDIR"/configs/providers.cfg "$CRASHDIR"/configs/providers_uri.cfg 2>/dev/null |
@@ -48,10 +48,10 @@ set_core_config() {
. "$CRASHDIR"/menus/providers.sh . "$CRASHDIR"/menus/providers.sh
providers providers
else else
error_report "\033[33m仅限Mihomo/singboxr内核使用,请更换内核!\033[0m" msg_alert "\033[33m仅限Mihomo/singboxr内核使用,请更换内核!\033[0m"
fi fi
else else
error_report "请先添加提供者!" msg_alert "请先添加提供者!"
fi fi
;; ;;
c) c)
@@ -59,7 +59,7 @@ set_core_config() {
. "$CRASHDIR"/menus/subconverter.sh . "$CRASHDIR"/menus/subconverter.sh
subconverter subconverter
else else
error_report "请先添加提供者!" msg_alert "请先添加提供者!"
fi fi
;; ;;
d) d)
@@ -114,7 +114,7 @@ setproviders() {
[ -z "$ua" ] && ua='clash.meta' [ -z "$ua" ] && ua='clash.meta'
while true; do while true; do
link_info=$(echo "$link$link_uri" | cut -c 1-30) link_info=$(echo "$link$link_uri" | cut -c 1-30)
format_box "\033[36m支持添加订阅链接/分享链接/本地文件作为提供者\033[0m" comp_box "\033[36m支持添加订阅链接/分享链接/本地文件作为提供者\033[0m"
content_line "1) 设置\033[36m名称或代号\033[0m \033[32m$name\033[0m" content_line "1) 设置\033[36m名称或代号\033[0m \033[32m$name\033[0m"
content_line "2) 设置\033[32m链接或路径\033[0m \033[36m$link_info...\033[0m" content_line "2) 设置\033[32m链接或路径\033[0m \033[36m$link_info...\033[0m"
[ -n "$link" ] && { [ -n "$link" ] && {
@@ -338,7 +338,7 @@ addproviders() {
echo "$name $link_uri" >>"$CRASHDIR"/configs/providers_uri.cfg echo "$name $link_uri" >>"$CRASHDIR"/configs/providers_uri.cfg
return 0 return 0
else else
error_report "\033[31m请先完成必填选项\033[0m" msg_alert "\033[31m请先完成必填选项\033[0m"
return 1 return 1
fi fi
} }

View File

@@ -3,13 +3,13 @@
check_port() { check_port() {
if [ "$1" -gt 65535 ] || [ "$1" -le 1 ]; then if [ "$1" -gt 65535 ] || [ "$1" -le 1 ]; then
echo -e "\033[31m输入错误请输入正确的数值(1-65535)\033[0m" msg_alert "\033[31m输入错误请输入正确的数值(1-65535)\033[0m"
return 1 return 1
elif echo "|$mix_port|$redir_port|$dns_port|$db_port|" | grep -q "|$1|"; then elif echo "|$mix_port|$redir_port|$dns_port|$db_port|" | grep -q "|$1|"; then
echo -e "\033[31m输入错误请不要输入重复的端口\033[0m" msg_alert "\033[31m输入错误请不要输入重复的端口\033[0m"
return 1 return 1
elif netstat -ntul | grep -q ":$1[[:space:]]"; then elif netstat -ntul | grep -q ":$1[[:space:]]"; then
echo -e "\033[31m当前端口已被其他进程占用请重新输入\033[0m" msg_alert "\033[31m当前端口已被其他进程占用请重新输入\033[0m"
return 1 return 1
else else
return 0 return 0

View File

@@ -1,12 +1,23 @@
error_report() { msg_alert() {
# Default sleep time
_sleep_time=1
if [ "$1" = "-t" ] && [ -n "$2" ]; then
_sleep_time="$2"
shift 2
fi
line_break line_break
separator_line "=" separator_line "="
content_line "\033[31m$1\033[0m" for line in "$@"; do
content_line "$line"
done
separator_line "=" separator_line "="
sleep 1 sleep "$_sleep_time"
} }
format_box() { # complete box
comp_box() {
line_break line_break
separator_line "=" separator_line "="
for line in "$@"; do for line in "$@"; do
@@ -15,21 +26,31 @@ format_box() {
separator_line "=" separator_line "="
} }
# bottom box
btm_box() {
for line in "$@"; do
content_line "$line"
done
separator_line "="
}
# =================================================
common_back() { common_back() {
content_line "0) $COMMON_BACK" content_line "0) $COMMON_BACK"
separator_line "=" separator_line "="
} }
errornum() { errornum() {
error_report "\033[31m$COMMON_ERR_NUM\033[0m" msg_alert "\033[31m$COMMON_ERR_NUM\033[0m"
} }
error_letter() { error_letter() {
error_report "\033[31m$COMMON_ERR_LETTER\033[0m" msg_alert "\033[31m$COMMON_ERR_LETTER\033[0m"
} }
error_input() { error_input() {
error_report "\033[31m$COMMON_ERR_INPUT\033[0m" msg_alert "\033[31m$COMMON_ERR_INPUT\033[0m"
} }
error_cancel() { error_cancel() {

View File

@@ -17,17 +17,18 @@ set_dns_mod() {
content_line "$DNS_CURRENT_MODE\033[47;30m $dns_mod \033[0m" content_line "$DNS_CURRENT_MODE\033[47;30m $dns_mod \033[0m"
content_line "\033[33m$DNS_RESTART_NOTICE\033[0m" content_line "\033[33m$DNS_RESTART_NOTICE\033[0m"
separator_line "=" separator_line "="
content_line "1) MIX$COMMON_MOD\t\033[32m$DNS_MODE_MIX_DESC\033[0m" content_line "1) 设为MIX$COMMON_MOD\t\033[32m$DNS_MODE_MIX_DESC\033[0m"
content_line "2) Route$COMMON_MOD\t\033[32m$DNS_MODE_ROUTE_DESC\033[0m" content_line "2) 设为Route$COMMON_MOD\t\033[32m$DNS_MODE_ROUTE_DESC\033[0m"
content_line "3) Redir$COMMON_MOD\t\033[33m$DNS_MODE_REDIR_DESC\033[0m" content_line "3) 设为Redir$COMMON_MOD\t\033[33m$DNS_MODE_REDIR_DESC\033[0m"
content_line "" content_line ""
content_line "4) $DNS_MENU_PROTECT\t\033[36m$dns_protect\033[0m\t$DNS_PROTECT_DESC" content_line "4) $DNS_MENU_PROTECT\t \033[36m$dns_protect\033[0m\t$DNS_PROTECT_DESC"
content_line "5) $DNS_MENU_HOSTS\t\033[36m$hosts_opt\033[0m\t$DNS_HOSTS_DESC" content_line "5) $DNS_MENU_HOSTS\t \033[36m$hosts_opt\033[0m\t$DNS_HOSTS_DESC"
content_line "6) $DNS_MENU_ECS\t\033[36m$ecs_subnet\033[0m\t$DNS_ECS_DESC" content_line "6) $DNS_MENU_ECS\t \033[36m$ecs_subnet\033[0m\t$DNS_ECS_DESC"
content_line "7) $DNS_MENU_REDIR\033[36m$dns_redir_port\033[0m\t$DNS_REDIR_PORT_DESC" content_line "7) $DNS_MENU_REDIR\033[36m$dns_redir_port\033[0m\t$DNS_REDIR_PORT_DESC"
[ "$dns_mod" = "mix" ] && [ "$dns_mod" = "mix" ] &&
content_line "8) \033[33m$DNS_FAKEIP_MENU\033[0m" content_line "8) \033[33m$DNS_FAKEIP_MENU\033[0m"
content_line "9) \033[36m$DNS_ADV_MENU\033[0m" content_line "9) \033[36m$DNS_ADV_MENU\033[0m"
content_line ""
content_line "0) $COMMON_BACK" content_line "0) $COMMON_BACK"
separator_line "=" separator_line "="
read -r -p "$COMMON_INPUT> " num read -r -p "$COMMON_INPUT> " num

View File

@@ -12,25 +12,28 @@ set_fw_filter() {
[ -z "$cn_ip_route" ] && cn_ip_route=OFF [ -z "$cn_ip_route" ] && cn_ip_route=OFF
touch "$CRASHDIR"/configs/mac "$CRASHDIR"/configs/ip_filter touch "$CRASHDIR"/configs/mac "$CRASHDIR"/configs/ip_filter
[ -z "$(cat "$CRASHDIR"/configs/mac "$CRASHDIR"/configs/ip_filter 2>/dev/null)" ] && mac_return=OFF || mac_return=ON [ -z "$(cat "$CRASHDIR"/configs/mac "$CRASHDIR"/configs/ip_filter 2>/dev/null)" ] && mac_return=OFF || mac_return=ON
echo "-----------------------------------------------" line_break
echo -e " 1 过滤非常用端口: \033[36m$common_ports\033[0m ————用于过滤P2P流量" separator_line "="
echo -e " 2 过滤局域网设备: \033[36m$mac_return\033[0m ———使用黑/白名单进行过滤" content_line "1) 过滤非常用端口: \033[36m$common_ports\033[0m ———用于过滤P2P流量"
echo -e " 3 过滤QUIC协议: \033[36m$quic_rj\033[0m ————优化视频性能" content_line "2) 过滤局域网设备: \033[36m$mac_return\033[0m ———使用黑/白名单进行过滤"
echo -e " 4 过滤CN_IP(4/6)列表: \033[36m$cn_ip_route\033[0m ———优化性能" content_line "3) 过滤QUIC协议 \033[36m$quic_rj\033[0m ———优化视频性能"
echo -e " 5 自定义透明路由ipv4网段: 适合vlan等复杂网络环境" content_line "4) 过滤CN_IP(4/6)列表:\033[36m$cn_ip_route\033[0m ———优化性能"
echo -e " 6 自定义保留地址ipv4网段: 需要以保留地址为访问目标的环境" content_line "5) 自定义透明路由ipv4网段适合vlan等复杂网络环境"
echo "-----------------------------------------------" content_line "6) 自定义保留地址ipv4网段需要以保留地址为访问目标的环境"
echo -e " 0 返回上级菜单 \033[0m" content_line ""
echo "-----------------------------------------------" common_back
read -r -p "请输入对应数字 > " num read -r -p "$COMMON_INPUT> " num
case "$num" in case "$num" in
"" | 0) "" | 0)
break break
;; ;;
1) 1)
echo "-----------------------------------------------"
if [ -n "$(pidof CrashCore)" ] && [ "$firewall_mod" = 'iptables' ]; then if [ -n "$(pidof CrashCore)" ] && [ "$firewall_mod" = 'iptables' ]; then
read -r -p "切换时将停止服务,是否继续(1/0) > " res comp_box "切换时将停止服务,是否继续"
content_line "1) 是"
content_line "0) 否,返回上级菜单"
separator_line "="
read -r -p "$COMMON_INPUT> " res
[ "$res" = 1 ] && "$CRASHDIR"/start.sh stop && set_common_ports [ "$res" = 1 ] && "$CRASHDIR"/start.sh stop && set_common_ports
else else
set_common_ports set_common_ports
@@ -45,60 +48,65 @@ set_fw_filter() {
fi fi
;; ;;
3) 3)
echo "-----------------------------------------------"
if echo "$redir_mod" | grep -oqE '混合|Tproxy|Tun'; then if echo "$redir_mod" | grep -oqE '混合|Tproxy|Tun'; then
if [ "$quic_rj" = "OFF" ]; then if [ "$quic_rj" = "OFF" ]; then
echo -e "\033[33m已禁止QUIC流量通过ShellCrash内核\033[0m"
quic_rj=ON quic_rj=ON
msg_alert "\033[33m已禁止QUIC流量通过ShellCrash内核\033[0m"
else else
echo -e "\033[33m已取消禁止QUIC协议流量\033[0m"
quic_rj=OFF quic_rj=OFF
msg_alert "\033[33m已取消禁止QUIC协议流量\033[0m"
fi fi
setconfig quic_rj $quic_rj setconfig quic_rj $quic_rj
else else
echo -e "\033[33m当前模式默认不会代理UDP流量无需设置\033[0m" msg_alert "\033[33m当前模式默认不会代理UDP流量无需设置\033[0m"
fi fi
sleep 1
;; ;;
4) 4)
if [ -n "$(ipset -v 2>/dev/null)" ] || [ "$firewall_mod" = 'nftables' ]; then if [ -n "$(ipset -v 2>/dev/null)" ] || [ "$firewall_mod" = 'nftables' ]; then
if [ "$cn_ip_route" = "OFF" ]; then if [ "$cn_ip_route" = "OFF" ]; then
echo -e "\033[32m已开启CN_IP绕过内核功能\033[0m"
echo -e "\033[31m注意此功能会导致全局模式及一切CN相关规则失效\033[0m"
cn_ip_route=ON cn_ip_route=ON
sleep 2 msg_alert -t 2 "\033[32m已开启CN_IP绕过内核功能\033[0m" \
"\033[31m注意此功能会导致全局模式及一切CN相关规则失效\033[0m"
else else
echo -e "\033[33m已禁用CN_IP绕过内核功能\033[0m"
cn_ip_route=OFF cn_ip_route=OFF
msg_alert "\033[33m已禁用CN_IP绕过内核功能\033[0m"
fi fi
setconfig cn_ip_route $cn_ip_route setconfig cn_ip_route $cn_ip_route
else else
echo -e "\033[31m当前设备缺少ipset模块或未使用nftables模式无法启用绕过功能\033[0m" msg_alert "\033[31m当前设备缺少ipset模块或未使用nftables模式无法启用绕过功能\033[0m"
sleep 1
fi fi
;; ;;
5) 5)
set_cust_host_ipv4 set_cust_host_ipv4
;; ;;
6) 6)
[ -z "$reserve_ipv4" ] && reserve_ipv4="0.0.0.0/8 10.0.0.0/8 127.0.0.0/8 100.64.0.0/10 169.254.0.0/16 172.16.0.0/12 192.168.0.0/16 224.0.0.0/4 240.0.0.0/4" while true; do
echo -e "当前网段:\033[36m$reserve_ipv4\033[0m" [ -z "$reserve_ipv4" ] && reserve_ipv4="0.0.0.0/8 10.0.0.0/8 127.0.0.0/8 100.64.0.0/10 169.254.0.0/16 172.16.0.0/12 192.168.0.0/16 224.0.0.0/4 240.0.0.0/4"
echo -e "\033[33m地址必须是空格分隔错误的设置可能导致网络回环或启动报错请务必谨慎\033[0m" comp_box "\033[33m注意:地址必须是空格分隔,错误的设置可能导致网络回环或启动报错,请务必谨慎!\033[0m" \
read -p "请输入 > " text "" \
if "当前网段:" \
echo "$text" | grep -Eq "(((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])/(3[0-2]|[1-2]?[0-9]))( +|$)+" "\033[36m$reserve_ipv4\033[0m"
then btm_box "请直接输入自定义保留地址ipv4网段" \
reserve_ipv4="$text" "或输入 0 返回上级菜单"
echo -e "已将保留地址网段设为:\033[32m$reserve_ipv4\033[0m" read -r -p "请输入> " text
setconfig reserve_ipv4 "'$reserve_ipv4'" if [ "$text" = 0 ]; then
else break
echo -e "\033[31m输入有误操作已取消\033[0m" elif
fi echo "$text" | grep -Eq "(((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])/(3[0-2]|[1-2]?[0-9]))( +|$)+"
sleep 1 then
reserve_ipv4="$text"
if setconfig reserve_ipv4 "'$reserve_ipv4'"; then
msg_alert "已将保留地址网段设为:\033[32m$reserve_ipv4\033[0m"
else
msg_alert "\033[31m$COMMON_FAILED\033[0m"
fi
else
msg_alert "\033[31m输入有误请重新输入\033[0m"
fi
done
;; ;;
*) *)
errornum errornum
sleep 1
;; ;;
esac esac
done done
@@ -107,19 +115,22 @@ set_fw_filter() {
set_common_ports() { set_common_ports() {
while true; do while true; do
[ -z "$multiport" ] && multiport='22,80,443,8080,8443' [ -z "$multiport" ] && multiport='22,80,443,8080,8443'
echo "-----------------------------------------------" line_break
echo -e "\033[31m注意\033[0mMIX模式下所有fake-ip来源的非常用端口流量不会被过滤" separator_line "="
[ -n "$common_ports" ] && content_line "\033[31m注意\n\033[0mMIX模式下所有fake-ip来源的非常用端口流量不会被过滤"
echo -e "当前放行端口:\033[36m$multiport\033[0m" if [ -n "$common_ports" ]; then
echo "-----------------------------------------------" content_line ""
echo -e " 1 启用/关闭端口过滤: \033[36m$common_ports\033[0m" content_line "当前已放行端口:\033[36m$multiport\033[0m"
echo -e " 2 添加放行端口" fi
echo -e " 3 移除指定放行端口" separator_line "="
echo -e " 4 重置默认放行端口" content_line "1) 启用/关闭端口过滤: \033[36m$common_ports\033[0m"
echo -e " 5 重置为旧版放行端口" content_line "2) 添加放行端口"
echo -e " 0 返回上级菜单" content_line "3) 移除指定放行端口"
echo "-----------------------------------------------" content_line "4) 重置默认放行端口"
read -r -p "请输入对应数字 > " num content_line "5) 重置为旧版放行端口"
content_line ""
common_back
read -r -p "$COMMON_INPUT> " num
case "$num" in case "$num" in
"" | 0) "" | 0)
break break
@@ -130,52 +141,83 @@ set_common_ports() {
else else
common_ports=ON common_ports=ON
fi fi
setconfig common_ports "$common_ports"
if setconfig common_ports "$common_ports"; then
msg_alert "\033[32m$COMMON_SUCCESS\033[0m"
else
msg_alert "\033[31m$COMMON_FAILED\033[0m"
fi
;; ;;
2) 2)
port_count=$(echo "$multiport" | awk -F',' '{print NF}') while true; do
if [ "$port_count" -ge 15 ]; then port_count=$(echo "$multiport" | awk -F',' '{print NF}')
echo -e "\033[31m最多支持设置放行15个端口请先减少一些\033[0m" if [ "$port_count" -ge 15 ]; then
else comp_box "\033[31m最多支持设置放行15个端口请先减少一些\033[0m"
read -r -p "请输入要放行的端口号 > " port
if echo ",$multiport," | grep -q ",$port,"; then
echo -e "\033[31m输入错误请勿重复添加\033[0m"
elif [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
echo -e "\033[31m输入错误请输入正确的数值(1-65535)\033[0m"
else else
multiport=$(echo "$multiport,$port" | sed "s/^,//") comp_box "当前已放行端口:\033[36m$multiport\033[0m"
setconfig multiport "$multiport" btm_box "请直接输入要放行的端口号\n每次只能输入一个端口号切勿一次添加多个端口号" \
"或输入 0 返回上级菜单"
read -r -p "请输入> " port
if [ "$port" = 0 ]; then
break
elif echo ",$multiport," | grep -q ",$port,"; then
msg_alert "\033[31m输入错误请勿重复添加\033[0m"
elif [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
msg_alert "\033[31m输入错误请输入正确的数值165535\033[0m"
else
multiport=$(echo "$multiport,$port" | sed "s/^,//")
if setconfig multiport "$multiport"; then
msg_alert "\033[32m$COMMON_SUCCESS\033[0m"
else
msg_alert "\033[31m$COMMON_FAILED\033[0m"
fi
fi
fi fi
fi done
sleep 1
;; ;;
3) 3)
read -r -p "请输入要移除的端口号 > " port while true; do
if echo ",$multiport," | grep -q ",$port,"; then comp_box "当前已放行端口:\033[36m$multiport\033[0m"
if [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then btm_box "请直接输入要移除的端口号\n每次只能输入一个端口号切勿一次添加多个端口号" \
echo -e "\033[31m输入错误请输入正确的数值(1-65535)\033[0m" "或输入 0 返回上级菜单"
read -r -p "请输入> " port
if [ "$port" = 0 ]; then
break
elif echo ",$multiport," | grep -q ",$port,"; then
if [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
msg_alert "\033[31m输入错误请输入正确的数值165535\033[0m"
else
multiport=$(echo ",$multiport," | sed "s/,$port//; s/^,//; s/,$//")
if setconfig multiport "$multiport"; then
msg_alert "\033[32m$COMMON_SUCCESS\033[0m"
else
msg_alert "\033[31m$COMMON_FAILED\033[0m"
fi
fi
else else
multiport=$(echo ",$multiport," | sed "s/,$port//; s/^,//; s/,$//") msg_alert "\033[31m输入错误请输入已添加过的端口\033[0m"
setconfig multiport "$multiport"
fi fi
else done
echo -e "\033[31m输入错误请输入已添加过的端口\033[0m"
fi
sleep 1
;; ;;
4) 4)
multiport='' multiport=''
setconfig multiport if setconfig multiport; then
sleep 1 msg_alert "\033[32m$COMMON_SUCCESS\033[0m"
else
msg_alert "\033[31m$COMMON_FAILED\033[0m"
fi
;; ;;
5) 5)
multiport='22,80,143,194,443,465,587,853,993,995,5222,8080,8443' multiport='22,80,143,194,443,465,587,853,993,995,5222,8080,8443'
setconfig multiport "$multiport" if setconfig multiport "$multiport"; then
sleep 1 msg_alert "\033[32m$COMMON_SUCCESS\033[0m"
else
msg_alert "\033[31m$COMMON_FAILED\033[0m"
fi
;; ;;
*) *)
errornum errornum
sleep 1
;; ;;
esac esac
done done
@@ -186,39 +228,48 @@ set_cust_host_ipv4() {
while true; do while true; do
[ -z "$replace_default_host_ipv4" ] && replace_default_host_ipv4="OFF" [ -z "$replace_default_host_ipv4" ] && replace_default_host_ipv4="OFF"
. "$CRASHDIR"/starts/fw_getlanip.sh && getlanip . "$CRASHDIR"/starts/fw_getlanip.sh && getlanip
echo "-----------------------------------------------" comp_box "当前默认透明路由的网段为:\033[32m$host_ipv4\033[0m" \
echo -e "当前默认透明路由的网段为: \033[32m$host_ipv4 \033[0m" "当前已添加的自定义网段为\033[36m$cust_host_ipv4\033[0m"
echo -e "当前已添加的自定义网段为:\033[36m$cust_host_ipv4\033[0m" content_line "1) 移除所有自定义网段"
echo "-----------------------------------------------" content_line "2) 使用自定义网段覆盖默认网段 \033[36m$replace_default_host_ipv4\033[0m"
echo -e " 1 移除所有自定义网段" common_back
echo -e " 2 使用自定义网段覆盖默认网段 \033[36m$replace_default_host_ipv4\033[0m" read -r -p "请输入对应的序号或需要额外添加的网段> " text
echo -e " 0 返回上级菜单"
read -r -p "请输入对应的序号或需要额外添加的网段 > " text
case "$text" in case "$text" in
"" | 0) "" | 0)
break break
;; ;;
1) 1)
unset cust_host_ipv4 unset cust_host_ipv4
setconfig cust_host_ipv4 if setconfig cust_host_ipv4; then
msg_alert "\033[32m$COMMON_SUCCESS\033[0m"
else
msg_alert "\033[31m$COMMON_FAILED\033[0m"
fi
;; ;;
2) 2)
if [ "$replace_default_host_ipv4" == "OFF" ]; then if [ "$replace_default_host_ipv4" = "OFF" ]; then
replace_default_host_ipv4="ON" replace_default_host_ipv4="ON"
else else
replace_default_host_ipv4="OFF" replace_default_host_ipv4="OFF"
fi fi
setconfig replace_default_host_ipv4 "$replace_default_host_ipv4"
if setconfig replace_default_host_ipv4 "$replace_default_host_ipv4"; then
msg_alert "\033[32m$COMMON_SUCCESS\033[0m"
else
msg_alert "\033[31m$COMMON_FAILED\033[0m"
fi
;; ;;
*) *)
if [ -n "$(echo "$text" | grep -Eo '^([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]{1,2}'$)" ] && [ -z "$(echo "$cust_host_ipv4" | grep "$text")" ]; then if [ -n "$(echo "$text" | grep -Eo '^([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]{1,2}'$)" ] && echo "$cust_host_ipv4" | grep -q "$text"; then
cust_host_ipv4="$cust_host_ipv4 $text" cust_host_ipv4="$cust_host_ipv4 $text"
setconfig cust_host_ipv4 "'$cust_host_ipv4'" if setconfig cust_host_ipv4 "'$cust_host_ipv4'"; then
msg_alert "\033[32m$COMMON_SUCCESS\033[0m"
else
msg_alert "\033[31m$COMMON_FAILED\033[0m"
fi
else else
echo "-----------------------------------------------" msg_alert "\033[31m请输入正确的网段地址\033[0m"
echo -e "\033[31m请输入正确的网段地址\033[0m"
fi fi
sleep 1
;; ;;
esac esac
done done
@@ -234,17 +285,31 @@ fw_filter_lan() {
add_mac() { add_mac() {
while true; do while true; do
echo "-----------------------------------------------" comp_box "手动输入mac地址时仅支持\033[32mxx:xx:xx:xx:xx:xx\033[0m的形式"
echo "已添加的mac地址" content_line "已添加的mac地址"
cat "$CRASHDIR"/configs/mac 2>/dev/null content_line ""
echo "-----------------------------------------------" if [ -s "$CRASHDIR/configs/mac" ]; then
echo -e "\033[33m序号 设备IP 设备mac地址 设备名称\033[32m" while IFS= read -r line; do
cat "$dhcpdir" | awk '{print " "NR" "$3,$2,$4}' content_line "$line"
echo -e "\033[0m-----------------------------------------------" done <"$CRASHDIR/configs/mac"
echo -e "手动输入mac地址时仅支持\033[32mxx:xx:xx:xx:xx:xx\033[0m的形式" else
echo -e " 0 或回车 结束添加" content_line "暫未添加任何mac地址"
echo "-----------------------------------------------" fi
read -r -p "请输入对应序号或直接输入mac地址 > " num
separator_line "="
content_line "序号 \033[33m设备IP 设备mac地址 设备名称\033[0m"
if [ -s "$dhcpdir" ]; then
awk '{print NR") "$3,$2,$4}' "$dhcpdir" |
while IFS= read -r line; do
content_line "$line"
done
else
content_line "无纪录"
fi
content_line ""
common_back
read -r -p "请输入对应序号或直接输入mac地址> " num
if [ -z "$num" ] || [ "$num" = 0 ]; then if [ -z "$num" ] || [ "$num" = 0 ]; then
i= i=
break break
@@ -252,41 +317,49 @@ fw_filter_lan() {
if [ -z "$(cat "$CRASHDIR"/configs/mac | grep -E "$num")" ]; then if [ -z "$(cat "$CRASHDIR"/configs/mac | grep -E "$num")" ]; then
echo "$num" | grep -oE '^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$' >>"$CRASHDIR"/configs/mac echo "$num" | grep -oE '^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$' >>"$CRASHDIR"/configs/mac
else else
echo "-----------------------------------------------" msg_alert "\033[31m已添加的设备请勿重复添加\033[0m"
echo -e "\033[31m已添加的设备请勿重复添加\033[0m"
sleep 1
fi fi
elif [ "$num" -le $(cat $dhcpdir 2>/dev/null | awk 'END{print NR}') ]; then elif [ "$num" -le $(cat $dhcpdir 2>/dev/null | awk 'END{print NR}') ]; then
macadd=$(cat "$dhcpdir" | awk '{print $2}' | sed -n "$num"p) macadd=$(cat "$dhcpdir" | awk '{print $2}' | sed -n "$num"p)
if [ -z "$(cat "$CRASHDIR"/configs/mac | grep -E "$macadd")" ]; then if [ -z "$(cat "$CRASHDIR"/configs/mac | grep -E "$macadd")" ]; then
echo "$macadd" >>"$CRASHDIR"/configs/mac echo "$macadd" >>"$CRASHDIR"/configs/mac
else else
echo "-----------------------------------------------" msg_alert "\033[31m已添加的设备请勿重复添加\033[0m"
echo -e "\033[31m已添加的设备请勿重复添加\033[0m"
sleep 1
fi fi
else else
echo "-----------------------------------------------" msg_alert "\033[31m输入有误请重新输入\033[0m"
echo -e "\033[31m输入有误请重新输入\033[0m"
sleep 1
fi fi
done done
} }
add_ip() { add_ip() {
while true; do while true; do
echo "-----------------------------------------------" comp_box "手动输入时仅支持 \033[32m192.168.1.0/24\033[0m 或 \033[32m192.168.1.0\033[0m 的形式" \
echo "已添加的IP地址(段)" "不支持ipv6地址过滤如有需求请使用mac地址过滤"
cat "$CRASHDIR"/configs/ip_filter 2>/dev/null content_line "已添加的IP地址"
echo "-----------------------------------------------" content_line ""
echo -e "\033[33m序号 设备IP 设备名称\033[32m" if [ -s "$CRASHDIR/configs/ip_filter" ]; then
cat "$dhcpdir" | awk '{print " "NR" "$3,$4}' while IFS= read -r line; do
echo -e "\033[0m-----------------------------------------------" content_line "$line"
echo -e "手动输入时仅支持\033[32m 192.168.1.0/24\033[0m 或 \033[32m192.168.1.0\033[0m 的形式" done <"$CRASHDIR/configs/ip_filter"
echo -e "不支持ipv6地址过滤如有需求请使用mac地址过滤" else
echo -e " 0 或回车 结束添加" content_line "暫未添加任何IP地址"
echo "-----------------------------------------------" fi
read -r -p "请输入对应序号或直接输入IP地址段 > " num
separator_line "="
content_line "\033[33m序号 设备IP 设备名称\033[32m"
if [ -s "$dhcpdir" ]; then
awk '{print NR") "$3, $4}' "$dhcpdir" |
while IFS= read -r line; do
content_line "$line"
done
else
content_line "无纪录"
fi
content_line ""
common_back
read -r -p "请输入对应序号或直接输入IP地址段> " num
if [ -z "$num" ] || [ "$num" = 0 ]; then if [ -z "$num" ] || [ "$num" = 0 ]; then
i= i=
break break
@@ -294,45 +367,39 @@ fw_filter_lan() {
if [ -z "$(cat "$CRASHDIR"/configs/ip_filter | grep -E "$num")" ]; then if [ -z "$(cat "$CRASHDIR"/configs/ip_filter | grep -E "$num")" ]; then
echo "$num" | grep -oE '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(/(3[0-2]|[12]?[0-9]))?$' >>"$CRASHDIR"/configs/ip_filter echo "$num" | grep -oE '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(/(3[0-2]|[12]?[0-9]))?$' >>"$CRASHDIR"/configs/ip_filter
else else
echo "-----------------------------------------------" msg_alert "\033[31m已添加的地址请勿重复添加\033[0m"
echo -e "\033[31m已添加的地址请勿重复添加\033[0m"
sleep 1
fi fi
elif [ "$num" -le "$(cat "$dhcpdir" 2>/dev/null | awk 'END{print NR}')" ]; then elif [ "$num" -le "$(cat "$dhcpdir" 2>/dev/null | awk 'END{print NR}')" ]; then
ipadd=$(cat "$dhcpdir" | awk '{print $3}' | sed -n "$num"p) ipadd=$(cat "$dhcpdir" | awk '{print $3}' | sed -n "$num"p)
if [ -z "$(cat "$CRASHDIR"/configs/mac | grep -E "$ipadd")" ]; then if [ -z "$(cat "$CRASHDIR"/configs/mac | grep -E "$ipadd")" ]; then
echo "$ipadd" >>"$CRASHDIR"/configs/ip_filter echo "$ipadd" >>"$CRASHDIR"/configs/ip_filter
else else
echo "-----------------------------------------------" msg_alert "\033[31m已添加的地址请勿重复添加\033[0m"
echo -e "\033[31m已添加的地址请勿重复添加\033[0m"
sleep 1
fi fi
else else
echo "-----------------------------------------------" msg_alert "\033[31m输入有误请重新输入\033[0m"
echo -e "\033[31m输入有误请重新输入\033[0m"
sleep 1
fi fi
done done
} }
del_all() { del_all() {
while true; do while true; do
echo "-----------------------------------------------"
if [ -z "$(cat "$CRASHDIR"/configs/mac "$CRASHDIR"/configs/ip_filter 2>/dev/null)" ]; then if [ -z "$(cat "$CRASHDIR"/configs/mac "$CRASHDIR"/configs/ip_filter 2>/dev/null)" ]; then
echo -e "\033[31m列表中没有需要移除的设备\033[0m" msg_alert "\033[31m列表中没有需要移除的设备\033[0m"
sleep 1 break
else else
echo -e "请选择需要移除的设备:\033[36m" comp_box "请选择需要移除的设备:"
echo -e "\033[33m 设备IP 设备mac地址 设备名称\033[0m" content_line " \033[32m设备IP \033[36m设备mac地址 \033[35m设备名称\033[0m"
i=1 i=1
for dev in $(cat "$CRASHDIR"/configs/mac "$CRASHDIR"/configs/ip_filter 2>/dev/null); do for dev in $(cat "$CRASHDIR"/configs/mac "$CRASHDIR"/configs/ip_filter 2>/dev/null); do
get_devinfo get_devinfo
echo -e " $i \033[32m$dev_ip \033[36m$dev_mac \033[32m$dev_name\033[0m" content_line "$(printf "%s) \033[32m%-18s \033[36m%-18s \033[35m%s\033[0m" \
"$i" "$dev_ip" "$dev_mac" "$dev_name")"
i=$((i + 1)) i=$((i + 1))
done done
echo "-----------------------------------------------" content_line ""
echo -e "\033[0m 0 或回车 结束删除" common_back
read -r -p "请输入需要移除的设备的对应序号 > " num read -r -p "$COMMON_INPUT> " num
mac_filter_rows=$(cat "$CRASHDIR"/configs/mac 2>/dev/null | wc -l) mac_filter_rows=$(cat "$CRASHDIR"/configs/mac 2>/dev/null | wc -l)
ip_filter_rows=$(cat "$CRASHDIR"/configs/ip_filter 2>/dev/null | wc -l) ip_filter_rows=$(cat "$CRASHDIR"/configs/ip_filter 2>/dev/null | wc -l)
if [ -z "$num" ] || [ "$num" -le 0 ]; then if [ -z "$num" ] || [ "$num" -le 0 ]; then
@@ -340,26 +407,19 @@ fw_filter_lan() {
break break
elif [ "$num" -le "$mac_filter_rows" ]; then elif [ "$num" -le "$mac_filter_rows" ]; then
sed -i "${num}d" "$CRASHDIR"/configs/mac sed -i "${num}d" "$CRASHDIR"/configs/mac
echo "-----------------------------------------------" msg_alert "\033[32m对应设备已移除\033[0m"
echo -e "\033[32m对应设备已移除\033[0m"
sleep 1
elif [ "$num" -le $((mac_filter_rows + ip_filter_rows)) ]; then elif [ "$num" -le $((mac_filter_rows + ip_filter_rows)) ]; then
num=$((num - mac_filter_rows)) num=$((num - mac_filter_rows))
sed -i "${num}d" "$CRASHDIR"/configs/ip_filter sed -i "${num}d" "$CRASHDIR"/configs/ip_filter
echo "-----------------------------------------------" msg_alert "\033[32m对应设备已移除\033[0m"
echo -e "\033[32m对应设备已移除\033[0m"
sleep 1
else else
echo "-----------------------------------------------" msg_alert "\033[31m输入有误请重新输入\033[0m"
echo -e "\033[31m输入有误请重新输入\033[0m"
sleep 1
fi fi
fi fi
done done
} }
while true; do while true; do
echo "-----------------------------------------------"
[ -z "$dhcpdir" ] && [ -f /var/lib/dhcp/dhcpd.leases ] && dhcpdir='/var/lib/dhcp/dhcpd.leases' [ -z "$dhcpdir" ] && [ -f /var/lib/dhcp/dhcpd.leases ] && dhcpdir='/var/lib/dhcp/dhcpd.leases'
[ -z "$dhcpdir" ] && [ -f /var/lib/dhcpd/dhcpd.leases ] && dhcpdir='/var/lib/dhcpd/dhcpd.leases' [ -z "$dhcpdir" ] && [ -f /var/lib/dhcpd/dhcpd.leases ] && dhcpdir='/var/lib/dhcpd/dhcpd.leases'
[ -z "$dhcpdir" ] && [ -f /tmp/dhcp.leases ] && dhcpdir='/tmp/dhcp.leases' [ -z "$dhcpdir" ] && [ -f /tmp/dhcp.leases ] && dhcpdir='/tmp/dhcp.leases'
@@ -374,39 +434,45 @@ fw_filter_lan() {
fw_filter_lan_scrip='' fw_filter_lan_scrip=''
fi fi
echo -e "\033[30;47m请在此添加或移除设备\033[0m" comp_box "\033[30;47m请在此添加或移除设备\033[0m" \
echo -e "当前过滤方式为:\033[33m$fw_filter_lan_type模式\033[0m" "" \
echo -e "仅列表内设备流量\033[36m$fw_filter_lan_scrip经过\033[0m内核" "当前过滤方式为:\033[33m$fw_filter_lan_type模式\033[0m" \
"仅列表内设备流量\033[36m$fw_filter_lan_scrip经过\033[0m内核"
if [ -n "$(cat "$CRASHDIR"/configs/mac)" ]; then if [ -n "$(cat "$CRASHDIR"/configs/mac)" ]; then
echo "-----------------------------------------------" content_line "当前已过滤设备为:"
echo -e "当前已过滤设备为:\033[36m" content_line ""
echo -e "\033[33m 设备mac/ip地址 设备名称\033[0m" content_line " \033[36m设备mac/ip地址\033[0m \033[35m设备名称\033[0m"
for dev in $(cat "$CRASHDIR"/configs/mac 2>/dev/null); do for dev in $(cat "$CRASHDIR"/configs/mac 2>/dev/null); do
get_devinfo get_devinfo
echo -e "\033[36m$dev_mac \033[0m$dev_name" content_line "$(printf "\033[36m%-20s \033[35m%s\033[0m" \
"$dev_mac" "$dev_name")"
done done
for dev in $(cat "$CRASHDIR"/configs/ip_filter 2>/dev/null); do for dev in $(cat "$CRASHDIR"/configs/ip_filter 2>/dev/null); do
get_devinfo get_devinfo
echo -e "\033[32m$dev_ip \033[0m$dev_name" content_line "$(printf "\033[36m%-20s \033[35m%s\033[0m" \
"$dev_ip" "$dev_name")"
done done
echo "-----------------------------------------------" separator_line "="
fi fi
echo -e " 1 切换为\033[33m$fw_filter_lan_over模式\033[0m" content_line "1) 切换为\033[33m$fw_filter_lan_over模式\033[0m"
echo -e " 2 \033[32m添加指定设备(mac地址)\033[0m" content_line "2) \033[32m添加指定设备mac地址\033[0m"
echo -e " 3 \033[32m添加指定设备(IP地址/网段)\033[0m" content_line "3) \033[32m添加指定设备IP地址网段\033[0m"
echo -e " 4 \033[36m移除指定设备\033[0m" content_line "4) \033[36m移除指定设备\033[0m"
echo -e " 9 \033[31m清空整个列表\033[0m" content_line "9) \033[31m清空整个列表\033[0m"
echo -e " 0 返回上级菜单" content_line ""
read -r -p "请输入对应数字 > " num common_back
read -r -p "$COMMON_INPUT> " num
case "$num" in case "$num" in
"" | 0) "" | 0)
break break
;; ;;
1) 1)
macfilter_type=$fw_filter_lan_over macfilter_type=$fw_filter_lan_over
setconfig macfilter_type $macfilter_type if setconfig macfilter_type $macfilter_type; then
echo "-----------------------------------------------" msg_alert "\033[32m已切换为$fw_filter_lan_type模式\033[0m"
echo -e "\033[32m已切换为$fw_filter_lan_type模式\033[0m" else
msg_alert "\033[31m$COMMON_FAILED\033[0m"
fi
;; ;;
2) 2)
add_mac add_mac
@@ -420,13 +486,10 @@ fw_filter_lan() {
9) 9)
: >"$CRASHDIR"/configs/mac : >"$CRASHDIR"/configs/mac
: >"$CRASHDIR"/configs/ip_filter : >"$CRASHDIR"/configs/ip_filter
echo "-----------------------------------------------" msg_alert "\033[31m设备列表已清空\033[0m"
echo -e "\033[31m设备列表已清空\033[0m"
sleep 1
;; ;;
*) *)
errornum errornum
sleep 1
;; ;;
esac esac
done done

View File

@@ -3,7 +3,7 @@
# 卸载 # 卸载
uninstall() { uninstall() {
format_box "\033[31m警告\033[0m" \ comp_box "\033[31m警告\033[0m" \
"\033[31m该操作不可逆\033" \ "\033[31m该操作不可逆\033" \
"是否确认卸载ShellCrash" "是否确认卸载ShellCrash"
content_line "1) 是" content_line "1) 是"
@@ -20,7 +20,7 @@ uninstall() {
# 移除安装目录 # 移除安装目录
if [ -n "$CRASHDIR" ] && [ "$CRASHDIR" != '/' ]; then if [ -n "$CRASHDIR" ] && [ "$CRASHDIR" != '/' ]; then
format_box "是否保留脚本配置及订阅文件:" comp_box "是否保留脚本配置及订阅文件:"
content_line "1) 是" content_line "1) 是"
content_line "0) 否" content_line "0) 否"
separator_line "=" separator_line "="
@@ -37,7 +37,7 @@ uninstall() {
rm -rf "$CRASHDIR" rm -rf "$CRASHDIR"
fi fi
else else
error_report "\033[31m环境变量配置有误请尝试手动移除安装目录\033[0m" msg_alert "\033[31m环境变量配置有误请尝试手动移除安装目录\033[0m"
fi fi
# 移除其他内容 # 移除其他内容
@@ -65,13 +65,12 @@ uninstall() {
userdel -r shellcrash 2>/dev/null userdel -r shellcrash 2>/dev/null
nvram set script_usbmount="" 2>/dev/null nvram set script_usbmount="" 2>/dev/null
nvram commit 2>/dev/null nvram commit 2>/dev/null
format_box "\033[36m已卸载ShellCrash相关文件有缘再会\033[0m" \ comp_box "\033[36m已卸载ShellCrash相关文件有缘再会\033[0m" \
"\033[33m请手动关闭当前窗口以重置环境变量\033[0m" "\033[33m请手动关闭当前窗口以重置环境变量\033[0m"
line_break line_break
sleep 1 sleep 1
exit 0 exit 0
else else
format_box "\033[31m操作已取消\033[0m" msg_alert "\033[31m操作已取消\033[0m"
sleep 1
fi fi
} }