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_features.h"
103 #include "ircd_reply.h"
104 #include "ircd_string.h"
106 #include "listener.h"
111 #include "numnicks.h"
112 #include "opercmds.h"
121 #include "userload.h"
128 int report_klines(struct Client* sptr, char* mask, int limit_query)
134 const struct DenyConf* conf;
136 if (EmptyString(mask)) {
138 return need_more_params(sptr, "STATS K");
140 report_deny_list(sptr);
145 wilds = string_has_wildcards(mask);
149 if ((host = strchr(mask, '@'))) {
157 for (conf = conf_get_deny_list(); conf; conf = conf->next) {
158 if ((!wilds && ((user || conf->hostmask) &&
159 !match(conf->hostmask, host) &&
160 (!user || !match(conf->usermask, user)))) ||
161 (wilds && !mmatch(host, conf->hostmask) &&
162 (!user || !mmatch(user, conf->usermask))))
164 send_reply(sptr, RPL_STATSKLINE, (conf->ip_kill) ? 'k' : 'K',
165 conf->hostmask, conf->message, conf->usermask);
170 /* send_reply(sptr, RPL_ENDOFSTATS, stat); */
176 * m_stats - generic message handler
178 * parv[0] = sender prefix
179 * parv[1] = statistics selector (defaults to Message frequency)
180 * parv[2] = target server (current server defaulted, if omitted)
181 * And 'stats l' and 'stats' L:
182 * parv[3] = server mask ("*" defaulted, if omitted)
184 * parv[3] = port mask (returns p-lines when its port is matched by this)
185 * Or for stats k,K,i and I:
186 * parv[3] = [user@]host.name (returns which K/I-lines match this)
187 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
188 * (defaults to old reply if ommitted, when local or Oper)
189 * A remote mask (something containing wildcards) is only
190 * allowed for IRC Operators.
192 * parv[3] = time param
193 * parv[4] = time param
194 * (see report_memleak_stats() in runmalloc.c for details)
196 * This function is getting really ugly. -Ghostwolf
198 int m_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
200 struct Message *mptr;
201 struct Client *acptr;
202 struct ConfItem *aconf;
203 char stat = parc > 1 ? parv[1][0] : '\0';
204 const char **infotext = statsinfo;
207 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
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));
259 report_configured_links(sptr, CONF_SERVER);
262 case 'g': /* send glines */
267 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
270 case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
271 if (0 == report_klines(sptr, (parc == 4) ? parv[3] : 0, 0))
276 feature_report(sptr);
286 report_configured_links(sptr, CONF_CLIENT);
289 if (EmptyString(parv[3]))
290 return need_more_params(sptr, "STATS I");
293 wilds = string_has_wildcards(host);
295 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
296 if (CONF_CLIENT == aconf->status) {
297 if ((!wilds && (!match(aconf->host, host) ||
298 !match(aconf->name, host))) ||
299 (wilds && (!mmatch(host, aconf->host) ||
300 !mmatch(host, aconf->name))))
302 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
303 aconf->port, get_conf_class(aconf));
313 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
314 fda_get_block_count());
318 for (mptr = msgtab; mptr->cmd; mptr++)
320 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
325 report_configured_links(sptr, CONF_OPS);
330 * show listener ports
331 * show hidden ports to opers, if there are more than 3 parameters,
332 * interpret the fourth parameter as the port number.
334 show_ports(sptr, 0, (parc > 3) ? atoi(parv[3]) : 0, 100);
339 send_usage(sptr, parv[0]);
343 report_crule_list(sptr, CRULE_ALL);
346 report_crule_list(sptr, CRULE_MASK);
349 tstats(sptr, parv[0]);
355 report_configured_links(sptr, CONF_UWORLD);
361 nowr = CurrentTime - cli_since(&me);
362 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
363 (nowr / 60) % 60, nowr % 60);
364 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
374 class_send_meminfo(sptr);
375 send_listinfo(sptr, parv[0]);
380 report_classes(sptr);
384 count_memory(sptr, parv[0]);
389 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
392 send_reply(sptr, RPL_ENDOFSTATS, stat);
397 * ms_stats - server message handler
399 * parv[0] = sender prefix
400 * parv[1] = statistics selector (defaults to Message frequency)
401 * parv[2] = target server (current server defaulted, if omitted)
402 * And 'stats l' and 'stats' L:
403 * parv[3] = server mask ("*" defaulted, if omitted)
405 * parv[3] = port mask (returns p-lines when its port is matched by this)
406 * Or for stats k,K,i and I:
407 * parv[3] = [user@]host.name (returns which K/I-lines match this)
408 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
409 * (defaults to old reply if ommitted, when local or Oper)
410 * A remote mask (something containing wildcards) is only
411 * allowed for IRC Operators.
413 * parv[3] = time param
414 * parv[4] = time param
415 * (see report_memleak_stats() in runmalloc.c for details)
417 * This function is getting really ugly. -Ghostwolf
419 int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
421 struct Message *mptr;
422 struct Client *acptr;
423 struct ConfItem *aconf;
424 char stat = parc > 1 ? parv[1][0] : '\0';
427 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
439 if (parc > 3 && !EmptyString(parv[3])) {
441 wilds = string_has_wildcards(name);
446 * Send info about connections which match, or all if the
447 * mask matches me.name. Only restrictions are on those who
448 * are invisible not being visible to 'foreigners' who use
449 * a wild card based search to list it.
451 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
452 "SendM SendKBytes RcveM RcveKBytes :Open since");
453 for (i = 0; i <= HighestFd; i++)
455 if (!(acptr = LocalClientArray[i]))
457 /* Don't return clients when this is a request for `all' */
458 if (doall && IsUser(acptr))
460 /* Don't show invisible people to unauthorized people when using
461 * wildcards -- Is this still needed now /stats is oper only ?
462 * Not here, because ms_stats is specifically a remote command,
463 * thus the check was removed. -Ghostwolf */
464 /* Only show the ones that match the given mask - if any */
465 if (!doall && wilds && match(name, cli_name(acptr)))
467 /* Skip all that do not match the specific query */
468 if (!(doall || wilds) && 0 != ircd_strcmp(name, cli_name(acptr)))
470 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
471 "%s %u %u %u %u %u :%Tu", cli_name(acptr),
472 (int)MsgQLength(&(cli_sendQ(acptr))), (int)cli_sendM(acptr),
473 (int)cli_sendK(acptr), (int)cli_receiveM(acptr),
474 (int)cli_receiveK(acptr), CurrentTime - cli_firsttime(acptr));
480 report_configured_links(sptr, CONF_SERVER);
483 case 'g': /* send glines */
488 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
491 case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
492 if (0 == report_klines(sptr, (parc > 3) ? parv[3] : 0, !IsOper(sptr)))
497 feature_report(sptr);
506 if (parc < 4 && IsOper(sptr)) {
507 report_configured_links(sptr, CONF_CLIENT);
510 if (parc < 4 || EmptyString(parv[3]))
511 return need_more_params(sptr, "STATS I");
514 wilds = string_has_wildcards(parv[3]);
520 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
521 if (CONF_CLIENT == aconf->status) {
522 if ((!wilds && (!match(aconf->host, host) ||
523 !match(aconf->name, host))) ||
524 (wilds && (!mmatch(host, aconf->host) ||
525 !mmatch(host, aconf->name))))
527 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
528 aconf->port, get_conf_class(aconf));
538 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
539 fda_get_block_count());
543 for (mptr = msgtab; mptr->cmd; mptr++)
545 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
550 report_configured_links(sptr, CONF_OPS);
555 * show listener ports
556 * show hidden ports to opers, if there are more than 3 parameters,
557 * interpret the fourth parameter as the port number, limit non-local
558 * or non-oper results to 8 ports.
560 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0, IsOper(sptr) ? 100 : 8);
565 send_usage(sptr, parv[0]);
569 report_crule_list(sptr, CRULE_ALL);
572 report_crule_list(sptr, CRULE_MASK);
575 tstats(sptr, parv[0]);
581 report_configured_links(sptr, CONF_UWORLD);
587 nowr = CurrentTime - cli_since(&me);
588 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
589 (nowr / 60) % 60, nowr % 60);
590 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
600 class_send_meminfo(sptr);
601 send_listinfo(sptr, parv[0]);
606 report_classes(sptr);
610 count_memory(sptr, parv[0]);
616 send_reply(sptr, RPL_ENDOFSTATS, stat);
621 * mo_stats - oper message handler
623 * parv[0] = sender prefix
624 * parv[1] = statistics selector (defaults to Message frequency)
625 * parv[2] = target server (current server defaulted, if omitted)
626 * And 'stats l' and 'stats' L:
627 * parv[3] = server mask ("*" defaulted, if omitted)
629 * parv[3] = port mask (returns p-lines when its port is matched by this)
630 * Or for stats k,K,i and I:
631 * parv[3] = [user@]host.name (returns which K/I-lines match this)
632 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
633 * (defaults to old reply if ommitted, when local or Oper)
634 * A remote mask (something containing wildcards) is only
635 * allowed for IRC Operators.
637 * parv[3] = time param
638 * parv[4] = time param
639 * (see report_memleak_stats() in runmalloc.c for details)
641 * This function is getting really ugly. -Ghostwolf
643 int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
645 struct Message* mptr;
646 struct Client* acptr;
647 struct ConfItem* aconf;
648 char stat = parc > 1 ? parv[1][0] : '\0';
649 const char** infotext = statsinfo;
652 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
660 int doall = 0, wilds = 0;
662 if (parc > 3 && !EmptyString(parv[3])) {
664 wilds = string_has_wildcards(name);
669 * Send info about connections which match, or all if the
670 * mask matches me.name. Only restrictions are on those who
671 * are invisible not being visible to 'foreigners' who use
672 * a wild card based search to list it.
674 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
675 "SendM SendKBytes RcveM RcveKBytes :Open since");
676 for (i = 0; i <= HighestFd; i++)
678 if (!(acptr = LocalClientArray[i]))
680 /* Don't return clients when this is a request for `all' */
681 if (doall && IsUser(acptr))
683 /* Only show the ones that match the given mask - if any */
684 if (!doall && wilds && match(name, cli_name(acptr)))
686 /* Skip all that do not match the specific query */
687 if (!(doall || wilds) && 0 != ircd_strcmp(name, cli_name(acptr)))
689 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
690 "%s %u %u %u %u %u :%Tu", cli_name(acptr),
691 (int)MsgQLength(&(cli_sendQ(acptr))), (int)cli_sendM(acptr),
692 (int)cli_sendK(acptr), (int)cli_receiveM(acptr),
693 (int)cli_receiveK(acptr), CurrentTime - cli_firsttime(acptr));
699 report_configured_links(sptr, CONF_SERVER);
702 case 'g': /* send glines */
707 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
710 case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
711 if (0 == report_klines(sptr, (parc > 3) ? parv[3] : 0, 0))
716 feature_report(sptr);
726 report_configured_links(sptr, CONF_CLIENT);
729 if (EmptyString(parv[3]))
730 return need_more_params(sptr, "STATS I");
733 wilds = string_has_wildcards(host);
735 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
736 if (CONF_CLIENT == aconf->status) {
737 if ((!wilds && (!match(aconf->host, host) ||
738 !match(aconf->name, host))) ||
739 (wilds && (!mmatch(host, aconf->host) ||
740 !mmatch(host, aconf->name))))
742 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
743 aconf->port, get_conf_class(aconf));
753 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
754 fda_get_block_count());
758 for (mptr = msgtab; mptr->cmd; mptr++)
760 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
765 report_configured_links(sptr, CONF_OPS);
770 * show listener ports
771 * show hidden ports to opers, if there are more than 3 parameters,
772 * interpret the fourth parameter as the port number, limit non-local
773 * or non-oper results to 8 ports.
775 show_ports(sptr, 1, (parc > 3) ? atoi(parv[3]) : 0, 100);
780 send_usage(sptr, parv[0]);
784 report_crule_list(sptr, CRULE_ALL);
787 report_crule_list(sptr, CRULE_MASK);
790 tstats(sptr, parv[0]);
796 report_configured_links(sptr, CONF_UWORLD);
802 nowr = CurrentTime - cli_since(&me);
803 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
804 (nowr / 60) % 60, nowr % 60);
805 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
815 class_send_meminfo(sptr);
816 send_listinfo(sptr, parv[0]);
821 report_classes(sptr);
825 count_memory(sptr, parv[0]);
830 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
833 send_reply(sptr, RPL_ENDOFSTATS, stat);