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)DBufLength(&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))
281 report_configured_links(sptr, CONF_CLIENT);
284 if (EmptyString(parv[3]))
285 return need_more_params(sptr, "STATS I");
288 wilds = string_has_wildcards(host);
290 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
291 if (CONF_CLIENT == aconf->status) {
292 if ((!wilds && (!match(aconf->host, host) ||
293 !match(aconf->name, host))) ||
294 (wilds && (!mmatch(host, aconf->host) ||
295 !mmatch(host, aconf->name))))
297 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
298 aconf->port, get_conf_class(aconf));
308 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
309 fda_get_block_count());
314 sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
315 me.name, parv[0], get_mem_size(), get_alloc_cnt());
318 report_memleak_stats(sptr, parc, parv);
320 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
321 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
322 "is not enabled on this server", me.name, parv[0]);
327 for (mptr = msgtab; mptr->cmd; mptr++)
329 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
334 report_configured_links(sptr, CONF_OPS);
339 * show listener ports
340 * show hidden ports to opers, if there are more than 3 parameters,
341 * interpret the fourth parameter as the port number.
343 show_ports(sptr, 0, (parc > 3) ? atoi(parv[3]) : 0, 100);
348 send_usage(sptr, parv[0]);
352 report_crule_list(sptr, CRULE_ALL);
355 report_crule_list(sptr, CRULE_MASK);
358 tstats(sptr, parv[0]);
364 report_configured_links(sptr, CONF_UWORLD);
370 nowr = CurrentTime - me.since;
371 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
372 (nowr / 60) % 60, nowr % 60);
373 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
383 class_send_meminfo(sptr);
384 send_listinfo(sptr, parv[0]);
389 report_classes(sptr);
393 count_memory(sptr, parv[0]);
398 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
401 send_reply(sptr, RPL_ENDOFSTATS, stat);
406 * ms_stats - server message handler
408 * parv[0] = sender prefix
409 * parv[1] = statistics selector (defaults to Message frequency)
410 * parv[2] = target server (current server defaulted, if omitted)
411 * And 'stats l' and 'stats' L:
412 * parv[3] = server mask ("*" defaulted, if omitted)
414 * parv[3] = port mask (returns p-lines when its port is matched by this)
415 * Or for stats k,K,i and I:
416 * parv[3] = [user@]host.name (returns which K/I-lines match this)
417 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
418 * (defaults to old reply if ommitted, when local or Oper)
419 * A remote mask (something containing wildcards) is only
420 * allowed for IRC Operators.
422 * parv[3] = time param
423 * parv[4] = time param
424 * (see report_memleak_stats() in runmalloc.c for details)
426 * This function is getting really ugly. -Ghostwolf
428 int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
430 struct Message *mptr;
431 struct Client *acptr;
432 struct ConfItem *aconf;
433 char stat = parc > 1 ? parv[1][0] : '\0';
436 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
448 if (parc > 3 && !EmptyString(parv[3])) {
450 wilds = string_has_wildcards(name);
455 * Send info about connections which match, or all if the
456 * mask matches me.name. Only restrictions are on those who
457 * are invisible not being visible to 'foreigners' who use
458 * a wild card based search to list it.
460 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
461 "SendM SendKBytes RcveM RcveKBytes :Open since");
462 for (i = 0; i <= HighestFd; i++)
464 if (!(acptr = LocalClientArray[i]))
466 /* Don't return clients when this is a request for `all' */
467 if (doall && IsUser(acptr))
469 /* Don't show invisible people to unauthorized people when using
470 * wildcards -- Is this still needed now /stats is oper only ?
471 * Not here, because ms_stats is specifically a remote command,
472 * thus the check was removed. -Ghostwolf */
473 /* Only show the ones that match the given mask - if any */
474 if (!doall && wilds && match(name, acptr->name))
476 /* Skip all that do not match the specific query */
477 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
479 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
480 "%s %u %u %u %u %u :%Tu", acptr->name,
481 (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
482 (int)acptr->sendK, (int)acptr->receiveM,
483 (int)acptr->receiveK, CurrentTime - acptr->firsttime);
489 report_configured_links(sptr, CONF_SERVER);
492 case 'g': /* send glines */
497 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
500 case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
501 if (0 == report_klines(sptr, (parc > 3) ? parv[3] : 0, !IsOper(sptr)))
511 if (parc < 4 && IsOper(sptr)) {
512 report_configured_links(sptr, CONF_CLIENT);
515 if (parc < 4 || EmptyString(parv[3]))
516 return need_more_params(sptr, "STATS I");
519 wilds = string_has_wildcards(parv[3]);
525 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
526 if (CONF_CLIENT == aconf->status) {
527 if ((!wilds && (!match(aconf->host, host) ||
528 !match(aconf->name, host))) ||
529 (wilds && (!mmatch(host, aconf->host) ||
530 !mmatch(host, aconf->name))))
532 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
533 aconf->port, get_conf_class(aconf));
543 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
544 fda_get_block_count());
549 sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
550 me.name, parv[0], get_mem_size(), get_alloc_cnt());
553 report_memleak_stats(sptr, parc, parv);
555 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
556 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
557 "is not enabled on this server", me.name, parv[0]);
562 for (mptr = msgtab; mptr->cmd; mptr++)
564 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
569 report_configured_links(sptr, CONF_OPS);
574 * show listener ports
575 * show hidden ports to opers, if there are more than 3 parameters,
576 * interpret the fourth parameter as the port number, limit non-local
577 * or non-oper results to 8 ports.
579 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0, IsOper(sptr) ? 100 : 8);
584 send_usage(sptr, parv[0]);
588 report_crule_list(sptr, CRULE_ALL);
591 report_crule_list(sptr, CRULE_MASK);
594 tstats(sptr, parv[0]);
600 report_configured_links(sptr, CONF_UWORLD);
606 nowr = CurrentTime - me.since;
607 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
608 (nowr / 60) % 60, nowr % 60);
609 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
619 class_send_meminfo(sptr);
620 send_listinfo(sptr, parv[0]);
625 report_classes(sptr);
629 count_memory(sptr, parv[0]);
635 send_reply(sptr, RPL_ENDOFSTATS, stat);
640 * mo_stats - oper message handler
642 * parv[0] = sender prefix
643 * parv[1] = statistics selector (defaults to Message frequency)
644 * parv[2] = target server (current server defaulted, if omitted)
645 * And 'stats l' and 'stats' L:
646 * parv[3] = server mask ("*" defaulted, if omitted)
648 * parv[3] = port mask (returns p-lines when its port is matched by this)
649 * Or for stats k,K,i and I:
650 * parv[3] = [user@]host.name (returns which K/I-lines match this)
651 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
652 * (defaults to old reply if ommitted, when local or Oper)
653 * A remote mask (something containing wildcards) is only
654 * allowed for IRC Operators.
656 * parv[3] = time param
657 * parv[4] = time param
658 * (see report_memleak_stats() in runmalloc.c for details)
660 * This function is getting really ugly. -Ghostwolf
662 int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
664 struct Message* mptr;
665 struct Client* acptr;
666 struct ConfItem* aconf;
667 char stat = parc > 1 ? parv[1][0] : '\0';
668 const char** infotext = statsinfo;
671 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
679 int doall = 0, wilds = 0;
681 if (parc > 3 && !EmptyString(parv[3])) {
683 wilds = string_has_wildcards(name);
688 * Send info about connections which match, or all if the
689 * mask matches me.name. Only restrictions are on those who
690 * are invisible not being visible to 'foreigners' who use
691 * a wild card based search to list it.
693 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
694 "SendM SendKBytes RcveM RcveKBytes :Open since");
695 for (i = 0; i <= HighestFd; i++)
697 if (!(acptr = LocalClientArray[i]))
699 /* Don't return clients when this is a request for `all' */
700 if (doall && IsUser(acptr))
702 /* Only show the ones that match the given mask - if any */
703 if (!doall && wilds && match(name, acptr->name))
705 /* Skip all that do not match the specific query */
706 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
708 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
709 "%s %u %u %u %u %u :%Tu", acptr->name,
710 (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
711 (int)acptr->sendK, (int)acptr->receiveM,
712 (int)acptr->receiveK, CurrentTime - acptr->firsttime);
718 report_configured_links(sptr, CONF_SERVER);
721 case 'g': /* send glines */
726 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
729 case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
730 if (0 == report_klines(sptr, (parc > 3) ? parv[3] : 0, 0))
741 report_configured_links(sptr, CONF_CLIENT);
744 if (EmptyString(parv[3]))
745 return need_more_params(sptr, "STATS I");
748 wilds = string_has_wildcards(host);
750 for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
751 if (CONF_CLIENT == aconf->status) {
752 if ((!wilds && (!match(aconf->host, host) ||
753 !match(aconf->name, host))) ||
754 (wilds && (!mmatch(host, aconf->host) ||
755 !mmatch(host, aconf->name))))
757 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
758 aconf->port, get_conf_class(aconf));
768 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
769 fda_get_block_count());
774 sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
775 me.name, parv[0], get_mem_size(), get_alloc_cnt());
778 report_memleak_stats(sptr, parc, parv);
780 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
781 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
782 "is not enabled on this server", me.name, parv[0]);
787 for (mptr = msgtab; mptr->cmd; mptr++)
789 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
794 report_configured_links(sptr, CONF_OPS);
799 * show listener ports
800 * show hidden ports to opers, if there are more than 3 parameters,
801 * interpret the fourth parameter as the port number, limit non-local
802 * or non-oper results to 8 ports.
804 show_ports(sptr, 1, (parc > 3) ? atoi(parv[3]) : 0, 100);
809 send_usage(sptr, parv[0]);
813 report_crule_list(sptr, CRULE_ALL);
816 report_crule_list(sptr, CRULE_MASK);
819 tstats(sptr, parv[0]);
825 report_configured_links(sptr, CONF_UWORLD);
831 nowr = CurrentTime - me.since;
832 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
833 (nowr / 60) % 60, nowr % 60);
834 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
844 class_send_meminfo(sptr);
845 send_listinfo(sptr, parv[0]);
850 report_classes(sptr);
854 count_memory(sptr, parv[0]);
859 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
862 send_reply(sptr, RPL_ENDOFSTATS, stat);