diff --git a/package/ntlf9t/luci-app-clash/Makefile b/package/ntlf9t/luci-app-clash/Makefile index 2b16992cd5..069fdf5964 100644 --- a/package/ntlf9t/luci-app-clash/Makefile +++ b/package/ntlf9t/luci-app-clash/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-clash -PKG_VERSION:=1.6.0 +PKG_VERSION:=1.6.1 PKG_MAINTAINER:=frainzy1477 @@ -12,7 +12,7 @@ define Package/luci-app-clash CATEGORY:=LuCI SUBMENU:=3. Applications TITLE:=LuCI app for clash - DEPENDS:=+luci-base +wget +iptables +coreutils-base64 +coreutils +coreutils-nohup +bash +ipset +libustream-openssl +libopenssl +openssl-util +curl +jsonfilter +ca-certificates + DEPENDS:=+luci-base +wget +iptables +coreutils-base64 +coreutils +coreutils-nohup +bash +ipset +libustream-openssl +libopenssl +openssl-util +curl +jsonfilter +ca-certificates +iptables-mod-tproxy PKGARCH:=all MAINTAINER:=frainzy1477 endef @@ -141,10 +141,10 @@ define Package/$(PKG_NAME)/install $(INSTALL_BIN) ./root/usr/share/clash/clash.txt $(1)/usr/share/clash/ $(INSTALL_BIN) ./root/usr/share/clash/dashboard/index.html $(1)/usr/share/clash/dashboard/ - $(INSTALL_BIN) ./root/usr/share/clash/dashboard/main.f302eae39f433a9c3fa1.css $(1)/usr/share/clash/dashboard/ + $(INSTALL_BIN) ./root/usr/share/clash/dashboard/main.f42e08fe49cdc3329278.css $(1)/usr/share/clash/dashboard/ $(INSTALL_BIN) ./root/usr/share/clash/dashboard/img/33343e6117c37aaef8886179007ba6b5.png $(1)/usr/share/clash/dashboard/img/ - $(INSTALL_BIN) ./root/usr/share/clash/dashboard/js/1.bundle.f302eae39f433a9c3fa1.min.js $(1)/usr/share/clash/dashboard/js/ - $(INSTALL_BIN) ./root/usr/share/clash/dashboard/js/bundle.f302eae39f433a9c3fa1.min.js $(1)/usr/share/clash/dashboard/js/ + $(INSTALL_BIN) ./root/usr/share/clash/dashboard/js/1.bundle.f42e08fe49cdc3329278.min.js $(1)/usr/share/clash/dashboard/js/ + $(INSTALL_BIN) ./root/usr/share/clash/dashboard/js/bundle.f42e08fe49cdc3329278.min.js $(1)/usr/share/clash/dashboard/js/ $(INSTALL_BIN) ./root/usr/share/clash/yacd/* $(1)/usr/share/clash/yacd/ $(INSTALL_DATA) ./luasrc/clash.lua $(1)/usr/lib/lua/luci/ diff --git a/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/client.lua b/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/client.lua index 46d49ce5a2..9d29852012 100644 --- a/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/client.lua +++ b/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/client.lua @@ -29,6 +29,12 @@ o:value("4", translate("Clash(dTun)")) end o.description = translate("Select core, clashr support ssr while clash does not.") + +o = s:option(ListValue, "new_conf", translate("New Config(Rename fields)")) +o:value("0", translate("Disable")) +o:value("1", translate("Enable")) +o.description = translate("https://github.com/Dreamacro/clash/commit/88d8f937938d7aba774b1af638df6910b1a1a14d") + o = s:option(ListValue, "g_rules", translate("Game Rules")) o.default = "0" o:value("0", translate("Disable")) diff --git a/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/create.lua b/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/create.lua index 831a92acd7..a86811ef7a 100644 --- a/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/create.lua +++ b/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/create.lua @@ -71,6 +71,11 @@ o.title = translate("Config Name") o.rmempty = true o.description = translate("Give a name for your config") +o = s:option(ListValue, "new_conff", translate("New Config(Rename fields)")) +o:value("0", translate("Disable")) +o:value("1", translate("Enable")) +o.description = translate("https://github.com/Dreamacro/clash/commit/88d8f937938d7aba774b1af638df6910b1a1a14d") + cc = s:option(Flag, "same_tag", translate("Force Same Name")) cc.default = 1 cc.description = translate("Enable to overwrite config file") diff --git a/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/dns.lua b/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/dns.lua index 912a237673..564c740a14 100644 --- a/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/dns.lua +++ b/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/dns.lua @@ -21,6 +21,11 @@ y:value("0", translate("disabled")) y:value("1", translate("enabled")) y.description = translate("Set custom DNS forwarder in DHCP and DNS Settings and forward all dns traffic to clash") +y = s:option(ListValue, "enable_udp", translate("Enable UDP")) +y:value("0", translate("disabled")) +y:value("1", translate("enabled")) +y.description = translate("Enable udp traffic ,make sure your server support udp") + deldns = s:option(Flag, "delan", translate("Remove Lan DNS")) deldns.description = translate("Remove Lan custom DNS Servers when client is disabled") @@ -35,17 +40,16 @@ dns.datatype = "ipaddr" dns.cast = "string" dns:depends("culan", 1) -y = s:option(ListValue, "ipv6", translate("Enable ipv6")) -y:value("0", translate("disabled")) -y:value("1", translate("enabled")) -y.description = translate("Allow ipv6 traffic through clash") - md = s:option(Flag, "tun_mode", translate("Tun Mode DNS")) md.default = 0 md.description = translate("Enable Tun custom DNS and make sure you are using tun supported core") md:depends("mode", 0) +y = s:option(ListValue, "ipv6", translate("Enable ipv6")) +y:value("0", translate("disabled")) +y:value("1", translate("enabled")) +y.description = translate("Allow ipv6 traffic through clash") md = s:option(Flag, "mode", translate("Custom DNS")) md.default = 1 diff --git a/package/ntlf9t/luci-app-clash/luasrc/view/clash/status.htm b/package/ntlf9t/luci-app-clash/luasrc/view/clash/status.htm index 6fdf276f23..09b3216899 100644 --- a/package/ntlf9t/luci-app-clash/luasrc/view/clash/status.htm +++ b/package/ntlf9t/luci-app-clash/luasrc/view/clash/status.htm @@ -161,7 +161,7 @@ var HTTP = { XHR.poll(1, '<%=luci.dispatcher.build_url("admin", "services", "clash", "status")%>', null, function(x, status) { if ( x && x.status == 200 ) { web.innerHTML = status.clash ? '<%:DASHBOARD%>' : '<%:NOT RUNNING%>'; - webb.innerHTML = status.clash ? '<%:DASHBOARD%>' : '<%:NOT RUNNING%>'; + webb.innerHTML = status.clash ? '<%:DASHBOARD%>' : '<%:NOT RUNNING%>'; clash.innerHTML = status.clash ? '<%:RUNNING%> ' : '<%:NOT RUNNING%>'; ip.innerHTML = status.localip ? ''+status.localip+' ' : '<%:NOT SET%>'; port.innerHTML = status.dash_port ? ''+status.dash_port+' ' : '<%:NOT SET%>'; diff --git a/package/ntlf9t/luci-app-clash/po/zh-cn/clash.po b/package/ntlf9t/luci-app-clash/po/zh-cn/clash.po index 97ac893b52..f437afd98a 100644 --- a/package/ntlf9t/luci-app-clash/po/zh-cn/clash.po +++ b/package/ntlf9t/luci-app-clash/po/zh-cn/clash.po @@ -1025,5 +1025,11 @@ msgstr "Yacd控制面板" msgid "Enable Ping Servers" msgstr "启用Ping服务器" -msgid "DISABLED" -msgstr "禁用" +msgid "New Config(Rename fields)" +msgstr "新配置(重命名字段)" + +msgid "Enable UDP" +msgstr "启用UDP" + +msgid "Enable udp traffic ,make sure your server support udp" +msgstr "启用udp流量,服务器必须支持udp" diff --git a/package/ntlf9t/luci-app-clash/root/etc/config/clash b/package/ntlf9t/luci-app-clash/root/etc/config/clash index 586652edd2..dfaa6e22e1 100644 --- a/package/ntlf9t/luci-app-clash/root/etc/config/clash +++ b/package/ntlf9t/luci-app-clash/root/etc/config/clash @@ -28,6 +28,9 @@ config clash 'config' option auto_update_time '12' option clear_time '12' option append_rules '0' + option enable_udp '0' + option new_conf '0' + option ping_enable '1' config groups @@ -57,27 +60,11 @@ config groups option name '🔑Proxy' list other_group 'ALL' + config addtype - option type 'SRC-IP-CIDR' - option pgroup 'DIRECT' - list ipaaddr '192.168.1.4/30' + option type 'IP-CIDR' + option pgroup 'REJECT' + option ipaaddr '198.18.0.1/16' + option res '1' + -config addtype - option type 'SRC-IP-CIDR' - option pgroup 'DIRECT' - option ipaaddr '192.168.1.2/31' - -config addtype - option type 'DOMAIN-KEYWORD' - option pgroup 'DIRECT' - option ipaaddr 'baidu' - -config addtype - option type 'SRC-PORT' - option pgroup 'DIRECT' - option ipaaddr '22' - -config addtype - option type 'DST-PORT' - option pgroup 'DIRECT' - option ipaaddr '443' diff --git a/package/ntlf9t/luci-app-clash/root/etc/init.d/clash b/package/ntlf9t/luci-app-clash/root/etc/init.d/clash index 01340b8c82..2c7af64b7f 100644 --- a/package/ntlf9t/luci-app-clash/root/etc/init.d/clash +++ b/package/ntlf9t/luci-app-clash/root/etc/init.d/clash @@ -33,7 +33,7 @@ revert_dns() { add_cron(){ config_type=$(uci get clash.config.config_type 2>/dev/null) #=========================================================================================================================== - [ -z "$(grep -w "/usr/share/clash/clash-watchdog.sh" $CRON_FILE)" ] && echo "*/1 * * * * /usr/share/clash/clash-watchdog.sh" >> $CRON_FILE + [ -z "$(grep -w "/usr/share/clash/clash-watchdog.sh" $CRON_FILE)" ] && echo "*/2 * * * * /usr/share/clash/clash-watchdog.sh" >> $CRON_FILE [ -z "$(grep -w "/usr/share/clash/kill_watchdog.sh" $CRON_FILE)" ] && echo "*/1 * * * * /usr/share/clash/kill_watchdog.sh" >> $CRON_FILE clear=$(uci get clash.config.auto_clear_log 2>/dev/null) if [ "${clear}" -eq 1 ]; then @@ -208,6 +208,16 @@ yml_dns_change(){ #=========================================================================================================================== } + +check(){ + + sed -i 's/Proxy Group:/proxy-groups:/g' "$CONFIG_YAML" + sed -i 's/proxy-provider:/proxy-providers:/g' "$CONFIG_YAML" + sed -i 's/Proxy:/proxies:/g' "$CONFIG_YAML" + sed -i 's/Rule:/rules:/g' "$CONFIG_YAML" + +} + rules(){ #=========================================================================================================================== @@ -218,9 +228,12 @@ rules(){ core=$(uci get clash.config.core 2>/dev/null) tun_mode=$(uci get clash.config.tun_mode 2>/dev/null) lan_ip=$(uci get network.lan.ipaddr 2>/dev/null |awk -F '/' '{print $1}' 2>/dev/null) - wan=$(ubus call network.interface.wan status 2>/dev/null | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' 2>/dev/null) + wan=$(ifconfig | grep 'inet addr' | awk '{print $2}' | cut -d: -f2 2>/dev/null) + ip6=$(ifconfig | grep 'inet6 addr' | awk '{print $3}' 2>/dev/null) + enable_udp=$(uci get clash.config.enable_udp 2>/dev/null) + if [ "${core}" -eq 1 ] || [ "${core}" -eq 2 ];then - iptables -t nat -N clash + iptables -t nat -N clash iptables -t nat -A clash -d 0.0.0.0/8 -j RETURN iptables -t nat -A clash -d 10.0.0.0/8 -j RETURN iptables -t nat -A clash -d 127.0.0.0/8 -j RETURN @@ -230,18 +243,57 @@ rules(){ iptables -t nat -A clash -d 224.0.0.0/4 -j RETURN iptables -t nat -A clash -d 240.0.0.0/4 -j RETURN iptables -t nat -A clash -d "${lan_ip}" -j RETURN - if [ ! -z "${wan}" ]; then - iptables -t nat -A clash -d "${wan}" -j RETURN + if [ ! -z "${wan}" ]; then + for wan_ip in $wan; do + iptables -t mangle -A clash -d "$wan_ip" -j RETURN 2>/dev/null + done fi - iptables -t nat -A clash -p tcp -j REDIRECT --to-ports "${redir_port}" - iptables -t nat -A PREROUTING -p tcp -j clash - + + iptables -t nat -A clash -p tcp -j REDIRECT --to-ports "${redir_port}" + iptables -t nat -A PREROUTING -p tcp -j clash + + + + if [ "${enable_udp}" -eq 1 ]; then + + ip rule add fwmark 1 table 100 + ip route add local default dev lo table 100 + + iptables -t mangle -N clash + iptables -t mangle -A clash -d 0.0.0.0/8 -j RETURN + iptables -t mangle -A clash -d 10.0.0.0/8 -j RETURN + iptables -t mangle -A clash -d 127.0.0.0/8 -j RETURN + iptables -t mangle -A clash -d 169.254.0.0/16 -j RETURN + iptables -t mangle -A clash -d 172.16.0.0/12 -j RETURN + iptables -t mangle -A clash -d 192.168.0.0/16 -j RETURN + iptables -t mangle -A clash -d 224.0.0.0/4 -j RETURN + iptables -t mangle -A clash -d 240.0.0.0/4 -j RETURN + if [ ! -z "${wan}" ]; then + for wan_ip in $wan; do + iptables -t mangle -A clash -d "$wan_ip" -j RETURN 2>/dev/null + done + fi + + iptables -t mangle -A clash -p udp -j TPROXY --on-port "${redir_port}" --tproxy-mark 1 + #iptables -t mangle -A clash -p udp --dport 53 -j TPROXY --on-port "${redir_port}" --tproxy-mark 0x01/0x01 + iptables -t mangle -A PREROUTING -p udp -j clash + + fi + + + fake_ip_range=$(egrep '^ {0,}fake-ip-range' /etc/clash/config.yaml |grep fake-ip-range: |awk -F ': ' '{print $2}') if [ ! -z "${fake_ip_range}" ];then iptables -t nat -A OUTPUT -p tcp -d $fake_ip_range -j REDIRECT --to-ports "${redir_port}" + if [ "${enable_udp}" -eq 1 ]; then + iptables -t mangle -A OUTPUT -p udp -d $fake_ip_range -j MARK --set-mark 1 + fi else iptables -t nat -A OUTPUT -p tcp -d 198.18.0.1/16 -j REDIRECT --to-ports "${redir_port}" + if [ "${enable_udp}" -eq 1 ]; then + iptables -t mangle -A OUTPUT -p udp -d 198.18.0.1/16 -j MARK --set-mark 1 + fi fi @@ -250,6 +302,20 @@ rules(){ ip6tables -t nat -A clash_ipv6 -p tcp -j REDIRECT --to-ports "${redir_port}" ip6tables -t nat -A PREROUTING -p tcp -j clash_ipv6 + + if [ "${enable_udp}" -eq 1 ]; then + ip6tables -t mangle -N clash + if [ ! -z "${ip6}" ]; then + for lan_ip6 in $ip6; do + if [ "$enable_udp" -eq 1 ]; then + ip6tables -t mangle -A clash -d "$lan_ip6" -j RETURN 2>/dev/null + fi + done + fi + ip6tables -t mangle -A clash -p udp -j TPROXY --on-port "$proxy_port" --tproxy-mark 1 + ip6tables -t mangle -A PREROUTING -p udp -j clash + fi + fi elif [ "${core}" -eq 3 ] || [ "${core}" -eq 4 ];then @@ -281,6 +347,7 @@ rules(){ ip link set $TUN_DEVICE_NAME up ip address replace 198.18.0.0/16 dev $TUN_DEVICE_NAME ip route replace default dev $TUN_DEVICE_NAME table "$PROXY_ROUTE_TABLE" + iptables -t nat -I PREROUTING -p tcp --dport 53 -j ACCEPT elif [ "${core}" -eq 4 ];then ip route replace default dev utun table "$PROXY_ROUTE_TABLE" fi @@ -293,6 +360,7 @@ rules(){ iptables -t mangle -A clash -m set --match-set localnetwork dst -j RETURN iptables -t mangle -I OUTPUT -j clash iptables -t mangle -I PREROUTING -m set ! --match-set localnetwork dst -j MARK --set-mark "$PROXY_FWMARK" + iptables -t nat -I PREROUTING -p tcp --dport 53 -j ACCEPT if [ -f /usr/sbin/ip6tables ] && [ "${ipv6}" -eq 1 ]; then ip6tables -t mangle -I PREROUTING -j MARK --set-mark "$PROXY_FWMARK" @@ -321,6 +389,7 @@ enable=$(uci get clash.config.enable 2>/dev/null) core=$(uci get clash.config.core 2>/dev/null) tun_mode=$(uci get clash.config.tun_mode 2>/dev/null) + if [ -f /etc/clash/config.yaml ];then rm -rf /etc/clash/config.yaml >/dev/null 2>&1 fi @@ -370,11 +439,14 @@ elif [ "${core}" -eq 3 ] && [ ! -f /etc/clash/clashtun/clash ]; then exit 0 else if [ -f $CONFIG_YAML ] && [ "$(ls -l $CONFIG_YAML|awk '{print int($5/1024)}')" -ne 0 ] ; then - + new_conf=$(uci get clash.config.new_conf 2>/dev/null) yml_change >/dev/null 2>&1 + if [ "$new_conf" -eq 1 ];then + check >/dev/null 2>&1 + fi checktype=$(grep -c "type: ssr" /etc/clash/config.yaml 2>/dev/null) - if [ "${checktype}" -gt 0 ] && [ "${core}" -eq 1 ] || [ "${checktype}" -gt 0 ] && [ "${core}" -eq 3 ]; then + if [ "${checktype}" -gt 0 ] && [ "${core}" -ne 2 ]; then if [ "${lang}" == "en" ] || [ $lang == "auto" ];then echo "Clash Core does not Support Config, use clashr core" >$REAL_LOG @@ -632,23 +704,53 @@ stop(){ echo "删除clash iptables规则" >$REAL_LOG fi - iptables -t nat -F clash >/dev/null 2>&1 && iptables -t nat -X clash >/dev/null 2>&1 + nat_indexs=$(iptables -nvL PREROUTING -t nat | sed 1,2d | sed -n '/clash/=' | sort -r) + for nat_index in $nat_indexs; do + iptables -t nat -D PREROUTING $nat_index >/dev/null 2>&1 + iptables -t nat -F clash >/dev/null 2>&1 && iptables -t nat -X clash >/dev/null 2>&1 + iptables -t mangle -F clash >/dev/null 2>&1 && iptables -t mangle -D PREROUTING -p udp -j clash >/dev/null 2>&1 && iptables -t mangle -X clash >/dev/null 2>&1 + done + sleep 1 + + ip rule del fwmark 1 table 100 >/dev/null 2>&1 + ip route del local default dev lo table 100 >/dev/null 2>&1 + + iptables -t nat -D PREROUTING -p tcp --dport 53 -j ACCEPT >/dev/null 2>&1 + + sleep 1 + + ip6tables -t mangle -F clash >/dev/null 2>&1 + ip6tables -t mangle -D PREROUTING -p udp -j clash >/dev/null 2>&1 + ip6tables -t mangle -X clash >/dev/null 2>&1 + + + out_linese=$(iptables -nvL OUTPUT -t mangle |sed 1,2d |sed -n '/198.18.0.1\/16/=' 2>/dev/null |sort -rn) + for out_linee in $out_linese; do + iptables -t mangle -D OUTPUT "$out_linee" >/dev/null 2>&1 + done + + out_linesee=$(iptables -nvL OUTPUT -t mangle |sed 1,2d |sed -n '/198.18.0.0\/16/=' 2>/dev/null |sort -rn) + for out_linees in $out_linesee; do + iptables -t mangle -D OUTPUT "$out_linees" >/dev/null 2>&1 + done + nat_indexs=$(iptables -nvL PREROUTING -t nat | sed 1,2d | sed -n '/clash/=' | sort -r) for nat_index in $nat_indexs; do iptables -t nat -D PREROUTING $nat_index >/dev/null 2>&1 done + fake=$(iptables -nvL OUTPUT -t nat |sed 1,2d |sed -n '/198.18.0.0\/16/=' |sort -r) - for fake in $fake; do - iptables -t nat -D OUTPUT $fake >/dev/null 2>&1 - done + for fake in $fake; do + iptables -t nat -D OUTPUT $fake >/dev/null 2>&1 + done fake2=$(iptables -nvL OUTPUT -t nat |sed 1,2d |sed -n '/198.18.0.1\/16/=' |sort -r) - for fake2 in $fake2; do - iptables -t nat -D OUTPUT $fake2 >/dev/null 2>&1 - done + for fake2 in $fake2; do + iptables -t nat -D OUTPUT $fake2 >/dev/null 2>&1 + done remove_mark >/dev/null 2>&1 diff --git a/package/ntlf9t/luci-app-clash/root/usr/share/clash/custom_rule.yaml b/package/ntlf9t/luci-app-clash/root/usr/share/clash/custom_rule.yaml index fbfe8a8d76..32f0cb940c 100644 --- a/package/ntlf9t/luci-app-clash/root/usr/share/clash/custom_rule.yaml +++ b/package/ntlf9t/luci-app-clash/root/usr/share/clash/custom_rule.yaml @@ -1,4 +1,4 @@ -Rule: +rules: # (GlobalTV) # > ABC - DOMAIN-SUFFIX,edgedatg.com,📺GlobalTV diff --git a/package/ntlf9t/luci-app-clash/root/usr/share/clash/dashboard/index.html b/package/ntlf9t/luci-app-clash/root/usr/share/clash/dashboard/index.html index ad630255e7..08e7119b2e 100644 --- a/package/ntlf9t/luci-app-clash/root/usr/share/clash/dashboard/index.html +++ b/package/ntlf9t/luci-app-clash/root/usr/share/clash/dashboard/index.html @@ -4,9 +4,9 @@ -