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);
382 class_send_meminfo(sptr);
383 send_listinfo(sptr, parv[0]);
388 report_classes(sptr);
392 count_memory(sptr, parv[0]);
397 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
400 send_reply(sptr, RPL_ENDOFSTATS, stat);
405 * ms_stats - server message handler
407 * parv[0] = sender prefix
408 * parv[1] = statistics selector (defaults to Message frequency)
409 * parv[2] = target server (current server defaulted, if omitted)
410 * And 'stats l' and 'stats' L:
411 * parv[3] = server mask ("*" defaulted, if omitted)
413 * parv[3] = port mask (returns p-lines when its port is matched by this)
414 * Or for stats k,K,i and I:
415 * parv[3] = [user@]host.name (returns which K/I-lines match this)
416 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
417 * (defaults to old reply if ommitted, when local or Oper)
418 * A remote mask (something containing wildcards) is only
419 * allowed for IRC Operators.
421 * parv[3] = time param
422 * parv[4] = time param
423 * (see report_memleak_stats() in runmalloc.c for details)
425 * This function is getting really ugly. -Ghostwolf
427 int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
429 struct Message *mptr;
430 struct Client *acptr;
431 struct ConfItem *aconf;
432 char stat = parc > 1 ? parv[1][0] : '\0';
435 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
447 if (parc > 3 && !EmptyString(parv[3])) {
449 wilds = string_has_wildcards(name);
454 * Send info about connections which match, or all if the
455 * mask matches me.name. Only restrictions are on those who
456 * are invisible not being visible to 'foreigners' who use
457 * a wild card based search to list it.
459 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
460 "SendM SendKBytes RcveM RcveKBytes :Open since");
461 for (i = 0; i <= HighestFd; i++)
463 if (!(acptr = LocalClientArray[i]))
465 /* Don't return clients when this is a request for `all' */
466 if (doall && IsUser(acptr))
468 /* Don't show invisible people to unauthorized people when using
469 * wildcards -- Is this still needed now /stats is oper only ?
470 * Not here, because ms_stats is specifically a remote command,
471 * thus the check was removed. -Ghostwolf */
472 /* Only show the ones that match the given mask - if any */
473 if (!doall && wilds && match(name, acptr->name))
475 /* Skip all that do not match the specific query */
476 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
478 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
479 "%s %u %u %u %u %u :%Tu", acptr->name,
480 (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
481 (int)acptr->sendK, (int)acptr->receiveM,
482 (int)acptr->receiveK, CurrentTime - acptr->firsttime);
488 report_configured_links(sptr, CONF_SERVER);
491 case 'g': /* send glines */
496 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
499 case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
500 if (0 == report_klines(sptr, (parc > 3) ? parv[3] : 0, !IsOper(sptr)))
510 if (parc < 4 && IsOper(sptr)) {
511 report_configured_links(sptr, CONF_CLIENT);
514 if (parc < 4 || EmptyString(parv[3]))
515 return need_more_params(sptr, "STATS I");
518 wilds = string_has_wildcards(parv[3]);
524 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
525 if (CONF_CLIENT == aconf->status) {
526 if ((!wilds && (!match(aconf->host, host) ||
527 !match(aconf->name, host))) ||
528 (wilds && (!mmatch(host, aconf->host) ||
529 !mmatch(host, aconf->name))))
531 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
532 aconf->port, get_conf_class(aconf));
542 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
543 fda_get_block_count());
548 sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
549 me.name, parv[0], get_mem_size(), get_alloc_cnt());
552 report_memleak_stats(sptr, parc, parv);
554 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
555 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
556 "is not enabled on this server", me.name, parv[0]);
561 for (mptr = msgtab; mptr->cmd; mptr++)
563 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
568 report_configured_links(sptr, CONF_OPS);
573 * show listener ports
574 * show hidden ports to opers, if there are more than 3 parameters,
575 * interpret the fourth parameter as the port number, limit non-local
576 * or non-oper results to 8 ports.
578 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0, IsOper(sptr) ? 100 : 8);
583 send_usage(sptr, parv[0]);
587 report_crule_list(sptr, CRULE_ALL);
590 report_crule_list(sptr, CRULE_MASK);
593 tstats(sptr, parv[0]);
596 report_motd_list(sptr);
599 report_configured_links(sptr, CONF_UWORLD);
605 nowr = CurrentTime - me.since;
606 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
607 (nowr / 60) % 60, nowr % 60);
608 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
618 class_send_meminfo(sptr);
619 send_listinfo(sptr, parv[0]);
624 report_classes(sptr);
628 count_memory(sptr, parv[0]);
634 send_reply(sptr, RPL_ENDOFSTATS, stat);
639 * mo_stats - oper message handler
641 * parv[0] = sender prefix
642 * parv[1] = statistics selector (defaults to Message frequency)
643 * parv[2] = target server (current server defaulted, if omitted)
644 * And 'stats l' and 'stats' L:
645 * parv[3] = server mask ("*" defaulted, if omitted)
647 * parv[3] = port mask (returns p-lines when its port is matched by this)
648 * Or for stats k,K,i and I:
649 * parv[3] = [user@]host.name (returns which K/I-lines match this)
650 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
651 * (defaults to old reply if ommitted, when local or Oper)
652 * A remote mask (something containing wildcards) is only
653 * allowed for IRC Operators.
655 * parv[3] = time param
656 * parv[4] = time param
657 * (see report_memleak_stats() in runmalloc.c for details)
659 * This function is getting really ugly. -Ghostwolf
661 int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
663 struct Message* mptr;
664 struct Client* acptr;
665 struct ConfItem* aconf;
666 char stat = parc > 1 ? parv[1][0] : '\0';
667 const char** infotext = statsinfo;
670 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
678 int doall = 0, wilds = 0;
680 if (parc > 3 && !EmptyString(parv[3])) {
682 wilds = string_has_wildcards(name);
687 * Send info about connections which match, or all if the
688 * mask matches me.name. Only restrictions are on those who
689 * are invisible not being visible to 'foreigners' who use
690 * a wild card based search to list it.
692 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
693 "SendM SendKBytes RcveM RcveKBytes :Open since");
694 for (i = 0; i <= HighestFd; i++)
696 if (!(acptr = LocalClientArray[i]))
698 /* Don't return clients when this is a request for `all' */
699 if (doall && IsUser(acptr))
701 /* Only show the ones that match the given mask - if any */
702 if (!doall && wilds && match(name, acptr->name))
704 /* Skip all that do not match the specific query */
705 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
707 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
708 "%s %u %u %u %u %u :%Tu", acptr->name,
709 (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
710 (int)acptr->sendK, (int)acptr->receiveM,
711 (int)acptr->receiveK, CurrentTime - acptr->firsttime);
717 report_configured_links(sptr, CONF_SERVER);
720 case 'g': /* send glines */
725 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
728 case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
729 if (0 == report_klines(sptr, (parc > 3) ? parv[3] : 0, 0))
740 report_configured_links(sptr, CONF_CLIENT);
743 if (EmptyString(parv[3]))
744 return need_more_params(sptr, "STATS I");
747 wilds = string_has_wildcards(host);
749 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
750 if (CONF_CLIENT == aconf->status) {
751 if ((!wilds && (!match(aconf->host, host) ||
752 !match(aconf->name, host))) ||
753 (wilds && (!mmatch(host, aconf->host) ||
754 !mmatch(host, aconf->name))))
756 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
757 aconf->port, get_conf_class(aconf));
767 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
768 fda_get_block_count());
773 sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
774 me.name, parv[0], get_mem_size(), get_alloc_cnt());
777 report_memleak_stats(sptr, parc, parv);
779 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
780 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
781 "is not enabled on this server", me.name, parv[0]);
786 for (mptr = msgtab; mptr->cmd; mptr++)
788 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
793 report_configured_links(sptr, CONF_OPS);
798 * show listener ports
799 * show hidden ports to opers, if there are more than 3 parameters,
800 * interpret the fourth parameter as the port number, limit non-local
801 * or non-oper results to 8 ports.
803 show_ports(sptr, 1, (parc > 3) ? atoi(parv[3]) : 0, 100);
808 send_usage(sptr, parv[0]);
812 report_crule_list(sptr, CRULE_ALL);
815 report_crule_list(sptr, CRULE_MASK);
818 tstats(sptr, parv[0]);
821 report_motd_list(sptr);
824 report_configured_links(sptr, CONF_UWORLD);
830 nowr = CurrentTime - me.since;
831 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
832 (nowr / 60) % 60, nowr % 60);
833 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
843 class_send_meminfo(sptr);
844 send_listinfo(sptr, parv[0]);
849 report_classes(sptr);
853 count_memory(sptr, parv[0]);
858 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
861 send_reply(sptr, RPL_ENDOFSTATS, stat);