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, acptr->name))
245 /* Skip all that do not match the specific query */
246 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
248 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
249 "%s %u %u %u %u %u :%Tu", (*acptr->name) ? acptr->name : "<unregistered>",
250 (int)MsgQLength(&acptr->sendQ), (int)acptr->sendM,
251 (int)acptr->sendK, (int)acptr->receiveM,
252 (int)acptr->receiveK, CurrentTime - acptr->firsttime);
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());
318 sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
319 me.name, parv[0], get_mem_size(), get_alloc_cnt());
322 report_memleak_stats(sptr, parc, parv);
324 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
325 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
326 "is not enabled on this server", me.name, parv[0]);
331 for (mptr = msgtab; mptr->cmd; mptr++)
333 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
338 report_configured_links(sptr, CONF_OPS);
343 * show listener ports
344 * show hidden ports to opers, if there are more than 3 parameters,
345 * interpret the fourth parameter as the port number.
347 show_ports(sptr, 0, (parc > 3) ? atoi(parv[3]) : 0, 100);
352 send_usage(sptr, parv[0]);
356 report_crule_list(sptr, CRULE_ALL);
359 report_crule_list(sptr, CRULE_MASK);
362 tstats(sptr, parv[0]);
368 report_configured_links(sptr, CONF_UWORLD);
374 nowr = CurrentTime - me.since;
375 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
376 (nowr / 60) % 60, nowr % 60);
377 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
387 class_send_meminfo(sptr);
388 send_listinfo(sptr, parv[0]);
393 report_classes(sptr);
397 count_memory(sptr, parv[0]);
402 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
405 send_reply(sptr, RPL_ENDOFSTATS, stat);
410 * ms_stats - server message handler
412 * parv[0] = sender prefix
413 * parv[1] = statistics selector (defaults to Message frequency)
414 * parv[2] = target server (current server defaulted, if omitted)
415 * And 'stats l' and 'stats' L:
416 * parv[3] = server mask ("*" defaulted, if omitted)
418 * parv[3] = port mask (returns p-lines when its port is matched by this)
419 * Or for stats k,K,i and I:
420 * parv[3] = [user@]host.name (returns which K/I-lines match this)
421 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
422 * (defaults to old reply if ommitted, when local or Oper)
423 * A remote mask (something containing wildcards) is only
424 * allowed for IRC Operators.
426 * parv[3] = time param
427 * parv[4] = time param
428 * (see report_memleak_stats() in runmalloc.c for details)
430 * This function is getting really ugly. -Ghostwolf
432 int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
434 struct Message *mptr;
435 struct Client *acptr;
436 struct ConfItem *aconf;
437 char stat = parc > 1 ? parv[1][0] : '\0';
440 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
452 if (parc > 3 && !EmptyString(parv[3])) {
454 wilds = string_has_wildcards(name);
459 * Send info about connections which match, or all if the
460 * mask matches me.name. Only restrictions are on those who
461 * are invisible not being visible to 'foreigners' who use
462 * a wild card based search to list it.
464 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
465 "SendM SendKBytes RcveM RcveKBytes :Open since");
466 for (i = 0; i <= HighestFd; i++)
468 if (!(acptr = LocalClientArray[i]))
470 /* Don't return clients when this is a request for `all' */
471 if (doall && IsUser(acptr))
473 /* Don't show invisible people to unauthorized people when using
474 * wildcards -- Is this still needed now /stats is oper only ?
475 * Not here, because ms_stats is specifically a remote command,
476 * thus the check was removed. -Ghostwolf */
477 /* Only show the ones that match the given mask - if any */
478 if (!doall && wilds && match(name, acptr->name))
480 /* Skip all that do not match the specific query */
481 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
483 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
484 "%s %u %u %u %u %u :%Tu", acptr->name,
485 (int)MsgQLength(&acptr->sendQ), (int)acptr->sendM,
486 (int)acptr->sendK, (int)acptr->receiveM,
487 (int)acptr->receiveK, CurrentTime - acptr->firsttime);
493 report_configured_links(sptr, CONF_SERVER);
496 case 'g': /* send glines */
501 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
504 case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
505 if (0 == report_klines(sptr, (parc > 3) ? parv[3] : 0, !IsOper(sptr)))
510 report_feature_list(sptr);
519 if (parc < 4 && IsOper(sptr)) {
520 report_configured_links(sptr, CONF_CLIENT);
523 if (parc < 4 || EmptyString(parv[3]))
524 return need_more_params(sptr, "STATS I");
527 wilds = string_has_wildcards(parv[3]);
533 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
534 if (CONF_CLIENT == aconf->status) {
535 if ((!wilds && (!match(aconf->host, host) ||
536 !match(aconf->name, host))) ||
537 (wilds && (!mmatch(host, aconf->host) ||
538 !mmatch(host, aconf->name))))
540 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
541 aconf->port, get_conf_class(aconf));
551 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
552 fda_get_block_count());
557 sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
558 me.name, parv[0], get_mem_size(), get_alloc_cnt());
561 report_memleak_stats(sptr, parc, parv);
563 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
564 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
565 "is not enabled on this server", me.name, parv[0]);
570 for (mptr = msgtab; mptr->cmd; mptr++)
572 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
577 report_configured_links(sptr, CONF_OPS);
582 * show listener ports
583 * show hidden ports to opers, if there are more than 3 parameters,
584 * interpret the fourth parameter as the port number, limit non-local
585 * or non-oper results to 8 ports.
587 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0, IsOper(sptr) ? 100 : 8);
592 send_usage(sptr, parv[0]);
596 report_crule_list(sptr, CRULE_ALL);
599 report_crule_list(sptr, CRULE_MASK);
602 tstats(sptr, parv[0]);
608 report_configured_links(sptr, CONF_UWORLD);
614 nowr = CurrentTime - me.since;
615 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
616 (nowr / 60) % 60, nowr % 60);
617 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
627 class_send_meminfo(sptr);
628 send_listinfo(sptr, parv[0]);
633 report_classes(sptr);
637 count_memory(sptr, parv[0]);
643 send_reply(sptr, RPL_ENDOFSTATS, stat);
648 * mo_stats - oper message handler
650 * parv[0] = sender prefix
651 * parv[1] = statistics selector (defaults to Message frequency)
652 * parv[2] = target server (current server defaulted, if omitted)
653 * And 'stats l' and 'stats' L:
654 * parv[3] = server mask ("*" defaulted, if omitted)
656 * parv[3] = port mask (returns p-lines when its port is matched by this)
657 * Or for stats k,K,i and I:
658 * parv[3] = [user@]host.name (returns which K/I-lines match this)
659 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
660 * (defaults to old reply if ommitted, when local or Oper)
661 * A remote mask (something containing wildcards) is only
662 * allowed for IRC Operators.
664 * parv[3] = time param
665 * parv[4] = time param
666 * (see report_memleak_stats() in runmalloc.c for details)
668 * This function is getting really ugly. -Ghostwolf
670 int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
672 struct Message* mptr;
673 struct Client* acptr;
674 struct ConfItem* aconf;
675 char stat = parc > 1 ? parv[1][0] : '\0';
676 const char** infotext = statsinfo;
679 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
687 int doall = 0, wilds = 0;
689 if (parc > 3 && !EmptyString(parv[3])) {
691 wilds = string_has_wildcards(name);
696 * Send info about connections which match, or all if the
697 * mask matches me.name. Only restrictions are on those who
698 * are invisible not being visible to 'foreigners' who use
699 * a wild card based search to list it.
701 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
702 "SendM SendKBytes RcveM RcveKBytes :Open since");
703 for (i = 0; i <= HighestFd; i++)
705 if (!(acptr = LocalClientArray[i]))
707 /* Don't return clients when this is a request for `all' */
708 if (doall && IsUser(acptr))
710 /* Only show the ones that match the given mask - if any */
711 if (!doall && wilds && match(name, acptr->name))
713 /* Skip all that do not match the specific query */
714 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
716 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
717 "%s %u %u %u %u %u :%Tu", acptr->name,
718 (int)MsgQLength(&acptr->sendQ), (int)acptr->sendM,
719 (int)acptr->sendK, (int)acptr->receiveM,
720 (int)acptr->receiveK, CurrentTime - acptr->firsttime);
726 report_configured_links(sptr, CONF_SERVER);
729 case 'g': /* send glines */
734 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
737 case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
738 if (0 == report_klines(sptr, (parc > 3) ? parv[3] : 0, 0))
743 report_feature_list(sptr);
753 report_configured_links(sptr, CONF_CLIENT);
756 if (EmptyString(parv[3]))
757 return need_more_params(sptr, "STATS I");
760 wilds = string_has_wildcards(host);
762 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
763 if (CONF_CLIENT == aconf->status) {
764 if ((!wilds && (!match(aconf->host, host) ||
765 !match(aconf->name, host))) ||
766 (wilds && (!mmatch(host, aconf->host) ||
767 !mmatch(host, aconf->name))))
769 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
770 aconf->port, get_conf_class(aconf));
780 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
781 fda_get_block_count());
786 sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
787 me.name, parv[0], get_mem_size(), get_alloc_cnt());
790 report_memleak_stats(sptr, parc, parv);
792 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
793 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
794 "is not enabled on this server", me.name, parv[0]);
799 for (mptr = msgtab; mptr->cmd; mptr++)
801 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
806 report_configured_links(sptr, CONF_OPS);
811 * show listener ports
812 * show hidden ports to opers, if there are more than 3 parameters,
813 * interpret the fourth parameter as the port number, limit non-local
814 * or non-oper results to 8 ports.
816 show_ports(sptr, 1, (parc > 3) ? atoi(parv[3]) : 0, 100);
821 send_usage(sptr, parv[0]);
825 report_crule_list(sptr, CRULE_ALL);
828 report_crule_list(sptr, CRULE_MASK);
831 tstats(sptr, parv[0]);
837 report_configured_links(sptr, CONF_UWORLD);
843 nowr = CurrentTime - me.since;
844 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
845 (nowr / 60) % 60, nowr % 60);
846 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
856 class_send_meminfo(sptr);
857 send_listinfo(sptr, parv[0]);
862 report_classes(sptr);
866 count_memory(sptr, parv[0]);
871 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
874 send_reply(sptr, RPL_ENDOFSTATS, stat);