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 */
29 #include "ircd.h" /* me */
30 #include "listener.h" /* show_ports */
31 #include "msg.h" /* Message */
32 #include "hostmask.h" /* report_mtrie_conf_links */
33 #include "numeric.h" /* ERR_xxx */
34 #include "scache.h" /* list_scache */
35 #include "send.h" /* sendto_one */
36 #include "s_conf.h" /* ConfItem */
37 #include "s_serv.h" /* hunt_server */
39 #include "s_user.h" /* show_opers */
43 #include "s_newconf.h"
47 #include "rb_radixtree.h"
51 static const char stats_desc
[] =
52 "Provides the STATS command to inspect various server/network information";
54 static void m_stats (struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
56 struct Message stats_msgtab
= {
57 "STATS", false, false, false, false,
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 *, bool, bool, rb_dlink_list
*, char,
76 bool (*check_fn
)(struct Client
*source_p
, 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 typedef void (*handler_t
)(struct Client
*source_p
);
84 typedef void (*handler_parv_t
)(struct Client
*source_p
, int parc
, const char *parv
[]);
91 handler_parv_t handler_parv
;
93 const char *need_priv
;
98 static void stats_dns_servers(struct Client
*);
99 static void stats_delay(struct Client
*);
100 static void stats_hash(struct Client
*);
101 static void stats_connect(struct Client
*);
102 static void stats_tdeny(struct Client
*);
103 static void stats_deny(struct Client
*);
104 static void stats_exempt(struct Client
*);
105 static void stats_events(struct Client
*);
106 static void stats_prop_klines(struct Client
*);
107 static void stats_hubleaf(struct Client
*);
108 static void stats_auth(struct Client
*);
109 static void stats_tklines(struct Client
*);
110 static void stats_klines(struct Client
*);
111 static void stats_messages(struct Client
*);
112 static void stats_dnsbl(struct Client
*);
113 static void stats_oper(struct Client
*);
114 static void stats_privset(struct Client
*);
115 static void stats_operedup(struct Client
*);
116 static void stats_ports(struct Client
*);
117 static void stats_tresv(struct Client
*);
118 static void stats_resv(struct Client
*);
119 static void stats_ssld(struct Client
*);
120 static void stats_usage(struct Client
*);
121 static void stats_tstats(struct Client
*);
122 static void stats_uptime(struct Client
*);
123 static void stats_servers(struct Client
*);
124 static void stats_tgecos(struct Client
*);
125 static void stats_gecos(struct Client
*);
126 static void stats_class(struct Client
*);
127 static void stats_memory(struct Client
*);
128 static void stats_servlinks(struct Client
*);
129 static void stats_ltrace(struct Client
*, int, const char **);
130 static void stats_ziplinks(struct Client
*);
131 static void stats_comm(struct Client
*);
132 static void stats_capability(struct Client
*);
134 #define HANDLER_NORM(fn, admin, priv) \
135 { { .handler = fn }, .need_parv = false, .need_priv = priv, .need_admin = admin }
136 #define HANDLER_PARV(fn, admin, priv) \
137 { { .handler_parv = fn }, .need_parv = true, .need_priv = priv, .need_admin = admin }
139 /* This table contains the possible stats items, in order:
140 * stats letter, function to call, operonly? adminonly? --fl_
142 * Previously in this table letters were a column. I fixed it to use modern
143 * C initalisers so we don't have to iterate anymore
146 static struct stats_cmd stats_cmd_table
[256] = {
147 /* letter handler admin priv */
148 ['a'] = HANDLER_NORM(stats_dns_servers
, true, NULL
),
149 ['A'] = HANDLER_NORM(stats_dns_servers
, true, NULL
),
150 ['b'] = HANDLER_NORM(stats_delay
, true, NULL
),
151 ['B'] = HANDLER_NORM(stats_hash
, true, NULL
),
152 ['c'] = HANDLER_NORM(stats_connect
, false, NULL
),
153 ['C'] = HANDLER_NORM(stats_capability
, false, "oper:general"),
154 ['d'] = HANDLER_NORM(stats_tdeny
, false, "oper:general"),
155 ['D'] = HANDLER_NORM(stats_deny
, false, "oper:general"),
156 ['e'] = HANDLER_NORM(stats_exempt
, false, "oper:general"),
157 ['E'] = HANDLER_NORM(stats_events
, true, NULL
),
158 ['f'] = HANDLER_NORM(stats_comm
, true, NULL
),
159 ['F'] = HANDLER_NORM(stats_comm
, true, NULL
),
160 ['g'] = HANDLER_NORM(stats_prop_klines
, false, "oper:general"),
161 ['h'] = HANDLER_NORM(stats_hubleaf
, false, NULL
),
162 ['H'] = HANDLER_NORM(stats_hubleaf
, false, NULL
),
163 ['i'] = HANDLER_NORM(stats_auth
, false, NULL
),
164 ['I'] = HANDLER_NORM(stats_auth
, false, NULL
),
165 ['k'] = HANDLER_NORM(stats_tklines
, false, NULL
),
166 ['K'] = HANDLER_NORM(stats_klines
, false, NULL
),
167 ['l'] = HANDLER_PARV(stats_ltrace
, false, NULL
),
168 ['L'] = HANDLER_PARV(stats_ltrace
, false, NULL
),
169 ['m'] = HANDLER_NORM(stats_messages
, false, NULL
),
170 ['M'] = HANDLER_NORM(stats_messages
, false, NULL
),
171 ['n'] = HANDLER_NORM(stats_dnsbl
, false, NULL
),
172 ['o'] = HANDLER_NORM(stats_oper
, false, NULL
),
173 ['O'] = HANDLER_NORM(stats_privset
, false, "oper:privs"),
174 ['p'] = HANDLER_NORM(stats_operedup
, false, NULL
),
175 ['P'] = HANDLER_NORM(stats_ports
, false, NULL
),
176 ['q'] = HANDLER_NORM(stats_tresv
, false, "oper:general"),
177 ['Q'] = HANDLER_NORM(stats_resv
, false, "oper:general"),
178 ['r'] = HANDLER_NORM(stats_usage
, false, "oper:general"),
179 ['R'] = HANDLER_NORM(stats_usage
, false, "oper:general"),
180 ['s'] = HANDLER_NORM(stats_ssld
, true, NULL
),
181 ['S'] = HANDLER_NORM(stats_ssld
, true, NULL
),
182 ['t'] = HANDLER_NORM(stats_tstats
, false, "oper:general"),
183 ['T'] = HANDLER_NORM(stats_tstats
, false, "oper:general"),
184 ['u'] = HANDLER_NORM(stats_uptime
, false, NULL
),
185 ['v'] = HANDLER_NORM(stats_servers
, false, NULL
),
186 ['V'] = HANDLER_NORM(stats_servers
, false, NULL
),
187 ['x'] = HANDLER_NORM(stats_tgecos
, false, "oper:general"),
188 ['X'] = HANDLER_NORM(stats_gecos
, false, "oper:general"),
189 ['y'] = HANDLER_NORM(stats_class
, false, NULL
),
190 ['Y'] = HANDLER_NORM(stats_class
, false, NULL
),
191 ['z'] = HANDLER_NORM(stats_memory
, false, "oper:general"),
192 ['Z'] = HANDLER_NORM(stats_ziplinks
, false, "oper:general"),
193 ['?'] = HANDLER_NORM(stats_servlinks
, false, NULL
),
198 * Modified heavily by Elizafox
199 * parv[1] = stat letter/command
200 * parv[2] = (if present) server/mask in stats L, or target
202 * This will search the tables for the appropriate stats letter,
203 * if found execute it.
206 m_stats(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
208 static time_t last_used
= 0;
209 struct stats_cmd
*cmd
;
210 unsigned char statchar
;
213 statchar
= parv
[1][0];
215 if(MyClient(source_p
) && !IsOperGeneral(source_p
) && parc
> 2)
217 /* Check the user is actually allowed to do /stats, and isnt flooding */
218 if((last_used
+ ConfigFileEntry
.pace_wait
) > rb_current_time())
220 /* safe enough to give this on a local connect only */
221 sendto_one(source_p
, form_str(RPL_LOAD2HI
),
222 me
.name
, source_p
->name
, "STATS");
223 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
224 form_str(RPL_ENDOFSTATS
), statchar
);
228 last_used
= rb_current_time();
231 if(hunt_server(client_p
, source_p
, ":%s STATS %s :%s", 2, parc
, parv
) != HUNTED_ISME
)
234 if(tolower(statchar
) != 'l')
236 did_stats
= stats_spy(source_p
, statchar
, NULL
);
238 /* if did_stats is true, a module grabbed this STATS request */
243 cmd
= &stats_cmd_table
[statchar
];
244 if(cmd
->handler
!= NULL
)
246 /* The stats table says what privs are needed, so check --fl_ */
247 const char *missing_priv
= NULL
;
248 if(cmd
->need_admin
&& !IsOperAdmin(source_p
))
249 missing_priv
= "admin";
250 else if(cmd
->need_priv
&& !HasPrivilege(source_p
, cmd
->need_priv
))
251 missing_priv
= cmd
->need_priv
;
253 if(missing_priv
!= NULL
)
255 if(!IsOper(source_p
))
257 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
258 form_str(ERR_NOPRIVILEGES
));
262 if(!strncmp(missing_priv
, "oper:", 5))
264 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
265 me
.name
, source_p
->name
, missing_priv
);
271 cmd
->handler_parv(source_p
, parc
, parv
);
273 cmd
->handler(source_p
);
277 /* Send the end of stats notice, and the stats_spy */
278 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
279 form_str(RPL_ENDOFSTATS
), statchar
);
283 stats_dns_servers (struct Client
*source_p
)
287 RB_DLINK_FOREACH(n
, nameservers
.head
)
289 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "A :%s", (char *)n
->data
);
294 stats_delay(struct Client
*source_p
)
297 rb_dictionary_iter iter
;
299 RB_DICTIONARY_FOREACH(nd
, &iter
, nd_dict
)
301 sendto_one_notice(source_p
, ":Delaying: %s for %ld",
302 nd
->name
, (long) nd
->expire
);
307 stats_hash_cb(const char *buf
, void *client_p
)
309 sendto_one_numeric(client_p
, RPL_STATSDEBUG
, "B :%s", buf
);
313 stats_hash(struct Client
*source_p
)
315 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "B :%-30s %-15s %-10s %-10s %-10s %-10s",
316 "NAME", "TYPE", "OBJECTS", "DEPTH SUM", "AVG DEPTH", "MAX DEPTH");
318 rb_dictionary_stats_walk(stats_hash_cb
, source_p
);
319 rb_radixtree_stats_walk(stats_hash_cb
, source_p
);
323 stats_connect(struct Client
*source_p
)
325 static char buf
[BUFSIZE
];
326 struct server_conf
*server_p
;
330 if((ConfigFileEntry
.stats_c_oper_only
||
331 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
332 !IsOperGeneral(source_p
))
334 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
335 form_str(ERR_NOPRIVILEGES
));
339 RB_DLINK_FOREACH(ptr
, server_conf_list
.head
)
341 server_p
= ptr
->data
;
343 if(ServerConfIllegal(server_p
))
348 if(IsOperGeneral(source_p
))
350 if(ServerConfAutoconn(server_p
))
352 if(ServerConfSCTP(server_p
))
354 if(ServerConfSSL(server_p
))
356 if(ServerConfTb(server_p
))
358 if(ServerConfCompressed(server_p
))
367 sendto_one_numeric(source_p
, RPL_STATSCLINE
,
368 form_str(RPL_STATSCLINE
),
371 server_p
->port
, server_p
->class_name
,
372 server_p
->certfp
? server_p
->certfp
: "*");
378 * input - client to report to
380 * side effects - client is given temp dline list.
383 stats_tdeny (struct Client
*source_p
)
385 char *host
, *pass
, *user
, *oper_reason
;
386 struct AddressRec
*arec
;
387 struct ConfItem
*aconf
;
390 for (i
= 0; i
< ATABLE_SIZE
; i
++)
392 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
394 if(arec
->type
== CONF_DLINE
)
398 if(!(aconf
->flags
& CONF_FLAGS_TEMPORARY
))
401 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
403 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
404 form_str (RPL_STATSDLINE
),
406 oper_reason
? "|" : "",
407 oper_reason
? oper_reason
: "");
415 * input - client to report to
417 * side effects - client is given dline list.
420 stats_deny (struct Client
*source_p
)
422 char *host
, *pass
, *user
, *oper_reason
;
423 struct AddressRec
*arec
;
424 struct ConfItem
*aconf
;
427 for (i
= 0; i
< ATABLE_SIZE
; i
++)
429 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
431 if(arec
->type
== CONF_DLINE
)
435 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
438 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
440 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
441 form_str (RPL_STATSDLINE
),
443 oper_reason
? "|" : "",
444 oper_reason
? oper_reason
: "");
453 * input - client to report to
455 * side effects - client is given list of exempt blocks
458 stats_exempt(struct Client
*source_p
)
460 char *name
, *host
, *user
, *classname
;
462 struct AddressRec
*arec
;
463 struct ConfItem
*aconf
;
466 if(ConfigFileEntry
.stats_e_disabled
)
468 sendto_one_numeric(source_p
, ERR_DISABLED
,
469 form_str(ERR_DISABLED
), "STATS e");
473 for (i
= 0; i
< ATABLE_SIZE
; i
++)
475 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
477 if(arec
->type
== CONF_EXEMPTDLINE
)
480 get_printable_conf (aconf
, &name
, &host
, &pass
,
481 &user
, &port
, &classname
);
483 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
484 form_str(RPL_STATSDLINE
),
485 'e', host
, pass
, "", "");
492 stats_events_cb(char *str
, void *ptr
)
494 sendto_one_numeric(ptr
, RPL_STATSDEBUG
, "E :%s", str
);
498 stats_events (struct Client
*source_p
)
500 rb_dump_events(stats_events_cb
, source_p
);
504 stats_prop_klines(struct Client
*source_p
)
506 struct ConfItem
*aconf
;
508 char *user
, *host
, *pass
, *oper_reason
;
510 RB_DLINK_FOREACH(ptr
, prop_bans
.head
)
514 /* Skip non-klines and deactivated klines. */
515 if(aconf
->status
!= CONF_KILL
)
518 get_printable_kline(source_p
, aconf
, &host
, &pass
,
519 &user
, &oper_reason
);
521 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
522 form_str(RPL_STATSKLINE
),
523 'g', host
, user
, pass
,
524 oper_reason
? "|" : "",
525 oper_reason
? oper_reason
: "");
530 stats_hubleaf(struct Client
*source_p
)
532 struct remote_conf
*hub_p
;
535 if((ConfigFileEntry
.stats_h_oper_only
||
536 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
537 !IsOperGeneral(source_p
))
539 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
540 form_str (ERR_NOPRIVILEGES
));
544 RB_DLINK_FOREACH(ptr
, hubleaf_conf_list
.head
)
548 if(hub_p
->flags
& CONF_HUB
)
549 sendto_one_numeric(source_p
, RPL_STATSHLINE
,
550 form_str(RPL_STATSHLINE
),
551 hub_p
->host
, hub_p
->server
);
553 sendto_one_numeric(source_p
, RPL_STATSLLINE
,
554 form_str(RPL_STATSLLINE
),
555 hub_p
->host
, hub_p
->server
);
561 stats_auth (struct Client
*source_p
)
563 /* Oper only, if unopered, return ERR_NOPRIVS */
564 if((ConfigFileEntry
.stats_i_oper_only
== 2) && !IsOperGeneral (source_p
))
565 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
566 form_str (ERR_NOPRIVILEGES
));
568 /* If unopered, Only return matching auth blocks */
569 else if((ConfigFileEntry
.stats_i_oper_only
== 1) && !IsOperGeneral (source_p
))
571 struct ConfItem
*aconf
;
572 char *name
, *host
, *user
, *classname
;
573 const char *pass
= "*";
576 if(MyConnect (source_p
))
577 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
578 (struct sockaddr
*)&source_p
->localClient
->ip
,
580 GET_SS_FAMILY(&source_p
->localClient
->ip
),
581 source_p
->username
, NULL
);
583 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_CLIENT
,
584 0, source_p
->username
, NULL
);
589 get_printable_conf (aconf
, &name
, &host
, &pass
, &user
, &port
, &classname
);
590 if(!EmptyString(aconf
->spasswd
))
591 pass
= aconf
->spasswd
;
593 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
594 name
, pass
, show_iline_prefix(source_p
, aconf
, user
),
595 host
, port
, classname
);
598 /* Theyre opered, or allowed to see all auth blocks */
600 report_auth (source_p
);
605 stats_tklines(struct Client
*source_p
)
607 /* Oper only, if unopered, return ERR_NOPRIVS */
608 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOperGeneral (source_p
))
609 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
610 form_str (ERR_NOPRIVILEGES
));
612 /* If unopered, Only return matching klines */
613 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOperGeneral (source_p
))
615 struct ConfItem
*aconf
;
616 char *host
, *pass
, *user
, *oper_reason
;
618 if(MyConnect (source_p
))
619 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
620 (struct sockaddr
*)&source_p
->localClient
->ip
,
622 GET_SS_FAMILY(&source_p
->localClient
->ip
),
623 source_p
->username
, NULL
);
625 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
626 0, source_p
->username
, NULL
);
631 /* dont report a permanent kline as a tkline */
632 if((aconf
->flags
& CONF_FLAGS_TEMPORARY
) == 0)
635 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
637 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
638 form_str(RPL_STATSKLINE
), (aconf
->flags
& CONF_FLAGS_TEMPORARY
) ? 'k' : 'K',
639 host
, user
, pass
, oper_reason
? "|" : "",
640 oper_reason
? oper_reason
: "");
642 /* Theyre opered, or allowed to see all klines */
645 struct ConfItem
*aconf
;
648 char *user
, *host
, *pass
, *oper_reason
;
650 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
652 RB_DLINK_FOREACH(ptr
, temp_klines
[i
].head
)
656 get_printable_kline(source_p
, aconf
, &host
, &pass
,
657 &user
, &oper_reason
);
659 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
660 form_str(RPL_STATSKLINE
),
661 'k', host
, user
, pass
,
662 oper_reason
? "|" : "",
663 oper_reason
? oper_reason
: "");
671 * inputs - Client to report to, mask
673 * side effects - Reports configured K-lines to client_p.
676 report_Klines(struct Client
*source_p
)
678 char *host
, *pass
, *user
, *oper_reason
;
679 struct AddressRec
*arec
;
680 struct ConfItem
*aconf
= NULL
;
683 for (i
= 0; i
< ATABLE_SIZE
; i
++)
685 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
687 if(arec
->type
== CONF_KILL
)
691 /* its a tempkline, theyre reported elsewhere */
692 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
695 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
696 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
697 form_str(RPL_STATSKLINE
),
698 'K', host
, user
, pass
,
699 oper_reason
? "|" : "",
700 oper_reason
? oper_reason
: "");
707 stats_klines(struct Client
*source_p
)
709 /* Oper only, if unopered, return ERR_NOPRIVS */
710 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOperGeneral (source_p
))
711 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
712 form_str (ERR_NOPRIVILEGES
));
714 /* If unopered, Only return matching klines */
715 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOperGeneral (source_p
))
717 struct ConfItem
*aconf
;
718 char *host
, *pass
, *user
, *oper_reason
;
720 /* search for a kline */
721 if(MyConnect (source_p
))
722 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
723 (struct sockaddr
*)&source_p
->localClient
->ip
,
725 GET_SS_FAMILY(&source_p
->localClient
->ip
),
726 source_p
->username
, NULL
);
728 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
729 0, source_p
->username
, NULL
);
734 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
736 sendto_one_numeric(source_p
, RPL_STATSKLINE
, form_str(RPL_STATSKLINE
),
737 (aconf
->flags
& CONF_FLAGS_TEMPORARY
) ? 'k' : 'K',
738 host
, user
, pass
, oper_reason
? "|" : "",
739 oper_reason
? oper_reason
: "");
741 /* Theyre opered, or allowed to see all klines */
743 report_Klines (source_p
);
747 stats_messages(struct Client
*source_p
)
749 rb_dictionary_iter iter
;
752 RB_DICTIONARY_FOREACH(msg
, &iter
, cmd_dict
)
754 s_assert(msg
->cmd
!= NULL
);
755 sendto_one_numeric(source_p
, RPL_STATSCOMMANDS
,
756 form_str(RPL_STATSCOMMANDS
),
757 msg
->cmd
, msg
->count
,
758 msg
->bytes
, msg
->rcount
);
763 stats_dnsbl(struct Client
*source_p
)
765 rb_dictionary_iter iter
;
766 struct DNSBLEntryStats
*stats
;
768 if(dnsbl_stats
== NULL
)
771 RB_DICTIONARY_FOREACH(stats
, &iter
, dnsbl_stats
)
773 /* use RPL_STATSDEBUG for now -- jilles */
774 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "n :%d %s",
775 stats
->hits
, (const char *)iter
.cur
->key
);
780 stats_oper(struct Client
*source_p
)
782 struct oper_conf
*oper_p
;
785 if(!IsOperGeneral(source_p
) && ConfigFileEntry
.stats_o_oper_only
)
787 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
788 form_str (ERR_NOPRIVILEGES
));
792 RB_DLINK_FOREACH(ptr
, oper_conf_list
.head
)
796 sendto_one_numeric(source_p
, RPL_STATSOLINE
,
797 form_str(RPL_STATSOLINE
),
798 oper_p
->username
, oper_p
->host
, oper_p
->name
,
799 HasPrivilege(source_p
, "oper:privs") ? oper_p
->privset
->name
: "0", "-1");
804 stats_capability_walk(const char *line
, void *data
)
806 struct Client
*client_p
= data
;
808 sendto_one_numeric(client_p
, RPL_STATSDEBUG
, "C :%s", line
);
812 stats_capability(struct Client
*client_p
)
814 capability_index_stats(stats_capability_walk
, client_p
);
818 stats_privset(struct Client
*source_p
)
820 privilegeset_report(source_p
);
825 * input - client pointer
827 * side effects - client is shown a list of active opers
830 stats_operedup (struct Client
*source_p
)
832 struct Client
*target_p
;
833 rb_dlink_node
*oper_ptr
;
834 unsigned int count
= 0;
836 RB_DLINK_FOREACH (oper_ptr
, oper_list
.head
)
838 target_p
= oper_ptr
->data
;
840 if(!SeesOper(target_p
, source_p
))
843 if(target_p
->user
->away
)
848 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
850 target_p
->name
, target_p
->username
,
854 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
855 "p :%u staff members", count
);
857 stats_p_spy (source_p
);
861 stats_ports (struct Client
*source_p
)
863 if(!IsOperGeneral (source_p
) && ConfigFileEntry
.stats_P_oper_only
)
864 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
865 form_str (ERR_NOPRIVILEGES
));
867 show_ports (source_p
);
871 stats_tresv(struct Client
*source_p
)
873 struct ConfItem
*aconf
;
874 rb_radixtree_iteration_state state
;
877 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
881 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
882 form_str(RPL_STATSQLINE
),
883 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
886 RB_RADIXTREE_FOREACH(aconf
, &state
, resv_tree
)
889 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
890 form_str(RPL_STATSQLINE
),
891 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
897 stats_resv(struct Client
*source_p
)
899 struct ConfItem
*aconf
;
900 rb_radixtree_iteration_state state
;
903 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
907 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
908 form_str(RPL_STATSQLINE
),
909 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
912 RB_RADIXTREE_FOREACH(aconf
, &state
, resv_tree
)
915 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
916 form_str(RPL_STATSQLINE
),
917 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
922 stats_ssld_foreach(void *data
, pid_t pid
, int cli_count
, enum ssld_status status
, const char *version
)
924 struct Client
*source_p
= data
;
926 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
929 status
== SSLD_DEAD
? 'D' : (status
== SSLD_SHUTDOWN
? 'S' : 'A'),
935 stats_ssld(struct Client
*source_p
)
937 ssld_foreach_info(stats_ssld_foreach
, source_p
);
941 stats_usage (struct Client
*source_p
)
957 if(getrusage(RUSAGE_SELF
, &rus
) == -1)
959 sendto_one_notice(source_p
, ":Getruseage error: %s.",
963 secs
= rus
.ru_utime
.tv_sec
+ rus
.ru_stime
.tv_sec
;
967 rup
= (rb_current_time() - startup_time
) * hzz
;
971 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
972 "R :CPU Secs %d:%02d User %d:%02d System %d:%02d",
973 (int) (secs
/ 60), (int) (secs
% 60),
974 (int) (rus
.ru_utime
.tv_sec
/ 60),
975 (int) (rus
.ru_utime
.tv_sec
% 60),
976 (int) (rus
.ru_stime
.tv_sec
/ 60),
977 (int) (rus
.ru_stime
.tv_sec
% 60));
978 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
979 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
980 rus
.ru_maxrss
, (rus
.ru_ixrss
/ rup
),
981 (rus
.ru_idrss
/ rup
), (rus
.ru_isrss
/ rup
));
982 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
983 "R :Swaps %d Reclaims %d Faults %d",
984 (int) rus
.ru_nswap
, (int) rus
.ru_minflt
, (int) rus
.ru_majflt
);
985 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
986 "R :Block in %d out %d",
987 (int) rus
.ru_inblock
, (int) rus
.ru_oublock
);
988 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
989 "R :Msg Rcv %d Send %d",
990 (int) rus
.ru_msgrcv
, (int) rus
.ru_msgsnd
);
991 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
992 "R :Signals %d Context Vol. %d Invol %d",
993 (int) rus
.ru_nsignals
, (int) rus
.ru_nvcsw
,
994 (int) rus
.ru_nivcsw
);
999 stats_tstats (struct Client
*source_p
)
1001 struct Client
*target_p
;
1002 struct ServerStatistics sp
;
1005 memcpy(&sp
, &ServerStats
, sizeof(struct ServerStatistics
));
1007 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1009 target_p
= ptr
->data
;
1011 sp
.is_sbs
+= target_p
->localClient
->sendB
;
1012 sp
.is_sbr
+= target_p
->localClient
->receiveB
;
1013 sp
.is_sti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
1017 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
1019 target_p
= ptr
->data
;
1021 sp
.is_cbs
+= target_p
->localClient
->sendB
;
1022 sp
.is_cbr
+= target_p
->localClient
->receiveB
;
1023 sp
.is_cti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
1027 RB_DLINK_FOREACH(ptr
, unknown_list
.head
)
1032 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1033 "T :accepts %u refused %u", sp
.is_ac
, sp
.is_ref
);
1034 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1035 "T :rejected %u delaying %lu",
1036 sp
.is_rej
, delay_exit_length());
1037 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1038 "T :throttled refused %u throttle list size %lu", sp
.is_thr
, throttle_size());
1039 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1040 "T :nicks being delayed %lu",
1042 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1043 "T :unknown commands %u prefixes %u",
1044 sp
.is_unco
, sp
.is_unpf
);
1045 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1046 "T :nick collisions %u saves %u unknown closes %u",
1047 sp
.is_kill
, sp
.is_save
, sp
.is_ni
);
1048 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1049 "T :wrong direction %u empty %u",
1050 sp
.is_wrdi
, sp
.is_empt
);
1051 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1052 "T :numerics seen %u", sp
.is_num
);
1053 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1054 "T :tgchange blocked msgs %u restricted addrs %lu",
1055 sp
.is_tgch
, rb_dlink_list_length(&tgchange_list
));
1056 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1057 "T :ratelimit blocked commands %u", sp
.is_rl
);
1058 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1059 "T :auth successes %u fails %u",
1060 sp
.is_asuc
, sp
.is_abad
);
1061 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1062 "T :sasl successes %u fails %u",
1063 sp
.is_ssuc
, sp
.is_sbad
);
1064 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "T :Client Server");
1065 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1066 "T :connected %u %u", sp
.is_cl
, sp
.is_sv
);
1067 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1068 "T :bytes sent %lluK %lluK",
1071 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1072 "T :bytes recv %lluK %lluK",
1075 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1076 "T :time connected %llu %llu",
1077 sp
.is_cti
, sp
.is_sti
);
1081 stats_uptime (struct Client
*source_p
)
1085 now
= rb_current_time() - startup_time
;
1086 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
1087 form_str (RPL_STATSUPTIME
),
1088 (int)(now
/ 86400), (int)((now
/ 3600) % 24),
1089 (int)((now
/ 60) % 60), (int)(now
% 60));
1090 sendto_one_numeric(source_p
, RPL_STATSCONN
,
1091 form_str (RPL_STATSCONN
),
1092 MaxConnectionCount
, MaxClientCount
,
1093 Count
.totalrestartcount
);
1099 * input - client pointer
1101 * side effects - client is shown lists of who connected servers
1104 stats_servers (struct Client
*source_p
)
1106 struct Client
*target_p
;
1109 int days
, hours
, minutes
;
1112 if(ConfigServerHide
.flatten_links
&& !IsOperGeneral(source_p
) &&
1113 !IsExemptShide(source_p
))
1115 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1116 form_str (ERR_NOPRIVILEGES
));
1120 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1122 target_p
= ptr
->data
;
1125 seconds
= rb_current_time() - target_p
->localClient
->firsttime
;
1127 days
= (int) (seconds
/ 86400);
1129 hours
= (int) (seconds
/ 3600);
1131 minutes
= (int) (seconds
/ 60);
1134 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1135 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1136 "Connected: %d day%s, %d:%02d:%02d",
1138 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
1139 (int) (rb_current_time() - target_p
->localClient
->lasttime
),
1140 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1141 days
, (days
== 1) ? "" : "s", hours
, minutes
,
1145 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1146 "V :%d Server(s)", j
);
1150 stats_tgecos(struct Client
*source_p
)
1152 struct ConfItem
*aconf
;
1155 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1160 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1161 form_str(RPL_STATSXLINE
),
1162 'x', aconf
->port
, aconf
->host
,
1168 stats_gecos(struct Client
*source_p
)
1170 struct ConfItem
*aconf
;
1173 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1178 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1179 form_str(RPL_STATSXLINE
),
1180 'X', aconf
->port
, aconf
->host
,
1186 stats_class(struct Client
*source_p
)
1188 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOperGeneral(source_p
))
1189 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1190 form_str (ERR_NOPRIVILEGES
));
1192 report_classes(source_p
);
1196 stats_memory (struct Client
*source_p
)
1198 struct Client
*target_p
;
1199 struct Channel
*chptr
;
1200 rb_dlink_node
*rb_dlink
;
1202 int channel_count
= 0;
1203 int local_client_conf_count
= 0; /* local client conf links */
1204 int users_counted
= 0; /* user structs */
1206 int channel_users
= 0;
1207 int channel_invites
= 0;
1208 int channel_bans
= 0;
1209 int channel_except
= 0;
1210 int channel_invex
= 0;
1211 int channel_quiets
= 0;
1213 int class_count
= 0; /* classes */
1214 int conf_count
= 0; /* conf lines */
1215 int users_invited_count
= 0; /* users invited */
1216 int user_channels
= 0; /* users in channels */
1217 int aways_counted
= 0;
1218 size_t number_servers_cached
; /* number of servers cached by scache */
1220 size_t channel_memory
= 0;
1221 size_t channel_ban_memory
= 0;
1222 size_t channel_except_memory
= 0;
1223 size_t channel_invex_memory
= 0;
1224 size_t channel_quiet_memory
= 0;
1226 size_t away_memory
= 0; /* memory used by aways */
1227 size_t ww
= 0; /* whowas array count */
1228 size_t wwm
= 0; /* whowas array memory used */
1229 size_t conf_memory
= 0; /* memory used by conf lines */
1230 size_t mem_servers_cached
; /* memory used by scache */
1232 size_t linebuf_count
= 0;
1233 size_t linebuf_memory_used
= 0;
1235 size_t total_channel_memory
= 0;
1238 size_t local_client_count
= 0;
1239 size_t local_client_memory_used
= 0;
1241 size_t remote_client_count
= 0;
1242 size_t remote_client_memory_used
= 0;
1244 size_t total_memory
= 0;
1246 whowas_memory_usage(&ww
, &wwm
);
1248 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
1250 target_p
= ptr
->data
;
1251 if(MyConnect(target_p
))
1253 local_client_conf_count
++;
1259 users_invited_count
+= rb_dlink_list_length(&target_p
->user
->invited
);
1260 user_channels
+= rb_dlink_list_length(&target_p
->user
->channel
);
1261 if(target_p
->user
->away
)
1264 away_memory
+= (strlen(target_p
->user
->away
) + 1);
1269 /* Count up all channels, ban lists, except lists, Invex lists */
1270 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
1274 channel_memory
+= (strlen(chptr
->chname
) + sizeof(struct Channel
));
1276 channel_users
+= rb_dlink_list_length(&chptr
->members
);
1277 channel_invites
+= rb_dlink_list_length(&chptr
->invites
);
1279 RB_DLINK_FOREACH(rb_dlink
, chptr
->banlist
.head
)
1283 channel_ban_memory
+= sizeof(rb_dlink_node
) + sizeof(struct Ban
);
1286 RB_DLINK_FOREACH(rb_dlink
, chptr
->exceptlist
.head
)
1290 channel_except_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1293 RB_DLINK_FOREACH(rb_dlink
, chptr
->invexlist
.head
)
1297 channel_invex_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1300 RB_DLINK_FOREACH(rb_dlink
, chptr
->quietlist
.head
)
1304 channel_quiet_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1308 /* count up all classes */
1310 class_count
= rb_dlink_list_length(&class_list
) + 1;
1312 rb_count_rb_linebuf_memory(&linebuf_count
, &linebuf_memory_used
);
1314 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1315 "z :Users %u(%lu) Invites %u(%lu)",
1317 (unsigned long) users_counted
* sizeof(struct User
),
1318 users_invited_count
,
1319 (unsigned long) users_invited_count
* sizeof(rb_dlink_node
));
1321 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1322 "z :User channels %u(%lu) Aways %u(%d)",
1324 (unsigned long) user_channels
* sizeof(rb_dlink_node
),
1325 aways_counted
, (int) away_memory
);
1327 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1328 "z :Attached confs %u(%lu)",
1329 local_client_conf_count
,
1330 (unsigned long) local_client_conf_count
* sizeof(rb_dlink_node
));
1332 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1333 "z :Conflines %u(%d)", conf_count
, (int) conf_memory
);
1335 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1336 "z :Classes %u(%lu)",
1338 (unsigned long) class_count
* sizeof(struct Class
));
1340 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1341 "z :Channels %u(%d)",
1342 channel_count
, (int) channel_memory
);
1344 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1345 "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)",
1346 channel_bans
, (int) channel_ban_memory
,
1347 channel_except
, (int) channel_except_memory
,
1348 channel_invex
, (int) channel_invex_memory
,
1349 channel_quiets
, (int) channel_quiet_memory
);
1351 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1352 "z :Channel members %u(%lu) invite %u(%lu)",
1354 (unsigned long) channel_users
* sizeof(rb_dlink_node
),
1356 (unsigned long) channel_invites
* sizeof(rb_dlink_node
));
1358 total_channel_memory
= channel_memory
+
1359 channel_ban_memory
+
1360 channel_users
* sizeof(rb_dlink_node
) + channel_invites
* sizeof(rb_dlink_node
);
1362 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1363 "z :Whowas array %ld(%ld)",
1364 (long)ww
, (long)wwm
);
1368 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1369 "z :Hash: client %u(%ld) chan %u(%ld)",
1370 U_MAX
, (long)(U_MAX
* sizeof(rb_dlink_list
)),
1371 CH_MAX
, (long)(CH_MAX
* sizeof(rb_dlink_list
)));
1373 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1374 "z :linebuf %ld(%ld)",
1375 (long)linebuf_count
, (long)linebuf_memory_used
);
1377 count_scache(&number_servers_cached
, &mem_servers_cached
);
1379 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1380 "z :scache %ld(%ld)",
1381 (long)number_servers_cached
, (long)mem_servers_cached
);
1383 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1384 "z :hostname hash %d(%ld)",
1385 HOST_MAX
, (long)HOST_MAX
* sizeof(rb_dlink_list
));
1387 total_memory
= totww
+ total_channel_memory
+ conf_memory
+
1388 class_count
* sizeof(struct Class
);
1390 total_memory
+= mem_servers_cached
;
1391 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1392 "z :Total: whowas %d channel %d conf %d",
1393 (int) totww
, (int) total_channel_memory
,
1396 count_local_client_memory(&local_client_count
, &local_client_memory_used
);
1397 total_memory
+= local_client_memory_used
;
1399 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1400 "z :Local client Memory in use: %ld(%ld)",
1401 (long)local_client_count
, (long)local_client_memory_used
);
1404 count_remote_client_memory(&remote_client_count
, &remote_client_memory_used
);
1405 total_memory
+= remote_client_memory_used
;
1407 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1408 "z :Remote client Memory in use: %ld(%ld)",
1409 (long)remote_client_count
,
1410 (long)remote_client_memory_used
);
1414 stats_ziplinks (struct Client
*source_p
)
1417 struct Client
*target_p
;
1418 struct ZipStats
*zipstats
;
1420 char buf
[128], buf1
[128];
1421 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1423 target_p
= ptr
->data
;
1424 if(IsCapable (target_p
, CAP_ZIP
))
1426 zipstats
= target_p
->localClient
->zipstats
;
1427 sprintf(buf
, "%.2f%%", zipstats
->out_ratio
);
1428 sprintf(buf1
, "%.2f%%", zipstats
->in_ratio
);
1429 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1430 "Z :ZipLinks stats for %s send[%s compression "
1431 "(%llu kB data/%llu kB wire)] recv[%s compression "
1432 "(%llu kB data/%llu kB wire)]",
1434 buf
, zipstats
->out
>> 10,
1435 zipstats
->out_wire
>> 10, buf1
,
1436 zipstats
->in
>> 10, zipstats
->in_wire
>> 10);
1441 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1442 "Z :%u ziplink(s)", sent_data
);
1446 stats_servlinks (struct Client
*source_p
)
1448 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1449 long uptime
, sendK
, receiveK
;
1450 struct Client
*target_p
;
1455 if(ConfigServerHide
.flatten_links
&& !IsOperGeneral (source_p
) &&
1456 !IsExemptShide(source_p
))
1458 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1459 form_str (ERR_NOPRIVILEGES
));
1463 sendK
= receiveK
= 0;
1465 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1467 target_p
= ptr
->data
;
1470 sendK
+= target_p
->localClient
->sendK
;
1471 receiveK
+= target_p
->localClient
->receiveK
;
1473 sendto_one(source_p
, Sformat
,
1474 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1476 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1477 (int) target_p
->localClient
->sendM
,
1478 (int) target_p
->localClient
->sendK
,
1479 (int) target_p
->localClient
->receiveM
,
1480 (int) target_p
->localClient
->receiveK
,
1481 rb_current_time() - target_p
->localClient
->firsttime
,
1482 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1483 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1484 IsOperGeneral (source_p
) ? show_capabilities (target_p
) : "TS");
1487 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1488 "? :%u total server(s)", j
);
1490 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((sendK
)));
1491 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1492 "? :Sent total : %s %s",
1493 buf
, _GMKs (sendK
));
1494 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((receiveK
)));
1495 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1496 "? :Recv total : %s %s",
1497 buf
, _GMKs (receiveK
));
1499 uptime
= (rb_current_time() - startup_time
);
1500 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1501 _GMKv (me
.localClient
->sendK
),
1502 _GMKs (me
.localClient
->sendK
),
1503 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1504 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server send: %s", buf
);
1505 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1506 _GMKv (me
.localClient
->receiveK
),
1507 _GMKs (me
.localClient
->receiveK
),
1508 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1509 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server recv: %s", buf
);
1513 stats_l_should_show_oper(struct Client
*source_p
, struct Client
*target_p
)
1515 return SeesOper(target_p
, source_p
);
1519 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1524 char statchar
= parv
[1][0];
1526 /* this is def targeted at us somehow.. */
1527 if(parc
> 2 && !EmptyString(parv
[2]))
1529 /* directed at us generically? */
1530 if(match(parv
[2], me
.name
) ||
1531 (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1539 wilds
= strchr(name
, '*') || strchr(name
, '?');
1542 /* must be directed at a specific person thats not us */
1543 if(!doall
&& !wilds
)
1545 struct Client
*target_p
;
1547 if(MyClient(source_p
))
1548 target_p
= find_named_person(name
);
1550 target_p
= find_person(name
);
1552 if(target_p
!= NULL
)
1554 stats_spy(source_p
, statchar
, target_p
->name
);
1555 stats_l_client(source_p
, target_p
, statchar
);
1558 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1559 form_str(ERR_NOSUCHSERVER
),
1571 stats_spy(source_p
, statchar
, name
);
1575 /* local opers get everyone */
1576 if(MyOper(source_p
))
1578 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
, NULL
);
1579 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1583 /* they still need themselves if theyre local.. */
1584 if(MyClient(source_p
))
1585 stats_l_client(source_p
, source_p
, statchar
);
1587 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
, stats_l_should_show_oper
);
1590 if (!ConfigServerHide
.flatten_links
|| IsOperGeneral(source_p
) ||
1591 IsExemptShide(source_p
))
1592 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
, NULL
);
1597 /* ok, at this point theyre looking for a specific client whos on
1598 * our server.. but it contains a wildcard. --fl
1600 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1606 stats_l_list(struct Client
*source_p
, const char *name
, bool doall
, bool wilds
,
1607 rb_dlink_list
* list
, char statchar
, bool (*check_fn
)(struct Client
*source_p
, struct Client
*target_p
))
1610 struct Client
*target_p
;
1612 /* send information about connections which match. note, we
1613 * dont need tests for IsInvisible(), because non-opers will
1614 * never get here for normal clients --fl
1616 RB_DLINK_FOREACH(ptr
, list
->head
)
1618 target_p
= ptr
->data
;
1620 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1623 if (check_fn
== NULL
|| check_fn(source_p
, target_p
))
1624 stats_l_client(source_p
, target_p
, statchar
);
1629 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1632 if(IsAnyServer(target_p
))
1634 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1636 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1637 (int) target_p
->localClient
->sendM
,
1638 (int) target_p
->localClient
->sendK
,
1639 (int) target_p
->localClient
->receiveM
,
1640 (int) target_p
->localClient
->receiveK
,
1641 rb_current_time() - target_p
->localClient
->firsttime
,
1642 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1643 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1644 IsOperGeneral(source_p
) ? show_capabilities(target_p
) : "-");
1649 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1650 show_ip(source_p
, target_p
) ?
1651 (IsUpper(statchar
) ?
1652 get_client_name(target_p
, SHOW_IP
) :
1653 get_client_name(target_p
, HIDE_IP
)) :
1654 get_client_name(target_p
, MASK_IP
),
1655 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1656 (int) target_p
->localClient
->sendM
,
1657 (int) target_p
->localClient
->sendK
,
1658 (int) target_p
->localClient
->receiveM
,
1659 (int) target_p
->localClient
->receiveK
,
1660 rb_current_time() - target_p
->localClient
->firsttime
,
1661 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1662 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1668 rb_dump_fd_callback(int fd
, const char *desc
, void *data
)
1670 struct Client
*source_p
= data
;
1671 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "F :fd %-3d desc '%s'", fd
, desc
);
1675 stats_comm(struct Client
*source_p
)
1677 rb_dump_fd(rb_dump_fd_callback
, source_p
);
1683 * inputs - pointer to client doing the /stats
1684 * - char letter they are doing /stats on
1687 * This little helper function reports to opers if configured.
1690 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1694 data
.client
= source_p
;
1696 data
.arg2
= (int) statchar
;
1699 call_hook(doing_stats_hook
, &data
);
1706 * input - pointer to client doing stats
1708 * side effects - call hook doing_stats_p
1711 stats_p_spy (struct Client
*source_p
)
1715 data
.client
= source_p
;
1716 data
.arg1
= data
.arg2
= NULL
;
1718 call_hook(doing_stats_p_hook
, &data
);