Merge branch 'master' into singbox
This commit is contained in:
+94
-12
@@ -9,6 +9,8 @@ class Bot
|
||||
public $limit;
|
||||
public $key;
|
||||
public $file;
|
||||
public $dns;
|
||||
public $mtu;
|
||||
|
||||
public function __construct($key, $i18n)
|
||||
{
|
||||
@@ -22,6 +24,7 @@ class Bot
|
||||
$this->i18n = $i18n;
|
||||
$this->language = $this->getPacConf()['language'] ?: 'en';
|
||||
$this->dns = '1.1.1.1, 8.8.8.8';
|
||||
$this->mtu = 1350;
|
||||
$this->limit = $this->getPacConf()['limitpage'] ?: 5;
|
||||
$this->adguard = '/config/AdGuardHome.yaml';
|
||||
$this->update = '/update/json';
|
||||
@@ -184,6 +187,9 @@ class Bot
|
||||
case preg_match('~^/defaultDNS (?P<arg>\d+(?:_(?:-)?\d+)?)$~', $this->input['callback'], $m):
|
||||
$this->defaultDNS(...explode('_', $m['arg']));
|
||||
break;
|
||||
case preg_match('~^/defaultMTU (?P<arg>\d+(?:_(?:-)?\d+)?)$~', $this->input['callback'], $m):
|
||||
$this->defaultMTU(...explode('_', $m['arg']));
|
||||
break;
|
||||
case preg_match('~^/subnet (?P<arg>-?\d+(?:_(?:-)?\d+)?)$~', $this->input['callback'], $m):
|
||||
$this->subnet(...explode('_', $m['arg']));
|
||||
break;
|
||||
@@ -199,6 +205,9 @@ class Bot
|
||||
case preg_match('~^/changeAllowedIps (?P<arg>\d+(?:_(?:-)?\d+)?)$~', $this->input['callback'], $m):
|
||||
$this->changeAllowedIps(...explode('_', $m['arg']));
|
||||
break;
|
||||
case preg_match('~^/changeMTU (?P<arg>\d+(?:_(?:-)?\d+)?)$~', $this->input['callback'], $m):
|
||||
$this->changeMTU(...explode('_', $m['arg']));
|
||||
break;
|
||||
case preg_match('~^/calc$~', $this->input['callback'], $m):
|
||||
$this->calc();
|
||||
break;
|
||||
@@ -1573,26 +1582,30 @@ class Bot
|
||||
$this->menu('config');
|
||||
}
|
||||
|
||||
public function qrPeer($client)
|
||||
public function sendQr($name, $code, $title = false)
|
||||
{
|
||||
$cl = $client;
|
||||
$client = $this->readClients()[$client];
|
||||
$name = $this->getName($client['interface']);
|
||||
if ($this->getWGType() == 'awg') {
|
||||
$sl = $this->getAmneziaShortLink($client);
|
||||
$code = preg_replace('/^vpn:\/\//', '', $sl);
|
||||
} else {
|
||||
$code = $this->createConfig($client);
|
||||
}
|
||||
$qr = preg_replace(['~\s+~', '~\(~', '~\)~'], ['_'], $name);
|
||||
$qr_file = __DIR__ . "/qr/$qr.png";
|
||||
exec("qrencode -t png -o $qr_file '$code'");
|
||||
$r = $this->sendPhoto(
|
||||
$this->input['chat'],
|
||||
curl_file_create($qr_file),
|
||||
($this->getWGType() == 'awg') ? "$name for AmneziaVPN" : $name
|
||||
$title ?: $name
|
||||
);
|
||||
unlink($qr_file);
|
||||
}
|
||||
|
||||
public function qrPeer($client)
|
||||
{
|
||||
$cl = $client;
|
||||
$client = $this->readClients()[$client];
|
||||
$name = $this->getName($client['interface']);
|
||||
if ($this->getWGType() == 'awg') {
|
||||
$this->sendQr($name, preg_replace('/^vpn:\/\//', '', $this->getAmneziaShortLink($client)), "$name for AmneziaVPN");
|
||||
$this->sendQr($name, $this->createConfig($client), "$name for AmneziaWG");
|
||||
} else {
|
||||
$this->sendQr($name, $this->createConfig($client), "$name for Wireguard");
|
||||
}
|
||||
if ($this->getPacConf()['blinkmenu']) {
|
||||
$this->delete($this->input['chat'], $this->input['message_id']);
|
||||
$this->input['message_id'] = $this->send($this->input['chat'], '.')['result']['message_id'];
|
||||
@@ -2513,6 +2526,7 @@ DNS-over-HTTPS with IP:
|
||||
$bt = $c[$this->getInstanceWG(1) . 'blocktorrent'];
|
||||
$ex = $c[$this->getInstanceWG(1) . 'exchange'];
|
||||
$dns = $c[$this->getInstanceWG(1) . 'dns'];
|
||||
$mtu = $c[$this->getInstanceWG(1) . 'mtu'] ?: $this->mtu;
|
||||
$am = $c[$this->getInstanceWG(1) . 'amnezia'];
|
||||
$data = [
|
||||
[
|
||||
@@ -2540,6 +2554,10 @@ DNS-over-HTTPS with IP:
|
||||
'text' => $this->i18n('defaultDNS') . ': ' . ($dns ?: $this->dns),
|
||||
'callback_data' => "/defaultDNS $page",
|
||||
],
|
||||
[
|
||||
'text' => $this->i18n('defaultMTU') . ': ' . $mtu,
|
||||
'callback_data' => "/defaultMTU $page",
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
@@ -2627,6 +2645,38 @@ DNS-over-HTTPS with IP:
|
||||
];
|
||||
}
|
||||
|
||||
public function defaultMTU($page = 0)
|
||||
{
|
||||
$r = $this->send(
|
||||
$this->input['chat'],
|
||||
"@{$this->input['username']} enter MTU",
|
||||
$this->input['message_id'],
|
||||
reply: 'enter MTU',
|
||||
);
|
||||
$_SESSION['reply'][$r['result']['message_id']] = [
|
||||
'start_message' => $this->input['message_id'],
|
||||
'start_callback' => $this->input['callback_id'],
|
||||
'callback' => 'setMTU',
|
||||
'args' => [$page],
|
||||
];
|
||||
}
|
||||
|
||||
public function changeMTU($client, $page = 0)
|
||||
{
|
||||
$r = $this->send(
|
||||
$this->input['chat'],
|
||||
"@{$this->input['username']} enter MTU",
|
||||
$this->input['message_id'],
|
||||
reply: 'enter MTU',
|
||||
);
|
||||
$_SESSION['reply'][$r['result']['message_id']] = [
|
||||
'start_message' => $this->input['message_id'],
|
||||
'start_callback' => $this->input['callback_id'],
|
||||
'callback' => 'changeClientMTU',
|
||||
'args' => [$client, $page],
|
||||
];
|
||||
}
|
||||
|
||||
public function setDNS($text, $page = 0)
|
||||
{
|
||||
$c = $this->getPacConf();
|
||||
@@ -2639,6 +2689,30 @@ DNS-over-HTTPS with IP:
|
||||
$this->menu('wg', $page);
|
||||
}
|
||||
|
||||
public function setMTU($text, $page = 0)
|
||||
{
|
||||
$c = $this->getPacConf();
|
||||
if ($text) {
|
||||
$c[$this->getInstanceWG(1) . 'mtu'] = $text;
|
||||
} else {
|
||||
unset($c[$this->getInstanceWG(1) . 'mtu']);
|
||||
}
|
||||
$this->setPacConf($c);
|
||||
$this->menu('wg', $page);
|
||||
}
|
||||
|
||||
public function changeClientMTU($text, $client, $page = 0)
|
||||
{
|
||||
$clients = $this->readClients();
|
||||
if (!empty((int) $text)) {
|
||||
$clients[$client]['interface']['MTU'] = $text;
|
||||
} else {
|
||||
unset($clients[$client]['interface']['MTU']);
|
||||
}
|
||||
$this->saveClients($clients);
|
||||
$this->menu('client', "{$client}_$page");
|
||||
}
|
||||
|
||||
public function subnetAdd($wgpage, $page)
|
||||
{
|
||||
$r = $this->send(
|
||||
@@ -2957,6 +3031,12 @@ DNS-over-HTTPS with IP:
|
||||
'callback_data' => "/changeAllowedIps {$client}_$page",
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
'text' => $this->i18n('MTU') . " " . ($clients[$client]['interface']['MTU'] ?: $this->getPacConf()[$this->getInstanceWG(1) . 'mtu'] ?: $this->mtu),
|
||||
'callback_data' => "/changeMTU {$client}_$page",
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
'text' => $this->i18n('delete'),
|
||||
@@ -5190,6 +5270,9 @@ DNS-over-HTTPS with IP:
|
||||
if (empty($data['interface']['DNS'])) {
|
||||
$data['interface']['DNS'] = $this->getPacConf()[$this->getInstanceWG(1) . 'dns'] ?: $this->dns;
|
||||
}
|
||||
if (empty($data['interface']['MTU'])) {
|
||||
$data['interface']['MTU'] = $this->getPacConf()[$this->getInstanceWG(1) . 'mtu'] ?: $this->mtu;
|
||||
}
|
||||
}
|
||||
foreach ($data['interface'] as $k => $v) {
|
||||
$conf[] = "$k = $v";
|
||||
@@ -5279,7 +5362,6 @@ DNS-over-HTTPS with IP:
|
||||
'## name' => $name,
|
||||
'PrivateKey' => $private_peer_key,
|
||||
'Address' => "$client_ip/32",
|
||||
'MTU' => 1350,
|
||||
],
|
||||
$this->getPacConf()[$this->getInstanceWG(1) . 'amnezia'] ? $this->amneziaKeys() : []
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user