diff --git a/.gitignore b/.gitignore index 71cdd29..37ef49e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ /todo.todo /app/zapretlists/* !/app/zapretlists/.gitkeep +.vscode/sftp.json diff --git a/app/bot.php b/app/bot.php index 2c9f64a..2699767 100644 --- a/app/bot.php +++ b/app/bot.php @@ -221,6 +221,9 @@ class Bot case preg_match('~^/switchTorrent (\d+)$~', $this->input['callback'], $m): $this->switchTorrent($m[1]); break; + case preg_match('~^/switchExchange (\d+)$~', $this->input['callback'], $m): + $this->switchExchange($m[1]); + break; case preg_match('~^/blinkmenuswitch$~', $this->input['callback'], $m): $this->blinkmenuswitch(); break; @@ -938,6 +941,18 @@ class Bot } $this->menu('wg', $page); } + public function switchExchange($page) + { + $c = $this->getPacConf(); + $c['exchange'] = $c['exchange'] ? 0 : 1; + $this->setPacConf($c); + if ($c['exchange']) { + $this->ssh('bash /block_exchange.sh'); + } else { + $this->ssh('bash /unblock_exchange.sh'); + } + $this->menu('wg', $page); + } public function blinkmenuswitch() { @@ -1765,22 +1780,17 @@ DNS-over-HTTPS with IP: $status = $this->readStatus(); $clients = $this->getClients($page); $bt = $this->getPacConf()['blocktorrent']; + $ex = $this->getPacConf()['exchange']; $dns = $this->getPacConf()['dns']; $data = [ [ [ - 'text' => $this->i18n('update status'), - 'callback_data' => "/menu wg $page", - ], - [ - 'text' => $this->i18n(($bt ? 'block' : 'unblock') . 'torrent'), + 'text' => "{$this->i18n('torrent')} " . $this->i18n(!$bt ? 'on' : 'off'), 'callback_data' => "/switchTorrent $page", ], - ], - [ [ - 'text' => $this->i18n('add peer'), - 'callback_data' => "/menu addpeer $page", + 'text' => "{$this->i18n('exchange')} " . $this->i18n(!$ex ? 'on' : 'off'), + 'callback_data' => "/switchExchange $page", ], [ 'text' => $this->i18n('listSubnet'), @@ -1793,6 +1803,12 @@ DNS-over-HTTPS with IP: 'callback_data' => "/defaultDNS $page", ], ], + [ + [ + 'text' => $this->i18n('add peer'), + 'callback_data' => "/menu addpeer $page", + ], + ], ]; if ($clients) { $data = array_merge($data, $clients); @@ -1841,10 +1857,16 @@ DNS-over-HTTPS with IP: } } $text = "Menu -> Wireguard\n\n" . implode(PHP_EOL, $text ?: []) . ''; - $data[] = [[ - 'text' => $this->i18n('back'), - 'callback_data' => "/menu", - ]]; + $data[] = [ + [ + 'text' => $this->i18n('update status'), + 'callback_data' => "/menu wg $page", + ], + [ + 'text' => $this->i18n('back'), + 'callback_data' => "/menu", + ] + ]; return [ 'text' => $text, 'data' => $data, diff --git a/app/i18n.php b/app/i18n.php index 2364474..4ea1770 100644 --- a/app/i18n.php +++ b/app/i18n.php @@ -186,20 +186,16 @@ $i = [ 'ru' => 'удалить внутренний dns', ], 'on' => [ - 'en' => 'on', - 'ru' => 'вкл', + 'en' => '🟢', + 'ru' => '🟢', ], 'off' => [ - 'en' => 'off', - 'ru' => 'выкл', + 'en' => '🔴', + 'ru' => '🔴', ], - 'blocktorrent' => [ - 'en' => 'torrent off', - 'ru' => 'торренты выкл', - ], - 'unblocktorrent' => [ - 'en' => 'torrent on', - 'ru' => 'торренты вкл', + 'torrent' => [ + 'en' => 'torrents', + 'ru' => 'торренты', ], 'blinkmenuon' => [ 'en' => 'blinkmenu on', @@ -269,4 +265,8 @@ $i = [ 'en' => 'pagination', 'ru' => 'пагинация', ], + 'exchange' => [ + 'en' => 'open ip', + 'ru' => 'откр айпи', + ], ]; diff --git a/docker-compose.yml b/docker-compose.yml index 3decb7d..f8773b1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -152,10 +152,13 @@ services: volumes: - ./config/.profile:/root/.ashrc:ro - ./config/wg0.conf:/etc/wireguard/wg0.conf + - ./config/pac.json:/pac.json - ./scripts/start_wg.sh:/start_wg.sh - ./scripts/reset_wg.sh:/reset_wg.sh - ./scripts/block_torrent.sh:/block_torrent.sh - ./scripts/unblock_torrent.sh:/unblock_torrent.sh + - ./scripts/block_exchange.sh:/block_exchange.sh + - ./scripts/unblock_exchange.sh:/unblock_exchange.sh - ./ssh:/ssh - ./config/sshd_config:/etc/ssh/sshd_config hostname: wireguard diff --git a/dockerfile/wireguard.dockerfile b/dockerfile/wireguard.dockerfile index 2f879a3..b18455b 100644 --- a/dockerfile/wireguard.dockerfile +++ b/dockerfile/wireguard.dockerfile @@ -1,4 +1,4 @@ from alpine:3.18.2 -run apk add iproute2 linux-headers iptables xtables-addons wireguard-tools openssh \ +run apk add iproute2 linux-headers iptables xtables-addons wireguard-tools openssh jq \ && mkdir /root/.ssh -env ENV="/root/.ashrc" \ No newline at end of file +env ENV="/root/.ashrc" diff --git a/scripts/block_exchange.sh b/scripts/block_exchange.sh new file mode 100644 index 0000000..2bb13af --- /dev/null +++ b/scripts/block_exchange.sh @@ -0,0 +1 @@ +iptables -I FORWARD -i %i -o %i -j REJECT diff --git a/scripts/start_wg.sh b/scripts/start_wg.sh index 749037d..d3319fc 100644 --- a/scripts/start_wg.sh +++ b/scripts/start_wg.sh @@ -15,4 +15,12 @@ wg-quick up wg0 cat /ssh/key.pub > /root/.ssh/authorized_keys ssh-keygen -A exec /usr/sbin/sshd -D -e "$@" & +if [ $(cat /pac.json | jq .blocktorrent) -eq 1 ] +then + sh /block_torrent.sh +fi +if [ $(cat /pac.json | jq .exchange) -eq 1 ] +then + sh /block_exchange.sh +fi tail -f /dev/null diff --git a/scripts/unblock_exchange.sh b/scripts/unblock_exchange.sh new file mode 100644 index 0000000..7e3cf27 --- /dev/null +++ b/scripts/unblock_exchange.sh @@ -0,0 +1 @@ +iptables -D FORWARD -i %i -o %i -j REJECT diff --git a/version b/version index 2268d79..16eb068 100644 --- a/version +++ b/version @@ -1,3 +1,6 @@ +20.07.2023 кнопка блокировки обмена между пирами +git pull +make r 16.07.2023 AdGuardHome v0.107.34 git pull make r