Исправить зависимость конфигурации

This commit is contained in:
yandexru45
2026-03-07 16:09:55 +03:00
parent 4202530585
commit e8a764bbb3
2 changed files with 101 additions and 32 deletions

View File

@@ -37,7 +37,7 @@ function createSectionContent(section) {
_("Proxy Configuration URL"),
_("vless://, ss://, trojan://, socks4/5://, hy2/hysteria2:// links")
);
o.depends("proxy_config_type", "url");
o.depends({ connection_type: "proxy", proxy_config_type: "url" });
o.rows = 5;
// Enable soft wrapping for multi-line proxy URLs (e.g., for URLTest proxy links)
o.wrap = "soft";
@@ -66,7 +66,7 @@ function createSectionContent(section) {
_("Outbound Configuration"),
_("Enter complete outbound configuration in JSON format"),
);
o.depends("proxy_config_type", "outbound");
o.depends({ connection_type: "proxy", proxy_config_type: "outbound" });
o.rows = 10;
o.validate = function (section_id, value) {
// Optional
@@ -89,7 +89,7 @@ function createSectionContent(section) {
_("Subscription URL"),
_("Enter the subscription URL to fetch proxy configurations from your provider"),
);
o.depends("proxy_config_type", "subscription");
o.depends({ connection_type: "proxy", proxy_config_type: "subscription" });
o.placeholder = "https://example.com/api/sub";
o.rmempty = false;
o.validate = function (section_id, value) {
@@ -119,7 +119,7 @@ function createSectionContent(section) {
o.value("12h", _("Every 12 hours"));
o.value("1d", _("Every day"));
o.default = "1h";
o.depends("proxy_config_type", "subscription");
o.depends({ connection_type: "proxy", proxy_config_type: "subscription" });
o = section.option(
form.DynamicList,
@@ -127,7 +127,7 @@ function createSectionContent(section) {
_("Selector Proxy Links"),
_("vless://, ss://, trojan://, socks4/5://, hy2/hysteria2:// links")
);
o.depends("proxy_config_type", "selector");
o.depends({ connection_type: "proxy", proxy_config_type: "selector" });
o.rmempty = false;
o.validate = function (section_id, value) {
// Optional
@@ -150,7 +150,7 @@ function createSectionContent(section) {
_("URLTest Proxy Links"),
_("vless://, ss://, trojan://, socks4/5://, hy2/hysteria2:// links")
);
o.depends("proxy_config_type", "urltest");
o.depends({ connection_type: "proxy", proxy_config_type: "urltest" });
o.rmempty = false;
o.validate = function (section_id, value) {
// Optional
@@ -178,8 +178,8 @@ function createSectionContent(section) {
o.value("3m", _("Every 3 minutes"));
o.value("5m", _("Every 5 minutes"));
o.default = "3m";
o.depends("proxy_config_type", "urltest");
o.depends("proxy_config_type", "subscription");
o.depends({ connection_type: "proxy", proxy_config_type: "urltest" });
o.depends({ connection_type: "proxy", proxy_config_type: "subscription" });
o = section.option(
form.Value,
@@ -189,8 +189,8 @@ function createSectionContent(section) {
);
o.default = "50";
o.rmempty = false;
o.depends("proxy_config_type", "urltest");
o.depends("proxy_config_type", "subscription");
o.depends({ connection_type: "proxy", proxy_config_type: "urltest" });
o.depends({ connection_type: "proxy", proxy_config_type: "subscription" });
o.validate = function (section_id, value) {
if (!value || value.length === 0) {
return true;
@@ -217,8 +217,8 @@ function createSectionContent(section) {
o.value("https://connectivity-check.ubuntu.com", "https://connectivity-check.ubuntu.com (Ubuntu)")
o.default = "https://www.gstatic.com/generate_204";
o.rmempty = false;
o.depends("proxy_config_type", "urltest");
o.depends("proxy_config_type", "subscription");
o.depends({ connection_type: "proxy", proxy_config_type: "urltest" });
o.depends({ connection_type: "proxy", proxy_config_type: "subscription" });
o.validate = function (section_id, value) {
if (!value || value.length === 0) {
@@ -723,7 +723,10 @@ function createSectionContent(section) {
"Make sure the selected port is not used by another service",
),
);
o.rmempty = false;
o.default = "2080";
o.placeholder = "2080";
o.datatype = "port";
o.rmempty = true;
o.depends("mixed_proxy_enabled", "1");
}

View File

@@ -78,23 +78,63 @@ check_requirements() {
if has_outbound_section; then
log "Outbound section found" "debug"
else
log "Outbound section not found. Please check your configuration file (missing proxy_string, selector_proxy_links, urltest_proxy_links, outbound_json, or interface). Aborted." "error"
log "Outbound section not found. Please check your configuration file (missing proxy_string, selector_proxy_links, urltest_proxy_links, subscription_url, outbound_json, or interface according to connection_type/proxy_config_type). Aborted." "error"
exit 1
fi
}
section_has_configured_outbound() {
local section="$1"
local connection_type proxy_config_type
config_get connection_type "$section" "connection_type"
case "$connection_type" in
proxy)
config_get proxy_config_type "$section" "proxy_config_type" "url"
case "$proxy_config_type" in
url)
local proxy_string
config_get proxy_string "$section" "proxy_string"
[ -n "$proxy_string" ] && return 0
;;
selector)
local selector_proxy_links
config_get selector_proxy_links "$section" "selector_proxy_links"
[ -n "$selector_proxy_links" ] && return 0
;;
urltest)
local urltest_proxy_links
config_get urltest_proxy_links "$section" "urltest_proxy_links"
[ -n "$urltest_proxy_links" ] && return 0
;;
outbound)
local outbound_json
config_get outbound_json "$section" "outbound_json"
[ -n "$outbound_json" ] && return 0
;;
subscription)
local subscription_url
config_get subscription_url "$section" "subscription_url"
[ -n "$subscription_url" ] && return 0
;;
esac
;;
vpn)
local interface
config_get interface "$section" "interface"
[ -n "$interface" ] && return 0
;;
esac
return 1
}
_check_outbound_section() {
local section="$1"
local proxy_string interface outbound_json urltest_proxy_links
config_get proxy_string "$section" "proxy_string"
config_get selector_proxy_links "$section" "selector_proxy_links"
config_get urltest_proxy_links "$section" "urltest_proxy_links"
config_get outbound_json "$section" "outbound_json"
config_get interface "$section" "interface"
if [ -n "$proxy_string" ] || [ -n "$selector_proxy_links" ] || [ -n "$urltest_proxy_links" ] ||
[ -n "$outbound_json" ] || [ -n "$interface" ]; then
if section_has_configured_outbound "$section"; then
section_exists=0
fi
}
@@ -482,7 +522,12 @@ remove_cron_job() {
add_subscription_cron_job() {
local section="$1"
local proxy_config_type subscription_update_interval cron_job
local connection_type proxy_config_type subscription_update_interval cron_job
config_get connection_type "$section" "connection_type"
if [ "$connection_type" != "proxy" ]; then
return
fi
config_get proxy_config_type "$section" "proxy_config_type"
if [ "$proxy_config_type" != "subscription" ]; then
@@ -599,7 +644,13 @@ subscription_update() {
_check_subscription_section() {
local section="$1"
local proxy_config_type
local connection_type proxy_config_type
config_get connection_type "$section" "connection_type"
if [ "$connection_type" != "proxy" ]; then
return
fi
config_get proxy_config_type "$section" "proxy_config_type"
if [ "$proxy_config_type" = "subscription" ]; then
has_subscription=1
@@ -614,7 +665,13 @@ subscription_update() {
_update_subscription_for_section() {
local section="$1"
local proxy_config_type subscription_url subscription_json_path
local connection_type proxy_config_type subscription_url subscription_json_path
config_get connection_type "$section" "connection_type"
if [ "$connection_type" != "proxy" ]; then
return
fi
config_get proxy_config_type "$section" "proxy_config_type"
if [ "$proxy_config_type" != "subscription" ]; then
@@ -1385,7 +1442,19 @@ configure_section_mixed_proxy() {
log "Could not determine the listening IP address for the Mixed Proxy. The proxy will not be created." "warn"
return 1
fi
config_get mixed_proxy_port "$section" "mixed_proxy_port"
config_get mixed_proxy_port "$section" "mixed_proxy_port" "2080"
case "$mixed_proxy_port" in
'' | *[!0-9]*)
log "Invalid mixed_proxy_port '$mixed_proxy_port' for section '$section'. Falling back to 2080." "warn"
mixed_proxy_port="2080"
;;
esac
if [ "$mixed_proxy_port" -lt 1 ] || [ "$mixed_proxy_port" -gt 65535 ]; then
log "mixed_proxy_port '$mixed_proxy_port' for section '$section' is out of range (1-65535). Falling back to 2080." "warn"
mixed_proxy_port="2080"
fi
if [ "$mixed_inbound_enabled" -eq 1 ]; then
mixed_inbound_tag="$(get_inbound_tag_by_section "$section-mixed")"
mixed_outbound_tag="$(get_outbound_tag_by_section "$section")"
@@ -1686,11 +1755,8 @@ get_download_detour_tag() {
_determine_first_outbound_section() {
local section="$1"
local connection_type
config_get connection_type "$section" "connection_type"
if [ "$connection_type" = "proxy" ] || [ "$connection_type" = "vpn" ]; then
[ -z "$first_section" ] && first_section="$1"
if section_has_configured_outbound "$section"; then
[ -z "$first_section" ] && first_section="$section"
fi
}