From 3416cda8264992fd54e877e8a7e7f71e5ee78882 Mon Sep 17 00:00:00 2001 From: mercury Date: Sun, 25 Aug 2024 23:30:19 +0400 Subject: [PATCH] qr for singbox --- app/bot.php | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/app/bot.php b/app/bot.php index eafe572..1c7407b 100644 --- a/app/bot.php +++ b/app/bot.php @@ -353,8 +353,8 @@ class Bot case preg_match('~^/qrSS$~', $this->input['callback'], $m): $this->qrSS(); break; - case preg_match('~^/qrXray (\d+)$~', $this->input['callback'], $m): - $this->qrXray($m[1]); + case preg_match('~^/qrXray (\d+)(?:_(\d+))?$~', $this->input['callback'], $m): + $this->qrXray($m[1], $m[2] ?: false); break; case preg_match('~^/qrMtproto$~', $this->input['callback'], $m): $this->qrMtproto(); @@ -1604,9 +1604,9 @@ class Bot } } - public function qrXray($i) + public function qrXray($i, $s = false) { - $link = $this->linkXray($i); + $link = $this->linkXray($i, $s); $qr_file = __DIR__ . "/qr/xray.png"; exec("qrencode -t png -o $qr_file '$link'"); $r = $this->sendPhoto( @@ -3734,12 +3734,28 @@ DNS-over-HTTPS with IP: $this->answer($this->input['callback_id'], 'in developing...'); } - public function linkXray($i) + public function linkXray($i, $s = false) { $c = $this->getXray(); $pac = $this->getPacConf(); $domain = $pac['domain'] ?: $this->ip; - return "vless://{$c['inbounds'][0]['settings']['clients'][$i]['id']}@$domain:443?security=reality&sni={$c['inbounds'][0]['streamSettings']['realitySettings']['serverNames'][0]}&fp=chrome&pbk={$pac['xray']}&sid={$c['inbounds'][0]['streamSettings']['realitySettings']['shortIds'][0]}&type=tcp&flow=xtls-rprx-vision#{$c['inbounds'][0]['settings']['clients'][$i]['email']}"; + $scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https'; + $hash = substr(md5($this->key), 0, 8); + $si = "$scheme://{$domain}/pac/" . base64_encode(serialize([ + 'h' => $hash, + 't' => 'si', + 's' => $c['inbounds'][0]['settings']['clients'][$i]['id'], + ])); + + switch ($s) { + case 1: + return "$scheme://{$domain}/pac?h=$hash&t=s&s={$c['inbounds'][0]['settings']['clients'][$i]['id']}"; + case 2: + return "sing-box://import-remote-profile/?url={$si}#{$c['inbounds'][0]['settings']['clients'][$i]['email']}"; + + default: + return "vless://{$c['inbounds'][0]['settings']['clients'][$i]['id']}@$domain:443?security=reality&sni={$c['inbounds'][0]['streamSettings']['realitySettings']['serverNames'][0]}&fp=chrome&pbk={$pac['xray']}&sid={$c['inbounds'][0]['streamSettings']['realitySettings']['shortIds'][0]}&type=tcp&flow=xtls-rprx-vision#{$c['inbounds'][0]['settings']['clients'][$i]['email']}"; + } } public function dockerApi($url, $method = 'GET', $data = []) @@ -4459,9 +4475,17 @@ DNS-over-HTTPS with IP: ]; $data[] = [ [ - 'text' => $this->i18n('show QR'), + 'text' => $this->i18n('qr short'), 'callback_data' => "/qrXray $i", ], + [ + 'text' => $this->i18n('qr v2ray'), + 'callback_data' => "/qrXray {$i}_1", + ], + [ + 'text' => $this->i18n('qr singbox'), + 'callback_data' => "/qrXray {$i}_2", + ], ]; $data[] = [ [