From b9afaa82d454143d8b819b8fca61c2f6023aed88 Mon Sep 17 00:00:00 2001 From: mercury Date: Sat, 18 Feb 2023 20:42:05 +0400 Subject: [PATCH] fix v2ray without ssl --- app/bot.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/bot.php b/app/bot.php index c9118a3..7eb1666 100644 --- a/app/bot.php +++ b/app/bot.php @@ -302,9 +302,10 @@ class Bot { $this->ssh('pkill sslocal', 'proxy'); $this->ssh('pkill ssserver', 'ss'); + $ssl = $this->nginxGetTypeCert(); $c = $this->getSSConfig(); $l = $this->getSSLocalConfig(); - $domain = $this->getPacConf()['domain']; + $domain = $this->getPacConf()['domain'] ?: file_get_contents('https://ipinfo.io/ip'); if ($c['plugin']) { unset($c['plugin']); unset($c['plugin_opts']); @@ -317,9 +318,9 @@ class Bot $c['plugin'] = 'v2ray-plugin'; $c['plugin_opts'] = 'server;loglevel=none'; $l['server'] = 'ng'; - $l['server_port'] = 443; + $l['server_port'] = $ssl ? 443 : 80; $l['plugin'] = 'v2ray-plugin'; - $l['plugin_opts'] = "tls;fast-open;path=/v2ray;host=$domain"; + $l['plugin_opts'] = ($ssl ? 'tls;' : '') . "fast-open;path=/v2ray;host=$domain"; } file_put_contents('/config/ssserver.json', json_encode($c, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); file_put_contents('/config/sslocal.json', json_encode($l, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); @@ -513,8 +514,8 @@ class Bot $domain = $conf['domain'] ?: $ip; $scheme = empty($ssl = $this->nginxGetTypeCert()) ? 'http' : 'https'; $ss = $this->getSSConfig(); - $port = !empty($ssl) && !empty($ss['plugin']) ? 443 : getenv('SSPORT'); - $ss_link = preg_replace('~==~', '', 'ss://' . base64_encode("{$ss['method']}:{$ss['password']}")) . "@$domain:$port" . (!empty($ss['plugin']) ? '?plugin=' . urlencode("v2ray-plugin;path=/v2ray;host=$domain;tls") : ''); + $port = !empty($ss['plugin']) ? (!empty($ssl) ? 443 : 80) : getenv('SSPORT'); + $ss_link = preg_replace('~==~', '', 'ss://' . base64_encode("{$ss['method']}:{$ss['password']}")) . "@$domain:$port" . (!empty($ss['plugin']) ? '?plugin=' . urlencode("v2ray-plugin;path=/v2ray;host=$domain" . (!empty($ssl) ? ';tls' : '')) : ''); $qr_file = __DIR__ . "/qr/shadowsocks.png"; exec("qrencode -t png -o $qr_file '$ss_link'"); $r = $this->sendPhoto( @@ -1568,7 +1569,7 @@ DNS-over-HTTPS with IP: $scheme = empty($ssl = $this->nginxGetTypeCert()) ? 'http' : 'https'; $ss = $this->getSSConfig(); $v2ray = !empty($ss['plugin']) ? 'ON' : 'OFF'; - $port = !empty($ssl) && !empty($ss['plugin']) ? 443 : getenv('SSPORT'); + $port = !empty($ss['plugin']) ? (!empty($ssl) ? 443 : 80) : getenv('SSPORT'); $options = !empty($ssl) && !empty($ss['plugin']) ? "tls;fast-open;path=/v2ray;host=$domain" : "path=/v2ray;host=$domain"; $text = "Menu -> ShadowSocks"; @@ -1578,7 +1579,7 @@ DNS-over-HTTPS with IP: 'callback_data' => "/sspswd", ], ]; - $ss_link = preg_replace('~==~', '', 'ss://' . base64_encode("{$ss['method']}:{$ss['password']}")) . "@$domain:$port" . (!empty($ss['plugin']) ? '?plugin=' . urlencode("v2ray-plugin;path=/v2ray;host=$domain;tls") : ''); + $ss_link = preg_replace('~==~', '', 'ss://' . base64_encode("{$ss['method']}:{$ss['password']}")) . "@$domain:$port" . (!empty($ss['plugin']) ? '?plugin=' . urlencode("v2ray-plugin;path=/v2ray;host=$domain" . (!empty($ssl) ? ';tls' : '')) : ''); $text .= "\n\n$ss_link\n"; $text .= "\n\nserver: $domain:$port"; $text .= "\n\nmethod: {$ss['method']}";