Compare commits

...

29 Commits

Author SHA1 Message Date
itdoginfo
96ea424498 0.2.2 2024-11-06 14:00:25 +03:00
itdoginfo
0ad4133202 Fix hotplug, added logger, fix add_route 2024-11-06 13:59:15 +03:00
itdoginfo
b29a187d46 0.2.1 2024-11-05 18:31:04 +03:00
itdoginfo
adecd707cd Update 2024-11-05 18:27:44 +03:00
itdoginfo
eba1cbef64 Added interface up waiting 2024-11-05 18:27:36 +03:00
itdoginfo
ad21de83a9 Comment all list values 2024-11-05 18:26:48 +03:00
itdoginfo
fae0e42722 Uprade only mode, small refactor 2024-11-05 18:26:23 +03:00
itdoginfo
50f702aef9 Update 2024-11-05 14:05:11 +03:00
itdoginfo
d9c1f2a95c Merge pull request #1 from Slava-Shchipunov/main
Добавил автоматическую настройку туннелей awmneziawg и wg
2024-11-05 11:43:13 +03:00
Slava-Shchipunov
ee8bef67ee refactor: add handler_network_restart 2024-11-05 10:27:57 +07:00
Slava-Shchipunov
dcc0733b89 docs: update readme 2024-11-03 22:38:55 +07:00
Slava-Shchipunov
e154718e90 refactor: move wg-awg setup to install.sh 2024-11-03 22:19:36 +07:00
Slava-Shchipunov
a53adb2df1 refactor: move install awg packages to install.sh 2024-11-03 22:16:34 +07:00
Slava-Shchipunov
fe245c31c3 refactor: move add tunnel to function 2024-11-03 22:13:16 +07:00
Slava-Shchipunov
ee6bbe3f13 Merge remote-tracking branch 'upstream/main' 2024-11-03 22:06:52 +07:00
itdoginfo
f48670018f 0.2.0 2024-11-01 22:30:32 +03:00
itdoginfo
8870a56885 Move to PROCD 2024-11-01 22:02:58 +03:00
Slava-Shchipunov
8cf9f4b61b fix: add lost quotation mark 2024-11-01 21:22:40 +07:00
Slava-Shchipunov
fea3ae8606 Merge pull request #1 from Slava-Shchipunov/feat/add-amneziawg-auto-install
Feat/add amneziawg auto install
2024-11-01 20:42:43 +07:00
Slava-Shchipunov
2524e08096 feat: update obfuscation Jc 2024-11-01 20:33:27 +07:00
Slava-Shchipunov
9754708fc1 refactor: add raw base url 2024-11-01 20:25:37 +07:00
Slava-Shchipunov
afe96ff295 fix: fix syntax error 2024-11-01 18:07:56 +07:00
Slava-Shchipunov
708cbe5a97 feat: add wg obfuscation 2024-11-01 17:54:33 +07:00
Slava-Shchipunov
65efe20fd2 feat: add wg auto setup 2024-11-01 17:26:31 +07:00
Slava-Shchipunov
7b9f7ba605 fix: move network restart run 2024-10-30 10:23:52 +07:00
Slava-Shchipunov
415b5df621 fix: fix run wg-awg-setup 2024-10-30 10:13:57 +07:00
Slava-Shchipunov
0c8896bb6f feat: add wg_awg_setup script 2024-10-30 10:00:38 +07:00
Slava-Shchipunov
bdcbba1376 feat: add awg install script 2024-10-30 09:29:11 +07:00
Slava-Shchipunov
d070ba5c4e feat: add awg install to install.sh 2024-10-30 09:23:08 +07:00
7 changed files with 409 additions and 110 deletions

View File

@@ -20,6 +20,10 @@ sh <(wget -O - https://raw.githubusercontent.com/itdoginfo/domain-routing-openwr
sh <(wget -O - https://raw.githubusercontent.com/itdoginfo/podkop/refs/heads/main/install.sh)
```
Скрипт также предложит выбрать, какой туннель будет использоваться. Для выбранного туннеля будут установлены нужные пакеты, а для Wireguard и AmneziaWG также будет предложена автоматическая настройка - прямо в консоли скрипт запросит данные конфига. Для AmneziaWG можно также выбрать вариант с использованием конфига обычного Wireguard и автоматической обфускацией до AmneziaWG.
Для AmneziaWG скрипт проверяет наличие пакетов под вашу платформу в [стороннем репозитории](https://github.com/Slava-Shchipunov/awg-openwrt/releases), так как в официальном репозитории OpenWRT они отсутствуют, и автоматически их устанавливает.
## Вручную
Сделать `opkg update`, чтоб установились зависимости.
Скачать пакеты `podkop_*.ipk` и `luci-app-podkop_*.ipk` из релиза. `opkg install` сначала первый, потом второй.
@@ -63,8 +67,10 @@ opkg update && opkg install sing-box
# Известные баги
- [x] Не работает proxy при режимах main vpn, second proxy
- [ ] Не всегда отрабатывает ucitrack (применение настроек из luci). Не удаётся повторить
- [x] Не всегда отрабатывает ucitrack (применение настроек из luci). Не удаётся повторить
- [x] All traffic for IP ломает инет на клиенте. Proxy mode
- [ ] Не отрабатывает рестарт, при awg и не применяются изменения при awg
- [ ] awg работает не стабильно
# ToDo
Сделано
@@ -85,39 +91,39 @@ opkg update && opkg install sing-box
- [x] Открытый прокси порт на роутере для браузеров
Приоритет 1
- [ ] Переделать на PROCD и выкинуть ucitrack
- [ ] Нужен дебаг. Restart ucitrack в отдельный скрипт postinst, не отрабатывает.
- [x] Переделать на PROCD и выкинуть ucitrack.
- [x] Нужен дебаг. Restart ucitrack в отдельный скрипт postinst, не отрабатывает.
- [ ] Закомментировать дефолтные значения у list. interface поставить в пустое.
- [ ] Скрипт установки: проверка установлен ли уже podkop. Если да, то просто предлагать обновится без установки тунелей и прокси.
Приоритет 2
- [ ] Списки доменов и подсетей с роутера
- [ ] Кнопка обновления списка доменов и подсетей
- [ ] IPv6
- [ ] Придумать автонастройку DNS через stubby итд. Как лучше это реализовать.
- [ ] Удаление подсетей CF из domain sets раз в N часов
- [ ] Автонастройка wireguard по примеру getdomains
- [ ] Автонастройка awg по примеру getdomains
- [x] Автонастройка wireguard по примеру getdomains
- [x] Автонастройка awg по примеру getdomains
Wiki
- [ ] Тема
- [ ] Изначальное наполнение
- [ ] Nginx+acme.sh ansible playbook
- [ ] Сборка и деплой через github actions
- [ ] Общий мониторинг VM
- [ ] Мониторинг tls
- [x] Тема
- [x] Изначальное наполнение
Низкий приоритет
- [ ] Переменная, раз во сколько часов обновлять списки
- [ ] Галочка, которая режет доступ к doh серверам
- [ ] Свой конфиг sing-box
Рефактор
- [ ] Handle для sing-box
- [ ] Handle для dnsmasq
- [ ] Формирование json для sing-box на уровне jq, а не шаблонов
- [ ] Unit тесты (BATS)
- [ ] Интеграционые тесты бекенда (OpenWrt rootfs + BATS)
- [ ] RU перевод
- [ ] Handle для sing-box
- [ ] Handle для dnsmasq
Хз как сделать
- [ ] Добавить label от конфига vless\ss\etc в luci. Хз как
- [ ] Добавить label от конфига vless\ss\etc в luci.
# Разработка
Есть два варианта:

View File

@@ -2,9 +2,11 @@
REPO="https://api.github.com/repos/itdoginfo/podkop/releases/latest"
IS_SHOULD_RESTART_NETWORK=false
DOWNLOAD_DIR="/tmp/podkop"
mkdir -p "$DOWNLOAD_DIR"
main() {
wget -qO- "$REPO" | grep -o 'https://[^"]*\.ipk' | while read -r url; do
filename=$(basename "$url")
echo "Download $filename..."
@@ -24,15 +26,52 @@ else
[ -f /etc/config/dhcp-opkg ] && cp /etc/config/dhcp /etc/config/dhcp-old && mv /etc/config/dhcp-opkg /etc/config/dhcp
fi
echo "What type of VPN or proxy will be used?"
echo "1) VLESS, Shadowsocks (A sing-box will be installed)"
echo "2) Wireguard"
echo "3) AmneziaWG"
echo "4) OpenVPN"
echo "5) OpenConnect"
echo "6) Skip this step"
if [ -f "/etc/init.d/podkop" ]; then
printf "\033[32;1mPodkop is already installed. Just upgrade it? (y/n)\033[0m\n"
printf "\033[32;1my - Only upgrade podkop\033[0m\n"
printf "\033[32;1mn - Upgrade and install proxy or tunnels\033[0m\n"
while true; do
while true; do
read -r -p '' UPDATE
case $UPDATE in
y)
echo "Upgraded podkop..."
break
;;
n)
add_tunnel
break
;;
esac
done
else
echo "Installed podkop..."
add_tunnel
fi
opkg install $DOWNLOAD_DIR/podkop*.ipk
opkg install $DOWNLOAD_DIR/luci-app-podkop*.ipk
rm -f $DOWNLOAD_DIR/podkop*.ipk $DOWNLOAD_DIR/luci-app-podkop*.ipk
if [ "$IS_SHOULD_RESTART_NETWORK" ]; then
printf "\033[32;1mRestart network\033[0m\n"
/etc/init.d/network restart
fi
}
add_tunnel() {
echo "What type of VPN or proxy will be used? We also can automatically configure Wireguard and Amnezia WireGuard."
echo "1) VLESS, Shadowsocks (A sing-box will be installed)"
echo "2) Wireguard"
echo "3) AmneziaWG"
echo "4) OpenVPN"
echo "5) OpenConnect"
echo "6) Skip this step"
while true; do
read -r -p '' TUNNEL
case $TUNNEL in
@@ -43,13 +82,29 @@ while true; do
2)
opkg install wireguard-tools luci-proto-wireguard luci-app-wireguard
printf "\e[1;32mUse these instructions to configure https://itdog.info/nastrojka-klienta-wireguard-na-openwrt/\e[0m\n"
printf "\033[32;1mDo you want to configure the wireguard interface? (y/n): \033[0m\n"
read IS_SHOULD_CONFIGURE_WG_INTERFACE
if [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "y" ] || [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "Y" ]; then
wg_awg_setup Wireguard
else
printf "\e[1;32mUse these instructions to manual configure https://itdog.info/nastrojka-klienta-wireguard-na-openwrt/\e[0m\n"
fi
break
;;
3)
echo "As long as it's not automated"
printf "\e[1;32mUse script from here https://github.com/Slava-Shchipunov/awg-openwrt\e[0m\n"
install_awg_packages
printf "\033[32;1mThere are no instructions for manual configure yet. Do you want to configure the amneziawg interface? (y/n): \033[0m\n"
read IS_SHOULD_CONFIGURE_WG_INTERFACE
if [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "y" ] || [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "Y" ]; then
wg_awg_setup AmneziaWG
fi
break
;;
@@ -74,10 +129,228 @@ while true; do
echo "Choose from the following options"
;;
esac
done
done
}
echo "Installed podkop..."
opkg install $DOWNLOAD_DIR/podkop*.ipk
opkg install $DOWNLOAD_DIR/luci-app-podkop*.ipk
handler_network_restart() {
IS_SHOULD_RESTART_NETWORK=true
}
rm -f $DOWNLOAD_DIR/podkop*.ipk $DOWNLOAD_DIR/luci-app-podkop*.ipk
install_awg_packages() {
# Получение pkgarch с наибольшим приоритетом
PKGARCH=$(opkg print-architecture | awk 'BEGIN {max=0} {if ($3 > max) {max = $3; arch = $2}} END {print arch}')
TARGET=$(ubus call system board | jsonfilter -e '@.release.target' | cut -d '/' -f 1)
SUBTARGET=$(ubus call system board | jsonfilter -e '@.release.target' | cut -d '/' -f 2)
VERSION=$(ubus call system board | jsonfilter -e '@.release.version')
PKGPOSTFIX="_v${VERSION}_${PKGARCH}_${TARGET}_${SUBTARGET}.ipk"
BASE_URL="https://github.com/Slava-Shchipunov/awg-openwrt/releases/download/"
AWG_DIR="/tmp/amneziawg"
mkdir -p "$AWG_DIR"
if opkg list-installed | grep -q kmod-amneziawg; then
echo "kmod-amneziawg already installed"
else
KMOD_AMNEZIAWG_FILENAME="kmod-amneziawg${PKGPOSTFIX}"
DOWNLOAD_URL="${BASE_URL}v${VERSION}/${KMOD_AMNEZIAWG_FILENAME}"
wget -O "$AWG_DIR/$KMOD_AMNEZIAWG_FILENAME" "$DOWNLOAD_URL"
if [ $? -eq 0 ]; then
echo "kmod-amneziawg file downloaded successfully"
else
echo "Error downloading kmod-amneziawg. Please, install kmod-amneziawg manually and run the script again"
exit 1
fi
opkg install "$AWG_DIR/$KMOD_AMNEZIAWG_FILENAME"
if [ $? -eq 0 ]; then
echo "kmod-amneziawg file downloaded successfully"
else
echo "Error installing kmod-amneziawg. Please, install kmod-amneziawg manually and run the script again"
exit 1
fi
fi
if opkg list-installed | grep -q amneziawg-tools; then
echo "amneziawg-tools already installed"
else
AMNEZIAWG_TOOLS_FILENAME="amneziawg-tools${PKGPOSTFIX}"
DOWNLOAD_URL="${BASE_URL}v${VERSION}/${AMNEZIAWG_TOOLS_FILENAME}"
wget -O "$AWG_DIR/$AMNEZIAWG_TOOLS_FILENAME" "$DOWNLOAD_URL"
if [ $? -eq 0 ]; then
echo "amneziawg-tools file downloaded successfully"
else
echo "Error downloading amneziawg-tools. Please, install amneziawg-tools manually and run the script again"
exit 1
fi
opkg install "$AWG_DIR/$AMNEZIAWG_TOOLS_FILENAME"
if [ $? -eq 0 ]; then
echo "amneziawg-tools file downloaded successfully"
else
echo "Error installing amneziawg-tools. Please, install amneziawg-tools manually and run the script again"
exit 1
fi
fi
if opkg list-installed | grep -q luci-app-amneziawg; then
echo "luci-app-amneziawg already installed"
else
LUCI_APP_AMNEZIAWG_FILENAME="luci-app-amneziawg${PKGPOSTFIX}"
DOWNLOAD_URL="${BASE_URL}v${VERSION}/${LUCI_APP_AMNEZIAWG_FILENAME}"
wget -O "$AWG_DIR/$LUCI_APP_AMNEZIAWG_FILENAME" "$DOWNLOAD_URL"
if [ $? -eq 0 ]; then
echo "luci-app-amneziawg file downloaded successfully"
else
echo "Error downloading luci-app-amneziawg. Please, install luci-app-amneziawg manually and run the script again"
exit 1
fi
opkg install "$AWG_DIR/$LUCI_APP_AMNEZIAWG_FILENAME"
if [ $? -eq 0 ]; then
echo "luci-app-amneziawg file downloaded successfully"
else
echo "Error installing luci-app-amneziawg. Please, install luci-app-amneziawg manually and run the script again"
exit 1
fi
fi
rm -rf "$AWG_DIR"
}
wg_awg_setup() {
PROTOCOL_NAME=$1
printf "\033[32;1mConfigure ${PROTOCOL_NAME}\033[0m\n"
if [ "$PROTOCOL_NAME" = 'Wireguard' ]; then
INTERFACE_NAME="wg0"
CONFIG_NAME="wireguard_wg0"
PROTO="wireguard"
ZONE_NAME="wg"
fi
if [ "$PROTOCOL_NAME" = 'AmneziaWG' ]; then
INTERFACE_NAME="awg0"
CONFIG_NAME="amneziawg_awg0"
PROTO="amneziawg"
ZONE_NAME="awg"
echo "Do you want to use AmneziaWG config or basic Wireguard config + automatic obfuscation?"
echo "1) AmneziaWG"
echo "2) Wireguard + automatic obfuscation"
read CONFIG_TYPE
fi
read -r -p "Enter the private key (from [Interface]):"$'\n' WG_PRIVATE_KEY_INT
while true; do
read -r -p "Enter internal IP address with subnet, example 192.168.100.5/24 (from [Interface]):"$'\n' WG_IP
if echo "$WG_IP" | egrep -oq '^([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]+$'; then
break
else
echo "This IP is not valid. Please repeat"
fi
done
read -r -p "Enter the public key (from [Peer]):"$'\n' WG_PUBLIC_KEY_INT
read -r -p "If use PresharedKey, Enter this (from [Peer]). If your don't use leave blank:"$'\n' WG_PRESHARED_KEY_INT
read -r -p "Enter Endpoint host without port (Domain or IP) (from [Peer]):"$'\n' WG_ENDPOINT_INT
read -r -p "Enter Endpoint host port (from [Peer]) [51820]:"$'\n' WG_ENDPOINT_PORT_INT
WG_ENDPOINT_PORT_INT=${WG_ENDPOINT_PORT_INT:-51820}
if [ "$WG_ENDPOINT_PORT_INT" = '51820' ]; then
echo $WG_ENDPOINT_PORT_INT
fi
if [ "$PROTOCOL_NAME" = 'AmneziaWG' ]; then
if [ "$CONFIG_TYPE" = '1' ]; then
read -r -p "Enter Jc value (from [Interface]):"$'\n' AWG_JC
read -r -p "Enter Jmin value (from [Interface]):"$'\n' AWG_JMIN
read -r -p "Enter Jmax value (from [Interface]):"$'\n' AWG_JMAX
read -r -p "Enter S1 value (from [Interface]):"$'\n' AWG_S1
read -r -p "Enter S2 value (from [Interface]):"$'\n' AWG_S2
read -r -p "Enter H1 value (from [Interface]):"$'\n' AWG_H1
read -r -p "Enter H2 value (from [Interface]):"$'\n' AWG_H2
read -r -p "Enter H3 value (from [Interface]):"$'\n' AWG_H3
read -r -p "Enter H4 value (from [Interface]):"$'\n' AWG_H4
elif [ "$CONFIG_TYPE" = '2' ]; then
#Default values to wg automatic obfuscation
AWG_JC=4
AWG_JMIN=40
AWG_JMAX=70
AWG_S1=0
AWG_S2=0
AWG_H1=1
AWG_H2=2
AWG_H3=3
AWG_H4=4
fi
fi
uci set network.${INTERFACE_NAME}=interface
uci set network.${INTERFACE_NAME}.proto=$PROTO
uci set network.${INTERFACE_NAME}.private_key=$WG_PRIVATE_KEY_INT
uci set network.${INTERFACE_NAME}.listen_port='51821'
uci set network.${INTERFACE_NAME}.addresses=$WG_IP
if [ "$PROTOCOL_NAME" = 'AmneziaWG' ]; then
uci set network.${INTERFACE_NAME}.awg_jc=$AWG_JC
uci set network.${INTERFACE_NAME}.awg_jmin=$AWG_JMIN
uci set network.${INTERFACE_NAME}.awg_jmax=$AWG_JMAX
uci set network.${INTERFACE_NAME}.awg_s1=$AWG_S1
uci set network.${INTERFACE_NAME}.awg_s2=$AWG_S2
uci set network.${INTERFACE_NAME}.awg_h1=$AWG_H1
uci set network.${INTERFACE_NAME}.awg_h2=$AWG_H2
uci set network.${INTERFACE_NAME}.awg_h3=$AWG_H3
uci set network.${INTERFACE_NAME}.awg_h4=$AWG_H4
fi
if ! uci show network | grep -q ${CONFIG_NAME}; then
uci add network ${CONFIG_NAME}
fi
uci set network.@${CONFIG_NAME}[0]=$CONFIG_NAME
uci set network.@${CONFIG_NAME}[0].name="${INTERFACE_NAME}_client"
uci set network.@${CONFIG_NAME}[0].public_key=$WG_PUBLIC_KEY_INT
uci set network.@${CONFIG_NAME}[0].preshared_key=$WG_PRESHARED_KEY_INT
uci set network.@${CONFIG_NAME}[0].route_allowed_ips='0'
uci set network.@${CONFIG_NAME}[0].persistent_keepalive='25'
uci set network.@${CONFIG_NAME}[0].endpoint_host=$WG_ENDPOINT_INT
uci set network.@${CONFIG_NAME}[0].allowed_ips='0.0.0.0/0'
uci set network.@${CONFIG_NAME}[0].endpoint_port=$WG_ENDPOINT_PORT_INT
uci commit network
if ! uci show firewall | grep -q "@zone.*name='${ZONE_NAME}'"; then
printf "\033[32;1mZone Create\033[0m\n"
uci add firewall zone
uci set firewall.@zone[-1].name=$ZONE_NAME
uci set firewall.@zone[-1].network=$INTERFACE_NAME
uci set firewall.@zone[-1].forward='REJECT'
uci set firewall.@zone[-1].output='ACCEPT'
uci set firewall.@zone[-1].input='REJECT'
uci set firewall.@zone[-1].masq='1'
uci set firewall.@zone[-1].mtu_fix='1'
uci set firewall.@zone[-1].family='ipv4'
uci commit firewall
fi
if ! uci show firewall | grep -q "@forwarding.*name='${ZONE_NAME}'"; then
printf "\033[32;1mConfigured forwarding\033[0m\n"
uci add firewall forwarding
uci set firewall.@forwarding[-1]=forwarding
uci set firewall.@forwarding[-1].name="${ZONE_NAME}-lan"
uci set firewall.@forwarding[-1].dest=${ZONE_NAME}
uci set firewall.@forwarding[-1].src='lan'
uci set firewall.@forwarding[-1].family='ipv4'
uci commit firewall
fi
handler_network_restart
}
main

View File

@@ -4,7 +4,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-podkop
PKG_VERSION:=0.1.9
PKG_VERSION:=0.2.2
PKG_RELEASE:=1
LUCI_TITLE:=LuCI podkop app

View File

@@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=podkop
PKG_VERSION:=0.1.9
PKG_VERSION:=0.2.2
PKG_RELEASE:=1
PKG_MAINTAINER:=ITDog <podkop@itdog.info>
@@ -28,25 +28,13 @@ endef
define Build/Compile
endef
define Package/podkop/postinst
#!/bin/sh
if ! uci show ucitrack | grep -q 'podkop'; then
uci add ucitrack podkop
uci set ucitrack.@podkop[-1].init=podkop
uci commit ucitrack
/etc/init.d/ucitrack restart
fi
exit 0
endef
define Package/podkop/prerm
#!/bin/sh
grep -q "105 podkop" /etc/iproute2/rt_tables && sed -i "/105 podkop/d" /etc/iproute2/rt_tables
rm -f /etc/hotplug.d/iface/50-podkop
exit 0
endef

View File

@@ -1,25 +1,25 @@
config main 'main'
option mode 'proxy'
option interface 'wg0'
option interface ''
option proxy_string ''
option domain_list_enabled '1'
option domain_list 'ru_inside'
option subnets_list_enabled '0'
list subnets 'twitter'
#list subnets 'twitter'
option custom_domains_list_enabled '0'
list custom_domains ''
#list custom_domains ''
option custom_download_domains_list_enabled '0'
list custom_download_domains ''
#list custom_download_domains ''
option custom_subnets_list_enabled '0'
list custom_subnets ''
#list custom_subnets ''
option custom_download_subnets_list_enabled '0'
list custom_download_subnets ''
#list custom_download_subnets ''
option all_traffic_from_ip_enabled '0'
list all_traffic_ip ''
#list all_traffic_ip ''
option delist_domains_enabled '0'
list delist_domains ''
#list delist_domains ''
option exclude_from_ip_enabled '0'
list exclude_traffic_ip ''
#list exclude_traffic_ip ''
option yacd '0'
option socks5 '0'
option exclude_ntp '0'
@@ -30,8 +30,8 @@ config second 'second'
option interface 'wg1'
option proxy_string ''
option domain_list_enabled '0'
list domains 'youtube'
#list domains 'youtube'
option custom_domains_list_enabled '0'
list custom_domains 'ifconfig.io'
#list custom_domains 'ifconfig.io'
option custom_subnets_list_enabled '0'
list custom_subnets ''
#list custom_subnets ''

View File

@@ -1,3 +1,28 @@
#!/bin/sh
/etc/init.d/podkop add_route_interface
. /lib/functions.sh
config_load "/etc/config/podkop"
. /etc/init.d/podkop
config_get "interface" "main" "interface" "0"
config_get "mode" "main" "mode" "0"
if [ "$mode" = "vpn" ] && [ -n "$interface" ]; then
add_route_interface "$interface" "podkop"
fi
if [ "$mode" = "proxy" ]; then
echo "Add route for main tproxy"
add_route_tproxy podkop
fi
config_get second_enable "second" "second_enable" "0"
config_get interface "second" "interface" "0"
config_get "mode" "second" "mode" "0"
if [ "$second_enable" -eq "1" ] && [ "$mode" = "vpn" ] && [ -n "$interface" ]; then
add_route_interface "$interface" "podkop2"
fi
if [ "$second_enable" -eq "1" ] && [ "$mode" = "proxy" ]; then
echo "Add route for second tproxy"
add_route_tproxy podkop2
fi

View File

@@ -1,6 +1,7 @@
#!/bin/sh /etc/rc.common
START=99
USE_PROCD=1
script=$(readlink "$initscript")
NAME="$(basename ${script:-$initscript})"
@@ -13,11 +14,10 @@ EXTRA_HELP=" list_update Updating domain and subnet lists
cron_job="0 4 * * * /etc/init.d/podkop list_update"
start() {
start_service() {
log "Start podkop"
dnsmasqfull
ucitrack
routing_table_create
add_mark
@@ -194,7 +194,7 @@ start() {
fi
}
stop() {
stop_service() {
log "Stopping the podkop"
rm -f /tmp/dnsmasq.d/podkop*
remove_cron_job
@@ -232,16 +232,20 @@ stop() {
fi
}
restart() {
restart_service() {
stop
start
}
reload() {
reload_service() {
stop
start
}
service_triggers() {
procd_add_config_trigger "config.change" "$NAME" "$initscript" reload 'on_config_change'
}
log() {
local message="$1"
local timestamp=$(date +"%Y-%m-%d %H:%M:%S")
@@ -250,6 +254,7 @@ log() {
local RESET="\033[0m"
echo -e "${CYAN}[$timestamp]${RESET} ${GREEN}$message${RESET}"
logger -t "podkop" "$timestamp $message"
}
add_cron_job() {
@@ -369,14 +374,6 @@ dnsmasqfull() {
fi
}
ucitrack() {
if grep -q "podkop" /etc/config/ucitrack; then
log "ucitrack config ok"
else
log "ucitrack config not found"
fi
}
routing_table_create() {
grep -q "105 podkop" /etc/iproute2/rt_tables || echo '105 podkop' >>/etc/iproute2/rt_tables
config_get_bool second_enable "second" "second_enable" "0"
@@ -439,8 +436,18 @@ add_set() {
add_route_interface() {
local interface="$1"
local table="$2"
local retry_count=0
local max_retries=20
local retry_count_route=0
local max_retries=10
if ! ip link show "$interface" >/dev/null 2>&1; then
log "Interface "$interface" undetected, wait 10 sec..."
sleep 10
if ! ip link show "$interface" >/dev/null 2>&1; then
log "Interface "$interface" undetected. exit"
exit 1
fi
fi
if ! ip link show "$interface" >/dev/null 2>&1; then
log "Interface "$interface" does not exist, not possible to create a route"
@@ -453,11 +460,11 @@ add_route_interface() {
fi
log "Added route for "$interface""
while [ $retry_count -lt $max_retries ]; do
while [ $retry_count_route -lt $max_retries ]; do
if ip route add table $table default dev "$interface" 2>&1 | grep -q "Network is down"; then
log "Error: Network is down. Let's try again in 3 seconds"
log "Attempt $retry_count_route: Interface "$interface" is down, retrying in 3 seconds..."
sleep 3
retry_count=$((retry_count + 1))
retry_count_route=$((retry_count_route + 1))
else
log "Route for "$interface" added"
return 0