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
99 #include "ircd_alloc.h"
100 #include "ircd_chattr.h"
101 #include "ircd_reply.h"
102 #include "ircd_string.h"
104 #include "listener.h"
108 #include "numnicks.h"
109 #include "opercmds.h"
118 #include "userload.h"
125 * m_stats - generic message handler
127 * parv[0] = sender prefix
128 * parv[1] = statistics selector (defaults to Message frequency)
129 * parv[2] = target server (current server defaulted, if omitted)
130 * And 'stats l' and 'stats' L:
131 * parv[3] = server mask ("*" defaulted, if omitted)
133 * parv[3] = port mask (returns p-lines when its port is matched by this)
134 * Or for stats k,K,i and I:
135 * parv[3] = [user@]host.name (returns which K/I-lines match this)
136 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
137 * (defaults to old reply if ommitted, when local or Oper)
138 * A remote mask (something containing wildcards) is only
139 * allowed for IRC Operators.
141 * parv[3] = time param
142 * parv[4] = time param
143 * (see report_memleak_stats() in runmalloc.c for details)
145 * This function is getting really ugly. -Ghostwolf
147 int m_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
149 static char Sformat[] = ":%s %d %s Connection SendQ SendM SendKBytes "
150 "RcveM RcveKBytes :Open since";
151 static char Lformat[] = ":%s %d %s %s %u %u %u %u %u :" TIME_T_FMT;
152 struct Message *mptr;
153 struct Client *acptr;
155 struct ConfItem *aconf;
156 char stat = parc > 1 ? parv[1][0] : '\0';
159 /* m_stats is so obnoxiously full of special cases that the different
160 * hunt_server() possiblites were becoming very messy. It now uses a
161 * switch() so as to be easier to read and update as params change.
166 /* open to all, standard # of params */
170 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
176 /* open to all, varying # of params */
186 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv)
192 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
199 /* oper only, varying # of params */
206 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv)
212 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s %s :%s", 2, parc,
213 parv) != HUNTED_ISME)
216 else if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
222 /* oper only, standard # of params */
225 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
237 int doall = 0, wilds = 0;
239 if (parc > 3 && *parv[3])
243 wilds = (*name == '*' || *name == '?');
244 for (p = name + 1; *p; ++p)
245 if ((*p == '*' || *p == '?') && p[-1] != '\\')
254 * Send info about connections which match, or all if the
255 * mask matches me.name. Only restrictions are on those who
256 * are invisible not being visible to 'foreigners' who use
257 * a wild card based search to list it.
259 sendto_one(sptr, Sformat, me.name, RPL_STATSLINKINFO, parv[0]);
260 for (i = 0; i <= HighestFd; i++)
262 if (!(acptr = LocalClientArray[i]))
264 /* Don't return clients when this is a request for `all' */
265 if (doall && IsUser(acptr))
267 /* Don't show invisible people to unauthorized people when using
268 * wildcards -- Is this still needed now /stats is oper only ? */
269 if (IsInvisible(acptr) && (doall || wilds) &&
270 !(MyConnect(sptr) && IsOper(sptr)) &&
271 !IsAnOper(acptr) && (acptr != sptr))
273 /* Only show the ones that match the given mask - if any */
274 if (!doall && wilds && match(name, acptr->name))
276 /* Skip all that do not match the specific query */
277 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
279 sendto_one(sptr, Lformat, me.name, RPL_STATSLINKINFO, parv[0],
280 acptr->name, (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
281 (int)acptr->sendK, (int)acptr->receiveM, (int)acptr->receiveK,
282 CurrentTime - acptr->firsttime);
288 report_configured_links(sptr, CONF_SERVER);
291 case 'g': /* send glines */
292 gline_remove_expired(TStime());
293 for (gline = GlobalGlineList; gline; gline = gline->next) {
294 sendto_one(sptr, rpl_str(RPL_STATSGLINE), me.name,
295 sptr->name, 'G', gline->name, gline->host,
296 gline->expire, gline->reason);
305 case 'k': /* display CONF_IPKILL as well
309 char *user, *host, *p;
310 int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
311 if ((MyUser(sptr) || IsOper(sptr)) && parc < 4)
313 report_configured_links(sptr, conf_status);
316 if (parc < 4 || *parv[3] == '\0')
317 return need_more_params(sptr,
318 (conf_status & CONF_KLINE) ? "STATS K" : "STATS I");
321 for (p = parv[3]; *p; p++)
329 if (*p == '?' || *p == '*')
335 if (!(MyConnect(sptr) || IsOper(sptr)))
343 if (conf_status == CONF_CLIENT)
345 user = 0; /* Not used, but to avoid compiler warning. */
351 if ((host = strchr(parv[3], '@')))
362 for (aconf = GlobalConfList; aconf; aconf = aconf->next)
364 if ((aconf->status & conf_status))
366 if (conf_status == CONF_KLINE)
368 if ((!wilds && ((user || aconf->host[1]) &&
369 !match(aconf->host, host) &&
370 (!user || !match(aconf->name, user)))) ||
371 (wilds && !mmatch(host, aconf->host) &&
372 (!user || !mmatch(user, aconf->name))))
374 sendto_one(sptr, rpl_str(RPL_STATSKLINE), me.name,
375 sptr->name, 'K', aconf->host, aconf->passwd, aconf->name,
376 aconf->port, get_conf_class(aconf));
381 else if (conf_status == CONF_CLIENT)
383 if ((!wilds && (!match(aconf->host, host) ||
384 !match(aconf->name, host))) ||
385 (wilds && (!mmatch(host, aconf->host) ||
386 !mmatch(host, aconf->name))))
388 sendto_one(sptr, rpl_str(RPL_STATSILINE), me.name,
389 sptr->name, 'I', aconf->host, aconf->name,
390 aconf->port, get_conf_class(aconf));
401 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
402 me.name, parv[0], fda_get_byte_count(), fda_get_block_count());
407 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
408 me.name, parv[0], get_mem_size(), get_alloc_cnt());
411 report_memleak_stats(sptr, parc, parv);
413 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
414 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring "
415 "is not enabled on this server", me.name, parv[0]);
420 for (mptr = msgtab; mptr->cmd; mptr++)
422 sendto_one(sptr, rpl_str(RPL_STATSCOMMANDS),
423 me.name, parv[0], mptr->cmd, mptr->count, mptr->bytes);
427 report_configured_links(sptr, CONF_OPS);
432 * show listener ports
433 * show hidden ports to opers, if there are more than 3 parameters,
434 * interpret the fourth parameter as the port number, limit non-local
435 * or non-oper results to 8 ports.
437 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0,
438 (MyUser(sptr) || IsOper(sptr)) ? 100 : 8);
443 send_usage(sptr, parv[0]);
447 report_configured_links(sptr, CONF_CRULEALL);
450 report_configured_links(sptr, CONF_CRULE);
453 tstats(sptr, parv[0]);
456 report_configured_links(sptr, CONF_TLINES);
459 report_configured_links(sptr, CONF_UWORLD);
465 nowr = CurrentTime - me.since;
466 sendto_one(sptr, rpl_str(RPL_STATSUPTIME), me.name, parv[0],
467 nowr / 86400, (nowr / 3600) % 24, (nowr / 60) % 60, nowr % 60);
468 sendto_one(sptr, rpl_str(RPL_STATSCONN), me.name, parv[0],
469 max_connection_count, max_client_count);
479 send_listinfo(sptr, parv[0]);
484 report_classes(sptr);
488 count_memory(sptr, parv[0]);
494 sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, parv[0], stat);
499 * ms_stats - server message handler
501 * parv[0] = sender prefix
502 * parv[1] = statistics selector (defaults to Message frequency)
503 * parv[2] = target server (current server defaulted, if omitted)
504 * And 'stats l' and 'stats' L:
505 * parv[3] = server mask ("*" defaulted, if omitted)
507 * parv[3] = port mask (returns p-lines when its port is matched by this)
508 * Or for stats k,K,i and I:
509 * parv[3] = [user@]host.name (returns which K/I-lines match this)
510 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
511 * (defaults to old reply if ommitted, when local or Oper)
512 * A remote mask (something containing wildcards) is only
513 * allowed for IRC Operators.
515 * parv[3] = time param
516 * parv[4] = time param
517 * (see report_memleak_stats() in runmalloc.c for details)
519 * This function is getting really ugly. -Ghostwolf
521 int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
523 static char Sformat[] = ":%s %d %s Connection SendQ SendM SendKBytes "
524 "RcveM RcveKBytes :Open since";
525 static char Lformat[] = ":%s %d %s %s %u %u %u %u %u :" TIME_T_FMT;
526 struct Message *mptr;
527 struct Client *acptr;
529 struct ConfItem *aconf;
530 char stat = parc > 1 ? parv[1][0] : '\0';
533 /* m_stats is so obnoxiously full of special cases that the different
534 * hunt_server() possiblites were becoming very messy. It now uses a
535 * switch() so as to be easier to read and update as params change.
540 /* open to all, standard # of params */
544 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
550 /* open to all, varying # of params */
560 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv)
566 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
573 /* oper only, varying # of params */
580 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv)
586 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s %s :%s", 2, parc,
587 parv) != HUNTED_ISME)
590 else if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
596 /* oper only, standard # of params */
599 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
611 int doall = 0, wilds = 0;
613 if (parc > 3 && *parv[3])
617 wilds = (*name == '*' || *name == '?');
618 for (p = name + 1; *p; ++p)
619 if ((*p == '*' || *p == '?') && p[-1] != '\\')
628 * Send info about connections which match, or all if the
629 * mask matches me.name. Only restrictions are on those who
630 * are invisible not being visible to 'foreigners' who use
631 * a wild card based search to list it.
633 sendto_one(sptr, Sformat, me.name, RPL_STATSLINKINFO, parv[0]);
634 for (i = 0; i <= HighestFd; i++)
636 if (!(acptr = LocalClientArray[i]))
638 /* Don't return clients when this is a request for `all' */
639 if (doall && IsUser(acptr))
641 /* Don't show invisible people to unauthorized people when using
642 * wildcards -- Is this still needed now /stats is oper only ? */
643 if (IsInvisible(acptr) && (doall || wilds) &&
644 !(MyConnect(sptr) && IsOper(sptr)) &&
645 !IsAnOper(acptr) && (acptr != sptr))
647 /* Only show the ones that match the given mask - if any */
648 if (!doall && wilds && match(name, acptr->name))
650 /* Skip all that do not match the specific query */
651 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
653 sendto_one(sptr, Lformat, me.name, RPL_STATSLINKINFO, parv[0],
654 acptr->name, (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
655 (int)acptr->sendK, (int)acptr->receiveM, (int)acptr->receiveK,
656 CurrentTime - acptr->firsttime);
663 report_configured_links(sptr, CONF_SERVER);
666 case 'g': /* send glines */
667 gline_remove_expired(TStime());
668 for (gline = GlobalGlineList; gline; gline = gline->next) {
669 sendto_one(sptr, rpl_str(RPL_STATSGLINE), me.name,
670 sptr->name, 'G', gline->name, gline->host,
671 gline->expire, gline->reason);
676 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
681 case 'k': /* display CONF_IPKILL as well
685 char *user, *host, *p;
686 int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
687 if ((MyUser(sptr) || IsOper(sptr)) && parc < 4)
689 report_configured_links(sptr, conf_status);
692 if (parc < 4 || *parv[3] == '\0')
693 return need_more_params(sptr,
694 (conf_status & CONF_KLINE) ? "STATS K" : "STATS I");
697 for (p = parv[3]; *p; p++)
705 if (*p == '?' || *p == '*')
711 if (!(MyConnect(sptr) || IsOper(sptr)))
719 if (conf_status == CONF_CLIENT)
721 user = 0; /* Not used, but to avoid compiler warning. */
727 if ((host = strchr(parv[3], '@')))
738 for (aconf = GlobalConfList; aconf; aconf = aconf->next)
740 if ((aconf->status & conf_status))
742 if (conf_status == CONF_KLINE)
744 if ((!wilds && ((user || aconf->host[1]) &&
745 !match(aconf->host, host) &&
746 (!user || !match(aconf->name, user)))) ||
747 (wilds && !mmatch(host, aconf->host) &&
748 (!user || !mmatch(user, aconf->name))))
750 sendto_one(sptr, rpl_str(RPL_STATSKLINE), me.name,
751 sptr->name, 'K', aconf->host, aconf->passwd, aconf->name,
752 aconf->port, get_conf_class(aconf));
757 else if (conf_status == CONF_CLIENT)
759 if ((!wilds && (!match(aconf->host, host) ||
760 !match(aconf->name, host))) ||
761 (wilds && (!mmatch(host, aconf->host) ||
762 !mmatch(host, aconf->name))))
764 sendto_one(sptr, rpl_str(RPL_STATSILINE), me.name,
765 sptr->name, 'I', aconf->host, aconf->name,
766 aconf->port, get_conf_class(aconf));
777 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
778 me.name, parv[0], fda_get_byte_count(), fda_get_block_count());
783 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
784 me.name, parv[0], get_mem_size(), get_alloc_cnt());
787 report_memleak_stats(sptr, parc, parv);
789 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
790 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring "
791 "is not enabled on this server", me.name, parv[0]);
796 for (mptr = msgtab; mptr->cmd; mptr++)
798 sendto_one(sptr, rpl_str(RPL_STATSCOMMANDS),
799 me.name, parv[0], mptr->cmd, mptr->count, mptr->bytes);
803 report_configured_links(sptr, CONF_OPS);
808 * show listener ports
809 * show hidden ports to opers, if there are more than 3 parameters,
810 * interpret the fourth parameter as the port number, limit non-local
811 * or non-oper results to 8 ports.
813 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0,
814 (MyUser(sptr) || IsOper(sptr)) ? 100 : 8);
819 send_usage(sptr, parv[0]);
823 report_configured_links(sptr, CONF_CRULEALL);
826 report_configured_links(sptr, CONF_CRULE);
829 tstats(sptr, parv[0]);
832 report_configured_links(sptr, CONF_TLINES);
835 report_configured_links(sptr, CONF_UWORLD);
841 nowr = CurrentTime - me.since;
842 sendto_one(sptr, rpl_str(RPL_STATSUPTIME), me.name, parv[0],
843 nowr / 86400, (nowr / 3600) % 24, (nowr / 60) % 60, nowr % 60);
844 sendto_one(sptr, rpl_str(RPL_STATSCONN), me.name, parv[0],
845 max_connection_count, max_client_count);
855 send_listinfo(sptr, parv[0]);
860 report_classes(sptr);
864 count_memory(sptr, parv[0]);
870 sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, parv[0], stat);
875 * mo_stats - oper message handler
877 * parv[0] = sender prefix
878 * parv[1] = statistics selector (defaults to Message frequency)
879 * parv[2] = target server (current server defaulted, if omitted)
880 * And 'stats l' and 'stats' L:
881 * parv[3] = server mask ("*" defaulted, if omitted)
883 * parv[3] = port mask (returns p-lines when its port is matched by this)
884 * Or for stats k,K,i and I:
885 * parv[3] = [user@]host.name (returns which K/I-lines match this)
886 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
887 * (defaults to old reply if ommitted, when local or Oper)
888 * A remote mask (something containing wildcards) is only
889 * allowed for IRC Operators.
891 * parv[3] = time param
892 * parv[4] = time param
893 * (see report_memleak_stats() in runmalloc.c for details)
895 * This function is getting really ugly. -Ghostwolf
897 int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
899 static char Sformat[] = ":%s %d %s Connection SendQ SendM SendKBytes "
900 "RcveM RcveKBytes :Open since";
901 static char Lformat[] = ":%s %d %s %s %u %u %u %u %u :" TIME_T_FMT;
902 struct Message *mptr;
903 struct Client *acptr;
905 struct ConfItem *aconf;
906 char stat = parc > 1 ? parv[1][0] : '\0';
909 /* m_stats is so obnoxiously full of special cases that the different
910 * hunt_server() possiblites were becoming very messy. It now uses a
911 * switch() so as to be easier to read and update as params change.
916 /* open to all, standard # of params */
920 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
926 /* open to all, varying # of params */
936 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv)
942 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
949 /* oper only, varying # of params */
956 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv)
962 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s %s :%s", 2, parc,
963 parv) != HUNTED_ISME)
966 else if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
972 /* oper only, standard # of params */
975 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
987 int doall = 0, wilds = 0;
989 if (parc > 3 && *parv[3])
993 wilds = (*name == '*' || *name == '?');
994 for (p = name + 1; *p; ++p)
995 if ((*p == '*' || *p == '?') && p[-1] != '\\')
1004 * Send info about connections which match, or all if the
1005 * mask matches me.name. Only restrictions are on those who
1006 * are invisible not being visible to 'foreigners' who use
1007 * a wild card based search to list it.
1009 sendto_one(sptr, Sformat, me.name, RPL_STATSLINKINFO, parv[0]);
1010 for (i = 0; i <= HighestFd; i++)
1012 if (!(acptr = LocalClientArray[i]))
1014 /* Don't return clients when this is a request for `all' */
1015 if (doall && IsUser(acptr))
1017 /* Don't show invisible people to unauthorized people when using
1018 * wildcards -- Is this still needed now /stats is oper only ? */
1019 if (IsInvisible(acptr) && (doall || wilds) &&
1020 !(MyConnect(sptr) && IsOper(sptr)) &&
1021 !IsAnOper(acptr) && (acptr != sptr))
1023 /* Only show the ones that match the given mask - if any */
1024 if (!doall && wilds && match(name, acptr->name))
1026 /* Skip all that do not match the specific query */
1027 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
1029 sendto_one(sptr, Lformat, me.name, RPL_STATSLINKINFO, parv[0],
1030 acptr->name, (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
1031 (int)acptr->sendK, (int)acptr->receiveM, (int)acptr->receiveK,
1032 CurrentTime - acptr->firsttime);
1038 report_configured_links(sptr, CONF_SERVER);
1041 case 'g': /* send glines */
1042 gline_remove_expired(TStime());
1043 for (gline = GlobalGlineList; gline; gline = gline->next) {
1044 sendto_one(sptr, rpl_str(RPL_STATSGLINE), me.name,
1045 sptr->name, 'G', gline->name, gline->host,
1046 gline->expire, gline->reason);
1051 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
1056 case 'k': /* display CONF_IPKILL as well
1057 as CONF_KILL -Kev */
1060 char *user, *host, *p;
1061 int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
1062 if ((MyUser(sptr) || IsOper(sptr)) && parc < 4)
1064 report_configured_links(sptr, conf_status);
1067 if (parc < 4 || *parv[3] == '\0')
1068 return need_more_params(sptr,
1069 (conf_status & CONF_KLINE) ? "STATS K" : "STATS I");
1072 for (p = parv[3]; *p; p++)
1080 if (*p == '?' || *p == '*')
1086 if (!(MyConnect(sptr) || IsOper(sptr)))
1094 if (conf_status == CONF_CLIENT)
1096 user = 0; /* Not used, but to avoid compiler warning. */
1102 if ((host = strchr(parv[3], '@')))
1113 for (aconf = GlobalConfList; aconf; aconf = aconf->next)
1115 if ((aconf->status & conf_status))
1117 if (conf_status == CONF_KLINE)
1119 if ((!wilds && ((user || aconf->host[1]) &&
1120 !match(aconf->host, host) &&
1121 (!user || !match(aconf->name, user)))) ||
1122 (wilds && !mmatch(host, aconf->host) &&
1123 (!user || !mmatch(user, aconf->name))))
1125 sendto_one(sptr, rpl_str(RPL_STATSKLINE), me.name,
1126 sptr->name, 'K', aconf->host, aconf->passwd, aconf->name,
1127 aconf->port, get_conf_class(aconf));
1132 else if (conf_status == CONF_CLIENT)
1134 if ((!wilds && (!match(aconf->host, host) ||
1135 !match(aconf->name, host))) ||
1136 (wilds && (!mmatch(host, aconf->host) ||
1137 !mmatch(host, aconf->name))))
1139 sendto_one(sptr, rpl_str(RPL_STATSILINE), me.name,
1140 sptr->name, 'I', aconf->host, aconf->name,
1141 aconf->port, get_conf_class(aconf));
1151 #if !defined(NDEBUG)
1152 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
1153 me.name, parv[0], fda_get_byte_count(), fda_get_block_count());
1158 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
1159 me.name, parv[0], get_mem_size(), get_alloc_cnt());
1162 report_memleak_stats(sptr, parc, parv);
1164 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
1165 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring "
1166 "is not enabled on this server", me.name, parv[0]);
1171 for (mptr = msgtab; mptr->cmd; mptr++)
1173 sendto_one(sptr, rpl_str(RPL_STATSCOMMANDS),
1174 me.name, parv[0], mptr->cmd, mptr->count, mptr->bytes);
1178 report_configured_links(sptr, CONF_OPS);
1183 * show listener ports
1184 * show hidden ports to opers, if there are more than 3 parameters,
1185 * interpret the fourth parameter as the port number, limit non-local
1186 * or non-oper results to 8 ports.
1188 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0,
1189 (MyUser(sptr) || IsOper(sptr)) ? 100 : 8);
1194 send_usage(sptr, parv[0]);
1198 report_configured_links(sptr, CONF_CRULEALL);
1201 report_configured_links(sptr, CONF_CRULE);
1204 tstats(sptr, parv[0]);
1207 report_configured_links(sptr, CONF_TLINES);
1210 report_configured_links(sptr, CONF_UWORLD);
1216 nowr = CurrentTime - me.since;
1217 sendto_one(sptr, rpl_str(RPL_STATSUPTIME), me.name, parv[0],
1218 nowr / 86400, (nowr / 3600) % 24, (nowr / 60) % 60, nowr % 60);
1219 sendto_one(sptr, rpl_str(RPL_STATSCONN), me.name, parv[0],
1220 max_connection_count, max_client_count);
1230 send_listinfo(sptr, parv[0]);
1235 report_classes(sptr);
1239 count_memory(sptr, parv[0]);
1245 sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, parv[0], stat);
1253 * parv[0] = sender prefix
1254 * parv[1] = statistics selector (defaults to Message frequency)
1255 * parv[2] = target server (current server defaulted, if omitted)
1256 * And 'stats l' and 'stats' L:
1257 * parv[3] = server mask ("*" defaulted, if omitted)
1259 * parv[3] = port mask (returns p-lines when its port is matched by this)
1260 * Or for stats k,K,i and I:
1261 * parv[3] = [user@]host.name (returns which K/I-lines match this)
1262 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
1263 * (defaults to old reply if ommitted, when local or Oper)
1264 * A remote mask (something containing wildcards) is only
1265 * allowed for IRC Operators.
1267 * parv[3] = time param
1268 * parv[4] = time param
1269 * (see report_memleak_stats() in runmalloc.c for details)
1271 * This function is getting really ugly. -Ghostwolf
1273 int m_stats(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
1275 static char Sformat[] = ":%s %d %s Connection SendQ SendM SendKBytes "
1276 "RcveM RcveKBytes :Open since";
1277 static char Lformat[] = ":%s %d %s %s %u %u %u %u %u :" TIME_T_FMT;
1278 struct Message *mptr;
1279 struct Client *acptr;
1280 struct Gline* gline;
1281 struct ConfItem *aconf;
1282 char stat = parc > 1 ? parv[1][0] : '\0';
1285 /* m_stats is so obnoxiously full of special cases that the different
1286 * hunt_server() possiblites were becoming very messy. It now uses a
1287 * switch() so as to be easier to read and update as params change.
1292 /* open to all, standard # of params */
1296 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
1302 /* open to all, varying # of params */
1312 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv)
1318 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
1325 /* oper only, varying # of params */
1332 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv)
1338 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s %s :%s", 2, parc,
1339 parv) != HUNTED_ISME)
1342 else if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
1348 /* oper only, standard # of params */
1351 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
1363 int doall = 0, wilds = 0;
1365 if (parc > 3 && *parv[3])
1369 wilds = (*name == '*' || *name == '?');
1370 for (p = name + 1; *p; ++p)
1371 if ((*p == '*' || *p == '?') && p[-1] != '\\')
1380 * Send info about connections which match, or all if the
1381 * mask matches me.name. Only restrictions are on those who
1382 * are invisible not being visible to 'foreigners' who use
1383 * a wild card based search to list it.
1385 sendto_one(sptr, Sformat, me.name, RPL_STATSLINKINFO, parv[0]);
1386 for (i = 0; i <= HighestFd; i++)
1388 if (!(acptr = LocalClientArray[i]))
1390 /* Don't return clients when this is a request for `all' */
1391 if (doall && IsUser(acptr))
1393 /* Don't show invisible people to unauthorized people when using
1394 * wildcards -- Is this still needed now /stats is oper only ? */
1395 if (IsInvisible(acptr) && (doall || wilds) &&
1396 !(MyConnect(sptr) && IsOper(sptr)) &&
1397 !IsAnOper(acptr) && (acptr != sptr))
1399 /* Only show the ones that match the given mask - if any */
1400 if (!doall && wilds && match(name, acptr->name))
1402 /* Skip all that do not match the specific query */
1403 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
1405 sendto_one(sptr, Lformat, me.name, RPL_STATSLINKINFO, parv[0],
1407 (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
1408 (int)acptr->sendK, (int)acptr->receiveM, (int)acptr->receiveK,
1409 CurrentTime - acptr->firsttime);
1415 report_configured_links(sptr, CONF_SERVER);
1418 case 'g': /* send glines */
1419 gline_remove_expired(TStime());
1420 for (gline = GlobalGlineList; gline; gline = gline->next) {
1421 sendto_one(sptr, rpl_str(RPL_STATSGLINE), me.name,
1422 sptr->name, 'G', gline->name, gline->host,
1423 gline->expire, gline->reason);
1428 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
1433 case 'k': /* display CONF_IPKILL as well
1434 as CONF_KILL -Kev */
1437 char *user, *host, *p;
1438 int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
1439 if ((MyUser(sptr) || IsOper(sptr)) && parc < 4)
1441 report_configured_links(sptr, conf_status);
1444 if (parc < 4 || *parv[3] == '\0')
1445 return need_more_params(sptr,
1446 (conf_status & CONF_KLINE) ? "STATS K" : "STATS I");
1449 for (p = parv[3]; *p; p++)
1457 if (*p == '?' || *p == '*')
1463 if (!(MyConnect(sptr) || IsOper(sptr)))
1471 if (conf_status == CONF_CLIENT)
1473 user = 0; /* Not used, but to avoid compiler warning. */
1479 if ((host = strchr(parv[3], '@')))
1490 for (aconf = GlobalConfList; aconf; aconf = aconf->next)
1492 if ((aconf->status & conf_status))
1494 if (conf_status == CONF_KLINE)
1496 if ((!wilds && ((user || aconf->host[1]) &&
1497 !match(aconf->host, host) &&
1498 (!user || !match(aconf->name, user)))) ||
1499 (wilds && !mmatch(host, aconf->host) &&
1500 (!user || !mmatch(user, aconf->name))))
1502 sendto_one(sptr, rpl_str(RPL_STATSKLINE), me.name,
1503 sptr->name, 'K', aconf->host, aconf->passwd, aconf->name,
1504 aconf->port, get_conf_class(aconf));
1509 else if (conf_status == CONF_CLIENT)
1511 if ((!wilds && (!match(aconf->host, host) ||
1512 !match(aconf->name, host))) ||
1513 (wilds && (!mmatch(host, aconf->host) ||
1514 !mmatch(host, aconf->name))))
1516 sendto_one(sptr, rpl_str(RPL_STATSILINE), me.name,
1517 sptr->name, 'I', aconf->host, aconf->name,
1518 aconf->port, get_conf_class(aconf));
1528 #if !defined(NDEBUG)
1529 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
1530 me.name, parv[0], fda_get_byte_count(), fda_get_block_count());
1535 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
1536 me.name, parv[0], get_mem_size(), get_alloc_cnt());
1539 report_memleak_stats(sptr, parc, parv);
1541 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
1542 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring "
1543 "is not enabled on this server", me.name, parv[0]);
1548 for (mptr = msgtab; mptr->cmd; mptr++)
1550 sendto_one(sptr, rpl_str(RPL_STATSCOMMANDS),
1551 me.name, parv[0], mptr->cmd, mptr->count, mptr->bytes);
1555 report_configured_links(sptr, CONF_OPS);
1560 * show listener ports
1561 * show hidden ports to opers, if there are more than 3 parameters,
1562 * interpret the fourth parameter as the port number, limit non-local
1563 * or non-oper results to 8 ports.
1565 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0,
1566 (MyUser(sptr) || IsOper(sptr)) ? 100 : 8);
1571 send_usage(sptr, parv[0]);
1575 report_configured_links(sptr, CONF_CRULEALL);
1578 report_configured_links(sptr, CONF_CRULE);
1581 tstats(sptr, parv[0]);
1584 report_configured_links(sptr, CONF_TLINES);
1587 report_configured_links(sptr, CONF_UWORLD);
1593 nowr = CurrentTime - me.since;
1594 sendto_one(sptr, rpl_str(RPL_STATSUPTIME), me.name, parv[0],
1595 nowr / 86400, (nowr / 3600) % 24, (nowr / 60) % 60, nowr % 60);
1596 sendto_one(sptr, rpl_str(RPL_STATSCONN), me.name, parv[0],
1597 max_connection_count, max_client_count);
1607 send_listinfo(sptr, parv[0]);
1612 report_classes(sptr);
1616 count_memory(sptr, parv[0]);
1622 sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, parv[0], stat);