From 08f0babed63f3470995376d6a4fc2388cda73894 Mon Sep 17 00:00:00 2001 From: mercury Date: Sat, 27 Apr 2024 17:46:08 +0400 Subject: [PATCH] fix sinbox users actions --- app/bot.php | 152 +++++++++++++++++--------------------------- config/pac.json | 100 +---------------------------- config/singbox.json | 6 +- docker-compose.yml | 2 +- 4 files changed, 66 insertions(+), 194 deletions(-) diff --git a/app/bot.php b/app/bot.php index ba376e3..7f94484 100644 --- a/app/bot.php +++ b/app/bot.php @@ -498,9 +498,18 @@ class Bot } } - public function restartXray($c) + public function restartXray($c = false) { - $c['inbounds'][0]['users'] = array_values($c['inbounds'][0]['users']); + $c = $c ?: $this->getXray(); + $cl = array_filter($this->getPacConf()['xrusers'], fn ($e) => empty($e['off']) && (empty($e['time']) || $e['time'] >= time())); + foreach ($cl as $v) { + $t[] = [ + "uuid" => $v['uuid'], + "flow" => $v['flow'], + "name" => $v['name'], + ]; + } + $c['inbounds'][0]['users'] = $t ?: []; $this->ssh('pkill sing-box', 'si'); file_put_contents('/config/singbox.json', json_encode($c, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); $this->ssh('sing-box run -c /config/singbox.json > /dev/null 2>&1 &', 'si'); @@ -3344,7 +3353,7 @@ DNS-over-HTTPS with IP: $c = $this->getXray(); $pac = $this->getPacConf(); $domain = $pac['domain'] ?: $this->ip; - return "vless://{$c['inbounds'][0]['users'][$i]['uuid']}@$domain:443?security=reality&sni={$c['inbounds'][0]['tls']['reality']['handshake']['server']}&fp=chrome&pbk={$pac['xray']}&sid={$c['inbounds'][0]['tls']['reality']['short_id'][0]}&type=tcp&flow=xtls-rprx-vision#vpnbot"; + return "vless://{$pac['xrusers'][$i]['uuid']}@$domain:443?security=reality&sni={$c['inbounds'][0]['tls']['reality']['handshake']['server']}&fp=chrome&pbk={$pac['xray']}&sid={$c['inbounds'][0]['tls']['reality']['short_id'][0]}&type=tcp&flow=xtls-rprx-vision#vpnbot"; } public function dockerApi($url, $method = 'GET', $data = []) @@ -3551,14 +3560,10 @@ DNS-over-HTTPS with IP: public function delxr($i) { - $r = $this->getXray(); - foreach ($r['inbounds'][0]['users'] as $k => $v) { - if ($i == $k) { - unset($r['inbounds'][0]['users'][$k]); - $this->restartXray($r); - break; - } - } + $p = $this->getPacConf(); + unset($p['xrusers'][$i]); + $this->setPacConf($p); + $this->restartXray(); $this->xray(); } @@ -3577,50 +3582,51 @@ DNS-over-HTTPS with IP: public function addxrus($user) { - $c = $this->getXray(); $uuid = trim($this->ssh('sing-box generate uuid', 'si')); - $c['inbounds'][0]['users'][] = [ + $pac = $this->getPacConf(); + + $pac['xrusers'][] = [ 'uuid' => $uuid, 'flow' => 'xtls-rprx-vision', 'name' => $user, ]; - $this->restartXray($c); - $this->userXr(count($c['inbounds'][0]['users']) - 1); + $this->setPacConf($pac); + $this->restartXray($this->getXray()); + $this->userXr(count($pac['xrusers']) - 1); } public function setTimerXr($time, $i) { - $time = strtotime($time); - if ($time === false) { - $this->send($this->input['chat'], 'wrong format'); - return; - } - $c = $this->getXray(); - if (empty($time)) { - unset($c['inbounds'][0]['users'][$i]['time']); + $c = $this->getPacConf(); + if ($time === '0') { + unset($c['xrusers'][$i]['time']); } else { - if (!empty($c['inbounds'][0]['users'][$i]['off'])) { - $this->switchXr($i, 1); - $c = $this->getXray(); + $time = strtotime($time); + if ($time === false) { + $this->send($this->input['chat'], 'wrong format'); + return; } - $c['inbounds'][0]['users'][$i]['time'] = $time; + if (!empty($c['xrusers'][$i]['off'])) { + unset($c['xrusers'][$i]['off']); + } + $c['xrusers'][$i]['time'] = $time; } - file_put_contents('/config/singbox.json', json_encode($c, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); + $this->setPacConf($c); + $this->restartXray(); $this->userXr($i); } public function switchXr($i, $nm = 0) { - $c = $this->getXray(); - unset($c['inbounds'][0]['users'][$i]['time']); - if (empty($c['inbounds'][0]['users'][$i]['off'])) { - $c['inbounds'][0]['users'][$i]['off'] = $c['inbounds'][0]['users'][$i]['uuid']; - $c['inbounds'][0]['users'][$i]['uuid'] = trim($this->ssh('sing-box generate uuid', 'si')); + $p = $this->getPacConf(); + unset($p['xrusers'][$i]['time']); + if (empty($p['xrusers'][$i]['off'])) { + $p['xrusers'][$i]['off'] = 1; } else { - $c['inbounds'][0]['users'][$i]['uuid'] = $c['inbounds'][0]['users'][$i]['off']; - unset($c['inbounds'][0]['users'][$i]['off']); + unset($p['xrusers'][$i]['off']); } - $this->restartXray($c); + $this->setPacConf($p); + $this->restartXray(); if (empty($nm)) { $this->userXr($i); } @@ -3628,9 +3634,9 @@ DNS-over-HTTPS with IP: public function renXrUs($name, $i) { - $c = $this->getXray(); - $c['inbounds'][0]['users'][$i]['email'] = $name; - $this->restartXray($c); + $c = $this->getPacConf(); + $c['xrusers'][$i]['name'] = $name; + $this->setPacConf($c); $this->userXr($i); } @@ -3768,6 +3774,7 @@ DNS-over-HTTPS with IP: $this->generateSecretXray(); } $c = $this->getXray(); + $pac = $this->getPacConf(); $text[] = "Menu -> " . $this->i18n('xray'); $text[] = "fake domain: {$c['inbounds'][0]['tls']['reality']['handshake']['server']}"; $data[] = [ @@ -3775,10 +3782,6 @@ DNS-over-HTTPS with IP: 'text' => $this->i18n('changeFakeDomain'), 'callback_data' => "/changeFakeDomain", ], - [ - 'text' => $this->i18n('selfFakeDomain'), - 'callback_data' => "/selfFakeDomain", - ], ]; $data[] = [ [ @@ -3800,15 +3803,15 @@ DNS-over-HTTPS with IP: 'callback_data' => "/xtlswarp", ], ]; - foreach ($c['inbounds'][0]['users'] as $k => $v) { + $cl = $pac['xrusers'] ?: []; + foreach ($cl as $k => $v) { if (!empty($v['off'])) { $off++; } else { $on++; } } - $type = $this->getPacConf()['xtlslist']; - $clients = array_filter($c['inbounds'][0]['users'], fn($e) => !$type ? empty($e['off']) : !empty($e['off'])); + $clients = array_filter($cl, fn($e) => !$pac['xtlslist'] ? empty($e['off']) : !empty($e['off'])); uasort($clients, fn($a, $b) => ($a['time'] ?: PHP_INT_MAX) <=> ($b['time'] ?: PHP_INT_MAX)); $all = (int) ceil(count($clients) / $this->limit); @@ -3842,11 +3845,11 @@ DNS-over-HTTPS with IP: 'callback_data' => "/addXrUser", ], [ - 'text' => $this->i18n('on') . " $on " . (!$type ? "✅" : ''), + 'text' => $this->i18n('on') . " $on " . (!$pac['xtlslist'] ? "✅" : ''), 'callback_data' => "/listXr 0", ], [ - 'text' => $this->i18n('off') . " $off " . ($type ? "✅" : ''), + 'text' => $this->i18n('off') . " $off " . ($pac['xtlslist'] ? "✅" : ''), 'callback_data' => "/listXr 1", ], ]; @@ -3926,13 +3929,13 @@ DNS-over-HTTPS with IP: public function choiceTemplate($arg) { $arg = explode('_', $arg); - $c = $this->getXray(); + $c = $this->getPacConf(); if (!empty($arg[2])) { - $c['inbounds'][0]['users'][$arg[1]]["{$arg[0]}template"] = $arg[2]; + $c['xrusers'][$arg[1]]["{$arg[0]}template"] = $arg[2]; } else { - unset($c['inbounds'][0]['users'][$arg[1]]["{$arg[0]}template"]); + unset($c['xrusers'][$arg[1]]["{$arg[0]}template"]); } - file_put_contents('/config/singbox.json', json_encode($c, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); + $this->setPacConf($c); $this->userXr($arg[1]); } @@ -3940,7 +3943,7 @@ DNS-over-HTTPS with IP: { $c = $this->getXray(); $pac = $this->getPacConf(); - $text[] = "Menu -> " . $this->i18n('xray') . " -> {$c['inbounds'][0]['users'][$i]['email']}\n"; + $text[] = "Menu -> " . $this->i18n('xray') . " -> {$pac['xrusers'][$i]['name']}\n"; $templates = $pac["{$type}templates"]; $data[] = [ [ @@ -3978,8 +3981,8 @@ DNS-over-HTTPS with IP: public function userXr($i) { - $c = $this->getXray()['inbounds'][0]['users'][$i]; $pac = $this->getPacConf(); + $c = $pac['xrusers'][$i]; $domain = $pac['domain'] ?: $this->ip; $scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https'; $hash = substr(md5($this->key), 0, 8); @@ -4059,45 +4062,6 @@ DNS-over-HTTPS with IP: ); } - public function v2raySubscription($key, $fs = 0) - { - $pac = $this->getPacConf(); - $domain = $pac['domain'] ?: $this->ip; - $xr = $this->getXray(); - - $flag = true; - foreach ($xr['inbounds'][0]['users'] as $k => $v) { - if ($v['uuid'] == $key) { - if (!empty($fs)) { - return $this->userXr($k); - } - if (empty($v['off'])) { - $flag = false; - } - break; - } - } - if ($flag) { - return; - } - - $c = json_decode(file_get_contents('/config/v2ray.json'), true); - - $c['outbounds'][0]['settings']['vnext'][0]['address'] = $domain; - $c['outbounds'][0]['settings']['vnext'][0]['users'][0]['id'] = $key; - $c['outbounds'][0]['streamSettings']['realitySettings']['serverName'] = $xr['inbounds'][0]['tls']['reality']['handshake']['server']; - $c['outbounds'][0]['streamSettings']['realitySettings']['publicKey'] = $pac['xray']; - $c['outbounds'][0]['streamSettings']['realitySettings']['shortId'] = $xr['inbounds'][0]['tls']['reality']['short_id'][0]; - $c['routing']['rules'][0]['domain'] = array_keys(array_filter($pac['includelist'])); - - if (empty($c['routing']['rules'][0]['domain'])) { - unset($c['routing']['rules'][0]); - $c['routing']['rules'] = array_values($c['routing']['rules']); - - } - echo json_encode($c); - } - public function subscription() { $pac = $this->getPacConf(); @@ -4107,7 +4071,7 @@ DNS-over-HTTPS with IP: $hash = substr(md5($this->key), 0, 8); $flag = true; - foreach ($xr['inbounds'][0]['users'] as $k => $v) { + foreach ($pac['xrusers'] as $k => $v) { if ($v['uuid'] == $_GET['s']) { if (empty($v['off'])) { $flag = false; diff --git a/config/pac.json b/config/pac.json index 1a24005..2f08ac2 100644 --- a/config/pac.json +++ b/config/pac.json @@ -1,99 +1,3 @@ { - "zapret": false, - "excludelist": { - "(?:v|w)ul(?:c|k)an": true, - "^\\d": true, - "^a\\w-": true, - "^admiral": true, - "^avtomaty": true, - "^azart": true, - "^azimob": true, - "^baltplay": true, - "a(?:s|z)ino": true, - "adrenalin": true, - "alco": true, - "bet": true, - "prostitut": true, - "zenit": true, - "zerkalo": true, - "777": true - }, - "includelist": {}, - "reverselist": {}, - "subzoneslist": { - "3dn": false, - "3nx": true, - "akadns": true, - "appspot": true, - "azurewebsites": true, - "beget": true, - "berlogovo": true, - "biz": true, - "brightcove": true, - "cc": true, - "cloudfront": true, - "co": true, - "com": true, - "cu": true, - "ddns": true, - "deviantart": true, - "dn": true, - "dp": true, - "dyndns": true, - "edgecastcdn": true, - "edu": true, - "eu": true, - "fastly": true, - "force": true, - "github": true, - "google": true, - "googleusercontent": true, - "gov": true, - "herokuapp": true, - "hldns": true, - "ho": true, - "hopto": true, - "hwcdn": true, - "i": true, - "iboards": true, - "in": true, - "info": true, - "int": true, - "itch": true, - "keenetic": true, - "kiev": true, - "kirov": true, - "linode": true, - "livejournal": true, - "maryno": true, - "mil": true, - "msk": true, - "my1": true, - "mybb2": true, - "ne": true, - "net": true, - "netdna-ssl": true, - "nnov": true, - "notion": true, - "nov": true, - "od": true, - "org": true, - "pp": true, - "pximg": true, - "pythonanywhere": true, - "ru": true, - "scaleway": true, - "sl": true, - "sl-reverse": true, - "spb": true, - "tilda": true, - "trafficmanager": true, - "tut": true, - "u-stream": true, - "ucoz": true, - "v": true, - "vercel": true, - "wix": true, - "wixmp": true - } -} + "includelist": [] +} \ No newline at end of file diff --git a/config/singbox.json b/config/singbox.json index 21b0e5d..fe2203e 100644 --- a/config/singbox.json +++ b/config/singbox.json @@ -41,5 +41,9 @@ "server": "10.10.0.13", "server_port": 4000 } - ] + ], + "route" : { + "rules": [], + "final": "direct" + } } \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 06e4764..459cc75 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,7 +15,7 @@ volumes: services: up: - image: mercurykd/vpnbot-up:1.1 + image: mercurykd/vpnbot-ng:1.1 build: context: dockerfile dockerfile: nginx.dockerfile