Compare commits

..

3 Commits

Author SHA1 Message Date
mercury c56fe4ff78 blocklist improve
add https://github.com/legiz-ru/sb-rule-sets/raw/main/ru-bundle.lst button
2024-11-15 11:49:20 +04:00
mercury b0e6835ac9 improve scanner 2024-11-15 01:04:06 +04:00
mercury f29d366aef scaner: fix regex 2024-11-14 16:47:55 +04:00
3 changed files with 127 additions and 78 deletions
+112 -72
View File
@@ -149,6 +149,10 @@ class Bot
case preg_match('~^/switchBanIp$~', $this->input['callback'], $m):
$this->switchBanIp();
break;
case preg_match('~^/searchLogs (.+)$~', $this->input['message'], $m):
case preg_match('~^/searchLogs (.+)$~', $this->input['callback'], $m):
$this->searchLogs($m[1]);
break;
case preg_match('~^/switchSilence$~', $this->input['callback'], $m):
$this->switchSilence();
break;
@@ -240,6 +244,9 @@ class Bot
case preg_match('~^/addCommunityFilter$~', $this->input['callback'], $m):
$this->addCommunityFilter();
break;
case preg_match('~^/addLegizFilter$~', $this->input['callback'], $m):
$this->addLegizFilter();
break;
case preg_match('~^/pacMenu (\d+)$~', $this->input['callback'], $m):
$this->pacMenu($m[1]);
break;
@@ -1182,14 +1189,14 @@ class Bot
]];
}
}
if (empty($pac['silence'])) {
if ($pac['silence'] == 0 || $pac['silence'] == 1) {
foreach ($c['admin'] as $k => $v) {
$this->send($v, "suspicious ips found: $text" . ($ban ? "\nbanned:$ban" : ''), button: $ips ?: [[
[
'text' => $this->i18n('analyze'),
'callback_data' => '/analysisIp',
],
]]);
]], disable_notification: $pac['silence'] ? true : false);
}
}
}
@@ -3476,6 +3483,19 @@ DNS-over-HTTPS with IP:
$this->pacUpdate();
}
public function addLegizFilter()
{
$pac = $this->getPacConf();
$l = array_filter(array_map(fn($e) => trim($e), explode("\n", file_get_contents('https://github.com/legiz-ru/sb-rule-sets/raw/main/ru-bundle.lst'))));
if (!empty($l)) {
foreach ($l as $k => $v) {
$pac['includelist'][$v] = true;
}
}
$this->setPacConf($pac);
$this->pacUpdate();
}
public function pacMenu($page = 0)
{
unset($_SESSION['proxylistentry']);
@@ -3559,6 +3579,12 @@ DNS-over-HTTPS with IP:
'callback_data' => "/addCommunityFilter",
],
];
$data[] = [
[
'text' => $this->i18n('add') . ' ru-bundle',
'callback_data' => "/addLegizFilter",
],
];
$data = array_merge($data, $this->listPac('includelist', $page, 'pacMenu')[0]);
$data[] = [
[
@@ -4100,7 +4126,7 @@ DNS-over-HTTPS with IP:
],
[
[
'text' => $this->i18n('IP ban'),
'text' => $this->i18n('IP ban & Logs'),
'callback_data' => "/ipMenu",
],
],
@@ -4181,7 +4207,7 @@ DNS-over-HTTPS with IP:
public function switchSilence()
{
$c = $this->getPacConf();
$c['silence'] = $c['silence'] ? 0 : 1;
$c['silence'] = (($c['silence'] ?: 0) + 1) % 3;
$this->setPacConf($c);
$this->ipMenu();
}
@@ -4192,6 +4218,12 @@ DNS-over-HTTPS with IP:
$pac = $this->getPacConf();
$d = count($pac['deny'] ?: []);
$w = count($pac['white'] ?: []);
$data[] = [
[
'text' => $this->i18n('logs'),
'callback_data' => "/logs",
],
];
$data[] = [
[
'text' => $this->i18n('autoscan') . ': ' . ($pac['autoscan'] ? $this->getTime(strtotime(($pac['autoscan_timeout'] ?: 3600) . ' seconds')) : $this->i18n('off')),
@@ -4204,10 +4236,17 @@ DNS-over-HTTPS with IP:
'text' => $this->i18n('autoblock') . ': ' . $this->i18n($pac['autodeny'] ? 'on' : 'off'),
'callback_data' => '/switchBanIp',
],
];
$data[] = [
[
'text' => $this->i18n('silence') . ': ' . $this->i18n($pac['silence'] ? 'on' : 'off'),
'text' => $this->i18n('silence') . ': ' . ((function ($pac) {
switch ($pac['silence']) {
case 0:
return $this->i18n('off');
case 1:
return '🟡';
case 2:
return $this->i18n('on');
}
})($pac)),
'callback_data' => '/switchSilence',
],
];
@@ -4217,8 +4256,6 @@ DNS-over-HTTPS with IP:
'text' => $this->i18n('ignorelist') . ": $w",
'callback_data' => '/denyList 0 1',
],
];
$data[] = [
[
'text' => $this->i18n('blocklist') . ": $d",
'callback_data' => '/denyList 0 0',
@@ -4247,7 +4284,23 @@ DNS-over-HTTPS with IP:
public function analysisIp($return = false)
{
$pac = $this->getPacConf();
foreach (array_merge($pac['white'] ?: [], $pac['deny'] ?: [], ['10.10.0.10']) as $v) {
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;
}
if ($r = fopen('/logs/nginx_tlgrm_access', 'r')) {
@@ -4282,15 +4335,15 @@ DNS-over-HTTPS with IP:
}
$reg = [
'GET /ws.+ HTTP',
'GET /adguard/.+ HTTP',
'GET /webapp.+ HTTP',
'GET /pac.+ HTTP',
'GET \.well-known.+ HTTP',
'GET /v2ray.+ HTTP',
'GET /dns-query.+ HTTP',
'GET /ws(?:.+)? HTTP',
'GET /adguard/(?:.+)? HTTP',
'GET /webapp(?:.+)? HTTP',
'GET /pac(?:.+)? HTTP',
'GET \.well-known(?:.+)? HTTP',
'GET /v2ray(?:.+)? HTTP',
'GET /dns-query(?:.+)? HTTP',
'GET / HTTP',
'GET /tlgrm.+ HTTP',
'GET /tlgrm(?:.+)? HTTP',
'GET /jsoneditor.min.css HTTP',
'GET /jsoneditor.min.js HTTP',
'GET /jquery-3.7.1.min.js HTTP',
@@ -4326,45 +4379,44 @@ DNS-over-HTTPS with IP:
fclose($r);
}
$i = 0;
if (!empty($ip)) {
foreach ($ip as $k => $v) {
if ($i > 10) {
break;
}
$comment = implode(', ', array_unique($v));
if (!empty($return)) {
$ret[$k] = $v;
} else {
$this->send($this->input['from'], "$k $comment\n", button: [[
[
'text' => $this->i18n('block'),
'callback_data' => "/denyIp $k",
],
[
'text' => $this->i18n('ignore'),
'callback_data' => "/whiteIp $k",
],
[
'text' => $this->i18n('logs'),
'callback_data' => "/searchIp $k",
],
[
'text' => $this->i18n('clean logs'),
'callback_data' => "/cleanLogs $k",
],
]]);
$i++;
}
}
if (!empty($return)) {
return $ret;
return $ip;
}
foreach ($ip as $k => $v) {
$file .= "/searchLogs $k\n";
}
$this->sendFile($this->input['from'], new CURLStringFile($file, 'analyze_ip_' . date('Y_m_d_H_i_s')));
} else {
$this->answer($this->input['callback_id'], 'empty');
}
}
public function searchLogs($search)
{
if (preg_match('~^\d+\.\d+\.\d+\.\d+$~', $search)) {
$info = file_get_contents("https://ipinfo.io/$search/json", context: stream_context_create(['http' => ['timeout' => 2]]));
$this->send($this->input['from'], "$search\n<pre>$info</pre>", button: [[
[
'text' => $this->i18n('block'),
'callback_data' => "/denyIp $search",
],
[
'text' => $this->i18n('ignore'),
'callback_data' => "/whiteIp $search",
],
[
'text' => $this->i18n('logs'),
'callback_data' => "/searchIp $search",
],
[
'text' => $this->i18n('clean logs'),
'callback_data' => "/cleanLogs $search",
],
]]);
}
}
public function searchIp($ip)
{
foreach ($this->logs as $v) {
@@ -4408,21 +4460,13 @@ DNS-over-HTTPS with IP:
foreach (array_slice($domains, $page * $this->limit, $this->limit) as $v) {
$data[] = [
[
'text' => $this->i18n('delete') . " $v",
'text' => $v,
'callback_data' => "/searchLogs $v",
],
[
'text' => $this->i18n('delete'),
'callback_data' => "/allowIp $v $page" . ($white ? " 1" : ''),
],
[
'text' => $this->i18n($white ? 'block' : 'ignore'),
'callback_data' => ($white ? "/denyIp" : "/whiteIp") . " $v 1 $page $white",
],
[
'text' => $this->i18n('logs'),
'callback_data' => "/searchIp $v",
],
[
'text' => $this->i18n('clean logs'),
'callback_data' => "/cleanLogs $v 1",
],
];
}
if ($all > 1) {
@@ -4935,9 +4979,9 @@ DNS-over-HTTPS with IP:
{
$r = $this->send(
$this->input['chat'],
"@{$this->input['username']} send time:",
"@{$this->input['username']} send time like 1 hour or 1 day etc",
$this->input['message_id'],
reply: 'send time:',
reply: 'send time like 1 hour or 1 day etc',
);
$_SESSION['reply'][$r['result']['message_id']] = [
'start_message' => $this->input['message_id'],
@@ -6381,10 +6425,6 @@ DNS-over-HTTPS with IP:
],
];
$data[] = [
[
'text' => $this->i18n('logs'),
'callback_data' => "/logs",
],
[
'text' => $this->i18n('debug') . ': ' . $this->i18n($c['debug'] ? 'on' : 'off'),
'callback_data' => "/debug",
@@ -6534,7 +6574,7 @@ DNS-over-HTTPS with IP:
$data[] = [
[
'text' => $this->i18n('back'),
'callback_data' => "/menu config",
'callback_data' => "/ipMenu",
],
];
$this->update(
@@ -7146,7 +7186,7 @@ DNS-over-HTTPS with IP:
var_dump($this->request('setMyCommands', json_encode($data), 1));
}
public function send($chat, $text, ?int $to = 0, $button = false, $reply = false, $mode = 'HTML')
public function send($chat, $text, ?int $to = 0, $button = false, $reply = false, $mode = 'HTML', $disable_notification = false)
{
if ($button) {
$extra = ['inline_keyboard' => $button];
@@ -7167,7 +7207,7 @@ DNS-over-HTTPS with IP:
'text' => "$v\n",
'parse_mode' => $mode,
// 'disable_web_page_preview' => true,
// 'disable_notification' => !empty($to) && 0 == $k,
'disable_notification' => $disable_notification,
'reply_to_message_id' => 0 == $k && $to > 0 ? $to : false,
];
if ($k == array_key_last($tails)) {
@@ -7183,7 +7223,7 @@ DNS-over-HTTPS with IP:
'text' => $text,
'parse_mode' => $mode,
// 'disable_web_page_preview' => true,
// 'disable_notification' => !empty($to),
'disable_notification' => $disable_notification,
'reply_to_message_id' => $to,
];
if (!empty($extra)) {
+6 -6
View File
@@ -10,23 +10,23 @@ do
if [[ -n "$cmd" ]]
then
key=$(cat $pwd/update/key)
curl -H "Content-Type: application/json" -X POST https://api.telegram.org/bot$key/editMessageText -d "$(cat $pwd/update/curl | sed 's/"text":"~t~"/"text": "останавливаю бота"/')"
curl -H "Content-Type: application/json" -X POST https://api.telegram.org/bot$key/editMessageText -d "$(cat $pwd/update/curl | sed 's/"text":"~t~"/"text": "stopping the bot"/')"
docker compose down --remove-orphans
if [[ "$cmd" == "1" ]]
then
curl -H "Content-Type: application/json" -X POST https://api.telegram.org/bot$key/editMessageText -d "$(cat $pwd/update/curl | sed 's/"text":"~t~"/"text": "очищаю директорию"/')"
curl -H "Content-Type: application/json" -X POST https://api.telegram.org/bot$key/editMessageText -d "$(cat $pwd/update/curl | sed 's/"text":"~t~"/"text": "clearing the directory"/')"
git reset --hard && git clean -fd
curl -H "Content-Type: application/json" -X POST https://api.telegram.org/bot$key/editMessageText -d "$(cat $pwd/update/curl | sed 's/"text":"~t~"/"text": "скачиваю обновление"/')"
curl -H "Content-Type: application/json" -X POST https://api.telegram.org/bot$key/editMessageText -d "$(cat $pwd/update/curl | sed 's/"text":"~t~"/"text": "downloading the update"/')"
git fetch
if [[ -n "$branch" ]]
then
curl -H "Content-Type: application/json" -X POST https://api.telegram.org/bot$key/editMessageText -d "$(cat $pwd/update/curl | sed 's/"text":"~t~"/"text": "меняю ветку"/')"
curl -H "Content-Type: application/json" -X POST https://api.telegram.org/bot$key/editMessageText -d "$(cat $pwd/update/curl | sed 's/"text":"~t~"/"text": "changing branch"/')"
git checkout -t origin/$branch || git checkout $branch
fi
curl -H "Content-Type: application/json" -X POST https://api.telegram.org/bot$key/editMessageText -d "$(cat $pwd/update/curl | sed 's/"text":"~t~"/"text": "применяю обновления"/')"
curl -H "Content-Type: application/json" -X POST https://api.telegram.org/bot$key/editMessageText -d "$(cat $pwd/update/curl | sed 's/"text":"~t~"/"text": "applying updates"/')"
git pull > ./update/message
fi
curl -H "Content-Type: application/json" -X POST https://api.telegram.org/bot$key/editMessageText -d "$(cat $pwd/update/curl | sed 's/"text":"~t~"/"text": "запускаю бота"/')"
curl -H "Content-Type: application/json" -X POST https://api.telegram.org/bot$key/editMessageText -d "$(cat $pwd/update/curl | sed 's/"text":"~t~"/"text": "launching the bot"/')"
IP=$(curl ipinfo.io/ip) VER=$(git describe --tags) docker compose --env-file ./.env --env-file ./override.env up -d --force-recreate
bash $pwd/update/update.sh &
> $pwd/update/key
+9
View File
@@ -1,3 +1,12 @@
15.11.2024 v1.101
- кнопка добавления https://github.com/legiz-ru/sb-rule-sets/raw/main/ru-bundle.lst
- переделан раздел списка ip для читаемости
15.11.2024 v1.100
- несколько режимов silence для сканера
- анализ сканера скидывает файл всех найденных айпи
- команда /searchLogs (пока только для айпи)
- логи переехали в меню сканера
- обновление текстов и подсказок
14.11.2024 v1.99.1
- анализ логов и бан айпишников, фиксы
14.11.2024 v1.99