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"
110 #include "numnicks.h"
111 #include "opercmds.h"
120 #include "userload.h"
127 int report_klines(struct Client* sptr, char* mask, int limit_query)
133 const struct DenyConf* conf;
135 if (EmptyString(mask)) {
137 return need_more_params(sptr, "STATS K");
139 report_deny_list(sptr);
144 wilds = string_has_wildcards(mask);
148 if ((host = strchr(mask, '@'))) {
156 for (conf = conf_get_deny_list(); conf; conf = conf->next) {
157 if ((!wilds && ((user || conf->hostmask) &&
158 !match(conf->hostmask, host) &&
159 (!user || !match(conf->usermask, user)))) ||
160 (wilds && !mmatch(host, conf->hostmask) &&
161 (!user || !mmatch(user, conf->usermask))))
163 send_reply(sptr, RPL_STATSKLINE, (conf->ip_kill) ? 'k' : 'K',
164 conf->hostmask, conf->message, conf->usermask);
169 /* send_reply(sptr, RPL_ENDOFSTATS, stat); */
175 * m_stats - generic message handler
177 * parv[0] = sender prefix
178 * parv[1] = statistics selector (defaults to Message frequency)
179 * parv[2] = target server (current server defaulted, if omitted)
180 * And 'stats l' and 'stats' L:
181 * parv[3] = server mask ("*" defaulted, if omitted)
183 * parv[3] = port mask (returns p-lines when its port is matched by this)
184 * Or for stats k,K,i and I:
185 * parv[3] = [user@]host.name (returns which K/I-lines match this)
186 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
187 * (defaults to old reply if ommitted, when local or Oper)
188 * A remote mask (something containing wildcards) is only
189 * allowed for IRC Operators.
191 * parv[3] = time param
192 * parv[4] = time param
193 * (see report_memleak_stats() in runmalloc.c for details)
195 * This function is getting really ugly. -Ghostwolf
197 int m_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
199 struct Message *mptr;
200 struct Client *acptr;
201 struct ConfItem *aconf;
202 char stat = parc > 1 ? parv[1][0] : '\0';
203 const char **infotext = statsinfo;
206 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
218 if (parc > 3 && !EmptyString(parv[3])) {
220 wilds = string_has_wildcards(name);
225 * Send info about connections which match, or all if the
226 * mask matches me.name. Only restrictions are on those who
227 * are invisible not being visible to 'foreigners' who use
228 * a wild card based search to list it.
230 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
231 "SendM SendKBytes RcveM RcveKBytes :Open since");
232 for (i = 0; i <= HighestFd; i++)
234 if (!(acptr = LocalClientArray[i]))
236 /* Don't return clients when this is a request for `all' */
237 if (doall && IsUser(acptr))
239 /* Don't show invisible people to non opers unless they know the nick */
240 if (IsInvisible(acptr) && (doall || wilds) && !IsAnOper(acptr) && (acptr != sptr))
242 /* Only show the ones that match the given mask - if any */
243 if (!doall && wilds && match(name, cli_name(acptr)))
245 /* Skip all that do not match the specific query */
246 if (!(doall || wilds) && 0 != ircd_strcmp(name, cli_name(acptr)))
248 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
249 "%s %u %u %u %u %u :%Tu", (*(cli_name(acptr))) ? cli_name(acptr) : "<unregistered>",
250 (int)MsgQLength(&(cli_sendQ(acptr))), (int)cli_sendM(acptr),
251 (int)cli_sendK(acptr), (int)cli_receiveM(acptr),
252 (int)cli_receiveK(acptr), CurrentTime - cli_firsttime(acptr));
258 report_configured_links(sptr, CONF_SERVER);
261 case 'g': /* send glines */
266 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
269 case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
270 if (0 == report_klines(sptr, (parc == 4) ? parv[3] : 0, 0))
275 report_feature_list(sptr);
285 report_configured_links(sptr, CONF_CLIENT);
288 if (EmptyString(parv[3]))
289 return need_more_params(sptr, "STATS I");
292 wilds = string_has_wildcards(host);
294 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
295 if (CONF_CLIENT == aconf->status) {
296 if ((!wilds && (!match(aconf->host, host) ||
297 !match(aconf->name, host))) ||
298 (wilds && (!mmatch(host, aconf->host) ||
299 !mmatch(host, aconf->name))))
301 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
302 aconf->port, get_conf_class(aconf));
312 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
313 fda_get_block_count());
317 for (mptr = msgtab; mptr->cmd; mptr++)
319 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
324 report_configured_links(sptr, CONF_OPS);
329 * show listener ports
330 * show hidden ports to opers, if there are more than 3 parameters,
331 * interpret the fourth parameter as the port number.
333 show_ports(sptr, 0, (parc > 3) ? atoi(parv[3]) : 0, 100);
338 send_usage(sptr, parv[0]);
342 report_crule_list(sptr, CRULE_ALL);
345 report_crule_list(sptr, CRULE_MASK);
348 tstats(sptr, parv[0]);
354 report_configured_links(sptr, CONF_UWORLD);
360 nowr = CurrentTime - cli_since(&me);
361 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
362 (nowr / 60) % 60, nowr % 60);
363 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
373 class_send_meminfo(sptr);
374 send_listinfo(sptr, parv[0]);
379 report_classes(sptr);
383 count_memory(sptr, parv[0]);
388 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
391 send_reply(sptr, RPL_ENDOFSTATS, stat);
396 * ms_stats - server message handler
398 * parv[0] = sender prefix
399 * parv[1] = statistics selector (defaults to Message frequency)
400 * parv[2] = target server (current server defaulted, if omitted)
401 * And 'stats l' and 'stats' L:
402 * parv[3] = server mask ("*" defaulted, if omitted)
404 * parv[3] = port mask (returns p-lines when its port is matched by this)
405 * Or for stats k,K,i and I:
406 * parv[3] = [user@]host.name (returns which K/I-lines match this)
407 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
408 * (defaults to old reply if ommitted, when local or Oper)
409 * A remote mask (something containing wildcards) is only
410 * allowed for IRC Operators.
412 * parv[3] = time param
413 * parv[4] = time param
414 * (see report_memleak_stats() in runmalloc.c for details)
416 * This function is getting really ugly. -Ghostwolf
418 int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
420 struct Message *mptr;
421 struct Client *acptr;
422 struct ConfItem *aconf;
423 char stat = parc > 1 ? parv[1][0] : '\0';
426 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
438 if (parc > 3 && !EmptyString(parv[3])) {
440 wilds = string_has_wildcards(name);
445 * Send info about connections which match, or all if the
446 * mask matches me.name. Only restrictions are on those who
447 * are invisible not being visible to 'foreigners' who use
448 * a wild card based search to list it.
450 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
451 "SendM SendKBytes RcveM RcveKBytes :Open since");
452 for (i = 0; i <= HighestFd; i++)
454 if (!(acptr = LocalClientArray[i]))
456 /* Don't return clients when this is a request for `all' */
457 if (doall && IsUser(acptr))
459 /* Don't show invisible people to unauthorized people when using
460 * wildcards -- Is this still needed now /stats is oper only ?
461 * Not here, because ms_stats is specifically a remote command,
462 * thus the check was removed. -Ghostwolf */
463 /* Only show the ones that match the given mask - if any */
464 if (!doall && wilds && match(name, cli_name(acptr)))
466 /* Skip all that do not match the specific query */
467 if (!(doall || wilds) && 0 != ircd_strcmp(name, cli_name(acptr)))
469 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
470 "%s %u %u %u %u %u :%Tu", cli_name(acptr),
471 (int)MsgQLength(&(cli_sendQ(acptr))), (int)cli_sendM(acptr),
472 (int)cli_sendK(acptr), (int)cli_receiveM(acptr),
473 (int)cli_receiveK(acptr), CurrentTime - cli_firsttime(acptr));
479 report_configured_links(sptr, CONF_SERVER);
482 case 'g': /* send glines */
487 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
490 case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
491 if (0 == report_klines(sptr, (parc > 3) ? parv[3] : 0, !IsOper(sptr)))
496 report_feature_list(sptr);
505 if (parc < 4 && IsOper(sptr)) {
506 report_configured_links(sptr, CONF_CLIENT);
509 if (parc < 4 || EmptyString(parv[3]))
510 return need_more_params(sptr, "STATS I");
513 wilds = string_has_wildcards(parv[3]);
519 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
520 if (CONF_CLIENT == aconf->status) {
521 if ((!wilds && (!match(aconf->host, host) ||
522 !match(aconf->name, host))) ||
523 (wilds && (!mmatch(host, aconf->host) ||
524 !mmatch(host, aconf->name))))
526 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
527 aconf->port, get_conf_class(aconf));
537 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
538 fda_get_block_count());
542 for (mptr = msgtab; mptr->cmd; mptr++)
544 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
549 report_configured_links(sptr, CONF_OPS);
554 * show listener ports
555 * show hidden ports to opers, if there are more than 3 parameters,
556 * interpret the fourth parameter as the port number, limit non-local
557 * or non-oper results to 8 ports.
559 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0, IsOper(sptr) ? 100 : 8);
564 send_usage(sptr, parv[0]);
568 report_crule_list(sptr, CRULE_ALL);
571 report_crule_list(sptr, CRULE_MASK);
574 tstats(sptr, parv[0]);
580 report_configured_links(sptr, CONF_UWORLD);
586 nowr = CurrentTime - cli_since(&me);
587 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
588 (nowr / 60) % 60, nowr % 60);
589 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
599 class_send_meminfo(sptr);
600 send_listinfo(sptr, parv[0]);
605 report_classes(sptr);
609 count_memory(sptr, parv[0]);
615 send_reply(sptr, RPL_ENDOFSTATS, stat);
620 * mo_stats - oper message handler
622 * parv[0] = sender prefix
623 * parv[1] = statistics selector (defaults to Message frequency)
624 * parv[2] = target server (current server defaulted, if omitted)
625 * And 'stats l' and 'stats' L:
626 * parv[3] = server mask ("*" defaulted, if omitted)
628 * parv[3] = port mask (returns p-lines when its port is matched by this)
629 * Or for stats k,K,i and I:
630 * parv[3] = [user@]host.name (returns which K/I-lines match this)
631 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
632 * (defaults to old reply if ommitted, when local or Oper)
633 * A remote mask (something containing wildcards) is only
634 * allowed for IRC Operators.
636 * parv[3] = time param
637 * parv[4] = time param
638 * (see report_memleak_stats() in runmalloc.c for details)
640 * This function is getting really ugly. -Ghostwolf
642 int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
644 struct Message* mptr;
645 struct Client* acptr;
646 struct ConfItem* aconf;
647 char stat = parc > 1 ? parv[1][0] : '\0';
648 const char** infotext = statsinfo;
651 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
659 int doall = 0, wilds = 0;
661 if (parc > 3 && !EmptyString(parv[3])) {
663 wilds = string_has_wildcards(name);
668 * Send info about connections which match, or all if the
669 * mask matches me.name. Only restrictions are on those who
670 * are invisible not being visible to 'foreigners' who use
671 * a wild card based search to list it.
673 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
674 "SendM SendKBytes RcveM RcveKBytes :Open since");
675 for (i = 0; i <= HighestFd; i++)
677 if (!(acptr = LocalClientArray[i]))
679 /* Don't return clients when this is a request for `all' */
680 if (doall && IsUser(acptr))
682 /* Only show the ones that match the given mask - if any */
683 if (!doall && wilds && match(name, cli_name(acptr)))
685 /* Skip all that do not match the specific query */
686 if (!(doall || wilds) && 0 != ircd_strcmp(name, cli_name(acptr)))
688 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
689 "%s %u %u %u %u %u :%Tu", cli_name(acptr),
690 (int)MsgQLength(&(cli_sendQ(acptr))), (int)cli_sendM(acptr),
691 (int)cli_sendK(acptr), (int)cli_receiveM(acptr),
692 (int)cli_receiveK(acptr), CurrentTime - cli_firsttime(acptr));
698 report_configured_links(sptr, CONF_SERVER);
701 case 'g': /* send glines */
706 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
709 case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
710 if (0 == report_klines(sptr, (parc > 3) ? parv[3] : 0, 0))
715 report_feature_list(sptr);
725 report_configured_links(sptr, CONF_CLIENT);
728 if (EmptyString(parv[3]))
729 return need_more_params(sptr, "STATS I");
732 wilds = string_has_wildcards(host);
734 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
735 if (CONF_CLIENT == aconf->status) {
736 if ((!wilds && (!match(aconf->host, host) ||
737 !match(aconf->name, host))) ||
738 (wilds && (!mmatch(host, aconf->host) ||
739 !mmatch(host, aconf->name))))
741 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
742 aconf->port, get_conf_class(aconf));
752 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
753 fda_get_block_count());
757 for (mptr = msgtab; mptr->cmd; mptr++)
759 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
764 report_configured_links(sptr, CONF_OPS);
769 * show listener ports
770 * show hidden ports to opers, if there are more than 3 parameters,
771 * interpret the fourth parameter as the port number, limit non-local
772 * or non-oper results to 8 ports.
774 show_ports(sptr, 1, (parc > 3) ? atoi(parv[3]) : 0, 100);
779 send_usage(sptr, parv[0]);
783 report_crule_list(sptr, CRULE_ALL);
786 report_crule_list(sptr, CRULE_MASK);
789 tstats(sptr, parv[0]);
795 report_configured_links(sptr, CONF_UWORLD);
801 nowr = CurrentTime - cli_since(&me);
802 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
803 (nowr / 60) % 60, nowr % 60);
804 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
814 class_send_meminfo(sptr);
815 send_listinfo(sptr, parv[0]);
820 report_classes(sptr);
824 count_memory(sptr, parv[0]);
829 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
832 send_reply(sptr, RPL_ENDOFSTATS, stat);