mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-11 14:06:58 +03:00
Merge pull request #170 from itdoginfo/fix
Fix: Mask urltest_proxy_links and move sing-box config check to init config function
This commit is contained in:
@@ -66,7 +66,6 @@ start_main() {
|
|||||||
|
|
||||||
# sing-box
|
# sing-box
|
||||||
sing_box_init_config
|
sing_box_init_config
|
||||||
sing_box_config_check
|
|
||||||
config_foreach add_cron_job
|
config_foreach add_cron_job
|
||||||
/etc/init.d/sing-box start
|
/etc/init.d/sing-box start
|
||||||
|
|
||||||
@@ -239,23 +238,29 @@ migration() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
validate_service() {
|
validate_service() {
|
||||||
local domain="$1"
|
local service="$1"
|
||||||
|
|
||||||
for valid_service in $VALID_SERVICES; do
|
for domain_service in $COMMUNITY_DOMAIN_SERVICES; do
|
||||||
if [ "$domain" = "$valid_service" ]; then
|
if [ "$service" = "$domain_service" ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
log "Invalid service in domain_list: $domain. Exiting. Check config and LuCI cache"
|
for subnet_service in $COMMUNITY_SUBNET_SERVICES; do
|
||||||
|
if [ "$service" = "$subnet_service" ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
log "Invalid service in community lists: $service. Check config and LuCI cache. Aborted." "fatal"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
process_validate_service() {
|
process_validate_service() {
|
||||||
local domain_list_enabled
|
local community_lists_enabled
|
||||||
config_get_bool domain_list_enabled "$section" "domain_list_enabled" 0
|
config_get_bool community_lists_enabled "$section" "community_lists_enabled" 0
|
||||||
if [ "$domain_list_enabled" -eq 1 ]; then
|
if [ "$community_lists_enabled" -eq 1 ]; then
|
||||||
config_list_foreach "$section" domain_list validate_service
|
config_list_foreach "$section" "community_lists" validate_service
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -971,8 +976,14 @@ configure_community_list_handler() {
|
|||||||
config_get update_interval "main" "update_interval" "1d"
|
config_get update_interval "main" "update_interval" "1d"
|
||||||
|
|
||||||
config=$(sing_box_cm_add_remote_ruleset "$config" "$ruleset_tag" "$format" "$url" "$detour" "$update_interval")
|
config=$(sing_box_cm_add_remote_ruleset "$config" "$ruleset_tag" "$format" "$url" "$detour" "$update_interval")
|
||||||
_add_ruleset_to_dns_rules "$ruleset_tag"
|
|
||||||
config=$(sing_box_cm_patch_route_rule "$config" "$route_rule_tag" "rule_set" "$ruleset_tag")
|
config=$(sing_box_cm_patch_route_rule "$config" "$route_rule_tag" "rule_set" "$ruleset_tag")
|
||||||
|
|
||||||
|
for service in $COMMUNITY_DOMAIN_SERVICES; do
|
||||||
|
if [ "$tag" = "$service" ]; then
|
||||||
|
_add_ruleset_to_dns_rules "$ruleset_tag"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
configure_user_domain_or_subnets_list() {
|
configure_user_domain_or_subnets_list() {
|
||||||
@@ -1167,6 +1178,8 @@ sing_box_save_config() {
|
|||||||
log "Save sing-box temporary config to $temp_file_path" "debug"
|
log "Save sing-box temporary config to $temp_file_path" "debug"
|
||||||
sing_box_cm_save_config_to_file "$config" "$temp_file_path"
|
sing_box_cm_save_config_to_file "$config" "$temp_file_path"
|
||||||
|
|
||||||
|
sing_box_config_check "$temp_file_path"
|
||||||
|
|
||||||
current_config_hash=$(md5sum "$sing_box_config_path" 2> /dev/null | awk '{print $1}')
|
current_config_hash=$(md5sum "$sing_box_config_path" 2> /dev/null | awk '{print $1}')
|
||||||
temp_config_hash=$(md5sum "$temp_file_path" | awk '{print $1}')
|
temp_config_hash=$(md5sum "$temp_file_path" | awk '{print $1}')
|
||||||
log "Current sing-box config hash: $current_config_hash" "debug"
|
log "Current sing-box config hash: $current_config_hash" "debug"
|
||||||
@@ -1181,10 +1194,10 @@ sing_box_save_config() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sing_box_config_check() {
|
sing_box_config_check() {
|
||||||
local sing_box_config_path
|
local config_path="$1"
|
||||||
config_get sing_box_config_path "main" "config_path"
|
|
||||||
if ! sing-box -c "$sing_box_config_path" check > /dev/null 2>&1; then
|
if ! sing-box -c "$config_path" check > /dev/null 2>&1; then
|
||||||
log "Sing-box configuration is invalid" "fatal"
|
log "Sing-box configuration $config_path is invalid" "fatal"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -1752,15 +1765,14 @@ show_sing_box_config() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
show_config() {
|
show_config() {
|
||||||
if [ ! -f /etc/config/podkop ]; then
|
if [ ! -f "$PODKOP_CONFIG" ]; then
|
||||||
nolog "Configuration file not found"
|
nolog "Configuration file not found"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tmp_config=$(mktemp)
|
tmp_config=$(mktemp)
|
||||||
|
|
||||||
cat /etc/config/podkop | sed \
|
sed -e 's/\(option proxy_string\).*/\1 '\''MASKED'\''/g' \
|
||||||
-e 's/\(option proxy_string\).*/\1 '\''MASKED'\''/g' \
|
|
||||||
-e 's/\(option outbound_json\).*/\1 '\''MASKED'\''/g' \
|
-e 's/\(option outbound_json\).*/\1 '\''MASKED'\''/g' \
|
||||||
-e 's/\(option second_proxy_string\).*/\1 '\''MASKED'\''/g' \
|
-e 's/\(option second_proxy_string\).*/\1 '\''MASKED'\''/g' \
|
||||||
-e 's/\(option second_outbound_json\).*/\1 '\''MASKED'\''/g' \
|
-e 's/\(option second_outbound_json\).*/\1 '\''MASKED'\''/g' \
|
||||||
@@ -1769,8 +1781,9 @@ show_config() {
|
|||||||
-e 's/\(pbk=[^&]*\)/pbk=MASKED/g' \
|
-e 's/\(pbk=[^&]*\)/pbk=MASKED/g' \
|
||||||
-e 's/\(sid=[^&]*\)/sid=MASKED/g' \
|
-e 's/\(sid=[^&]*\)/sid=MASKED/g' \
|
||||||
-e 's/\(option dns_server '\''[^'\'']*\.dns\.nextdns\.io'\''\)/option dns_server '\''MASKED.dns.nextdns.io'\''/g' \
|
-e 's/\(option dns_server '\''[^'\'']*\.dns\.nextdns\.io'\''\)/option dns_server '\''MASKED.dns.nextdns.io'\''/g' \
|
||||||
-e "s|\(option dns_server 'dns\.nextdns\.io\)/[^']*|\1/MASKED|"
|
-e "s|\(option dns_server 'dns\.nextdns\.io\)/[^']*|\1/MASKED|" \
|
||||||
> "$tmp_config"
|
-e 's/\(list urltest_proxy_links\).*/\1 '\''MASKED'\''/g' \
|
||||||
|
"$PODKOP_CONFIG" > "$tmp_config"
|
||||||
|
|
||||||
cat "$tmp_config"
|
cat "$tmp_config"
|
||||||
rm -f "$tmp_config"
|
rm -f "$tmp_config"
|
||||||
|
|||||||
@@ -63,4 +63,5 @@ SUBNETS_HETZNER="${GITHUB_RAW_URL}/Subnets/IPv4/hetzner.lst"
|
|||||||
SUBNETS_OVH="${GITHUB_RAW_URL}/Subnets/IPv4/ovh.lst"
|
SUBNETS_OVH="${GITHUB_RAW_URL}/Subnets/IPv4/ovh.lst"
|
||||||
SUBNETS_DIGITALOCEAN="${GITHUB_RAW_URL}/Subnets/IPv4/digitalocean.lst"
|
SUBNETS_DIGITALOCEAN="${GITHUB_RAW_URL}/Subnets/IPv4/digitalocean.lst"
|
||||||
SUBNETS_CLOUDFRONT="${GITHUB_RAW_URL}/Subnets/IPv4/cloudfront.lst"
|
SUBNETS_CLOUDFRONT="${GITHUB_RAW_URL}/Subnets/IPv4/cloudfront.lst"
|
||||||
VALID_SERVICES="russia_inside russia_outside ukraine_inside geoblock block porn news anime youtube discord meta twitter hdrezka tiktok telegram cloudflare google_ai google_play hetzner ovh hodca digitalocean cloudfront"
|
COMMUNITY_DOMAIN_SERVICES="russia_inside russia_outside ukraine_inside geoblock block porn news anime youtube hdrezka tiktok google_ai google_play hodca"
|
||||||
|
COMMUNITY_SUBNET_SERVICES="discord meta twitter cloudflare cloudfront digitalocean hetzner ovh telegram"
|
||||||
@@ -299,33 +299,11 @@ parse_domain_or_subnet_string_to_commas_string() {
|
|||||||
local string="$1"
|
local string="$1"
|
||||||
local type="$2"
|
local type="$2"
|
||||||
|
|
||||||
local result
|
tmpfile=$(mktemp)
|
||||||
for item in $string; do
|
printf "%s\n" "$string" | sed 's/\/\/.*//' | tr ', ' '\n' | grep -v '^$' > "$tmpfile"
|
||||||
case "$type" in
|
|
||||||
domains)
|
|
||||||
if ! is_domain_suffix "$item"; then
|
|
||||||
log "'$item' is not a valid domain" "debug"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
subnets)
|
|
||||||
if ! is_ipv4_ip_or_ipv4_cidr "$item"; then
|
|
||||||
log "'$item' is not IPv4 or IPv4 CIDR" "debug"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
log "Unknown type: $type" "error"
|
|
||||||
return 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if [ -z "$result" ]; then
|
result="$(parse_domain_or_subnet_file_to_comma_string "$tmpfile" "$type")"
|
||||||
result="$item"
|
rm -f "$tmpfile"
|
||||||
else
|
|
||||||
result="$result,$item"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "$result"
|
echo "$result"
|
||||||
}
|
}
|
||||||
@@ -345,6 +323,8 @@ parse_domain_or_subnet_file_to_comma_string() {
|
|||||||
|
|
||||||
local result
|
local result
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
|
line=$(echo "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
||||||
|
|
||||||
[ -z "$line" ] && continue
|
[ -z "$line" ] && continue
|
||||||
|
|
||||||
case "$type" in
|
case "$type" in
|
||||||
|
|||||||
Reference in New Issue
Block a user