From 4999ae408ccc6d61af4f42744f39ed033a6dd345 Mon Sep 17 00:00:00 2001 From: Ron Nazarov Date: Sun, 30 Oct 2022 02:42:11 +0000 Subject: [PATCH] Add TLINE command Suggested by PeGaSuS in https://bugs.unrealircd.org/view.php?id=6174 --- Makefile.windows | 4 ++ doc/conf/help/help.conf | 27 ++++++++--- doc/conf/modules.default.conf | 1 + src/modules/Makefile.in | 2 +- src/modules/tline.c | 87 +++++++++++++++++++++++++++++++++++ 5 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 src/modules/tline.c diff --git a/Makefile.windows b/Makefile.windows index bbd8682bc..e9b98a1f0 100644 --- a/Makefile.windows +++ b/Makefile.windows @@ -379,6 +379,7 @@ DLL_FILES=\ src/modules/time.dll \ src/modules/tkl.dll \ src/modules/tkldb.dll \ + src/modules/tline.dll \ src/modules/tls_antidos.dll \ src/modules/tls_cipher.dll \ src/modules/topic.dll \ @@ -1224,6 +1225,9 @@ src/modules/tkl.dll: src/modules/tkl.c $(INCLUDES) src/modules/tkldb.dll: src/modules/tkldb.c $(INCLUDES) $(CC) $(MODCFLAGS) src/modules/tkldb.c /Fesrc/modules/ /Fosrc/modules/ /Fdsrc/modules/tkldb.pdb $(MODLFLAGS) +src/modules/tline.dll: src/modules/tline.c $(INCLUDES) + $(CC) $(MODCFLAGS) src/modules/tline.c /Fesrc/modules/ /Fosrc/modules/ /Fdsrc/modules/tline.pdb $(MODLFLAGS) + src/modules/tls_antidos.dll: src/modules/tls_antidos.c $(INCLUDES) $(CC) $(MODCFLAGS) src/modules/tls_antidos.c /Fesrc/modules/ /Fosrc/modules/ /Fdsrc/modules/tls_antidos.pdb $(MODLFLAGS) diff --git a/doc/conf/help/help.conf b/doc/conf/help/help.conf index e137d29f0..b066f5de9 100644 --- a/doc/conf/help/help.conf +++ b/doc/conf/help/help.conf @@ -59,12 +59,12 @@ help Opercmds { " ADDOMOTD GLINE OPERMOTD SPAMFILTER"; " GLOBOPS REHASH SQUIT"; " CHGHOST GZLINE RESTART TEMPSHUN"; - " CHGIDENT KILL TRACE"; - " CHGNAME KLINE SAJOIN TSCTL"; - " CLOSE LAG SAMODE UNDCCDENY"; - " CONNECT LOCOPS SAPART WALLOPS"; - " DCCDENY MKPASSWD SDESC ZLINE"; - " DIE MODULE SETHOST"; + " CHGIDENT KILL TLINE"; + " CHGNAME KLINE SAJOIN TRACE"; + " CLOSE LAG SAMODE TSCTL"; + " CONNECT LOCOPS SAPART UNDCCDENY"; + " DCCDENY MKPASSWD SDESC WALLOPS"; + " DIE MODULE SETHOST ZLINE"; " ==-------------------------oOo-------------------------=="; } @@ -1000,6 +1000,21 @@ help Eline { " S - SSL/TLS client certificate fingerprint"; } +help Tline { + " Shows number of clients matching a server ban mask."; + " IRC Operator only command."; + " Syntax: TLINE "; + " Example: TLINE *!*@127.0.0.0/8"; + " -"; + " Extended server bans (more info at https://www.unrealircd.org/docs/Extended_server_bans)"; + " Syntax: TLINE ~:"; + " Example: TLINE ~a:0"; + " Supported are:"; + " a - Services account name"; + " r - gecos/realname string"; + " S - SSL/TLS client certificate fingerprint"; +} + help Rehash { " Prompts the server to reread the configuration files."; " IRC Operator only command."; diff --git a/doc/conf/modules.default.conf b/doc/conf/modules.default.conf index edae95f6d..02552e68e 100644 --- a/doc/conf/modules.default.conf +++ b/doc/conf/modules.default.conf @@ -99,6 +99,7 @@ loadmodule "sethost"; loadmodule "setident"; loadmodule "stats"; loadmodule "tkl"; /* also server-to-server */ +loadmodule "tline"; loadmodule "trace"; loadmodule "tsctl"; loadmodule "unsqline"; diff --git a/src/modules/Makefile.in b/src/modules/Makefile.in index 7555b3807..67707f8e5 100644 --- a/src/modules/Makefile.in +++ b/src/modules/Makefile.in @@ -80,7 +80,7 @@ MODULES= \ monitor.so slog.so tls_cipher.so operinfo.so creationtime.so \ unreal_server_compat.so \ extended-monitor.so geoip_csv.so \ - geoip_base.so extjwt.so \ + geoip_base.so extjwt.so tline.so \ $(GEOIP_CLASSIC_OBJECTS) $(GEOIP_MAXMIND_OBJECTS) MODULEFLAGS=@MODULEFLAGS@ diff --git a/src/modules/tline.c b/src/modules/tline.c new file mode 100644 index 000000000..f00caec7d --- /dev/null +++ b/src/modules/tline.c @@ -0,0 +1,87 @@ +/* + * IRC - Internet Relay Chat, src/modules/tline.c + * (C) 2022 Noisytoot & The UnrealIRCd Team + * + * See file AUTHORS in IRC package for additional names of + * the programmers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "unrealircd.h" + +#define MSG_TLINE "TLINE" + +CMD_FUNC(cmd_tline); + +ModuleHeader MOD_HEADER + = { + "tline", + "1.0", + "TLINE command to show amount of clients matching a server ban mask", + "UnrealIRCd team", + "unrealircd-6", + }; + +MOD_INIT() +{ + CommandAdd(modinfo->handle, MSG_TLINE, cmd_tline, 1, CMD_OPER); + MARK_AS_OFFICIAL_MODULE(modinfo); + return MOD_SUCCESS; +} + +MOD_LOAD() +{ + return MOD_SUCCESS; +} + +MOD_UNLOAD() +{ + return MOD_SUCCESS; +} + +/* +** cmd_tline +** parv[1] = mask to test +*/ +CMD_FUNC(cmd_tline) +{ + Client *acptr; + int matching_lclients = 0; + int matching_clients = 0; + + if ((parc < 1) || BadPtr(parv[1])) + { + sendnumeric(client, ERR_NEEDMOREPARAMS, MSG_TLINE); + return; + } + + list_for_each_entry(acptr, &client_list, client_node) + { + if (match_user(parv[1], acptr, MATCH_CHECK_REAL)) + { + if (MyUser(acptr)) + matching_lclients++; + matching_clients++; + } + } + + sendnotice(client, + "*** TLINE: Users matching mask '%s': global: %d/%d (%.2f%%), local: %d/%d (%.2f%%).", + parv[1], matching_clients, irccounts.clients, + (double)matching_clients / irccounts.clients * 100, + matching_lclients, irccounts.me_clients, + (double)matching_lclients / irccounts.me_clients * 100); +}