Add MTProto adtag setting in bot UI

This commit is contained in:
denied1011
2026-03-28 02:44:41 +03:00
parent 8effb72cdc
commit fb075463ee
2 changed files with 52 additions and 1 deletions
+48 -1
View File
@@ -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: <code>$d</code>\n";
$text[] = "adtag: <code>" . ($adtag ?: 'off') . "</code>\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();
+4
View File
@@ -261,6 +261,10 @@ $i = [
'en' => 'setSecret',
'ru' => 'установить свой ключ',
],
'setAdTag' => [
'en' => 'set adtag',
'ru' => 'установить adtag',
],
'defaultDNS' => [
'en' => 'defaultDNS',
'ru' => 'дефолтный днс',