Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: split mixin option to allow more flexible configuration #233

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
4 changes: 2 additions & 2 deletions luci-app-mihomo/po/zh_Hans/mihomo.po
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ msgstr "订阅:"
msgid "Upload Profile"
msgstr "上传配置文件"

msgid "Mixin"
msgstr "混入"
msgid "Mixin Config Content"
msgstr "混入配置内容"

msgid "Test Profile"
msgstr "检查配置文件"
Expand Down
3 changes: 2 additions & 1 deletion mihomo/files/mihomo.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
43 changes: 23 additions & 20 deletions mihomo/files/mihomo.init
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" \
Expand Down Expand Up @@ -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
Expand Down