xray: change fake domain

This commit is contained in:
mercury
2023-06-28 11:09:58 +04:00
parent 652f6b698f
commit 4e44beb83d
3 changed files with 57 additions and 2 deletions
+52 -2
View File
@@ -269,6 +269,9 @@ class Bot
case preg_match('~^/generateSecretXray$~', $this->input['callback'], $m):
$this->generateSecretXray();
break;
case preg_match('~^/changeFakeDomain$~', $this->input['callback'], $m):
$this->changeFakeDomain();
break;
case preg_match('~^/include (\d+)$~', $this->input['callback'], $m):
$this->include($m[1]);
break;
@@ -830,6 +833,7 @@ class Bot
$out[] = 'update xray';
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
$this->restartXray($json['xray']);
$this->setUpstreamDomain($json['xray']['inbounds'][0]['streamSettings']['realitySettings']['serverNames'][0]);
}
// nginx
$out[] = 'reset nginx';
@@ -2535,13 +2539,14 @@ DNS-over-HTTPS with IP:
public function xray()
{
$c = json_decode(file_get_contents('/config/xray.json'), true);
$c = $this->getXray();
$pac = $this->getPacConf();
$st = $this->ssh('pgrep xray', 'xr') ? 'on' : 'off';
$text[] = "Menu -> " . $this->i18n('xray') . "\n";
$text[] = "uuid: <code>{$c['inbounds'][0]['settings']['clients'][0]['id']}</code>";
$text[] = "shortId: <code>{$c['inbounds'][0]['streamSettings']['realitySettings']['shortIds'][0]}</code>";
$text[] = "pubkey: <code>{$pac['xray']}</code>";
$text[] = "fake domain: <code>{$c['inbounds'][0]['streamSettings']['realitySettings']['serverNames'][0]}</code>";
$text[] = "\nstatus: $st";
$data[] = [
@@ -2550,6 +2555,12 @@ DNS-over-HTTPS with IP:
'callback_data' => "/generateSecretXray",
],
];
$data[] = [
[
'text' => $this->i18n('changeFakeDomain'),
'callback_data' => "/changeFakeDomain",
],
];
$data[] = [
[
'text' => $this->i18n('back'),
@@ -2564,9 +2575,14 @@ DNS-over-HTTPS with IP:
);
}
public function getXray()
{
return json_decode(file_get_contents('/config/xray.json'), true);
}
public function generateSecretXray()
{
$c = json_decode(file_get_contents('/config/xray.json'), true);
$c = $this->getXray();
$uuid = trim($this->ssh('xray uuid', 'xr'));
$shortId = trim($this->ssh('openssl rand -hex 8', 'xr'));
$keys = $this->ssh('xray x25519', 'xr');
@@ -2584,6 +2600,14 @@ DNS-over-HTTPS with IP:
$this->xray();
}
public function setUpstreamDomain($domain)
{
$nginx = file_get_contents('/config/upstream.conf');
$t = preg_replace('~#domain.+#domain~s', "#domain\n$domain reality;\n#domain", $nginx);
file_put_contents('/config/upstream.conf', $t);
$this->ssh("nginx -s reload 2>&1", 'up');
}
public function addWg($page)
{
$text = "Menu -> Wireguard -> Add peer\n\n";
@@ -2906,6 +2930,32 @@ DNS-over-HTTPS with IP:
];
}
public function changeFakeDomain()
{
$r = $this->send(
$this->input['chat'],
"@{$this->input['username']} enter domain",
$this->input['message_id'],
reply: 'enter domain',
);
$_SESSION['reply'][$r['result']['message_id']] = [
'start_message' => $this->input['message_id'],
'start_callback' => $this->input['callback_id'],
'callback' => 'setFakeDomain',
'args' => [],
];
}
public function setFakeDomain($domain)
{
$c = $this->getXray();
$c['inbounds'][0]['streamSettings']['realitySettings']['serverNames'][0] = $domain;
$c['inbounds'][0]['streamSettings']['realitySettings']['dest'] = "$domain:443";
$this->restartXray($c);
$this->setUpstreamDomain($domain);
$this->xray();
}
public function setBackup($text)
{
$text = trim($text);