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
;
63 int doing_stats_show_idle_hook
;
65 mapi_clist_av1 stats_clist
[] = { &stats_msgtab
, NULL
};
66 mapi_hlist_av1 stats_hlist
[] = {
67 { "doing_stats", &doing_stats_hook
},
68 { "doing_stats_p", &doing_stats_p_hook
},
69 { "doing_stats_show_idle", &doing_stats_show_idle_hook
},
73 DECLARE_MODULE_AV2(stats
, NULL
, NULL
, stats_clist
, stats_hlist
, NULL
, NULL
, NULL
, stats_desc
);
75 const char *Lformat
= "%s %u %u %u %u %u :%u %u %s";
77 static void stats_l_list(struct Client
*s
, const char *, bool, bool, rb_dlink_list
*, char,
78 bool (*check_fn
)(struct Client
*source_p
, struct Client
*target_p
));
79 static void stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
82 static int stats_spy(struct Client
*, char, const char *);
83 static void stats_p_spy(struct Client
*);
85 typedef void (*handler_t
)(struct Client
*source_p
);
86 typedef void (*handler_parv_t
)(struct Client
*source_p
, int parc
, const char *parv
[]);
93 handler_parv_t handler_parv
;
95 const char *need_priv
;
100 static void stats_dns_servers(struct Client
*);
101 static void stats_delay(struct Client
*);
102 static void stats_hash(struct Client
*);
103 static void stats_connect(struct Client
*);
104 static void stats_tdeny(struct Client
*);
105 static void stats_deny(struct Client
*);
106 static void stats_exempt(struct Client
*);
107 static void stats_events(struct Client
*);
108 static void stats_prop_klines(struct Client
*);
109 static void stats_auth(struct Client
*);
110 static void stats_tklines(struct Client
*);
111 static void stats_klines(struct Client
*);
112 static void stats_messages(struct Client
*);
113 static void stats_dnsbl(struct Client
*);
114 static void stats_oper(struct Client
*);
115 static void stats_privset(struct Client
*);
116 static void stats_operedup(struct Client
*);
117 static void stats_ports(struct Client
*);
118 static void stats_tresv(struct Client
*);
119 static void stats_resv(struct Client
*);
120 static void stats_secure(struct Client
*);
121 static void stats_ssld(struct Client
*);
122 static void stats_usage(struct Client
*);
123 static void stats_tstats(struct Client
*);
124 static void stats_uptime(struct Client
*);
125 static void stats_servers(struct Client
*);
126 static void stats_tgecos(struct Client
*);
127 static void stats_gecos(struct Client
*);
128 static void stats_class(struct Client
*);
129 static void stats_memory(struct Client
*);
130 static void stats_servlinks(struct Client
*);
131 static void stats_ltrace(struct Client
*, int, const char **);
132 static void stats_comm(struct Client
*);
133 static void stats_capability(struct Client
*);
135 #define HANDLER_NORM(fn, admin, priv) \
136 { { .handler = fn }, .need_parv = false, .need_priv = priv, .need_admin = admin }
137 #define HANDLER_PARV(fn, admin, priv) \
138 { { .handler_parv = fn }, .need_parv = true, .need_priv = priv, .need_admin = admin }
140 /* This table contains the possible stats items, in order:
141 * stats letter, function to call, operonly? adminonly? --fl_
143 * Previously in this table letters were a column. I fixed it to use modern
144 * C initalisers so we don't have to iterate anymore
147 static struct stats_cmd stats_cmd_table
[256] = {
148 /* letter handler admin priv */
149 ['a'] = HANDLER_NORM(stats_dns_servers
, true, NULL
),
150 ['A'] = HANDLER_NORM(stats_dns_servers
, true, NULL
),
151 ['b'] = HANDLER_NORM(stats_delay
, true, NULL
),
152 ['B'] = HANDLER_NORM(stats_hash
, true, NULL
),
153 ['c'] = HANDLER_NORM(stats_connect
, false, NULL
),
154 ['C'] = HANDLER_NORM(stats_capability
, false, "oper:general"),
155 ['d'] = HANDLER_NORM(stats_tdeny
, false, "oper:general"),
156 ['D'] = HANDLER_NORM(stats_deny
, false, "oper:general"),
157 ['e'] = HANDLER_NORM(stats_exempt
, false, "oper:general"),
158 ['E'] = HANDLER_NORM(stats_events
, true, NULL
),
159 ['f'] = HANDLER_NORM(stats_comm
, true, NULL
),
160 ['F'] = HANDLER_NORM(stats_comm
, true, NULL
),
161 ['g'] = HANDLER_NORM(stats_prop_klines
, false, "oper:general"),
162 ['i'] = HANDLER_NORM(stats_auth
, false, NULL
),
163 ['I'] = HANDLER_NORM(stats_auth
, false, NULL
),
164 ['k'] = HANDLER_NORM(stats_tklines
, false, NULL
),
165 ['K'] = HANDLER_NORM(stats_klines
, false, NULL
),
166 ['l'] = HANDLER_PARV(stats_ltrace
, false, NULL
),
167 ['L'] = HANDLER_PARV(stats_ltrace
, false, NULL
),
168 ['m'] = HANDLER_NORM(stats_messages
, false, NULL
),
169 ['M'] = HANDLER_NORM(stats_messages
, false, NULL
),
170 ['n'] = HANDLER_NORM(stats_dnsbl
, false, NULL
),
171 ['o'] = HANDLER_NORM(stats_oper
, false, NULL
),
172 ['O'] = HANDLER_NORM(stats_privset
, false, "oper:privs"),
173 ['p'] = HANDLER_NORM(stats_operedup
, false, NULL
),
174 ['P'] = HANDLER_NORM(stats_ports
, false, NULL
),
175 ['q'] = HANDLER_NORM(stats_tresv
, false, "oper:general"),
176 ['Q'] = HANDLER_NORM(stats_resv
, false, "oper:general"),
177 ['r'] = HANDLER_NORM(stats_usage
, false, "oper:general"),
178 ['R'] = HANDLER_NORM(stats_usage
, false, "oper:general"),
179 ['s'] = HANDLER_NORM(stats_secure
, false, "oper:general"),
180 ['S'] = HANDLER_NORM(stats_ssld
, true, NULL
),
181 ['t'] = HANDLER_NORM(stats_tstats
, false, "oper:general"),
182 ['T'] = HANDLER_NORM(stats_tstats
, false, "oper:general"),
183 ['u'] = HANDLER_NORM(stats_uptime
, false, NULL
),
184 ['v'] = HANDLER_NORM(stats_servers
, false, NULL
),
185 ['V'] = HANDLER_NORM(stats_servers
, false, NULL
),
186 ['x'] = HANDLER_NORM(stats_tgecos
, false, "oper:general"),
187 ['X'] = HANDLER_NORM(stats_gecos
, false, "oper:general"),
188 ['y'] = HANDLER_NORM(stats_class
, false, NULL
),
189 ['Y'] = HANDLER_NORM(stats_class
, false, NULL
),
190 ['z'] = HANDLER_NORM(stats_memory
, false, "oper:general"),
191 ['?'] = HANDLER_NORM(stats_servlinks
, false, NULL
),
196 * Modified heavily by Elizafox
197 * parv[1] = stat letter/command
198 * parv[2] = (if present) server/mask in stats L, or target
200 * This will search the tables for the appropriate stats letter,
201 * if found execute it.
204 m_stats(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
206 static time_t last_used
= 0;
207 struct stats_cmd
*cmd
;
208 unsigned char statchar
;
211 statchar
= parv
[1][0];
213 if(MyClient(source_p
) && !IsOperGeneral(source_p
) && parc
> 2)
215 /* Check the user is actually allowed to do /stats, and isnt flooding */
216 if((last_used
+ ConfigFileEntry
.pace_wait
) > rb_current_time())
218 /* safe enough to give this on a local connect only */
219 sendto_one(source_p
, form_str(RPL_LOAD2HI
),
220 me
.name
, source_p
->name
, "STATS");
221 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
222 form_str(RPL_ENDOFSTATS
), statchar
);
226 last_used
= rb_current_time();
229 if(hunt_server(client_p
, source_p
, ":%s STATS %s :%s", 2, parc
, parv
) != HUNTED_ISME
)
232 if(tolower(statchar
) != 'l')
234 did_stats
= stats_spy(source_p
, statchar
, NULL
);
236 /* if did_stats is true, a module grabbed this STATS request */
241 cmd
= &stats_cmd_table
[statchar
];
242 if(cmd
->handler
!= NULL
)
244 /* The stats table says what privs are needed, so check --fl_ */
245 const char *missing_priv
= NULL
;
246 if(cmd
->need_admin
&& !IsOperAdmin(source_p
))
247 missing_priv
= "admin";
248 else if(cmd
->need_priv
&& !HasPrivilege(source_p
, cmd
->need_priv
))
249 missing_priv
= cmd
->need_priv
;
251 if(missing_priv
!= NULL
)
253 if(!IsOper(source_p
))
255 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
256 form_str(ERR_NOPRIVILEGES
));
260 if(!strncmp(missing_priv
, "oper:", 5))
262 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
263 me
.name
, source_p
->name
, missing_priv
);
269 cmd
->handler_parv(source_p
, parc
, parv
);
271 cmd
->handler(source_p
);
275 /* Send the end of stats notice, and the stats_spy */
276 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
277 form_str(RPL_ENDOFSTATS
), statchar
);
281 stats_dns_servers (struct Client
*source_p
)
285 RB_DLINK_FOREACH(n
, nameservers
.head
)
287 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "A :%s", (char *)n
->data
);
292 stats_delay(struct Client
*source_p
)
295 rb_dictionary_iter iter
;
297 RB_DICTIONARY_FOREACH(nd
, &iter
, nd_dict
)
299 sendto_one_notice(source_p
, ":Delaying: %s for %ld",
300 nd
->name
, (long) nd
->expire
);
305 stats_hash_cb(const char *buf
, void *client_p
)
307 sendto_one_numeric(client_p
, RPL_STATSDEBUG
, "B :%s", buf
);
311 stats_hash(struct Client
*source_p
)
313 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "B :%-30s %-15s %-10s %-10s %-10s %-10s",
314 "NAME", "TYPE", "OBJECTS", "DEPTH SUM", "AVG DEPTH", "MAX DEPTH");
316 rb_dictionary_stats_walk(stats_hash_cb
, source_p
);
317 rb_radixtree_stats_walk(stats_hash_cb
, source_p
);
321 stats_connect(struct Client
*source_p
)
323 static char buf
[BUFSIZE
];
324 struct server_conf
*server_p
;
328 if((ConfigFileEntry
.stats_c_oper_only
||
329 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
330 !IsOperGeneral(source_p
))
332 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
333 form_str(ERR_NOPRIVILEGES
));
337 RB_DLINK_FOREACH(ptr
, server_conf_list
.head
)
339 server_p
= ptr
->data
;
341 if(ServerConfIllegal(server_p
))
346 if(IsOperGeneral(source_p
))
348 if(ServerConfAutoconn(server_p
))
350 if(ServerConfSCTP(server_p
))
352 if(ServerConfSSL(server_p
))
354 if(ServerConfTb(server_p
))
363 sendto_one_numeric(source_p
, RPL_STATSCLINE
,
364 form_str(RPL_STATSCLINE
),
367 server_p
->port
, server_p
->class_name
,
368 server_p
->certfp
? server_p
->certfp
: "*");
374 * input - client to report to
376 * side effects - client is given temp dline list.
379 stats_tdeny (struct Client
*source_p
)
381 char *host
, *pass
, *user
, *oper_reason
;
382 struct AddressRec
*arec
;
383 struct ConfItem
*aconf
;
386 for (i
= 0; i
< ATABLE_SIZE
; i
++)
388 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
390 if(arec
->type
== CONF_DLINE
)
394 if(!(aconf
->flags
& CONF_FLAGS_TEMPORARY
))
397 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
399 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
400 form_str (RPL_STATSDLINE
),
402 oper_reason
? "|" : "",
403 oper_reason
? oper_reason
: "");
411 * input - client to report to
413 * side effects - client is given dline list.
416 stats_deny (struct Client
*source_p
)
418 char *host
, *pass
, *user
, *oper_reason
;
419 struct AddressRec
*arec
;
420 struct ConfItem
*aconf
;
423 for (i
= 0; i
< ATABLE_SIZE
; i
++)
425 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
427 if(arec
->type
== CONF_DLINE
)
431 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
434 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
436 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
437 form_str (RPL_STATSDLINE
),
439 oper_reason
? "|" : "",
440 oper_reason
? oper_reason
: "");
449 * input - client to report to
451 * side effects - client is given list of exempt blocks
454 stats_exempt(struct Client
*source_p
)
456 char *name
, *host
, *user
, *classname
, *desc
;
458 struct AddressRec
*arec
;
459 struct ConfItem
*aconf
;
462 if(ConfigFileEntry
.stats_e_disabled
)
464 sendto_one_numeric(source_p
, ERR_DISABLED
,
465 form_str(ERR_DISABLED
), "STATS e");
469 for (i
= 0; i
< ATABLE_SIZE
; i
++)
471 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
473 if(arec
->type
== CONF_EXEMPTDLINE
)
476 get_printable_conf (aconf
, &name
, &host
, &pass
,
477 &user
, &port
, &classname
, &desc
);
479 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
480 form_str(RPL_STATSDLINE
),
481 'e', host
, pass
, "", "");
489 stats_events_cb(char *str
, void *ptr
)
491 sendto_one_numeric(ptr
, RPL_STATSDEBUG
, "E :%s", str
);
495 stats_events (struct Client
*source_p
)
497 rb_dump_events(stats_events_cb
, source_p
);
501 stats_prop_klines(struct Client
*source_p
)
503 struct ConfItem
*aconf
;
504 char *user
, *host
, *pass
, *oper_reason
;
505 rb_dictionary_iter state
;
507 RB_DICTIONARY_FOREACH(aconf
, &state
, prop_bans_dict
)
509 /* Skip non-klines and deactivated klines. */
510 if (aconf
->status
!= CONF_KILL
)
513 get_printable_kline(source_p
, aconf
, &host
, &pass
,
514 &user
, &oper_reason
);
516 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
517 form_str(RPL_STATSKLINE
),
518 'g', host
, user
, pass
,
519 oper_reason
? "|" : "",
520 oper_reason
? oper_reason
: "");
525 stats_auth (struct Client
*source_p
)
527 /* Oper only, if unopered, return ERR_NOPRIVS */
528 if((ConfigFileEntry
.stats_i_oper_only
== 2) && !IsOperGeneral (source_p
))
529 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
530 form_str (ERR_NOPRIVILEGES
));
532 /* If unopered, Only return matching auth blocks */
533 else if((ConfigFileEntry
.stats_i_oper_only
== 1) && !IsOperGeneral (source_p
))
535 struct ConfItem
*aconf
;
536 char *name
, *host
, *user
, *classname
, *desc
;
537 const char *pass
= "*";
540 if(MyConnect (source_p
))
541 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
542 (struct sockaddr
*)&source_p
->localClient
->ip
,
544 GET_SS_FAMILY(&source_p
->localClient
->ip
),
545 source_p
->username
, NULL
);
547 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_CLIENT
,
548 0, source_p
->username
, NULL
);
553 get_printable_conf (aconf
, &name
, &host
, &pass
, &user
, &port
, &classname
, &desc
);
554 if(!EmptyString(aconf
->spasswd
))
555 pass
= aconf
->spasswd
;
557 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
558 name
, pass
, show_iline_prefix(source_p
, aconf
, user
),
559 host
, port
, classname
, desc
);
562 /* Theyre opered, or allowed to see all auth blocks */
564 report_auth (source_p
);
569 stats_tklines(struct Client
*source_p
)
571 /* Oper only, if unopered, return ERR_NOPRIVS */
572 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOperGeneral (source_p
))
573 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
574 form_str (ERR_NOPRIVILEGES
));
576 /* If unopered, Only return matching klines */
577 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOperGeneral (source_p
))
579 struct ConfItem
*aconf
;
580 char *host
, *pass
, *user
, *oper_reason
;
582 if(MyConnect (source_p
))
583 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
584 (struct sockaddr
*)&source_p
->localClient
->ip
,
586 GET_SS_FAMILY(&source_p
->localClient
->ip
),
587 source_p
->username
, NULL
);
589 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
590 0, source_p
->username
, NULL
);
595 /* dont report a permanent kline as a tkline */
596 if((aconf
->flags
& CONF_FLAGS_TEMPORARY
) == 0)
599 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
601 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
602 form_str(RPL_STATSKLINE
), (aconf
->flags
& CONF_FLAGS_TEMPORARY
) ? 'k' : 'K',
603 host
, user
, pass
, oper_reason
? "|" : "",
604 oper_reason
? oper_reason
: "");
606 /* Theyre opered, or allowed to see all klines */
609 struct ConfItem
*aconf
;
612 char *user
, *host
, *pass
, *oper_reason
;
614 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
616 RB_DLINK_FOREACH(ptr
, temp_klines
[i
].head
)
620 get_printable_kline(source_p
, aconf
, &host
, &pass
,
621 &user
, &oper_reason
);
623 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
624 form_str(RPL_STATSKLINE
),
625 'k', host
, user
, pass
,
626 oper_reason
? "|" : "",
627 oper_reason
? oper_reason
: "");
635 * inputs - Client to report to, mask
637 * side effects - Reports configured K-lines to client_p.
640 report_Klines(struct Client
*source_p
)
642 char *host
, *pass
, *user
, *oper_reason
;
643 struct AddressRec
*arec
;
644 struct ConfItem
*aconf
= NULL
;
647 for (i
= 0; i
< ATABLE_SIZE
; i
++)
649 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
651 if(arec
->type
== CONF_KILL
)
655 /* its a tempkline, theyre reported elsewhere */
656 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
659 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
660 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
661 form_str(RPL_STATSKLINE
),
662 'K', host
, user
, pass
,
663 oper_reason
? "|" : "",
664 oper_reason
? oper_reason
: "");
671 stats_klines(struct Client
*source_p
)
673 /* Oper only, if unopered, return ERR_NOPRIVS */
674 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOperGeneral (source_p
))
675 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
676 form_str (ERR_NOPRIVILEGES
));
678 /* If unopered, Only return matching klines */
679 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOperGeneral (source_p
))
681 struct ConfItem
*aconf
;
682 char *host
, *pass
, *user
, *oper_reason
;
684 /* search for a kline */
685 if(MyConnect (source_p
))
686 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
687 (struct sockaddr
*)&source_p
->localClient
->ip
,
689 GET_SS_FAMILY(&source_p
->localClient
->ip
),
690 source_p
->username
, NULL
);
692 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
693 0, source_p
->username
, NULL
);
698 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
700 sendto_one_numeric(source_p
, RPL_STATSKLINE
, form_str(RPL_STATSKLINE
),
701 (aconf
->flags
& CONF_FLAGS_TEMPORARY
) ? 'k' : 'K',
702 host
, user
, pass
, oper_reason
? "|" : "",
703 oper_reason
? oper_reason
: "");
705 /* Theyre opered, or allowed to see all klines */
707 report_Klines (source_p
);
711 stats_messages(struct Client
*source_p
)
713 rb_dictionary_iter iter
;
716 RB_DICTIONARY_FOREACH(msg
, &iter
, cmd_dict
)
718 s_assert(msg
->cmd
!= NULL
);
719 sendto_one_numeric(source_p
, RPL_STATSCOMMANDS
,
720 form_str(RPL_STATSCOMMANDS
),
721 msg
->cmd
, msg
->count
,
722 msg
->bytes
, msg
->rcount
);
727 stats_dnsbl(struct Client
*source_p
)
729 rb_dictionary_iter iter
;
730 struct DNSBLEntryStats
*stats
;
732 if(dnsbl_stats
== NULL
)
735 RB_DICTIONARY_FOREACH(stats
, &iter
, dnsbl_stats
)
737 /* use RPL_STATSDEBUG for now -- jilles */
738 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "n :%d %s",
739 stats
->hits
, (const char *)iter
.cur
->key
);
744 stats_oper(struct Client
*source_p
)
746 struct oper_conf
*oper_p
;
749 if(!IsOperGeneral(source_p
) && ConfigFileEntry
.stats_o_oper_only
)
751 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
752 form_str (ERR_NOPRIVILEGES
));
756 RB_DLINK_FOREACH(ptr
, oper_conf_list
.head
)
760 sendto_one_numeric(source_p
, RPL_STATSOLINE
,
761 form_str(RPL_STATSOLINE
),
762 oper_p
->username
, oper_p
->host
, oper_p
->name
,
763 HasPrivilege(source_p
, "oper:privs") ? oper_p
->privset
->name
: "0", "-1");
768 stats_capability_walk(const char *line
, void *data
)
770 struct Client
*client_p
= data
;
772 sendto_one_numeric(client_p
, RPL_STATSDEBUG
, "C :%s", line
);
776 stats_capability(struct Client
*client_p
)
778 capability_index_stats(stats_capability_walk
, client_p
);
782 stats_privset(struct Client
*source_p
)
784 privilegeset_report(source_p
);
789 * input - client pointer
791 * side effects - client is shown a list of active opers
794 stats_operedup (struct Client
*source_p
)
796 struct Client
*target_p
;
797 rb_dlink_node
*oper_ptr
;
798 unsigned int count
= 0;
800 RB_DLINK_FOREACH (oper_ptr
, oper_list
.head
)
802 target_p
= oper_ptr
->data
;
804 if(!SeesOper(target_p
, source_p
))
807 if(target_p
->user
->away
)
812 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
814 target_p
->name
, target_p
->username
,
818 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
819 "p :%u staff members", count
);
821 stats_p_spy (source_p
);
825 stats_ports (struct Client
*source_p
)
827 if(!IsOperGeneral (source_p
) && ConfigFileEntry
.stats_P_oper_only
)
828 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
829 form_str (ERR_NOPRIVILEGES
));
831 show_ports (source_p
);
835 stats_tresv(struct Client
*source_p
)
837 struct ConfItem
*aconf
;
838 rb_radixtree_iteration_state state
;
841 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
845 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
846 form_str(RPL_STATSQLINE
),
847 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
850 RB_RADIXTREE_FOREACH(aconf
, &state
, resv_tree
)
853 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
854 form_str(RPL_STATSQLINE
),
855 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
861 stats_resv(struct Client
*source_p
)
863 struct ConfItem
*aconf
;
864 rb_radixtree_iteration_state state
;
867 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
871 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
872 form_str(RPL_STATSQLINE
),
873 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
876 RB_RADIXTREE_FOREACH(aconf
, &state
, resv_tree
)
879 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
880 form_str(RPL_STATSQLINE
),
881 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
886 stats_secure(struct Client
*source_p
)
888 struct AddressRec
*arec
;
889 struct ConfItem
*aconf
;
892 for (i
= 0; i
< ATABLE_SIZE
; i
++)
894 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
896 if(arec
->type
== CONF_SECURE
)
899 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "s :%s", aconf
->host
);
906 stats_ssld_foreach(void *data
, pid_t pid
, int cli_count
, enum ssld_status status
, const char *version
)
908 struct Client
*source_p
= data
;
910 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
913 status
== SSLD_DEAD
? 'D' : (status
== SSLD_SHUTDOWN
? 'S' : 'A'),
919 stats_ssld(struct Client
*source_p
)
921 ssld_foreach_info(stats_ssld_foreach
, source_p
);
925 stats_usage (struct Client
*source_p
)
940 if(getrusage(RUSAGE_SELF
, &rus
) == -1)
942 sendto_one_notice(source_p
, ":Getruseage error: %s.",
946 secs
= rus
.ru_utime
.tv_sec
+ rus
.ru_stime
.tv_sec
;
950 rup
= (rb_current_time() - startup_time
) * hzz
;
954 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
955 "R :CPU Secs %d:%02d User %d:%02d System %d:%02d",
956 (int) (secs
/ 60), (int) (secs
% 60),
957 (int) (rus
.ru_utime
.tv_sec
/ 60),
958 (int) (rus
.ru_utime
.tv_sec
% 60),
959 (int) (rus
.ru_stime
.tv_sec
/ 60),
960 (int) (rus
.ru_stime
.tv_sec
% 60));
961 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
962 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
963 rus
.ru_maxrss
, (long)(rus
.ru_ixrss
/ rup
),
964 (long)(rus
.ru_idrss
/ rup
), (long)(rus
.ru_isrss
/ rup
));
965 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
966 "R :Swaps %d Reclaims %d Faults %d",
967 (int) rus
.ru_nswap
, (int) rus
.ru_minflt
, (int) rus
.ru_majflt
);
968 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
969 "R :Block in %d out %d",
970 (int) rus
.ru_inblock
, (int) rus
.ru_oublock
);
971 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
972 "R :Msg Rcv %d Send %d",
973 (int) rus
.ru_msgrcv
, (int) rus
.ru_msgsnd
);
974 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
975 "R :Signals %d Context Vol. %d Invol %d",
976 (int) rus
.ru_nsignals
, (int) rus
.ru_nvcsw
,
977 (int) rus
.ru_nivcsw
);
981 stats_tstats (struct Client
*source_p
)
983 struct Client
*target_p
;
984 struct ServerStatistics sp
;
987 memcpy(&sp
, &ServerStats
, sizeof(struct ServerStatistics
));
989 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
991 target_p
= ptr
->data
;
993 sp
.is_sbs
+= target_p
->localClient
->sendB
;
994 sp
.is_sbr
+= target_p
->localClient
->receiveB
;
995 sp
.is_sti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
999 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
1001 target_p
= ptr
->data
;
1003 sp
.is_cbs
+= target_p
->localClient
->sendB
;
1004 sp
.is_cbr
+= target_p
->localClient
->receiveB
;
1005 sp
.is_cti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
1009 RB_DLINK_FOREACH(ptr
, unknown_list
.head
)
1014 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1015 "T :accepts %u refused %u", sp
.is_ac
, sp
.is_ref
);
1016 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1017 "T :rejected %u delaying %lu",
1018 sp
.is_rej
, delay_exit_length());
1019 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1020 "T :throttled refused %u throttle list size %lu", sp
.is_thr
, throttle_size());
1021 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1022 "T :nicks being delayed %lu",
1024 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1025 "T :unknown commands %u prefixes %u",
1026 sp
.is_unco
, sp
.is_unpf
);
1027 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1028 "T :nick collisions %u saves %u unknown closes %u",
1029 sp
.is_kill
, sp
.is_save
, sp
.is_ni
);
1030 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1031 "T :wrong direction %u empty %u",
1032 sp
.is_wrdi
, sp
.is_empt
);
1033 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1034 "T :numerics seen %u", sp
.is_num
);
1035 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1036 "T :tgchange blocked msgs %u restricted addrs %lu",
1037 sp
.is_tgch
, rb_dlink_list_length(&tgchange_list
));
1038 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1039 "T :ratelimit blocked commands %u", sp
.is_rl
);
1040 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1041 "T :auth successes %u fails %u",
1042 sp
.is_asuc
, sp
.is_abad
);
1043 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1044 "T :sasl successes %u fails %u",
1045 sp
.is_ssuc
, sp
.is_sbad
);
1046 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "T :Client Server");
1047 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1048 "T :connected %u %u", sp
.is_cl
, sp
.is_sv
);
1049 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1050 "T :bytes sent %lluK %lluK",
1053 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1054 "T :bytes recv %lluK %lluK",
1057 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1058 "T :time connected %llu %llu",
1059 sp
.is_cti
, sp
.is_sti
);
1063 stats_uptime (struct Client
*source_p
)
1067 now
= rb_current_time() - startup_time
;
1068 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
1069 form_str (RPL_STATSUPTIME
),
1070 (int)(now
/ 86400), (int)((now
/ 3600) % 24),
1071 (int)((now
/ 60) % 60), (int)(now
% 60));
1072 sendto_one_numeric(source_p
, RPL_STATSCONN
,
1073 form_str (RPL_STATSCONN
),
1074 MaxConnectionCount
, MaxClientCount
,
1075 Count
.totalrestartcount
);
1081 * input - client pointer
1083 * side effects - client is shown lists of who connected servers
1086 stats_servers (struct Client
*source_p
)
1088 struct Client
*target_p
;
1091 int days
, hours
, minutes
;
1094 if(ConfigServerHide
.flatten_links
&& !IsOperGeneral(source_p
) &&
1095 !IsExemptShide(source_p
))
1097 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1098 form_str (ERR_NOPRIVILEGES
));
1102 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1104 target_p
= ptr
->data
;
1107 seconds
= rb_current_time() - target_p
->localClient
->firsttime
;
1109 days
= (int) (seconds
/ 86400);
1111 hours
= (int) (seconds
/ 3600);
1113 minutes
= (int) (seconds
/ 60);
1116 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1117 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1118 "Connected: %d day%s, %d:%02d:%02d",
1120 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
1121 (int) (rb_current_time() - target_p
->localClient
->lasttime
),
1122 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1123 days
, (days
== 1) ? "" : "s", hours
, minutes
,
1127 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1128 "V :%d Server(s)", j
);
1132 stats_tgecos(struct Client
*source_p
)
1134 struct ConfItem
*aconf
;
1137 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1142 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1143 form_str(RPL_STATSXLINE
),
1144 'x', aconf
->port
, aconf
->host
,
1150 stats_gecos(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_class(struct Client
*source_p
)
1170 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOperGeneral(source_p
))
1171 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1172 form_str (ERR_NOPRIVILEGES
));
1174 report_classes(source_p
);
1178 stats_memory (struct Client
*source_p
)
1180 struct Client
*target_p
;
1181 struct Channel
*chptr
;
1182 rb_dlink_node
*rb_dlink
;
1184 int channel_count
= 0;
1185 int local_client_conf_count
= 0; /* local client conf links */
1186 int users_counted
= 0; /* user structs */
1188 int channel_users
= 0;
1189 int channel_invites
= 0;
1190 int channel_bans
= 0;
1191 int channel_except
= 0;
1192 int channel_invex
= 0;
1193 int channel_quiets
= 0;
1195 int class_count
= 0; /* classes */
1196 int conf_count
= 0; /* conf lines */
1197 int users_invited_count
= 0; /* users invited */
1198 int user_channels
= 0; /* users in channels */
1199 int aways_counted
= 0;
1200 size_t number_servers_cached
; /* number of servers cached by scache */
1202 size_t channel_memory
= 0;
1203 size_t channel_ban_memory
= 0;
1204 size_t channel_except_memory
= 0;
1205 size_t channel_invex_memory
= 0;
1206 size_t channel_quiet_memory
= 0;
1208 size_t away_memory
= 0; /* memory used by aways */
1209 size_t ww
= 0; /* whowas array count */
1210 size_t wwm
= 0; /* whowas array memory used */
1211 size_t conf_memory
= 0; /* memory used by conf lines */
1212 size_t mem_servers_cached
; /* memory used by scache */
1214 size_t linebuf_count
= 0;
1215 size_t linebuf_memory_used
= 0;
1217 size_t total_channel_memory
= 0;
1220 size_t local_client_count
= 0;
1221 size_t local_client_memory_used
= 0;
1223 size_t remote_client_count
= 0;
1224 size_t remote_client_memory_used
= 0;
1226 size_t total_memory
= 0;
1228 whowas_memory_usage(&ww
, &wwm
);
1230 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
1232 target_p
= ptr
->data
;
1233 if(MyConnect(target_p
))
1235 local_client_conf_count
++;
1241 users_invited_count
+= rb_dlink_list_length(&target_p
->user
->invited
);
1242 user_channels
+= rb_dlink_list_length(&target_p
->user
->channel
);
1243 if(target_p
->user
->away
)
1246 away_memory
+= (strlen(target_p
->user
->away
) + 1);
1251 /* Count up all channels, ban lists, except lists, Invex lists */
1252 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
1256 channel_memory
+= (strlen(chptr
->chname
) + sizeof(struct Channel
));
1258 channel_users
+= rb_dlink_list_length(&chptr
->members
);
1259 channel_invites
+= rb_dlink_list_length(&chptr
->invites
);
1261 RB_DLINK_FOREACH(rb_dlink
, chptr
->banlist
.head
)
1265 channel_ban_memory
+= sizeof(rb_dlink_node
) + sizeof(struct Ban
);
1268 RB_DLINK_FOREACH(rb_dlink
, chptr
->exceptlist
.head
)
1272 channel_except_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1275 RB_DLINK_FOREACH(rb_dlink
, chptr
->invexlist
.head
)
1279 channel_invex_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1282 RB_DLINK_FOREACH(rb_dlink
, chptr
->quietlist
.head
)
1286 channel_quiet_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1290 /* count up all classes */
1292 class_count
= rb_dlink_list_length(&class_list
) + 1;
1294 rb_count_rb_linebuf_memory(&linebuf_count
, &linebuf_memory_used
);
1296 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1297 "z :Users %u(%lu) Invites %u(%lu)",
1299 (unsigned long) users_counted
* sizeof(struct User
),
1300 users_invited_count
,
1301 (unsigned long) users_invited_count
* sizeof(rb_dlink_node
));
1303 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1304 "z :User channels %u(%lu) Aways %u(%zu)",
1306 (unsigned long) user_channels
* sizeof(rb_dlink_node
),
1307 aways_counted
, away_memory
);
1309 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1310 "z :Attached confs %u(%lu)",
1311 local_client_conf_count
,
1312 (unsigned long) local_client_conf_count
* sizeof(rb_dlink_node
));
1314 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1315 "z :Conflines %u(%zu)", conf_count
, conf_memory
);
1317 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1318 "z :Classes %u(%lu)",
1320 (unsigned long) class_count
* sizeof(struct Class
));
1322 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1323 "z :Channels %u(%zu)",
1324 channel_count
, channel_memory
);
1326 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1327 "z :Bans %u(%zu) Exceptions %u(%zu) Invex %u(%zu) Quiets %u(%zu)",
1328 channel_bans
, channel_ban_memory
,
1329 channel_except
, channel_except_memory
,
1330 channel_invex
, channel_invex_memory
,
1331 channel_quiets
, channel_quiet_memory
);
1333 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1334 "z :Channel members %u(%lu) invite %u(%lu)",
1336 (unsigned long) channel_users
* sizeof(rb_dlink_node
),
1338 (unsigned long) channel_invites
* sizeof(rb_dlink_node
));
1340 total_channel_memory
= channel_memory
+
1341 channel_ban_memory
+
1342 channel_users
* sizeof(rb_dlink_node
) + channel_invites
* sizeof(rb_dlink_node
);
1344 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1345 "z :Whowas array %zu(%zu)",
1350 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1351 "z :Hash: client %u(%lu) chan %u(%lu)",
1352 U_MAX
, (unsigned long)(U_MAX
* sizeof(rb_dlink_list
)),
1353 CH_MAX
, (unsigned long)(CH_MAX
* sizeof(rb_dlink_list
)));
1355 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1356 "z :linebuf %zu(%zu)",
1357 linebuf_count
, linebuf_memory_used
);
1359 count_scache(&number_servers_cached
, &mem_servers_cached
);
1361 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1362 "z :scache %zu(%zu)",
1363 number_servers_cached
, mem_servers_cached
);
1365 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1366 "z :hostname hash %d(%lu)",
1367 HOST_MAX
, (unsigned long)HOST_MAX
* sizeof(rb_dlink_list
));
1369 total_memory
= totww
+ total_channel_memory
+ conf_memory
+
1370 class_count
* sizeof(struct Class
);
1372 total_memory
+= mem_servers_cached
;
1373 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1374 "z :Total: whowas %zu channel %zu conf %zu",
1375 totww
, total_channel_memory
,
1378 count_local_client_memory(&local_client_count
, &local_client_memory_used
);
1379 total_memory
+= local_client_memory_used
;
1381 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1382 "z :Local client Memory in use: %zu(%zu)",
1383 local_client_count
, local_client_memory_used
);
1386 count_remote_client_memory(&remote_client_count
, &remote_client_memory_used
);
1387 total_memory
+= remote_client_memory_used
;
1389 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1390 "z :Remote client Memory in use: %zu(%zu)",
1391 remote_client_count
,
1392 remote_client_memory_used
);
1394 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1400 stats_servlinks (struct Client
*source_p
)
1402 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1403 long uptime
, sendK
, receiveK
;
1404 struct Client
*target_p
;
1409 if(ConfigServerHide
.flatten_links
&& !IsOperGeneral (source_p
) &&
1410 !IsExemptShide(source_p
))
1412 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1413 form_str (ERR_NOPRIVILEGES
));
1417 sendK
= receiveK
= 0;
1419 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1421 target_p
= ptr
->data
;
1424 sendK
+= target_p
->localClient
->sendK
;
1425 receiveK
+= target_p
->localClient
->receiveK
;
1427 sendto_one(source_p
, Sformat
,
1428 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1430 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1431 (int) target_p
->localClient
->sendM
,
1432 (int) target_p
->localClient
->sendK
,
1433 (int) target_p
->localClient
->receiveM
,
1434 (int) target_p
->localClient
->receiveK
,
1435 rb_current_time() - target_p
->localClient
->firsttime
,
1436 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1437 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1438 IsOperGeneral (source_p
) ? show_capabilities (target_p
) : "TS");
1441 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1442 "? :%u total server(s)", j
);
1444 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((sendK
)));
1445 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1446 "? :Sent total : %s %s",
1447 buf
, _GMKs (sendK
));
1448 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((receiveK
)));
1449 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1450 "? :Recv total : %s %s",
1451 buf
, _GMKs (receiveK
));
1453 uptime
= (rb_current_time() - startup_time
);
1454 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1455 _GMKv (me
.localClient
->sendK
),
1456 _GMKs (me
.localClient
->sendK
),
1457 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1458 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server send: %s", buf
);
1459 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1460 _GMKv (me
.localClient
->receiveK
),
1461 _GMKs (me
.localClient
->receiveK
),
1462 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1463 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server recv: %s", buf
);
1467 stats_l_should_show_oper(struct Client
*source_p
, struct Client
*target_p
)
1469 return SeesOper(target_p
, source_p
);
1473 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1478 char statchar
= parv
[1][0];
1480 if (ConfigFileEntry
.stats_l_oper_only
== STATS_L_OPER_ONLY_YES
&& !IsOperGeneral(source_p
))
1482 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
1486 /* this is def targeted at us somehow.. */
1487 if (parc
> 2 && !EmptyString(parv
[2]))
1489 /* directed at us generically? */
1490 if (match(parv
[2], me
.name
) || (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1498 wilds
= strchr(name
, '*') || strchr(name
, '?');
1501 /* must be directed at a specific person thats not us */
1502 if (!doall
&& !wilds
)
1504 struct Client
*target_p
;
1506 if (MyClient(source_p
))
1507 target_p
= find_named_person(name
);
1509 target_p
= find_person(name
);
1511 if (target_p
!= source_p
&& ConfigFileEntry
.stats_l_oper_only
!= STATS_L_OPER_ONLY_NO
1512 && !IsOperGeneral(source_p
))
1514 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
1516 else if (target_p
!= NULL
)
1518 stats_spy(source_p
, statchar
, target_p
->name
);
1519 stats_l_client(source_p
, target_p
, statchar
);
1523 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1524 form_str(ERR_NOSUCHSERVER
),
1537 stats_spy(source_p
, statchar
, name
);
1539 if (ConfigFileEntry
.stats_l_oper_only
!= STATS_L_OPER_ONLY_NO
&& !IsOperGeneral(source_p
))
1541 if (doall
&& MyClient(source_p
))
1542 stats_l_client(source_p
, source_p
, statchar
);
1544 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
1550 /* local opers get everyone */
1551 if(MyOper(source_p
))
1553 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
, NULL
);
1554 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1558 /* they still need themselves if theyre local.. */
1559 if(MyClient(source_p
))
1560 stats_l_client(source_p
, source_p
, statchar
);
1562 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
, stats_l_should_show_oper
);
1565 if (!ConfigServerHide
.flatten_links
|| IsOperGeneral(source_p
) ||
1566 IsExemptShide(source_p
))
1567 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
, NULL
);
1572 /* ok, at this point theyre looking for a specific client whos on
1573 * our server.. but it contains a wildcard. --fl
1575 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1581 stats_l_list(struct Client
*source_p
, const char *name
, bool doall
, bool wilds
,
1582 rb_dlink_list
* list
, char statchar
, bool (*check_fn
)(struct Client
*source_p
, struct Client
*target_p
))
1585 struct Client
*target_p
;
1587 /* send information about connections which match. note, we
1588 * dont need tests for IsInvisible(), because non-opers will
1589 * never get here for normal clients --fl
1591 RB_DLINK_FOREACH(ptr
, list
->head
)
1593 target_p
= ptr
->data
;
1595 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1598 if (check_fn
== NULL
|| check_fn(source_p
, target_p
))
1599 stats_l_client(source_p
, target_p
, statchar
);
1604 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1607 if(IsAnyServer(target_p
))
1609 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1611 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1612 (int) target_p
->localClient
->sendM
,
1613 (int) target_p
->localClient
->sendK
,
1614 (int) target_p
->localClient
->receiveM
,
1615 (int) target_p
->localClient
->receiveK
,
1616 rb_current_time() - target_p
->localClient
->firsttime
,
1617 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1618 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1619 IsOperGeneral(source_p
) ? show_capabilities(target_p
) : "-");
1624 /* fire the doing_stats_show_idle hook to allow modules to tell us whether to show the idle time */
1625 hook_data_client_approval hdata_showidle
;
1627 hdata_showidle
.client
= source_p
;
1628 hdata_showidle
.target
= target_p
;
1629 hdata_showidle
.approved
= WHOIS_IDLE_SHOW
;
1631 call_hook(doing_stats_show_idle_hook
, &hdata_showidle
);
1632 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1633 show_ip(source_p
, target_p
) ?
1634 (IsUpper(statchar
) ?
1635 get_client_name(target_p
, SHOW_IP
) :
1636 get_client_name(target_p
, HIDE_IP
)) :
1637 get_client_name(target_p
, MASK_IP
),
1638 hdata_showidle
.approved
? (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
) : 0,
1639 hdata_showidle
.approved
? (int) target_p
->localClient
->sendM
: 0,
1640 hdata_showidle
.approved
? (int) target_p
->localClient
->sendK
: 0,
1641 hdata_showidle
.approved
? (int) target_p
->localClient
->receiveM
: 0,
1642 hdata_showidle
.approved
? (int) target_p
->localClient
->receiveK
: 0,
1643 rb_current_time() - target_p
->localClient
->firsttime
,
1644 (rb_current_time() > target_p
->localClient
->lasttime
) && hdata_showidle
.approved
?
1645 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1651 rb_dump_fd_callback(int fd
, const char *desc
, void *data
)
1653 struct Client
*source_p
= data
;
1654 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "F :fd %-3d desc '%s'", fd
, desc
);
1658 stats_comm(struct Client
*source_p
)
1660 rb_dump_fd(rb_dump_fd_callback
, source_p
);
1666 * inputs - pointer to client doing the /stats
1667 * - char letter they are doing /stats on
1670 * This little helper function reports to opers if configured.
1673 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1677 data
.client
= source_p
;
1679 data
.arg2
= (int) statchar
;
1682 call_hook(doing_stats_hook
, &data
);
1689 * input - pointer to client doing stats
1691 * side effects - call hook doing_stats_p
1694 stats_p_spy (struct Client
*source_p
)
1698 data
.client
= source_p
;
1699 data
.arg1
= data
.arg2
= NULL
;
1701 call_hook(doing_stats_p_hook
, &data
);