From ffe6bb4ba80b0a7d0504c2f294f2fa8fec375daa Mon Sep 17 00:00:00 2001 From: mercury Date: Fri, 4 Jul 2025 17:45:50 +0400 Subject: [PATCH] subscription page --- .gitignore | 2 ++ app/bot.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ app/index.php | 4 ++++ 3 files changed, 50 insertions(+) diff --git a/.gitignore b/.gitignore index 6a8d037..59247f6 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ docker-compose.override.yml backup.json app/webapp/override/ .rest + +subscription.php \ No newline at end of file diff --git a/app/bot.php b/app/bot.php index 14cd571..28baa7e 100644 --- a/app/bot.php +++ b/app/bot.php @@ -6316,6 +6316,9 @@ DNS-over-HTTPS with IP: $hash = $this->getHashBot(); $text[] = "Menu -> " . $this->i18n('xray') . " -> {$c['email']}\n"; + if (file_exists(__DIR__ . '/subscription.php')) { + $text[] = "subscription"; + } $text[] = "
{$this->linkXray($i)}
\n"; $text[] = "import://v2rayng"; @@ -6443,6 +6446,47 @@ DNS-over-HTTPS with IP: return $c['domain'] ?: $this->ip; } + public function sub() + { + $xr = $this->getXray(); + $pac = $this->getPacConf(); + $st = $this->getXrayStats(); + $domain = $_GET['cdn'] ?: ($_SERVER['SERVER_NAME'] ?: $this->getDomain($pac['transport'] != 'Reality')); + $scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https'; + $hash = $this->getHashBot(); + $flag = true; + foreach ($xr['inbounds'][0]['settings']['clients'] as $k => $v) { + if ($v['id'] == $_GET['id']) { + if (empty($v['off'])) { + $flag = false; + } + $uid = $v['id']; + $email = $v['email']; + break; + } + } + $download = $this->getBytes($st['users'][$k]['global']['download'] + $st['users'][$k]['session']['download']); + $upload = $this->getBytes($st['users'][$k]['global']['upload'] + $st['users'][$k]['session']['upload']); + $singbox = "$scheme://{$domain}/pac$hash/" . base64_encode(serialize([ + 'h' => $hash, + 't' => 'si', + 's' => $uid, + ])); + $xray = "$scheme://{$domain}/pac$hash/" . base64_encode(serialize([ + 'h' => $hash, + 't' => 's', + 's' => $uid, + ])); + $clash = "$scheme://{$domain}/pac$hash/" . base64_encode(serialize([ + 'h' => $hash, + 't' => 'cl', + 's' => $uid, + ])); + $vless = $this->linkXray($k); + $windows = "$scheme://{$domain}/pac$hash?t=si&r=w&s=$uid"; + require __DIR__ . '/subscription.php'; + } + public function subscription() { switch ($_GET['t']) { diff --git a/app/index.php b/app/index.php index 4ea1d45..9a33f81 100644 --- a/app/index.php +++ b/app/index.php @@ -42,6 +42,10 @@ switch (true) { echo "/adguard$hash/"; break; + case preg_match('~^' . preg_quote("/pac$hash/sub") . '~', $_SERVER['REQUEST_URI']) && file_exists(__DIR__ . '/subscription.php'): + $bot->sub(); + exit; + // subs & pac case preg_match('~^' . preg_quote("/pac$hash") . '~', $_SERVER['REQUEST_URI']): if (!empty($t = unserialize(base64_decode(explode('/', $_SERVER['REQUEST_URI'])[2])))) { // fix sing-box import