mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-09 04:56:51 +03:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00db99723c | ||
|
|
5439504de7 | ||
|
|
c3072162de | ||
|
|
d021636f85 | ||
|
|
a06aac0613 |
@@ -32,6 +32,7 @@ function createConfigSection(section, map, network) {
|
|||||||
o = s.taboption('basic', form.ListValue, 'proxy_config_type', _('Configuration Type'), _('Select how to configure the proxy'));
|
o = s.taboption('basic', form.ListValue, 'proxy_config_type', _('Configuration Type'), _('Select how to configure the proxy'));
|
||||||
o.value('url', _('Connection URL'));
|
o.value('url', _('Connection URL'));
|
||||||
o.value('outbound', _('Outbound Config'));
|
o.value('outbound', _('Outbound Config'));
|
||||||
|
o.value('urltest', _('URLTest'));
|
||||||
o.default = 'url';
|
o.default = 'url';
|
||||||
o.depends('mode', 'proxy');
|
o.depends('mode', 'proxy');
|
||||||
o.ucisection = s.section;
|
o.ucisection = s.section;
|
||||||
@@ -205,6 +206,11 @@ function createConfigSection(section, map, network) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
o = s.taboption('basic', form.DynamicList, 'urltest_proxy_links', _('URLTest Proxy Links'));
|
||||||
|
o.depends('proxy_config_type', 'urltest');
|
||||||
|
o.placeholder = 'vless:// or ss:// link';
|
||||||
|
o.rmempty = false;
|
||||||
|
|
||||||
o = s.taboption('basic', form.Flag, 'ss_uot', _('Shadowsocks UDP over TCP'), _('Apply for SS2022'));
|
o = s.taboption('basic', form.Flag, 'ss_uot', _('Shadowsocks UDP over TCP'), _('Apply for SS2022'));
|
||||||
o.default = '0';
|
o.default = '0';
|
||||||
o.depends('mode', 'proxy');
|
o.depends('mode', 'proxy');
|
||||||
|
|||||||
@@ -83,13 +83,14 @@ start_main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
local proxy_string interface outbound_json dont_touch_dhcp
|
local proxy_string interface outbound_json urltest_proxy_links dont_touch_dhcp
|
||||||
config_get proxy_string "main" "proxy_string"
|
config_get proxy_string "main" "proxy_string"
|
||||||
config_get interface "main" "interface"
|
config_get interface "main" "interface"
|
||||||
config_get outbound_json "main" "outbound_json"
|
config_get outbound_json "main" "outbound_json"
|
||||||
|
config_get urltest_proxy_links "main" "urltest_proxy_links"
|
||||||
|
|
||||||
if [ -z "$proxy_string" ] && [ -z "$interface" ] && [ -z "$outbound_json" ]; then
|
if [ -z "$proxy_string" ] && [ -z "$interface" ] && [ -z "$outbound_json" ] && [ -z "$urltest_proxy_links" ]; then
|
||||||
log "Podkop start aborted: required options (proxy_string, interface, outbound_json) are missing in 'main' section"
|
log "Required options (proxy_string, interface, outbound_json, urltest_proxy_links) are missing in 'main' section. Aborted." "fatal"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -629,7 +630,7 @@ configure_outbound_handler() {
|
|||||||
|
|
||||||
case "$proxy_config_type" in
|
case "$proxy_config_type" in
|
||||||
url)
|
url)
|
||||||
log "Detected proxy configuration type: url"
|
log "Detected proxy configuration type: url" "debug"
|
||||||
local proxy_string udp_over_tcp
|
local proxy_string udp_over_tcp
|
||||||
config_get proxy_string "$section" "proxy_string"
|
config_get proxy_string "$section" "proxy_string"
|
||||||
config_get udp_over_tcp "$section" "ss_uot"
|
config_get udp_over_tcp "$section" "ss_uot"
|
||||||
@@ -643,11 +644,42 @@ configure_outbound_handler() {
|
|||||||
config=$(sing_box_cf_add_proxy_outbound "$config" "$section" "$active_proxy_string" "$udp_over_tcp")
|
config=$(sing_box_cf_add_proxy_outbound "$config" "$section" "$active_proxy_string" "$udp_over_tcp")
|
||||||
;;
|
;;
|
||||||
outbound)
|
outbound)
|
||||||
log "Detected proxy configuration type: outbound"
|
log "Detected proxy configuration type: outbound" "debug"
|
||||||
local json_outbound
|
local json_outbound
|
||||||
config_get json_outbound "$section" "outbound_json"
|
config_get json_outbound "$section" "outbound_json"
|
||||||
config=$(sing_box_cf_add_json_outbound "$config" "$section" "$json_outbound")
|
config=$(sing_box_cf_add_json_outbound "$config" "$section" "$json_outbound")
|
||||||
;;
|
;;
|
||||||
|
urltest)
|
||||||
|
log "Detected proxy configuration type: urltest" "debug"
|
||||||
|
local urltest_proxy_links udp_over_tcp i urltest_tag selector_tag outbound_tag outbound_tags \
|
||||||
|
urltest_outbounds selector_outbounds
|
||||||
|
config_get urltest_proxy_links "$section" "urltest_proxy_links"
|
||||||
|
config_get udp_over_tcp "$section" "ss_uot"
|
||||||
|
|
||||||
|
if [ -z "$urltest_proxy_links" ]; then
|
||||||
|
log "URLTest proxy links is not set. Aborted." "fatal"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
i=1
|
||||||
|
for link in $urltest_proxy_links; do
|
||||||
|
config="$(sing_box_cf_add_proxy_outbound "$config" "$section-$i" "$link" "$udp_over_tcp")"
|
||||||
|
outbound_tag="$(get_outbound_tag_by_section "$section-$i")"
|
||||||
|
if [ -z "$outbound_tags" ]; then
|
||||||
|
outbound_tags="$outbound_tag"
|
||||||
|
else
|
||||||
|
outbound_tags="$outbound_tags,$outbound_tag"
|
||||||
|
fi
|
||||||
|
i=$((i+1))
|
||||||
|
done
|
||||||
|
|
||||||
|
urltest_tag="$(get_outbound_tag_by_section "$section-urltest")"
|
||||||
|
selector_tag="$(get_outbound_tag_by_section "$section")"
|
||||||
|
urltest_outbounds="$(comma_string_to_json_array "$outbound_tags")"
|
||||||
|
selector_outbounds="$(comma_string_to_json_array "$outbound_tags,$urltest_tag")"
|
||||||
|
config="$(sing_box_cm_add_urltest_outbound "$config" "$urltest_tag" "$urltest_outbounds")"
|
||||||
|
config="$(sing_box_cm_add_selector_outbound "$config" "$selector_tag" "$selector_outbounds" "$urltest_tag")"
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
log "Unknown proxy configuration type: '$proxy_config_type'. Aborted." "fatal"
|
log "Unknown proxy configuration type: '$proxy_config_type'. Aborted." "fatal"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -832,6 +832,90 @@ sing_box_cm_add_raw_outbound() {
|
|||||||
)]'
|
)]'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Add a URLTest outbound to the outbounds section of a sing-box JSON configuration.
|
||||||
|
# Arguments:
|
||||||
|
# config: JSON configuration
|
||||||
|
# tag: string, identifier for the URLTest outbound
|
||||||
|
# outbounds: JSON array of outbound tags to test
|
||||||
|
# url: URL to probe (optional)
|
||||||
|
# interval: test interval (e.g., "10s") (optional)
|
||||||
|
# tolerance: max latency difference tolerated (optional)
|
||||||
|
# idle_timeout: idle timeout duration (optional)
|
||||||
|
# interrupt_exist_connections: flag to interrupt existing connections ("true"/"false") (optional)
|
||||||
|
# Outputs:
|
||||||
|
# Writes updated JSON configuration to stdout
|
||||||
|
# Example:
|
||||||
|
# CONFIG=$(sing_box_cm_add_urltest_outbound "$CONFIG" "auto-select" '["proxy1","proxy2"]')
|
||||||
|
#######################################
|
||||||
|
sing_box_cm_add_urltest_outbound() {
|
||||||
|
local config="$1"
|
||||||
|
local tag="$2"
|
||||||
|
local outbounds="$3"
|
||||||
|
local url="$4"
|
||||||
|
local interval="$5"
|
||||||
|
local tolerance="$6"
|
||||||
|
local idle_timeout="$7"
|
||||||
|
local interrupt_exist_connections="$8"
|
||||||
|
|
||||||
|
echo "$config" | jq \
|
||||||
|
--arg tag "$tag" \
|
||||||
|
--argjson outbounds "$outbounds" \
|
||||||
|
--arg url "$url" \
|
||||||
|
--arg interval "$interval" \
|
||||||
|
--arg tolerance "$tolerance" \
|
||||||
|
--arg idle_timeout "$idle_timeout" \
|
||||||
|
--arg interrupt_exist_connections "$interrupt_exist_connections" \
|
||||||
|
'.outbounds += [
|
||||||
|
{
|
||||||
|
type: "urltest",
|
||||||
|
tag: $tag,
|
||||||
|
outbounds: $outbounds
|
||||||
|
}
|
||||||
|
+ (if $url != "" then {url: $url} else {} end)
|
||||||
|
+ (if $interval != "" then {interval: $interval} else {} end)
|
||||||
|
+ (if $tolerance != "" then {tolerance: ($tolerance | tonumber)} else {} end)
|
||||||
|
+ (if $idle_timeout != "" then {idle_timeout: $idle_timeout} else {} end)
|
||||||
|
+ (if $interrupt_exist_connections == "true" then {interrupt_exist_connections: true} else {} end)
|
||||||
|
]'
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Add a Selector outbound to the outbounds section of a sing-box JSON configuration.
|
||||||
|
# Arguments:
|
||||||
|
# config: JSON configuration
|
||||||
|
# tag: string, identifier for the Selector outbound
|
||||||
|
# outbounds: JSON array of outbound tags to choose from
|
||||||
|
# default: default outbound tag if none selected (optional)
|
||||||
|
# interrupt_exist_connections: flag to interrupt existing connections ("true"/"false") (optional)
|
||||||
|
# Outputs:
|
||||||
|
# Writes updated JSON configuration to stdout
|
||||||
|
# Example:
|
||||||
|
# CONFIG=$(sing_box_cm_add_selector_outbound "$CONFIG" "select-proxy" '["proxy1","proxy2"]')
|
||||||
|
#######################################
|
||||||
|
sing_box_cm_add_selector_outbound() {
|
||||||
|
local config="$1"
|
||||||
|
local tag="$2"
|
||||||
|
local outbounds="$3"
|
||||||
|
local default="$4"
|
||||||
|
local interrupt_exist_connections="$5"
|
||||||
|
|
||||||
|
echo "$config" | jq \
|
||||||
|
--arg tag "$tag" \
|
||||||
|
--argjson outbounds "$outbounds" \
|
||||||
|
--arg default "$default" \
|
||||||
|
--arg interrupt_exist_connections "$interrupt_exist_connections" \
|
||||||
|
'.outbounds += [
|
||||||
|
{
|
||||||
|
type: "selector",
|
||||||
|
tag: $tag,
|
||||||
|
outbounds: $outbounds,
|
||||||
|
default: $default
|
||||||
|
}
|
||||||
|
+ (if $interrupt_exist_connections == "true" then {interrupt_exist_connections: true} else {} end)
|
||||||
|
]'
|
||||||
|
}
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# Configure the route section of a sing-box JSON configuration.
|
# Configure the route section of a sing-box JSON configuration.
|
||||||
# Arguments:
|
# Arguments:
|
||||||
|
|||||||
Reference in New Issue
Block a user