From d36b4e22e0a35cb38dae745a5e1aa8fa1845788d Mon Sep 17 00:00:00 2001 From: Joseph Mory Date: Mon, 14 Oct 2024 21:54:55 +0800 Subject: [PATCH] v1.8.7 add switch for mixin file content --- luci-app-mihomo/Makefile | 2 +- .../luci-static/resources/view/mihomo/config.js | 4 ++-- mihomo/files/mihomo.conf | 1 + mihomo/files/mihomo.init | 12 ++++++++---- mihomo/files/nftables/hijack.nft | 3 ++- mihomo/files/uci-defaults/migrate.sh | 4 ++++ 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/luci-app-mihomo/Makefile b/luci-app-mihomo/Makefile index 5ff816c4f..4ec97e119 100644 --- a/luci-app-mihomo/Makefile +++ b/luci-app-mihomo/Makefile @@ -1,6 +1,6 @@ include $(TOPDIR)/rules.mk -PKG_VERSION:=1.8.6 +PKG_VERSION:=1.8.7 LUCI_TITLE:=LuCI Support for mihomo LUCI_DEPENDS:=+luci-base +mihomo diff --git a/luci-app-mihomo/htdocs/luci-static/resources/view/mihomo/config.js b/luci-app-mihomo/htdocs/luci-static/resources/view/mihomo/config.js index c8b92be56..fd526f4f2 100644 --- a/luci-app-mihomo/htdocs/luci-static/resources/view/mihomo/config.js +++ b/luci-app-mihomo/htdocs/luci-static/resources/view/mihomo/config.js @@ -517,9 +517,9 @@ return view.extend({ o.retain = true; o.depends('geox_auto_update', '1'); - s.tab('mixin_file_content', _('Mixin File Content'), _('Please go to the editor tab to edit the file for mixin')); + s.tab('mixin_file_content', _('Mixin File Content')); - o = s.taboption('mixin_file_content', form.HiddenValue, '_mixin_file_content'); + o = s.taboption('mixin_file_content', form.Flag, 'mixin_file_content', '*' + ' ' + _('Enable'), _('Please go to the editor tab to edit the file for mixin')); return m.render(); } diff --git a/mihomo/files/mihomo.conf b/mihomo/files/mihomo.conf index 235f99297..1128dc942 100644 --- a/mihomo/files/mihomo.conf +++ b/mihomo/files/mihomo.conf @@ -80,6 +80,7 @@ config mixin 'mixin' option 'geoip_asn_url' 'https://mirror.ghproxy.com/https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/GeoLite2-ASN.mmdb' option 'geox_auto_update' '0' option 'geox_update_interval' '24' + option 'mixin_file_content' '0' config authentication option 'enabled' '1' diff --git a/mihomo/files/mihomo.init b/mihomo/files/mihomo.init index 475070df4..5c3edc132 100644 --- a/mihomo/files/mihomo.init +++ b/mihomo/files/mihomo.init @@ -108,6 +108,9 @@ start_service() { config_get geoip_asn_url "mixin" "geoip_asn_url" config_get_bool geox_auto_update "mixin" "geox_auto_update" 0 config_get geox_update_interval "mixin" "geox_update_interval" "24" + ### mixin file content + local mixin_file_content + config_get_bool mixin_file_content "mixin" "mixin_file_content" 0 # prepare local tproxy_enable; tproxy_enable=0 if [[ "$tcp_transparent_proxy_mode" == "tproxy" || "$udp_transparent_proxy_mode" == "tproxy" ]]; then @@ -195,10 +198,6 @@ start_service() { yq -M -i 'del(.dns.nameserver-policy)' "$RUN_PROFILE_PATH" config_foreach mixin_nameserver_policies "nameserver_policy" fi - # mixin file - if [ -s "$MIXIN_FILE_PATH" ]; then - yq ea -M -i '. as $item ireduce ({}; . * $item ) | ... comments=""' "$RUN_PROFILE_PATH" "$MIXIN_FILE_PATH" - fi fi yq -M -i 'del (.bind-address)' "$RUN_PROFILE_PATH" if [ -n "$outbound_interface" ]; then @@ -215,6 +214,11 @@ start_service() { if [ "$tun_enable" == 1 ]; then yq -M -i '.tun.auto-route = false | .tun.auto-redirect = false | .tun.auto-detect-interface = false | .tun.dns-hijack = []' "$RUN_PROFILE_PATH" fi + if [ "$mixin_file_content" == 1 ]; then + if [ -s "$MIXIN_FILE_PATH" ]; then + yq ea -M -i '. as $item ireduce ({}; . * $item ) | ... comments=""' "$RUN_PROFILE_PATH" "$MIXIN_FILE_PATH" + fi + fi # test profile if [ "$test_profile" == 1 ]; then log "Profile testing..." diff --git a/mihomo/files/nftables/hijack.nft b/mihomo/files/nftables/hijack.nft index c277fa294..699d7e766 100644 --- a/mihomo/files/nftables/hijack.nft +++ b/mihomo/files/nftables/hijack.nft @@ -63,7 +63,8 @@ table inet mihomo { } chain router_dns_hijack { - meta nfproto @dns_hijack_nfproto meta l4proto { tcp, udp } th dport 53 oifname lo meta skuid != $MIHOMO_USER counter redirect to :$DNS_PORT + meta skuid $MIHOMO_USER counter return + meta nfproto @dns_hijack_nfproto meta l4proto { tcp, udp } th dport 53 oifname lo counter redirect to :$DNS_PORT } chain all_dns_hijack { diff --git a/mihomo/files/uci-defaults/migrate.sh b/mihomo/files/uci-defaults/migrate.sh index 0febd30e6..9a566cf94 100644 --- a/mihomo/files/uci-defaults/migrate.sh +++ b/mihomo/files/uci-defaults/migrate.sh @@ -6,6 +6,10 @@ dns_doh_prefer_http3=$(uci -q get mihomo.mixin.dns_doh_prefer_http3); [ -z "$dns_doh_prefer_http3" ] && uci set mihomo.mixin.dns_doh_prefer_http3=0 +# since v1.8.7 + +mixin_file_content=$(uci -q get mihomo.mixin.mixin_file_content); [ -z "$mixin_file_content" ] && uci set mihomo.mixin.mixin_file_content=$(uci -q get mihomo.config.mixin) + # commit uci commit mihomo