|
|
|
@@ -40,7 +40,7 @@ class Bot
|
|
|
|
|
$this->reg = '~' . implode('|', [
|
|
|
|
|
'GET / HTTP',
|
|
|
|
|
'GET /favicon.ico HTTP',
|
|
|
|
|
preg_quote($this->getHashBot())
|
|
|
|
|
preg_quote($this->getHashBot(1))
|
|
|
|
|
]) . '~';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -162,6 +162,9 @@ class Bot
|
|
|
|
|
case preg_match('~^/switchBanIp$~', $this->input['callback'], $m):
|
|
|
|
|
$this->switchBanIp();
|
|
|
|
|
break;
|
|
|
|
|
case preg_match('~^/switchMonthlyStats$~', $this->input['callback'], $m):
|
|
|
|
|
$this->switchMonthlyStats();
|
|
|
|
|
break;
|
|
|
|
|
case preg_match('~^/setIpLimit$~', $this->input['callback'], $m):
|
|
|
|
|
$this->setIpLimit();
|
|
|
|
|
break;
|
|
|
|
@@ -736,7 +739,7 @@ class Bot
|
|
|
|
|
"statsOutboundDownlink" => true
|
|
|
|
|
];
|
|
|
|
|
if (empty($norestart)) {
|
|
|
|
|
$c = $this->collectSession($c);
|
|
|
|
|
$this->collectSession();
|
|
|
|
|
file_put_contents('/config/xray.json', json_encode($c, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
|
|
|
|
$this->ssh('pkill xray', 'xr');
|
|
|
|
|
$this->ssh('xray run -config /xray.json > /dev/null 2>&1 &', 'xr');
|
|
|
|
@@ -745,24 +748,23 @@ class Bot
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function collectSession($c) {
|
|
|
|
|
$p = $this->getPacConf();
|
|
|
|
|
$p['vlessstat']['global'] = [
|
|
|
|
|
'download' => $p['vlessstat']['global']['download'] + $p['vlessstat']['session']['download'],
|
|
|
|
|
'upload' => $p['vlessstat']['global']['upload'] + $p['vlessstat']['session']['upload'],
|
|
|
|
|
public function collectSession() {
|
|
|
|
|
$p = $this->getXrayStats();
|
|
|
|
|
$p['global'] = [
|
|
|
|
|
'download' => $p['global']['download'] + $p['session']['download'],
|
|
|
|
|
'upload' => $p['global']['upload'] + $p['session']['upload'],
|
|
|
|
|
];
|
|
|
|
|
$p['vlessstat']['session'] = [
|
|
|
|
|
$p['session'] = [
|
|
|
|
|
'download' => 0,
|
|
|
|
|
'upload' => 0,
|
|
|
|
|
];
|
|
|
|
|
$this->setPacConf($p);
|
|
|
|
|
foreach ($c['inbounds'][0]['settings']['clients'] as $k => $v) {
|
|
|
|
|
$c['inbounds'][0]['settings']['clients'][$k]['global']['download'] += $v['session']['download'];
|
|
|
|
|
$c['inbounds'][0]['settings']['clients'][$k]['session']['download'] = 0;
|
|
|
|
|
$c['inbounds'][0]['settings']['clients'][$k]['global']['upload'] += $v['session']['upload'];
|
|
|
|
|
$c['inbounds'][0]['settings']['clients'][$k]['session']['upload'] = 0;
|
|
|
|
|
foreach ($p['users'] as $k => $v) {
|
|
|
|
|
$p['users'][$k]['global']['download'] += $v['session']['download'];
|
|
|
|
|
$p['users'][$k]['session']['download'] = 0;
|
|
|
|
|
$p['users'][$k]['global']['upload'] += $v['session']['upload'];
|
|
|
|
|
$p['users'][$k]['session']['upload'] = 0;
|
|
|
|
|
}
|
|
|
|
|
return $c;
|
|
|
|
|
$this->setXrayStats($p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function linkMtproto()
|
|
|
|
@@ -994,7 +996,7 @@ class Bot
|
|
|
|
|
{
|
|
|
|
|
$r = $this->send(
|
|
|
|
|
$this->input['chat'],
|
|
|
|
|
"@{$this->input['username']} enter pass",
|
|
|
|
|
"@{$this->input['username']} enter password",
|
|
|
|
|
$this->input['message_id'],
|
|
|
|
|
reply: 'enter password',
|
|
|
|
|
);
|
|
|
|
@@ -1012,7 +1014,7 @@ class Bot
|
|
|
|
|
$this->input['chat'],
|
|
|
|
|
"@{$this->input['username']} enter name",
|
|
|
|
|
$this->input['message_id'],
|
|
|
|
|
reply: 'enter password',
|
|
|
|
|
reply: 'enter name',
|
|
|
|
|
);
|
|
|
|
|
$_SESSION['reply'][$r['result']['message_id']] = [
|
|
|
|
|
'start_message' => $this->input['message_id'],
|
|
|
|
@@ -1189,8 +1191,7 @@ class Bot
|
|
|
|
|
$this->ssh('ssserver -v -d -c /config.json', 'ss');
|
|
|
|
|
$this->ssh('sslocal -v -d -c /config.json', 'proxy');
|
|
|
|
|
|
|
|
|
|
$this->sd($c, 1);
|
|
|
|
|
if (!empty($nomenu)) {
|
|
|
|
|
if (empty($nomenu)) {
|
|
|
|
|
$this->menu('ss');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -1339,6 +1340,7 @@ class Bot
|
|
|
|
|
$this->checkVersion();
|
|
|
|
|
$this->checkBackup($period);
|
|
|
|
|
$this->checkLogs($period);
|
|
|
|
|
$this->checkResetXrayStats($period);
|
|
|
|
|
$this->checkCert();
|
|
|
|
|
$this->autoAnalyzeLogs();
|
|
|
|
|
$this->xrayStatsUser();
|
|
|
|
@@ -1350,23 +1352,32 @@ class Bot
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$x = $this->getXray();
|
|
|
|
|
$p = $this->getPacConf();
|
|
|
|
|
$td = json_decode($this->ssh('xray api stats --server=127.0.0.1:8080 -name "inbound>>>vless_tls>>>traffic>>>downlink" 2>&1', 'xr'), true)['stat']['value'] ?: 0;
|
|
|
|
|
$tu = json_decode($this->ssh('xray api stats --server=127.0.0.1:8080 -name "inbound>>>vless_tls>>>traffic>>>uplink" 2>&1', 'xr'), true)['stat']['value'] ?: 0;
|
|
|
|
|
$p['vlessstat']['session']['download'] = $td;
|
|
|
|
|
$p['vlessstat']['session']['upload'] = $tu;
|
|
|
|
|
$this->setPacConf($p);
|
|
|
|
|
$p = $this->getXrayStats();
|
|
|
|
|
$p['session'] = [
|
|
|
|
|
'download' => $td,
|
|
|
|
|
'upload' => $tu,
|
|
|
|
|
];
|
|
|
|
|
if (!empty($users = $x['inbounds'][0]['settings']['clients'])) {
|
|
|
|
|
$tmp = [];
|
|
|
|
|
foreach ($users as $k => $v) {
|
|
|
|
|
$d = json_decode($this->ssh('xray api stats --server=127.0.0.1:8080 -name "user>>>' . $v['email'] . '>>>traffic>>>downlink" 2>&1', 'xr'), true)['stat']['value'] ?: 0;
|
|
|
|
|
$u = json_decode($this->ssh('xray api stats --server=127.0.0.1:8080 -name "user>>>' . $v['email'] . '>>>traffic>>>uplink" 2>&1', 'xr'), true)['stat']['value'] ?: 0;
|
|
|
|
|
$x['inbounds'][0]['settings']['clients'][$k]['session'] = [
|
|
|
|
|
'download' => $d,
|
|
|
|
|
'upload' => $u,
|
|
|
|
|
$tmp[$k] = [
|
|
|
|
|
'session' => [
|
|
|
|
|
'download' => $d,
|
|
|
|
|
'upload' => $u,
|
|
|
|
|
],
|
|
|
|
|
'global' => [
|
|
|
|
|
'download' => $p['users'][$k]['global']['download'],
|
|
|
|
|
'upload' => $p['users'][$k]['global']['upload'],
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$this->restartXray($x, norestart: 1);
|
|
|
|
|
$p['users'] = $tmp;
|
|
|
|
|
}
|
|
|
|
|
$this->setXrayStats($p);
|
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -1437,6 +1448,29 @@ class Bot
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function checkResetXrayStats($delta)
|
|
|
|
|
{
|
|
|
|
|
$pac = $this->getPacConf();
|
|
|
|
|
if (!empty($pac['reset_monthly'])) {
|
|
|
|
|
$now = strtotime(date('Y-m-d H:i:s'));
|
|
|
|
|
$start = strtotime('first day of previous month midnight');
|
|
|
|
|
$period = strtotime('1 month', 0);
|
|
|
|
|
if (
|
|
|
|
|
!empty($start)
|
|
|
|
|
&& !empty($period)
|
|
|
|
|
&& empty($this->backup)
|
|
|
|
|
&& $now - $start >= 0
|
|
|
|
|
&& (($now - $start) % $period < $delta)
|
|
|
|
|
) {
|
|
|
|
|
$this->resetXrStats(1);
|
|
|
|
|
require __DIR__ . '/config.php';
|
|
|
|
|
foreach ($c['admin'] as $admin) {
|
|
|
|
|
$this->send($admin, "vless: reset stats");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function checkLogs($delta)
|
|
|
|
|
{
|
|
|
|
|
$c = $this->getPacConf();
|
|
|
|
@@ -1669,7 +1703,7 @@ class Bot
|
|
|
|
|
'ocu' => file_get_contents('/config/ocserv.passwd'),
|
|
|
|
|
'ss' => $this->getSSConfig(),
|
|
|
|
|
'sl' => $this->getSSLocalConfig(),
|
|
|
|
|
|
|
|
|
|
'xraystats' => $this->getXrayStats(),
|
|
|
|
|
];
|
|
|
|
|
return json_encode($conf, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
|
|
|
}
|
|
|
|
@@ -1782,6 +1816,12 @@ class Bot
|
|
|
|
|
$this->adguardXrayClients();
|
|
|
|
|
$this->setUpstreamDomain($json['pac']['transport'] != 'Reality' ? 't' : ($json['pac']['reality']['domain'] ?: $json['xray']['inbounds'][0]['streamSettings']['realitySettings']['serverNames'][0]));
|
|
|
|
|
}
|
|
|
|
|
// xraystats
|
|
|
|
|
if (!empty($json['xraystats'])) {
|
|
|
|
|
$out[] = 'update xray stats';
|
|
|
|
|
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
|
|
|
|
|
$this->setXrayStats($json['xraystats']);
|
|
|
|
|
}
|
|
|
|
|
// ocserv
|
|
|
|
|
if (!empty($json['oc'])) {
|
|
|
|
|
$out[] = 'update ocserv';
|
|
|
|
@@ -2421,9 +2461,9 @@ class Bot
|
|
|
|
|
{
|
|
|
|
|
$r = $this->send(
|
|
|
|
|
$this->input['chat'],
|
|
|
|
|
"@{$this->input['username']} enter seconds",
|
|
|
|
|
"@{$this->input['username']} enter seconds and count ip",
|
|
|
|
|
$this->input['message_id'],
|
|
|
|
|
reply: 'enter seconds',
|
|
|
|
|
reply: 'enter seconds:count_ip',
|
|
|
|
|
);
|
|
|
|
|
$_SESSION['reply'][$r['result']['message_id']] = [
|
|
|
|
|
'start_message' => $this->input['message_id'],
|
|
|
|
@@ -4263,6 +4303,43 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
$this->menu('wg', 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function alignColumns(array $columns): string
|
|
|
|
|
{
|
|
|
|
|
// Находим максимальную длину для каждого столбца
|
|
|
|
|
$columnLengths = [];
|
|
|
|
|
foreach ($columns as $column) {
|
|
|
|
|
$maxLength = 0;
|
|
|
|
|
foreach ($column as $cell) {
|
|
|
|
|
$len = mb_strlen($cell, 'UTF-8');
|
|
|
|
|
$maxLength = max($maxLength, $len);
|
|
|
|
|
}
|
|
|
|
|
$columnLengths[] = $maxLength;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Получаем количество строк из первого столбца
|
|
|
|
|
$rowCount = count($columns[0]);
|
|
|
|
|
$columnCount = count($columns);
|
|
|
|
|
|
|
|
|
|
// Формируем строки с выравниванием
|
|
|
|
|
$result = [];
|
|
|
|
|
for ($row = 0; $row < $rowCount; $row++) {
|
|
|
|
|
$line = '';
|
|
|
|
|
for ($col = 0; $col < $columnCount; $col++) {
|
|
|
|
|
$cell = $columns[$col][$row];
|
|
|
|
|
$padding = str_repeat(' ', $columnLengths[$col] - mb_strlen($cell, 'UTF-8'));
|
|
|
|
|
$line .= $cell . $padding;
|
|
|
|
|
|
|
|
|
|
// Добавляем разделитель между столбцами, кроме последнего
|
|
|
|
|
if ($col < $columnCount - 1) {
|
|
|
|
|
$line .= ' '; // Два пробела между столбцами
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$result[] = $line;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return implode("\n", $result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function menu($type = false, $arg = false, $return = false)
|
|
|
|
|
{
|
|
|
|
|
$conf = $this->getPacConf();
|
|
|
|
@@ -4283,26 +4360,70 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
$f = '/docker/compose';
|
|
|
|
|
$c = yaml_parse_file($f)['services'];
|
|
|
|
|
$main[] = 'v' . getenv('VER') . " $branch" . ($update ? ' (have updates)' : '');
|
|
|
|
|
$main[] = '';
|
|
|
|
|
$main[] = $cron;
|
|
|
|
|
$main[] = $this->i18n($backup ? 'on' : 'off') . ' autobackup' . ($backup ? " $backup" : '');
|
|
|
|
|
$main[] = $this->i18n($conf['autoupdate'] ? 'on' : 'off') . ' autoupdate';
|
|
|
|
|
$main[] = $this->i18n($conf['autoscan'] ? 'on' : 'off') . ' autoscan';
|
|
|
|
|
$main[] = $this->i18n($conf['autodeny'] ? 'on' : 'off') . ' autoblock' . ($conf['deny'] ? ': ' . count($conf['deny']) : '');
|
|
|
|
|
$main[] = '';
|
|
|
|
|
$main[] = $this->i18n($c['wg'] ? 'on' : 'off') . ' ' . getenv('WGPORT') . ' Wireguard';
|
|
|
|
|
$main[] = $this->i18n($c['wg1'] ? 'on' : 'off') . ' ' . getenv('WG1PORT') . ' Wireguard 1';
|
|
|
|
|
$main[] = $this->i18n($c['tg'] ? 'on' : 'off') . ' ' . getenv('TGPORT') . ' MTProto';
|
|
|
|
|
$main[] = $this->i18n($c['ad'] ? 'on' : 'off') . ' 853 AdguardHome DoT';
|
|
|
|
|
$main[] = $this->i18n($c['ss'] ? 'on' : 'off') . ' 8388 Shadowsocks';
|
|
|
|
|
|
|
|
|
|
if (!empty($conf['domain'])) {
|
|
|
|
|
$main[] = '';
|
|
|
|
|
$oc = $this->getHashSubdomain('oc');
|
|
|
|
|
$np = $this->getHashSubdomain('np');
|
|
|
|
|
$main[] = $conf['domain'] ? "Domains:\n{$conf['domain']}\n$np.{$conf['domain']} (for naiveproxy)\n$oc.{$conf['domain']} (for openconnect)" . ($conf['adguardkey'] ? "\n{$conf['adguardkey']}.{$conf['domain']} (for adguard DoT)" : '') : $this->i18n('domain explain');
|
|
|
|
|
$ssl = $this->expireCert();
|
|
|
|
|
$main[] = $conf['domain'] ? "\nSSL: " . ($ssl ? date('Y-m-d H:i:s', $this->expireCert()) . "\n" . $this->domainsCert() : 'none') : '';
|
|
|
|
|
if (!empty($conf['domain'])) {
|
|
|
|
|
$ssl_expiry = $this->expireCert();
|
|
|
|
|
$certs = $this->domainsCert() ?: [];
|
|
|
|
|
|
|
|
|
|
$main[] = "<blockquote>";
|
|
|
|
|
$main[] = "Domains:";
|
|
|
|
|
$main[] = $conf['domain'] . (in_array($conf['domain'], $certs) ? ' (ssl: ' . date('Y-m-d H:i:s', $ssl_expiry) . ')' : '');
|
|
|
|
|
$main[] = 'naive ' . "$np.{$conf['domain']}" . (in_array("$np.{$conf['domain']}", $certs) ? ' (ssl: ' . date('Y-m-d H:i:s', $ssl_expiry) . ')' : '');
|
|
|
|
|
$main[] = 'openconnect ' . "$oc.{$conf['domain']}" . (in_array("$oc.{$conf['domain']}", $certs) ? ' (ssl: ' . date('Y-m-d H:i:s', $ssl_expiry) . ')' : '');
|
|
|
|
|
if (!empty($conf['adguardkey'])) {
|
|
|
|
|
$main[] = "{$conf['adguardkey']}.{$conf['domain']}" . (in_array("{$conf['adguardkey']}.{$conf['domain']}", $certs) ? ' (ssl: ' . date('Y-m-d H:i:s', $ssl_expiry) . ')' : '') . ' adguard DOT';;
|
|
|
|
|
}
|
|
|
|
|
$main[] = "</blockquote>";
|
|
|
|
|
} else {
|
|
|
|
|
$main[] = $this->i18n('domain explain');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$main[] = '';
|
|
|
|
|
|
|
|
|
|
$main[] = '<code>';
|
|
|
|
|
$main[] = $this->alignColumns([
|
|
|
|
|
[
|
|
|
|
|
$this->i18n($this->ssh($this->getPacConf()['amnezia'] ? 'awg' : 'wg', 'wg') ? 'on' : 'off') . ' ' . $this->i18n($this->getPacConf()['amnezia'] ? 'amnezia' : 'wg_title'),
|
|
|
|
|
$this->i18n($this->ssh($this->getPacConf()['wg1_amnezia'] ? 'awg' : 'wg', 'wg1') ? 'on' : 'off') . ' ' . $this->i18n($this->getPacConf()['wg1_amnezia'] ? 'amnezia' : 'wg_title'),
|
|
|
|
|
$this->i18n($this->ssh('pgrep xray', 'xr') ? 'on' : 'off') . ' ' . $this->i18n('xray'),
|
|
|
|
|
$this->i18n($this->ssh('pgrep caddy', 'np') ? 'on' : 'off') . ' ' . $this->i18n('naive'),
|
|
|
|
|
$this->i18n($this->ssh('pgrep ocserv', 'oc') ? 'on' : 'off') . ' ' . $this->i18n('ocserv'),
|
|
|
|
|
$this->i18n($this->ssh('pgrep mtproto-proxy', 'tg') ? 'on' : 'off') . ' ' . $this->i18n('mtproto'),
|
|
|
|
|
$this->i18n(exec("JSON=1 timeout 2 dnslookup google.com ad") ? 'on' : 'off') . ' ' . $this->i18n('ad_title'),
|
|
|
|
|
$this->i18n($this->ssh('pgrep ssserver', 'ss') ? 'on' : 'off') . ' ' . $this->i18n('sh_title'),
|
|
|
|
|
$this->i18n($this->warpStatus()) . ' ' . $this->i18n('warp'),
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
$this->i18n($c['wg'] ? 'on' : 'off') . ' ' . getenv('WGPORT'),
|
|
|
|
|
$this->i18n($c['wg1'] ? 'on' : 'off') . ' ' . getenv('WG1PORT'),
|
|
|
|
|
$this->i18n('on') . ' 443',
|
|
|
|
|
$this->i18n('on') . ' 443',
|
|
|
|
|
$this->i18n('on') . ' 443',
|
|
|
|
|
$this->i18n($c['tg'] ? 'on' : 'off') . ' ' . getenv('TGPORT'),
|
|
|
|
|
$this->i18n($c['ad'] ? 'on' : 'off') . ' 853',
|
|
|
|
|
$this->i18n($c['ss'] ? 'on' : 'off') . ' ' . getenv('SSPORT'),
|
|
|
|
|
'',
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
$main[] = '';
|
|
|
|
|
$main[] = $this->alignColumns([
|
|
|
|
|
[
|
|
|
|
|
$this->i18n($backup ? 'on' : 'off') . ' autobackup',
|
|
|
|
|
$this->i18n($conf['autoupdate'] ? 'on' : 'off') . ' autoupdate',
|
|
|
|
|
$this->i18n($conf['autoscan'] ? 'on' : 'off') . ' autoscan',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
$this->i18n($conf['autodeny'] ? 'on' : 'off') . ' autoblock' . ($conf['deny'] ? ': ' . count($conf['deny']) : ''),
|
|
|
|
|
$this->i18n($conf['reset_monthly'] ? 'on' : 'off') . ' autoreset',
|
|
|
|
|
$cron,
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
$main[] = '</code>';
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
$menu = [
|
|
|
|
|
'main' => [
|
|
|
|
@@ -4344,7 +4465,7 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
'callback_data' => "/menu adguard",
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'text' => $this->i18n('warp') . ': ' . $this->warpStatus(),
|
|
|
|
|
'text' => $this->i18n('warp'),
|
|
|
|
|
'callback_data' => "/warp",
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
@@ -4446,13 +4567,24 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
$this->ipMenu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function switchIpLimit(int $limit)
|
|
|
|
|
public function switchMonthlyStats()
|
|
|
|
|
{
|
|
|
|
|
$c = $this->getPacConf();
|
|
|
|
|
if ($limit <= 0) {
|
|
|
|
|
$c['reset_monthly'] = $c['reset_monthly'] ? 0 : 1;
|
|
|
|
|
$this->setPacConf($c);
|
|
|
|
|
$this->xray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function switchIpLimit($limit)
|
|
|
|
|
{
|
|
|
|
|
$limit = explode(':', $limit);
|
|
|
|
|
$c = $this->getPacConf();
|
|
|
|
|
if ((int) $limit[0] <= 0) {
|
|
|
|
|
unset($c['ip_limit']);
|
|
|
|
|
unset($c['ip_count']);
|
|
|
|
|
} else {
|
|
|
|
|
$c['ip_limit'] = $limit;
|
|
|
|
|
$c['ip_limit'] = (int) $limit[0];
|
|
|
|
|
$c['ip_count'] = (int) $limit[1] ?: 1;
|
|
|
|
|
}
|
|
|
|
|
$this->setPacConf($c);
|
|
|
|
|
$this->xray();
|
|
|
|
@@ -5295,10 +5427,13 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
|
|
|
|
|
public function delxr($i)
|
|
|
|
|
{
|
|
|
|
|
$r = $this->getXray();
|
|
|
|
|
$r = $this->getXray();
|
|
|
|
|
$st = $this->getXrayStats();
|
|
|
|
|
foreach ($r['inbounds'][0]['settings']['clients'] as $k => $v) {
|
|
|
|
|
if ($i == $k) {
|
|
|
|
|
unset($r['inbounds'][0]['settings']['clients'][$k]);
|
|
|
|
|
unset($st['users'][$k]);
|
|
|
|
|
$this->setXrayStats($st);
|
|
|
|
|
$this->restartXray($r);
|
|
|
|
|
$this->adguardXrayClients();
|
|
|
|
|
break;
|
|
|
|
@@ -5326,8 +5461,16 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
$p = $this->getPacConf();
|
|
|
|
|
$users = array_map(fn ($e) => trim($e), explode(',', $users));
|
|
|
|
|
$users = array_map(fn ($e) => explode(':', $e), $users);
|
|
|
|
|
foreach ($c['inbounds'][0]['settings']['clients'] as $k => $v) {
|
|
|
|
|
$uuids[] = $v['id'];
|
|
|
|
|
$emails[] = $v['email'];
|
|
|
|
|
}
|
|
|
|
|
foreach ($users as $user) {
|
|
|
|
|
$uuid = $user[1] ?: trim($this->ssh('xray uuid', 'xr'));
|
|
|
|
|
if (in_array($uuid, $uuids ?: []) || in_array($user[0], $emails ?: [])) {
|
|
|
|
|
$this->send($this->input['chat'], "user {$user[0]} already exists");
|
|
|
|
|
return $this->xray();
|
|
|
|
|
}
|
|
|
|
|
$c['inbounds'][0]['settings']['clients'][] = $p['transport'] != 'Reality' ? [
|
|
|
|
|
'id' => $uuid,
|
|
|
|
|
'email' => $user[0],
|
|
|
|
@@ -5357,20 +5500,22 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
$this->send($this->input['chat'], 'wrong format');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!empty($c['inbounds'][0]['settings']['clients'][$i]['off'])) {
|
|
|
|
|
$this->switchXr($i, 1);
|
|
|
|
|
$c = $this->getXray();
|
|
|
|
|
}
|
|
|
|
|
$c['inbounds'][0]['settings']['clients'][$i]['time'] = $time;
|
|
|
|
|
}
|
|
|
|
|
file_put_contents('/config/xray.json', json_encode($c, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
|
|
|
|
$this->userXr($i);
|
|
|
|
|
$this->restartXray($c, 1);
|
|
|
|
|
if (!empty($c['inbounds'][0]['settings']['clients'][$i]['off'])) {
|
|
|
|
|
$this->switchXr($i, 0, 1);
|
|
|
|
|
} else {
|
|
|
|
|
$this->userXr($i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function switchXr($i, $nm = 0)
|
|
|
|
|
public function switchXr($i, $nm = 0, $time = false)
|
|
|
|
|
{
|
|
|
|
|
$c = $this->getXray();
|
|
|
|
|
unset($c['inbounds'][0]['settings']['clients'][$i]['time']);
|
|
|
|
|
if (empty($time)) {
|
|
|
|
|
unset($c['inbounds'][0]['settings']['clients'][$i]['time']);
|
|
|
|
|
}
|
|
|
|
|
if (empty($c['inbounds'][0]['settings']['clients'][$i]['off'])) {
|
|
|
|
|
$c['inbounds'][0]['settings']['clients'][$i]['off'] = $c['inbounds'][0]['settings']['clients'][$i]['id'];
|
|
|
|
|
$c['inbounds'][0]['settings']['clients'][$i]['id'] = trim($this->ssh('xray uuid', 'xr'));
|
|
|
|
@@ -5393,29 +5538,31 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
$this->userXr($i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getXrayStats()
|
|
|
|
|
{
|
|
|
|
|
return json_decode(file_get_contents('/config/xray.stats'), true) ?: [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setXrayStats($x)
|
|
|
|
|
{
|
|
|
|
|
file_put_contents('/config/xray.stats', json_encode($x));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function resetXrUser($i)
|
|
|
|
|
{
|
|
|
|
|
$c = $this->getXray();
|
|
|
|
|
$c['inbounds'][0]['settings']['clients'][$i]['global'] = [
|
|
|
|
|
'download' => 0,
|
|
|
|
|
'upload' => 0,
|
|
|
|
|
];
|
|
|
|
|
$this->restartXray($c);
|
|
|
|
|
$c = $this->getXrayStats();
|
|
|
|
|
unset($c['users'][$i]);
|
|
|
|
|
$this->restartXray($this->getXray());
|
|
|
|
|
$this->userXr($i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function resetXrStats()
|
|
|
|
|
public function resetXrStats($nomenu = false)
|
|
|
|
|
{
|
|
|
|
|
$x = $this->getXray();
|
|
|
|
|
$p = $this->getPacConf();
|
|
|
|
|
unset($p['vlessstat']);
|
|
|
|
|
foreach ($x['inbounds'][0]['settings']['clients'] as $k => $v) {
|
|
|
|
|
unset($x['inbounds'][0]['settings']['clients'][$k]['global']);
|
|
|
|
|
unset($x['inbounds'][0]['settings']['clients'][$k]['session']);
|
|
|
|
|
$this->restartXray($this->getXray());
|
|
|
|
|
$this->setXrayStats([]);
|
|
|
|
|
if (empty($nomenu)) {
|
|
|
|
|
$this->xray();
|
|
|
|
|
}
|
|
|
|
|
$this->restartXray($x);
|
|
|
|
|
$this->setPacConf($p);
|
|
|
|
|
$this->xray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function listXr($i)
|
|
|
|
@@ -5588,6 +5735,7 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
<code>~block~</code>
|
|
|
|
|
<code>~warp~</code>
|
|
|
|
|
<code>~dns~</code>
|
|
|
|
|
<code>~dnspath~</code>
|
|
|
|
|
<code>~uid~</code>
|
|
|
|
|
<code>~domain~</code>
|
|
|
|
|
<code>~directdomain~</code>
|
|
|
|
@@ -5718,13 +5866,18 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
$text[] = "fake domain: <code>$fake</code>";
|
|
|
|
|
}
|
|
|
|
|
$text[] = 'transport: ' . ($p['transport'] ?: 'Websocket');
|
|
|
|
|
$td = $this->getBytes($p['vlessstat']['global']['download'] + $p['vlessstat']['session']['download']);
|
|
|
|
|
$tu = $this->getBytes($p['vlessstat']['global']['upload'] + $p['vlessstat']['session']['upload']);
|
|
|
|
|
$st = $this->getXrayStats();
|
|
|
|
|
$td = $this->getBytes($st['global']['download'] + $st['session']['download']);
|
|
|
|
|
$tu = $this->getBytes($st['global']['upload'] + $st['session']['upload']);
|
|
|
|
|
$data[] = [
|
|
|
|
|
[
|
|
|
|
|
'text' => $this->i18n('reset stats') . ": ↓$td ↑$tu",
|
|
|
|
|
'callback_data' => '/resetXrStats',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'text' => $this->i18n('reset monthly') . ": " . $this->i18n($this->getPacConf()['reset_monthly'] ? 'on' : 'off'),
|
|
|
|
|
'callback_data' => '/switchMonthlyStats',
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
$data[] = [
|
|
|
|
|
[
|
|
|
|
@@ -5747,8 +5900,11 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
'text' => $this->i18n('Websocket') . ' ' . ($p['transport'] != 'Reality' ? $this->i18n('on') : $this->i18n('off')),
|
|
|
|
|
'callback_data' => "/changeTransport 1",
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
$ip_count = $p['ip_count'] ?: 1;
|
|
|
|
|
$data[] = [
|
|
|
|
|
[
|
|
|
|
|
'text' => $this->i18n('ip limit') . ' ' . ($p['ip_limit'] ? ": {$p['ip_limit']} sec" : $this->i18n('off')),
|
|
|
|
|
'text' => $this->i18n('ip limit') . ' ' . ($p['ip_limit'] ? ": {$p['ip_limit']} sec & $ip_count" : $this->i18n('off')),
|
|
|
|
|
'callback_data' => "/setIpLimit",
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
@@ -5800,8 +5956,8 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
$page = $page == -2 ? $all - 1 : $page;
|
|
|
|
|
$clients = $page != -1 ? array_slice($clients, $page * $this->limit, $this->limit, true) : $clients;
|
|
|
|
|
foreach ($clients as $k => $v) {
|
|
|
|
|
$download = $this->getBytes($v['global']['download'] + $v['session']['download']);
|
|
|
|
|
$upload = $this->getBytes($v['global']['upload'] + $v['session']['upload']);
|
|
|
|
|
$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']);
|
|
|
|
|
$time = $v['time'] ? $this->getTime($v['time']) : '';
|
|
|
|
|
$data[] = [
|
|
|
|
|
[
|
|
|
|
@@ -5974,7 +6130,6 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
|
|
|
|
|
public function frequencyAnalyze($line, $pac)
|
|
|
|
|
{
|
|
|
|
|
preg_match('~(?<date>.+)\sfrom\s(?<ip>\d+\.\d+\.\d+\.\d+)(?=.+email:\s(?<email>.+))~', $line, $m);
|
|
|
|
|
if (!empty($this->pool)) {
|
|
|
|
|
foreach ($this->pool as $i => $j) {
|
|
|
|
|
if (!empty($j['ips'])) {
|
|
|
|
@@ -5986,29 +6141,33 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (empty(preg_match('~(?<date>.+)\sfrom\s(?<ip>\d+\.\d+\.\d+\.\d+)(?=.+email:\s(?<email>.+))~', $line, $m))) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!empty($m['ip']) && !empty($m['email'])) {
|
|
|
|
|
$ip = ip2long($m['ip']);
|
|
|
|
|
if (!empty($this->pool[$m['email']]['ip']) && $this->pool[$m['email']]['ip'] != $ip) {
|
|
|
|
|
$this->pool[$m['email']]['ips'][$ip] = time();
|
|
|
|
|
}
|
|
|
|
|
if (!empty($this->pool[$m['email']]['ips']) && count($this->pool[$m['email']]['ips']) > 1) {
|
|
|
|
|
if (!empty($this->pool[$m['email']]['ips']) && count($this->pool[$m['email']]['ips']) > ($pac['ip_count'] ?: 1)) {
|
|
|
|
|
$xr = $this->getXray();
|
|
|
|
|
foreach ($xr['inbounds'][0]['settings']['clients'] as $k => $v) {
|
|
|
|
|
if (empty($v['off']) && $v['email'] == $m['email']) {
|
|
|
|
|
require __DIR__ . '/config.php';
|
|
|
|
|
foreach ($c['admin'] as $k => $v) {
|
|
|
|
|
$this->send($v, "vless: {$m['email']} is turned off (limit by one IP)");
|
|
|
|
|
foreach ($c['admin'] as $admin) {
|
|
|
|
|
$this->send($admin, "vless: {$m['email']} limit ip " . count($this->pool[$m['email']]['ips']) . ' > ' . ($pac['ip_count'] ?: 1), button: [[
|
|
|
|
|
[
|
|
|
|
|
'text' => $this->i18n($c['off'] ? 'off' : 'on'),
|
|
|
|
|
'callback_data' => "/switchXr $k",
|
|
|
|
|
],
|
|
|
|
|
]]);
|
|
|
|
|
}
|
|
|
|
|
unset($this->pool[$m['email']]);
|
|
|
|
|
$this->switchXr($k, 1);
|
|
|
|
|
$flag = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (empty($flag)) {
|
|
|
|
|
$this->pool[$m['email']]['ip'] = $ip;
|
|
|
|
|
}
|
|
|
|
|
$this->pool[$m['email']]['ip'] = $ip;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -6166,10 +6325,11 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
$text[] = "sing-box config: <pre><code>$si</code></pre>";
|
|
|
|
|
$text[] = "mihomo config: <pre><code>$cl</code></pre>";
|
|
|
|
|
|
|
|
|
|
$text[] = "sing-box windows: <a href='$scheme://{$domain}/pac$hash?t=si&r=w&s={$c['id']}'>windows service</a>";
|
|
|
|
|
$download = $this->getBytes($c['global']['download'] + $c['session']['download']);
|
|
|
|
|
$upload = $this->getBytes($c['global']['upload'] + $c['session']['upload']);
|
|
|
|
|
$data[] = [
|
|
|
|
|
$text[] = "sing-box windows: <a href='$scheme://{$domain}/pac$hash?t=si&r=w&s={$c['id']}'>windows service</a>";
|
|
|
|
|
$st = $this->getXrayStats();
|
|
|
|
|
$download = $this->getBytes($st['users'][$i]['global']['download'] + $st['users'][$i]['session']['download']);
|
|
|
|
|
$upload = $this->getBytes($st['users'][$i]['global']['upload'] + $st['users'][$i]['session']['upload']);
|
|
|
|
|
$data[] = [
|
|
|
|
|
[
|
|
|
|
|
'text' => $this->i18n('reset stats') . ": ↓$download ↑$upload",
|
|
|
|
|
'callback_data' => "/resetXrUser $i",
|
|
|
|
@@ -6332,7 +6492,7 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
header("Location: hiddify://install-config/?url=$si");
|
|
|
|
|
exit;
|
|
|
|
|
case 'c':
|
|
|
|
|
header("Location: clash://install-config/?url=$cl&name=$email");
|
|
|
|
|
header("Location: clash://install-config/?url=$cl&overwrite=no&name=$email");
|
|
|
|
|
exit;
|
|
|
|
|
case 'w':
|
|
|
|
|
$link = htmlspecialchars($si, ENT_XML1, 'UTF-8');
|
|
|
|
@@ -6472,6 +6632,7 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
'"~package~"' => json_encode(array_keys(array_filter($pac['packagelist'] ?: []))),
|
|
|
|
|
'"~subnet~"' => json_encode(array_keys(array_filter($pac['subnetlist'] ?: []))),
|
|
|
|
|
'~dns~' => "https://$domain/dns-query$hash/$uid",
|
|
|
|
|
'~dnspath~' => "/dns-query$hash/$uid",
|
|
|
|
|
'~uid~' => $uid,
|
|
|
|
|
'~domain~' => $domain,
|
|
|
|
|
'~directdomain~' => $pac['domain'],
|
|
|
|
@@ -6629,7 +6790,7 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
if (!empty($route['rules'])) {
|
|
|
|
|
foreach ($route['rules'] as $k => $v) {
|
|
|
|
|
if (!empty($v['addruleset'])) {
|
|
|
|
|
$t[$v['outbound']] = $k;
|
|
|
|
|
$t[$v['outbound'] ?: 'block'] = $k;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$p = $this->getPacConf();
|
|
|
|
@@ -6778,14 +6939,16 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
$this->ssh("nginx -s reload 2>&1", 'up');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getHashBot()
|
|
|
|
|
public function getHashBot($notset = false)
|
|
|
|
|
{
|
|
|
|
|
$p = $this->getPacConf();
|
|
|
|
|
if (!empty($p['hashbot'])) {
|
|
|
|
|
return $p['hashbot'];
|
|
|
|
|
}
|
|
|
|
|
$p['hashbot'] = substr(hash('sha256', $this->key), 0, 8);
|
|
|
|
|
$this->setPacConf($p);
|
|
|
|
|
if (empty($notset)) {
|
|
|
|
|
$this->setPacConf($p);
|
|
|
|
|
}
|
|
|
|
|
return $p['hashbot'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -6830,7 +6993,13 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
|
|
|
|
|
public function getHashSubdomain($subdomain)
|
|
|
|
|
{
|
|
|
|
|
return $this->getPacConf()["{$subdomain}_domain"] ?: substr(hash('sha256', "$subdomain{$this->key}"), 0, 8);
|
|
|
|
|
$p = $this->getPacConf();
|
|
|
|
|
if (!empty($p["{$subdomain}_domain"])) {
|
|
|
|
|
return $p["{$subdomain}_domain"];
|
|
|
|
|
}
|
|
|
|
|
$p["{$subdomain}_domain"] = substr(hash('sha256', "$subdomain{$this->key}"), 0, 8);
|
|
|
|
|
$this->setPacConf($p);
|
|
|
|
|
return $p["{$subdomain}_domain"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addWg($page)
|
|
|
|
@@ -7049,7 +7218,7 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
if (empty($domains)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return implode("\n", array_map(fn($e) => trim($e), explode(',', str_replace('DNS:', '', $domains))));
|
|
|
|
|
return array_map(fn($e) => trim($e), explode(',', str_replace('DNS:', '', $domains)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updatebot()
|
|
|
|
@@ -7119,17 +7288,24 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
public function configMenu()
|
|
|
|
|
{
|
|
|
|
|
$conf = $this->getPacConf();
|
|
|
|
|
if (!empty($conf['subdomain'])) {
|
|
|
|
|
$custom = "\ncustom:\n";
|
|
|
|
|
foreach ($conf['subdomain'] as $v) {
|
|
|
|
|
$custom .= "$v\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$oc = $this->getHashSubdomain('oc');
|
|
|
|
|
$np = $this->getHashSubdomain('np');
|
|
|
|
|
$text[] = $conf['domain'] ? "Domains:\n{$conf['domain']}\n$np.{$conf['domain']} (for naiveproxy)\n$oc.{$conf['domain']} (for openconnect)" . ($conf['adguardkey'] ? "\n{$conf['adguardkey']}.{$conf['domain']} (for adguard DoT)" : '') : $this->i18n('domain explain');
|
|
|
|
|
$ssl = $this->expireCert();
|
|
|
|
|
$text[] = $conf['domain'] ? "\nSSL: " . ($ssl ? date('Y-m-d H:i:s', $this->expireCert()) . "\n" . $this->domainsCert() : 'none') : '';
|
|
|
|
|
if (!empty($conf['domain'])) {
|
|
|
|
|
$ssl_expiry = $this->expireCert();
|
|
|
|
|
$certs = $this->domainsCert() ?: [];
|
|
|
|
|
|
|
|
|
|
$text[] = "<blockquote>";
|
|
|
|
|
$text[] = "Domains:";
|
|
|
|
|
$text[] = $conf['domain'] . (in_array($conf['domain'], $certs) ? ' (ssl: ' . date('Y-m-d H:i:s', $ssl_expiry) . ')' : '');
|
|
|
|
|
$text[] = 'naive ' . "$np.{$conf['domain']}" . (in_array("$np.{$conf['domain']}", $certs) ? ' (ssl: ' . date('Y-m-d H:i:s', $ssl_expiry) . ')' : '');
|
|
|
|
|
$text[] = 'openconnect ' . "$oc.{$conf['domain']}" . (in_array("$oc.{$conf['domain']}", $certs) ? ' (ssl: ' . date('Y-m-d H:i:s', $ssl_expiry) . ')' : '');
|
|
|
|
|
if (!empty($conf['adguardkey'])) {
|
|
|
|
|
$text[] = "{$conf['adguardkey']}.{$conf['domain']}" . (in_array("{$conf['adguardkey']}.{$conf['domain']}", $certs) ? ' (ssl: ' . date('Y-m-d H:i:s', $ssl_expiry) . ')' : '') . ' adguard DOT';;
|
|
|
|
|
}
|
|
|
|
|
$text[] = "</blockquote>";
|
|
|
|
|
} else {
|
|
|
|
|
$text[] = $this->i18n('domain explain');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
|
[
|
|
|
|
@@ -8050,8 +8226,9 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
}
|
|
|
|
|
echo "$ip\n";
|
|
|
|
|
var_dump($r = $this->request('setWebhook', [
|
|
|
|
|
'url' => "https://$ip/tlgrm?k={$this->key}",
|
|
|
|
|
'certificate' => curl_file_create('/certs/self_public'),
|
|
|
|
|
'url' => "https://$ip/tlgrm?k={$this->key}",
|
|
|
|
|
'certificate' => curl_file_create('/certs/self_public'),
|
|
|
|
|
'allowed_updates' => json_encode(['*']),
|
|
|
|
|
]));
|
|
|
|
|
if (!empty($r['result']) && $r['result'] == true) {
|
|
|
|
|
file_put_contents('/start', 1);
|
|
|
|
|