From fb075463eeb64f0c927e4dd667519305a07c7448 Mon Sep 17 00:00:00 2001 From: denied1011 Date: Sat, 28 Mar 2026 02:44:41 +0300 Subject: [PATCH] Add MTProto adtag setting in bot UI --- app/bot.php | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- app/i18n.php | 4 ++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/app/bot.php b/app/bot.php index 1f1d8c7..e16a824 100644 --- a/app/bot.php +++ b/app/bot.php @@ -648,6 +648,9 @@ class Bot case preg_match('~^/changeTGDomain$~', $this->input['callback'], $m): $this->changeTGDomain(); break; + case preg_match('~^/setTGAdtag$~', $this->input['callback'], $m): + $this->changeTGAdtag(); + break; case preg_match('~^/include (\w+)$~', $this->input['callback'], $m): $this->include($m[1]); break; @@ -728,14 +731,32 @@ class Bot $this->mtproto(); } + public function setTelegramAdtag($adtag) + { + $adtag = trim($adtag); + if ($adtag === '0') { + $adtag = ''; + } elseif (!preg_match('~^[a-f0-9]{32}$~i', $adtag)) { + $this->update($this->input['chat'], $this->input['message_id'], 'wrong adtag'); + sleep(2); + $this->mtproto(); + return; + } + file_put_contents('/config/mtprotoadtag', strtolower($adtag)); + $this->restartTG(); + $this->mtproto(); + } + public function restartTG() { $secret = file_get_contents('/config/mtprotosecret'); $fakedomain = file_get_contents('/config/mtprotodomain') ?: 'yandex.ru'; + $adtag = trim(file_exists('/config/mtprotoadtag') ? file_get_contents('/config/mtprotoadtag') : ''); $this->ssh('pkill mtproto-proxy', 'tg'); if (preg_match('~^\w{32}$~', $secret)) { $p = getenv('TGPORT'); - $this->ssh("mtproto-proxy --domain $fakedomain -u nobody -H $p --nat-info 10.10.0.8:{$this->ip} -S $secret --aes-pwd /proxy-secret /proxy-multi.conf -M 1", 'tg', false, '/logs/mtproto'); + $proxyTag = $adtag ? " -P " . escapeshellarg($adtag) : ''; + $this->ssh("mtproto-proxy --domain $fakedomain -u nobody -H $p --nat-info 10.10.0.8:{$this->ip} -S $secret --aes-pwd /proxy-secret /proxy-multi.conf -M 1$proxyTag", 'tg', false, '/logs/mtproto'); } } @@ -832,10 +853,12 @@ class Bot public function mtproto() { $d = file_get_contents('/config/mtprotodomain') ?: 'yandex.ru'; + $adtag = trim(file_exists('/config/mtprotoadtag') ? file_get_contents('/config/mtprotoadtag') : ''); $st = $this->ssh('pgrep mtproto-proxy', 'tg') ? 'on' : 'off'; $text[] = "Menu -> MTProto\n"; $text[] = "status: $st\n"; $text[] = "fake domain: $d\n"; + $text[] = "adtag: " . ($adtag ?: 'off') . "\n"; if ($st == 'on') { $text[] = $this->linkMtproto(); } @@ -857,6 +880,12 @@ class Bot 'callback_data' => "/changeTGDomain", ], ]; + $data[] = [ + [ + 'text' => $this->i18n('setAdTag'), + 'callback_data' => "/setTGAdtag", + ], + ]; $data[] = [ [ 'text' => $this->i18n('show QR'), @@ -1847,6 +1876,7 @@ class Bot ] : false, 'mtproto' => file_get_contents('/config/mtprotosecret'), 'mtprotodomain' => file_get_contents('/config/mtprotodomain'), + 'mtprotoadtag' => file_exists('/config/mtprotoadtag') ? file_get_contents('/config/mtprotoadtag') : '', 'xray' => $this->getXray(), 'hy' => yaml_parse_file('/config/hysteria.yaml'), 'oc' => file_get_contents('/config/ocserv.conf'), @@ -1956,6 +1986,7 @@ class Bot $this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out)); file_put_contents('/config/mtprotosecret', $json['mtproto']); file_put_contents('/config/mtprotodomain', $json['mtprotodomain'] ?: ''); + file_put_contents('/config/mtprotoadtag', trim($json['mtprotoadtag'] ?? '')); $this->restartTG(); } // hwid @@ -9100,6 +9131,22 @@ DNS-over-HTTPS with IP: ]; } + public function changeTGAdtag() + { + $r = $this->send( + $this->input['chat'], + "@{$this->input['username']} enter adtag or 0 for disable", + $this->input['message_id'], + reply: 'enter adtag or 0 for disable', + ); + $_SESSION['reply'][$r['result']['message_id']] = [ + 'start_message' => $this->input['message_id'], + 'start_callback' => $this->input['callback_id'], + 'callback' => 'setTelegramAdtag', + 'args' => [], + ]; + } + public function setFakeDomain($domain, $self = false) { $c = $this->getXray(); diff --git a/app/i18n.php b/app/i18n.php index 756f98c..6c60261 100644 --- a/app/i18n.php +++ b/app/i18n.php @@ -261,6 +261,10 @@ $i = [ 'en' => 'setSecret', 'ru' => 'установить свой ключ', ], + 'setAdTag' => [ + 'en' => 'set adtag', + 'ru' => 'установить adtag', + ], 'defaultDNS' => [ 'en' => 'defaultDNS', 'ru' => 'дефолтный днс',