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
95 #include "ircd_alloc.h"
96 #include "ircd_chattr.h"
97 #include "ircd_events.h"
98 #include "ircd_features.h"
99 #include "ircd_policy.h"
100 #include "ircd_reply.h"
101 #include "ircd_string.h"
103 #include "listener.h"
108 #include "numnicks.h"
109 #include "opercmds.h"
118 #include "userload.h"
125 int report_klines(struct Client* sptr, char* mask, int limit_query)
131 const struct DenyConf* conf;
133 if (EmptyString(mask)) {
135 return need_more_params(sptr, "STATS K");
137 report_deny_list(sptr);
142 wilds = string_has_wildcards(mask);
146 if ((host = strchr(mask, '@'))) {
154 for (conf = conf_get_deny_list(); conf; conf = conf->next) {
155 if ((!wilds && ((user || conf->hostmask) &&
156 !match(conf->hostmask, host) &&
157 (!user || !match(conf->usermask, user)))) ||
158 (wilds && !mmatch(host, conf->hostmask) &&
159 (!user || !mmatch(user, conf->usermask))))
161 send_reply(sptr, RPL_STATSKLINE,
162 (conf->flags & DENY_FLAGS_IP) ? 'k' : 'K',
163 conf->hostmask, conf->message, conf->usermask);
168 /* send_reply(sptr, RPL_ENDOFSTATS, stat); */
174 * m_stats - generic message handler
176 * parv[0] = sender prefix
177 * parv[1] = statistics selector (defaults to Message frequency)
178 * parv[2] = target server (current server defaulted, if omitted)
179 * And 'stats l' and 'stats' L:
180 * parv[3] = server mask ("*" defaulted, if omitted)
182 * parv[3] = port mask (returns p-lines when its port is matched by this)
183 * Or for stats k,K,i and I:
184 * parv[3] = [user@]host.name (returns which K/I-lines match this)
185 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
186 * (defaults to old reply if ommitted, when local or Oper)
187 * A remote mask (something containing wildcards) is only
188 * allowed for IRC Operators.
190 * parv[3] = time param
191 * parv[4] = time param
192 * (see report_memleak_stats() in runmalloc.c for details)
194 * This function is getting really ugly. -Ghostwolf
196 int m_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
198 char stat = parc > 1 ? parv[1][0] : '\0';
199 const char **infotext = statsinfo;
201 if (hunt_stats(cptr, sptr, parc, parv, stat, HEAD_IN_SAND_REMOTE)
209 #ifdef HEAD_IN_SAND_STATS_L
210 return m_not_oper(sptr,cptr,parc,parv);
213 struct Client *acptr;
219 if (parc > 3 && !EmptyString(parv[3])) {
221 wilds = string_has_wildcards(name);
226 * Send info about connections which match, or all if the
227 * mask matches me.name. Only restrictions are on those who
228 * are invisible not being visible to 'foreigners' who use
229 * a wild card based search to list it.
231 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
232 "SendM SendKBytes RcveM RcveKBytes :Open since");
233 for (i = 0; i <= HighestFd; i++)
235 if (!(acptr = LocalClientArray[i]))
237 /* Don't return clients when this is a request for `all' */
238 if (doall && IsUser(acptr))
240 /* Don't show invisible people to non opers unless they know the nick */
241 if (IsInvisible(acptr) && (doall || wilds) && !IsAnOper(acptr) && (acptr != sptr))
243 /* Only show the ones that match the given mask - if any */
244 if (!doall && wilds && match(name, cli_name(acptr)))
246 /* Skip all that do not match the specific query */
247 if (!(doall || wilds) && 0 != ircd_strcmp(name, cli_name(acptr)))
249 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
250 "%s %u %u %u %u %u :%Tu", (*(cli_name(acptr))) ? cli_name(acptr) : "<unregistered>",
251 (int)MsgQLength(&(cli_sendQ(acptr))), (int)cli_sendM(acptr),
252 (int)cli_sendK(acptr), (int)cli_receiveM(acptr),
253 (int)cli_receiveK(acptr), CurrentTime - cli_firsttime(acptr));
261 #ifdef HEAD_IN_SAND_STATS_C
262 return m_not_oper(sptr,cptr,parc,parv);
264 report_configured_links(sptr, CONF_SERVER);
269 case 'e': /* report engine name */
270 #ifdef HEAD_IN_SAND_STATS_E
271 return m_not_oper(sptr,cptr,parc,parv);
273 send_reply(sptr, RPL_STATSENGINE, engine_name());
278 case 'g': /* send glines */
279 #ifdef HEAD_IN_SAND_STATS_G
280 return m_not_oper(sptr,cptr,parc,parv);
288 #ifdef HEAD_IN_SAND_STATS_H
289 return m_not_oper(sptr,cptr,parc,parv);
291 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
296 case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
297 #ifdef HEAD_IN_SAND_STATS_K
298 /* Simple version - if you want to fix it - send in a patch */
299 return m_not_oper(sptr,cptr,parc,parv);
301 if (0 == report_klines(sptr, (parc == 4) ? parv[3] : 0, 0))
307 #ifdef HEAD_IN_SAND_STATS_F
308 return m_not_oper(sptr,cptr,parc,parv);
310 feature_report(sptr);
316 #ifdef HEAD_IN_SAND_STATS_I
317 /* Simple version - if you want to fix it - send in a patch */
318 return m_not_oper(sptr,cptr,parc,parv);
321 struct ConfItem *aconf;
327 report_configured_links(sptr, CONF_CLIENT);
330 if (EmptyString(parv[3]))
331 return need_more_params(sptr, "STATS I");
334 wilds = string_has_wildcards(host);
336 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
337 if (CONF_CLIENT == aconf->status) {
338 if ((!wilds && (!match(aconf->host, host) ||
339 !match(aconf->name, host))) ||
340 (wilds && (!mmatch(host, aconf->host) ||
341 !mmatch(host, aconf->name))))
343 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
344 aconf->port, get_conf_class(aconf));
355 #ifdef HEAD_IN_SAND_STATS_M
356 return m_not_oper(sptr,cptr,parc,parv);
359 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
360 fda_get_block_count());
366 #ifdef HEAD_IN_SAND_STATS_m
367 return m_not_oper(sptr,cptr,parc,parv);
370 struct Message *mptr;
372 for (mptr = msgtab; mptr->cmd; mptr++)
374 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
382 #ifdef HEAD_IN_SAND_STATS_O
383 return m_not_oper(sptr,cptr,parc,parv);
385 report_configured_links(sptr, CONF_OPS);
392 * show listener ports
393 * show hidden ports to opers, if there are more than 3 parameters,
394 * interpret the fourth parameter as the port number.
396 #ifdef HEAD_IN_SAND_STATS_P
397 return m_not_oper(sptr,cptr,parc,parv);
399 show_ports(sptr, 0, (parc > 3) ? atoi(parv[3]) : 0, 100);
405 #ifdef HEAD_IN_SAND_STATS_R
406 return m_not_oper(sptr,cptr,parc,parv);
409 send_usage(sptr, parv[0]);
415 #ifdef HEAD_IN_SAND_STATS_D
416 return m_not_oper(sptr,cptr,parc,parv);
418 report_crule_list(sptr, CRULE_ALL);
423 #ifdef HEAD_IN_SAND_STATS_d
424 return m_not_oper(sptr,cptr,parc,parv);
426 report_crule_list(sptr, CRULE_MASK);
431 #ifdef HEAD_IN_SAND_STATS_t
432 return m_not_oper(sptr,cptr,parc,parv);
434 tstats(sptr, parv[0]);
439 #ifdef HEAD_IN_SAND_STATS_T
440 return m_not_oper(sptr,cptr,parc,parv);
447 #ifdef HEAD_IN_SAND_STATS_U
448 return m_not_oper(sptr,cptr,parc,parv);
450 report_configured_links(sptr, CONF_UWORLD);
455 #ifdef HEAD_IN_SAND_STATS_u
456 return m_not_oper(sptr,cptr,parc,parv);
461 nowr = CurrentTime - cli_since(&me);
462 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
463 (nowr / 60) % 60, nowr % 60);
464 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
471 #ifdef HEAD_IN_SAND_STATS_W
472 return m_not_oper(sptr,cptr,parc,parv);
480 #ifdef HEAD_IN_SAND_STATS_X
481 return m_not_oper(sptr,cptr,parc,parv);
484 class_send_meminfo(sptr);
485 send_listinfo(sptr, parv[0]);
492 #ifdef HEAD_IN_SAND_STATS_Y
493 return m_not_oper(sptr,cptr,parc,parv);
495 report_classes(sptr);
501 #ifdef HEAD_IN_SAND_STATS_Z
502 return m_not_oper(sptr,cptr,parc,parv);
504 count_memory(sptr, parv[0]);
511 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
514 send_reply(sptr, RPL_ENDOFSTATS, stat);
519 * ms_stats - server message handler
521 * parv[0] = sender prefix
522 * parv[1] = statistics selector (defaults to Message frequency)
523 * parv[2] = target server (current server defaulted, if omitted)
524 * And 'stats l' and 'stats' L:
525 * parv[3] = server mask ("*" defaulted, if omitted)
527 * parv[3] = port mask (returns p-lines when its port is matched by this)
528 * Or for stats k,K,i and I:
529 * parv[3] = [user@]host.name (returns which K/I-lines match this)
530 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
531 * (defaults to old reply if ommitted, when local or Oper)
532 * A remote mask (something containing wildcards) is only
533 * allowed for IRC Operators.
535 * parv[3] = time param
536 * parv[4] = time param
537 * (see report_memleak_stats() in runmalloc.c for details)
539 * This function is getting really ugly. -Ghostwolf
541 int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
543 struct Message *mptr;
544 struct Client *acptr;
545 struct ConfItem *aconf;
546 char stat = parc > 1 ? parv[1][0] : '\0';
549 if (hunt_stats(cptr, sptr, parc, parv, stat, 0) != HUNTED_ISME)
561 if (parc > 3 && !EmptyString(parv[3])) {
563 wilds = string_has_wildcards(name);
568 * Send info about connections which match, or all if the
569 * mask matches me.name. Only restrictions are on those who
570 * are invisible not being visible to 'foreigners' who use
571 * a wild card based search to list it.
573 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
574 "SendM SendKBytes RcveM RcveKBytes :Open since");
575 for (i = 0; i <= HighestFd; i++)
577 if (!(acptr = LocalClientArray[i]))
579 /* Don't return clients when this is a request for `all' */
580 if (doall && IsUser(acptr))
582 /* Don't show invisible people to unauthorized people when using
583 * wildcards -- Is this still needed now /stats is oper only ?
584 * Not here, because ms_stats is specifically a remote command,
585 * thus the check was removed. -Ghostwolf */
586 /* Only show the ones that match the given mask - if any */
587 if (!doall && wilds && match(name, cli_name(acptr)))
589 /* Skip all that do not match the specific query */
590 if (!(doall || wilds) && 0 != ircd_strcmp(name, cli_name(acptr)))
592 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
593 "%s %u %u %u %u %u :%Tu", cli_name(acptr),
594 (int)MsgQLength(&(cli_sendQ(acptr))), (int)cli_sendM(acptr),
595 (int)cli_sendK(acptr), (int)cli_receiveM(acptr),
596 (int)cli_receiveK(acptr), CurrentTime - cli_firsttime(acptr));
602 report_configured_links(sptr, CONF_SERVER);
605 case 'e': /* report engine name */
606 send_reply(sptr, RPL_STATSENGINE, engine_name());
609 case 'g': /* send glines */
614 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
617 case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
618 if (0 == report_klines(sptr, (parc > 3) ? parv[3] : 0, !IsOper(sptr)))
623 feature_report(sptr);
632 if (parc < 4 && IsOper(sptr)) {
633 report_configured_links(sptr, CONF_CLIENT);
636 if (parc < 4 || EmptyString(parv[3]))
637 return need_more_params(sptr, "STATS I");
640 wilds = string_has_wildcards(parv[3]);
646 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
647 if (CONF_CLIENT == aconf->status) {
648 if ((!wilds && (!match(aconf->host, host) ||
649 !match(aconf->name, host))) ||
650 (wilds && (!mmatch(host, aconf->host) ||
651 !mmatch(host, aconf->name))))
653 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
654 aconf->port, get_conf_class(aconf));
664 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
665 fda_get_block_count());
669 for (mptr = msgtab; mptr->cmd; mptr++)
671 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
676 report_configured_links(sptr, CONF_OPS);
681 * show listener ports
682 * show hidden ports to opers, if there are more than 3 parameters,
683 * interpret the fourth parameter as the port number, limit non-local
684 * or non-oper results to 8 ports.
686 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0, IsOper(sptr) ? 100 : 8);
691 send_usage(sptr, parv[0]);
695 report_crule_list(sptr, CRULE_ALL);
698 report_crule_list(sptr, CRULE_MASK);
701 tstats(sptr, parv[0]);
707 report_configured_links(sptr, CONF_UWORLD);
713 nowr = CurrentTime - cli_since(&me);
714 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
715 (nowr / 60) % 60, nowr % 60);
716 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
726 class_send_meminfo(sptr);
727 send_listinfo(sptr, parv[0]);
732 report_classes(sptr);
736 count_memory(sptr, parv[0]);
742 send_reply(sptr, RPL_ENDOFSTATS, stat);
747 * mo_stats - oper message handler
749 * parv[0] = sender prefix
750 * parv[1] = statistics selector (defaults to Message frequency)
751 * parv[2] = target server (current server defaulted, if omitted)
752 * And 'stats l' and 'stats' L:
753 * parv[3] = server mask ("*" defaulted, if omitted)
755 * parv[3] = port mask (returns p-lines when its port is matched by this)
756 * Or for stats k,K,i and I:
757 * parv[3] = [user@]host.name (returns which K/I-lines match this)
758 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
759 * (defaults to old reply if ommitted, when local or Oper)
760 * A remote mask (something containing wildcards) is only
761 * allowed for IRC Operators.
763 * parv[3] = time param
764 * parv[4] = time param
765 * (see report_memleak_stats() in runmalloc.c for details)
767 * This function is getting really ugly. -Ghostwolf
769 int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
771 struct Message* mptr;
772 struct Client* acptr;
773 struct ConfItem* aconf;
774 char stat = parc > 1 ? parv[1][0] : '\0';
775 const char** infotext = statsinfo;
778 if (hunt_stats(cptr, sptr, parc, parv, stat, HEAD_IN_SAND_REMOTE)
787 int doall = 0, wilds = 0;
789 if (parc > 3 && !EmptyString(parv[3])) {
791 wilds = string_has_wildcards(name);
796 * Send info about connections which match, or all if the
797 * mask matches me.name. Only restrictions are on those who
798 * are invisible not being visible to 'foreigners' who use
799 * a wild card based search to list it.
801 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
802 "SendM SendKBytes RcveM RcveKBytes :Open since");
803 for (i = 0; i <= HighestFd; i++)
805 if (!(acptr = LocalClientArray[i]))
807 /* Don't return clients when this is a request for `all' */
808 if (doall && IsUser(acptr))
810 /* Only show the ones that match the given mask - if any */
811 if (!doall && wilds && match(name, cli_name(acptr)))
813 /* Skip all that do not match the specific query */
814 if (!(doall || wilds) && 0 != ircd_strcmp(name, cli_name(acptr)))
816 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
817 "%s %u %u %u %u %u :%Tu", cli_name(acptr),
818 (int)MsgQLength(&(cli_sendQ(acptr))), (int)cli_sendM(acptr),
819 (int)cli_sendK(acptr), (int)cli_receiveM(acptr),
820 (int)cli_receiveK(acptr), CurrentTime - cli_firsttime(acptr));
826 report_configured_links(sptr, CONF_SERVER);
829 case 'e': /* report engine name */
830 send_reply(sptr, RPL_STATSENGINE, engine_name());
833 case 'g': /* send glines */
838 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
841 case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
842 if (0 == report_klines(sptr, (parc > 3) ? parv[3] : 0, 0))
847 feature_report(sptr);
857 report_configured_links(sptr, CONF_CLIENT);
860 if (EmptyString(parv[3]))
861 return need_more_params(sptr, "STATS I");
864 wilds = string_has_wildcards(host);
866 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
867 if (CONF_CLIENT == aconf->status) {
868 if ((!wilds && (!match(aconf->host, host) ||
869 !match(aconf->name, host))) ||
870 (wilds && (!mmatch(host, aconf->host) ||
871 !mmatch(host, aconf->name))))
873 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
874 aconf->port, get_conf_class(aconf));
884 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
885 fda_get_block_count());
889 for (mptr = msgtab; mptr->cmd; mptr++)
891 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
896 report_configured_links(sptr, CONF_OPS);
901 * show listener ports
902 * show hidden ports to opers, if there are more than 3 parameters,
903 * interpret the fourth parameter as the port number, limit non-local
904 * or non-oper results to 8 ports.
906 show_ports(sptr, 1, (parc > 3) ? atoi(parv[3]) : 0, 100);
911 send_usage(sptr, parv[0]);
915 report_crule_list(sptr, CRULE_ALL);
918 report_crule_list(sptr, CRULE_MASK);
921 tstats(sptr, parv[0]);
927 report_configured_links(sptr, CONF_UWORLD);
933 nowr = CurrentTime - cli_since(&me);
934 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
935 (nowr / 60) % 60, nowr % 60);
936 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
946 class_send_meminfo(sptr);
947 send_listinfo(sptr, parv[0]);
952 report_classes(sptr);
956 count_memory(sptr, parv[0]);
961 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
964 send_reply(sptr, RPL_ENDOFSTATS, stat);