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 * Help info displayed when user provides no stats parameter. --Gte
127 const char *statsinfo[] = {
128 "The following statistics are available:",
129 "U - Service server & nick jupes information.",
130 "u - Current uptime & highest connection count.",
131 "p - Listening ports.",
132 "i - Connection authorisation lines.",
133 "y - Connection classes.",
134 "c - Remote server connection lines.",
135 "h - Hubs information (Oper only).",
136 "d - Dynamic routing configuration.",
137 "l - Current connections information.",
138 "g - Global bans (G-lines).",
139 "k - Local bans (K-Lines).",
140 "o - Operator information.",
141 "m - Message usage information.",
142 "t - Local connection statistics (Total SND/RCV, etc).",
143 "w - Userload statistics.",
144 "M - Memory allocation & leak monitoring.",
145 "z - Memory/Structure allocation information.",
146 "r - System resource usage (Debug only).",
147 "x - List usage information (Debug only).",
152 * m_stats - generic message handler
154 * parv[0] = sender prefix
155 * parv[1] = statistics selector (defaults to Message frequency)
156 * parv[2] = target server (current server defaulted, if omitted)
157 * And 'stats l' and 'stats' L:
158 * parv[3] = server mask ("*" defaulted, if omitted)
160 * parv[3] = port mask (returns p-lines when its port is matched by this)
161 * Or for stats k,K,i and I:
162 * parv[3] = [user@]host.name (returns which K/I-lines match this)
163 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
164 * (defaults to old reply if ommitted, when local or Oper)
165 * A remote mask (something containing wildcards) is only
166 * allowed for IRC Operators.
168 * parv[3] = time param
169 * parv[4] = time param
170 * (see report_memleak_stats() in runmalloc.c for details)
172 * This function is getting really ugly. -Ghostwolf
174 int m_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
176 static char Sformat[] = ":%s %d %s Connection SendQ SendM SendKBytes "
177 "RcveM RcveKBytes :Open since";
178 static char Lformat[] = ":%s %d %s %s %u %u %u %u %u :" TIME_T_FMT;
179 struct Message *mptr;
180 struct Client *acptr;
182 struct ConfItem *aconf;
183 char stat = parc > 1 ? parv[1][0] : '\0';
184 const char **infotext = statsinfo;
187 /* m_stats is so obnoxiously full of special cases that the different
188 * hunt_server() possiblites were becoming very messy. It now uses a
189 * switch() so as to be easier to read and update as params change.
194 /* open to all, standard # of params */
198 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
204 /* open to all, varying # of params */
214 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv)
220 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
227 /* oper only, varying # of params */
234 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv)
240 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s %s :%s", 2, parc,
241 parv) != HUNTED_ISME)
244 else if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
250 /* oper only, standard # of params */
253 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
265 int doall = 0, wilds = 0;
267 if (parc > 3 && *parv[3])
271 wilds = (*name == '*' || *name == '?');
272 for (p = name + 1; *p; ++p)
273 if ((*p == '*' || *p == '?') && p[-1] != '\\')
282 * Send info about connections which match, or all if the
283 * mask matches me.name. Only restrictions are on those who
284 * are invisible not being visible to 'foreigners' who use
285 * a wild card based search to list it.
287 sendto_one(sptr, Sformat, me.name, RPL_STATSLINKINFO, parv[0]);
288 for (i = 0; i <= HighestFd; i++)
290 if (!(acptr = LocalClientArray[i]))
292 /* Don't return clients when this is a request for `all' */
293 if (doall && IsUser(acptr))
295 /* Don't show invisible people to unauthorized people when using
296 * wildcards -- Is this still needed now /stats is oper only ?
297 * Yeah it is -- non opers can /stats l, just not remotely.
299 if (IsInvisible(acptr) && (doall || wilds) &&
300 !(MyConnect(sptr) && IsOper(sptr)) &&
301 !IsAnOper(acptr) && (acptr != sptr))
303 /* Only show the ones that match the given mask - if any */
304 if (!doall && wilds && match(name, acptr->name))
306 /* Skip all that do not match the specific query */
307 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
309 sendto_one(sptr, Lformat, me.name, RPL_STATSLINKINFO, parv[0],
310 acptr->name, (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
311 (int)acptr->sendK, (int)acptr->receiveM, (int)acptr->receiveK,
312 CurrentTime - acptr->firsttime);
318 report_configured_links(sptr, CONF_SERVER);
321 case 'g': /* send glines */
322 gline_remove_expired(TStime());
323 for (gline = GlobalGlineList; gline; gline = gline->next) {
324 sendto_one(sptr, rpl_str(RPL_STATSGLINE), me.name,
325 sptr->name, 'G', gline->name, gline->host,
326 gline->expire, gline->reason);
335 case 'k': /* display CONF_IPKILL as well
339 char *user, *host, *p;
340 int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
341 if ((MyUser(sptr) || IsOper(sptr)) && parc < 4)
343 report_configured_links(sptr, conf_status);
346 if (parc < 4 || *parv[3] == '\0')
347 return need_more_params(sptr,
348 (conf_status & CONF_KLINE) ? "STATS K" : "STATS I");
351 for (p = parv[3]; *p; p++)
359 if (*p == '?' || *p == '*')
365 if (!(MyConnect(sptr) || IsOper(sptr)))
373 if (conf_status == CONF_CLIENT)
375 user = 0; /* Not used, but to avoid compiler warning. */
381 if ((host = strchr(parv[3], '@')))
392 for (aconf = GlobalConfList; aconf; aconf = aconf->next)
394 if ((aconf->status & conf_status))
396 if (conf_status == CONF_KLINE)
398 if ((!wilds && ((user || aconf->host[1]) &&
399 !match(aconf->host, host) &&
400 (!user || !match(aconf->name, user)))) ||
401 (wilds && !mmatch(host, aconf->host) &&
402 (!user || !mmatch(user, aconf->name))))
404 sendto_one(sptr, rpl_str(RPL_STATSKLINE), me.name,
405 sptr->name, 'K', aconf->host, aconf->passwd, aconf->name,
406 aconf->port, get_conf_class(aconf));
411 else if (conf_status == CONF_CLIENT)
413 if ((!wilds && (!match(aconf->host, host) ||
414 !match(aconf->name, host))) ||
415 (wilds && (!mmatch(host, aconf->host) ||
416 !mmatch(host, aconf->name))))
418 sendto_one(sptr, rpl_str(RPL_STATSILINE), me.name,
419 sptr->name, 'I', aconf->host, aconf->name,
420 aconf->port, get_conf_class(aconf));
431 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
432 me.name, parv[0], fda_get_byte_count(), fda_get_block_count());
437 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
438 me.name, parv[0], get_mem_size(), get_alloc_cnt());
441 report_memleak_stats(sptr, parc, parv);
443 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
444 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring "
445 "is not enabled on this server", me.name, parv[0]);
450 for (mptr = msgtab; mptr->cmd; mptr++)
452 sendto_one(sptr, rpl_str(RPL_STATSCOMMANDS),
453 me.name, parv[0], mptr->cmd, mptr->count, mptr->bytes);
457 report_configured_links(sptr, CONF_OPS);
462 * show listener ports
463 * show hidden ports to opers, if there are more than 3 parameters,
464 * interpret the fourth parameter as the port number, limit non-local
465 * or non-oper results to 8 ports.
467 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0,
468 (MyUser(sptr) || IsOper(sptr)) ? 100 : 8);
473 send_usage(sptr, parv[0]);
477 report_configured_links(sptr, CONF_CRULEALL);
480 report_configured_links(sptr, CONF_CRULE);
483 tstats(sptr, parv[0]);
486 report_configured_links(sptr, CONF_TLINES);
489 report_configured_links(sptr, CONF_UWORLD);
495 nowr = CurrentTime - me.since;
496 sendto_one(sptr, rpl_str(RPL_STATSUPTIME), me.name, parv[0],
497 nowr / 86400, (nowr / 3600) % 24, (nowr / 60) % 60, nowr % 60);
498 sendto_one(sptr, rpl_str(RPL_STATSCONN), me.name, parv[0],
499 max_connection_count, max_client_count);
509 send_listinfo(sptr, parv[0]);
514 report_classes(sptr);
518 count_memory(sptr, parv[0]);
522 while (*infotext) sendto_one(sptr, ":%s NOTICE %s :%s", me.name, parv[0], *infotext++);
525 sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, parv[0], stat);
530 * ms_stats - server message handler
532 * parv[0] = sender prefix
533 * parv[1] = statistics selector (defaults to Message frequency)
534 * parv[2] = target server (current server defaulted, if omitted)
535 * And 'stats l' and 'stats' L:
536 * parv[3] = server mask ("*" defaulted, if omitted)
538 * parv[3] = port mask (returns p-lines when its port is matched by this)
539 * Or for stats k,K,i and I:
540 * parv[3] = [user@]host.name (returns which K/I-lines match this)
541 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
542 * (defaults to old reply if ommitted, when local or Oper)
543 * A remote mask (something containing wildcards) is only
544 * allowed for IRC Operators.
546 * parv[3] = time param
547 * parv[4] = time param
548 * (see report_memleak_stats() in runmalloc.c for details)
550 * This function is getting really ugly. -Ghostwolf
552 int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
554 static char Sformat[] = ":%s %d %s Connection SendQ SendM SendKBytes "
555 "RcveM RcveKBytes :Open since";
556 static char Lformat[] = ":%s %d %s %s %u %u %u %u %u :" TIME_T_FMT;
557 struct Message *mptr;
558 struct Client *acptr;
560 struct ConfItem *aconf;
561 char stat = parc > 1 ? parv[1][0] : '\0';
564 /* m_stats is so obnoxiously full of special cases that the different
565 * hunt_server() possiblites were becoming very messy. It now uses a
566 * switch() so as to be easier to read and update as params change.
571 /* open to all, standard # of params */
575 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
581 /* open to all, varying # of params */
591 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv)
597 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
604 /* oper only, varying # of params */
611 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv)
617 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s %s :%s", 2, parc,
618 parv) != HUNTED_ISME)
621 else if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
627 /* oper only, standard # of params */
630 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
642 int doall = 0, wilds = 0;
644 if (parc > 3 && *parv[3])
648 wilds = (*name == '*' || *name == '?');
649 for (p = name + 1; *p; ++p)
650 if ((*p == '*' || *p == '?') && p[-1] != '\\')
659 * Send info about connections which match, or all if the
660 * mask matches me.name. Only restrictions are on those who
661 * are invisible not being visible to 'foreigners' who use
662 * a wild card based search to list it.
664 sendto_one(sptr, Sformat, me.name, RPL_STATSLINKINFO, parv[0]);
665 for (i = 0; i <= HighestFd; i++)
667 if (!(acptr = LocalClientArray[i]))
669 /* Don't return clients when this is a request for `all' */
670 if (doall && IsUser(acptr))
672 /* Don't show invisible people to unauthorized people when using
673 * wildcards -- Is this still needed now /stats is oper only ? */
674 if (IsInvisible(acptr) && (doall || wilds) &&
675 !(MyConnect(sptr) && IsOper(sptr)) &&
676 !IsAnOper(acptr) && (acptr != sptr))
678 /* Only show the ones that match the given mask - if any */
679 if (!doall && wilds && match(name, acptr->name))
681 /* Skip all that do not match the specific query */
682 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
684 sendto_one(sptr, Lformat, me.name, RPL_STATSLINKINFO, parv[0],
685 acptr->name, (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
686 (int)acptr->sendK, (int)acptr->receiveM, (int)acptr->receiveK,
687 CurrentTime - acptr->firsttime);
694 report_configured_links(sptr, CONF_SERVER);
697 case 'g': /* send glines */
698 gline_remove_expired(TStime());
699 for (gline = GlobalGlineList; gline; gline = gline->next) {
700 sendto_one(sptr, rpl_str(RPL_STATSGLINE), me.name,
701 sptr->name, 'G', gline->name, gline->host,
702 gline->expire, gline->reason);
707 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
712 case 'k': /* display CONF_IPKILL as well
716 char *user, *host, *p;
717 int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
718 if ((MyUser(sptr) || IsOper(sptr)) && parc < 4)
720 report_configured_links(sptr, conf_status);
723 if (parc < 4 || *parv[3] == '\0')
724 return need_more_params(sptr,
725 (conf_status & CONF_KLINE) ? "STATS K" : "STATS I");
728 for (p = parv[3]; *p; p++)
736 if (*p == '?' || *p == '*')
742 if (!(MyConnect(sptr) || IsOper(sptr)))
750 if (conf_status == CONF_CLIENT)
752 user = 0; /* Not used, but to avoid compiler warning. */
758 if ((host = strchr(parv[3], '@')))
769 for (aconf = GlobalConfList; aconf; aconf = aconf->next)
771 if ((aconf->status & conf_status))
773 if (conf_status == CONF_KLINE)
775 if ((!wilds && ((user || aconf->host[1]) &&
776 !match(aconf->host, host) &&
777 (!user || !match(aconf->name, user)))) ||
778 (wilds && !mmatch(host, aconf->host) &&
779 (!user || !mmatch(user, aconf->name))))
781 sendto_one(sptr, rpl_str(RPL_STATSKLINE), me.name,
782 sptr->name, 'K', aconf->host, aconf->passwd, aconf->name,
783 aconf->port, get_conf_class(aconf));
788 else if (conf_status == CONF_CLIENT)
790 if ((!wilds && (!match(aconf->host, host) ||
791 !match(aconf->name, host))) ||
792 (wilds && (!mmatch(host, aconf->host) ||
793 !mmatch(host, aconf->name))))
795 sendto_one(sptr, rpl_str(RPL_STATSILINE), me.name,
796 sptr->name, 'I', aconf->host, aconf->name,
797 aconf->port, get_conf_class(aconf));
808 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
809 me.name, parv[0], fda_get_byte_count(), fda_get_block_count());
814 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
815 me.name, parv[0], get_mem_size(), get_alloc_cnt());
818 report_memleak_stats(sptr, parc, parv);
820 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
821 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring "
822 "is not enabled on this server", me.name, parv[0]);
827 for (mptr = msgtab; mptr->cmd; mptr++)
829 sendto_one(sptr, rpl_str(RPL_STATSCOMMANDS),
830 me.name, parv[0], mptr->cmd, mptr->count, mptr->bytes);
834 report_configured_links(sptr, CONF_OPS);
839 * show listener ports
840 * show hidden ports to opers, if there are more than 3 parameters,
841 * interpret the fourth parameter as the port number, limit non-local
842 * or non-oper results to 8 ports.
844 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0,
845 (MyUser(sptr) || IsOper(sptr)) ? 100 : 8);
850 send_usage(sptr, parv[0]);
854 report_configured_links(sptr, CONF_CRULEALL);
857 report_configured_links(sptr, CONF_CRULE);
860 tstats(sptr, parv[0]);
863 report_configured_links(sptr, CONF_TLINES);
866 report_configured_links(sptr, CONF_UWORLD);
872 nowr = CurrentTime - me.since;
873 sendto_one(sptr, rpl_str(RPL_STATSUPTIME), me.name, parv[0],
874 nowr / 86400, (nowr / 3600) % 24, (nowr / 60) % 60, nowr % 60);
875 sendto_one(sptr, rpl_str(RPL_STATSCONN), me.name, parv[0],
876 max_connection_count, max_client_count);
886 send_listinfo(sptr, parv[0]);
891 report_classes(sptr);
895 count_memory(sptr, parv[0]);
901 sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, parv[0], stat);
906 * mo_stats - oper message handler
908 * parv[0] = sender prefix
909 * parv[1] = statistics selector (defaults to Message frequency)
910 * parv[2] = target server (current server defaulted, if omitted)
911 * And 'stats l' and 'stats' L:
912 * parv[3] = server mask ("*" defaulted, if omitted)
914 * parv[3] = port mask (returns p-lines when its port is matched by this)
915 * Or for stats k,K,i and I:
916 * parv[3] = [user@]host.name (returns which K/I-lines match this)
917 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
918 * (defaults to old reply if ommitted, when local or Oper)
919 * A remote mask (something containing wildcards) is only
920 * allowed for IRC Operators.
922 * parv[3] = time param
923 * parv[4] = time param
924 * (see report_memleak_stats() in runmalloc.c for details)
926 * This function is getting really ugly. -Ghostwolf
928 int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
930 static char Sformat[] = ":%s %d %s Connection SendQ SendM SendKBytes "
931 "RcveM RcveKBytes :Open since";
932 static char Lformat[] = ":%s %d %s %s %u %u %u %u %u :" TIME_T_FMT;
933 struct Message *mptr;
934 struct Client *acptr;
936 struct ConfItem *aconf;
937 char stat = parc > 1 ? parv[1][0] : '\0';
938 const char **infotext = statsinfo;
941 /* m_stats is so obnoxiously full of special cases that the different
942 * hunt_server() possiblites were becoming very messy. It now uses a
943 * switch() so as to be easier to read and update as params change.
948 /* open to all, standard # of params */
952 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
958 /* open to all, varying # of params */
968 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv)
974 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
981 /* oper only, varying # of params */
988 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv)
994 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s %s :%s", 2, parc,
995 parv) != HUNTED_ISME)
998 else if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
1004 /* oper only, standard # of params */
1007 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
1019 int doall = 0, wilds = 0;
1021 if (parc > 3 && *parv[3])
1025 wilds = (*name == '*' || *name == '?');
1026 for (p = name + 1; *p; ++p)
1027 if ((*p == '*' || *p == '?') && p[-1] != '\\')
1036 * Send info about connections which match, or all if the
1037 * mask matches me.name. Only restrictions are on those who
1038 * are invisible not being visible to 'foreigners' who use
1039 * a wild card based search to list it.
1041 sendto_one(sptr, Sformat, me.name, RPL_STATSLINKINFO, parv[0]);
1042 for (i = 0; i <= HighestFd; i++)
1044 if (!(acptr = LocalClientArray[i]))
1046 /* Don't return clients when this is a request for `all' */
1047 if (doall && IsUser(acptr))
1049 /* Don't show invisible people to unauthorized people when using
1050 * wildcards -- Is this still needed now /stats is oper only ? */
1051 if (IsInvisible(acptr) && (doall || wilds) &&
1052 !(MyConnect(sptr) && IsOper(sptr)) &&
1053 !IsAnOper(acptr) && (acptr != sptr))
1055 /* Only show the ones that match the given mask - if any */
1056 if (!doall && wilds && match(name, acptr->name))
1058 /* Skip all that do not match the specific query */
1059 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
1061 sendto_one(sptr, Lformat, me.name, RPL_STATSLINKINFO, parv[0],
1062 acptr->name, (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
1063 (int)acptr->sendK, (int)acptr->receiveM, (int)acptr->receiveK,
1064 CurrentTime - acptr->firsttime);
1070 report_configured_links(sptr, CONF_SERVER);
1073 case 'g': /* send glines */
1074 gline_remove_expired(TStime());
1075 for (gline = GlobalGlineList; gline; gline = gline->next) {
1076 sendto_one(sptr, rpl_str(RPL_STATSGLINE), me.name,
1077 sptr->name, 'G', gline->name, gline->host,
1078 gline->expire, gline->reason);
1083 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
1088 case 'k': /* display CONF_IPKILL as well
1089 as CONF_KILL -Kev */
1092 char *user, *host, *p;
1093 int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
1094 if ((MyUser(sptr) || IsOper(sptr)) && parc < 4)
1096 report_configured_links(sptr, conf_status);
1099 if (parc < 4 || *parv[3] == '\0')
1100 return need_more_params(sptr,
1101 (conf_status & CONF_KLINE) ? "STATS K" : "STATS I");
1104 for (p = parv[3]; *p; p++)
1112 if (*p == '?' || *p == '*')
1118 if (!(MyConnect(sptr) || IsOper(sptr)))
1126 if (conf_status == CONF_CLIENT)
1128 user = 0; /* Not used, but to avoid compiler warning. */
1134 if ((host = strchr(parv[3], '@')))
1145 for (aconf = GlobalConfList; aconf; aconf = aconf->next)
1147 if ((aconf->status & conf_status))
1149 if (conf_status == CONF_KLINE)
1151 if ((!wilds && ((user || aconf->host[1]) &&
1152 !match(aconf->host, host) &&
1153 (!user || !match(aconf->name, user)))) ||
1154 (wilds && !mmatch(host, aconf->host) &&
1155 (!user || !mmatch(user, aconf->name))))
1157 sendto_one(sptr, rpl_str(RPL_STATSKLINE), me.name,
1158 sptr->name, 'K', aconf->host, aconf->passwd, aconf->name,
1159 aconf->port, get_conf_class(aconf));
1164 else if (conf_status == CONF_CLIENT)
1166 if ((!wilds && (!match(aconf->host, host) ||
1167 !match(aconf->name, host))) ||
1168 (wilds && (!mmatch(host, aconf->host) ||
1169 !mmatch(host, aconf->name))))
1171 sendto_one(sptr, rpl_str(RPL_STATSILINE), me.name,
1172 sptr->name, 'I', aconf->host, aconf->name,
1173 aconf->port, get_conf_class(aconf));
1183 #if !defined(NDEBUG)
1184 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
1185 me.name, parv[0], fda_get_byte_count(), fda_get_block_count());
1190 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
1191 me.name, parv[0], get_mem_size(), get_alloc_cnt());
1194 report_memleak_stats(sptr, parc, parv);
1196 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
1197 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring "
1198 "is not enabled on this server", me.name, parv[0]);
1203 for (mptr = msgtab; mptr->cmd; mptr++)
1205 sendto_one(sptr, rpl_str(RPL_STATSCOMMANDS),
1206 me.name, parv[0], mptr->cmd, mptr->count, mptr->bytes);
1210 report_configured_links(sptr, CONF_OPS);
1215 * show listener ports
1216 * show hidden ports to opers, if there are more than 3 parameters,
1217 * interpret the fourth parameter as the port number, limit non-local
1218 * or non-oper results to 8 ports.
1220 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0,
1221 (MyUser(sptr) || IsOper(sptr)) ? 100 : 8);
1226 send_usage(sptr, parv[0]);
1230 report_configured_links(sptr, CONF_CRULEALL);
1233 report_configured_links(sptr, CONF_CRULE);
1236 tstats(sptr, parv[0]);
1239 report_configured_links(sptr, CONF_TLINES);
1242 report_configured_links(sptr, CONF_UWORLD);
1248 nowr = CurrentTime - me.since;
1249 sendto_one(sptr, rpl_str(RPL_STATSUPTIME), me.name, parv[0],
1250 nowr / 86400, (nowr / 3600) % 24, (nowr / 60) % 60, nowr % 60);
1251 sendto_one(sptr, rpl_str(RPL_STATSCONN), me.name, parv[0],
1252 max_connection_count, max_client_count);
1262 send_listinfo(sptr, parv[0]);
1267 report_classes(sptr);
1271 count_memory(sptr, parv[0]);
1275 while (*infotext) sendto_one(sptr, ":%s NOTICE %s :%s", me.name, parv[0], *infotext++);
1278 sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, parv[0], stat);
1286 * parv[0] = sender prefix
1287 * parv[1] = statistics selector (defaults to Message frequency)
1288 * parv[2] = target server (current server defaulted, if omitted)
1289 * And 'stats l' and 'stats' L:
1290 * parv[3] = server mask ("*" defaulted, if omitted)
1292 * parv[3] = port mask (returns p-lines when its port is matched by this)
1293 * Or for stats k,K,i and I:
1294 * parv[3] = [user@]host.name (returns which K/I-lines match this)
1295 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
1296 * (defaults to old reply if ommitted, when local or Oper)
1297 * A remote mask (something containing wildcards) is only
1298 * allowed for IRC Operators.
1300 * parv[3] = time param
1301 * parv[4] = time param
1302 * (see report_memleak_stats() in runmalloc.c for details)
1304 * This function is getting really ugly. -Ghostwolf
1306 int m_stats(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
1308 static char Sformat[] = ":%s %d %s Connection SendQ SendM SendKBytes "
1309 "RcveM RcveKBytes :Open since";
1310 static char Lformat[] = ":%s %d %s %s %u %u %u %u %u :" TIME_T_FMT;
1311 struct Message *mptr;
1312 struct Client *acptr;
1313 struct Gline* gline;
1314 struct ConfItem *aconf;
1315 char stat = parc > 1 ? parv[1][0] : '\0';
1318 /* m_stats is so obnoxiously full of special cases that the different
1319 * hunt_server() possiblites were becoming very messy. It now uses a
1320 * switch() so as to be easier to read and update as params change.
1325 /* open to all, standard # of params */
1329 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
1335 /* open to all, varying # of params */
1345 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv)
1351 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
1358 /* oper only, varying # of params */
1365 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv)
1371 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s %s :%s", 2, parc,
1372 parv) != HUNTED_ISME)
1375 else if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
1381 /* oper only, standard # of params */
1384 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
1396 int doall = 0, wilds = 0;
1398 if (parc > 3 && *parv[3])
1402 wilds = (*name == '*' || *name == '?');
1403 for (p = name + 1; *p; ++p)
1404 if ((*p == '*' || *p == '?') && p[-1] != '\\')
1413 * Send info about connections which match, or all if the
1414 * mask matches me.name. Only restrictions are on those who
1415 * are invisible not being visible to 'foreigners' who use
1416 * a wild card based search to list it.
1418 sendto_one(sptr, Sformat, me.name, RPL_STATSLINKINFO, parv[0]);
1419 for (i = 0; i <= HighestFd; i++)
1421 if (!(acptr = LocalClientArray[i]))
1423 /* Don't return clients when this is a request for `all' */
1424 if (doall && IsUser(acptr))
1426 /* Don't show invisible people to unauthorized people when using
1427 * wildcards -- Is this still needed now /stats is oper only ? */
1428 if (IsInvisible(acptr) && (doall || wilds) &&
1429 !(MyConnect(sptr) && IsOper(sptr)) &&
1430 !IsAnOper(acptr) && (acptr != sptr))
1432 /* Only show the ones that match the given mask - if any */
1433 if (!doall && wilds && match(name, acptr->name))
1435 /* Skip all that do not match the specific query */
1436 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
1438 sendto_one(sptr, Lformat, me.name, RPL_STATSLINKINFO, parv[0],
1440 (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
1441 (int)acptr->sendK, (int)acptr->receiveM, (int)acptr->receiveK,
1442 CurrentTime - acptr->firsttime);
1448 report_configured_links(sptr, CONF_SERVER);
1451 case 'g': /* send glines */
1452 gline_remove_expired(TStime());
1453 for (gline = GlobalGlineList; gline; gline = gline->next) {
1454 sendto_one(sptr, rpl_str(RPL_STATSGLINE), me.name,
1455 sptr->name, 'G', gline->name, gline->host,
1456 gline->expire, gline->reason);
1461 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
1466 case 'k': /* display CONF_IPKILL as well
1467 as CONF_KILL -Kev */
1470 char *user, *host, *p;
1471 int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
1472 if ((MyUser(sptr) || IsOper(sptr)) && parc < 4)
1474 report_configured_links(sptr, conf_status);
1477 if (parc < 4 || *parv[3] == '\0')
1478 return need_more_params(sptr,
1479 (conf_status & CONF_KLINE) ? "STATS K" : "STATS I");
1482 for (p = parv[3]; *p; p++)
1490 if (*p == '?' || *p == '*')
1496 if (!(MyConnect(sptr) || IsOper(sptr)))
1504 if (conf_status == CONF_CLIENT)
1506 user = 0; /* Not used, but to avoid compiler warning. */
1512 if ((host = strchr(parv[3], '@')))
1523 for (aconf = GlobalConfList; aconf; aconf = aconf->next)
1525 if ((aconf->status & conf_status))
1527 if (conf_status == CONF_KLINE)
1529 if ((!wilds && ((user || aconf->host[1]) &&
1530 !match(aconf->host, host) &&
1531 (!user || !match(aconf->name, user)))) ||
1532 (wilds && !mmatch(host, aconf->host) &&
1533 (!user || !mmatch(user, aconf->name))))
1535 sendto_one(sptr, rpl_str(RPL_STATSKLINE), me.name,
1536 sptr->name, 'K', aconf->host, aconf->passwd, aconf->name,
1537 aconf->port, get_conf_class(aconf));
1542 else if (conf_status == CONF_CLIENT)
1544 if ((!wilds && (!match(aconf->host, host) ||
1545 !match(aconf->name, host))) ||
1546 (wilds && (!mmatch(host, aconf->host) ||
1547 !mmatch(host, aconf->name))))
1549 sendto_one(sptr, rpl_str(RPL_STATSILINE), me.name,
1550 sptr->name, 'I', aconf->host, aconf->name,
1551 aconf->port, get_conf_class(aconf));
1561 #if !defined(NDEBUG)
1562 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
1563 me.name, parv[0], fda_get_byte_count(), fda_get_block_count());
1568 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
1569 me.name, parv[0], get_mem_size(), get_alloc_cnt());
1572 report_memleak_stats(sptr, parc, parv);
1574 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
1575 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring "
1576 "is not enabled on this server", me.name, parv[0]);
1581 for (mptr = msgtab; mptr->cmd; mptr++)
1583 sendto_one(sptr, rpl_str(RPL_STATSCOMMANDS),
1584 me.name, parv[0], mptr->cmd, mptr->count, mptr->bytes);
1588 report_configured_links(sptr, CONF_OPS);
1593 * show listener ports
1594 * show hidden ports to opers, if there are more than 3 parameters,
1595 * interpret the fourth parameter as the port number, limit non-local
1596 * or non-oper results to 8 ports.
1598 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0,
1599 (MyUser(sptr) || IsOper(sptr)) ? 100 : 8);
1604 send_usage(sptr, parv[0]);
1608 report_configured_links(sptr, CONF_CRULEALL);
1611 report_configured_links(sptr, CONF_CRULE);
1614 tstats(sptr, parv[0]);
1617 report_configured_links(sptr, CONF_TLINES);
1620 report_configured_links(sptr, CONF_UWORLD);
1626 nowr = CurrentTime - me.since;
1627 sendto_one(sptr, rpl_str(RPL_STATSUPTIME), me.name, parv[0],
1628 nowr / 86400, (nowr / 3600) % 24, (nowr / 60) % 60, nowr % 60);
1629 sendto_one(sptr, rpl_str(RPL_STATSCONN), me.name, parv[0],
1630 max_connection_count, max_client_count);
1640 send_listinfo(sptr, parv[0]);
1645 report_classes(sptr);
1649 count_memory(sptr, parv[0]);
1655 sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, parv[0], stat);