feat: Enhance custom domain/subnet input
This commit is contained in:
@@ -50,9 +50,6 @@ define Package/podkop/install
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_CONF) ./files/etc/config/podkop $(1)/etc/config/podkop
|
||||
|
||||
$(INSTALL_DIR) $(1)/etc/podkop
|
||||
$(INSTALL_DATA) ./files/etc/podkop/* $(1)/etc/podkop/
|
||||
|
||||
$(INSTALL_DIR) $(1)/etc/hotplug.d/iface
|
||||
$(INSTALL_DATA) ./files/etc/hotplug.d/iface/50-podkop $(1)/etc/hotplug.d/iface/50-podkop
|
||||
endef
|
||||
|
||||
@@ -96,20 +96,25 @@ start_service() {
|
||||
if [ "$proxy_config_type" = "outbound" ]; then
|
||||
config_get outbound_json main "outbound_json"
|
||||
if [ -n "$outbound_json" ]; then
|
||||
echo "$outbound_json" > "$outbound_main"
|
||||
jq '.tag = "main"' "$outbound_main" > "${outbound_main}.tmp" && mv "${outbound_main}.tmp" "$outbound_main"
|
||||
echo '{"outbounds":[' > "$outbound_main"
|
||||
echo "$outbound_json" | jq '. + {tag: "main"}' >> "$outbound_main"
|
||||
echo ']}' >> "$outbound_main"
|
||||
else
|
||||
log "Missing main outbound JSON configuration"
|
||||
rm -f "$outbound_main" "$outbound_second"
|
||||
return
|
||||
fi
|
||||
else
|
||||
config_get proxy_string main "proxy_string"
|
||||
if [[ "$proxy_string" =~ ^ss:// ]]; then
|
||||
sing_box_config_outbound_shadowsocks "$proxy_string" "$outbound_main" main
|
||||
sing_box_config_shadowsocks "$proxy_string" "1602"
|
||||
jq '.outbounds[0] + {tag: "main"} | {outbounds: [.]}' /etc/sing-box/config.json > "$outbound_main"
|
||||
elif [[ "$proxy_string" =~ ^vless:// ]]; then
|
||||
sing_box_config_outbound_vless "$proxy_string" "$outbound_main" main
|
||||
sing_box_config_vless "$proxy_string" "1602"
|
||||
jq '.outbounds[0] + {tag: "main"} | {outbounds: [.]}' /etc/sing-box/config.json > "$outbound_main"
|
||||
else
|
||||
log "Unsupported proxy type or missing configuration for main"
|
||||
rm -f "$outbound_main" "$outbound_second"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
@@ -119,26 +124,62 @@ start_service() {
|
||||
if [ "$proxy_config_type" = "outbound" ]; then
|
||||
config_get outbound_json second "second_outbound_json"
|
||||
if [ -n "$outbound_json" ]; then
|
||||
echo "$outbound_json" > "$outbound_second"
|
||||
jq '.tag = "second"' "$outbound_second" > "${outbound_second}.tmp" && mv "${outbound_second}.tmp" "$outbound_second"
|
||||
echo '{"outbounds":[' > "$outbound_second"
|
||||
echo "$outbound_json" | jq '. + {tag: "second"}' >> "$outbound_second"
|
||||
echo ']}' >> "$outbound_second"
|
||||
else
|
||||
log "Missing second outbound JSON configuration"
|
||||
rm -f "$outbound_main" "$outbound_second"
|
||||
return
|
||||
fi
|
||||
else
|
||||
config_get proxy_string "second" "second_proxy_string"
|
||||
if [[ "$proxy_string" =~ ^ss:// ]]; then
|
||||
sing_box_config_outbound_shadowsocks "$proxy_string" "$outbound_second" second
|
||||
sing_box_config_shadowsocks "$proxy_string" "1603"
|
||||
jq '.outbounds[0] + {tag: "second"} | {outbounds: [.]}' /etc/sing-box/config.json > "$outbound_second"
|
||||
elif [[ "$proxy_string" =~ ^vless:// ]]; then
|
||||
sing_box_config_outbound_vless "$proxy_string" "$outbound_second" second
|
||||
sing_box_config_vless "$proxy_string" "1603"
|
||||
jq '.outbounds[0] + {tag: "second"} | {outbounds: [.]}' /etc/sing-box/config.json > "$outbound_second"
|
||||
else
|
||||
log "Unsupported proxy type or missing configuration for second"
|
||||
rm -f "$outbound_main" "$outbound_second"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
jq --argjson outbounds "$(jq -s '{"outbounds": [{"type":"selector","tag":"proxy","outbounds":["main","second"]}] + .[0].outbounds + .[1].outbounds}' "$outbound_main" "$outbound_second")" \
|
||||
'.outbounds += $outbounds.outbounds' /etc/podkop/sing-box-two-proxy-template.json >/etc/sing-box/config.json
|
||||
jq -s '{
|
||||
"log": {"level": "warn"},
|
||||
"inbounds": [
|
||||
{
|
||||
"type": "tproxy",
|
||||
"listen": "::",
|
||||
"listen_port": 1602,
|
||||
"sniff": false,
|
||||
"tag": "main"
|
||||
},
|
||||
{
|
||||
"type": "tproxy",
|
||||
"listen": "::",
|
||||
"listen_port": 1603,
|
||||
"sniff": false,
|
||||
"tag": "second"
|
||||
}
|
||||
],
|
||||
"outbounds": (.[0].outbounds + .[1].outbounds),
|
||||
"route": {
|
||||
"rules": [
|
||||
{
|
||||
"inbound": "main",
|
||||
"outbound": "main"
|
||||
},
|
||||
{
|
||||
"inbound": "second",
|
||||
"outbound": "second"
|
||||
}
|
||||
],
|
||||
"auto_detect_interface": true
|
||||
}
|
||||
}' "$outbound_main" "$outbound_second" > /etc/sing-box/config.json
|
||||
|
||||
rm -f "$outbound_main" "$outbound_second"
|
||||
|
||||
@@ -326,6 +367,7 @@ remove_cron_job() {
|
||||
}
|
||||
|
||||
list_update() {
|
||||
# Main domains processing
|
||||
config_get_bool domain_list_enabled "main" "domain_list_enabled" "0"
|
||||
if [ "$domain_list_enabled" -eq 1 ]; then
|
||||
log "Adding a common domains list"
|
||||
@@ -335,15 +377,24 @@ list_update() {
|
||||
dnsmasq_config_check podkop-domains.lst
|
||||
fi
|
||||
|
||||
config_get_bool custom_domains_list_enabled "main" "custom_domains_list_enabled" "0"
|
||||
if [ "$custom_domains_list_enabled" -eq 1 ]; then
|
||||
# Main custom domains processing
|
||||
config_get custom_domains_list_type "main" "custom_domains_list_enabled" "disabled"
|
||||
if [ "$custom_domains_list_type" != "disabled" ]; then
|
||||
log "Adding a custom domains list"
|
||||
add_set "podkop_domains" "main"
|
||||
rm -f /tmp/dnsmasq.d/podkop-custom-domains.lst
|
||||
config_list_foreach main custom_domains "list_custom_domains_create" "podkop"
|
||||
|
||||
if [ "$custom_domains_list_type" = "dynamic" ]; then
|
||||
config_list_foreach main custom_domains "list_custom_domains_create" "podkop"
|
||||
elif [ "$custom_domains_list_type" = "text" ]; then
|
||||
config_get custom_domains_text main "custom_domains_text"
|
||||
process_domains_text "$custom_domains_text" "podkop"
|
||||
fi
|
||||
|
||||
dnsmasq_config_check podkop-custom-domains.lst
|
||||
fi
|
||||
|
||||
# Main custom download domains
|
||||
config_get_bool custom_download_domains_list_enabled "main" "custom_download_domains_list_enabled" "0"
|
||||
if [ "$custom_download_domains_list_enabled" -eq 1 ]; then
|
||||
log "Adding a custom domains list from URL"
|
||||
@@ -351,6 +402,7 @@ list_update() {
|
||||
config_list_foreach main custom_download_domains "list_custom_download_domains_create" "podkop"
|
||||
fi
|
||||
|
||||
# Main domains delist
|
||||
config_get_bool delist_domains_enabled "main" "delist_domains_enabled" "0"
|
||||
if [ "$delist_domains_enabled" -eq 1 ] && [ "$domain_list_enabled" -eq 1 ]; then
|
||||
log "Exclude domains from the common list"
|
||||
@@ -358,20 +410,56 @@ list_update() {
|
||||
dnsmasq_config_check podkop-domains.lst
|
||||
fi
|
||||
|
||||
if [ "$domain_list_enabled" -eq 1 ] || [ "$custom_domains_list_enabled" -eq 1 ]; then
|
||||
/etc/init.d/dnsmasq restart
|
||||
# Main subnets processing
|
||||
config_get_bool subnets_list_enabled "main" "subnets_list_enabled" "0"
|
||||
if [ "$subnets_list_enabled" -eq 1 ]; then
|
||||
log "Adding a subnets from list"
|
||||
mkdir -p /tmp/podkop
|
||||
add_set "podkop_subnets" "main"
|
||||
config_list_foreach main subnets "list_subnets_download"
|
||||
fi
|
||||
|
||||
config_get_bool second_custom_domains_list_enabled "second" "second_custom_domains_list_enabled" "0"
|
||||
if [ "$second_custom_domains_list_enabled" -eq 1 ]; then
|
||||
# Main custom subnets
|
||||
config_get custom_subnets_list_type "main" "custom_subnets_list_enabled" "disabled"
|
||||
if [ "$custom_subnets_list_type" != "disabled" ]; then
|
||||
log "Adding a custom subnets list"
|
||||
add_set "podkop_subnets" "main"
|
||||
|
||||
if [ "$custom_subnets_list_type" = "dynamic" ]; then
|
||||
config_list_foreach main custom_subnets list_custom_subnets_preprocess "podkop"
|
||||
elif [ "$custom_subnets_list_type" = "text" ]; then
|
||||
config_get custom_subnets_text main "custom_subnets_text"
|
||||
process_subnets_text "$custom_subnets_text" "podkop"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Main custom download subnets
|
||||
config_get_bool custom_download_subnets_list_enabled "main" "custom_download_subnets_list_enabled" "0"
|
||||
if [ "$custom_download_subnets_list_enabled" -eq 1 ]; then
|
||||
log "Adding a subnets from URL"
|
||||
mkdir -p /tmp/podkop
|
||||
add_set "podkop_subnets" "main"
|
||||
config_list_foreach main custom_download_subnets "list_subnets_download"
|
||||
fi
|
||||
|
||||
# Second custom domains processing
|
||||
config_get second_custom_domains_list_type "second" "second_custom_domains_list_enabled" "disabled"
|
||||
if [ "$second_custom_domains_list_type" != "disabled" ]; then
|
||||
log "Adding a custom domains list. Second podkop"
|
||||
add_set "podkop2_domains" "second"
|
||||
rm -f /tmp/dnsmasq.d/podkop2-custom-domains.lst
|
||||
config_list_foreach second second_custom_domains "list_delist_domains"
|
||||
config_list_foreach second second_custom_domains "list_custom_domains_create" "podkop2"
|
||||
|
||||
if [ "$second_custom_domains_list_type" = "dynamic" ]; then
|
||||
config_list_foreach second second_custom_domains "list_custom_domains_create" "podkop2"
|
||||
elif [ "$second_custom_domains_list_type" = "text" ]; then
|
||||
config_get second_custom_domains_text second "second_custom_domains_text"
|
||||
process_domains_text "$second_custom_domains_text" "podkop2"
|
||||
fi
|
||||
|
||||
dnsmasq_config_check podkop2-custom-domains.lst
|
||||
fi
|
||||
|
||||
# Second service domains
|
||||
config_get_bool second_domain_service_enabled "second" "second_domain_service_enabled" "0"
|
||||
if [ "$second_domain_service_enabled" -eq 1 ]; then
|
||||
log "Adding a service for podkop2"
|
||||
@@ -382,38 +470,26 @@ list_update() {
|
||||
dnsmasq_config_check podkop2-domains.lst
|
||||
fi
|
||||
|
||||
if [ "$second_custom_domains_list_enabled" -eq 1 ] || [ "$second_domain_service_enabled" -eq 1 ]; then
|
||||
/etc/init.d/dnsmasq restart
|
||||
fi
|
||||
|
||||
config_get_bool subnets_list_enabled "main" "subnets_list_enabled" "0"
|
||||
if [ "$subnets_list_enabled" -eq 1 ]; then
|
||||
log "Adding a subnets from list"
|
||||
mkdir -p /tmp/podkop
|
||||
add_set "podkop_subnets" "main"
|
||||
config_list_foreach main subnets "list_subnets_download"
|
||||
fi
|
||||
|
||||
config_get_bool custom_download_subnets_list_enabled "main" "custom_download_subnets_list_enabled" "0"
|
||||
if [ "$custom_download_subnets_list_enabled" -eq 1 ]; then
|
||||
log "Adding a subnets from URL"
|
||||
mkdir -p /tmp/podkop
|
||||
add_set "podkop_subnets" "main"
|
||||
config_list_foreach main custom_download_subnets "list_subnets_download"
|
||||
fi
|
||||
|
||||
config_get_bool custom_subnets_list_enabled "main" "custom_subnets_list_enabled" "0"
|
||||
if [ "$custom_subnets_list_enabled" -eq 1 ]; then
|
||||
log "Adding a custom subnets list"
|
||||
add_set "podkop_subnets" "main"
|
||||
config_list_foreach main custom_subnets "list_custom_subnets_create" "podkop"
|
||||
fi
|
||||
|
||||
config_get_bool second_custom_subnets_list_enabled "second" "second_custom_subnets_list_enabled" "0"
|
||||
if [ "$second_custom_subnets_list_enabled" -eq 1 ]; then
|
||||
# Second custom subnets
|
||||
config_get second_custom_subnets_list_type "second" "second_custom_subnets_list_enabled" "disabled"
|
||||
if [ "$second_custom_subnets_list_type" != "disabled" ]; then
|
||||
log "Adding a custom subnets list. Second"
|
||||
add_set "podkop2_subnets" "second"
|
||||
config_list_foreach second second_custom_subnets "list_custom_subnets_create" "podkop2"
|
||||
|
||||
if [ "$second_custom_subnets_list_type" = "dynamic" ]; then
|
||||
config_list_foreach second second_custom_subnets list_custom_subnets_preprocess "podkop2"
|
||||
elif [ "$second_custom_subnets_list_type" = "text" ]; then
|
||||
config_get second_custom_subnets_text second "second_custom_subnets_text"
|
||||
process_subnets_text "$second_custom_subnets_text" "podkop2"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Restart dnsmasq if needed
|
||||
if [ "$domain_list_enabled" -eq 1 ] || [ "$custom_domains_list_type" != "disabled" ] || \
|
||||
[ "$custom_download_domains_list_enabled" -eq 1 ] || \
|
||||
[ "$second_custom_domains_list_type" != "disabled" ] || \
|
||||
[ "$second_domain_service_enabled" -eq 1 ]; then
|
||||
/etc/init.d/dnsmasq restart
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -889,38 +965,33 @@ sing_box_config_vless() {
|
||||
|
||||
get_param() {
|
||||
local param="$1"
|
||||
local value=$(echo "$STRING" | sed -n "s/.*[?&]$param=\([^&?#]*\).*/\1/p" | sed 's/%2F/\//g; s/%2C/,/g; s/%3D/=/g')
|
||||
local value=$(echo "$STRING" | sed -n "s/.*[?&]$param=\([^&?#]*\).*/\1/p")
|
||||
value=$(echo "$value" | sed 's/%2F/\//gi; s/%2C/,/gi; s/%3D/=/gi; s/%2B/+/gi')
|
||||
echo "$value"
|
||||
}
|
||||
|
||||
# Extract basic parameters
|
||||
uuid=$(echo "$STRING" | cut -d'/' -f3 | cut -d'@' -f1)
|
||||
server=$(echo "$STRING" | cut -d'@' -f2 | cut -d':' -f1)
|
||||
port=$(echo "$STRING" | cut -d'@' -f2 | cut -d':' -f2 | cut -d'?' -f1 | cut -d'/' -f1)
|
||||
|
||||
# Get all possible parameters
|
||||
type=$(get_param "type")
|
||||
security=$(get_param "security")
|
||||
sni=$(get_param "sni")
|
||||
fp=$(get_param "fp")
|
||||
flow=$(get_param "flow")
|
||||
|
||||
# Reality specific
|
||||
pbk=$(get_param "pbk")
|
||||
sid=$(get_param "sid")
|
||||
|
||||
# TLS specific
|
||||
alpn=$(get_param "alpn")
|
||||
if [ -z "$alpn" ]; then
|
||||
alpn="h2,http/1.1"
|
||||
fi
|
||||
alpn_json=$(echo "$alpn" | tr ',' '\n' | jq -R . | jq -s .)
|
||||
|
||||
# WebSocket specific
|
||||
path=$(get_param "path")
|
||||
host=$(get_param "host")
|
||||
|
||||
# Create base config
|
||||
cat > /tmp/vless_config.json << EOF
|
||||
{
|
||||
"log": {
|
||||
@@ -942,7 +1013,6 @@ sing_box_config_vless() {
|
||||
"uuid": "$uuid"
|
||||
EOF
|
||||
|
||||
# Add transport configuration if needed
|
||||
if [ "$type" = "ws" ]; then
|
||||
cat >> /tmp/vless_config.json << EOF
|
||||
,
|
||||
@@ -968,7 +1038,6 @@ EOF
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Add security configuration
|
||||
if [ "$security" = "reality" ]; then
|
||||
if [ -n "$flow" ]; then
|
||||
echo " ,\"flow\": \"$flow\"" >> /tmp/vless_config.json
|
||||
@@ -1010,7 +1079,6 @@ EOF
|
||||
echo " }" >> /tmp/vless_config.json
|
||||
fi
|
||||
|
||||
# Close outbound and add route
|
||||
cat >> /tmp/vless_config.json << EOF
|
||||
}
|
||||
],
|
||||
@@ -1027,7 +1095,6 @@ sing_box_config_outbound_json() {
|
||||
local json_config="$1"
|
||||
local listen_port="$2"
|
||||
|
||||
# Create temporary file with base config structure
|
||||
cat > /tmp/base_config.json << EOF
|
||||
{
|
||||
"log": {
|
||||
@@ -1048,10 +1115,7 @@ sing_box_config_outbound_json() {
|
||||
}
|
||||
EOF
|
||||
|
||||
# Add the outbound config using jq
|
||||
jq --argjson outbound "$json_config" '.outbounds += [$outbound]' /tmp/base_config.json > /etc/sing-box/config.json
|
||||
|
||||
# Cleanup
|
||||
rm -f /tmp/base_config.json
|
||||
}
|
||||
|
||||
@@ -1060,4 +1124,51 @@ sing_box_config_check() {
|
||||
log "Sing-box configuration is invalid"
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
process_domains_text() {
|
||||
local text="$1"
|
||||
local name="$2"
|
||||
|
||||
local tmp_file=$(mktemp)
|
||||
echo "$text" > "$tmp_file"
|
||||
|
||||
sed 's/[, ]\+/\n/g' "$tmp_file" | while IFS= read -r domain; do
|
||||
domain=$(echo "$domain" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
||||
if [ -n "$domain" ]; then
|
||||
list_custom_domains_create "$domain" "$name"
|
||||
fi
|
||||
done
|
||||
|
||||
rm -f "$tmp_file"
|
||||
}
|
||||
|
||||
process_subnets_text() {
|
||||
local text="$1"
|
||||
local name="$2"
|
||||
|
||||
local tmp_file=$(mktemp)
|
||||
echo "$text" > "$tmp_file"
|
||||
|
||||
sed 's/[, ]\+/\n/g' "$tmp_file" | while IFS= read -r subnet; do
|
||||
subnet=$(echo "$subnet" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
||||
if [ -n "$subnet" ]; then
|
||||
if ! echo "$subnet" | grep -q "/"; then
|
||||
subnet="$subnet/32"
|
||||
fi
|
||||
list_custom_subnets_create "$subnet" "$name"
|
||||
fi
|
||||
done
|
||||
|
||||
rm -f "$tmp_file"
|
||||
}
|
||||
|
||||
list_custom_subnets_preprocess() {
|
||||
local subnet="$1"
|
||||
local name="$2"
|
||||
|
||||
if ! echo "$subnet" | grep -q "/"; then
|
||||
subnet="$subnet/32"
|
||||
fi
|
||||
list_custom_subnets_create "$subnet" "$name"
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
{
|
||||
"log": {
|
||||
"level": "warn"
|
||||
},
|
||||
"inbounds": [
|
||||
{
|
||||
"type": "tproxy",
|
||||
"listen": "::",
|
||||
"listen_port": 1602,
|
||||
"sniff": false,
|
||||
"tag": "main"
|
||||
},
|
||||
{
|
||||
"type": "tproxy",
|
||||
"listen": "::",
|
||||
"listen_port": 1603,
|
||||
"sniff": false,
|
||||
"tag": "second"
|
||||
}
|
||||
],
|
||||
"outbounds": [],
|
||||
"route": {
|
||||
"rules": [
|
||||
{
|
||||
"inbound": "main",
|
||||
"outbound": "main"
|
||||
},
|
||||
{
|
||||
"inbound": "second",
|
||||
"outbound": "second"
|
||||
}
|
||||
],
|
||||
"auto_detect_interface": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user