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_auth(struct Client
*);
108 static void stats_tklines(struct Client
*);
109 static void stats_klines(struct Client
*);
110 static void stats_messages(struct Client
*);
111 static void stats_dnsbl(struct Client
*);
112 static void stats_oper(struct Client
*);
113 static void stats_privset(struct Client
*);
114 static void stats_operedup(struct Client
*);
115 static void stats_ports(struct Client
*);
116 static void stats_tresv(struct Client
*);
117 static void stats_resv(struct Client
*);
118 static void stats_secure(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_comm(struct Client
*);
131 static void stats_capability(struct Client
*);
133 #define HANDLER_NORM(fn, admin, priv) \
134 { { .handler = fn }, .need_parv = false, .need_priv = priv, .need_admin = admin }
135 #define HANDLER_PARV(fn, admin, priv) \
136 { { .handler_parv = fn }, .need_parv = true, .need_priv = priv, .need_admin = admin }
138 /* This table contains the possible stats items, in order:
139 * stats letter, function to call, operonly? adminonly? --fl_
141 * Previously in this table letters were a column. I fixed it to use modern
142 * C initalisers so we don't have to iterate anymore
145 static struct stats_cmd stats_cmd_table
[256] = {
146 /* letter handler admin priv */
147 ['a'] = HANDLER_NORM(stats_dns_servers
, true, NULL
),
148 ['A'] = HANDLER_NORM(stats_dns_servers
, true, NULL
),
149 ['b'] = HANDLER_NORM(stats_delay
, true, NULL
),
150 ['B'] = HANDLER_NORM(stats_hash
, true, NULL
),
151 ['c'] = HANDLER_NORM(stats_connect
, false, NULL
),
152 ['C'] = HANDLER_NORM(stats_capability
, false, "oper:general"),
153 ['d'] = HANDLER_NORM(stats_tdeny
, false, "oper:general"),
154 ['D'] = HANDLER_NORM(stats_deny
, false, "oper:general"),
155 ['e'] = HANDLER_NORM(stats_exempt
, false, "oper:general"),
156 ['E'] = HANDLER_NORM(stats_events
, true, NULL
),
157 ['f'] = HANDLER_NORM(stats_comm
, true, NULL
),
158 ['F'] = HANDLER_NORM(stats_comm
, true, NULL
),
159 ['g'] = HANDLER_NORM(stats_prop_klines
, false, "oper:general"),
160 ['i'] = HANDLER_NORM(stats_auth
, false, NULL
),
161 ['I'] = HANDLER_NORM(stats_auth
, false, NULL
),
162 ['k'] = HANDLER_NORM(stats_tklines
, false, NULL
),
163 ['K'] = HANDLER_NORM(stats_klines
, false, NULL
),
164 ['l'] = HANDLER_PARV(stats_ltrace
, false, NULL
),
165 ['L'] = HANDLER_PARV(stats_ltrace
, false, NULL
),
166 ['m'] = HANDLER_NORM(stats_messages
, false, NULL
),
167 ['M'] = HANDLER_NORM(stats_messages
, false, NULL
),
168 ['n'] = HANDLER_NORM(stats_dnsbl
, false, NULL
),
169 ['o'] = HANDLER_NORM(stats_oper
, false, NULL
),
170 ['O'] = HANDLER_NORM(stats_privset
, false, "oper:privs"),
171 ['p'] = HANDLER_NORM(stats_operedup
, false, NULL
),
172 ['P'] = HANDLER_NORM(stats_ports
, false, NULL
),
173 ['q'] = HANDLER_NORM(stats_tresv
, false, "oper:general"),
174 ['Q'] = HANDLER_NORM(stats_resv
, false, "oper:general"),
175 ['r'] = HANDLER_NORM(stats_usage
, false, "oper:general"),
176 ['R'] = HANDLER_NORM(stats_usage
, false, "oper:general"),
177 ['s'] = HANDLER_NORM(stats_secure
, false, "oper:general"),
178 ['S'] = HANDLER_NORM(stats_ssld
, true, NULL
),
179 ['t'] = HANDLER_NORM(stats_tstats
, false, "oper:general"),
180 ['T'] = HANDLER_NORM(stats_tstats
, false, "oper:general"),
181 ['u'] = HANDLER_NORM(stats_uptime
, false, NULL
),
182 ['v'] = HANDLER_NORM(stats_servers
, false, NULL
),
183 ['V'] = HANDLER_NORM(stats_servers
, false, NULL
),
184 ['x'] = HANDLER_NORM(stats_tgecos
, false, "oper:general"),
185 ['X'] = HANDLER_NORM(stats_gecos
, false, "oper:general"),
186 ['y'] = HANDLER_NORM(stats_class
, false, NULL
),
187 ['Y'] = HANDLER_NORM(stats_class
, false, NULL
),
188 ['z'] = HANDLER_NORM(stats_memory
, false, "oper:general"),
189 ['?'] = HANDLER_NORM(stats_servlinks
, false, NULL
),
194 * Modified heavily by Elizafox
195 * parv[1] = stat letter/command
196 * parv[2] = (if present) server/mask in stats L, or target
198 * This will search the tables for the appropriate stats letter,
199 * if found execute it.
202 m_stats(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
204 static time_t last_used
= 0;
205 struct stats_cmd
*cmd
;
206 unsigned char statchar
;
209 statchar
= parv
[1][0];
211 if(MyClient(source_p
) && !IsOperGeneral(source_p
) && parc
> 2)
213 /* Check the user is actually allowed to do /stats, and isnt flooding */
214 if((last_used
+ ConfigFileEntry
.pace_wait
) > rb_current_time())
216 /* safe enough to give this on a local connect only */
217 sendto_one(source_p
, form_str(RPL_LOAD2HI
),
218 me
.name
, source_p
->name
, "STATS");
219 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
220 form_str(RPL_ENDOFSTATS
), statchar
);
224 last_used
= rb_current_time();
227 if(hunt_server(client_p
, source_p
, ":%s STATS %s :%s", 2, parc
, parv
) != HUNTED_ISME
)
230 if(tolower(statchar
) != 'l')
232 did_stats
= stats_spy(source_p
, statchar
, NULL
);
234 /* if did_stats is true, a module grabbed this STATS request */
239 cmd
= &stats_cmd_table
[statchar
];
240 if(cmd
->handler
!= NULL
)
242 /* The stats table says what privs are needed, so check --fl_ */
243 const char *missing_priv
= NULL
;
244 if(cmd
->need_admin
&& !IsOperAdmin(source_p
))
245 missing_priv
= "admin";
246 else if(cmd
->need_priv
&& !HasPrivilege(source_p
, cmd
->need_priv
))
247 missing_priv
= cmd
->need_priv
;
249 if(missing_priv
!= NULL
)
251 if(!IsOper(source_p
))
253 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
254 form_str(ERR_NOPRIVILEGES
));
258 if(!strncmp(missing_priv
, "oper:", 5))
260 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
261 me
.name
, source_p
->name
, missing_priv
);
267 cmd
->handler_parv(source_p
, parc
, parv
);
269 cmd
->handler(source_p
);
273 /* Send the end of stats notice, and the stats_spy */
274 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
275 form_str(RPL_ENDOFSTATS
), statchar
);
279 stats_dns_servers (struct Client
*source_p
)
283 RB_DLINK_FOREACH(n
, nameservers
.head
)
285 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "A :%s", (char *)n
->data
);
290 stats_delay(struct Client
*source_p
)
293 rb_dictionary_iter iter
;
295 RB_DICTIONARY_FOREACH(nd
, &iter
, nd_dict
)
297 sendto_one_notice(source_p
, ":Delaying: %s for %ld",
298 nd
->name
, (long) nd
->expire
);
303 stats_hash_cb(const char *buf
, void *client_p
)
305 sendto_one_numeric(client_p
, RPL_STATSDEBUG
, "B :%s", buf
);
309 stats_hash(struct Client
*source_p
)
311 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "B :%-30s %-15s %-10s %-10s %-10s %-10s",
312 "NAME", "TYPE", "OBJECTS", "DEPTH SUM", "AVG DEPTH", "MAX DEPTH");
314 rb_dictionary_stats_walk(stats_hash_cb
, source_p
);
315 rb_radixtree_stats_walk(stats_hash_cb
, source_p
);
319 stats_connect(struct Client
*source_p
)
321 static char buf
[BUFSIZE
];
322 struct server_conf
*server_p
;
326 if((ConfigFileEntry
.stats_c_oper_only
||
327 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
328 !IsOperGeneral(source_p
))
330 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
331 form_str(ERR_NOPRIVILEGES
));
335 RB_DLINK_FOREACH(ptr
, server_conf_list
.head
)
337 server_p
= ptr
->data
;
339 if(ServerConfIllegal(server_p
))
344 if(IsOperGeneral(source_p
))
346 if(ServerConfAutoconn(server_p
))
348 if(ServerConfSCTP(server_p
))
350 if(ServerConfSSL(server_p
))
352 if(ServerConfTb(server_p
))
354 if(ServerConfCompressed(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
;
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
);
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
;
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
);
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
);
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
)
941 if(getrusage(RUSAGE_SELF
, &rus
) == -1)
943 sendto_one_notice(source_p
, ":Getruseage error: %s.",
947 secs
= rus
.ru_utime
.tv_sec
+ rus
.ru_stime
.tv_sec
;
951 rup
= (rb_current_time() - startup_time
) * hzz
;
955 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
956 "R :CPU Secs %d:%02d User %d:%02d System %d:%02d",
957 (int) (secs
/ 60), (int) (secs
% 60),
958 (int) (rus
.ru_utime
.tv_sec
/ 60),
959 (int) (rus
.ru_utime
.tv_sec
% 60),
960 (int) (rus
.ru_stime
.tv_sec
/ 60),
961 (int) (rus
.ru_stime
.tv_sec
% 60));
962 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
963 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
964 rus
.ru_maxrss
, (rus
.ru_ixrss
/ rup
),
965 (rus
.ru_idrss
/ rup
), (rus
.ru_isrss
/ rup
));
966 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
967 "R :Swaps %d Reclaims %d Faults %d",
968 (int) rus
.ru_nswap
, (int) rus
.ru_minflt
, (int) rus
.ru_majflt
);
969 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
970 "R :Block in %d out %d",
971 (int) rus
.ru_inblock
, (int) rus
.ru_oublock
);
972 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
973 "R :Msg Rcv %d Send %d",
974 (int) rus
.ru_msgrcv
, (int) rus
.ru_msgsnd
);
975 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
976 "R :Signals %d Context Vol. %d Invol %d",
977 (int) rus
.ru_nsignals
, (int) rus
.ru_nvcsw
,
978 (int) rus
.ru_nivcsw
);
983 stats_tstats (struct Client
*source_p
)
985 struct Client
*target_p
;
986 struct ServerStatistics sp
;
989 memcpy(&sp
, &ServerStats
, sizeof(struct ServerStatistics
));
991 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
993 target_p
= ptr
->data
;
995 sp
.is_sbs
+= target_p
->localClient
->sendB
;
996 sp
.is_sbr
+= target_p
->localClient
->receiveB
;
997 sp
.is_sti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
1001 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
1003 target_p
= ptr
->data
;
1005 sp
.is_cbs
+= target_p
->localClient
->sendB
;
1006 sp
.is_cbr
+= target_p
->localClient
->receiveB
;
1007 sp
.is_cti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
1011 RB_DLINK_FOREACH(ptr
, unknown_list
.head
)
1016 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1017 "T :accepts %u refused %u", sp
.is_ac
, sp
.is_ref
);
1018 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1019 "T :rejected %u delaying %lu",
1020 sp
.is_rej
, delay_exit_length());
1021 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1022 "T :throttled refused %u throttle list size %lu", sp
.is_thr
, throttle_size());
1023 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1024 "T :nicks being delayed %lu",
1026 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1027 "T :unknown commands %u prefixes %u",
1028 sp
.is_unco
, sp
.is_unpf
);
1029 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1030 "T :nick collisions %u saves %u unknown closes %u",
1031 sp
.is_kill
, sp
.is_save
, sp
.is_ni
);
1032 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1033 "T :wrong direction %u empty %u",
1034 sp
.is_wrdi
, sp
.is_empt
);
1035 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1036 "T :numerics seen %u", sp
.is_num
);
1037 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1038 "T :tgchange blocked msgs %u restricted addrs %lu",
1039 sp
.is_tgch
, rb_dlink_list_length(&tgchange_list
));
1040 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1041 "T :ratelimit blocked commands %u", sp
.is_rl
);
1042 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1043 "T :auth successes %u fails %u",
1044 sp
.is_asuc
, sp
.is_abad
);
1045 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1046 "T :sasl successes %u fails %u",
1047 sp
.is_ssuc
, sp
.is_sbad
);
1048 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "T :Client Server");
1049 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1050 "T :connected %u %u", sp
.is_cl
, sp
.is_sv
);
1051 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1052 "T :bytes sent %lluK %lluK",
1055 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1056 "T :bytes recv %lluK %lluK",
1059 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1060 "T :time connected %llu %llu",
1061 sp
.is_cti
, sp
.is_sti
);
1065 stats_uptime (struct Client
*source_p
)
1069 now
= rb_current_time() - startup_time
;
1070 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
1071 form_str (RPL_STATSUPTIME
),
1072 (int)(now
/ 86400), (int)((now
/ 3600) % 24),
1073 (int)((now
/ 60) % 60), (int)(now
% 60));
1074 sendto_one_numeric(source_p
, RPL_STATSCONN
,
1075 form_str (RPL_STATSCONN
),
1076 MaxConnectionCount
, MaxClientCount
,
1077 Count
.totalrestartcount
);
1083 * input - client pointer
1085 * side effects - client is shown lists of who connected servers
1088 stats_servers (struct Client
*source_p
)
1090 struct Client
*target_p
;
1093 int days
, hours
, minutes
;
1096 if(ConfigServerHide
.flatten_links
&& !IsOperGeneral(source_p
) &&
1097 !IsExemptShide(source_p
))
1099 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1100 form_str (ERR_NOPRIVILEGES
));
1104 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1106 target_p
= ptr
->data
;
1109 seconds
= rb_current_time() - target_p
->localClient
->firsttime
;
1111 days
= (int) (seconds
/ 86400);
1113 hours
= (int) (seconds
/ 3600);
1115 minutes
= (int) (seconds
/ 60);
1118 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1119 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1120 "Connected: %d day%s, %d:%02d:%02d",
1122 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
1123 (int) (rb_current_time() - target_p
->localClient
->lasttime
),
1124 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1125 days
, (days
== 1) ? "" : "s", hours
, minutes
,
1129 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1130 "V :%d Server(s)", j
);
1134 stats_tgecos(struct Client
*source_p
)
1136 struct ConfItem
*aconf
;
1139 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1144 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1145 form_str(RPL_STATSXLINE
),
1146 'x', aconf
->port
, aconf
->host
,
1152 stats_gecos(struct Client
*source_p
)
1154 struct ConfItem
*aconf
;
1157 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1162 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1163 form_str(RPL_STATSXLINE
),
1164 'X', aconf
->port
, aconf
->host
,
1170 stats_class(struct Client
*source_p
)
1172 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOperGeneral(source_p
))
1173 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1174 form_str (ERR_NOPRIVILEGES
));
1176 report_classes(source_p
);
1180 stats_memory (struct Client
*source_p
)
1182 struct Client
*target_p
;
1183 struct Channel
*chptr
;
1184 rb_dlink_node
*rb_dlink
;
1186 int channel_count
= 0;
1187 int local_client_conf_count
= 0; /* local client conf links */
1188 int users_counted
= 0; /* user structs */
1190 int channel_users
= 0;
1191 int channel_invites
= 0;
1192 int channel_bans
= 0;
1193 int channel_except
= 0;
1194 int channel_invex
= 0;
1195 int channel_quiets
= 0;
1197 int class_count
= 0; /* classes */
1198 int conf_count
= 0; /* conf lines */
1199 int users_invited_count
= 0; /* users invited */
1200 int user_channels
= 0; /* users in channels */
1201 int aways_counted
= 0;
1202 size_t number_servers_cached
; /* number of servers cached by scache */
1204 size_t channel_memory
= 0;
1205 size_t channel_ban_memory
= 0;
1206 size_t channel_except_memory
= 0;
1207 size_t channel_invex_memory
= 0;
1208 size_t channel_quiet_memory
= 0;
1210 size_t away_memory
= 0; /* memory used by aways */
1211 size_t ww
= 0; /* whowas array count */
1212 size_t wwm
= 0; /* whowas array memory used */
1213 size_t conf_memory
= 0; /* memory used by conf lines */
1214 size_t mem_servers_cached
; /* memory used by scache */
1216 size_t linebuf_count
= 0;
1217 size_t linebuf_memory_used
= 0;
1219 size_t total_channel_memory
= 0;
1222 size_t local_client_count
= 0;
1223 size_t local_client_memory_used
= 0;
1225 size_t remote_client_count
= 0;
1226 size_t remote_client_memory_used
= 0;
1228 size_t total_memory
= 0;
1230 whowas_memory_usage(&ww
, &wwm
);
1232 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
1234 target_p
= ptr
->data
;
1235 if(MyConnect(target_p
))
1237 local_client_conf_count
++;
1243 users_invited_count
+= rb_dlink_list_length(&target_p
->user
->invited
);
1244 user_channels
+= rb_dlink_list_length(&target_p
->user
->channel
);
1245 if(target_p
->user
->away
)
1248 away_memory
+= (strlen(target_p
->user
->away
) + 1);
1253 /* Count up all channels, ban lists, except lists, Invex lists */
1254 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
1258 channel_memory
+= (strlen(chptr
->chname
) + sizeof(struct Channel
));
1260 channel_users
+= rb_dlink_list_length(&chptr
->members
);
1261 channel_invites
+= rb_dlink_list_length(&chptr
->invites
);
1263 RB_DLINK_FOREACH(rb_dlink
, chptr
->banlist
.head
)
1267 channel_ban_memory
+= sizeof(rb_dlink_node
) + sizeof(struct Ban
);
1270 RB_DLINK_FOREACH(rb_dlink
, chptr
->exceptlist
.head
)
1274 channel_except_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1277 RB_DLINK_FOREACH(rb_dlink
, chptr
->invexlist
.head
)
1281 channel_invex_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1284 RB_DLINK_FOREACH(rb_dlink
, chptr
->quietlist
.head
)
1288 channel_quiet_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1292 /* count up all classes */
1294 class_count
= rb_dlink_list_length(&class_list
) + 1;
1296 rb_count_rb_linebuf_memory(&linebuf_count
, &linebuf_memory_used
);
1298 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1299 "z :Users %u(%lu) Invites %u(%lu)",
1301 (unsigned long) users_counted
* sizeof(struct User
),
1302 users_invited_count
,
1303 (unsigned long) users_invited_count
* sizeof(rb_dlink_node
));
1305 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1306 "z :User channels %u(%lu) Aways %u(%d)",
1308 (unsigned long) user_channels
* sizeof(rb_dlink_node
),
1309 aways_counted
, (int) away_memory
);
1311 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1312 "z :Attached confs %u(%lu)",
1313 local_client_conf_count
,
1314 (unsigned long) local_client_conf_count
* sizeof(rb_dlink_node
));
1316 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1317 "z :Conflines %u(%d)", conf_count
, (int) conf_memory
);
1319 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1320 "z :Classes %u(%lu)",
1322 (unsigned long) class_count
* sizeof(struct Class
));
1324 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1325 "z :Channels %u(%d)",
1326 channel_count
, (int) channel_memory
);
1328 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1329 "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)",
1330 channel_bans
, (int) channel_ban_memory
,
1331 channel_except
, (int) channel_except_memory
,
1332 channel_invex
, (int) channel_invex_memory
,
1333 channel_quiets
, (int) channel_quiet_memory
);
1335 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1336 "z :Channel members %u(%lu) invite %u(%lu)",
1338 (unsigned long) channel_users
* sizeof(rb_dlink_node
),
1340 (unsigned long) channel_invites
* sizeof(rb_dlink_node
));
1342 total_channel_memory
= channel_memory
+
1343 channel_ban_memory
+
1344 channel_users
* sizeof(rb_dlink_node
) + channel_invites
* sizeof(rb_dlink_node
);
1346 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1347 "z :Whowas array %ld(%ld)",
1348 (long)ww
, (long)wwm
);
1352 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1353 "z :Hash: client %u(%ld) chan %u(%ld)",
1354 U_MAX
, (long)(U_MAX
* sizeof(rb_dlink_list
)),
1355 CH_MAX
, (long)(CH_MAX
* sizeof(rb_dlink_list
)));
1357 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1358 "z :linebuf %ld(%ld)",
1359 (long)linebuf_count
, (long)linebuf_memory_used
);
1361 count_scache(&number_servers_cached
, &mem_servers_cached
);
1363 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1364 "z :scache %ld(%ld)",
1365 (long)number_servers_cached
, (long)mem_servers_cached
);
1367 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1368 "z :hostname hash %d(%ld)",
1369 HOST_MAX
, (long)HOST_MAX
* sizeof(rb_dlink_list
));
1371 total_memory
= totww
+ total_channel_memory
+ conf_memory
+
1372 class_count
* sizeof(struct Class
);
1374 total_memory
+= mem_servers_cached
;
1375 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1376 "z :Total: whowas %d channel %d conf %d",
1377 (int) totww
, (int) total_channel_memory
,
1380 count_local_client_memory(&local_client_count
, &local_client_memory_used
);
1381 total_memory
+= local_client_memory_used
;
1383 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1384 "z :Local client Memory in use: %ld(%ld)",
1385 (long)local_client_count
, (long)local_client_memory_used
);
1388 count_remote_client_memory(&remote_client_count
, &remote_client_memory_used
);
1389 total_memory
+= remote_client_memory_used
;
1391 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1392 "z :Remote client Memory in use: %ld(%ld)",
1393 (long)remote_client_count
,
1394 (long)remote_client_memory_used
);
1398 stats_servlinks (struct Client
*source_p
)
1400 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1401 long uptime
, sendK
, receiveK
;
1402 struct Client
*target_p
;
1407 if(ConfigServerHide
.flatten_links
&& !IsOperGeneral (source_p
) &&
1408 !IsExemptShide(source_p
))
1410 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1411 form_str (ERR_NOPRIVILEGES
));
1415 sendK
= receiveK
= 0;
1417 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1419 target_p
= ptr
->data
;
1422 sendK
+= target_p
->localClient
->sendK
;
1423 receiveK
+= target_p
->localClient
->receiveK
;
1425 sendto_one(source_p
, Sformat
,
1426 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1428 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1429 (int) target_p
->localClient
->sendM
,
1430 (int) target_p
->localClient
->sendK
,
1431 (int) target_p
->localClient
->receiveM
,
1432 (int) target_p
->localClient
->receiveK
,
1433 rb_current_time() - target_p
->localClient
->firsttime
,
1434 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1435 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1436 IsOperGeneral (source_p
) ? show_capabilities (target_p
) : "TS");
1439 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1440 "? :%u total server(s)", j
);
1442 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((sendK
)));
1443 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1444 "? :Sent total : %s %s",
1445 buf
, _GMKs (sendK
));
1446 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((receiveK
)));
1447 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1448 "? :Recv total : %s %s",
1449 buf
, _GMKs (receiveK
));
1451 uptime
= (rb_current_time() - startup_time
);
1452 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1453 _GMKv (me
.localClient
->sendK
),
1454 _GMKs (me
.localClient
->sendK
),
1455 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1456 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server send: %s", buf
);
1457 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1458 _GMKv (me
.localClient
->receiveK
),
1459 _GMKs (me
.localClient
->receiveK
),
1460 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1461 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server recv: %s", buf
);
1465 stats_l_should_show_oper(struct Client
*source_p
, struct Client
*target_p
)
1467 return SeesOper(target_p
, source_p
);
1471 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1476 char statchar
= parv
[1][0];
1478 if (ConfigFileEntry
.stats_l_oper_only
== STATS_L_OPER_ONLY_YES
&& !IsOperGeneral(source_p
))
1480 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
1484 /* this is def targeted at us somehow.. */
1485 if (parc
> 2 && !EmptyString(parv
[2]))
1487 /* directed at us generically? */
1488 if (match(parv
[2], me
.name
) || (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1496 wilds
= strchr(name
, '*') || strchr(name
, '?');
1499 /* must be directed at a specific person thats not us */
1500 if (!doall
&& !wilds
)
1502 struct Client
*target_p
;
1504 if (MyClient(source_p
))
1505 target_p
= find_named_person(name
);
1507 target_p
= find_person(name
);
1509 if (target_p
!= source_p
&& ConfigFileEntry
.stats_l_oper_only
!= STATS_L_OPER_ONLY_NO
1510 && !IsOperGeneral(source_p
))
1512 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
1514 else if (target_p
!= NULL
)
1516 stats_spy(source_p
, statchar
, target_p
->name
);
1517 stats_l_client(source_p
, target_p
, statchar
);
1521 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1522 form_str(ERR_NOSUCHSERVER
),
1535 stats_spy(source_p
, statchar
, name
);
1537 if (ConfigFileEntry
.stats_l_oper_only
!= STATS_L_OPER_ONLY_NO
&& !IsOperGeneral(source_p
))
1539 if (doall
&& MyClient(source_p
))
1540 stats_l_client(source_p
, source_p
, statchar
);
1542 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
1548 /* local opers get everyone */
1549 if(MyOper(source_p
))
1551 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
, NULL
);
1552 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1556 /* they still need themselves if theyre local.. */
1557 if(MyClient(source_p
))
1558 stats_l_client(source_p
, source_p
, statchar
);
1560 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
, stats_l_should_show_oper
);
1563 if (!ConfigServerHide
.flatten_links
|| IsOperGeneral(source_p
) ||
1564 IsExemptShide(source_p
))
1565 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
, NULL
);
1570 /* ok, at this point theyre looking for a specific client whos on
1571 * our server.. but it contains a wildcard. --fl
1573 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1579 stats_l_list(struct Client
*source_p
, const char *name
, bool doall
, bool wilds
,
1580 rb_dlink_list
* list
, char statchar
, bool (*check_fn
)(struct Client
*source_p
, struct Client
*target_p
))
1583 struct Client
*target_p
;
1585 /* send information about connections which match. note, we
1586 * dont need tests for IsInvisible(), because non-opers will
1587 * never get here for normal clients --fl
1589 RB_DLINK_FOREACH(ptr
, list
->head
)
1591 target_p
= ptr
->data
;
1593 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1596 if (check_fn
== NULL
|| check_fn(source_p
, target_p
))
1597 stats_l_client(source_p
, target_p
, statchar
);
1602 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1605 if(IsAnyServer(target_p
))
1607 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1609 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1610 (int) target_p
->localClient
->sendM
,
1611 (int) target_p
->localClient
->sendK
,
1612 (int) target_p
->localClient
->receiveM
,
1613 (int) target_p
->localClient
->receiveK
,
1614 rb_current_time() - target_p
->localClient
->firsttime
,
1615 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1616 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1617 IsOperGeneral(source_p
) ? show_capabilities(target_p
) : "-");
1622 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1623 show_ip(source_p
, target_p
) ?
1624 (IsUpper(statchar
) ?
1625 get_client_name(target_p
, SHOW_IP
) :
1626 get_client_name(target_p
, HIDE_IP
)) :
1627 get_client_name(target_p
, MASK_IP
),
1628 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1629 (int) target_p
->localClient
->sendM
,
1630 (int) target_p
->localClient
->sendK
,
1631 (int) target_p
->localClient
->receiveM
,
1632 (int) target_p
->localClient
->receiveK
,
1633 rb_current_time() - target_p
->localClient
->firsttime
,
1634 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1635 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1641 rb_dump_fd_callback(int fd
, const char *desc
, void *data
)
1643 struct Client
*source_p
= data
;
1644 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "F :fd %-3d desc '%s'", fd
, desc
);
1648 stats_comm(struct Client
*source_p
)
1650 rb_dump_fd(rb_dump_fd_callback
, source_p
);
1656 * inputs - pointer to client doing the /stats
1657 * - char letter they are doing /stats on
1660 * This little helper function reports to opers if configured.
1663 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1667 data
.client
= source_p
;
1669 data
.arg2
= (int) statchar
;
1672 call_hook(doing_stats_hook
, &data
);
1679 * input - pointer to client doing stats
1681 * side effects - call hook doing_stats_p
1684 stats_p_spy (struct Client
*source_p
)
1688 data
.client
= source_p
;
1689 data
.arg1
= data
.arg2
= NULL
;
1691 call_hook(doing_stats_p_hook
, &data
);