From d005ccc919e74972a7d18f99ecac5a757b8eb5de Mon Sep 17 00:00:00 2001 From: mercury Date: Mon, 4 Mar 2024 23:26:09 +0400 Subject: [PATCH] fix start wg1 --- app/bot.php | 2 +- scripts/start_wg.sh | 47 +++++++++++++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/app/bot.php b/app/bot.php index aa78f75..cb3a206 100644 --- a/app/bot.php +++ b/app/bot.php @@ -3829,7 +3829,6 @@ DNS-over-HTTPS with IP: public function readStatus() { - // $this->sd([$this->getWGType(), $this->getInstanceWG()]); $r = $this->ssh($this->getWGType(), $this->getInstanceWG()); $r = explode(PHP_EOL, $r); $r = array_filter($r); @@ -4016,6 +4015,7 @@ DNS-over-HTTPS with IP: } $this->saveClients($clients); } + unset($this->wg); } public function saveClients(array $clients) diff --git a/scripts/start_wg.sh b/scripts/start_wg.sh index 0e053fe..679498c 100644 --- a/scripts/start_wg.sh +++ b/scripts/start_wg.sh @@ -1,3 +1,7 @@ +cat /ssh/key.pub > /root/.ssh/authorized_keys +ssh-keygen -A +exec /usr/sbin/sshd -D -e "$@" & + INTERFACE=$(route | grep '^default' | grep -o '[^ ]*$') if [ $(cat /etc/wireguard/wg0.conf | wc -c) -eq 0 ] then @@ -13,21 +17,36 @@ fi iptables -t nat -A POSTROUTING --destination 10.10.0.5 -j ACCEPT iptables -t nat -A POSTROUTING -o $INTERFACE -j MASQUERADE ln -s /etc/wireguard/wg0.conf /etc/amnezia/amneziawg/wg0.conf -if [ $(cat /pac.json | jq .amnezia) -eq 1 ] +if [ "$HOSTNAME" = "wireguard1" ] then - awg-quick up wg0 + if [ $(cat /pac.json | jq .wg1_amnezia) -eq 1 ] + then + awg-quick up wg0 + else + wg-quick up wg0 + fi + if [ $(cat /pac.json | jq .wg1_blocktorrent) -eq 1 ] + then + sh /block_torrent.sh + fi + if [ $(cat /pac.json | jq .wg1_exchange) -eq 1 ] + then + sh /block_exchange.sh + fi else - wg-quick up wg0 -fi -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 + if [ $(cat /pac.json | jq .amnezia) -eq 1 ] + then + awg-quick up wg0 + else + wg-quick up wg0 + fi + 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 fi tail -f /dev/null