Compare commits

..

32 Commits

Author SHA1 Message Date
mercury 99bce7a988 update version 2024-12-09 14:30:26 +04:00
mercury 446a5d7150 mihomo: rule-providers add format 2024-12-09 13:32:25 +04:00
mercury 855f516936 update version 2024-12-06 23:39:12 +04:00
mercury e1c13480d1 mihomo: fix empty rules 2024-12-06 23:36:43 +04:00
mercury bd5e10fa23 naming: clash -> mihomo 2024-12-06 23:12:22 +04:00
mercury 3627b389b4 mihomo: added yaml support 2024-12-06 22:26:00 +04:00
mercury f3f9cb5348 fix ruleset for mihomo 2024-12-06 22:11:12 +04:00
mercury 1527b9f856 added rule-set for clash 2024-12-04 00:08:32 +04:00
mercury f896b307ea removed check when adding a subnet to openconnect 2024-11-28 20:11:05 +04:00
mercury 8ba7ddedee update version 2024-11-28 20:04:53 +04:00
mercury 19ef567873 fix createruleset 2024-11-28 19:51:21 +04:00
mercury 4f4e36e1cb doh ip exclude for analyze ip 2024-11-28 15:17:42 +04:00
mercury 6267931475 fix bug createruleset for singbox 2024-11-28 12:59:06 +04:00
mercury 7e2d90e7da update prioritet clash rules 2024-11-28 10:36:10 +04:00
mercury 28906176f5 update clash links 2024-11-28 00:21:22 +04:00
mercury 968d72ce81 autoscan call fix 2024-11-28 00:12:12 +04:00
mercury 66e204e5ba import url for clash 2024-11-27 23:37:39 +04:00
mercury 36e8acd2aa xray: template for clash 2024-11-27 22:00:30 +04:00
mercury cdc20adccd consistent template logic 2024-11-27 16:52:30 +04:00
mercury 8ad00bc47a update version 2024-11-21 18:09:25 +04:00
mercury 4902eb53ce fix addruleset for direct 2024-11-21 16:04:09 +04:00
mercury 253cceb44c fix analyze ip autoban 2024-11-21 12:13:02 +04:00
mercury 9d53f2896c fix analyze memory 2024-11-21 11:49:29 +04:00
mercury 550a8ad3b7 fix ip/32 analyze 2024-11-21 01:37:22 +04:00
mercury e2f84b0ee7 update version 2024-11-21 00:39:07 +04:00
mercury b394e769c6 роутинг для openconnect 2024-11-21 00:24:50 +04:00
mercury 7d8dc1dd2d duplicating the list of subnets for openconnect 2024-11-20 20:59:25 +04:00
mercury 34b1de5132 import telegram, gcore, cloudflare ip 2024-11-20 20:58:17 +04:00
mercury 12b5d84afc IP analyzer takes into account subnets 2024-11-20 17:12:08 +04:00
mercury c3d90ada83 addruleset and additional tags 2024-11-20 15:55:10 +04:00
mercury dbe3f290ea commands reset and backup 2024-11-20 15:46:03 +04:00
mercury b56b48e080 override ignore 2024-11-20 15:45:02 +04:00
10 changed files with 659 additions and 205 deletions
+4 -1
View File
@@ -22,4 +22,7 @@ update/*
override.env
override.html
override.php
docker-compose.override.yml
docker-compose.override.yml
backup.json
app/webapp/override/
.rest
+13
View File
@@ -0,0 +1,13 @@
<?php
require __DIR__ . '/timezone.php';
require __DIR__ . '/bot.php';
require __DIR__ . '/config.php';
require __DIR__ . '/i18n.php';
if ($c['debug']) {
require __DIR__ . '/debug.php';
}
$bot = new Bot($c['key'], $i);
echo $bot->export();
+463 -188
View File
@@ -37,7 +37,7 @@ class Bot
'xray',
];
$this->reg = '~' . implode('|', [
'GET /ws(?:.+)? HTTP',
'GET /ws HTTP',
'GET /adguard/(?:.+)? HTTP',
'GET /webapp(?:.+)? HTTP',
'GET /pac(?:.+)? HTTP',
@@ -163,6 +163,12 @@ class Bot
case preg_match('~^/mirror$~', $this->input['message'], $m):
$this->menu('mirror');
break;
case preg_match('~^/mainOutbound$~', $this->input['callback'], $m):
$this->mainOutbound();
break;
case preg_match('~^/importIps (.+)$~', $this->input['callback'], $m):
$this->importIps($m[1]);
break;
case preg_match('~^/switchBanIp$~', $this->input['callback'], $m):
$this->switchBanIp();
break;
@@ -202,7 +208,7 @@ class Bot
case preg_match('~^/cleanLogs (.+?)(?:\s(1))?$~', $this->input['callback'], $m):
$this->cleanLogs($m[1], $m[2]);
break;
case preg_match('~^/allowIp (\d+\.\d+\.\d+\.\d+) (\d+)(?:\s(\d+))?$~', $this->input['callback'], $m):
case preg_match('~^/allowIp (.+?) (\d+)(?:\s(\d+))?$~', $this->input['callback'], $m):
$this->allowIp($m[1], $m[2], $m[3]);
break;
case preg_match('~^/searchIp (.+)$~', $this->input['callback'], $m):
@@ -319,13 +325,13 @@ class Bot
case preg_match('~^/defaultMTU (?P<arg>\d+(?:_(?:-)?\d+)?)$~', $this->input['callback'], $m):
$this->defaultMTU(...explode('_', $m['arg']));
break;
case preg_match('~^/subnet (?P<arg>-?\d+(?:_(?:-)?\d+)?)$~', $this->input['callback'], $m):
case preg_match('~^/subnet (?P<arg>-?\d+(?:_-?\d+)?(?:_\d)?)$~', $this->input['callback'], $m):
$this->subnet(...explode('_', $m['arg']));
break;
case preg_match('~^/subnetAdd (?P<arg>-?\d+(?:_(?:-)?\d+)?)$~', $this->input['callback'], $m):
case preg_match('~^/subnetAdd (?P<arg>-?\d+(?:_-?\d+)?(?:_-?\d+)?)$~', $this->input['callback'], $m):
$this->subnetAdd(...explode('_', $m['arg']));
break;
case preg_match('~^/subnetDelete (?P<arg>-?\d+(?:_-?\d+)?(?:_-?\d+)?)$~', $this->input['callback'], $m):
case preg_match('~^/subnetDelete (?P<arg>-?\d+(?:_-?\d+)?(?:_-?\d+)?(?:_-?\d+)?)$~', $this->input['callback'], $m):
$this->subnetDelete(...explode('_', $m['arg']));
break;
case preg_match('~^/addSubnets (?P<arg>-?\d+(?:_(?:-)?\d+)?)$~', $this->input['callback'], $m):
@@ -1186,10 +1192,10 @@ class Bot
try {
$pac = $this->getPacConf();
if (!empty($pac['autoscan'])) {
$r = $this->analysisIp(return: 1);
require __DIR__ . '/config.php';
if (!empty($c['admin']) && (empty($this->time3) || ((time() - $this->time3) > $pac['autoscan_timeout']))) {
$this->time3 = time();
$r = $this->analysisIp(return: 1);
if (!empty($r)) {
foreach ($r as $k => $v) {
foreach ($v as $i) {
@@ -2574,9 +2580,9 @@ DNS-over-HTTPS with IP:
case 'rulessetlist':
$r = $this->send(
$this->input['chat'],
"@{$this->input['username']} [direct | block | proxy]:time:URL",
"@{$this->input['username']} outbound[:behavior]:time:URL",
$this->input['message_id'],
reply: '[direct | block | proxy]:time:URL',
reply: 'outbound[:behavior]:time:URL',
);
break;
@@ -3106,7 +3112,7 @@ DNS-over-HTTPS with IP:
$this->menu('client', "{$client}_$page");
}
public function subnetAdd($wgpage, $page)
public function subnetAdd($wgpage, $page, $openconnect)
{
$r = $this->send(
$this->input['chat'],
@@ -3118,11 +3124,11 @@ DNS-over-HTTPS with IP:
'start_message' => $this->input['message_id'],
'start_callback' => $this->input['callback_id'],
'callback' => 'subnetSave',
'args' => [$wgpage, $page],
'args' => [$wgpage, $page, $openconnect],
];
}
public function subnetSave($text, $wgpage, $page)
public function subnetSave($text, $wgpage, $page, $openconnect)
{
$c = $this->getPacConf();
$subnets = explode(',', $text);
@@ -3131,15 +3137,42 @@ DNS-over-HTTPS with IP:
$this->setPacConf($c);
$page = floor(count($c['subnets']) / $this->limit);
}
$this->subnet($wgpage, $page);
if (!empty($openconnect)) {
$this->ocservRoute();
}
$this->subnet($wgpage, $page, $openconnect);
}
public function subnetDelete($wgpage, $k, $page = 0)
public function subnetDelete($wgpage, $k, $page = 0, $openconnect = 0)
{
$c = $this->getPacConf();
unset($c['subnets'][$k]);
$this->setPacConf($c);
$this->subnet($wgpage, $page);
if (!empty($openconnect)) {
$this->ocservRoute();
}
$this->subnet($wgpage, $page, $openconnect);
}
public function ocservRoute()
{
$p = $this->getPacConf();
$c = file_get_contents('/config/ocserv.conf');
$t = preg_replace('~^route[^\n]+~sm', '', $c);
if (!empty($p['subnets'])) {
foreach ($p['subnets'] as $v) {
if (preg_match('~^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/\d{1,2}~', $v)) {
$t .= "route = $v";
$flag = true;
}
}
if (empty($flag)) {
$t .= 'route = default';
}
} else {
$t .= 'route = default';
}
$this->restartOcserv($t);
}
public function calc()
@@ -3195,10 +3228,10 @@ DNS-over-HTTPS with IP:
}
}
public function subnet($wgpage = 0, $page = 0, $count = 5)
public function subnet($wgpage = 0, $page = 0, $openconnect = 0)
{
$count = $this->limit;
$text = "Menu -> Wireguard -> " . $this->i18n('listSubnet') . "\n";
$text = 'Menu -> ' . ($openconnect ? 'Openconnect' : 'Wireguard') . ' -> ' . $this->i18n('listSubnet') . "\n";
$data[] = [
[
'text' => $this->i18n('calc'),
@@ -3208,7 +3241,7 @@ DNS-over-HTTPS with IP:
$data[] = [
[
'text' => $this->i18n('add'),
'callback_data' => "/subnetAdd {$wgpage}_$page",
'callback_data' => "/subnetAdd {$wgpage}_{$page}_$openconnect",
],
];
$subnets = $this->getPacConf()['subnets'];
@@ -3221,7 +3254,7 @@ DNS-over-HTTPS with IP:
$data[] = [
[
'text' => $this->i18n('delete') . " $v",
'callback_data' => "/subnetDelete {$wgpage}_{$k}_$page",
'callback_data' => "/subnetDelete {$wgpage}_{$k}_{$page}_$openconnect",
],
];
}
@@ -3229,11 +3262,11 @@ DNS-over-HTTPS with IP:
$data[] = [
[
'text' => '<<',
'callback_data' => "/subnet {$wgpage}_" . ($page - 1 >= 0 ? $page - 1 : $all - 1),
'callback_data' => "/subnet {$wgpage}_" . ($page - 1 >= 0 ? $page - 1 : $all - 1) . ($openconnect ? '_1' : ''),
],
[
'text' => '>>',
'callback_data' => "/subnet {$wgpage}_" . ($page < $all - 1 ? $page + 1 : 0),
'callback_data' => "/subnet {$wgpage}_" . ($page < $all - 1 ? $page + 1 : 0) . ($openconnect ? '_1' : ''),
]
];
}
@@ -3241,7 +3274,7 @@ DNS-over-HTTPS with IP:
$data[] = [
[
'text' => $this->i18n('back'),
'callback_data' => "/menu wg $wgpage",
'callback_data' => $openconnect ? '/menu oc' : "/menu wg $wgpage",
],
];
$this->update(
@@ -3792,12 +3825,6 @@ DNS-over-HTTPS with IP:
$p = $this->getPacConf();
$text[] = "Menu -> " . $this->i18n('xray') . ' -> ' . $this->i18n('routes') . ' -> proxy list';
[$data] = $this->listPac('includelist', $page, 'xtlsproxy');
$data[] = [
[
'text' => 'set to ' . ($p['domains_outbound'] ? 'proxy' : 'direct'),
'callback_data' => "/domainsOutbound",
],
];
$data[] = [
[
'text' => $this->i18n('back'),
@@ -3850,12 +3877,6 @@ DNS-over-HTTPS with IP:
[$data] = $this->listPac('packagelist', $page, 'xtlsapp');
$p = $this->getPacConf();
$data[] = [
[
'text' => 'set to ' . ($p['app_outbound'] ? 'proxy' : 'direct'),
'callback_data' => "/appOutbound",
],
];
$data[] = [
[
'text' => $this->i18n('back'),
@@ -3876,12 +3897,6 @@ DNS-over-HTTPS with IP:
[$data] = $this->listPac('processlist', $page, 'xtlsprocess');
$p = $this->getPacConf();
$data[] = [
[
'text' => 'set to ' . ($p['process_outbound'] ? 'proxy' : 'direct'),
'callback_data' => "/processOutbound",
],
];
$data[] = [
[
'text' => $this->i18n('back'),
@@ -4309,22 +4324,38 @@ DNS-over-HTTPS with IP:
);
}
public function suspicious($regexp, $file, $ip, $title, $reverse = false)
public function ipInRange($ip, $range) {
[$range, $netmask] = explode('/', $range, 2);
$rangeDecimal = ip2long($range);
$ipDecimal = ip2long($ip);
$wildcardDecimal = pow(2, 32 - $netmask) - 1;
$netmaskDecimal = ~$wildcardDecimal;
return ($ipDecimal & $netmaskDecimal) == ($rangeDecimal & $netmaskDecimal);
}
public function suspicious($regexp, $file, $ranges, $title, $reverse = false)
{
if ($r = fopen($file, 'r')) {
while (feof($r) === false) {
$l = fgets($r);
if (preg_match('~(\d+\.\d+\.\d+\.\d+)~', $l, $m)) {
if ($reverse xor preg_match($regexp, $l)) {
if (is_array($ip)) {
if (empty($ip[$m[1]])) {
if (is_array($ranges)) {
$flag = true;
foreach ($ranges as $range) {
if ($this->ipInRange($m[1], $range)) {
$flag = false;
break;
}
}
if ($flag) {
$ret[$m[1]][] = [
'title' => $title,
'log' => $l,
];
}
} else {
if ($ip == $m[1]) {
if ($this->ipInRange($m[1], $ranges)) {
$ret[$m[1]][] = [
'title' => $title,
'log' => $l,
@@ -4342,30 +4373,32 @@ DNS-over-HTTPS with IP:
public function analysisIp(int $page = 0, $return = false)
{
$pac = $this->getPacConf();
foreach (array_merge($pac['white'] ?: [], $pac['deny'] ?: [], [
'10.10.0.1' ,'10.10.1.1' ,
'10.10.0.2' ,'10.10.1.2' ,
'10.10.0.3' ,'10.10.1.3' ,
'10.10.0.4' ,'10.10.1.4' ,
'10.10.0.5' ,'10.10.1.5' ,
'10.10.0.6' ,'10.10.1.6' ,
'10.10.0.7' ,'10.10.1.7' ,
'10.10.0.8' ,'10.10.1.8' ,
'10.10.0.9' ,'10.10.1.9' ,
'10.10.0.10','10.10.1.10',
'10.10.0.11','10.10.1.11',
'10.10.0.12','10.10.1.12',
'10.10.0.13','10.10.1.13',
'10.10.0.14','10.10.1.14',
'10.10.0.15','10.10.1.15',
]) as $v) {
$xr[$v] = true;
$xr = [];
foreach (array_merge($pac['white'] ?: [], $pac['deny'] ?: [], ['10.10.0.0/23']) as $v) {
if (preg_match('~^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(?:(/\d{1,2}))?$~', $v, $m)) {
if (!in_array($m[1] . ($m[2] ?: '/32'), $xr)) {
$xr[] = $m[1] . ($m[2] ?: '/32');
}
}
}
if ($r = fopen('/logs/nginx_tlgrm_access', 'r')) {
while (feof($r) === false) {
$l = fgets($r);
if (preg_match('~(\d+\.\d+\.\d+\.\d+)~', $l, $m)) {
$xr[$m[1]] = true;
if (!in_array("{$m[1]}/32", $xr)) {
$xr[] = "{$m[1]}/32";
}
}
}
fclose($r);
}
if ($r = fopen('/logs/nginx_doh_access', 'r')) {
while (feof($r) === false) {
$l = fgets($r);
if (preg_match('~(\d+\.\d+\.\d+\.\d+)~', $l, $m)) {
if (!in_array("{$m[1]}/32", $xr)) {
$xr[] = "{$m[1]}/32";
}
}
}
fclose($r);
@@ -4374,7 +4407,9 @@ DNS-over-HTTPS with IP:
while (feof($r) === false) {
$l = fgets($r);
if (preg_match('~(\d+\.\d+\.\d+\.\d+)(?=.+accepted)~', $l, $m)) {
$xr[$m[1]] = true;
if (!in_array("{$m[1]}/32", $xr)) {
$xr[] = "{$m[1]}/32";
}
}
}
fclose($r);
@@ -4513,9 +4548,9 @@ DNS-over-HTTPS with IP:
public function searchSuspiciousIp($ip)
{
$t = [
$this->suspicious('~\d+\.\d+\.\d+\.\d+.+200\s\d+\s0$~', '/logs/upstream_access', $ip, 'possibly a Reality Degenerate'),
$this->suspicious($this->reg, '/logs/nginx_default_access', $ip, 'possibly a scanner', true),
$this->suspicious($this->reg, '/logs/nginx_domain_access', $ip, 'possibly a scanner', true),
$this->suspicious('~\d+\.\d+\.\d+\.\d+.+200\s\d+\s0$~', '/logs/upstream_access', "$ip/32", 'possibly a Reality Degenerate'),
$this->suspicious($this->reg, '/logs/nginx_default_access', "$ip/32", 'possibly a scanner', true),
$this->suspicious($this->reg, '/logs/nginx_domain_access', "$ip/32", 'possibly a scanner', true),
];
foreach ($t as $r) {
if (!empty($r)) {
@@ -4544,6 +4579,33 @@ DNS-over-HTTPS with IP:
}
}
public function importIps($type)
{
switch ($type) {
case 'telegram':
$r = file_get_contents('https://core.telegram.org/resources/cidr.txt');
if (!empty($r)) {
$domains = explode("\n", $r);
}
break;
case 'gcore':
$r = json_decode(file_get_contents('https://api.gcore.com/cdn/public-ip-list'), true);
if (!empty($r['addresses'])) {
$domains = $r['addresses'];
}
break;
case 'cloudflare':
$r = json_decode(file_get_contents('https://api.cloudflare.com/client/v4/ips'), true);
if (!empty($r['result']['ipv4_cidrs'])) {
$domains = $r['result']['ipv4_cidrs'];
}
break;
}
if (!empty($domains = array_filter($domains ?: [], fn($e) => preg_match('~^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/\d{1,2}~', $e)))) {
$this->addInclude(implode(',', $domains), 'white');
}
}
public function denyList($page = 0, $white = 0)
{
$text = 'Menu -> IP -> ' . ($white ? 'ignore' : 'block') . 'list';
@@ -4552,6 +4614,26 @@ DNS-over-HTTPS with IP:
$page = min($page, $all - 1);
$page = $page < 0 ? $all - 1 : $page;
if (!empty($white)) {
$data[] = [
[
'text' => $this->i18n('telegram IPs'),
'callback_data' => "/importIps telegram",
],
];
$data[] = [
[
'text' => $this->i18n('gcore IPs'),
'callback_data' => "/importIps gcore",
],
];
$data[] = [
[
'text' => $this->i18n('cloudflare IPs'),
'callback_data' => "/importIps cloudflare",
],
];
}
$data[] = [
[
'text' => $this->i18n('add'),
@@ -4712,8 +4794,12 @@ DNS-over-HTTPS with IP:
if (!empty($pac['deny'])) {
$pac['deny'] = array_unique($pac['deny']);
sort($pac['deny']);
foreach ($pac['deny'] as $v) {
$text .= "deny $v;\n";
foreach ($pac['deny'] as $k => $v) {
if (!in_array($v, $pac['white'] ?: []) && !in_array($v, array_keys($xr ?: []))) {
$text .= "deny $v;\n";
} else {
unset($pac['deny'][$k]);
}
}
}
$this->setPacConf($pac);
@@ -4916,11 +5002,19 @@ DNS-over-HTTPS with IP:
'text' => $this->i18n('change password'),
'callback_data' => "/changeOcPass",
],
];
$data[] = [
[
'text' => $this->i18n('dns') . ": $dns",
'callback_data' => "/changeOcDns",
],
];
$data[] = [
[
'text' => $this->i18n('listSubnet'),
'callback_data' => "/subnet 0_0_1",
],
];
$data[] = [
[
'text' => $this->i18n('expose-iroutes') . ' ' . $this->i18n($expose ? 'on' : 'off'),
@@ -5234,7 +5328,24 @@ DNS-over-HTTPS with IP:
$pac = $this->getPacConf();
$domain = $this->getDomain();
$hash = substr(md5($this->key), 0, 8);
$text[] = "Menu -> " . $this->i18n('xray') . " -> $type templates";
$text[] = "Menu -> " . $this->i18n('xray') . " -> " . $this->i18n($type) . " templates";
$text[] = <<<TEXT
<code>~outbound~</code>
<code>"~pac~"</code>
<code>~package~</code>
<code>~process~</code>
<code>~block~</code>
<code>~warp~</code>
<code>~dns~</code>
<code>~uid~</code>
<code>~domain~</code>
<code>~directdomain~</code>
<code>~cdndomain~</code>
<code>~short_id~</code>
<code>~public_key~</code>
<code>~server_name~</code>
<code>~ip~</code>
TEXT;
$templates = $pac["{$type}templates"];
$data[] = [
@@ -5296,6 +5407,34 @@ DNS-over-HTTPS with IP:
);
}
public function mainOutbound()
{
$r = $this->send(
$this->input['chat'],
"@{$this->input['username']} send name",
$this->input['message_id'],
reply: 'send name',
);
$_SESSION['reply'][$r['result']['message_id']] = [
'start_message' => $this->input['message_id'],
'start_callback' => $this->input['callback_id'],
'callback' => 'setMainOutbound',
'args' => [],
];
}
public function setMainOutbound($text)
{
$pac = $this->getPacConf();
if (!empty($text)) {
$pac['outbound'] = $text;
} else {
unset($pac['outbound']);
}
$this->setPacConf($pac);
$this->xray();
}
public function xray($page = 0)
{
if (!$this->ssh('pgrep xray', 'xr')) {
@@ -5308,6 +5447,12 @@ DNS-over-HTTPS with IP:
$text[] = "fake domain: <code>$fake</code>";
}
$text[] = 'transport: ' . ($p['transport'] ?: 'Reality');
$data[] = [
[
'text' => $this->i18n('main outbound name: ') . ($p['outbound'] ?: 'proxy'),
'callback_data' => '/mainOutbound',
],
];
$data[] = [
[
'text' => $p['linkdomain'] ?: $this->i18n('cdn'),
@@ -5345,6 +5490,10 @@ DNS-over-HTTPS with IP:
'text' => $this->i18n('sing-box templates'),
'callback_data' => "/templates sing",
],
[
'text' => $this->i18n('mihomo templates'),
'callback_data' => "/templates clash",
],
];
$data[] = [
[
@@ -5434,24 +5583,20 @@ DNS-over-HTTPS with IP:
'callback_data' => "/xtlswarp",
]],
[[
'text' => $this->i18n('rulesset'),
'callback_data' => "/xtlsrulesset",
]],
[[
'text' => 'domains: ' . ($p['domains_outbound'] ? 'direct' : $outbound),
'text' => 'domains',
'callback_data' => "/xtlsproxy",
]],
[[
'text' => 'process: ' . ($p['process_outbound'] ? 'direct' : $outbound),
'text' => 'process',
'callback_data' => "/xtlsprocess",
]],
[[
'text' => 'package: ' . ($p['app_outbound'] ? 'direct' : $outbound),
'text' => 'package',
'callback_data' => "/xtlsapp",
]],
[[
'text' => 'final: ' . ($p['final_outbound'] ? $outbound : 'direct'),
'callback_data' => "/finalOutbound",
'text' => $this->i18n('rulesset'),
'callback_data' => "/xtlsrulesset",
]],
];
$data[] = [
@@ -5635,12 +5780,12 @@ DNS-over-HTTPS with IP:
$text[] = "Menu -> " . $this->i18n('xray') . " -> {$c['email']}\n";
$text[] = "<pre><code>{$this->linkXray($i)}</code></pre>\n";
$text[] = "import subscribe:";
$text[] = "<a href='$scheme://{$domain}/pac?h=$hash&t=s&r=v&s={$c['id']}#{$c['email']}'>v2rayng</a>";
$text[] = "<a href='$scheme://{$domain}/pac?h=$hash&t=si&r=si&s={$c['id']}#{$c['email']}'>sing-box</a>";
$text[] = "<a href='$scheme://{$domain}/pac?h=$hash&t=s&r=st&s={$c['id']}#{$c['email']}'>streisand</a>";
$text[] = "<a href='$scheme://{$domain}/pac?h=$hash&t=si&r=h&s={$c['id']}#{$c['email']}'>hiddify</a>";
$text[] = "<a href='$scheme://{$domain}/pac?h=$hash&t=si&r=k&s={$c['id']}#{$c['email']}'>karing</a>";
$text[] = "<a href='$scheme://{$domain}/pac?h=$hash&t=s&r=v&s={$c['id']}#{$c['email']}'>import://v2rayng</a>";
$text[] = "<a href='$scheme://{$domain}/pac?h=$hash&t=si&r=si&s={$c['id']}#{$c['email']}'>import://sing-box</a>";
$text[] = "<a href='$scheme://{$domain}/pac?h=$hash&t=s&r=st&s={$c['id']}#{$c['email']}'>import://streisand</a>";
$text[] = "<a href='$scheme://{$domain}/pac?h=$hash&t=si&r=h&s={$c['id']}#{$c['email']}'>import://hiddify</a>";
$text[] = "<a href='$scheme://{$domain}/pac?h=$hash&t=si&r=k&s={$c['id']}#{$c['email']}'>import://karing</a>";
$text[] = "<a href='$scheme://{$domain}/pac?h=$hash&t=si&r=c&s={$c['id']}#{$c['email']}'>import://mihomo</a>";
$si = "$scheme://{$domain}/pac/" . base64_encode(serialize([
'h' => $hash,
@@ -5652,21 +5797,31 @@ DNS-over-HTTPS with IP:
't' => 's',
's' => $c['id'],
]));
$cl = "$scheme://{$domain}/pac/" . base64_encode(serialize([
'h' => $hash,
't' => 'cl',
's' => $c['id'],
]));
$text[] = "\nxray config: <pre><code>$xr</code></pre>";
$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?h=$hash&t=si&r=w&s={$c['id']}'>windows service</a>";
$data[] = [
[
'text' => 'xray',
'text' => $this->i18n('v2ray'),
'web_app' => ['url' => "https://{$domain}/pac?h=$hash&t=s&s={$c['id']}"],
],
[
'text' => 'sing-box',
'text' => $this->i18n('singbox'),
'web_app' => ['url' => "https://{$domain}/pac?h=$hash&t=si&s={$c['id']}"],
],
[
'text' => $this->i18n('mihomo'),
'web_app' => ['url' => "https://{$domain}/pac?h=$hash&t=cl&s={$c['id']}"],
],
];
$data[] = [
[
@@ -5680,6 +5835,7 @@ DNS-over-HTTPS with IP:
];
$singtemplate = $c['singtemplate'] ? base64_decode($c['singtemplate']) : 'default(' . ($pac['defaultsingtemplate'] && !empty($pac['singtemplates'][base64_decode($pac['defaultsingtemplate'])]) ? base64_decode($pac['defaultsingtemplate']) : 'origin') . ')';
$v2raytemplate = $c['v2raytemplate'] ? base64_decode($c['v2raytemplate']) : 'default(' . ($pac['defaultv2raytemplate'] && !empty($pac['v2raytemplates'][base64_decode($pac['defaultv2raytemplate'])]) ? base64_decode($pac['defaultv2raytemplate']) : 'origin') . ')';
$clashtemplate = $c['clashtemplate'] ? base64_decode($c['clashtemplate']) : 'default(' . ($pac['defaultclashtemplate'] && !empty($pac['clashtemplates'][base64_decode($pac['defaultclashtemplate'])]) ? base64_decode($pac['defaultclashtemplate']) : 'origin') . ')';
$data[] = [
[
'text' => $this->i18n('v2ray') . ": $v2raytemplate",
@@ -5689,6 +5845,10 @@ DNS-over-HTTPS with IP:
'text' => $this->i18n('singbox') . ": $singtemplate",
'callback_data' => "/templateUser sing $i",
],
[
'text' => $this->i18n('mihomo') . ": $clashtemplate",
'callback_data' => "/templateUser clash $i",
],
];
$data[] = [
[
@@ -5739,7 +5899,17 @@ DNS-over-HTTPS with IP:
public function subscription()
{
$type = $_GET['t'] == 's' ? 'v2ray' : 'sing';
switch ($_GET['t']) {
case 's':
$type = 'v2ray';
break;
case 'si':
$type = 'sing';
break;
case 'cl':
$type = 'clash';
break;
}
$pac = $this->getPacConf();
$domain = $_GET['cdn'] ?: ($_SERVER['SERVER_NAME'] ?: $this->getDomain($pac['transport'] == 'Websocket'));
$xr = $this->getXray();
@@ -5773,6 +5943,11 @@ DNS-over-HTTPS with IP:
't' => 's',
's' => $uid,
]));
$cl = "$scheme://{$domain}/pac/" . base64_encode(serialize([
'h' => $hash,
't' => 'cl',
's' => $uid,
]));
switch ($_GET['r']) {
case 'si':
header("Location: sing-box://import-remote-profile/?url=$si");
@@ -5789,6 +5964,9 @@ DNS-over-HTTPS with IP:
case 'h':
header("Location: hiddify://install-config/?url=$si");
exit;
case 'c':
header("Location: clash://install-config/?url=$cl&name=$email");
exit;
case 'w':
$link = htmlspecialchars($si, ENT_XML1, 'UTF-8');
$n = "singbox_$uid.zip";
@@ -5829,6 +6007,14 @@ DNS-over-HTTPS with IP:
break;
}
}
if (!isset($index)) {
foreach ($c['proxies'] as $k => $v) {
if ($v['name'] == $outbound) {
$index = $k;
break;
}
}
}
switch ($_GET['t']) {
case 's':
@@ -5887,30 +6073,145 @@ DNS-over-HTTPS with IP:
$c['outbounds'][$index]['tls']['server_name'] = '~server_name~';
$c['outbounds'][$index]['tls']['reality']['short_id'] = '~short_id~';
}
break;
case 'cl':
$c['proxies'][$index]['server'] = '~domain~';
$c['proxies'][$index]['uuid'] = '~uid~';
if ($pac['transport'] == 'Websocket') {
unset($c['proxies'][$index]['flow']);
unset($c['proxies'][$index]['reality-opts']);
$c['proxies'][$index]["network"] = "ws";
$c['proxies'][$index]["ws-opts"]['path'] = '/ws';
$c['proxies'][$index]["skip-cert-verify"] = false;
$c['proxies'][$index]['servername'] = '~domain~';
} else {
unset($c['proxies'][$index]["ws-opts"]);
unset($c['proxies'][$index]["skip-cert-verify"]);
$c['proxies'][$index]["network"] = "tcp";
$c['proxies'][$index]['flow'] = 'xtls-rprx-vision';
$c['proxies'][$index]['servername'] = '~server_name~';
$c['proxies'][$index]['reality-opts'] = [
'public-key' => '~public_key~',
'short-id' => '~short_id~',
];
}
break;
}
$c = json_decode($this->replaceTags(json_encode($c), [
'"~pac~"' => json_encode(array_keys(array_filter($pac['includelist'] ?: []))),
'"~block~"' => json_encode(array_keys(array_filter($pac['blocklist'] ?: []))),
'"~warp~"' => json_encode(array_keys(array_filter($pac['warplist'] ?: []))),
'"~process~"' => json_encode(array_keys(array_filter($pac['processlist'] ?: []))),
'"~package~"' => json_encode(array_keys(array_filter($pac['packagelist'] ?: []))),
'~dns~' => "https://$domain/dns-query/$uid",
'~uid~' => $uid,
'~domain~' => $domain,
'~directdomain~' => $pac['domain'],
'~cdndomain~' => $pac['linkdomain'],
'~short_id~' => $xr['inbounds'][0]['streamSettings']['realitySettings']['shortIds'][0],
'~public_key~' => $pac['xray'],
'~server_name~' => $xr['inbounds'][0]['streamSettings']['realitySettings']['serverNames'][0],
'~ip~' => $this->ip,
]), true);
switch ($_GET['t']) {
case 's':
if (!empty($c['routing']['rules'])) {
foreach ($c['routing']['rules'] as $k => $v) {
if (array_key_exists('domain', $v) && empty($v['domain'])) {
unset($c['routing']['rules'][$k]);
}
}
$c['routing']['rules'] = array_values($c['routing']['rules']);
}
break;
case 'si':
$c['route'] = $this->addRuleSet($c['route']);
$c['route'] = $this->createRuleSet($c['route'], $uid, $domain);
if (!empty($c['route']['rules'])) {
foreach ($c['route']['rules'] as $k => $v) {
if (count($v) < 2) {
unset($c['route']['rules'][$k]);
}
}
$c['route']['rules'] = array_values($c['route']['rules']);
}
break;
case 'cl':
$c = $this->clashRuleSet($c);
if (!empty($c['rules'])) {
$c['rules'] = $this->clashRules($c['rules']);
if (count($c['rules']) == 1) {
unset($c['rules']);
}
}
break;
}
$json = $this->replaceTags(json_encode($c), [
'"~pac~"' => json_encode(array_keys(array_filter($pac['includelist'] ?: []))),
'~dns~' => "https://$domain/dns-query/$uid",
'~uid~' => $uid,
'~domain~' => $domain,
'~short_id~' => $xr['inbounds'][0]['streamSettings']['realitySettings']['shortIds'][0],
'~public_key~' => $pac['xray'],
'~server_name~' => $xr['inbounds'][0]['streamSettings']['realitySettings']['serverNames'][0],
'~app_outbound~' => $pac['app_outbound'] ? 'direct' : $outbound,
'~process_outbound~' => $pac['process_outbound'] ? 'direct' : $outbound,
'~domains_outbound~' => $pac['domains_outbound'] ? 'direct' : $outbound,
'~final_outbound~' => $pac['final_outbound'] ? $outbound : 'direct',
'~ip~' => $this->ip,
]);
$json = $this->clearEmptyRules($json);
if ($_GET['t'] == 'cl') {
header('Content-type: text/yaml');
echo yaml_emit($c);
return;
}
header('Content-type: application/json');
echo $json;
echo json_encode($c);
}
public function clashRuleSet($c)
{
$p = $this->getPacConf();
if (!empty($p['rulessetlist']) && $c['add-rule-providers']) {
foreach ($p['rulessetlist'] as $k => $v) {
if (!empty($v)) {
[$type, $behavior, $time, $url] = explode(':', $k, 4);
if (preg_match('~\.(mrs|yaml|yml)$~', $url, $m)) {
$c['rule-providers'][$url] = [
'type' => 'http',
'url' => $url,
'interval' => (int) $time,
'behavior' => $behavior,
'format' => $m[1],
];
switch ($type) {
case 'reject':
case 'REJECT':
array_unshift($c['rules'], [
'RULE-SET', $url, strtoupper($type)
]);
break;
default:
array_splice($c['rules'], count($c['rules']) - 1, 0, [[
'RULE-SET', $url, strtoupper($type)
]]);
break;
}
}
}
}
}
unset($c['add-rule-providers']);
if (empty($c['rule-providers'])) {
unset($c['rule-providers']);
}
return $c;
}
public function clashRules($rules)
{
foreach ($rules as $v) {
if (isset($v['list'])) {
if (!empty($v['list'])) {
foreach ($v['list'] as $j) {
$tmp[] = "{$v['type']}, $j, {$v['action']}";
}
}
} else {
$tmp[] = implode(', ', $v);
}
}
return $tmp;
}
public function replaceTags($subject, $tags)
@@ -5918,108 +6219,82 @@ DNS-over-HTTPS with IP:
return str_replace(array_keys($tags), array_values($tags), $subject);
}
public function clearEmptyRules($json)
{
$json = json_decode($json, 1);
if (!empty($json['routing']['rules'])) {
foreach ($json['routing']['rules'] as $k => $v) {
if (array_key_exists('domain', $v) && empty($v['domain'])) {
unset($json['routing']['rules'][$k]);
}
}
$json['routing']['rules'] = array_values($json['routing']['rules']);
}
if (!empty($json['route']['rules'])) {
foreach ($json['route']['rules'] as $k => $v) {
if (count($v) < 2) {
unset($json['route']['rules'][$k]);
}
}
$json['route']['rules'] = array_values($json['route']['rules']);
}
return json_encode($json);
}
public function addRuleSet($route)
{
foreach ($route['rules'] as $k => $v) {
$t[$v['outbound']] = $k;
}
$p = $this->getPacConf();
if (!empty($p['rulessetlist'])) {
foreach ($p['rulessetlist'] as $k => $v) {
if (!empty($v)) {
[$type, $time, $url] = explode(':', $k, 3);
$route['rule_set'][] = [
"tag" => $k,
"type" => "remote",
"format" => "binary",
"url" => $url,
"download_detour" => "direct",
"update_interval" => $time
];
$route['rules'][$t[$type]]['rule_set'][] = $k;
if (!empty($route['rules'])) {
foreach ($route['rules'] as $k => $v) {
if (!empty($v['addruleset'])) {
$t[$v['outbound']] = $k;
}
}
$p = $this->getPacConf();
if (!empty($p['rulessetlist'])) {
foreach ($p['rulessetlist'] as $k => $v) {
if (!empty($v)) {
[$type, $time, $url] = explode(':', $k, 3);
if (preg_match('~\.srs$~', $url) && !empty($route['rules'][$t[$type]])) {
$route['rule_set'][] = [
"tag" => $k,
"type" => "remote",
"format" => "binary",
"url" => $url,
"download_detour" => "direct",
"update_interval" => $time
];
$route['rules'][$t[$type]]['rule_set'][] = $k;
}
}
}
}
foreach ($route['rules'] as $k => $v) {
unset($route['rules'][$k]['addruleset']);
}
}
return $route;
}
public function cleanEmptyKeys(array $arr)
{
foreach ($arr as $k => $v) {
if (empty($v)) {
unset($arr[$k]);
} elseif (is_array($v)) {
$arr[$k] = $this->cleanEmptyKeys($v);
if (empty($arr[$k])) {
unset($arr[$k]);
}
}
}
return $arr;
}
public function createSrs(string $name, array $rules)
{
$rules = $this->cleanEmptyKeys($rules);
header("Content-Disposition: attachment; filename=$name.srs");
header('Content-Type: application/binary');
$f = "/tmp/$name" . time() . rand(1, 100);
file_put_contents($f, json_encode([
'version' => 1,
'rules' => $rules ?: [],
]));
exec("sing-box rule-set compile $f");
echo file_get_contents("$f.srs");
unlink($f);
unlink("$f.srs");
exit;
}
public function createRuleSet($route, $uid, $domain)
{
$pac = $this->getPacConf();
$scheme = empty($this->nginxGetTypeCert()) ? 'http' : 'https';
$hash = substr(md5($this->key), 0, 8);
foreach ($route['rules'] as $k => $v) {
if (!empty($v['createruleset'])) {
foreach ($v['createruleset'] as $r) {
foreach ($r['rules'] as $l => $n) {
switch (true) {
case array_key_exists('domain_suffix', $n):
switch ($n['domain_suffix']) {
case '~pac~':
$t = 'includelist';
break;
case '~warp~':
$t = 'warplist';
break;
case '~block~':
$t = 'blocklist';
break;
}
$r['rules'][$l]['domain_suffix'] = array_keys(array_filter($pac[$t] ?: []));
if (empty($r['rules'][$l]['domain_suffix'])) {
unset($r['rules'][$l]);
}
break;
case array_key_exists('package_name', $n):
$r['rules'][$l]['package_name'] = array_keys(array_filter($pac['packagelist'] ?: []));
if (empty($r['rules'][$l]['package_name'])) {
unset($r['rules'][$l]);
}
break;
case array_key_exists('process_name', $n):
$r['rules'][$l]['process_name'] = array_keys(array_filter($pac['processlist'] ?: []));
if (empty($r['rules'][$l]['process_name'])) {
unset($r['rules'][$l]);
}
break;
}
}
if (!empty($_GET['r']) && $r['name'] == $_GET['r']) {
header("Content-Disposition: attachment; filename={$r['name']}.srs");
header('Content-Type: application/binary');
$f = "/tmp/{$r['name']}" . time() . rand(1, 100);
file_put_contents($f, json_encode([
'version' => 1,
'rules' => $r['rules'] ?: [],
]));
exec("sing-box rule-set compile $f");
echo file_get_contents("$f.srs");
unlink($f);
unlink("$f.srs");
exit;
$this->createSrs($r['name'], $r['rules']);
}
$ruleset[] = [
"tag" => $r['name'],
+6 -2
View File
@@ -262,8 +262,12 @@ $i = [
'ru' => 'очистить',
],
'xray' => [
'en' => 'Xray',
'ru' => 'Xray',
'en' => 'Vless',
'ru' => 'Vless',
],
'clash' => [
'en' => 'mihomo',
'ru' => 'mihomo',
],
'geodb' => [
'en' => 'GeoIp/GeoSite',
+1
View File
@@ -37,6 +37,7 @@ if ($hash == substr(md5($c['key']), 0, 8)) {
break;
case 's':
case 'si':
case 'cl':
$bot->subscription();
exit;
+126
View File
@@ -0,0 +1,126 @@
{
"mixed-port": 2080,
"allow-lan": true,
"tcp-concurrent": true,
"enable-process": true,
"find-process-mode": "strict",
"global-client-fingerprint": "chrome",
"mode": "rule",
"log-level": "debug",
"ipv6": false,
"keep-alive-interval": 30,
"unified-delay": false,
"profile": {
"store-selected": true,
"store-fake-ip": true
},
"sniffer": {
"enable": true,
"sniff": {
"HTTP": {
"ports": [
80,
"8080-8880"
],
"override-destination": true
},
"TLS": {
"ports": [
443,
8443
]
},
"QUIC": {
"ports": [
443,
8443
]
}
}
},
"tun": {
"enable": true,
"stack": "mixed",
"dns-hijack": [
"any:53"
],
"auto-route": true,
"auto-detect-interface": true,
"strict-route": true
},
"dns": {
"enable": true,
"listen": ":1053",
"prefer-h3": false,
"ipv6": false,
"enhanced-mode": "fake-ip",
"fake-ip-filter": [
"~domain~",
"+.lan",
"+.local"
],
"nameserver": [
"~dns~"
]
},
"proxies": [
{
"name": "~outbound~",
"type": "vless",
"server": "~domain~",
"port": 443,
"uuid": "~uid~",
"network": "tcp",
"flow": "xtls-rprx-vision",
"tls": true,
"reality-opts": {
"public-key": "~public_key~",
"short-id": "~short_id~"
},
"servername": "~server_name~",
"client-fingerprint": "chrome"
}
],
"proxy-groups": [
{
"name": "PROXY",
"type": "select",
"proxies": [
"~outbound~"
]
}
],
"add-rule-providers": true,
"rule-providers": {},
"rules": [
{
"type": "DOMAIN-SUFFIX",
"list": "~block~",
"action": "REJECT"
},
{
"type": "PROCESS-NAME",
"list": "~process~",
"action": "PROXY"
},
{
"type": "PROCESS-NAME",
"list": "~package~",
"action": "PROXY"
},
{
"type": "DOMAIN-SUFFIX",
"list": "~warp~",
"action": "PROXY"
},
{
"type": "DOMAIN-SUFFIX",
"list": "~pac~",
"action": "PROXY"
},
{
"type": "MATCH",
"action": "DIRECT"
}
]
}
+1 -1
View File
@@ -505,7 +505,7 @@ ipv4-netmask = 255.255.255.0
# Whether to tunnel all DNS queries via the VPN. This is the default
# when a default route is set.
#tunnel-all-dns = true
tunnel-all-dns = true
# The advertised DNS server. Use multiple lines for
# multiple servers.
+14 -12
View File
@@ -111,10 +111,11 @@
"outbound": "dns-out"
},
{
"addruleset": true,
"createruleset": [
{
"name": "pac",
"interval": "15s",
"interval": "30s",
"rules": [
{
"domain_suffix": "~pac~"
@@ -122,13 +123,14 @@
]
}
],
"outbound": "~domains_outbound~"
"outbound": "~outbound~"
},
{
"addruleset": true,
"createruleset": [
{
"name": "package",
"interval": "15s",
"interval": "30s",
"rules": [
{
"package_name": "~package~"
@@ -136,13 +138,14 @@
]
}
],
"outbound": "~app_outbound~"
"outbound": "~outbound~"
},
{
"addruleset": true,
"createruleset": [
{
"name": "process",
"interval": "15s",
"interval": "30s",
"rules": [
{
"process_name": "~process~"
@@ -150,13 +153,14 @@
]
}
],
"outbound": "~process_outbound~"
"outbound": "~outbound~"
},
{
"addruleset": true,
"createruleset": [
{
"name": "block",
"interval": "15s",
"interval": "30s",
"rules": [
{
"domain_suffix": "~block~"
@@ -167,10 +171,11 @@
"outbound": "block"
},
{
"addruleset": true,
"createruleset": [
{
"name": "warp",
"interval": "15s",
"interval": "30s",
"rules": [
{
"domain_suffix": "~warp~"
@@ -179,11 +184,8 @@
}
],
"outbound": "~outbound~"
},
{
"outbound": "direct"
}
],
"final": "~final_outbound~"
"final": "direct"
}
}
+9 -1
View File
@@ -59,4 +59,12 @@ c:
git checkout .
git reset
webhook:
docker compose exec php php checkwebhook.php
docker compose exec php php checkwebhook.php
reset:
make d
git reset --hard
git clean -fd
docker volume rm vpnbot_adguard vpnbot_warp
make u
backup:
docker compose exec php php backup.php > backup.json
+22
View File
@@ -1,3 +1,25 @@
09.12.2024 v1.111
- mihomo: фикс rule-providers format
06.12.2024 v1.110
- ruleset для mihomo
28.11.2024 v1.109
- фикс автоскана
- добавление clash-шаблонов
21.11.2024 v1.108
- xray: addruleset для direct
- openconnect:ограничение формата при добавлении подсети
- новый механизм сверки ip для анализатора айпи
- мелкие фиксы меню и текста
21.11.2024 v1.107
- xray: добавлены теги ~cdndomain~, ~directdomain~
- xray: возможность менять имя главного аутбаунда(тот аутбаунд который заполняет бот, в шаблонах идет как ~outbound~) для клиентских конфигов
- xray: в шаблонах теперь надо явно указывать ключ addruleset в route -> rules, чтобы бот заполнил их правилами из списка ruleset (см origin шаблон)
- openconnect: добавлена маршрутизация (список подсетей общий с wireguard)
- ip ban: фикс обработки подсетей в белом/черном списках
- ip ban: в белый список можно импортировать адреса от telegram, gcore, cloudflare
- добавлена в игнор папка app/webapp/override. она не будет перезатираться после обновления, туда можно положить ваши ресурсы к override.html
- <code>make backup</code> - сохранит в корень backup.json
- <code>make reset</code> - обнуляет все настройки
18.11.2024 v1.106
- фикс отвала бота при пустых логах телеги
17.11.2024 v1.105