2 * IRC - Internet Relay Chat, ircd/m_stats.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * See file AUTHORS in IRC package for additional names of
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 1, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * m_functions execute protocol messages on this server:
29 * cptr is always NON-NULL, pointing to a *LOCAL* client
30 * structure (with an open socket connected!). This
31 * identifies the physical socket where the message
32 * originated (or which caused the m_function to be
33 * executed--some m_functions may call others...).
35 * sptr is the source of the message, defined by the
36 * prefix part of the message if present. If not
37 * or prefix not found, then sptr==cptr.
39 * (!IsServer(cptr)) => (cptr == sptr), because
40 * prefixes are taken *only* from servers...
43 * (sptr == cptr) => the message didn't
46 * (sptr != cptr && IsServer(sptr) means
47 * the prefix specified servername. (?)
49 * (sptr != cptr && !IsServer(sptr) means
50 * that message originated from a remote
55 * (!IsServer(sptr)) means that, sptr can safely
56 * taken as defining the target structure of the
57 * message in this server.
59 * *Always* true (if 'parse' and others are working correct):
61 * 1) sptr->from == cptr (note: cptr->from == cptr)
63 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
64 * *cannot* be a local connection, unless it's
65 * actually cptr!). [MyConnect(x) should probably
66 * be defined as (x == x->from) --msa ]
68 * parc number of variable parameter strings (if zero,
69 * parv is allowed to be NULL)
71 * parv a NULL terminated list of parameter pointers,
73 * parv[0], sender (prefix string), if not present
74 * this points to an empty string.
75 * parv[1]...parv[parc-1]
76 * pointers to additional parameters
77 * parv[parc] == NULL, *always*
79 * note: it is guaranteed that parv[0]..parv[parc-1] are all
84 * No need to include handlers.h here the signatures must match
85 * and we don't need to force a rebuild of all the handlers everytime
86 * we add a new one to the list. --Bleep
100 #include "ircd_alloc.h"
101 #include "ircd_chattr.h"
102 #include "ircd_reply.h"
103 #include "ircd_string.h"
105 #include "listener.h"
109 #include "numnicks.h"
110 #include "opercmds.h"
119 #include "userload.h"
126 int report_klines(struct Client* sptr, char* mask, int limit_query)
132 const struct DenyConf* conf;
134 if (EmptyString(mask)) {
136 return need_more_params(sptr, "STATS K");
138 report_deny_list(sptr);
143 wilds = string_has_wildcards(mask);
147 if ((host = strchr(mask, '@'))) {
155 for (conf = conf_get_deny_list(); conf; conf = conf->next) {
156 if ((!wilds && ((user || conf->hostmask) &&
157 !match(conf->hostmask, host) &&
158 (!user || !match(conf->usermask, user)))) ||
159 (wilds && !mmatch(host, conf->hostmask) &&
160 (!user || !mmatch(user, conf->usermask))))
162 send_reply(sptr, RPL_STATSKLINE, (conf->ip_kill) ? 'k' : 'K',
163 conf->hostmask, conf->message, conf->usermask);
168 /* send_reply(sptr, RPL_ENDOFSTATS, stat); */
174 * m_stats - generic message handler
176 * parv[0] = sender prefix
177 * parv[1] = statistics selector (defaults to Message frequency)
178 * parv[2] = target server (current server defaulted, if omitted)
179 * And 'stats l' and 'stats' L:
180 * parv[3] = server mask ("*" defaulted, if omitted)
182 * parv[3] = port mask (returns p-lines when its port is matched by this)
183 * Or for stats k,K,i and I:
184 * parv[3] = [user@]host.name (returns which K/I-lines match this)
185 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
186 * (defaults to old reply if ommitted, when local or Oper)
187 * A remote mask (something containing wildcards) is only
188 * allowed for IRC Operators.
190 * parv[3] = time param
191 * parv[4] = time param
192 * (see report_memleak_stats() in runmalloc.c for details)
194 * This function is getting really ugly. -Ghostwolf
196 int m_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
198 struct Message *mptr;
199 struct Client *acptr;
200 struct ConfItem *aconf;
201 char stat = parc > 1 ? parv[1][0] : '\0';
202 const char **infotext = statsinfo;
205 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
217 if (parc > 3 && !EmptyString(parv[3])) {
219 wilds = string_has_wildcards(name);
224 * Send info about connections which match, or all if the
225 * mask matches me.name. Only restrictions are on those who
226 * are invisible not being visible to 'foreigners' who use
227 * a wild card based search to list it.
229 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
230 "SendM SendKBytes RcveM RcveKBytes :Open since");
231 for (i = 0; i <= HighestFd; i++)
233 if (!(acptr = LocalClientArray[i]))
235 /* Don't return clients when this is a request for `all' */
236 if (doall && IsUser(acptr))
238 /* Don't show invisible people to non opers unless they know the nick */
239 if (IsInvisible(acptr) && (doall || wilds) && !IsAnOper(acptr) && (acptr != sptr))
241 /* Only show the ones that match the given mask - if any */
242 if (!doall && wilds && match(name, acptr->name))
244 /* Skip all that do not match the specific query */
245 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
247 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
248 "%s %u %u %u %u %u :%Tu", (*acptr->name) ? acptr->name : "<unregistered>",
249 (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
250 (int)acptr->sendK, (int)acptr->receiveM,
251 (int)acptr->receiveK, CurrentTime - acptr->firsttime);
257 report_configured_links(sptr, CONF_SERVER);
260 case 'g': /* send glines */
265 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
268 case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
269 if (0 == report_klines(sptr, (parc == 4) ? parv[3] : 0, 0))
280 report_configured_links(sptr, CONF_CLIENT);
283 if (EmptyString(parv[3]))
284 return need_more_params(sptr, "STATS I");
287 wilds = string_has_wildcards(host);
289 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
290 if (CONF_CLIENT == aconf->status) {
291 if ((!wilds && (!match(aconf->host, host) ||
292 !match(aconf->name, host))) ||
293 (wilds && (!mmatch(host, aconf->host) ||
294 !mmatch(host, aconf->name))))
296 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
297 aconf->port, get_conf_class(aconf));
307 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
308 fda_get_block_count());
313 sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
314 me.name, parv[0], get_mem_size(), get_alloc_cnt());
317 report_memleak_stats(sptr, parc, parv);
319 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
320 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
321 "is not enabled on this server", me.name, parv[0]);
326 for (mptr = msgtab; mptr->cmd; mptr++)
328 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
333 report_configured_links(sptr, CONF_OPS);
338 * show listener ports
339 * show hidden ports to opers, if there are more than 3 parameters,
340 * interpret the fourth parameter as the port number.
342 show_ports(sptr, 0, (parc > 3) ? atoi(parv[3]) : 0, 100);
347 send_usage(sptr, parv[0]);
351 report_crule_list(sptr, CRULE_ALL);
354 report_crule_list(sptr, CRULE_MASK);
357 tstats(sptr, parv[0]);
360 report_motd_list(sptr);
363 report_configured_links(sptr, CONF_UWORLD);
369 nowr = CurrentTime - me.since;
370 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
371 (nowr / 60) % 60, nowr % 60);
372 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
377 const struct ConnectionClass* cl = get_class_list();
379 for ( ; cl; cl = cl->next) {
381 send_reply(sptr, RPL_TRACECLASS, ConClass(cl), Links(cl));
392 class_send_meminfo(sptr);
393 send_listinfo(sptr, parv[0]);
398 report_classes(sptr);
402 count_memory(sptr, parv[0]);
407 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
410 send_reply(sptr, RPL_ENDOFSTATS, stat);
415 * ms_stats - server message handler
417 * parv[0] = sender prefix
418 * parv[1] = statistics selector (defaults to Message frequency)
419 * parv[2] = target server (current server defaulted, if omitted)
420 * And 'stats l' and 'stats' L:
421 * parv[3] = server mask ("*" defaulted, if omitted)
423 * parv[3] = port mask (returns p-lines when its port is matched by this)
424 * Or for stats k,K,i and I:
425 * parv[3] = [user@]host.name (returns which K/I-lines match this)
426 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
427 * (defaults to old reply if ommitted, when local or Oper)
428 * A remote mask (something containing wildcards) is only
429 * allowed for IRC Operators.
431 * parv[3] = time param
432 * parv[4] = time param
433 * (see report_memleak_stats() in runmalloc.c for details)
435 * This function is getting really ugly. -Ghostwolf
437 int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
439 struct Message *mptr;
440 struct Client *acptr;
441 struct ConfItem *aconf;
442 char stat = parc > 1 ? parv[1][0] : '\0';
445 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
457 if (parc > 3 && !EmptyString(parv[3])) {
459 wilds = string_has_wildcards(name);
464 * Send info about connections which match, or all if the
465 * mask matches me.name. Only restrictions are on those who
466 * are invisible not being visible to 'foreigners' who use
467 * a wild card based search to list it.
469 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
470 "SendM SendKBytes RcveM RcveKBytes :Open since");
471 for (i = 0; i <= HighestFd; i++)
473 if (!(acptr = LocalClientArray[i]))
475 /* Don't return clients when this is a request for `all' */
476 if (doall && IsUser(acptr))
478 /* Don't show invisible people to unauthorized people when using
479 * wildcards -- Is this still needed now /stats is oper only ?
480 * Not here, because ms_stats is specifically a remote command,
481 * thus the check was removed. -Ghostwolf */
482 /* Only show the ones that match the given mask - if any */
483 if (!doall && wilds && match(name, acptr->name))
485 /* Skip all that do not match the specific query */
486 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
488 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
489 "%s %u %u %u %u %u :%Tu", acptr->name,
490 (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
491 (int)acptr->sendK, (int)acptr->receiveM,
492 (int)acptr->receiveK, CurrentTime - acptr->firsttime);
498 report_configured_links(sptr, CONF_SERVER);
501 case 'g': /* send glines */
506 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
509 case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
510 if (0 == report_klines(sptr, (parc > 3) ? parv[3] : 0, !IsOper(sptr)))
520 if (parc < 4 && IsOper(sptr)) {
521 report_configured_links(sptr, CONF_CLIENT);
524 if (parc < 4 || EmptyString(parv[3]))
525 return need_more_params(sptr, "STATS I");
528 wilds = string_has_wildcards(parv[3]);
534 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
535 if (CONF_CLIENT == aconf->status) {
536 if ((!wilds && (!match(aconf->host, host) ||
537 !match(aconf->name, host))) ||
538 (wilds && (!mmatch(host, aconf->host) ||
539 !mmatch(host, aconf->name))))
541 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
542 aconf->port, get_conf_class(aconf));
552 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
553 fda_get_block_count());
558 sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
559 me.name, parv[0], get_mem_size(), get_alloc_cnt());
562 report_memleak_stats(sptr, parc, parv);
564 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
565 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
566 "is not enabled on this server", me.name, parv[0]);
571 for (mptr = msgtab; mptr->cmd; mptr++)
573 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
578 report_configured_links(sptr, CONF_OPS);
583 * show listener ports
584 * show hidden ports to opers, if there are more than 3 parameters,
585 * interpret the fourth parameter as the port number, limit non-local
586 * or non-oper results to 8 ports.
588 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0, IsOper(sptr) ? 100 : 8);
593 send_usage(sptr, parv[0]);
597 report_crule_list(sptr, CRULE_ALL);
600 report_crule_list(sptr, CRULE_MASK);
603 tstats(sptr, parv[0]);
606 report_motd_list(sptr);
609 report_configured_links(sptr, CONF_UWORLD);
615 nowr = CurrentTime - me.since;
616 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
617 (nowr / 60) % 60, nowr % 60);
618 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
623 const struct ConnectionClass* cl = get_class_list();
625 for ( ; cl; cl = cl->next) {
627 send_reply(sptr, RPL_TRACECLASS, ConClass(cl), Links(cl));
639 class_send_meminfo(sptr);
640 send_listinfo(sptr, parv[0]);
645 report_classes(sptr);
649 count_memory(sptr, parv[0]);
655 send_reply(sptr, RPL_ENDOFSTATS, stat);
660 * mo_stats - oper message handler
662 * parv[0] = sender prefix
663 * parv[1] = statistics selector (defaults to Message frequency)
664 * parv[2] = target server (current server defaulted, if omitted)
665 * And 'stats l' and 'stats' L:
666 * parv[3] = server mask ("*" defaulted, if omitted)
668 * parv[3] = port mask (returns p-lines when its port is matched by this)
669 * Or for stats k,K,i and I:
670 * parv[3] = [user@]host.name (returns which K/I-lines match this)
671 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
672 * (defaults to old reply if ommitted, when local or Oper)
673 * A remote mask (something containing wildcards) is only
674 * allowed for IRC Operators.
676 * parv[3] = time param
677 * parv[4] = time param
678 * (see report_memleak_stats() in runmalloc.c for details)
680 * This function is getting really ugly. -Ghostwolf
682 int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
684 struct Message* mptr;
685 struct Client* acptr;
686 struct ConfItem* aconf;
687 char stat = parc > 1 ? parv[1][0] : '\0';
688 const char** infotext = statsinfo;
691 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
699 int doall = 0, wilds = 0;
701 if (parc > 3 && !EmptyString(parv[3])) {
703 wilds = string_has_wildcards(name);
708 * Send info about connections which match, or all if the
709 * mask matches me.name. Only restrictions are on those who
710 * are invisible not being visible to 'foreigners' who use
711 * a wild card based search to list it.
713 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
714 "SendM SendKBytes RcveM RcveKBytes :Open since");
715 for (i = 0; i <= HighestFd; i++)
717 if (!(acptr = LocalClientArray[i]))
719 /* Don't return clients when this is a request for `all' */
720 if (doall && IsUser(acptr))
722 /* Only show the ones that match the given mask - if any */
723 if (!doall && wilds && match(name, acptr->name))
725 /* Skip all that do not match the specific query */
726 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
728 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
729 "%s %u %u %u %u %u :%Tu", acptr->name,
730 (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
731 (int)acptr->sendK, (int)acptr->receiveM,
732 (int)acptr->receiveK, CurrentTime - acptr->firsttime);
738 report_configured_links(sptr, CONF_SERVER);
741 case 'g': /* send glines */
746 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
749 case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
750 if (0 == report_klines(sptr, (parc > 3) ? parv[3] : 0, 0))
761 report_configured_links(sptr, CONF_CLIENT);
764 if (EmptyString(parv[3]))
765 return need_more_params(sptr, "STATS I");
768 wilds = string_has_wildcards(host);
770 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
771 if (CONF_CLIENT == aconf->status) {
772 if ((!wilds && (!match(aconf->host, host) ||
773 !match(aconf->name, host))) ||
774 (wilds && (!mmatch(host, aconf->host) ||
775 !mmatch(host, aconf->name))))
777 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
778 aconf->port, get_conf_class(aconf));
788 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
789 fda_get_block_count());
794 sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
795 me.name, parv[0], get_mem_size(), get_alloc_cnt());
798 report_memleak_stats(sptr, parc, parv);
800 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
801 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
802 "is not enabled on this server", me.name, parv[0]);
807 for (mptr = msgtab; mptr->cmd; mptr++)
809 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
814 report_configured_links(sptr, CONF_OPS);
819 * show listener ports
820 * show hidden ports to opers, if there are more than 3 parameters,
821 * interpret the fourth parameter as the port number, limit non-local
822 * or non-oper results to 8 ports.
824 show_ports(sptr, 1, (parc > 3) ? atoi(parv[3]) : 0, 100);
829 send_usage(sptr, parv[0]);
833 report_crule_list(sptr, CRULE_ALL);
836 report_crule_list(sptr, CRULE_MASK);
839 tstats(sptr, parv[0]);
842 report_motd_list(sptr);
845 report_configured_links(sptr, CONF_UWORLD);
851 nowr = CurrentTime - me.since;
852 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
853 (nowr / 60) % 60, nowr % 60);
854 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
859 const struct ConnectionClass* cl = get_class_list();
861 for ( ; cl; cl = cl->next) {
863 send_reply(sptr, RPL_TRACECLASS, ConClass(cl), Links(cl));
874 class_send_meminfo(sptr);
875 send_listinfo(sptr, parv[0]);
880 report_classes(sptr);
884 count_memory(sptr, parv[0]);
889 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
892 send_reply(sptr, RPL_ENDOFSTATS, stat);