mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-07 03:56:55 +03:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57554d518b | ||
|
|
09d761956c | ||
|
|
ada807fec3 | ||
|
|
b28a5f1293 | ||
|
|
2332eae5ff | ||
|
|
a755b6661d | ||
|
|
567ce52253 | ||
|
|
b736360b66 |
10
README.md
10
README.md
@@ -74,16 +74,18 @@ Luci: Services/podkop
|
||||
**Custom subnets enable** - Добавить подсети или IP-адреса. Для подсетей задать маску.
|
||||
|
||||
# Известные баги
|
||||
- [ ] Не отрабатывает service podkop stop, если podkop запущен и не может, к пример, зарезолвить домен с сломанным DNS
|
||||
- [ ] Update list из remote url domain не удаляет старые домены. А добавляет новые. Для подсетей тоже самое скорее всего. Пересоздавать ruleset?
|
||||
- [x] Не отрабатывает service podkop stop, если podkop запущен и не может, к пример, зарезолвить домен с сломанным DNS
|
||||
- [x] Update list из remote url domain не удаляет старые домены. А добавляет новые. Для подсетей тоже самое скорее всего. Пересоздавать ruleset?
|
||||
|
||||
# ToDo
|
||||
Этот раздел не означает задачи, которые нужно брать и делать. Это общий список хотелок. Если вы хотите помочь, пожалуйста, спросите сначала в телеграмме.
|
||||
|
||||
- [ ] Проверка, что версия в makefile совпадает с тегом
|
||||
- [ ] Диагностика: Proxy check completed successfully предположительно не показывает IP, если вернулся это IPv6.
|
||||
- [ ] Сделать галку запрещающую подкопу редачить dhcp. Допилить в исключение вместе с пустыми полями proxy и vpn
|
||||
- [ ] Обработка ошибки `sing-box[9345]: FATAL[0000] start service: initialize DNS rule[2]: rule-set not found: main`. Когда не задана строка\интерфейс
|
||||
- [x] Обработка ошибки `sing-box[9345]: FATAL[0000] start service: initialize DNS rule[2]: rule-set not found: main`. Когда не задана строка\интерфейс
|
||||
- [x] Проверка `/etc/resolv.conf` на наличие DNS-серверов
|
||||
- [x] Отслеживание интерфейса wan в sing-box
|
||||
- [ ] Рестарт сервиса без рестарта dnsmasq
|
||||
|
||||
Низкий приоритет
|
||||
- [ ] Галочка, которая режет доступ к doh серверам
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-podkop
|
||||
PKG_VERSION:=0.3.23
|
||||
PKG_VERSION:=0.3.25
|
||||
PKG_RELEASE:=1
|
||||
|
||||
LUCI_TITLE:=LuCI podkop app
|
||||
|
||||
@@ -827,7 +827,7 @@ return view.extend({
|
||||
o.value('dns.adguard-dns.com', 'AdGuard Default (dns.adguard-dns.com)');
|
||||
o.value('unfiltered.adguard-dns.com', 'AdGuard Unfiltered (unfiltered.adguard-dns.com)');
|
||||
o.value('family.adguard-dns.com', 'AdGuard Family (family.adguard-dns.com)');
|
||||
o.default = '1.1.1.1';
|
||||
o.default = '8.8.8.8';
|
||||
o.rmempty = false;
|
||||
o.ucisection = 'main';
|
||||
o.validate = function (section_id, value) {
|
||||
@@ -856,7 +856,7 @@ return view.extend({
|
||||
};
|
||||
|
||||
o = mainSection.taboption('additional', form.Value, 'dns_rewrite_ttl', _('DNS Rewrite TTL'), _('Time in seconds for DNS record caching (default: 600)'));
|
||||
o.default = '600';
|
||||
o.default = '60';
|
||||
o.rmempty = false;
|
||||
o.ucisection = 'main';
|
||||
o.validate = function (section_id, value) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=podkop
|
||||
PKG_VERSION:=0.3.23
|
||||
PKG_VERSION:=0.3.25
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_MAINTAINER:=ITDog <podkop@itdog.info>
|
||||
|
||||
@@ -32,6 +32,6 @@ config main 'main'
|
||||
option dont_touch_dhcp '0'
|
||||
option update_interval '1d'
|
||||
option dns_type 'doh'
|
||||
option dns_server '1.1.1.1'
|
||||
option dns_rewrite_ttl '600'
|
||||
option dns_server '8.8.8.8'
|
||||
option dns_rewrite_ttl '60'
|
||||
option cache_file '/tmp/cache.db'
|
||||
@@ -6,6 +6,7 @@ USE_PROCD=1
|
||||
script=$(readlink "$initscript")
|
||||
NAME="$(basename ${script:-$initscript})"
|
||||
config_load "$NAME"
|
||||
resolv_conf="/etc/resolv.conf"
|
||||
|
||||
start_service() {
|
||||
echo "Start podkop"
|
||||
@@ -31,6 +32,10 @@ start_service() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! grep -q "search lan" "$resolv_conf" || ! grep -q "nameserver 127.0.0.1" "$resolv_conf"; then
|
||||
echo "/etc/resolv.conf does not contain 'search lan' or 'nameserver 127.0.0.1' entries"
|
||||
fi
|
||||
|
||||
procd_open_instance
|
||||
procd_set_param command /bin/sh -c "/usr/bin/podkop start"
|
||||
procd_set_param stdout 1
|
||||
|
||||
@@ -68,15 +68,17 @@ start() {
|
||||
# sing-box outbounds and rules
|
||||
config_foreach sing_box_outdound
|
||||
config_foreach process_domains_for_section
|
||||
config_foreach process_remote_ruleset
|
||||
config_foreach sing_box_rule_preset
|
||||
config_foreach process_domains_list_local
|
||||
config_foreach process_domains_list_url
|
||||
config_foreach process_subnet_for_section
|
||||
config_foreach process_subnet_for_section_remote
|
||||
config_foreach process_remote_ruleset_srs
|
||||
config_foreach process_all_traffic_for_section
|
||||
config_foreach add_cron_job
|
||||
|
||||
config_foreach prepare_custom_ruleset
|
||||
list_update &
|
||||
echo $! > /var/run/podkop_list_update.pid
|
||||
|
||||
# Future: exclude at the fakeip?
|
||||
config_get_bool exclude_from_ip_enabled "main" "exclude_from_ip_enabled" "0"
|
||||
if [ "$exclude_from_ip_enabled" -eq 1 ]; then
|
||||
@@ -123,6 +125,16 @@ start() {
|
||||
|
||||
stop() {
|
||||
log "Stopping the podkop"
|
||||
|
||||
if [ -f /var/run/podkop_list_update.pid ]; then
|
||||
pid=$(cat /var/run/podkop_list_update.pid)
|
||||
if kill -0 "$pid"; then
|
||||
kill "$pid"
|
||||
log "Stopped list_update"
|
||||
fi
|
||||
rm -f /var/run/podkop_list_update.pid
|
||||
fi
|
||||
|
||||
remove_cron_job
|
||||
|
||||
config_get_bool dont_touch_dhcp "main" "dont_touch_dhcp" "0"
|
||||
@@ -202,6 +214,9 @@ migration() {
|
||||
log "Found and removed use-application-dns.net in dhcp config"
|
||||
sed -i '/use-application-dns/d' "/etc/config/dhcp"
|
||||
fi
|
||||
|
||||
# corntab init.d
|
||||
(crontab -l | grep -v "/etc/init.d/podkop list_update") | crontab -
|
||||
}
|
||||
|
||||
validate_service() {
|
||||
@@ -389,19 +404,19 @@ add_cron_job() {
|
||||
|
||||
case "$update_interval" in
|
||||
"1h")
|
||||
cron_job="13 * * * * /etc/init.d/podkop list_update"
|
||||
cron_job="13 * * * * /usr/bin/podkop list_update"
|
||||
;;
|
||||
"3h")
|
||||
cron_job="13 */3 * * * /etc/init.d/podkop list_update"
|
||||
cron_job="13 */3 * * * /usr/bin/podkop list_update"
|
||||
;;
|
||||
"12h")
|
||||
cron_job="13 */12 * * * /etc/init.d/podkop list_update"
|
||||
cron_job="13 */12 * * * /usr/bin/podkop list_update"
|
||||
;;
|
||||
"1d")
|
||||
cron_job="13 9 * * * /etc/init.d/podkop list_update"
|
||||
cron_job="13 9 * * * /usr/bin/podkop list_update"
|
||||
;;
|
||||
"3d")
|
||||
cron_job="13 9 */3 * * /etc/init.d/podkop list_update"
|
||||
cron_job="13 9 */3 * * /usr/bin/podkop list_update"
|
||||
;;
|
||||
*)
|
||||
log "Invalid update_interval value: $update_interval"
|
||||
@@ -421,13 +436,74 @@ add_cron_job() {
|
||||
}
|
||||
|
||||
remove_cron_job() {
|
||||
(crontab -l | grep -v "/etc/init.d/podkop list_update") | crontab -
|
||||
(crontab -l | grep -v "/usr/bin/podkop list_update") | crontab -
|
||||
log "The cron job removed"
|
||||
}
|
||||
|
||||
prepare_custom_ruleset() {
|
||||
config_get custom_download_domains_list_enabled "$section" "custom_download_domains_list_enabled"
|
||||
config_get custom_download_subnets_list_enabled "$section" "custom_download_subnets_list_enabled"
|
||||
if [ "$custom_download_domains_list_enabled" -eq 1 ] || [ "$custom_download_subnets_list_enabled" -eq 1 ]; then
|
||||
local file="/tmp/podkop/$section-custom-domains-subnets.json"
|
||||
local tag="custom-$section"
|
||||
rm -f $file
|
||||
|
||||
jq -n '
|
||||
{
|
||||
"version": 3,
|
||||
"rules": []
|
||||
}' > $file
|
||||
|
||||
jq --arg tag "$tag" \
|
||||
--arg file "$file" \
|
||||
'.route.rule_set += [{
|
||||
"tag": $tag,
|
||||
"type": "local",
|
||||
"format": "source",
|
||||
"path": $file
|
||||
}]' $SING_BOX_CONFIG >/tmp/sing-box-config-tmp.json && mv /tmp/sing-box-config-tmp.json $SING_BOX_CONFIG
|
||||
|
||||
sing_box_rules $tag $section
|
||||
sing_box_dns_rule_fakeip_section $tag $tag
|
||||
|
||||
log "Added 'test' rule_set to sing-box config"
|
||||
fi
|
||||
}
|
||||
|
||||
list_update() {
|
||||
log "Update remote lists"
|
||||
config_foreach process_remote_ruleset
|
||||
|
||||
local i
|
||||
|
||||
for i in $(seq 1 60); do
|
||||
if nslookup -timeout=1 openwrt.org >/dev/null 2>&1; then
|
||||
log "DNS is available"
|
||||
break
|
||||
fi
|
||||
log "DNS is unavailable [$i/60]"
|
||||
sleep 3
|
||||
done
|
||||
|
||||
if [ "$i" -eq 60 ]; then
|
||||
log "Error: DNS check failed after 10 attempts"
|
||||
return 1
|
||||
fi
|
||||
|
||||
for i in $(seq 1 60); do
|
||||
if curl -s -m 3 https://github.com >/dev/null; then
|
||||
log "GitHub is available"
|
||||
break
|
||||
fi
|
||||
log "GitHub is unavailable [$i/60]"
|
||||
sleep 3
|
||||
done
|
||||
|
||||
if [ "$i" -eq 60 ]; then
|
||||
log "Error: Cannot connect to GitHub after 10 attempts"
|
||||
return 1
|
||||
fi
|
||||
|
||||
config_foreach process_remote_ruleset_subnet
|
||||
config_foreach process_domains_list_url
|
||||
config_foreach process_subnet_for_section_remote
|
||||
}
|
||||
@@ -454,35 +530,53 @@ sing_box_uci() {
|
||||
-e "s/option enabled '0'/option enabled '1'/" \
|
||||
-e "s/option user 'sing-box'/option user 'root'/" $config
|
||||
log "Change sing-box UCI config"
|
||||
else
|
||||
log "Sing-box UCI config OK"
|
||||
fi
|
||||
|
||||
if grep -q '#\s*list ifaces' "$config"; then
|
||||
sed -i '/ifaces/s/#//g' $config
|
||||
log "Uncommented list ifaces"
|
||||
fi
|
||||
}
|
||||
|
||||
# Future: for every section. +1 port?
|
||||
add_socks5_for_section() {
|
||||
local section="$1"
|
||||
local port="$2"
|
||||
local tag="$section-mixed-in"
|
||||
|
||||
log "Adding Socks5 for $section on port $port"
|
||||
|
||||
jq \
|
||||
--arg tag "$tag" \
|
||||
--arg port "$port" \
|
||||
--arg section "$section" \
|
||||
'.inbounds += [{
|
||||
"tag": $tag,
|
||||
"type": "mixed",
|
||||
"listen": "0.0.0.0",
|
||||
"listen_port": ($port|tonumber),
|
||||
"set_system_proxy": false
|
||||
}] |
|
||||
.route.rules += [{
|
||||
"inbound": [$tag],
|
||||
"outbound": $section,
|
||||
"action": "route"
|
||||
}]' $SING_BOX_CONFIG >/tmp/sing-box-config-tmp.json && mv /tmp/sing-box-config-tmp.json $SING_BOX_CONFIG
|
||||
}
|
||||
|
||||
process_socks5() {
|
||||
config_get_bool socks5 "main" "socks5" "0"
|
||||
if [ "$socks5" -eq 1 ]; then
|
||||
log "Socks5 local enable port 2080"
|
||||
jq '.inbounds += [{
|
||||
"tag": "mixed-in",
|
||||
"type": "mixed",
|
||||
"listen": "0.0.0.0",
|
||||
"listen_port": 2080,
|
||||
"set_system_proxy": false
|
||||
}]' $SING_BOX_CONFIG >/tmp/sing-box-config-tmp.json && mv /tmp/sing-box-config-tmp.json $SING_BOX_CONFIG
|
||||
|
||||
#local rule_exists=$(jq -r '.route.rules[] | select(.inbound[] == "mixed-in")' $SING_BOX_CONFIG)
|
||||
local rule_exists=$(jq -r '.route.rules // [] | map(select(.inbound // [] | index("mixed-in"))) | length' $SING_BOX_CONFIG)
|
||||
|
||||
if [ -z "$rule_exists" ]; then
|
||||
jq '.route.rules += [{
|
||||
"inbound": ["mixed-in"],
|
||||
"outbound": "main",
|
||||
"action": "route"
|
||||
}]' $SING_BOX_CONFIG >/tmp/sing-box-config-tmp.json && mv /tmp/sing-box-config-tmp.json $SING_BOX_CONFIG
|
||||
fi
|
||||
config_get_bool main_socks5 "main" "socks5" "0"
|
||||
if [ "$main_socks5" -eq 1 ]; then
|
||||
add_socks5_for_section "main" "2080"
|
||||
fi
|
||||
|
||||
local port=2081
|
||||
for section in $(uci show podkop | awk -F'[.=]' '/=extra/ {print $2}'); do
|
||||
config_get_bool section_socks5 "$section" "socks5" "0"
|
||||
if [ "$section_socks5" -eq 1 ]; then
|
||||
add_socks5_for_section "$section" "$port"
|
||||
port=$((port + 1))
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
sing_box_inbound_proxy() {
|
||||
@@ -669,6 +763,12 @@ sing_box_outdound() {
|
||||
log "VPN mode"
|
||||
log "You are using VPN mode, make sure you have installed all the necessary packages and configured."
|
||||
config_get interface "$section" "interface"
|
||||
|
||||
if [ -z "$interface" ]; then
|
||||
log "VPN interface is not set. Exit"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sing_box_outbound_interface $section $interface
|
||||
;;
|
||||
"proxy")
|
||||
@@ -691,8 +791,8 @@ sing_box_outdound() {
|
||||
active_proxy_string=$(echo "$proxy_string" | grep -v "^[[:space:]]*\/\/" | head -n 1)
|
||||
|
||||
if [ -z "$active_proxy_string" ]; then
|
||||
log "No active proxy configuration found"
|
||||
return
|
||||
log "Proxy string is not set. Exit"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$active_proxy_string" =~ ^ss:// ]]; then
|
||||
@@ -1091,6 +1191,32 @@ sing_box_ruleset_subnets() {
|
||||
fi
|
||||
}
|
||||
|
||||
sing_box_ruleset_domains_json() {
|
||||
local domain="$1"
|
||||
local section="$2"
|
||||
|
||||
local file="/tmp/podkop/$section-custom-domains-subnets.json"
|
||||
|
||||
jq --arg domain "$domain" '
|
||||
.rules[0].domain_suffix += if .rules[0].domain_suffix | index($domain) then [] else [$domain] end
|
||||
' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
|
||||
|
||||
log "$domain added to $section-custom-domains-subnets.json"
|
||||
}
|
||||
|
||||
sing_box_ruleset_subnets_json() {
|
||||
local subnet="$1"
|
||||
local section="$2"
|
||||
|
||||
local file="/tmp/podkop/$section-custom-domains-subnets.json"
|
||||
|
||||
jq --arg subnet "$subnet" '
|
||||
.rules[0].ip_cidr += if .rules[0].ip_cidr | index($subnet) then [] else [$subnet] end
|
||||
' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
|
||||
|
||||
log "$subnet added to $section-custom-domains-subnets.json"
|
||||
}
|
||||
|
||||
process_domains_for_section() {
|
||||
local section="$1"
|
||||
|
||||
@@ -1227,11 +1353,18 @@ sing_box_quic_reject() {
|
||||
fi
|
||||
}
|
||||
|
||||
process_remote_ruleset() {
|
||||
process_remote_ruleset_srs() {
|
||||
config_get_bool domain_list_enabled "$section" "domain_list_enabled" "0"
|
||||
if [ "$domain_list_enabled" -eq 1 ]; then
|
||||
log "Adding a srs list for $section"
|
||||
config_list_foreach "$section" domain_list "sing_box_ruleset_remote" "remote" "1d"
|
||||
fi
|
||||
}
|
||||
|
||||
process_remote_ruleset_subnet() {
|
||||
config_get_bool domain_list_enabled "$section" "domain_list_enabled" "0"
|
||||
if [ "$domain_list_enabled" -eq 1 ]; then
|
||||
log "Adding a srs list for $section"
|
||||
config_list_foreach "$section" domain_list "list_subnets_download" "$section" "$domain_list"
|
||||
fi
|
||||
}
|
||||
@@ -1240,17 +1373,15 @@ sing_box_rule_preset() {
|
||||
config_get custom_domains_list_type "$section" "custom_domains_list_type"
|
||||
config_get custom_subnets_list_enabled "$section" "custom_subnets_list_enabled"
|
||||
config_get custom_local_domains_list_enabled "$section" "custom_local_domains_list_enabled"
|
||||
config_get custom_download_domains_list_enabled "$section" "custom_download_domains_list_enabled"
|
||||
config_get custom_download_subnets_list_enabled "$section" "custom_download_subnets_list_enabled"
|
||||
# config_get custom_download_domains_list_enabled "$section" "custom_download_domains_list_enabled"
|
||||
# config_get custom_download_subnets_list_enabled "$section" "custom_download_subnets_list_enabled"
|
||||
|
||||
if [ "$custom_domains_list_type" != "disabled" ] || [ "$custom_subnets_list_enabled" != "disabled" ] ||
|
||||
[ "$custom_local_domains_list_enabled" = "1" ] || [ "$custom_download_domains_list_enabled" = "1" ] ||
|
||||
[ "$custom_download_subnets_list_enabled" = "1" ]; then
|
||||
[ "$custom_local_domains_list_enabled" = "1" ]; then
|
||||
sing_box_rules "$section" "$section"
|
||||
fi
|
||||
|
||||
if [ "$custom_domains_list_type" != "disabled" ] || [ "$custom_local_domains_list_enabled" = "1" ] ||
|
||||
[ "$custom_download_domains_list_enabled" = "1" ]; then
|
||||
if [ "$custom_domains_list_type" != "disabled" ] || [ "$custom_local_domains_list_enabled" = "1" ]; then
|
||||
sing_box_dns_rule_fakeip_section "$section" "$section"
|
||||
fi
|
||||
|
||||
@@ -1296,8 +1427,8 @@ list_custom_url_domains_create() {
|
||||
wget -q -O "/tmp/podkop/${filename}" "$URL"
|
||||
|
||||
while IFS= read -r domain; do
|
||||
log "From local file: $domain"
|
||||
sing_box_ruleset_domains $domain $section
|
||||
log "From downloaded file: $domain"
|
||||
sing_box_ruleset_domains_json $domain $section
|
||||
done <"/tmp/podkop/$filename"
|
||||
}
|
||||
|
||||
@@ -1337,7 +1468,8 @@ list_custom_url_subnets_create() {
|
||||
|
||||
while IFS= read -r subnet; do
|
||||
log "From local file: $subnet"
|
||||
sing_box_ruleset_subnets $subnet $section
|
||||
sing_box_ruleset_subnets_json $subnet $section
|
||||
nft add element inet PodkopTable podkop_subnets { $subnet }
|
||||
done <"/tmp/podkop/$filename"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user