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 c8b92be5..f2f623d3 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 @@ -124,7 +124,10 @@ return view.extend({ o = s.option(form.FileUpload, 'upload_profile', _('Upload Profile')); o.root_directory = mihomo.profilesDir; - o = s.option(form.Flag, 'mixin', _('Mixin')); + o = s.option(form.Flag, "mixin_config", _("Mixin Config Content")); + o.rmempty = false; + + o = s.option(form.Flag, "mixin_file", _("Mixin File Content")); o.rmempty = false; o = s.option(form.Flag, 'test_profile', _('Test Profile')); diff --git a/luci-app-mihomo/po/zh_Hans/mihomo.po b/luci-app-mihomo/po/zh_Hans/mihomo.po index 9368fba4..11411c7b 100644 --- a/luci-app-mihomo/po/zh_Hans/mihomo.po +++ b/luci-app-mihomo/po/zh_Hans/mihomo.po @@ -79,8 +79,8 @@ msgstr "订阅:" msgid "Upload Profile" msgstr "上传配置文件" -msgid "Mixin" -msgstr "混入" +msgid "Mixin Config Content" +msgstr "混入配置内容" msgid "Test Profile" msgstr "检查配置文件" diff --git a/mihomo/files/mihomo.conf b/mihomo/files/mihomo.conf index 235f9929..3303070d 100644 --- a/mihomo/files/mihomo.conf +++ b/mihomo/files/mihomo.conf @@ -6,7 +6,8 @@ config config 'config' option 'scheduled_restart' '0' option 'cron_expression' '0 3 * * *' option 'profile' 'subscription:subscription' - option 'mixin' '1' + option 'mixin_config' '1' + option 'mixin_file' '1' option 'test_profile' '1' config proxy 'proxy' diff --git a/mihomo/files/mihomo.init b/mihomo/files/mihomo.init index 475070df..7d72652d 100644 --- a/mihomo/files/mihomo.init +++ b/mihomo/files/mihomo.init @@ -24,11 +24,12 @@ start_service() { log "Starting..." # get config ## app config - local scheduled_restart cron_expression profile mixin test_profile fast_reload + local scheduled_restart cron_expression profile mixin_config mixin_file test_profile fast_reload config_get_bool scheduled_restart "config" "scheduled_restart" 0 config_get cron_expression "config" "cron_expression" config_get profile "config" "profile" - config_get_bool mixin "config" "mixin" 0 + config_get_bool mixin_config "config" "mixin_config" 0 + config_get_bool mixin_file "config" "mixin_file" 0 config_get_bool test_profile "config" "test_profile" 0 config_get_bool fast_reload "config" "fast_reload" 0 ## proxy config @@ -141,24 +142,9 @@ start_service() { return fi # mixin - if [ "$mixin" == 0 ]; then - log "Mixin is disabled, only 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" \ - allow_lan="$allow_lan" http_port="$http_port" socks_port="$socks_port" mixed_port="$mixed_port" redir_port="$redir_port" tproxy_port="$tproxy_port" \ - tun_enable="$tun_enable" tun_stack="$tun_stack" tun_device="$TUN_DEVICE" tun_mtu="$tun_mtu" tun_gso="$tun_gso" tun_gso_max_size="$tun_gso_max_size" tun_endpoint_independent_nat="$tun_endpoint_independent_nat" \ - dns_enable="true" dns_listen="0.0.0.0:$dns_port" dns_mode="$dns_mode" fake_ip_range="$fake_ip_range" \ - yq -M -i ' - .log-level = env(log_level) | .ipv6 = env(ipv6) == 1 | - .external-ui = env(ui_path) | .external-ui-name = env(ui_name) | .external-ui-url = env(ui_url) | .external-controller = env(api_listen) | .secret = env(api_secret) | - .allow-lan = env(allow_lan) == 1 | .port = env(http_port) | .socks-port = env(socks_port) | .mixed-port = env(mixed_port) | .redir-port = env(redir_port) | .tproxy-port = env(tproxy_port) | - .tun.enable = env(tun_enable) == 1 | .tun.stack = env(tun_stack) | .tun.device = env(tun_device) | .tun.mtu = env(tun_mtu) | .tun.gso = env(tun_gso) == 1 | .tun.gso-max-size = env(tun_gso_max_size) | .tun.endpoint-independent-nat = env(tun_endpoint_independent_nat) == 1 | - .dns.enable = env(dns_enable) | .dns.listen = env(dns_listen) | .dns.enhanced-mode = env(dns_mode) | .dns.fake-ip-range = env(fake_ip_range) - ' "$RUN_PROFILE_PATH" - else - log "Mixin is enabled, mixin all config." - # do mixin + if [ "$mixin_config" == 1 ]; then + # mixin config + log "Mixin config is enabled, mixin all config." 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" \ allow_lan="$allow_lan" http_port="$http_port" socks_port="$socks_port" mixed_port="$mixed_port" redir_port="$redir_port" tproxy_port="$tproxy_port" \ @@ -195,11 +181,28 @@ start_service() { yq -M -i 'del(.dns.nameserver-policy)' "$RUN_PROFILE_PATH" config_foreach mixin_nameserver_policies "nameserver_policy" fi + elif [ "$mixin_file" == 1 ]; then # mixin file + log "Mixin file is enabled, mixin file config." if [ -s "$MIXIN_FILE_PATH" ]; then yq ea -M -i '. as $item ireduce ({}; . * $item ) | ... comments=""' "$RUN_PROFILE_PATH" "$MIXIN_FILE_PATH" fi + else + log "Mixin config and mixin file are disabled, only mixin necessary config." fi + # mixin necessary + 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" \ + allow_lan="$allow_lan" http_port="$http_port" socks_port="$socks_port" mixed_port="$mixed_port" redir_port="$redir_port" tproxy_port="$tproxy_port" \ + tun_enable="$tun_enable" tun_stack="$tun_stack" tun_device="$TUN_DEVICE" tun_mtu="$tun_mtu" tun_gso="$tun_gso" tun_gso_max_size="$tun_gso_max_size" tun_endpoint_independent_nat="$tun_endpoint_independent_nat" \ + dns_enable="true" dns_listen="0.0.0.0:$dns_port" dns_mode="$dns_mode" fake_ip_range="$fake_ip_range" \ + yq -M -i ' + .log-level = env(log_level) | .ipv6 = env(ipv6) == 1 | + .external-ui = env(ui_path) | .external-ui-name = env(ui_name) | .external-ui-url = env(ui_url) | .external-controller = env(api_listen) | .secret = env(api_secret) | + .allow-lan = env(allow_lan) == 1 | .port = env(http_port) | .socks-port = env(socks_port) | .mixed-port = env(mixed_port) | .redir-port = env(redir_port) | .tproxy-port = env(tproxy_port) | + .tun.enable = env(tun_enable) == 1 | .tun.stack = env(tun_stack) | .tun.device = env(tun_device) | .tun.mtu = env(tun_mtu) | .tun.gso = env(tun_gso) == 1 | .tun.gso-max-size = env(tun_gso_max_size) | .tun.endpoint-independent-nat = env(tun_endpoint_independent_nat) == 1 | + .dns.enable = env(dns_enable) | .dns.listen = env(dns_listen) | .dns.enhanced-mode = env(dns_mode) | .dns.fake-ip-range = env(fake_ip_range) + ' "$RUN_PROFILE_PATH" yq -M -i 'del (.bind-address)' "$RUN_PROFILE_PATH" if [ -n "$outbound_interface" ]; then local outbound_device