diff --git a/app/bot.php b/app/bot.php
index d9575ba..f085486 100644
--- a/app/bot.php
+++ b/app/bot.php
@@ -146,6 +146,9 @@ class Bot
case preg_match('~^/download (\d+)$~', $this->input['callback'], $m):
$this->downloadPeer($m[1]);
break;
+ case preg_match('~^/qr (\d+)$~', $this->input['callback'], $m):
+ $this->qrPeer($m[1]);
+ break;
case preg_match('~^/delupstream (\d+)$~', $this->input['callback'], $m):
$this->delupstream($m[1]);
break;
@@ -452,6 +455,22 @@ class Bot
$this->upload(preg_replace(['~\s+~', '~\(|\)~'], ['_', ''], $name) . ".conf", $code);
}
+ public function qrPeer($client)
+ {
+ $client = $this->readClients()[$client];
+ $name = $this->getName($client['interface']);
+ $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),
+ $name,
+ );
+ unlink($qr_file);
+ }
+
public function upload($name, $code)
{
$path = "/logs/$name";
@@ -1126,8 +1145,9 @@ DNS-over-HTTPS with IP:
$clients = $this->readClients();
if ($clients) {
$name = $this->getName($clients[$client]['interface']);
+ $conf = $this->createConfig($clients[$client]);
return [
- 'text' => "{$this->createConfig($clients[$client])}\n\n$name",
+ 'text' => "$conf\n\n$name",
'data' => [
[
[
@@ -1137,7 +1157,11 @@ DNS-over-HTTPS with IP:
],
[
[
- 'text' => "download",
+ 'text' => "show QR",
+ 'callback_data' => "/qr $client",
+ ],
+ [
+ 'text' => "download config",
'callback_data' => "/download $client",
],
],
@@ -1153,7 +1177,7 @@ DNS-over-HTTPS with IP:
'callback_data' => "/menu wg $page",
],
],
- ]
+ ],
];
}
return [
@@ -2081,6 +2105,17 @@ DNS-over-HTTPS with IP:
]);
}
+ public function sendPhoto($chat, $id_url_cFile, $caption = false, $to = false)
+ {
+ return $this->request('sendPhoto', [
+ 'chat_id' => $chat,
+ 'photo' => $id_url_cFile,
+ 'caption' => $caption,
+ 'reply_to_message_id' => $to,
+ 'parse_mode' => 'html',
+ ]);
+ }
+
public function sendFile($chat, $id_url_cFile, $caption = false, $to = false)
{
return $this->request('sendDocument', [
diff --git a/app/qr/.gitkeep b/app/qr/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/dockerfile/php.dockerfile b/dockerfile/php.dockerfile
index b56047f..94deefe 100644
--- a/dockerfile/php.dockerfile
+++ b/dockerfile/php.dockerfile
@@ -1,6 +1,6 @@
from nginx/unit:1.29.0-php8.1
arg IP
-run apt update && apt install -y wget libssh2-1-dev ssh libicu-dev libyaml-dev certbot && \
+run apt update && apt install -y qrencode wget libssh2-1-dev ssh libicu-dev libyaml-dev certbot && \
pecl install https://pecl.php.net/get/ssh2-1.3.1.tgz && \
pecl install https://pecl.php.net/get/yaml-2.2.2.tgz && \
docker-php-ext-install intl && \