Compare commits

...

4 Commits

Author SHA1 Message Date
mercury 295ee6f2aa fix nginx.conf init 2024-09-19 12:11:05 +04:00
mercury 7ce7c56c1b domain for links -> cdn for xray 2024-09-19 12:02:51 +04:00
mercury dca34de723 fix config menu 2024-09-17 20:36:51 +04:00
mercury eb1ad21c88 domain for links 2024-09-17 20:15:34 +04:00
4 changed files with 121 additions and 17 deletions
+77 -17
View File
@@ -148,6 +148,9 @@ class Bot
case preg_match('~^/addSubdomain$~', $this->input['callback'], $m): case preg_match('~^/addSubdomain$~', $this->input['callback'], $m):
$this->addSubdomain(); $this->addSubdomain();
break; break;
case preg_match('~^/addLinkDomain$~', $this->input['callback'], $m):
$this->addLinkDomain();
break;
case preg_match('~^/id$~', $this->input['message'], $m): case preg_match('~^/id$~', $this->input['message'], $m):
$this->send($this->input['chat'], $this->input['from'], $this->input['message_id']); $this->send($this->input['chat'], $this->input['from'], $this->input['message_id']);
break; break;
@@ -1598,7 +1601,7 @@ class Bot
{ {
$conf = $this->getPacConf(); $conf = $this->getPacConf();
$ip = $this->ip; $ip = $this->ip;
$domain = $conf['domain'] ?: $ip; $domain = $this->getDomain();
$scheme = empty($ssl = $this->nginxGetTypeCert()) ? 'http' : 'https'; $scheme = empty($ssl = $this->nginxGetTypeCert()) ? 'http' : 'https';
$ss = $this->getSSConfig(); $ss = $this->getSSConfig();
$port = !empty($ss['plugin']) ? (!empty($ssl) ? 443 : 80) : getenv('SSPORT'); $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->xray();
}
public function setSubdomain($text) public function setSubdomain($text)
{ {
$c = $this->getPacConf(); $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->setPacConf($c);
$this->menu('config'); $this->menu('config');
} }
@@ -3238,7 +3272,7 @@ DNS-over-HTTPS with IP:
$mpac = stat(__DIR__ . '/zapretlists/mpac'); $mpac = stat(__DIR__ . '/zapretlists/mpac');
$pac = stat(__DIR__ . '/zapretlists/pac'); $pac = stat(__DIR__ . '/zapretlists/pac');
$conf = $this->getPacConf(); $conf = $this->getPacConf();
$ip = $conf['domain'] ?: $this->ip; $ip = $this->getDomain();
$hash = substr(md5($this->key), 0, 8); $hash = substr(md5($this->key), 0, 8);
$scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https'; $scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https';
$text = <<<text $text = <<<text
@@ -3650,7 +3684,7 @@ DNS-over-HTTPS with IP:
{ {
$conf = $this->getPacConf(); $conf = $this->getPacConf();
$ip = $this->ip; $ip = $this->ip;
$domain = $conf['domain'] ?: $ip; $domain = $this->getDomain();
$scheme = empty($ssl = $this->nginxGetTypeCert()) ? 'http' : 'https'; $scheme = empty($ssl = $this->nginxGetTypeCert()) ? 'http' : 'https';
$ss = $this->getSSConfig(); $ss = $this->getSSConfig();
$v2ray = !empty($ss['plugin']) ? 'ON' : 'OFF'; $v2ray = !empty($ss['plugin']) ? 'ON' : 'OFF';
@@ -3830,7 +3864,7 @@ DNS-over-HTTPS with IP:
{ {
$c = $this->getXray(); $c = $this->getXray();
$pac = $this->getPacConf(); $pac = $this->getPacConf();
$domain = $pac['domain'] ?: $this->ip; $domain = $this->getDomain($pac['transport'] == 'Websocket');
$scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https'; $scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https';
$hash = substr(md5($this->key), 0, 8); $hash = substr(md5($this->key), 0, 8);
$si = "$scheme://{$domain}/pac/" . base64_encode(serialize([ $si = "$scheme://{$domain}/pac/" . base64_encode(serialize([
@@ -3904,8 +3938,9 @@ DNS-over-HTTPS with IP:
public function naiveMenu() public function naiveMenu()
{ {
$pac = $this->getPacConf(); $pac = $this->getPacConf();
$domain = $this->getDomain();
$text[] = "Menu -> NaiveProxy"; $text[] = "Menu -> NaiveProxy";
$text[] = "<code>https://{$pac['naive']['user']}:{$pac['naive']['pass']}@np.{$pac['domain']}</code>"; $text[] = "<code>https://{$pac['naive']['user']}:{$pac['naive']['pass']}@np.$domain</code>";
$data[] = [ $data[] = [
[ [
'text' => $this->i18n('change login'), 'text' => $this->i18n('change login'),
@@ -3997,6 +4032,7 @@ DNS-over-HTTPS with IP:
public function ocMenu() public function ocMenu()
{ {
$pac = $this->getPacConf(); $pac = $this->getPacConf();
$domain = $this->getDomain();
$ocserv = file_get_contents('/config/ocserv.conf'); $ocserv = file_get_contents('/config/ocserv.conf');
preg_match('~^camouflage_secret[^\n]+?"([^"]+)*"~sm', $ocserv, $m); preg_match('~^camouflage_secret[^\n]+?"([^"]+)*"~sm', $ocserv, $m);
$cs = $m[1]; $cs = $m[1];
@@ -4005,7 +4041,7 @@ DNS-over-HTTPS with IP:
$pass = htmlspecialchars($pac['ocserv']); $pass = htmlspecialchars($pac['ocserv']);
$text[] = "Menu -> OpenConnect"; $text[] = "Menu -> OpenConnect";
if (!empty($m[1])) { if (!empty($m[1])) {
$text[] = "<code>https://oc.{$pac['domain']}/?$cs</code>"; $text[] = "<code>https://oc.$domain/?$cs</code>";
} }
$text[] = "password: <span class='tg-spoiler'>$pass</span>"; $text[] = "password: <span class='tg-spoiler'>$pass</span>";
$data[] = [ $data[] = [
@@ -4225,7 +4261,7 @@ DNS-over-HTTPS with IP:
public function templates($type) public function templates($type)
{ {
$pac = $this->getPacConf(); $pac = $this->getPacConf();
$domain = $pac['domain'] ?: $this->ip; $domain = $this->getDomain();
$hash = substr(md5($this->key), 0, 8); $hash = substr(md5($this->key), 0, 8);
$text[] = "Menu -> " . $this->i18n('xray') . " -> $type templates"; $text[] = "Menu -> " . $this->i18n('xray') . " -> $type templates";
$templates = $pac["{$type}templates"]; $templates = $pac["{$type}templates"];
@@ -4293,6 +4329,12 @@ DNS-over-HTTPS with IP:
$text[] = "fake domain: <code>$fake</code>"; $text[] = "fake domain: <code>$fake</code>";
} }
$text[] = 'transport: ' . ($p['transport'] ?: 'Reality'); $text[] = 'transport: ' . ($p['transport'] ?: 'Reality');
$data[] = [
[
'text' => $p['linkdomain'] ?: $this->i18n('cdn'),
'callback_data' => '/addLinkDomain',
],
];
$data[] = [ $data[] = [
[ [
'text' => $this->i18n('Reality') . ' ' . ($p['transport'] != 'Websocket' ? $this->i18n('on') : $this->i18n('off')), 'text' => $this->i18n('Reality') . ' ' . ($p['transport'] != 'Websocket' ? $this->i18n('on') : $this->i18n('off')),
@@ -4548,7 +4590,7 @@ DNS-over-HTTPS with IP:
{ {
$c = $this->getXray()['inbounds'][0]['settings']['clients'][$i]; $c = $this->getXray()['inbounds'][0]['settings']['clients'][$i];
$pac = $this->getPacConf(); $pac = $this->getPacConf();
$domain = $pac['domain'] ?: $this->ip; $domain = $this->getDomain($pac['transport'] == 'Websocket');
$scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https'; $scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https';
$hash = substr(md5($this->key), 0, 8); $hash = substr(md5($this->key), 0, 8);
@@ -4635,17 +4677,26 @@ DNS-over-HTTPS with IP:
); );
} }
public function getDomain($cdn = false)
{
$c = $this->getPacConf();
if ($cdn && $c['linkdomain']) {
return $c['linkdomain'];
}
return $c['domain'] ?: $this->ip;
}
public function v2raySubscription($key, $fs = 0) public function v2raySubscription($key, $fs = 0)
{ {
$pac = $this->getPacConf(); $pac = $this->getPacConf();
$domain = $pac['domain'] ?: $this->ip; $domain = $this->getDomain();
$xr = $this->getXray(); $xr = $this->getXray();
$flag = true; $flag = true;
foreach ($xr['inbounds'][0]['settings']['clients'] as $k => $v) { foreach ($xr['inbounds'][0]['settings']['clients'] as $k => $v) {
if ($v['id'] == $key) { if ($v['id'] == $key) {
if (!empty($fs)) { if (!empty($fs)) {
return $this->userXr($k, 0, 1); return $this->userXr($k);
} }
if (empty($v['off'])) { if (empty($v['off'])) {
$flag = false; $flag = false;
@@ -4678,7 +4729,7 @@ DNS-over-HTTPS with IP:
{ {
$type = $_GET['t'] == 's' ? 'v2ray' : 'sing'; $type = $_GET['t'] == 's' ? 'v2ray' : 'sing';
$pac = $this->getPacConf(); $pac = $this->getPacConf();
$domain = $pac['domain'] ?: $this->ip; $domain = $this->getDomain($pac['transport'] == 'Websocket');
$xr = $this->getXray(); $xr = $this->getXray();
$scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https'; $scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https';
$hash = substr(md5($this->key), 0, 8); $hash = substr(md5($this->key), 0, 8);
@@ -4900,7 +4951,7 @@ DNS-over-HTTPS with IP:
public function createRuleSet($route, $uid) public function createRuleSet($route, $uid)
{ {
$pac = $this->getPacConf(); $pac = $this->getPacConf();
$domain = $pac['domain'] ?: $this->ip; $domain = $this->getDomain();
$scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https'; $scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https';
$hash = substr(md5($this->key), 0, 8); $hash = substr(md5($this->key), 0, 8);
@@ -5117,7 +5168,7 @@ DNS-over-HTTPS with IP:
{ {
$conf = $this->getPacConf(); $conf = $this->getPacConf();
$ip = $this->ip; $ip = $this->ip;
$domain = $conf['domain'] ?: $ip; $domain = $this->getDomain();
$scheme = empty($ssl = $this->nginxGetTypeCert()) ? 'http' : 'https'; $scheme = empty($ssl = $this->nginxGetTypeCert()) ? 'http' : 'https';
$text = "$scheme://$domain/adguard\nLogin: admin\nPass: <span class='tg-spoiler'>{$conf['adpswd']}</span>\n\n"; $text = "$scheme://$domain/adguard\nLogin: admin\nPass: <span class='tg-spoiler'>{$conf['adpswd']}</span>\n\n";
if ($ssl) { if ($ssl) {
@@ -5221,6 +5272,15 @@ DNS-over-HTTPS with IP:
return openssl_x509_parse($c)["validTo_time_t"] ?: false; return openssl_x509_parse($c)["validTo_time_t"] ?: false;
} }
public function domainsCert()
{
$domains = openssl_x509_parse(openssl_x509_read(file_get_contents("/certs/cert_public")))['extensions']["subjectAltName"];
if (empty($domains)) {
return false;
}
return implode("\n", array_map(fn($e) => trim($e), explode(',', str_replace('DNS:', '', $domains))));
}
public function updatebot() public function updatebot()
{ {
$b = exec('git -C / rev-parse --abbrev-ref HEAD'); $b = exec('git -C / rev-parse --abbrev-ref HEAD');
@@ -5283,7 +5343,7 @@ DNS-over-HTTPS with IP:
} }
$text[] = $conf['domain'] ? "Domains:\n{$conf['domain']}\nnp.{$conf['domain']} (for naiveproxy)\noc.{$conf['domain']} (for openconnect)" . ($conf['adguardkey'] ? "\n{$conf['adguardkey']}.{$conf['domain']} (for adguard DoT)" : '') . $custom : $this->i18n('domain explain'); $text[] = $conf['domain'] ? "Domains:\n{$conf['domain']}\nnp.{$conf['domain']} (for naiveproxy)\noc.{$conf['domain']} (for openconnect)" . ($conf['adguardkey'] ? "\n{$conf['adguardkey']}.{$conf['domain']} (for adguard DoT)" : '') . $custom : $this->i18n('domain explain');
$ssl = $this->expireCert(); $ssl = $this->expireCert();
$text[] = $conf['domain'] ? "\nSSL: " . ($ssl ? date('Y-m-d H:i:s', $this->expireCert()) : 'none') : ''; $text[] = $conf['domain'] ? "\nSSL: " . ($ssl ? date('Y-m-d H:i:s', $this->expireCert()) . "\n" . $this->domainsCert() : 'none') : '';
$data = [ $data = [
[ [
@@ -5292,7 +5352,7 @@ DNS-over-HTTPS with IP:
'callback_data' => $conf['domain'] ? '/deldomain' : '/domain', 'callback_data' => $conf['domain'] ? '/deldomain' : '/domain',
], ],
[ [
'text' => $this->i18n('subdomain'), 'text' => $this->i18n('+ subdomain'),
'callback_data' => '/addSubdomain', 'callback_data' => '/addSubdomain',
], ],
], ],
@@ -5790,7 +5850,7 @@ DNS-over-HTTPS with IP:
$conf[] = ''; $conf[] = '';
$conf[] = $peer['# PublicKey'] ? '# [Peer]' : '[Peer]'; $conf[] = $peer['# PublicKey'] ? '# [Peer]' : '[Peer]';
if (!empty($peer['Endpoint'])) { 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) { foreach ($peer as $k => $v) {
$conf[] = "$k = $v"; $conf[] = "$k = $v";
+21
View File
@@ -75,6 +75,27 @@ http {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 5d; proxy_read_timeout 5d;
} }
#-ssl
# # The DoH server block
# location /dns-query {
# access_log /logs/nginx_doh_access;
# # Proxy HTTP/1.1, clear the connection header to enable Keep-Alive
# proxy_http_version 1.1;
# proxy_set_header Connection "";
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-Proto https;
# proxy_set_header X-Forwarded-For $remote_addr;
# proxy_set_header X-Forwarded-Host $remote_addr;
# # Enable Cache, and set the cache_key to include the request_body
# proxy_cache doh_cache;
# proxy_cache_key $scheme$proxy_host$uri$is_args$args$request_body;
# # proxy pass to the dohloop upstream
# proxy_pass https://ad/dns-query;
# }
#-ssl
location ~\.well-known { location ~\.well-known {
access_log /logs/nginx_certbot_access; access_log /logs/nginx_certbot_access;
root /certs/; root /certs/;
+21
View File
@@ -75,6 +75,27 @@ http {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 5d; proxy_read_timeout 5d;
} }
#-ssl
# # The DoH server block
# location /dns-query {
# access_log /logs/nginx_doh_access;
# # Proxy HTTP/1.1, clear the connection header to enable Keep-Alive
# proxy_http_version 1.1;
# proxy_set_header Connection "";
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-Proto https;
# proxy_set_header X-Forwarded-For $remote_addr;
# proxy_set_header X-Forwarded-Host $remote_addr;
# # Enable Cache, and set the cache_key to include the request_body
# proxy_cache doh_cache;
# proxy_cache_key $scheme$proxy_host$uri$is_args$args$request_body;
# # proxy pass to the dohloop upstream
# proxy_pass https://ad/dns-query;
# }
#-ssl
location ~\.well-known { location ~\.well-known {
access_log /logs/nginx_certbot_access; access_log /logs/nginx_certbot_access;
root /certs/; root /certs/;
+2
View File
@@ -1,3 +1,5 @@
17.09.2024 v1.55
- возможность подменить домен в ссылках на конфиги
16.09.2024 v1.54.2 16.09.2024 v1.54.2
- фикс нэйминга клиентов в adguardHome: замена на uuid - фикс нэйминга клиентов в adguardHome: замена на uuid
16.09.2024 v1.54.1 16.09.2024 v1.54.1