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_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 ['i'] = HANDLER_NORM(stats_auth
, false, NULL
),
162 ['I'] = HANDLER_NORM(stats_auth
, false, NULL
),
163 ['k'] = HANDLER_NORM(stats_tklines
, false, NULL
),
164 ['K'] = HANDLER_NORM(stats_klines
, false, NULL
),
165 ['l'] = HANDLER_PARV(stats_ltrace
, false, NULL
),
166 ['L'] = HANDLER_PARV(stats_ltrace
, false, NULL
),
167 ['m'] = HANDLER_NORM(stats_messages
, false, NULL
),
168 ['M'] = HANDLER_NORM(stats_messages
, false, NULL
),
169 ['n'] = HANDLER_NORM(stats_dnsbl
, false, NULL
),
170 ['o'] = HANDLER_NORM(stats_oper
, false, NULL
),
171 ['O'] = HANDLER_NORM(stats_privset
, false, "oper:privs"),
172 ['p'] = HANDLER_NORM(stats_operedup
, false, NULL
),
173 ['P'] = HANDLER_NORM(stats_ports
, false, NULL
),
174 ['q'] = HANDLER_NORM(stats_tresv
, false, "oper:general"),
175 ['Q'] = HANDLER_NORM(stats_resv
, false, "oper:general"),
176 ['r'] = HANDLER_NORM(stats_usage
, false, "oper:general"),
177 ['R'] = HANDLER_NORM(stats_usage
, false, "oper:general"),
178 ['s'] = HANDLER_NORM(stats_secure
, false, "oper:general"),
179 ['S'] = HANDLER_NORM(stats_ssld
, true, NULL
),
180 ['t'] = HANDLER_NORM(stats_tstats
, false, "oper:general"),
181 ['T'] = HANDLER_NORM(stats_tstats
, false, "oper:general"),
182 ['u'] = HANDLER_NORM(stats_uptime
, false, NULL
),
183 ['v'] = HANDLER_NORM(stats_servers
, false, NULL
),
184 ['V'] = HANDLER_NORM(stats_servers
, false, NULL
),
185 ['x'] = HANDLER_NORM(stats_tgecos
, false, "oper:general"),
186 ['X'] = HANDLER_NORM(stats_gecos
, false, "oper:general"),
187 ['y'] = HANDLER_NORM(stats_class
, false, NULL
),
188 ['Y'] = HANDLER_NORM(stats_class
, false, NULL
),
189 ['z'] = HANDLER_NORM(stats_memory
, false, "oper:general"),
190 ['Z'] = HANDLER_NORM(stats_ziplinks
, 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
))
356 if(ServerConfCompressed(server_p
))
365 sendto_one_numeric(source_p
, RPL_STATSCLINE
,
366 form_str(RPL_STATSCLINE
),
369 server_p
->port
, server_p
->class_name
,
370 server_p
->certfp
? server_p
->certfp
: "*");
376 * input - client to report to
378 * side effects - client is given temp dline list.
381 stats_tdeny (struct Client
*source_p
)
383 char *host
, *pass
, *user
, *oper_reason
;
384 struct AddressRec
*arec
;
385 struct ConfItem
*aconf
;
388 for (i
= 0; i
< ATABLE_SIZE
; i
++)
390 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
392 if(arec
->type
== CONF_DLINE
)
396 if(!(aconf
->flags
& CONF_FLAGS_TEMPORARY
))
399 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
401 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
402 form_str (RPL_STATSDLINE
),
404 oper_reason
? "|" : "",
405 oper_reason
? oper_reason
: "");
413 * input - client to report to
415 * side effects - client is given dline list.
418 stats_deny (struct Client
*source_p
)
420 char *host
, *pass
, *user
, *oper_reason
;
421 struct AddressRec
*arec
;
422 struct ConfItem
*aconf
;
425 for (i
= 0; i
< ATABLE_SIZE
; i
++)
427 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
429 if(arec
->type
== CONF_DLINE
)
433 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
436 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
438 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
439 form_str (RPL_STATSDLINE
),
441 oper_reason
? "|" : "",
442 oper_reason
? oper_reason
: "");
451 * input - client to report to
453 * side effects - client is given list of exempt blocks
456 stats_exempt(struct Client
*source_p
)
458 char *name
, *host
, *user
, *classname
;
460 struct AddressRec
*arec
;
461 struct ConfItem
*aconf
;
464 if(ConfigFileEntry
.stats_e_disabled
)
466 sendto_one_numeric(source_p
, ERR_DISABLED
,
467 form_str(ERR_DISABLED
), "STATS e");
471 for (i
= 0; i
< ATABLE_SIZE
; i
++)
473 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
475 if(arec
->type
== CONF_EXEMPTDLINE
)
478 get_printable_conf (aconf
, &name
, &host
, &pass
,
479 &user
, &port
, &classname
);
481 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
482 form_str(RPL_STATSDLINE
),
483 'e', host
, pass
, "", "");
491 stats_events_cb(char *str
, void *ptr
)
493 sendto_one_numeric(ptr
, RPL_STATSDEBUG
, "E :%s", str
);
497 stats_events (struct Client
*source_p
)
499 rb_dump_events(stats_events_cb
, source_p
);
503 stats_prop_klines(struct Client
*source_p
)
505 struct ConfItem
*aconf
;
507 char *user
, *host
, *pass
, *oper_reason
;
509 RB_DLINK_FOREACH(ptr
, prop_bans
.head
)
513 /* Skip non-klines and deactivated klines. */
514 if(aconf
->status
!= CONF_KILL
)
517 get_printable_kline(source_p
, aconf
, &host
, &pass
,
518 &user
, &oper_reason
);
520 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
521 form_str(RPL_STATSKLINE
),
522 'g', host
, user
, pass
,
523 oper_reason
? "|" : "",
524 oper_reason
? oper_reason
: "");
529 stats_auth (struct Client
*source_p
)
531 /* Oper only, if unopered, return ERR_NOPRIVS */
532 if((ConfigFileEntry
.stats_i_oper_only
== 2) && !IsOperGeneral (source_p
))
533 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
534 form_str (ERR_NOPRIVILEGES
));
536 /* If unopered, Only return matching auth blocks */
537 else if((ConfigFileEntry
.stats_i_oper_only
== 1) && !IsOperGeneral (source_p
))
539 struct ConfItem
*aconf
;
540 char *name
, *host
, *user
, *classname
;
541 const char *pass
= "*";
544 if(MyConnect (source_p
))
545 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
546 (struct sockaddr
*)&source_p
->localClient
->ip
,
548 GET_SS_FAMILY(&source_p
->localClient
->ip
),
549 source_p
->username
, NULL
);
551 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_CLIENT
,
552 0, source_p
->username
, NULL
);
557 get_printable_conf (aconf
, &name
, &host
, &pass
, &user
, &port
, &classname
);
558 if(!EmptyString(aconf
->spasswd
))
559 pass
= aconf
->spasswd
;
561 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
562 name
, pass
, show_iline_prefix(source_p
, aconf
, user
),
563 host
, port
, classname
);
566 /* Theyre opered, or allowed to see all auth blocks */
568 report_auth (source_p
);
573 stats_tklines(struct Client
*source_p
)
575 /* Oper only, if unopered, return ERR_NOPRIVS */
576 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOperGeneral (source_p
))
577 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
578 form_str (ERR_NOPRIVILEGES
));
580 /* If unopered, Only return matching klines */
581 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOperGeneral (source_p
))
583 struct ConfItem
*aconf
;
584 char *host
, *pass
, *user
, *oper_reason
;
586 if(MyConnect (source_p
))
587 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
588 (struct sockaddr
*)&source_p
->localClient
->ip
,
590 GET_SS_FAMILY(&source_p
->localClient
->ip
),
591 source_p
->username
, NULL
);
593 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
594 0, source_p
->username
, NULL
);
599 /* dont report a permanent kline as a tkline */
600 if((aconf
->flags
& CONF_FLAGS_TEMPORARY
) == 0)
603 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
605 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
606 form_str(RPL_STATSKLINE
), (aconf
->flags
& CONF_FLAGS_TEMPORARY
) ? 'k' : 'K',
607 host
, user
, pass
, oper_reason
? "|" : "",
608 oper_reason
? oper_reason
: "");
610 /* Theyre opered, or allowed to see all klines */
613 struct ConfItem
*aconf
;
616 char *user
, *host
, *pass
, *oper_reason
;
618 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
620 RB_DLINK_FOREACH(ptr
, temp_klines
[i
].head
)
624 get_printable_kline(source_p
, aconf
, &host
, &pass
,
625 &user
, &oper_reason
);
627 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
628 form_str(RPL_STATSKLINE
),
629 'k', host
, user
, pass
,
630 oper_reason
? "|" : "",
631 oper_reason
? oper_reason
: "");
639 * inputs - Client to report to, mask
641 * side effects - Reports configured K-lines to client_p.
644 report_Klines(struct Client
*source_p
)
646 char *host
, *pass
, *user
, *oper_reason
;
647 struct AddressRec
*arec
;
648 struct ConfItem
*aconf
= NULL
;
651 for (i
= 0; i
< ATABLE_SIZE
; i
++)
653 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
655 if(arec
->type
== CONF_KILL
)
659 /* its a tempkline, theyre reported elsewhere */
660 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
663 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
664 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
665 form_str(RPL_STATSKLINE
),
666 'K', host
, user
, pass
,
667 oper_reason
? "|" : "",
668 oper_reason
? oper_reason
: "");
675 stats_klines(struct Client
*source_p
)
677 /* Oper only, if unopered, return ERR_NOPRIVS */
678 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOperGeneral (source_p
))
679 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
680 form_str (ERR_NOPRIVILEGES
));
682 /* If unopered, Only return matching klines */
683 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOperGeneral (source_p
))
685 struct ConfItem
*aconf
;
686 char *host
, *pass
, *user
, *oper_reason
;
688 /* search for a kline */
689 if(MyConnect (source_p
))
690 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
691 (struct sockaddr
*)&source_p
->localClient
->ip
,
693 GET_SS_FAMILY(&source_p
->localClient
->ip
),
694 source_p
->username
, NULL
);
696 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
697 0, source_p
->username
, NULL
);
702 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
704 sendto_one_numeric(source_p
, RPL_STATSKLINE
, form_str(RPL_STATSKLINE
),
705 (aconf
->flags
& CONF_FLAGS_TEMPORARY
) ? 'k' : 'K',
706 host
, user
, pass
, oper_reason
? "|" : "",
707 oper_reason
? oper_reason
: "");
709 /* Theyre opered, or allowed to see all klines */
711 report_Klines (source_p
);
715 stats_messages(struct Client
*source_p
)
717 rb_dictionary_iter iter
;
720 RB_DICTIONARY_FOREACH(msg
, &iter
, cmd_dict
)
722 s_assert(msg
->cmd
!= NULL
);
723 sendto_one_numeric(source_p
, RPL_STATSCOMMANDS
,
724 form_str(RPL_STATSCOMMANDS
),
725 msg
->cmd
, msg
->count
,
726 msg
->bytes
, msg
->rcount
);
731 stats_dnsbl(struct Client
*source_p
)
733 rb_dictionary_iter iter
;
734 struct DNSBLEntryStats
*stats
;
736 if(dnsbl_stats
== NULL
)
739 RB_DICTIONARY_FOREACH(stats
, &iter
, dnsbl_stats
)
741 /* use RPL_STATSDEBUG for now -- jilles */
742 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "n :%d %s",
743 stats
->hits
, (const char *)iter
.cur
->key
);
748 stats_oper(struct Client
*source_p
)
750 struct oper_conf
*oper_p
;
753 if(!IsOperGeneral(source_p
) && ConfigFileEntry
.stats_o_oper_only
)
755 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
756 form_str (ERR_NOPRIVILEGES
));
760 RB_DLINK_FOREACH(ptr
, oper_conf_list
.head
)
764 sendto_one_numeric(source_p
, RPL_STATSOLINE
,
765 form_str(RPL_STATSOLINE
),
766 oper_p
->username
, oper_p
->host
, oper_p
->name
,
767 HasPrivilege(source_p
, "oper:privs") ? oper_p
->privset
->name
: "0", "-1");
772 stats_capability_walk(const char *line
, void *data
)
774 struct Client
*client_p
= data
;
776 sendto_one_numeric(client_p
, RPL_STATSDEBUG
, "C :%s", line
);
780 stats_capability(struct Client
*client_p
)
782 capability_index_stats(stats_capability_walk
, client_p
);
786 stats_privset(struct Client
*source_p
)
788 privilegeset_report(source_p
);
793 * input - client pointer
795 * side effects - client is shown a list of active opers
798 stats_operedup (struct Client
*source_p
)
800 struct Client
*target_p
;
801 rb_dlink_node
*oper_ptr
;
802 unsigned int count
= 0;
804 RB_DLINK_FOREACH (oper_ptr
, oper_list
.head
)
806 target_p
= oper_ptr
->data
;
808 if(!SeesOper(target_p
, source_p
))
811 if(target_p
->user
->away
)
816 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
818 target_p
->name
, target_p
->username
,
822 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
823 "p :%u staff members", count
);
825 stats_p_spy (source_p
);
829 stats_ports (struct Client
*source_p
)
831 if(!IsOperGeneral (source_p
) && ConfigFileEntry
.stats_P_oper_only
)
832 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
833 form_str (ERR_NOPRIVILEGES
));
835 show_ports (source_p
);
839 stats_tresv(struct Client
*source_p
)
841 struct ConfItem
*aconf
;
842 rb_radixtree_iteration_state state
;
845 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
849 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
850 form_str(RPL_STATSQLINE
),
851 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
854 RB_RADIXTREE_FOREACH(aconf
, &state
, resv_tree
)
857 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
858 form_str(RPL_STATSQLINE
),
859 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
865 stats_resv(struct Client
*source_p
)
867 struct ConfItem
*aconf
;
868 rb_radixtree_iteration_state state
;
871 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
875 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
876 form_str(RPL_STATSQLINE
),
877 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
880 RB_RADIXTREE_FOREACH(aconf
, &state
, resv_tree
)
883 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
884 form_str(RPL_STATSQLINE
),
885 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
890 stats_secure(struct Client
*source_p
)
892 struct AddressRec
*arec
;
893 struct ConfItem
*aconf
;
896 for (i
= 0; i
< ATABLE_SIZE
; i
++)
898 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
900 if(arec
->type
== CONF_SECURE
)
903 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "s :%s", aconf
->host
);
910 stats_ssld_foreach(void *data
, pid_t pid
, int cli_count
, enum ssld_status status
, const char *version
)
912 struct Client
*source_p
= data
;
914 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
917 status
== SSLD_DEAD
? 'D' : (status
== SSLD_SHUTDOWN
? 'S' : 'A'),
923 stats_ssld(struct Client
*source_p
)
925 ssld_foreach_info(stats_ssld_foreach
, source_p
);
929 stats_usage (struct Client
*source_p
)
945 if(getrusage(RUSAGE_SELF
, &rus
) == -1)
947 sendto_one_notice(source_p
, ":Getruseage error: %s.",
951 secs
= rus
.ru_utime
.tv_sec
+ rus
.ru_stime
.tv_sec
;
955 rup
= (rb_current_time() - startup_time
) * hzz
;
959 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
960 "R :CPU Secs %d:%02d User %d:%02d System %d:%02d",
961 (int) (secs
/ 60), (int) (secs
% 60),
962 (int) (rus
.ru_utime
.tv_sec
/ 60),
963 (int) (rus
.ru_utime
.tv_sec
% 60),
964 (int) (rus
.ru_stime
.tv_sec
/ 60),
965 (int) (rus
.ru_stime
.tv_sec
% 60));
966 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
967 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
968 rus
.ru_maxrss
, (rus
.ru_ixrss
/ rup
),
969 (rus
.ru_idrss
/ rup
), (rus
.ru_isrss
/ rup
));
970 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
971 "R :Swaps %d Reclaims %d Faults %d",
972 (int) rus
.ru_nswap
, (int) rus
.ru_minflt
, (int) rus
.ru_majflt
);
973 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
974 "R :Block in %d out %d",
975 (int) rus
.ru_inblock
, (int) rus
.ru_oublock
);
976 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
977 "R :Msg Rcv %d Send %d",
978 (int) rus
.ru_msgrcv
, (int) rus
.ru_msgsnd
);
979 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
980 "R :Signals %d Context Vol. %d Invol %d",
981 (int) rus
.ru_nsignals
, (int) rus
.ru_nvcsw
,
982 (int) rus
.ru_nivcsw
);
987 stats_tstats (struct Client
*source_p
)
989 struct Client
*target_p
;
990 struct ServerStatistics sp
;
993 memcpy(&sp
, &ServerStats
, sizeof(struct ServerStatistics
));
995 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
997 target_p
= ptr
->data
;
999 sp
.is_sbs
+= target_p
->localClient
->sendB
;
1000 sp
.is_sbr
+= target_p
->localClient
->receiveB
;
1001 sp
.is_sti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
1005 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
1007 target_p
= ptr
->data
;
1009 sp
.is_cbs
+= target_p
->localClient
->sendB
;
1010 sp
.is_cbr
+= target_p
->localClient
->receiveB
;
1011 sp
.is_cti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
1015 RB_DLINK_FOREACH(ptr
, unknown_list
.head
)
1020 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1021 "T :accepts %u refused %u", sp
.is_ac
, sp
.is_ref
);
1022 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1023 "T :rejected %u delaying %lu",
1024 sp
.is_rej
, delay_exit_length());
1025 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1026 "T :throttled refused %u throttle list size %lu", sp
.is_thr
, throttle_size());
1027 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1028 "T :nicks being delayed %lu",
1030 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1031 "T :unknown commands %u prefixes %u",
1032 sp
.is_unco
, sp
.is_unpf
);
1033 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1034 "T :nick collisions %u saves %u unknown closes %u",
1035 sp
.is_kill
, sp
.is_save
, sp
.is_ni
);
1036 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1037 "T :wrong direction %u empty %u",
1038 sp
.is_wrdi
, sp
.is_empt
);
1039 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1040 "T :numerics seen %u", sp
.is_num
);
1041 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1042 "T :tgchange blocked msgs %u restricted addrs %lu",
1043 sp
.is_tgch
, rb_dlink_list_length(&tgchange_list
));
1044 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1045 "T :ratelimit blocked commands %u", sp
.is_rl
);
1046 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1047 "T :auth successes %u fails %u",
1048 sp
.is_asuc
, sp
.is_abad
);
1049 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1050 "T :sasl successes %u fails %u",
1051 sp
.is_ssuc
, sp
.is_sbad
);
1052 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "T :Client Server");
1053 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1054 "T :connected %u %u", sp
.is_cl
, sp
.is_sv
);
1055 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1056 "T :bytes sent %lluK %lluK",
1059 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1060 "T :bytes recv %lluK %lluK",
1063 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1064 "T :time connected %llu %llu",
1065 sp
.is_cti
, sp
.is_sti
);
1069 stats_uptime (struct Client
*source_p
)
1073 now
= rb_current_time() - startup_time
;
1074 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
1075 form_str (RPL_STATSUPTIME
),
1076 (int)(now
/ 86400), (int)((now
/ 3600) % 24),
1077 (int)((now
/ 60) % 60), (int)(now
% 60));
1078 sendto_one_numeric(source_p
, RPL_STATSCONN
,
1079 form_str (RPL_STATSCONN
),
1080 MaxConnectionCount
, MaxClientCount
,
1081 Count
.totalrestartcount
);
1087 * input - client pointer
1089 * side effects - client is shown lists of who connected servers
1092 stats_servers (struct Client
*source_p
)
1094 struct Client
*target_p
;
1097 int days
, hours
, minutes
;
1100 if(ConfigServerHide
.flatten_links
&& !IsOperGeneral(source_p
) &&
1101 !IsExemptShide(source_p
))
1103 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1104 form_str (ERR_NOPRIVILEGES
));
1108 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1110 target_p
= ptr
->data
;
1113 seconds
= rb_current_time() - target_p
->localClient
->firsttime
;
1115 days
= (int) (seconds
/ 86400);
1117 hours
= (int) (seconds
/ 3600);
1119 minutes
= (int) (seconds
/ 60);
1122 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1123 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1124 "Connected: %d day%s, %d:%02d:%02d",
1126 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
1127 (int) (rb_current_time() - target_p
->localClient
->lasttime
),
1128 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1129 days
, (days
== 1) ? "" : "s", hours
, minutes
,
1133 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1134 "V :%d Server(s)", j
);
1138 stats_tgecos(struct Client
*source_p
)
1140 struct ConfItem
*aconf
;
1143 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1148 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1149 form_str(RPL_STATSXLINE
),
1150 'x', aconf
->port
, aconf
->host
,
1156 stats_gecos(struct Client
*source_p
)
1158 struct ConfItem
*aconf
;
1161 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1166 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1167 form_str(RPL_STATSXLINE
),
1168 'X', aconf
->port
, aconf
->host
,
1174 stats_class(struct Client
*source_p
)
1176 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOperGeneral(source_p
))
1177 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1178 form_str (ERR_NOPRIVILEGES
));
1180 report_classes(source_p
);
1184 stats_memory (struct Client
*source_p
)
1186 struct Client
*target_p
;
1187 struct Channel
*chptr
;
1188 rb_dlink_node
*rb_dlink
;
1190 int channel_count
= 0;
1191 int local_client_conf_count
= 0; /* local client conf links */
1192 int users_counted
= 0; /* user structs */
1194 int channel_users
= 0;
1195 int channel_invites
= 0;
1196 int channel_bans
= 0;
1197 int channel_except
= 0;
1198 int channel_invex
= 0;
1199 int channel_quiets
= 0;
1201 int class_count
= 0; /* classes */
1202 int conf_count
= 0; /* conf lines */
1203 int users_invited_count
= 0; /* users invited */
1204 int user_channels
= 0; /* users in channels */
1205 int aways_counted
= 0;
1206 size_t number_servers_cached
; /* number of servers cached by scache */
1208 size_t channel_memory
= 0;
1209 size_t channel_ban_memory
= 0;
1210 size_t channel_except_memory
= 0;
1211 size_t channel_invex_memory
= 0;
1212 size_t channel_quiet_memory
= 0;
1214 size_t away_memory
= 0; /* memory used by aways */
1215 size_t ww
= 0; /* whowas array count */
1216 size_t wwm
= 0; /* whowas array memory used */
1217 size_t conf_memory
= 0; /* memory used by conf lines */
1218 size_t mem_servers_cached
; /* memory used by scache */
1220 size_t linebuf_count
= 0;
1221 size_t linebuf_memory_used
= 0;
1223 size_t total_channel_memory
= 0;
1226 size_t local_client_count
= 0;
1227 size_t local_client_memory_used
= 0;
1229 size_t remote_client_count
= 0;
1230 size_t remote_client_memory_used
= 0;
1232 size_t total_memory
= 0;
1234 whowas_memory_usage(&ww
, &wwm
);
1236 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
1238 target_p
= ptr
->data
;
1239 if(MyConnect(target_p
))
1241 local_client_conf_count
++;
1247 users_invited_count
+= rb_dlink_list_length(&target_p
->user
->invited
);
1248 user_channels
+= rb_dlink_list_length(&target_p
->user
->channel
);
1249 if(target_p
->user
->away
)
1252 away_memory
+= (strlen(target_p
->user
->away
) + 1);
1257 /* Count up all channels, ban lists, except lists, Invex lists */
1258 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
1262 channel_memory
+= (strlen(chptr
->chname
) + sizeof(struct Channel
));
1264 channel_users
+= rb_dlink_list_length(&chptr
->members
);
1265 channel_invites
+= rb_dlink_list_length(&chptr
->invites
);
1267 RB_DLINK_FOREACH(rb_dlink
, chptr
->banlist
.head
)
1271 channel_ban_memory
+= sizeof(rb_dlink_node
) + sizeof(struct Ban
);
1274 RB_DLINK_FOREACH(rb_dlink
, chptr
->exceptlist
.head
)
1278 channel_except_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1281 RB_DLINK_FOREACH(rb_dlink
, chptr
->invexlist
.head
)
1285 channel_invex_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1288 RB_DLINK_FOREACH(rb_dlink
, chptr
->quietlist
.head
)
1292 channel_quiet_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1296 /* count up all classes */
1298 class_count
= rb_dlink_list_length(&class_list
) + 1;
1300 rb_count_rb_linebuf_memory(&linebuf_count
, &linebuf_memory_used
);
1302 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1303 "z :Users %u(%lu) Invites %u(%lu)",
1305 (unsigned long) users_counted
* sizeof(struct User
),
1306 users_invited_count
,
1307 (unsigned long) users_invited_count
* sizeof(rb_dlink_node
));
1309 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1310 "z :User channels %u(%lu) Aways %u(%d)",
1312 (unsigned long) user_channels
* sizeof(rb_dlink_node
),
1313 aways_counted
, (int) away_memory
);
1315 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1316 "z :Attached confs %u(%lu)",
1317 local_client_conf_count
,
1318 (unsigned long) local_client_conf_count
* sizeof(rb_dlink_node
));
1320 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1321 "z :Conflines %u(%d)", conf_count
, (int) conf_memory
);
1323 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1324 "z :Classes %u(%lu)",
1326 (unsigned long) class_count
* sizeof(struct Class
));
1328 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1329 "z :Channels %u(%d)",
1330 channel_count
, (int) channel_memory
);
1332 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1333 "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)",
1334 channel_bans
, (int) channel_ban_memory
,
1335 channel_except
, (int) channel_except_memory
,
1336 channel_invex
, (int) channel_invex_memory
,
1337 channel_quiets
, (int) channel_quiet_memory
);
1339 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1340 "z :Channel members %u(%lu) invite %u(%lu)",
1342 (unsigned long) channel_users
* sizeof(rb_dlink_node
),
1344 (unsigned long) channel_invites
* sizeof(rb_dlink_node
));
1346 total_channel_memory
= channel_memory
+
1347 channel_ban_memory
+
1348 channel_users
* sizeof(rb_dlink_node
) + channel_invites
* sizeof(rb_dlink_node
);
1350 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1351 "z :Whowas array %ld(%ld)",
1352 (long)ww
, (long)wwm
);
1356 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1357 "z :Hash: client %u(%ld) chan %u(%ld)",
1358 U_MAX
, (long)(U_MAX
* sizeof(rb_dlink_list
)),
1359 CH_MAX
, (long)(CH_MAX
* sizeof(rb_dlink_list
)));
1361 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1362 "z :linebuf %ld(%ld)",
1363 (long)linebuf_count
, (long)linebuf_memory_used
);
1365 count_scache(&number_servers_cached
, &mem_servers_cached
);
1367 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1368 "z :scache %ld(%ld)",
1369 (long)number_servers_cached
, (long)mem_servers_cached
);
1371 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1372 "z :hostname hash %d(%ld)",
1373 HOST_MAX
, (long)HOST_MAX
* sizeof(rb_dlink_list
));
1375 total_memory
= totww
+ total_channel_memory
+ conf_memory
+
1376 class_count
* sizeof(struct Class
);
1378 total_memory
+= mem_servers_cached
;
1379 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1380 "z :Total: whowas %d channel %d conf %d",
1381 (int) totww
, (int) total_channel_memory
,
1384 count_local_client_memory(&local_client_count
, &local_client_memory_used
);
1385 total_memory
+= local_client_memory_used
;
1387 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1388 "z :Local client Memory in use: %ld(%ld)",
1389 (long)local_client_count
, (long)local_client_memory_used
);
1392 count_remote_client_memory(&remote_client_count
, &remote_client_memory_used
);
1393 total_memory
+= remote_client_memory_used
;
1395 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1396 "z :Remote client Memory in use: %ld(%ld)",
1397 (long)remote_client_count
,
1398 (long)remote_client_memory_used
);
1402 stats_ziplinks (struct Client
*source_p
)
1405 struct Client
*target_p
;
1406 struct ZipStats
*zipstats
;
1408 char buf
[128], buf1
[128];
1409 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1411 target_p
= ptr
->data
;
1412 if(IsCapable (target_p
, CAP_ZIP
))
1414 zipstats
= target_p
->localClient
->zipstats
;
1415 sprintf(buf
, "%.2f%%", zipstats
->out_ratio
);
1416 sprintf(buf1
, "%.2f%%", zipstats
->in_ratio
);
1417 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1418 "Z :ZipLinks stats for %s send[%s compression "
1419 "(%llu kB data/%llu kB wire)] recv[%s compression "
1420 "(%llu kB data/%llu kB wire)]",
1422 buf
, zipstats
->out
>> 10,
1423 zipstats
->out_wire
>> 10, buf1
,
1424 zipstats
->in
>> 10, zipstats
->in_wire
>> 10);
1429 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1430 "Z :%u ziplink(s)", sent_data
);
1434 stats_servlinks (struct Client
*source_p
)
1436 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1437 long uptime
, sendK
, receiveK
;
1438 struct Client
*target_p
;
1443 if(ConfigServerHide
.flatten_links
&& !IsOperGeneral (source_p
) &&
1444 !IsExemptShide(source_p
))
1446 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1447 form_str (ERR_NOPRIVILEGES
));
1451 sendK
= receiveK
= 0;
1453 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1455 target_p
= ptr
->data
;
1458 sendK
+= target_p
->localClient
->sendK
;
1459 receiveK
+= target_p
->localClient
->receiveK
;
1461 sendto_one(source_p
, Sformat
,
1462 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1464 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1465 (int) target_p
->localClient
->sendM
,
1466 (int) target_p
->localClient
->sendK
,
1467 (int) target_p
->localClient
->receiveM
,
1468 (int) target_p
->localClient
->receiveK
,
1469 rb_current_time() - target_p
->localClient
->firsttime
,
1470 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1471 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1472 IsOperGeneral (source_p
) ? show_capabilities (target_p
) : "TS");
1475 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1476 "? :%u total server(s)", j
);
1478 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((sendK
)));
1479 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1480 "? :Sent total : %s %s",
1481 buf
, _GMKs (sendK
));
1482 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((receiveK
)));
1483 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1484 "? :Recv total : %s %s",
1485 buf
, _GMKs (receiveK
));
1487 uptime
= (rb_current_time() - startup_time
);
1488 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1489 _GMKv (me
.localClient
->sendK
),
1490 _GMKs (me
.localClient
->sendK
),
1491 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1492 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server send: %s", buf
);
1493 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1494 _GMKv (me
.localClient
->receiveK
),
1495 _GMKs (me
.localClient
->receiveK
),
1496 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1497 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server recv: %s", buf
);
1501 stats_l_should_show_oper(struct Client
*source_p
, struct Client
*target_p
)
1503 return SeesOper(target_p
, source_p
);
1507 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1512 char statchar
= parv
[1][0];
1514 if (ConfigFileEntry
.stats_l_oper_only
== STATS_L_OPER_ONLY_YES
&& !IsOperGeneral(source_p
))
1516 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
1520 /* this is def targeted at us somehow.. */
1521 if (parc
> 2 && !EmptyString(parv
[2]))
1523 /* directed at us generically? */
1524 if (match(parv
[2], me
.name
) || (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1532 wilds
= strchr(name
, '*') || strchr(name
, '?');
1535 /* must be directed at a specific person thats not us */
1536 if (!doall
&& !wilds
)
1538 struct Client
*target_p
;
1540 if (MyClient(source_p
))
1541 target_p
= find_named_person(name
);
1543 target_p
= find_person(name
);
1545 if (target_p
!= source_p
&& ConfigFileEntry
.stats_l_oper_only
!= STATS_L_OPER_ONLY_NO
1546 && !IsOperGeneral(source_p
))
1548 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
1550 else if (target_p
!= NULL
)
1552 stats_spy(source_p
, statchar
, target_p
->name
);
1553 stats_l_client(source_p
, target_p
, statchar
);
1557 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1558 form_str(ERR_NOSUCHSERVER
),
1571 stats_spy(source_p
, statchar
, name
);
1573 if (ConfigFileEntry
.stats_l_oper_only
!= STATS_L_OPER_ONLY_NO
&& !IsOperGeneral(source_p
))
1575 if (doall
&& MyClient(source_p
))
1576 stats_l_client(source_p
, source_p
, statchar
);
1578 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
1584 /* local opers get everyone */
1585 if(MyOper(source_p
))
1587 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
, NULL
);
1588 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1592 /* they still need themselves if theyre local.. */
1593 if(MyClient(source_p
))
1594 stats_l_client(source_p
, source_p
, statchar
);
1596 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
, stats_l_should_show_oper
);
1599 if (!ConfigServerHide
.flatten_links
|| IsOperGeneral(source_p
) ||
1600 IsExemptShide(source_p
))
1601 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
, NULL
);
1606 /* ok, at this point theyre looking for a specific client whos on
1607 * our server.. but it contains a wildcard. --fl
1609 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1615 stats_l_list(struct Client
*source_p
, const char *name
, bool doall
, bool wilds
,
1616 rb_dlink_list
* list
, char statchar
, bool (*check_fn
)(struct Client
*source_p
, struct Client
*target_p
))
1619 struct Client
*target_p
;
1621 /* send information about connections which match. note, we
1622 * dont need tests for IsInvisible(), because non-opers will
1623 * never get here for normal clients --fl
1625 RB_DLINK_FOREACH(ptr
, list
->head
)
1627 target_p
= ptr
->data
;
1629 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1632 if (check_fn
== NULL
|| check_fn(source_p
, target_p
))
1633 stats_l_client(source_p
, target_p
, statchar
);
1638 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1641 if(IsAnyServer(target_p
))
1643 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1645 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1646 (int) target_p
->localClient
->sendM
,
1647 (int) target_p
->localClient
->sendK
,
1648 (int) target_p
->localClient
->receiveM
,
1649 (int) target_p
->localClient
->receiveK
,
1650 rb_current_time() - target_p
->localClient
->firsttime
,
1651 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1652 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1653 IsOperGeneral(source_p
) ? show_capabilities(target_p
) : "-");
1658 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1659 show_ip(source_p
, target_p
) ?
1660 (IsUpper(statchar
) ?
1661 get_client_name(target_p
, SHOW_IP
) :
1662 get_client_name(target_p
, HIDE_IP
)) :
1663 get_client_name(target_p
, MASK_IP
),
1664 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1665 (int) target_p
->localClient
->sendM
,
1666 (int) target_p
->localClient
->sendK
,
1667 (int) target_p
->localClient
->receiveM
,
1668 (int) target_p
->localClient
->receiveK
,
1669 rb_current_time() - target_p
->localClient
->firsttime
,
1670 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1671 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1677 rb_dump_fd_callback(int fd
, const char *desc
, void *data
)
1679 struct Client
*source_p
= data
;
1680 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "F :fd %-3d desc '%s'", fd
, desc
);
1684 stats_comm(struct Client
*source_p
)
1686 rb_dump_fd(rb_dump_fd_callback
, source_p
);
1692 * inputs - pointer to client doing the /stats
1693 * - char letter they are doing /stats on
1696 * This little helper function reports to opers if configured.
1699 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1703 data
.client
= source_p
;
1705 data
.arg2
= (int) statchar
;
1708 call_hook(doing_stats_hook
, &data
);
1715 * input - pointer to client doing stats
1717 * side effects - call hook doing_stats_p
1720 stats_p_spy (struct Client
*source_p
)
1724 data
.client
= source_p
;
1725 data
.arg1
= data
.arg2
= NULL
;
1727 call_hook(doing_stats_p_hook
, &data
);