on/off wg peer
This commit is contained in:
+31
@@ -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<arg>\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",
|
||||
|
||||
@@ -185,4 +185,12 @@ $i = [
|
||||
'en' => 'delete internal dns',
|
||||
'ru' => 'удалить внутренний dns',
|
||||
],
|
||||
'on' => [
|
||||
'en' => 'on',
|
||||
'ru' => 'вкл',
|
||||
],
|
||||
'off' => [
|
||||
'en' => 'off',
|
||||
'ru' => 'выкл',
|
||||
],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user