2 * ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd).
3 * m_stats.c: Sends the user statistics or config information.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
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 2 of the License, or
12 * (at your option) any later version.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include "class.h" /* report_classes */
27 #include "client.h" /* Client */
28 #include "common.h" /* TRUE/FALSE */
30 #include "ircd.h" /* me */
31 #include "listener.h" /* show_ports */
32 #include "msg.h" /* Message */
33 #include "hostmask.h" /* report_mtrie_conf_links */
34 #include "numeric.h" /* ERR_xxx */
35 #include "scache.h" /* list_scache */
36 #include "send.h" /* sendto_one */
37 #include "s_conf.h" /* ConfItem */
38 #include "s_serv.h" /* hunt_server */
40 #include "s_user.h" /* show_opers */
41 #include "blacklist.h" /* dnsbl stuff */
45 #include "s_newconf.h"
49 #include "rb_radixtree.h"
52 static int m_stats (struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
53 static const char stats_desc
[] =
54 "Provides the STATS command to inspect various server/network information";
56 struct Message stats_msgtab
= {
58 {mg_unreg
, {m_stats
, 2}, {m_stats
, 3}, mg_ignore
, mg_ignore
, {m_stats
, 2}}
62 int doing_stats_p_hook
;
64 mapi_clist_av1 stats_clist
[] = { &stats_msgtab
, NULL
};
65 mapi_hlist_av1 stats_hlist
[] = {
66 { "doing_stats", &doing_stats_hook
},
67 { "doing_stats_p", &doing_stats_p_hook
},
71 DECLARE_MODULE_AV2(stats
, NULL
, NULL
, stats_clist
, stats_hlist
, NULL
, NULL
, NULL
, stats_desc
);
73 const char *Lformat
= "%s %u %u %u %u %u :%u %u %s";
75 static void stats_l_list(struct Client
*s
, const char *, int, int, rb_dlink_list
*, char,
76 int (*check_fn
)(struct Client
*target_p
));
77 static void stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
80 static int stats_spy(struct Client
*, char, const char *);
81 static void stats_p_spy(struct Client
*);
83 /* Heres our struct for the stats table */
87 void (*handler
) (struct Client
*source_p
);
92 static void stats_dns_servers(struct Client
*);
93 static void stats_delay(struct Client
*);
94 static void stats_hash(struct Client
*);
95 static void stats_connect(struct Client
*);
96 static void stats_tdeny(struct Client
*);
97 static void stats_deny(struct Client
*);
98 static void stats_exempt(struct Client
*);
99 static void stats_events(struct Client
*);
100 static void stats_prop_klines(struct Client
*);
101 static void stats_hubleaf(struct Client
*);
102 static void stats_auth(struct Client
*);
103 static void stats_tklines(struct Client
*);
104 static void stats_klines(struct Client
*);
105 static void stats_messages(struct Client
*);
106 static void stats_dnsbl(struct Client
*);
107 static void stats_oper(struct Client
*);
108 static void stats_privset(struct Client
*);
109 static void stats_operedup(struct Client
*);
110 static void stats_ports(struct Client
*);
111 static void stats_tresv(struct Client
*);
112 static void stats_resv(struct Client
*);
113 static void stats_ssld(struct Client
*);
114 static void stats_usage(struct Client
*);
115 static void stats_tstats(struct Client
*);
116 static void stats_uptime(struct Client
*);
117 static void stats_shared(struct Client
*);
118 static void stats_servers(struct Client
*);
119 static void stats_tgecos(struct Client
*);
120 static void stats_gecos(struct Client
*);
121 static void stats_class(struct Client
*);
122 static void stats_memory(struct Client
*);
123 static void stats_servlinks(struct Client
*);
124 static void stats_ltrace(struct Client
*, int, const char **);
125 static void stats_ziplinks(struct Client
*);
126 static void stats_comm(struct Client
*);
127 static void stats_capability(struct Client
*);
129 /* This table contains the possible stats items, in order:
130 * stats letter, function to call, operonly? adminonly?
131 * case only matters in the stats letter column.. -- fl_
133 static struct StatsStruct stats_cmd_table
[] = {
134 /* letter function need_oper need_admin */
135 {'a', stats_dns_servers
, 1, 1, },
136 {'A', stats_dns_servers
, 1, 1, },
137 {'b', stats_delay
, 1, 1, },
138 {'B', stats_hash
, 1, 1, },
139 {'c', stats_connect
, 0, 0, },
140 {'C', stats_capability
, 1, 0, },
141 {'d', stats_tdeny
, 1, 0, },
142 {'D', stats_deny
, 1, 0, },
143 {'e', stats_exempt
, 1, 0, },
144 {'E', stats_events
, 1, 1, },
145 {'f', stats_comm
, 1, 1, },
146 {'F', stats_comm
, 1, 1, },
147 {'g', stats_prop_klines
, 1, 0, },
148 {'h', stats_hubleaf
, 0, 0, },
149 {'H', stats_hubleaf
, 0, 0, },
150 {'i', stats_auth
, 0, 0, },
151 {'I', stats_auth
, 0, 0, },
152 {'k', stats_tklines
, 0, 0, },
153 {'K', stats_klines
, 0, 0, },
154 {'l', NULL
/* special */, 0, 0, },
155 {'L', NULL
/* special */, 0, 0, },
156 {'m', stats_messages
, 0, 0, },
157 {'M', stats_messages
, 0, 0, },
158 {'n', stats_dnsbl
, 0, 0, },
159 {'o', stats_oper
, 0, 0, },
160 {'O', stats_privset
, 1, 0, },
161 {'p', stats_operedup
, 0, 0, },
162 {'P', stats_ports
, 0, 0, },
163 {'q', stats_tresv
, 1, 0, },
164 {'Q', stats_resv
, 1, 0, },
165 {'r', stats_usage
, 1, 0, },
166 {'R', stats_usage
, 1, 0, },
167 {'s', stats_ssld
, 1, 1, },
168 {'S', stats_ssld
, 1, 1, },
169 {'t', stats_tstats
, 1, 0, },
170 {'T', stats_tstats
, 1, 0, },
171 {'u', stats_uptime
, 0, 0, },
172 {'U', stats_shared
, 1, 0, },
173 {'v', stats_servers
, 0, 0, },
174 {'V', stats_servers
, 0, 0, },
175 {'x', stats_tgecos
, 1, 0, },
176 {'X', stats_gecos
, 1, 0, },
177 {'y', stats_class
, 0, 0, },
178 {'Y', stats_class
, 0, 0, },
179 {'z', stats_memory
, 1, 0, },
180 {'Z', stats_ziplinks
, 1, 0, },
181 {'?', stats_servlinks
, 0, 0, },
182 {(char) 0, (void (*)()) 0, 0, 0, }
187 * parv[1] = stat letter/command
188 * parv[2] = (if present) server/mask in stats L, or target
190 * This will search the tables for the appropriate stats letter,
191 * if found execute it.
194 m_stats(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
196 static time_t last_used
= 0;
201 statchar
= parv
[1][0];
203 if(MyClient(source_p
) && !IsOper(source_p
))
205 /* Check the user is actually allowed to do /stats, and isnt flooding */
206 if((last_used
+ ConfigFileEntry
.pace_wait
) > rb_current_time())
208 /* safe enough to give this on a local connect only */
209 sendto_one(source_p
, form_str(RPL_LOAD2HI
),
210 me
.name
, source_p
->name
, "STATS");
211 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
212 form_str(RPL_ENDOFSTATS
), statchar
);
216 last_used
= rb_current_time();
219 if(hunt_server (client_p
, source_p
, ":%s STATS %s :%s", 2, parc
, parv
) != HUNTED_ISME
)
222 if((statchar
!= 'L') && (statchar
!= 'l'))
223 did_stats
= stats_spy(source_p
, statchar
, NULL
);
225 /* if did_stats is true, a module grabbed this STATS request */
229 for (i
= 0; stats_cmd_table
[i
].letter
; i
++)
231 if(stats_cmd_table
[i
].letter
== statchar
)
233 /* The stats table says what privs are needed, so check --fl_ */
234 /* Called for remote clients and for local opers, so check need_admin
237 if(stats_cmd_table
[i
].need_oper
&& !IsOper(source_p
))
239 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
240 form_str (ERR_NOPRIVILEGES
));
243 if(stats_cmd_table
[i
].need_admin
&& !IsOperAdmin(source_p
))
245 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
246 me
.name
, source_p
->name
, "admin");
250 /* Blah, stats L needs the parameters, none of the others do.. */
251 if(statchar
== 'L' || statchar
== 'l')
252 stats_ltrace (source_p
, parc
, parv
);
254 stats_cmd_table
[i
].handler (source_p
);
259 /* Send the end of stats notice, and the stats_spy */
260 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
261 form_str(RPL_ENDOFSTATS
), statchar
);
267 stats_dns_servers (struct Client
*source_p
)
269 report_dns_servers (source_p
);
273 stats_delay(struct Client
*source_p
)
276 struct DictionaryIter iter
;
278 DICTIONARY_FOREACH(nd
, &iter
, nd_dict
)
280 sendto_one_notice(source_p
, ":Delaying: %s for %ld",
281 nd
->name
, (long) nd
->expire
);
286 stats_hash_cb(const char *buf
, void *client_p
)
288 sendto_one_numeric(client_p
, RPL_STATSDEBUG
, "B :%s", buf
);
292 stats_hash(struct Client
*source_p
)
294 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "B :%-30s %-15s %-10s %-10s %-10s %-10s",
295 "NAME", "TYPE", "OBJECTS", "DEPTH SUM", "AVG DEPTH", "MAX DEPTH");
297 rb_dictionary_stats_walk(stats_hash_cb
, source_p
);
298 rb_radixtree_stats_walk(stats_hash_cb
, source_p
);
302 stats_connect(struct Client
*source_p
)
305 struct server_conf
*server_p
;
309 if((ConfigFileEntry
.stats_c_oper_only
||
310 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
313 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
314 form_str(ERR_NOPRIVILEGES
));
318 RB_DLINK_FOREACH(ptr
, server_conf_list
.head
)
320 server_p
= ptr
->data
;
322 if(ServerConfIllegal(server_p
))
329 if(ServerConfAutoconn(server_p
))
331 if(ServerConfSSL(server_p
))
333 if(ServerConfTb(server_p
))
335 if(ServerConfCompressed(server_p
))
344 sendto_one_numeric(source_p
, RPL_STATSCLINE
,
345 form_str(RPL_STATSCLINE
),
348 server_p
->port
, server_p
->class_name
);
354 * input - client to report to
356 * side effects - client is given temp dline list.
359 stats_tdeny (struct Client
*source_p
)
361 char *host
, *pass
, *user
, *oper_reason
;
362 struct AddressRec
*arec
;
363 struct ConfItem
*aconf
;
366 for (i
= 0; i
< ATABLE_SIZE
; i
++)
368 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
370 if(arec
->type
== CONF_DLINE
)
374 if(!(aconf
->flags
& CONF_FLAGS_TEMPORARY
))
377 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
379 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
380 form_str (RPL_STATSDLINE
),
382 oper_reason
? "|" : "",
383 oper_reason
? oper_reason
: "");
391 * input - client to report to
393 * side effects - client is given dline list.
396 stats_deny (struct Client
*source_p
)
398 char *host
, *pass
, *user
, *oper_reason
;
399 struct AddressRec
*arec
;
400 struct ConfItem
*aconf
;
403 for (i
= 0; i
< ATABLE_SIZE
; i
++)
405 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
407 if(arec
->type
== CONF_DLINE
)
411 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
414 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
416 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
417 form_str (RPL_STATSDLINE
),
419 oper_reason
? "|" : "",
420 oper_reason
? oper_reason
: "");
429 * input - client to report to
431 * side effects - client is given list of exempt blocks
434 stats_exempt(struct Client
*source_p
)
436 char *name
, *host
, *user
, *classname
;
438 struct AddressRec
*arec
;
439 struct ConfItem
*aconf
;
442 if(ConfigFileEntry
.stats_e_disabled
)
444 sendto_one_numeric(source_p
, ERR_DISABLED
,
445 form_str(ERR_DISABLED
), "STATS e");
449 for (i
= 0; i
< ATABLE_SIZE
; i
++)
451 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
453 if(arec
->type
== CONF_EXEMPTDLINE
)
456 get_printable_conf (aconf
, &name
, &host
, &pass
,
457 &user
, &port
, &classname
);
459 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
460 form_str(RPL_STATSDLINE
),
461 'e', host
, pass
, "", "");
468 stats_events_cb(char *str
, void *ptr
)
470 sendto_one_numeric(ptr
, RPL_STATSDEBUG
, "E :%s", str
);
474 stats_events (struct Client
*source_p
)
476 rb_dump_events(stats_events_cb
, source_p
);
480 stats_prop_klines(struct Client
*source_p
)
482 struct ConfItem
*aconf
;
484 char *user
, *host
, *pass
, *oper_reason
;
486 RB_DLINK_FOREACH(ptr
, prop_bans
.head
)
490 /* Skip non-klines and deactivated klines. */
491 if(aconf
->status
!= CONF_KILL
)
494 get_printable_kline(source_p
, aconf
, &host
, &pass
,
495 &user
, &oper_reason
);
497 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
498 form_str(RPL_STATSKLINE
),
499 'g', host
, user
, pass
,
500 oper_reason
? "|" : "",
501 oper_reason
? oper_reason
: "");
506 stats_hubleaf(struct Client
*source_p
)
508 struct remote_conf
*hub_p
;
511 if((ConfigFileEntry
.stats_h_oper_only
||
512 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
515 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
516 form_str (ERR_NOPRIVILEGES
));
520 RB_DLINK_FOREACH(ptr
, hubleaf_conf_list
.head
)
524 if(hub_p
->flags
& CONF_HUB
)
525 sendto_one_numeric(source_p
, RPL_STATSHLINE
,
526 form_str(RPL_STATSHLINE
),
527 hub_p
->host
, hub_p
->server
);
529 sendto_one_numeric(source_p
, RPL_STATSLLINE
,
530 form_str(RPL_STATSLLINE
),
531 hub_p
->host
, hub_p
->server
);
537 stats_auth (struct Client
*source_p
)
539 /* Oper only, if unopered, return ERR_NOPRIVS */
540 if((ConfigFileEntry
.stats_i_oper_only
== 2) && !IsOper (source_p
))
541 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
542 form_str (ERR_NOPRIVILEGES
));
544 /* If unopered, Only return matching auth blocks */
545 else if((ConfigFileEntry
.stats_i_oper_only
== 1) && !IsOper (source_p
))
547 struct ConfItem
*aconf
;
548 char *name
, *host
, *user
, *classname
;
549 const char *pass
= "*";
552 if(MyConnect (source_p
))
553 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
554 (struct sockaddr
*)&source_p
->localClient
->ip
,
556 source_p
->localClient
->ip
.ss_family
,
557 source_p
->username
, NULL
);
559 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_CLIENT
,
560 0, source_p
->username
, NULL
);
565 get_printable_conf (aconf
, &name
, &host
, &pass
, &user
, &port
, &classname
);
566 if(!EmptyString(aconf
->spasswd
))
567 pass
= aconf
->spasswd
;
569 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
570 name
, pass
, show_iline_prefix(source_p
, aconf
, user
),
571 host
, port
, classname
);
574 /* Theyre opered, or allowed to see all auth blocks */
576 report_auth (source_p
);
581 stats_tklines(struct Client
*source_p
)
583 /* Oper only, if unopered, return ERR_NOPRIVS */
584 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
585 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
586 form_str (ERR_NOPRIVILEGES
));
588 /* If unopered, Only return matching klines */
589 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
591 struct ConfItem
*aconf
;
592 char *host
, *pass
, *user
, *oper_reason
;
594 if(MyConnect (source_p
))
595 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
596 (struct sockaddr
*)&source_p
->localClient
->ip
,
598 source_p
->localClient
->ip
.ss_family
,
599 source_p
->username
, NULL
);
601 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
602 0, source_p
->username
, NULL
);
607 /* dont report a permanent kline as a tkline */
608 if((aconf
->flags
& CONF_FLAGS_TEMPORARY
) == 0)
611 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
613 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
614 form_str(RPL_STATSKLINE
), aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
615 host
, user
, pass
, oper_reason
? "|" : "",
616 oper_reason
? oper_reason
: "");
618 /* Theyre opered, or allowed to see all klines */
621 struct ConfItem
*aconf
;
624 char *user
, *host
, *pass
, *oper_reason
;
626 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
628 RB_DLINK_FOREACH(ptr
, temp_klines
[i
].head
)
632 get_printable_kline(source_p
, aconf
, &host
, &pass
,
633 &user
, &oper_reason
);
635 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
636 form_str(RPL_STATSKLINE
),
637 'k', host
, user
, pass
,
638 oper_reason
? "|" : "",
639 oper_reason
? oper_reason
: "");
647 * inputs - Client to report to, mask
649 * side effects - Reports configured K-lines to client_p.
652 report_Klines(struct Client
*source_p
)
654 char *host
, *pass
, *user
, *oper_reason
;
655 struct AddressRec
*arec
;
656 struct ConfItem
*aconf
= NULL
;
659 for (i
= 0; i
< ATABLE_SIZE
; i
++)
661 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
663 if(arec
->type
== CONF_KILL
)
667 /* its a tempkline, theyre reported elsewhere */
668 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
671 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
672 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
673 form_str(RPL_STATSKLINE
),
674 'K', host
, user
, pass
,
675 oper_reason
? "|" : "",
676 oper_reason
? oper_reason
: "");
683 stats_klines(struct Client
*source_p
)
685 /* Oper only, if unopered, return ERR_NOPRIVS */
686 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
687 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
688 form_str (ERR_NOPRIVILEGES
));
690 /* If unopered, Only return matching klines */
691 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
693 struct ConfItem
*aconf
;
694 char *host
, *pass
, *user
, *oper_reason
;
696 /* search for a kline */
697 if(MyConnect (source_p
))
698 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
699 (struct sockaddr
*)&source_p
->localClient
->ip
,
701 source_p
->localClient
->ip
.ss_family
,
702 source_p
->username
, NULL
);
704 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
705 0, source_p
->username
, NULL
);
710 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
712 sendto_one_numeric(source_p
, RPL_STATSKLINE
, form_str(RPL_STATSKLINE
),
713 aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
714 host
, user
, pass
, oper_reason
? "|" : "",
715 oper_reason
? oper_reason
: "");
717 /* Theyre opered, or allowed to see all klines */
719 report_Klines (source_p
);
723 stats_messages(struct Client
*source_p
)
725 struct DictionaryIter iter
;
727 struct alias_entry
*amsg
;
729 DICTIONARY_FOREACH(msg
, &iter
, cmd_dict
)
731 s_assert(msg
->cmd
!= NULL
);
732 sendto_one_numeric(source_p
, RPL_STATSCOMMANDS
,
733 form_str(RPL_STATSCOMMANDS
),
734 msg
->cmd
, msg
->count
,
735 msg
->bytes
, msg
->rcount
);
738 DICTIONARY_FOREACH(amsg
, &iter
, alias_dict
)
740 s_assert(amsg
->name
!= NULL
);
741 sendto_one_numeric(source_p
, RPL_STATSCOMMANDS
,
742 form_str(RPL_STATSCOMMANDS
),
743 amsg
->name
, amsg
->hits
, 0L, 0);
748 stats_dnsbl(struct Client
*source_p
)
751 struct Blacklist
*blptr
;
753 RB_DLINK_FOREACH(ptr
, blacklist_list
.head
)
757 /* use RPL_STATSDEBUG for now -- jilles */
758 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "n :%d %s %s (%d)",
761 blptr
->status
& CONF_ILLEGAL
? "disabled" : "active",
767 stats_oper(struct Client
*source_p
)
769 struct oper_conf
*oper_p
;
772 if(!IsOper(source_p
) && ConfigFileEntry
.stats_o_oper_only
)
774 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
775 form_str (ERR_NOPRIVILEGES
));
779 RB_DLINK_FOREACH(ptr
, oper_conf_list
.head
)
783 sendto_one_numeric(source_p
, RPL_STATSOLINE
,
784 form_str(RPL_STATSOLINE
),
785 oper_p
->username
, oper_p
->host
, oper_p
->name
,
786 IsOper(source_p
) ? oper_p
->privset
->name
: "0", "-1");
791 stats_capability_walk(const char *line
, void *data
)
793 struct Client
*client_p
= data
;
795 sendto_one_numeric(client_p
, RPL_STATSDEBUG
, "C :%s", line
);
799 stats_capability(struct Client
*client_p
)
801 capability_index_stats(stats_capability_walk
, client_p
);
805 stats_privset(struct Client
*source_p
)
807 privilegeset_report(source_p
);
812 * input - client pointer
814 * side effects - client is shown a list of active opers
817 stats_operedup (struct Client
*source_p
)
819 struct Client
*target_p
;
820 rb_dlink_node
*oper_ptr
;
821 unsigned int count
= 0;
823 RB_DLINK_FOREACH (oper_ptr
, oper_list
.head
)
825 target_p
= oper_ptr
->data
;
827 if(IsOperInvis(target_p
) && !IsOper(source_p
))
830 if(target_p
->user
->away
)
835 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
837 target_p
->name
, target_p
->username
,
841 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
842 "p :%u staff members", count
);
844 stats_p_spy (source_p
);
848 stats_ports (struct Client
*source_p
)
850 if(!IsOper (source_p
) && ConfigFileEntry
.stats_P_oper_only
)
851 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
852 form_str (ERR_NOPRIVILEGES
));
854 show_ports (source_p
);
858 stats_tresv(struct Client
*source_p
)
860 struct ConfItem
*aconf
;
861 struct rb_radixtree_iteration_state state
;
865 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
869 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
870 form_str(RPL_STATSQLINE
),
871 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
874 RB_RADIXTREE_FOREACH(aconf
, &state
, resv_tree
)
877 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
878 form_str(RPL_STATSQLINE
),
879 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
885 stats_resv(struct Client
*source_p
)
887 struct ConfItem
*aconf
;
888 struct rb_radixtree_iteration_state state
;
892 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
896 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
897 form_str(RPL_STATSQLINE
),
898 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
901 RB_RADIXTREE_FOREACH(aconf
, &state
, resv_tree
)
904 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
905 form_str(RPL_STATSQLINE
),
906 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
911 stats_ssld_foreach(void *data
, pid_t pid
, int cli_count
, enum ssld_status status
, const char *version
)
913 struct Client
*source_p
= data
;
915 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
918 status
== SSLD_DEAD
? 'D' : (status
== SSLD_SHUTDOWN
? 'S' : 'A'),
924 stats_ssld(struct Client
*source_p
)
926 ssld_foreach_info(stats_ssld_foreach
, source_p
);
930 stats_usage (struct Client
*source_p
)
945 if(getrusage(RUSAGE_SELF
, &rus
) == -1)
947 sendto_one_notice(source_p
, ":Getruseage error: %s.",
951 secs
= rus
.ru_utime
.tv_sec
+ rus
.ru_stime
.tv_sec
;
955 rup
= (rb_current_time() - startup_time
) * hzz
;
959 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
960 "R :CPU Secs %d:%02d User %d:%02d System %d:%02d",
961 (int) (secs
/ 60), (int) (secs
% 60),
962 (int) (rus
.ru_utime
.tv_sec
/ 60),
963 (int) (rus
.ru_utime
.tv_sec
% 60),
964 (int) (rus
.ru_stime
.tv_sec
/ 60),
965 (int) (rus
.ru_stime
.tv_sec
% 60));
966 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
967 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
968 rus
.ru_maxrss
, (rus
.ru_ixrss
/ rup
),
969 (rus
.ru_idrss
/ rup
), (rus
.ru_isrss
/ rup
));
970 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
971 "R :Swaps %d Reclaims %d Faults %d",
972 (int) rus
.ru_nswap
, (int) rus
.ru_minflt
, (int) rus
.ru_majflt
);
973 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
974 "R :Block in %d out %d",
975 (int) rus
.ru_inblock
, (int) rus
.ru_oublock
);
976 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
977 "R :Msg Rcv %d Send %d",
978 (int) rus
.ru_msgrcv
, (int) rus
.ru_msgsnd
);
979 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
980 "R :Signals %d Context Vol. %d Invol %d",
981 (int) rus
.ru_nsignals
, (int) rus
.ru_nvcsw
,
982 (int) rus
.ru_nivcsw
);
986 stats_tstats (struct Client
*source_p
)
988 struct Client
*target_p
;
989 struct ServerStatistics sp
;
992 memcpy(&sp
, &ServerStats
, sizeof(struct ServerStatistics
));
994 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
996 target_p
= ptr
->data
;
998 sp
.is_sbs
+= target_p
->localClient
->sendB
;
999 sp
.is_sbr
+= target_p
->localClient
->receiveB
;
1000 sp
.is_sti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
1004 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
1006 target_p
= ptr
->data
;
1008 sp
.is_cbs
+= target_p
->localClient
->sendB
;
1009 sp
.is_cbr
+= target_p
->localClient
->receiveB
;
1010 sp
.is_cti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
1014 RB_DLINK_FOREACH(ptr
, unknown_list
.head
)
1019 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1020 "T :accepts %u refused %u", sp
.is_ac
, sp
.is_ref
);
1021 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1022 "T :rejected %u delaying %lu",
1023 sp
.is_rej
, delay_exit_length());
1024 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1025 "T :throttled refused %u throttle list size %lu", sp
.is_thr
, throttle_size());
1026 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1027 "T :nicks being delayed %lu",
1029 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1030 "T :unknown commands %u prefixes %u",
1031 sp
.is_unco
, sp
.is_unpf
);
1032 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1033 "T :nick collisions %u saves %u unknown closes %u",
1034 sp
.is_kill
, sp
.is_save
, sp
.is_ni
);
1035 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1036 "T :wrong direction %u empty %u",
1037 sp
.is_wrdi
, sp
.is_empt
);
1038 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1039 "T :numerics seen %u", sp
.is_num
);
1040 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1041 "T :tgchange blocked msgs %u restricted addrs %lu",
1042 sp
.is_tgch
, rb_dlink_list_length(&tgchange_list
));
1043 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1044 "T :ratelimit blocked commands %u", sp
.is_rl
);
1045 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1046 "T :auth successes %u fails %u",
1047 sp
.is_asuc
, sp
.is_abad
);
1048 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1049 "T :sasl successes %u fails %u",
1050 sp
.is_ssuc
, sp
.is_sbad
);
1051 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "T :Client Server");
1052 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1053 "T :connected %u %u", sp
.is_cl
, sp
.is_sv
);
1054 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1055 "T :bytes sent %lluK %lluK",
1058 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1059 "T :bytes recv %lluK %lluK",
1062 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1063 "T :time connected %llu %llu",
1064 sp
.is_cti
, sp
.is_sti
);
1068 stats_uptime (struct Client
*source_p
)
1072 now
= rb_current_time() - startup_time
;
1073 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
1074 form_str (RPL_STATSUPTIME
),
1075 (int)(now
/ 86400), (int)((now
/ 3600) % 24),
1076 (int)((now
/ 60) % 60), (int)(now
% 60));
1077 sendto_one_numeric(source_p
, RPL_STATSCONN
,
1078 form_str (RPL_STATSCONN
),
1079 MaxConnectionCount
, MaxClientCount
,
1080 Count
.totalrestartcount
);
1088 static struct shared_flags shared_flagtable
[] =
1090 { SHARED_PKLINE
, 'K' },
1091 { SHARED_TKLINE
, 'k' },
1092 { SHARED_UNKLINE
, 'U' },
1093 { SHARED_PXLINE
, 'X' },
1094 { SHARED_TXLINE
, 'x' },
1095 { SHARED_UNXLINE
, 'Y' },
1096 { SHARED_PRESV
, 'Q' },
1097 { SHARED_TRESV
, 'q' },
1098 { SHARED_UNRESV
, 'R' },
1099 { SHARED_LOCOPS
, 'L' },
1100 { SHARED_REHASH
, 'H' },
1101 { SHARED_TDLINE
, 'd' },
1102 { SHARED_PDLINE
, 'D' },
1103 { SHARED_UNDLINE
, 'E' },
1104 { SHARED_GRANT
, 'G' },
1105 { SHARED_DIE
, 'I' },
1111 stats_shared (struct Client
*source_p
)
1113 struct remote_conf
*shared_p
;
1115 char buf
[sizeof(shared_flagtable
)/sizeof(shared_flagtable
[0])];
1119 RB_DLINK_FOREACH(ptr
, shared_conf_list
.head
)
1121 shared_p
= ptr
->data
;
1127 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1129 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1130 *p
++ = shared_flagtable
[i
].letter
;
1135 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1136 form_str(RPL_STATSULINE
),
1137 shared_p
->server
, shared_p
->username
,
1138 shared_p
->host
, buf
);
1141 RB_DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
1143 shared_p
= ptr
->data
;
1149 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1151 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1152 *p
++ = shared_flagtable
[i
].letter
;
1157 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1158 form_str(RPL_STATSULINE
),
1159 shared_p
->server
, "*", "*", buf
);
1165 * input - client pointer
1167 * side effects - client is shown lists of who connected servers
1170 stats_servers (struct Client
*source_p
)
1172 struct Client
*target_p
;
1175 int days
, hours
, minutes
;
1178 if(ConfigServerHide
.flatten_links
&& !IsOper(source_p
) &&
1179 !IsExemptShide(source_p
))
1181 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1182 form_str (ERR_NOPRIVILEGES
));
1186 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1188 target_p
= ptr
->data
;
1191 seconds
= rb_current_time() - target_p
->localClient
->firsttime
;
1193 days
= (int) (seconds
/ 86400);
1195 hours
= (int) (seconds
/ 3600);
1197 minutes
= (int) (seconds
/ 60);
1200 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1201 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1202 "Connected: %d day%s, %d:%02d:%02d",
1204 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
1205 (int) (rb_current_time() - target_p
->localClient
->lasttime
),
1206 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1207 days
, (days
== 1) ? "" : "s", hours
, minutes
,
1211 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1212 "V :%d Server(s)", j
);
1216 stats_tgecos(struct Client
*source_p
)
1218 struct ConfItem
*aconf
;
1221 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1226 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1227 form_str(RPL_STATSXLINE
),
1228 'x', aconf
->port
, aconf
->host
,
1234 stats_gecos(struct Client
*source_p
)
1236 struct ConfItem
*aconf
;
1239 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1244 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1245 form_str(RPL_STATSXLINE
),
1246 'X', aconf
->port
, aconf
->host
,
1252 stats_class(struct Client
*source_p
)
1254 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOper(source_p
))
1255 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1256 form_str (ERR_NOPRIVILEGES
));
1258 report_classes(source_p
);
1262 stats_memory (struct Client
*source_p
)
1264 struct Client
*target_p
;
1265 struct Channel
*chptr
;
1266 rb_dlink_node
*rb_dlink
;
1268 int channel_count
= 0;
1269 int local_client_conf_count
= 0; /* local client conf links */
1270 int users_counted
= 0; /* user structs */
1272 int channel_users
= 0;
1273 int channel_invites
= 0;
1274 int channel_bans
= 0;
1275 int channel_except
= 0;
1276 int channel_invex
= 0;
1277 int channel_quiets
= 0;
1279 int class_count
= 0; /* classes */
1280 int conf_count
= 0; /* conf lines */
1281 int users_invited_count
= 0; /* users invited */
1282 int user_channels
= 0; /* users in channels */
1283 int aways_counted
= 0;
1284 size_t number_servers_cached
; /* number of servers cached by scache */
1286 size_t channel_memory
= 0;
1287 size_t channel_ban_memory
= 0;
1288 size_t channel_except_memory
= 0;
1289 size_t channel_invex_memory
= 0;
1290 size_t channel_quiet_memory
= 0;
1292 size_t away_memory
= 0; /* memory used by aways */
1293 size_t ww
= 0; /* whowas array count */
1294 size_t wwm
= 0; /* whowas array memory used */
1295 size_t conf_memory
= 0; /* memory used by conf lines */
1296 size_t mem_servers_cached
; /* memory used by scache */
1298 size_t linebuf_count
= 0;
1299 size_t linebuf_memory_used
= 0;
1301 size_t total_channel_memory
= 0;
1304 size_t local_client_count
= 0;
1305 size_t local_client_memory_used
= 0;
1307 size_t remote_client_count
= 0;
1308 size_t remote_client_memory_used
= 0;
1310 size_t total_memory
= 0;
1312 whowas_memory_usage(&ww
, &wwm
);
1314 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
1316 target_p
= ptr
->data
;
1317 if(MyConnect(target_p
))
1319 local_client_conf_count
++;
1325 users_invited_count
+= rb_dlink_list_length(&target_p
->user
->invited
);
1326 user_channels
+= rb_dlink_list_length(&target_p
->user
->channel
);
1327 if(target_p
->user
->away
)
1330 away_memory
+= (strlen(target_p
->user
->away
) + 1);
1335 /* Count up all channels, ban lists, except lists, Invex lists */
1336 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
1340 channel_memory
+= (strlen(chptr
->chname
) + sizeof(struct Channel
));
1342 channel_users
+= rb_dlink_list_length(&chptr
->members
);
1343 channel_invites
+= rb_dlink_list_length(&chptr
->invites
);
1345 RB_DLINK_FOREACH(rb_dlink
, chptr
->banlist
.head
)
1349 channel_ban_memory
+= sizeof(rb_dlink_node
) + sizeof(struct Ban
);
1352 RB_DLINK_FOREACH(rb_dlink
, chptr
->exceptlist
.head
)
1356 channel_except_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1359 RB_DLINK_FOREACH(rb_dlink
, chptr
->invexlist
.head
)
1363 channel_invex_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1366 RB_DLINK_FOREACH(rb_dlink
, chptr
->quietlist
.head
)
1370 channel_quiet_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1374 /* count up all classes */
1376 class_count
= rb_dlink_list_length(&class_list
) + 1;
1378 rb_count_rb_linebuf_memory(&linebuf_count
, &linebuf_memory_used
);
1380 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1381 "z :Users %u(%lu) Invites %u(%lu)",
1383 (unsigned long) users_counted
* sizeof(struct User
),
1384 users_invited_count
,
1385 (unsigned long) users_invited_count
* sizeof(rb_dlink_node
));
1387 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1388 "z :User channels %u(%lu) Aways %u(%d)",
1390 (unsigned long) user_channels
* sizeof(rb_dlink_node
),
1391 aways_counted
, (int) away_memory
);
1393 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1394 "z :Attached confs %u(%lu)",
1395 local_client_conf_count
,
1396 (unsigned long) local_client_conf_count
* sizeof(rb_dlink_node
));
1398 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1399 "z :Conflines %u(%d)", conf_count
, (int) conf_memory
);
1401 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1402 "z :Classes %u(%lu)",
1404 (unsigned long) class_count
* sizeof(struct Class
));
1406 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1407 "z :Channels %u(%d)",
1408 channel_count
, (int) channel_memory
);
1410 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1411 "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)",
1412 channel_bans
, (int) channel_ban_memory
,
1413 channel_except
, (int) channel_except_memory
,
1414 channel_invex
, (int) channel_invex_memory
,
1415 channel_quiets
, (int) channel_quiet_memory
);
1417 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1418 "z :Channel members %u(%lu) invite %u(%lu)",
1420 (unsigned long) channel_users
* sizeof(rb_dlink_node
),
1422 (unsigned long) channel_invites
* sizeof(rb_dlink_node
));
1424 total_channel_memory
= channel_memory
+
1425 channel_ban_memory
+
1426 channel_users
* sizeof(rb_dlink_node
) + channel_invites
* sizeof(rb_dlink_node
);
1428 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1429 "z :Whowas array %ld(%ld)",
1430 (long)ww
, (long)wwm
);
1434 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1435 "z :Hash: client %u(%ld) chan %u(%ld)",
1436 U_MAX
, (long)(U_MAX
* sizeof(rb_dlink_list
)),
1437 CH_MAX
, (long)(CH_MAX
* sizeof(rb_dlink_list
)));
1439 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1440 "z :linebuf %ld(%ld)",
1441 (long)linebuf_count
, (long)linebuf_memory_used
);
1443 count_scache(&number_servers_cached
, &mem_servers_cached
);
1445 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1446 "z :scache %ld(%ld)",
1447 (long)number_servers_cached
, (long)mem_servers_cached
);
1449 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1450 "z :hostname hash %d(%ld)",
1451 HOST_MAX
, (long)HOST_MAX
* sizeof(rb_dlink_list
));
1453 total_memory
= totww
+ total_channel_memory
+ conf_memory
+
1454 class_count
* sizeof(struct Class
);
1456 total_memory
+= mem_servers_cached
;
1457 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1458 "z :Total: whowas %d channel %d conf %d",
1459 (int) totww
, (int) total_channel_memory
,
1462 count_local_client_memory(&local_client_count
, &local_client_memory_used
);
1463 total_memory
+= local_client_memory_used
;
1465 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1466 "z :Local client Memory in use: %ld(%ld)",
1467 (long)local_client_count
, (long)local_client_memory_used
);
1470 count_remote_client_memory(&remote_client_count
, &remote_client_memory_used
);
1471 total_memory
+= remote_client_memory_used
;
1473 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1474 "z :Remote client Memory in use: %ld(%ld)",
1475 (long)remote_client_count
,
1476 (long)remote_client_memory_used
);
1480 stats_ziplinks (struct Client
*source_p
)
1483 struct Client
*target_p
;
1484 struct ZipStats
*zipstats
;
1486 char buf
[128], buf1
[128];
1487 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1489 target_p
= ptr
->data
;
1490 if(IsCapable (target_p
, CAP_ZIP
))
1492 zipstats
= target_p
->localClient
->zipstats
;
1493 sprintf(buf
, "%.2f%%", zipstats
->out_ratio
);
1494 sprintf(buf1
, "%.2f%%", zipstats
->in_ratio
);
1495 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1496 "Z :ZipLinks stats for %s send[%s compression "
1497 "(%llu kB data/%llu kB wire)] recv[%s compression "
1498 "(%llu kB data/%llu kB wire)]",
1500 buf
, zipstats
->out
>> 10,
1501 zipstats
->out_wire
>> 10, buf1
,
1502 zipstats
->in
>> 10, zipstats
->in_wire
>> 10);
1507 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1508 "Z :%u ziplink(s)", sent_data
);
1512 stats_servlinks (struct Client
*source_p
)
1514 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1515 long uptime
, sendK
, receiveK
;
1516 struct Client
*target_p
;
1521 if(ConfigServerHide
.flatten_links
&& !IsOper (source_p
) &&
1522 !IsExemptShide(source_p
))
1524 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1525 form_str (ERR_NOPRIVILEGES
));
1529 sendK
= receiveK
= 0;
1531 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1533 target_p
= ptr
->data
;
1536 sendK
+= target_p
->localClient
->sendK
;
1537 receiveK
+= target_p
->localClient
->receiveK
;
1539 sendto_one(source_p
, Sformat
,
1540 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1542 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1543 (int) target_p
->localClient
->sendM
,
1544 (int) target_p
->localClient
->sendK
,
1545 (int) target_p
->localClient
->receiveM
,
1546 (int) target_p
->localClient
->receiveK
,
1547 rb_current_time() - target_p
->localClient
->firsttime
,
1548 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1549 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1550 IsOper (source_p
) ? show_capabilities (target_p
) : "TS");
1553 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1554 "? :%u total server(s)", j
);
1556 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((sendK
)));
1557 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1558 "? :Sent total : %s %s",
1559 buf
, _GMKs (sendK
));
1560 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((receiveK
)));
1561 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1562 "? :Recv total : %s %s",
1563 buf
, _GMKs (receiveK
));
1565 uptime
= (rb_current_time() - startup_time
);
1566 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1567 _GMKv (me
.localClient
->sendK
),
1568 _GMKs (me
.localClient
->sendK
),
1569 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1570 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server send: %s", buf
);
1571 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1572 _GMKv (me
.localClient
->receiveK
),
1573 _GMKs (me
.localClient
->receiveK
),
1574 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1575 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server recv: %s", buf
);
1579 stats_l_should_show_oper(struct Client
*target_p
)
1581 if (IsOperInvis(target_p
))
1588 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1593 char statchar
= parv
[1][0];
1595 /* this is def targeted at us somehow.. */
1596 if(parc
> 2 && !EmptyString(parv
[2]))
1598 /* directed at us generically? */
1599 if(match(parv
[2], me
.name
) ||
1600 (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1608 wilds
= strchr(name
, '*') || strchr(name
, '?');
1611 /* must be directed at a specific person thats not us */
1612 if(!doall
&& !wilds
)
1614 struct Client
*target_p
;
1616 if(MyClient(source_p
))
1617 target_p
= find_named_person(name
);
1619 target_p
= find_person(name
);
1621 if(target_p
!= NULL
)
1623 stats_spy(source_p
, statchar
, target_p
->name
);
1624 stats_l_client(source_p
, target_p
, statchar
);
1627 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1628 form_str(ERR_NOSUCHSERVER
),
1640 stats_spy(source_p
, statchar
, name
);
1644 /* local opers get everyone */
1645 if(MyOper(source_p
))
1647 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
, NULL
);
1648 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1652 /* they still need themselves if theyre local.. */
1653 if(MyClient(source_p
))
1654 stats_l_client(source_p
, source_p
, statchar
);
1656 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
, stats_l_should_show_oper
);
1659 if (!ConfigServerHide
.flatten_links
|| IsOper(source_p
) ||
1660 IsExemptShide(source_p
))
1661 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
, NULL
);
1666 /* ok, at this point theyre looking for a specific client whos on
1667 * our server.. but it contains a wildcard. --fl
1669 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1675 stats_l_list(struct Client
*source_p
, const char *name
, int doall
, int wilds
,
1676 rb_dlink_list
* list
, char statchar
, int (*check_fn
)(struct Client
*target_p
))
1679 struct Client
*target_p
;
1681 /* send information about connections which match. note, we
1682 * dont need tests for IsInvisible(), because non-opers will
1683 * never get here for normal clients --fl
1685 RB_DLINK_FOREACH(ptr
, list
->head
)
1687 target_p
= ptr
->data
;
1689 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1692 if (check_fn
== NULL
|| check_fn(target_p
))
1693 stats_l_client(source_p
, target_p
, statchar
);
1698 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1701 if(IsAnyServer(target_p
))
1703 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1705 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1706 (int) target_p
->localClient
->sendM
,
1707 (int) target_p
->localClient
->sendK
,
1708 (int) target_p
->localClient
->receiveM
,
1709 (int) target_p
->localClient
->receiveK
,
1710 rb_current_time() - target_p
->localClient
->firsttime
,
1711 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1712 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1713 IsOper(source_p
) ? show_capabilities(target_p
) : "-");
1718 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1719 show_ip(source_p
, target_p
) ?
1720 (IsUpper(statchar
) ?
1721 get_client_name(target_p
, SHOW_IP
) :
1722 get_client_name(target_p
, HIDE_IP
)) :
1723 get_client_name(target_p
, MASK_IP
),
1724 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1725 (int) target_p
->localClient
->sendM
,
1726 (int) target_p
->localClient
->sendK
,
1727 (int) target_p
->localClient
->receiveM
,
1728 (int) target_p
->localClient
->receiveK
,
1729 rb_current_time() - target_p
->localClient
->firsttime
,
1730 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1731 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1737 rb_dump_fd_callback(int fd
, const char *desc
, void *data
)
1739 struct Client
*source_p
= data
;
1740 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "F :fd %-3d desc '%s'", fd
, desc
);
1744 stats_comm(struct Client
*source_p
)
1746 rb_dump_fd(rb_dump_fd_callback
, source_p
);
1752 * inputs - pointer to client doing the /stats
1753 * - char letter they are doing /stats on
1756 * This little helper function reports to opers if configured.
1757 * personally, I don't see why opers need to see stats requests
1758 * at all. They are just "noise" to an oper, and users can't do
1759 * any damage with stats requests now anyway. So, why show them?
1763 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1767 data
.client
= source_p
;
1769 data
.arg2
= (int) statchar
;
1772 call_hook(doing_stats_hook
, &data
);
1779 * input - pointer to client doing stats
1781 * side effects - call hook doing_stats_p
1784 stats_p_spy (struct Client
*source_p
)
1788 data
.client
= source_p
;
1789 data
.arg1
= data
.arg2
= NULL
;
1791 call_hook(doing_stats_p_hook
, &data
);