From eb1ad21c88ec93697d1eac77d3475ba3e73b4521 Mon Sep 17 00:00:00 2001 From: mercury Date: Tue, 17 Sep 2024 20:15:34 +0400 Subject: [PATCH] domain for links --- app/bot.php | 76 ++++++++++++++++++++++++++++++++++++++++++----------- version | 2 ++ 2 files changed, 63 insertions(+), 15 deletions(-) diff --git a/app/bot.php b/app/bot.php index 3bf54b3..09b1d95 100644 --- a/app/bot.php +++ b/app/bot.php @@ -148,6 +148,9 @@ class Bot case preg_match('~^/addSubdomain$~', $this->input['callback'], $m): $this->addSubdomain(); break; + case preg_match('~^/addLinkDomain$~', $this->input['callback'], $m): + $this->addLinkDomain(); + break; case preg_match('~^/id$~', $this->input['message'], $m): $this->send($this->input['chat'], $this->input['from'], $this->input['message_id']); break; @@ -1598,7 +1601,7 @@ class Bot { $conf = $this->getPacConf(); $ip = $this->ip; - $domain = $conf['domain'] ?: $ip; + $domain = $this->getDomain(); $scheme = empty($ssl = $this->nginxGetTypeCert()) ? 'http' : 'https'; $ss = $this->getSSConfig(); $port = !empty($ss['plugin']) ? (!empty($ssl) ? 443 : 80) : getenv('SSPORT'); @@ -2085,10 +2088,41 @@ class Bot ]; } + public function addLinkDomain() + { + $r = $this->send( + $this->input['chat'], + "@{$this->input['username']} enter domain for link", + $this->input['message_id'], + reply: 'enter domain for link', + ); + $_SESSION['reply'][$r['result']['message_id']] = [ + 'start_message' => $this->input['message_id'], + 'callback' => 'setLinkDomain', + 'args' => [], + ]; + } + + public function setLinkDomain($text) + { + $c = $this->getPacConf(); + if (empty($text)) { + unset($c['linkdomain']); + } else { + $c['linkdomain'] = trim($text); + } + $this->setPacConf($c); + $this->menu('config'); + } + public function setSubdomain($text) { $c = $this->getPacConf(); - $c['subdomain'] = array_filter(explode(',', $text), fn($e) => !empty(trim($e))); + if (empty($text)) { + unset($c['subdomain']); + } else { + $c['subdomain'] = array_filter(explode(',', $text), fn($e) => !empty(trim($e))); + } $this->setPacConf($c); $this->menu('config'); } @@ -3238,7 +3272,7 @@ DNS-over-HTTPS with IP: $mpac = stat(__DIR__ . '/zapretlists/mpac'); $pac = stat(__DIR__ . '/zapretlists/pac'); $conf = $this->getPacConf(); - $ip = $conf['domain'] ?: $this->ip; + $ip = $this->getDomain(); $hash = substr(md5($this->key), 0, 8); $scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https'; $text = <<getPacConf(); $ip = $this->ip; - $domain = $conf['domain'] ?: $ip; + $domain = $this->getDomain(); $scheme = empty($ssl = $this->nginxGetTypeCert()) ? 'http' : 'https'; $ss = $this->getSSConfig(); $v2ray = !empty($ss['plugin']) ? 'ON' : 'OFF'; @@ -3830,7 +3864,7 @@ DNS-over-HTTPS with IP: { $c = $this->getXray(); $pac = $this->getPacConf(); - $domain = $pac['domain'] ?: $this->ip; + $domain = $this->getDomain(); $scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https'; $hash = substr(md5($this->key), 0, 8); $si = "$scheme://{$domain}/pac/" . base64_encode(serialize([ @@ -3904,8 +3938,9 @@ DNS-over-HTTPS with IP: public function naiveMenu() { $pac = $this->getPacConf(); + $domain = $this->getDomain(); $text[] = "Menu -> NaiveProxy"; - $text[] = "https://{$pac['naive']['user']}:{$pac['naive']['pass']}@np.{$pac['domain']}"; + $text[] = "https://{$pac['naive']['user']}:{$pac['naive']['pass']}@np.$domain"; $data[] = [ [ 'text' => $this->i18n('change login'), @@ -3997,6 +4032,7 @@ DNS-over-HTTPS with IP: public function ocMenu() { $pac = $this->getPacConf(); + $domain = $this->getDomain(); $ocserv = file_get_contents('/config/ocserv.conf'); preg_match('~^camouflage_secret[^\n]+?"([^"]+)*"~sm', $ocserv, $m); $cs = $m[1]; @@ -4005,7 +4041,7 @@ DNS-over-HTTPS with IP: $pass = htmlspecialchars($pac['ocserv']); $text[] = "Menu -> OpenConnect"; if (!empty($m[1])) { - $text[] = "https://oc.{$pac['domain']}/?$cs"; + $text[] = "https://oc.$domain/?$cs"; } $text[] = "password: $pass"; $data[] = [ @@ -4225,7 +4261,7 @@ DNS-over-HTTPS with IP: public function templates($type) { $pac = $this->getPacConf(); - $domain = $pac['domain'] ?: $this->ip; + $domain = $this->getDomain(); $hash = substr(md5($this->key), 0, 8); $text[] = "Menu -> " . $this->i18n('xray') . " -> $type templates"; $templates = $pac["{$type}templates"]; @@ -4548,7 +4584,7 @@ DNS-over-HTTPS with IP: { $c = $this->getXray()['inbounds'][0]['settings']['clients'][$i]; $pac = $this->getPacConf(); - $domain = $pac['domain'] ?: $this->ip; + $domain = $this->getDomain(); $scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https'; $hash = substr(md5($this->key), 0, 8); @@ -4635,10 +4671,16 @@ DNS-over-HTTPS with IP: ); } + public function getDomain() + { + $c = $this->getPacConf(); + return $c['linkdomain'] ?: ($c['domain'] ?: $this->ip); + } + public function v2raySubscription($key, $fs = 0) { $pac = $this->getPacConf(); - $domain = $pac['domain'] ?: $this->ip; + $domain = $this->getDomain(); $xr = $this->getXray(); $flag = true; @@ -4678,7 +4720,7 @@ DNS-over-HTTPS with IP: { $type = $_GET['t'] == 's' ? 'v2ray' : 'sing'; $pac = $this->getPacConf(); - $domain = $pac['domain'] ?: $this->ip; + $domain = $this->getDomain(); $xr = $this->getXray(); $scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https'; $hash = substr(md5($this->key), 0, 8); @@ -4900,7 +4942,7 @@ DNS-over-HTTPS with IP: public function createRuleSet($route, $uid) { $pac = $this->getPacConf(); - $domain = $pac['domain'] ?: $this->ip; + $domain = $this->getDomain(); $scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https'; $hash = substr(md5($this->key), 0, 8); @@ -5117,7 +5159,7 @@ DNS-over-HTTPS with IP: { $conf = $this->getPacConf(); $ip = $this->ip; - $domain = $conf['domain'] ?: $ip; + $domain = $this->getDomain(); $scheme = empty($ssl = $this->nginxGetTypeCert()) ? 'http' : 'https'; $text = "$scheme://$domain/adguard\nLogin: admin\nPass: {$conf['adpswd']}\n\n"; if ($ssl) { @@ -5292,9 +5334,13 @@ DNS-over-HTTPS with IP: 'callback_data' => $conf['domain'] ? '/deldomain' : '/domain', ], [ - 'text' => $this->i18n('subdomain'), + 'text' => $this->i18n('+ subdomain'), 'callback_data' => '/addSubdomain', ], + [ + 'text' => $this->i18n('domain for link'), + 'callback_data' => '/addLinkDomain', + ], ], ]; if ($conf['domain']) { @@ -5790,7 +5836,7 @@ DNS-over-HTTPS with IP: $conf[] = ''; $conf[] = $peer['# PublicKey'] ? '# [Peer]' : '[Peer]'; if (!empty($peer['Endpoint'])) { - $peer['Endpoint'] = ($pac['domain'] ? $pac['domain'] : $this->ip) . ":" . getenv($this->getInstanceWG(1) ? 'WG1PORT' : 'WGPORT'); + $peer['Endpoint'] = $this->getDomain() . ":" . getenv($this->getInstanceWG(1) ? 'WG1PORT' : 'WGPORT'); } foreach ($peer as $k => $v) { $conf[] = "$k = $v"; diff --git a/version b/version index 8cc2de5..ac16973 100644 --- a/version +++ b/version @@ -1,3 +1,5 @@ +17.09.2024 v1.55 +- возможность подменить домен в ссылках на конфиги 16.09.2024 v1.54.2 - фикс нэйминга клиентов в adguardHome: замена на uuid 16.09.2024 v1.54.1