From 8560d2340042f52d5e8b1a13f80c011a071ad3be Mon Sep 17 00:00:00 2001 From: gitea-action Date: Sat, 7 Dec 2024 14:00:21 +0800 Subject: [PATCH] mihomo: sync upstream last commit: https://github.com/morytyann/OpenWrt-mihomo/commit/1f6b512334fbc4bd7897cf25aedc835498ed8656 --- mihomo/Makefile | 8 ++-- mihomo/files/mihomo.init | 95 +++++++++++++++++++++------------------- 2 files changed, 55 insertions(+), 48 deletions(-) diff --git a/mihomo/Makefile b/mihomo/Makefile index 61e6b906f..8ac04e9ef 100644 --- a/mihomo/Makefile +++ b/mihomo/Makefile @@ -5,9 +5,9 @@ PKG_RELEASE:=1 PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://github.com/MetaCubeX/mihomo.git -PKG_SOURCE_DATE:=2024-11-30 -PKG_SOURCE_VERSION:=9de9f1ef518206e43e9f8300cfc724d8e128d049 -PKG_MIRROR_HASH:=f63f13e16866b769fddc90c1b14196fcee6ce804a4ff5975fbd9b82b45a95234 +PKG_SOURCE_DATE:=2024-12-06 +PKG_SOURCE_VERSION:=d6b496d3c0eb99cf966e0f93ed00434797e5216c +PKG_MIRROR_HASH:=c292d2bc4a733cfaf9f28ba6c4e5117672243b0552297bf31ba908469055dcc6 PKG_LICENSE:=MIT PKG_MAINTAINER:=Joseph Mory @@ -16,7 +16,7 @@ PKG_BUILD_DEPENDS:=golang/host PKG_BUILD_PARALLEL:=1 PKG_BUILD_FLAGS:=no-mips16 -PKG_BUILD_VERSION:=alpha-9de9f1e +PKG_BUILD_VERSION:=alpha-d6b496d PKG_BUILD_TIME:=$(shell date -u -Iseconds) GO_PKG:=github.com/metacubex/mihomo diff --git a/mihomo/files/mihomo.init b/mihomo/files/mihomo.init index 0e250a038..ba113d7a0 100644 --- a/mihomo/files/mihomo.init +++ b/mihomo/files/mihomo.init @@ -19,7 +19,7 @@ boot() { config_get_bool enabled "config" "enabled" 0 config_get start_delay "config" "start_delay" 0 if [[ "$enabled" == 1 && "$start_delay" -gt 0 ]]; then - log "App will start after $start_delay seconds." + log "App" "Start after $start_delay seconds." sleep "$start_delay" fi # start @@ -35,13 +35,13 @@ start_service() { local enabled config_get_bool enabled "config" "enabled" 0 if [ "$enabled" == 0 ]; then - log "App is disabled." - log "Exiting..." + log "App" "Disabled." + log "App" "Exit." return fi # start - log "App is enabled." - log "Starting..." + log "App" "Enabled." + log "App" "Start." # get config ## app config local scheduled_restart cron_expression profile mixin test_profile fast_reload @@ -150,10 +150,10 @@ start_service() { if [[ "$profile" == "file:"* ]]; then local profile_name; profile_name=$(basename "${profile/file:/}") local profile_file; profile_file="$PROFILES_DIR/$profile_name" - log "Use Profile: $profile_name." + log "Profile" "Use file: $profile_name." if [ ! -f "$profile_file" ]; then - log "File not found." - log "Exiting..." + log "Profile" "File not found." + log "App" "Exit." return fi cp -f "$profile_file" "$RUN_PROFILE_PATH" @@ -162,25 +162,26 @@ start_service() { local subscription_name subscription_prefer config_get subscription_name "$subscription_section" "name" config_get subscription_prefer "$subscription_section" "prefer" "remote" - log "Use Subscription: $subscription_name." + log "Profile" "Use subscription: $subscription_name." local subscription_file; subscription_file="$SUBSCRIPTIONS_DIR/$subscription_section.yaml" if [ "$subscription_prefer" == "remote" ] || [[ "$subscription_prefer" == "local" && ! -f "$subscription_file" ]]; then update_subscription "$subscription_section" fi if [ ! -f "$subscription_file" ]; then - log "Subscription file not found." - log "Exiting..." + log "Profile" "Subscription file not found." + log "App" "Exit." return fi cp -f "$subscription_file" "$RUN_PROFILE_PATH" else - log "No profile/subscription selected." - log "Exiting..." + log "Profile" "No profile/subscription selected." + log "App" "Exit." return fi # mixin if [ "$mixin" == 0 ]; then - log "Mixin is disabled, only mixin neccesary config." + log "Mixin" "Disabled." + log "Mixin" "Mixin neccesary config." # do mixin log_level="$log_level" ipv6="$ipv6" \ ui_path="ui" ui_name="$ui_name" ui_url="$ui_url" api_listen="0.0.0.0:$api_port" api_secret="$api_secret" \ @@ -195,7 +196,8 @@ start_service() { .dns.enable = env(dns_enable) | .dns.listen = strenv(dns_listen) | .dns.enhanced-mode = strenv(dns_mode) | .dns.fake-ip-range = strenv(fake_ip_range) ' "$RUN_PROFILE_PATH" else - log "Mixin is enabled, mixin all config." + log "Mixin" "Enabled." + log "Mixin" "Mixin all config." # do mixin log_level="$log_level" mode="$mode" match_process="$match_process" tcp_keep_alive_idle="$tcp_keep_alive_idle" tcp_keep_alive_interval="$tcp_keep_alive_interval" ipv6="$ipv6" \ ui_path="ui" ui_name="$ui_name" ui_url="$ui_url" api_listen="0.0.0.0:$api_port" api_secret="$api_secret" selection_cache="$selection_cache" \ @@ -255,17 +257,18 @@ start_service() { fi # test profile if [ "$test_profile" == 1 ]; then - log "Profile testing..." + log "Profile" "Testing..." if ($PROG -d "$RUN_DIR" -t >> "$CORE_LOG_PATH" 2>&1); then - log "Profile test passed!" + log "Profile" "Test passed!" else - log "Profile test failed!" - log "Exiting..." + log "Profile" "Test failed!" + log "Profile" "Please check the core log to find out the problem." + log "App" "Exit." return fi fi # start core - log "Start Core" + log "Core" "Start." procd_open_instance mihomo procd_set_param command /bin/sh -c "$PROG -d $RUN_DIR >> $CORE_LOG_PATH 2>&1" @@ -284,8 +287,9 @@ start_service() { procd_close_instance # transparent proxy if [ "$transparent_proxy" == 1 ]; then - log "Transparent Proxy is enabled." - log "Transparent Proxy: Start." + log "Transparent Proxy" "Enabled." + log "Transparent Proxy" "TCP Mode: $tcp_transparent_proxy_mode." + log "Transparent Proxy" "UDP Mode: $udp_transparent_proxy_mode." # prepare if [ "$tproxy_enable" == 1 ]; then if [ "$ipv4_proxy" == 1 ]; then @@ -339,27 +343,27 @@ start_service() { nft -f "$RESERVED_IP6_NFT" # dns hijack if [ "$ipv4_dns_hijack" == 1 ]; then - log "Transparent Proxy: IPv4 DNS Hijack is enabled, IPv4 dns request will redirect to the core." + log "Transparent Proxy" "Hijack IPv4 dns request." nft add element inet "$FW_TABLE" dns_hijack_nfproto \{ ipv4 \} fi if [ "$ipv6_dns_hijack" == 1 ]; then - log "Transparent Proxy: IPv6 DNS Hijack is enabled, IPv6 dns request will redirect to the core." + log "Transparent Proxy" "Hijack IPv6 dns request." nft add element inet "$FW_TABLE" dns_hijack_nfproto \{ ipv6 \} fi # proxy if [ "$ipv4_proxy" == 1 ]; then - log "Transparent Proxy: IPv4 Proxy is enabled, set proxy for IPv4 traffic." + log "Transparent Proxy" "Proxy IPv4 traffic." nft add element inet "$FW_TABLE" proxy_nfproto \{ ipv4 \} fi if [ "$ipv6_proxy" == 1 ]; then - log "Transparent Proxy: IPv6 Proxy is enabled, set proxy for IPv6 traffic." + log "Transparent Proxy" "Proxy IPv6 traffic." nft add element inet "$FW_TABLE" proxy_nfproto \{ ipv6 \} fi # bypass config_list_foreach "proxy" "bypass_user" add_bypass_user config_list_foreach "proxy" "bypass_group" add_bypass_group if [ "$bypass_china_mainland_ip" == 1 ]; then - log "Transparent Proxy: Bypass china mainland ip is enabled." + log "Transparent Proxy" "Bypass china mainland ip." if [ "$ipv4_proxy" == 1 ]; then nft -f "$GEOIP_CN_NFT" fi @@ -367,8 +371,8 @@ start_service() { nft -f "$GEOIP6_CN_NFT" fi fi - log "Transparent Proxy: Destination TCP Port to Proxy: $proxy_tcp_dport." - log "Transparent Proxy: Destination UDP Port to Proxy: $proxy_udp_dport." + log "Transparent Proxy" "Destination TCP Port to Proxy: $proxy_tcp_dport." + log "Transparent Proxy" "Destination UDP Port to Proxy: $proxy_udp_dport." local proxy_dport for proxy_dport in $proxy_tcp_dport; do nft add element inet "$FW_TABLE" proxy_dport \{ "tcp" . "$proxy_dport" \} @@ -378,7 +382,7 @@ start_service() { done # router proxy if [ "$router_proxy" == 1 ]; then - log "Transparent Proxy: Router Proxy is enabled, set proxy for router." + log "Transparent Proxy" "Set proxy for router." if [ "$tcp_transparent_proxy_mode" == "redirect" ]; then nft insert rule inet "$FW_TABLE" nat_output jump router_dns_hijack nft add rule inet "$FW_TABLE" nat_output meta l4proto tcp jump router_${tcp_transparent_proxy_mode} @@ -391,14 +395,14 @@ start_service() { fi # lan proxy if [ "$lan_proxy" == 1 ]; then - log "Transparent Proxy: Lan Proxy is enabled, set proxy for lan." + log "Transparent Proxy" "Set proxy for lan." # access control if [ "$access_control_mode" == "all" ]; then - log "Transparent Proxy: Access Control is using all mode, set proxy for all client." + log "Transparent Proxy" "Access Control is using all mode, set proxy for all client." elif [ "$access_control_mode" == "allow" ]; then - log "Transparent Proxy: Access Control is using allow mode, set proxy for client which is in acl." + log "Transparent Proxy" "Access Control is using allow mode, set proxy for client which is in acl." elif [ "$access_control_mode" == "block" ]; then - log "Transparent Proxy: Access Control is using block mode, set proxy for client which is not in acl." + log "Transparent Proxy" "Access Control is using block mode, set proxy for client which is not in acl." fi config_list_foreach "proxy" "acl_ip" add_acl_ip config_list_foreach "proxy" "acl_ip6" add_acl_ip6 @@ -434,11 +438,11 @@ start_service() { fi # cron if [[ "$scheduled_restart" == 1 && -n "$cron_expression" ]]; then - log "Add crontab for scheduled restart." + log "App" "Set scheduled restart." echo "$cron_expression /etc/init.d/mihomo restart #mihomo" >> "/etc/crontabs/root" /etc/init.d/cron restart fi - log "Start Successful!" + log "App" "Start Successful." } service_stopped() { @@ -455,6 +459,8 @@ service_triggers() { } cleanup() { + # clear log + clear_log # delete routing policy ip rule del ipproto tcp table "$TPROXY_ROUTE_TABLE" > /dev/null 2>&1 ip rule del ipproto udp table "$TPROXY_ROUTE_TABLE" > /dev/null 2>&1 @@ -503,18 +509,19 @@ prepare_log() { fi if [ ! -f "$APP_LOG_PATH" ]; then touch "$APP_LOG_PATH" - else - echo -n > "$APP_LOG_PATH" fi if [ ! -f "$CORE_LOG_PATH" ]; then touch "$CORE_LOG_PATH" - else - echo -n > "$CORE_LOG_PATH" fi } +clear_log() { + echo -n > "$APP_LOG_PATH" + echo -n > "$CORE_LOG_PATH" +} + log() { - echo "[$(date "+%Y-%m-%d %H:%M:%S")] $1" >> "$APP_LOG_PATH" + echo "[$(date "+%Y-%m-%d %H:%M:%S")] [$1] $2" >> "$APP_LOG_PATH" } mixin_authentications() { @@ -646,12 +653,12 @@ update_subscription() { uci_remove "mihomo" "$subscription_section" "update" uci_remove "mihomo" "$subscription_section" "success" # update subscription - log "Update Subscription: $subscription_name." + log "Profile" "Update subscription: $subscription_name." local subscription_header_tmpfile; subscription_header_tmpfile="/tmp/$subscription_section.header" local subscription_tmpfile; subscription_tmpfile="/tmp/$subscription_section.yaml" local subscription_file; subscription_file="$SUBSCRIPTIONS_DIR/$subscription_section.yaml" if (curl -s -f --connect-timeout 15 --retry 3 -L -X GET -A "$subscription_user_agent" -D "$subscription_header_tmpfile" -o "$subscription_tmpfile" "$subscription_url"); then - log "Subscription update succeed." + log "Profile" "Subscription update successful." local subscription_expire subscription_upload subscription_download subscription_total subscription_used subscription_avaliable subscription_expire=$(grep "subscription-userinfo: " "$subscription_header_tmpfile" | grep -o -E "expire=[[:digit:]]+" | cut -d '=' -f 2) subscription_upload=$(grep "subscription-userinfo: " "$subscription_header_tmpfile" | grep -o -E "upload=[[:digit:]]+" | cut -d '=' -f 2) @@ -688,7 +695,7 @@ update_subscription() { rm -f "$subscription_header_tmpfile" mv -f "$subscription_tmpfile" "$subscription_file" else - log "Subscription update failed." + log "Profile" "Subscription update failed." # update subscription info uci_set "mihomo" "$subscription_section" "success" "0" # remove tmpfile