mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-08 04:26:55 +03:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5eff41a0f | ||
|
|
bb1c06951c | ||
|
|
4999840340 | ||
|
|
6c5a271105 | ||
|
|
e336bb831c | ||
|
|
00db99723c | ||
|
|
5439504de7 | ||
|
|
c3072162de | ||
|
|
d021636f85 | ||
|
|
a06aac0613 | ||
|
|
29159243ea | ||
|
|
269123600a | ||
|
|
49add27f81 | ||
|
|
c929c74da5 | ||
|
|
bb91144a91 | ||
|
|
2291d9fb9d | ||
|
|
f722a513d0 | ||
|
|
a71707f174 |
17
README.md
17
README.md
@@ -4,12 +4,13 @@
|
|||||||
- При возникновении проблем, нужен технически грамотный фидбэк в чат.
|
- При возникновении проблем, нужен технически грамотный фидбэк в чат.
|
||||||
- При обновлении **обязательно** [сбрасывайте кэш LuCI](https://podkop.net/docs/clear-browser-cache/).
|
- При обновлении **обязательно** [сбрасывайте кэш LuCI](https://podkop.net/docs/clear-browser-cache/).
|
||||||
- Также при обновлении всегда заходите в конфигурацию и проверяйте свои настройки. Конфигурация может измениться.
|
- Также при обновлении всегда заходите в конфигурацию и проверяйте свои настройки. Конфигурация может измениться.
|
||||||
- Необходимо минимум 15МБ свободного места на роутере. Роутеры с флешками на 16МБ сразу мимо.
|
- Необходимо минимум 25МБ свободного места на роутере. Роутеры с флешками на 16МБ сразу мимо.
|
||||||
- При старте программы редактируется конфиг Dnsmasq.
|
- При старте программы редактируется конфиг Dnsmasq.
|
||||||
- Podkop редактирует конфиг sing-box. Обязательно сохраните ваш конфиг sing-box перед установкой, если он вам нужен.
|
- Podkop редактирует конфиг sing-box. Обязательно сохраните ваш конфиг sing-box перед установкой, если он вам нужен.
|
||||||
- Информация здесь может быть устаревшей. Все изменения фиксируются в [телеграм-чате](https://t.me/itdogchat/81758/420321).
|
- Информация здесь может быть устаревшей. Все изменения фиксируются в [телеграм-чате](https://t.me/itdogchat/81758/420321).
|
||||||
- [Если у вас не что-то не работает.](https://podkop.net/docs/diagnostics/)
|
- [Если у вас не что-то не работает.](https://podkop.net/docs/diagnostics/)
|
||||||
- Если у вас установлен Getdomains, [его следует удалить](https://github.com/itdoginfo/domain-routing-openwrt?tab=readme-ov-file#%D1%81%D0%BA%D1%80%D0%B8%D0%BF%D1%82-%D0%B4%D0%BB%D1%8F-%D1%83%D0%B4%D0%B0%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F).
|
- Если у вас установлен Getdomains, [его следует удалить](https://github.com/itdoginfo/domain-routing-openwrt?tab=readme-ov-file#%D1%81%D0%BA%D1%80%D0%B8%D0%BF%D1%82-%D0%B4%D0%BB%D1%8F-%D1%83%D0%B4%D0%B0%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F).
|
||||||
|
- Требуется версия OpenWrt 24.10.
|
||||||
|
|
||||||
# Документация
|
# Документация
|
||||||
https://podkop.net/
|
https://podkop.net/
|
||||||
@@ -28,17 +29,17 @@ sh <(wget -O - https://raw.githubusercontent.com/itdoginfo/podkop/refs/heads/mai
|
|||||||
Основные задачи в issues.
|
Основные задачи в issues.
|
||||||
|
|
||||||
## Рефактор
|
## Рефактор
|
||||||
- [ ] Очевидные повторения в `/usr/bin/podkop` загнать в переменые
|
- [x] Очевидные повторения в `/usr/bin/podkop` загнать в переменые
|
||||||
- [x] Возможно поменять структуру
|
- [x] Возможно поменять структуру
|
||||||
|
|
||||||
## Списки
|
## Списки
|
||||||
- [ ] CloudFront
|
- [x] CloudFront
|
||||||
- [ ] DO
|
- [x] DO
|
||||||
- [ ] HODCA
|
- [x] HODCA
|
||||||
|
|
||||||
## Будущее
|
## Будущее
|
||||||
- [ ] [Подписка](https://github.com/itdoginfo/podkop/issues/118). Здесь нужна реализация, чтоб для каждой секции помимо ручного выбора, был выбор фильтрации по тегу. Например, для main выбираем ключевые слова NL, DE, FI. А для extra секции фильтруем по RU. И создаётся outbound c urltest в которых перечислены outbound из фильтров.
|
- [ ] [Подписка](https://github.com/itdoginfo/podkop/issues/118). Здесь нужна реализация, чтоб для каждой секции помимо ручного выбора, был выбор фильтрации по тегу. Например, для main выбираем ключевые слова NL, DE, FI. А для extra секции фильтруем по RU. И создаётся outbound c urltest в которых перечислены outbound из фильтров.
|
||||||
- [ ] Опция, когда все запросы (с роутера в первую очередь), а не только br-lan идут в прокси. С этим связана #95. Требуется много переделать для nftables.
|
- [x] Опция, когда все запросы (с роутера в первую очередь), а не только br-lan идут в прокси. С этим связана #95. Требуется много переделать для nftables.
|
||||||
- [ ] Весь трафик в Proxy\VPN. Вопрос, что делать с экстрасекциями в этом случае. FakeIP здесь скорее не нужен, а значит только main секция остаётся. Всё что касается fakeip проверок, придётся выключать в этом режиме.
|
- [ ] Весь трафик в Proxy\VPN. Вопрос, что делать с экстрасекциями в этом случае. FakeIP здесь скорее не нужен, а значит только main секция остаётся. Всё что касается fakeip проверок, придётся выключать в этом режиме.
|
||||||
- [x] Поддержка Source format. Нужна расшифровка в json и если присуствуют подсети, заносить их в custom subnet nftset.
|
- [x] Поддержка Source format. Нужна расшифровка в json и если присуствуют подсети, заносить их в custom subnet nftset.
|
||||||
- [x] Переделывание функции формирования кастомных списков в JSON. Обрабатывать сразу скопом, а не по одному.
|
- [x] Переделывание функции формирования кастомных списков в JSON. Обрабатывать сразу скопом, а не по одному.
|
||||||
@@ -49,4 +50,6 @@ sh <(wget -O - https://raw.githubusercontent.com/itdoginfo/podkop/refs/heads/mai
|
|||||||
|
|
||||||
## Тесты
|
## Тесты
|
||||||
- [ ] Unit тесты (BATS)
|
- [ ] Unit тесты (BATS)
|
||||||
- [ ] Интеграционые тесты бекенда (OpenWrt rootfs + BATS)
|
- [ ] Интеграционые тесты бекенда (OpenWrt rootfs + BATS)
|
||||||
|
|
||||||
|
[](https://deepwiki.com/itdoginfo/podkop)
|
||||||
11
install.sh
11
install.sh
@@ -108,6 +108,15 @@ check_system() {
|
|||||||
MODEL=$(cat /tmp/sysinfo/model)
|
MODEL=$(cat /tmp/sysinfo/model)
|
||||||
msg "Router model: $MODEL"
|
msg "Router model: $MODEL"
|
||||||
|
|
||||||
|
# Check OpenWrt version
|
||||||
|
openwrt_version=$(cat /etc/openwrt_release | grep DISTRIB_RELEASE | cut -d"'" -f2 | cut -d'.' -f1)
|
||||||
|
if [ "$openwrt_version" = "23" ]; then
|
||||||
|
msg "OpenWrt 23.05 не поддерживается начиная с podkop 0.5.0"
|
||||||
|
msg "Для OpenWrt 23.05 используйте podkop версии 0.4.11 или устанавливайте зависимости и podkop вручную"
|
||||||
|
msg "Подробности: https://podkop.net/docs/install/#%d1%83%d1%81%d1%82%d0%b0%d0%bd%d0%be%d0%b2%d0%ba%d0%b0-%d0%bd%d0%b0-2305"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Check available space
|
# Check available space
|
||||||
AVAILABLE_SPACE=$(df /overlay | awk 'NR==2 {print $4}')
|
AVAILABLE_SPACE=$(df /overlay | awk 'NR==2 {print $4}')
|
||||||
REQUIRED_SPACE=15360 # 15MB in KB
|
REQUIRED_SPACE=15360 # 15MB in KB
|
||||||
@@ -150,7 +159,7 @@ sing_box() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
sing_box_version=$(sing-box version | head -n 1 | awk '{print $3}')
|
sing_box_version=$(sing-box version | head -n 1 | awk '{print $3}')
|
||||||
required_version="1.11.1"
|
required_version="1.12.4"
|
||||||
|
|
||||||
if [ "$(echo -e "$sing_box_version\n$required_version" | sort -V | head -n 1)" != "$required_version" ]; then
|
if [ "$(echo -e "$sing_box_version\n$required_version" | sort -V | head -n 1)" != "$required_version" ]; then
|
||||||
msg "sing-box version $sing_box_version is older than required $required_version"
|
msg "sing-box version $sing_box_version is older than required $required_version"
|
||||||
|
|||||||
@@ -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');
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
@@ -83,13 +82,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
|
||||||
|
|
||||||
@@ -238,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -629,7 +635,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 +649,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
|
||||||
@@ -939,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() {
|
||||||
@@ -1021,7 +1064,7 @@ import_local_domain_or_subnet_list() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local items json_array
|
local items json_array
|
||||||
items="$(parse_domain_or_subnet_file_to_comma_string "$tmpfile" "domains")"
|
items="$(parse_domain_or_subnet_file_to_comma_string "$filepath" "$type")"
|
||||||
|
|
||||||
if [ -z "$items" ]; then
|
if [ -z "$items" ]; then
|
||||||
log "No valid $type found in $filepath"
|
log "No valid $type found in $filepath"
|
||||||
@@ -1135,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"
|
||||||
@@ -1149,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
|
||||||
}
|
}
|
||||||
@@ -1375,7 +1420,7 @@ get_service_proxy_address() {
|
|||||||
local detour
|
local detour
|
||||||
config_get_bool detour "main" "detour" 0
|
config_get_bool detour "main" "detour" 0
|
||||||
if [ "$detour" -eq 1 ]; then
|
if [ "$detour" -eq 1 ]; then
|
||||||
echo "$SB_SERVICE_MIXED_INBOUND_TAG:$SB_SERVICE_MIXED_INBOUND_PORT"
|
echo "$SB_SERVICE_MIXED_INBOUND_ADDRESS:$SB_SERVICE_MIXED_INBOUND_PORT"
|
||||||
else
|
else
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
@@ -1720,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' \
|
||||||
@@ -1737,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"
|
||||||
@@ -16,10 +16,18 @@ is_ipv4_ip_or_ipv4_cidr() {
|
|||||||
is_ipv4 "$1" || is_ipv4_cidr "$1"
|
is_ipv4 "$1" || is_ipv4_cidr "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if string is valid domain
|
|
||||||
is_domain() {
|
is_domain() {
|
||||||
local str="$1"
|
local str="$1"
|
||||||
echo "$str" | grep -Eq '^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9]))+$'
|
local regex='^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$'
|
||||||
|
|
||||||
|
[[ "$str" =~ $regex ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
is_domain_suffix() {
|
||||||
|
local str="$1"
|
||||||
|
local normalized="${str#.}"
|
||||||
|
|
||||||
|
is_domain "$normalized"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Checks if the given string is a valid base64-encoded sequence
|
# Checks if the given string is a valid base64-encoded sequence
|
||||||
@@ -291,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 "$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"
|
||||||
}
|
}
|
||||||
@@ -337,11 +323,13 @@ 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
|
||||||
domains)
|
domains)
|
||||||
if ! is_domain "$line"; then
|
if ! is_domain_suffix "$line"; then
|
||||||
log "'$line' is not a valid domain" "debug"
|
log "'$line' is not a valid domain" "debug"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -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