From dd16e87d849b15050de95e4f0551cde859b2e8a5 Mon Sep 17 00:00:00 2001 From: mercury Date: Thu, 11 May 2023 00:48:53 +0400 Subject: [PATCH] on/off wg peer --- app/bot.php | 31 +++++++++++++++++++++++++++++++ app/i18n.php | 8 ++++++++ 2 files changed, 39 insertions(+) diff --git a/app/bot.php b/app/bot.php index 5444b5a..34ba894 100644 --- a/app/bot.php +++ b/app/bot.php @@ -161,6 +161,9 @@ class Bot case preg_match('~^/download (\d+)$~', $this->input['callback'], $m): $this->downloadPeer($m[1]); break; + case preg_match('~^/switchClient (?P\d+(?:_(?:-)?\d+)?)$~', $this->input['callback'], $m): + $this->switchClient(...explode('_', $m['arg'])); + break; case preg_match('~^/deladmin (\d+)$~', $this->input['callback'], $m): $this->delAdmin($m[1]); break; @@ -572,6 +575,30 @@ class Bot $this->upload(preg_replace(['~\s+~', '~\(|\)~'], ['_', ''], $name) . ".conf", $code); } + public function switchClient($client) + { + $clients = $this->readClients(); + if ($clients[$client]['# off']) { + unset($clients[$client]['# off']); + } else { + $clients[$client]['# off'] = 1; + } + $this->saveClients($clients); + $server = $this->readConfig(); + if (array_key_exists('# PublicKey', $server['peers'][$client])) { + foreach ($server['peers'][$client] as $k => $v) { + $new[trim(preg_replace('~#~', '', $k, 1))] = $v; + } + } else { + foreach ($server['peers'][$client] as $k => $v) { + $new["# $k"] = $v; + } + } + $server['peers'][$client] = $new; + $this->restartWG($this->createConfig($server)); + $this->menu('client', "{$client}_0"); + } + public function qrPeer($client) { $client = $this->readClients()[$client]; @@ -1379,6 +1406,10 @@ DNS-over-HTTPS with IP: ], ], [ + [ + 'text' => $this->i18n($clients[$client]['# off'] ? 'off' : 'on'), + 'callback_data' => "/switchClient {$client}_$page", + ], [ 'text' => $this->i18n($clients[$client]['interface']['DNS'] ? 'delete internal dns' : 'set internal dns'), 'callback_data' => "/" . ($clients[$client]['interface']['DNS'] ? 'delete' : '') . "dns {$client}_$page", diff --git a/app/i18n.php b/app/i18n.php index 61f9d08..bf75fe1 100644 --- a/app/i18n.php +++ b/app/i18n.php @@ -185,4 +185,12 @@ $i = [ 'en' => 'delete internal dns', 'ru' => 'удалить внутренний dns', ], + 'on' => [ + 'en' => 'on', + 'ru' => 'вкл', + ], + 'off' => [ + 'en' => 'off', + 'ru' => 'выкл', + ], ];