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 */
30 #include "ircd.h" /* me */
31 #include "listener.h" /* show_ports */
32 #include "msg.h" /* Message */
33 #include "hostmask.h" /* report_mtrie_conf_links */
34 #include "numeric.h" /* ERR_xxx */
35 #include "scache.h" /* list_scache */
36 #include "send.h" /* sendto_one */
37 #include "s_conf.h" /* ConfItem */
38 #include "s_serv.h" /* hunt_server */
40 #include "s_user.h" /* show_opers */
41 #include "blacklist.h" /* dnsbl stuff */
45 #include "s_newconf.h"
49 #include "rb_radixtree.h"
52 static const char stats_desc
[] =
53 "Provides the STATS command to inspect various server/network information";
55 static void m_stats (struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
57 struct Message stats_msgtab
= {
58 "STATS", false, false, false, false,
59 {mg_unreg
, {m_stats
, 2}, {m_stats
, 3}, mg_ignore
, mg_ignore
, {m_stats
, 2}}
63 int doing_stats_p_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
},
72 DECLARE_MODULE_AV2(stats
, NULL
, NULL
, stats_clist
, stats_hlist
, NULL
, NULL
, NULL
, stats_desc
);
74 const char *Lformat
= "%s %u %u %u %u %u :%u %u %s";
76 static void stats_l_list(struct Client
*s
, const char *, bool, bool, rb_dlink_list
*, char,
77 bool (*check_fn
)(struct Client
*target_p
));
78 static void stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
81 static int stats_spy(struct Client
*, char, const char *);
82 static void stats_p_spy(struct Client
*);
84 typedef void (*handler_t
)(struct Client
*source_p
);
85 typedef void (*handler_parv_t
)(struct Client
*source_p
, int parc
, const char *parv
[]);
92 handler_parv_t handler_parv
;
99 static void stats_dns_servers(struct Client
*);
100 static void stats_delay(struct Client
*);
101 static void stats_hash(struct Client
*);
102 static void stats_connect(struct Client
*);
103 static void stats_tdeny(struct Client
*);
104 static void stats_deny(struct Client
*);
105 static void stats_exempt(struct Client
*);
106 static void stats_events(struct Client
*);
107 static void stats_prop_klines(struct Client
*);
108 static void stats_hubleaf(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_ssld(struct Client
*);
121 static void stats_usage(struct Client
*);
122 static void stats_tstats(struct Client
*);
123 static void stats_uptime(struct Client
*);
124 static void stats_shared(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_ziplinks(struct Client
*);
133 static void stats_comm(struct Client
*);
134 static void stats_capability(struct Client
*);
136 /* This table contains the possible stats items, in order:
137 * stats letter, function to call, operonly? adminonly? --fl_
139 * Previously in this table letters were a column. I fixed it to use modern
140 * C initalisers so we don't have to iterate anymore
143 static struct stats_cmd stats_cmd_table
[256] = {
144 /* letter handler/handler_parv parv oper admin */
145 ['a'] = { stats_dns_servers
, false, true, true, },
146 ['A'] = { stats_dns_servers
, false, true, true, },
147 ['b'] = { stats_delay
, false, true, true, },
148 ['B'] = { stats_hash
, false, true, true, },
149 ['c'] = { stats_connect
, false, false, false, },
150 ['C'] = { stats_capability
, false, true, false, },
151 ['d'] = { stats_tdeny
, false, true, false, },
152 ['D'] = { stats_deny
, false, true, false, },
153 ['e'] = { stats_exempt
, false, true, false, },
154 ['E'] = { stats_events
, false, true, true, },
155 ['f'] = { stats_comm
, false, true, true, },
156 ['F'] = { stats_comm
, false, true, true, },
157 ['g'] = { stats_prop_klines
, false, true, false, },
158 ['h'] = { stats_hubleaf
, false, false, false, },
159 ['H'] = { stats_hubleaf
, false, false, false, },
160 ['i'] = { stats_auth
, false, false, false, },
161 ['I'] = { stats_auth
, false, false, false, },
162 ['k'] = { stats_tklines
, false, false, false, },
163 ['K'] = { stats_klines
, false, false, false, },
164 ['l'] = { .handler_parv
= stats_ltrace
, true, false, false, },
165 ['L'] = { .handler_parv
= stats_ltrace
, true, false, false, },
166 ['m'] = { stats_messages
, false, false, false, },
167 ['M'] = { stats_messages
, false, false, false, },
168 ['n'] = { stats_dnsbl
, false, false, false, },
169 ['o'] = { stats_oper
, false, false, false, },
170 ['O'] = { stats_privset
, false, true, false, },
171 ['p'] = { stats_operedup
, false, false, false, },
172 ['P'] = { stats_ports
, false, false, false, },
173 ['q'] = { stats_tresv
, false, true, false, },
174 ['Q'] = { stats_resv
, false, true, false, },
175 ['r'] = { stats_usage
, false, true, false, },
176 ['R'] = { stats_usage
, false, true, false, },
177 ['s'] = { stats_ssld
, false, true, true, },
178 ['S'] = { stats_ssld
, false, true, true, },
179 ['t'] = { stats_tstats
, false, true, false, },
180 ['T'] = { stats_tstats
, false, true, false, },
181 ['u'] = { stats_uptime
, false, false, false, },
182 ['U'] = { stats_shared
, false, true, false, },
183 ['v'] = { stats_servers
, false, false, false, },
184 ['V'] = { stats_servers
, false, false, false, },
185 ['x'] = { stats_tgecos
, false, true, false, },
186 ['X'] = { stats_gecos
, false, true, false, },
187 ['y'] = { stats_class
, false, false, false, },
188 ['Y'] = { stats_class
, false, false, false, },
189 ['z'] = { stats_memory
, false, true, false, },
190 ['Z'] = { stats_ziplinks
, false, true, false, },
191 ['?'] = { stats_servlinks
, false, false, false, },
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;
208 struct stats_cmd
*cmd
;
212 statchar
= parv
[1][0];
214 if(MyClient(source_p
) && !IsOper(source_p
))
216 /* Check the user is actually allowed to do /stats, and isnt flooding */
217 if((last_used
+ ConfigFileEntry
.pace_wait
) > rb_current_time())
219 /* safe enough to give this on a local connect only */
220 sendto_one(source_p
, form_str(RPL_LOAD2HI
),
221 me
.name
, source_p
->name
, "STATS");
222 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
223 form_str(RPL_ENDOFSTATS
), statchar
);
227 last_used
= rb_current_time();
230 if(hunt_server (client_p
, source_p
, ":%s STATS %s :%s", 2, parc
, parv
) != HUNTED_ISME
)
233 if(tolower(statchar
) != 'l')
235 did_stats
= stats_spy(source_p
, statchar
, NULL
);
237 /* if did_stats is true, a module grabbed this STATS request */
242 cmd
= &stats_cmd_table
[statchar
];
243 if(cmd
->handler
!= NULL
)
245 /* The stats table says what privs are needed, so check --fl_ */
246 /* Called for remote clients and for local opers, so check need_admin
249 if(cmd
->need_admin
&& !IsOperAdmin(source_p
))
251 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
252 me
.name
, source_p
->name
, "admin");
255 if(cmd
->need_oper
&& !IsOper(source_p
))
257 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
258 form_str (ERR_NOPRIVILEGES
));
263 cmd
->handler_parv(source_p
, parc
, parv
);
265 cmd
->handler(source_p
);
269 /* Send the end of stats notice, and the stats_spy */
270 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
271 form_str(RPL_ENDOFSTATS
), statchar
);
275 stats_dns_servers (struct Client
*source_p
)
279 RB_DLINK_FOREACH(n
, nameservers
.head
)
281 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "A %s", (char *)n
->data
);
286 stats_delay(struct Client
*source_p
)
289 struct DictionaryIter iter
;
291 DICTIONARY_FOREACH(nd
, &iter
, nd_dict
)
293 sendto_one_notice(source_p
, ":Delaying: %s for %ld",
294 nd
->name
, (long) nd
->expire
);
299 stats_hash_cb(const char *buf
, void *client_p
)
301 sendto_one_numeric(client_p
, RPL_STATSDEBUG
, "B :%s", buf
);
305 stats_hash(struct Client
*source_p
)
307 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "B :%-30s %-15s %-10s %-10s %-10s %-10s",
308 "NAME", "TYPE", "OBJECTS", "DEPTH SUM", "AVG DEPTH", "MAX DEPTH");
310 rb_dictionary_stats_walk(stats_hash_cb
, source_p
);
311 rb_radixtree_stats_walk(stats_hash_cb
, source_p
);
315 stats_connect(struct Client
*source_p
)
318 struct server_conf
*server_p
;
322 if((ConfigFileEntry
.stats_c_oper_only
||
323 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
326 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
327 form_str(ERR_NOPRIVILEGES
));
331 RB_DLINK_FOREACH(ptr
, server_conf_list
.head
)
333 server_p
= ptr
->data
;
335 if(ServerConfIllegal(server_p
))
342 if(ServerConfAutoconn(server_p
))
344 if(ServerConfSSL(server_p
))
346 if(ServerConfTb(server_p
))
348 if(ServerConfCompressed(server_p
))
357 sendto_one_numeric(source_p
, RPL_STATSCLINE
,
358 form_str(RPL_STATSCLINE
),
361 server_p
->port
, server_p
->class_name
);
367 * input - client to report to
369 * side effects - client is given temp dline list.
372 stats_tdeny (struct Client
*source_p
)
374 char *host
, *pass
, *user
, *oper_reason
;
375 struct AddressRec
*arec
;
376 struct ConfItem
*aconf
;
379 for (i
= 0; i
< ATABLE_SIZE
; i
++)
381 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
383 if(arec
->type
== CONF_DLINE
)
387 if(!(aconf
->flags
& CONF_FLAGS_TEMPORARY
))
390 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
392 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
393 form_str (RPL_STATSDLINE
),
395 oper_reason
? "|" : "",
396 oper_reason
? oper_reason
: "");
404 * input - client to report to
406 * side effects - client is given dline list.
409 stats_deny (struct Client
*source_p
)
411 char *host
, *pass
, *user
, *oper_reason
;
412 struct AddressRec
*arec
;
413 struct ConfItem
*aconf
;
416 for (i
= 0; i
< ATABLE_SIZE
; i
++)
418 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
420 if(arec
->type
== CONF_DLINE
)
424 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
427 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
429 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
430 form_str (RPL_STATSDLINE
),
432 oper_reason
? "|" : "",
433 oper_reason
? oper_reason
: "");
442 * input - client to report to
444 * side effects - client is given list of exempt blocks
447 stats_exempt(struct Client
*source_p
)
449 char *name
, *host
, *user
, *classname
;
451 struct AddressRec
*arec
;
452 struct ConfItem
*aconf
;
455 if(ConfigFileEntry
.stats_e_disabled
)
457 sendto_one_numeric(source_p
, ERR_DISABLED
,
458 form_str(ERR_DISABLED
), "STATS e");
462 for (i
= 0; i
< ATABLE_SIZE
; i
++)
464 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
466 if(arec
->type
== CONF_EXEMPTDLINE
)
469 get_printable_conf (aconf
, &name
, &host
, &pass
,
470 &user
, &port
, &classname
);
472 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
473 form_str(RPL_STATSDLINE
),
474 'e', host
, pass
, "", "");
481 stats_events_cb(char *str
, void *ptr
)
483 sendto_one_numeric(ptr
, RPL_STATSDEBUG
, "E :%s", str
);
487 stats_events (struct Client
*source_p
)
489 rb_dump_events(stats_events_cb
, source_p
);
493 stats_prop_klines(struct Client
*source_p
)
495 struct ConfItem
*aconf
;
497 char *user
, *host
, *pass
, *oper_reason
;
499 RB_DLINK_FOREACH(ptr
, prop_bans
.head
)
503 /* Skip non-klines and deactivated klines. */
504 if(aconf
->status
!= CONF_KILL
)
507 get_printable_kline(source_p
, aconf
, &host
, &pass
,
508 &user
, &oper_reason
);
510 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
511 form_str(RPL_STATSKLINE
),
512 'g', host
, user
, pass
,
513 oper_reason
? "|" : "",
514 oper_reason
? oper_reason
: "");
519 stats_hubleaf(struct Client
*source_p
)
521 struct remote_conf
*hub_p
;
524 if((ConfigFileEntry
.stats_h_oper_only
||
525 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
528 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
529 form_str (ERR_NOPRIVILEGES
));
533 RB_DLINK_FOREACH(ptr
, hubleaf_conf_list
.head
)
537 if(hub_p
->flags
& CONF_HUB
)
538 sendto_one_numeric(source_p
, RPL_STATSHLINE
,
539 form_str(RPL_STATSHLINE
),
540 hub_p
->host
, hub_p
->server
);
542 sendto_one_numeric(source_p
, RPL_STATSLLINE
,
543 form_str(RPL_STATSLLINE
),
544 hub_p
->host
, hub_p
->server
);
550 stats_auth (struct Client
*source_p
)
552 /* Oper only, if unopered, return ERR_NOPRIVS */
553 if((ConfigFileEntry
.stats_i_oper_only
== 2) && !IsOper (source_p
))
554 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
555 form_str (ERR_NOPRIVILEGES
));
557 /* If unopered, Only return matching auth blocks */
558 else if((ConfigFileEntry
.stats_i_oper_only
== 1) && !IsOper (source_p
))
560 struct ConfItem
*aconf
;
561 char *name
, *host
, *user
, *classname
;
562 const char *pass
= "*";
565 if(MyConnect (source_p
))
566 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
567 (struct sockaddr
*)&source_p
->localClient
->ip
,
569 source_p
->localClient
->ip
.ss_family
,
570 source_p
->username
, NULL
);
572 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_CLIENT
,
573 0, source_p
->username
, NULL
);
578 get_printable_conf (aconf
, &name
, &host
, &pass
, &user
, &port
, &classname
);
579 if(!EmptyString(aconf
->spasswd
))
580 pass
= aconf
->spasswd
;
582 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
583 name
, pass
, show_iline_prefix(source_p
, aconf
, user
),
584 host
, port
, classname
);
587 /* Theyre opered, or allowed to see all auth blocks */
589 report_auth (source_p
);
594 stats_tklines(struct Client
*source_p
)
596 /* Oper only, if unopered, return ERR_NOPRIVS */
597 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
598 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
599 form_str (ERR_NOPRIVILEGES
));
601 /* If unopered, Only return matching klines */
602 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
604 struct ConfItem
*aconf
;
605 char *host
, *pass
, *user
, *oper_reason
;
607 if(MyConnect (source_p
))
608 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
609 (struct sockaddr
*)&source_p
->localClient
->ip
,
611 source_p
->localClient
->ip
.ss_family
,
612 source_p
->username
, NULL
);
614 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
615 0, source_p
->username
, NULL
);
620 /* dont report a permanent kline as a tkline */
621 if((aconf
->flags
& CONF_FLAGS_TEMPORARY
) == 0)
624 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
626 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
627 form_str(RPL_STATSKLINE
), aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
628 host
, user
, pass
, oper_reason
? "|" : "",
629 oper_reason
? oper_reason
: "");
631 /* Theyre opered, or allowed to see all klines */
634 struct ConfItem
*aconf
;
637 char *user
, *host
, *pass
, *oper_reason
;
639 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
641 RB_DLINK_FOREACH(ptr
, temp_klines
[i
].head
)
645 get_printable_kline(source_p
, aconf
, &host
, &pass
,
646 &user
, &oper_reason
);
648 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
649 form_str(RPL_STATSKLINE
),
650 'k', host
, user
, pass
,
651 oper_reason
? "|" : "",
652 oper_reason
? oper_reason
: "");
660 * inputs - Client to report to, mask
662 * side effects - Reports configured K-lines to client_p.
665 report_Klines(struct Client
*source_p
)
667 char *host
, *pass
, *user
, *oper_reason
;
668 struct AddressRec
*arec
;
669 struct ConfItem
*aconf
= NULL
;
672 for (i
= 0; i
< ATABLE_SIZE
; i
++)
674 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
676 if(arec
->type
== CONF_KILL
)
680 /* its a tempkline, theyre reported elsewhere */
681 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
684 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
685 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
686 form_str(RPL_STATSKLINE
),
687 'K', host
, user
, pass
,
688 oper_reason
? "|" : "",
689 oper_reason
? oper_reason
: "");
696 stats_klines(struct Client
*source_p
)
698 /* Oper only, if unopered, return ERR_NOPRIVS */
699 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
700 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
701 form_str (ERR_NOPRIVILEGES
));
703 /* If unopered, Only return matching klines */
704 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
706 struct ConfItem
*aconf
;
707 char *host
, *pass
, *user
, *oper_reason
;
709 /* search for a kline */
710 if(MyConnect (source_p
))
711 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
712 (struct sockaddr
*)&source_p
->localClient
->ip
,
714 source_p
->localClient
->ip
.ss_family
,
715 source_p
->username
, NULL
);
717 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
718 0, source_p
->username
, NULL
);
723 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
725 sendto_one_numeric(source_p
, RPL_STATSKLINE
, form_str(RPL_STATSKLINE
),
726 aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
727 host
, user
, pass
, oper_reason
? "|" : "",
728 oper_reason
? oper_reason
: "");
730 /* Theyre opered, or allowed to see all klines */
732 report_Klines (source_p
);
736 stats_messages(struct Client
*source_p
)
738 struct DictionaryIter iter
;
740 struct alias_entry
*amsg
;
742 DICTIONARY_FOREACH(msg
, &iter
, cmd_dict
)
744 s_assert(msg
->cmd
!= NULL
);
745 sendto_one_numeric(source_p
, RPL_STATSCOMMANDS
,
746 form_str(RPL_STATSCOMMANDS
),
747 msg
->cmd
, msg
->count
,
748 msg
->bytes
, msg
->rcount
);
751 DICTIONARY_FOREACH(amsg
, &iter
, alias_dict
)
753 s_assert(amsg
->name
!= NULL
);
754 sendto_one_numeric(source_p
, RPL_STATSCOMMANDS
,
755 form_str(RPL_STATSCOMMANDS
),
756 amsg
->name
, amsg
->hits
, 0L, 0);
761 stats_dnsbl(struct Client
*source_p
)
764 struct Blacklist
*blptr
;
766 RB_DLINK_FOREACH(ptr
, blacklist_list
.head
)
770 /* use RPL_STATSDEBUG for now -- jilles */
771 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "n :%d %s %s (%d)",
774 blptr
->status
& CONF_ILLEGAL
? "disabled" : "active",
780 stats_oper(struct Client
*source_p
)
782 struct oper_conf
*oper_p
;
785 if(!IsOper(source_p
) && ConfigFileEntry
.stats_o_oper_only
)
787 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
788 form_str (ERR_NOPRIVILEGES
));
792 RB_DLINK_FOREACH(ptr
, oper_conf_list
.head
)
796 sendto_one_numeric(source_p
, RPL_STATSOLINE
,
797 form_str(RPL_STATSOLINE
),
798 oper_p
->username
, oper_p
->host
, oper_p
->name
,
799 IsOper(source_p
) ? oper_p
->privset
->name
: "0", "-1");
804 stats_capability_walk(const char *line
, void *data
)
806 struct Client
*client_p
= data
;
808 sendto_one_numeric(client_p
, RPL_STATSDEBUG
, "C :%s", line
);
812 stats_capability(struct Client
*client_p
)
814 capability_index_stats(stats_capability_walk
, client_p
);
818 stats_privset(struct Client
*source_p
)
820 privilegeset_report(source_p
);
825 * input - client pointer
827 * side effects - client is shown a list of active opers
830 stats_operedup (struct Client
*source_p
)
832 struct Client
*target_p
;
833 rb_dlink_node
*oper_ptr
;
834 unsigned int count
= 0;
836 RB_DLINK_FOREACH (oper_ptr
, oper_list
.head
)
838 target_p
= oper_ptr
->data
;
840 if(IsOperInvis(target_p
) && !IsOper(source_p
))
843 if(target_p
->user
->away
)
848 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
850 target_p
->name
, target_p
->username
,
854 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
855 "p :%u staff members", count
);
857 stats_p_spy (source_p
);
861 stats_ports (struct Client
*source_p
)
863 if(!IsOper (source_p
) && ConfigFileEntry
.stats_P_oper_only
)
864 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
865 form_str (ERR_NOPRIVILEGES
));
867 show_ports (source_p
);
871 stats_tresv(struct Client
*source_p
)
873 struct ConfItem
*aconf
;
874 struct rb_radixtree_iteration_state state
;
878 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
882 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
883 form_str(RPL_STATSQLINE
),
884 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
887 RB_RADIXTREE_FOREACH(aconf
, &state
, resv_tree
)
890 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
891 form_str(RPL_STATSQLINE
),
892 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
898 stats_resv(struct Client
*source_p
)
900 struct ConfItem
*aconf
;
901 struct rb_radixtree_iteration_state state
;
905 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
909 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
910 form_str(RPL_STATSQLINE
),
911 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
914 RB_RADIXTREE_FOREACH(aconf
, &state
, resv_tree
)
917 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
918 form_str(RPL_STATSQLINE
),
919 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
924 stats_ssld_foreach(void *data
, pid_t pid
, int cli_count
, enum ssld_status status
, const char *version
)
926 struct Client
*source_p
= data
;
928 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
931 status
== SSLD_DEAD
? 'D' : (status
== SSLD_SHUTDOWN
? 'S' : 'A'),
937 stats_ssld(struct Client
*source_p
)
939 ssld_foreach_info(stats_ssld_foreach
, source_p
);
943 stats_usage (struct Client
*source_p
)
958 if(getrusage(RUSAGE_SELF
, &rus
) == -1)
960 sendto_one_notice(source_p
, ":Getruseage error: %s.",
964 secs
= rus
.ru_utime
.tv_sec
+ rus
.ru_stime
.tv_sec
;
968 rup
= (rb_current_time() - startup_time
) * hzz
;
972 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
973 "R :CPU Secs %d:%02d User %d:%02d System %d:%02d",
974 (int) (secs
/ 60), (int) (secs
% 60),
975 (int) (rus
.ru_utime
.tv_sec
/ 60),
976 (int) (rus
.ru_utime
.tv_sec
% 60),
977 (int) (rus
.ru_stime
.tv_sec
/ 60),
978 (int) (rus
.ru_stime
.tv_sec
% 60));
979 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
980 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
981 rus
.ru_maxrss
, (rus
.ru_ixrss
/ rup
),
982 (rus
.ru_idrss
/ rup
), (rus
.ru_isrss
/ rup
));
983 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
984 "R :Swaps %d Reclaims %d Faults %d",
985 (int) rus
.ru_nswap
, (int) rus
.ru_minflt
, (int) rus
.ru_majflt
);
986 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
987 "R :Block in %d out %d",
988 (int) rus
.ru_inblock
, (int) rus
.ru_oublock
);
989 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
990 "R :Msg Rcv %d Send %d",
991 (int) rus
.ru_msgrcv
, (int) rus
.ru_msgsnd
);
992 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
993 "R :Signals %d Context Vol. %d Invol %d",
994 (int) rus
.ru_nsignals
, (int) rus
.ru_nvcsw
,
995 (int) rus
.ru_nivcsw
);
999 stats_tstats (struct Client
*source_p
)
1001 struct Client
*target_p
;
1002 struct ServerStatistics sp
;
1005 memcpy(&sp
, &ServerStats
, sizeof(struct ServerStatistics
));
1007 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1009 target_p
= ptr
->data
;
1011 sp
.is_sbs
+= target_p
->localClient
->sendB
;
1012 sp
.is_sbr
+= target_p
->localClient
->receiveB
;
1013 sp
.is_sti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
1017 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
1019 target_p
= ptr
->data
;
1021 sp
.is_cbs
+= target_p
->localClient
->sendB
;
1022 sp
.is_cbr
+= target_p
->localClient
->receiveB
;
1023 sp
.is_cti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
1027 RB_DLINK_FOREACH(ptr
, unknown_list
.head
)
1032 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1033 "T :accepts %u refused %u", sp
.is_ac
, sp
.is_ref
);
1034 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1035 "T :rejected %u delaying %lu",
1036 sp
.is_rej
, delay_exit_length());
1037 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1038 "T :throttled refused %u throttle list size %lu", sp
.is_thr
, throttle_size());
1039 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1040 "T :nicks being delayed %lu",
1042 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1043 "T :unknown commands %u prefixes %u",
1044 sp
.is_unco
, sp
.is_unpf
);
1045 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1046 "T :nick collisions %u saves %u unknown closes %u",
1047 sp
.is_kill
, sp
.is_save
, sp
.is_ni
);
1048 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1049 "T :wrong direction %u empty %u",
1050 sp
.is_wrdi
, sp
.is_empt
);
1051 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1052 "T :numerics seen %u", sp
.is_num
);
1053 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1054 "T :tgchange blocked msgs %u restricted addrs %lu",
1055 sp
.is_tgch
, rb_dlink_list_length(&tgchange_list
));
1056 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1057 "T :ratelimit blocked commands %u", sp
.is_rl
);
1058 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1059 "T :auth successes %u fails %u",
1060 sp
.is_asuc
, sp
.is_abad
);
1061 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1062 "T :sasl successes %u fails %u",
1063 sp
.is_ssuc
, sp
.is_sbad
);
1064 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "T :Client Server");
1065 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1066 "T :connected %u %u", sp
.is_cl
, sp
.is_sv
);
1067 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1068 "T :bytes sent %lluK %lluK",
1071 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1072 "T :bytes recv %lluK %lluK",
1075 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1076 "T :time connected %llu %llu",
1077 sp
.is_cti
, sp
.is_sti
);
1081 stats_uptime (struct Client
*source_p
)
1085 now
= rb_current_time() - startup_time
;
1086 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
1087 form_str (RPL_STATSUPTIME
),
1088 (int)(now
/ 86400), (int)((now
/ 3600) % 24),
1089 (int)((now
/ 60) % 60), (int)(now
% 60));
1090 sendto_one_numeric(source_p
, RPL_STATSCONN
,
1091 form_str (RPL_STATSCONN
),
1092 MaxConnectionCount
, MaxClientCount
,
1093 Count
.totalrestartcount
);
1101 static struct shared_flags shared_flagtable
[] =
1103 { SHARED_PKLINE
, 'K' },
1104 { SHARED_TKLINE
, 'k' },
1105 { SHARED_UNKLINE
, 'U' },
1106 { SHARED_PXLINE
, 'X' },
1107 { SHARED_TXLINE
, 'x' },
1108 { SHARED_UNXLINE
, 'Y' },
1109 { SHARED_PRESV
, 'Q' },
1110 { SHARED_TRESV
, 'q' },
1111 { SHARED_UNRESV
, 'R' },
1112 { SHARED_LOCOPS
, 'L' },
1113 { SHARED_REHASH
, 'H' },
1114 { SHARED_TDLINE
, 'd' },
1115 { SHARED_PDLINE
, 'D' },
1116 { SHARED_UNDLINE
, 'E' },
1117 { SHARED_GRANT
, 'G' },
1118 { SHARED_DIE
, 'I' },
1124 stats_shared (struct Client
*source_p
)
1126 struct remote_conf
*shared_p
;
1128 char buf
[sizeof(shared_flagtable
)/sizeof(shared_flagtable
[0])];
1132 RB_DLINK_FOREACH(ptr
, shared_conf_list
.head
)
1134 shared_p
= ptr
->data
;
1140 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1142 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1143 *p
++ = shared_flagtable
[i
].letter
;
1148 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1149 form_str(RPL_STATSULINE
),
1150 shared_p
->server
, shared_p
->username
,
1151 shared_p
->host
, buf
);
1154 RB_DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
1156 shared_p
= ptr
->data
;
1162 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1164 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1165 *p
++ = shared_flagtable
[i
].letter
;
1170 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1171 form_str(RPL_STATSULINE
),
1172 shared_p
->server
, "*", "*", buf
);
1178 * input - client pointer
1180 * side effects - client is shown lists of who connected servers
1183 stats_servers (struct Client
*source_p
)
1185 struct Client
*target_p
;
1188 int days
, hours
, minutes
;
1191 if(ConfigServerHide
.flatten_links
&& !IsOper(source_p
) &&
1192 !IsExemptShide(source_p
))
1194 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1195 form_str (ERR_NOPRIVILEGES
));
1199 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1201 target_p
= ptr
->data
;
1204 seconds
= rb_current_time() - target_p
->localClient
->firsttime
;
1206 days
= (int) (seconds
/ 86400);
1208 hours
= (int) (seconds
/ 3600);
1210 minutes
= (int) (seconds
/ 60);
1213 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1214 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1215 "Connected: %d day%s, %d:%02d:%02d",
1217 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
1218 (int) (rb_current_time() - target_p
->localClient
->lasttime
),
1219 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1220 days
, (days
== 1) ? "" : "s", hours
, minutes
,
1224 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1225 "V :%d Server(s)", j
);
1229 stats_tgecos(struct Client
*source_p
)
1231 struct ConfItem
*aconf
;
1234 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1239 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1240 form_str(RPL_STATSXLINE
),
1241 'x', aconf
->port
, aconf
->host
,
1247 stats_gecos(struct Client
*source_p
)
1249 struct ConfItem
*aconf
;
1252 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1257 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1258 form_str(RPL_STATSXLINE
),
1259 'X', aconf
->port
, aconf
->host
,
1265 stats_class(struct Client
*source_p
)
1267 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOper(source_p
))
1268 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1269 form_str (ERR_NOPRIVILEGES
));
1271 report_classes(source_p
);
1275 stats_memory (struct Client
*source_p
)
1277 struct Client
*target_p
;
1278 struct Channel
*chptr
;
1279 rb_dlink_node
*rb_dlink
;
1281 int channel_count
= 0;
1282 int local_client_conf_count
= 0; /* local client conf links */
1283 int users_counted
= 0; /* user structs */
1285 int channel_users
= 0;
1286 int channel_invites
= 0;
1287 int channel_bans
= 0;
1288 int channel_except
= 0;
1289 int channel_invex
= 0;
1290 int channel_quiets
= 0;
1292 int class_count
= 0; /* classes */
1293 int conf_count
= 0; /* conf lines */
1294 int users_invited_count
= 0; /* users invited */
1295 int user_channels
= 0; /* users in channels */
1296 int aways_counted
= 0;
1297 size_t number_servers_cached
; /* number of servers cached by scache */
1299 size_t channel_memory
= 0;
1300 size_t channel_ban_memory
= 0;
1301 size_t channel_except_memory
= 0;
1302 size_t channel_invex_memory
= 0;
1303 size_t channel_quiet_memory
= 0;
1305 size_t away_memory
= 0; /* memory used by aways */
1306 size_t ww
= 0; /* whowas array count */
1307 size_t wwm
= 0; /* whowas array memory used */
1308 size_t conf_memory
= 0; /* memory used by conf lines */
1309 size_t mem_servers_cached
; /* memory used by scache */
1311 size_t linebuf_count
= 0;
1312 size_t linebuf_memory_used
= 0;
1314 size_t total_channel_memory
= 0;
1317 size_t local_client_count
= 0;
1318 size_t local_client_memory_used
= 0;
1320 size_t remote_client_count
= 0;
1321 size_t remote_client_memory_used
= 0;
1323 size_t total_memory
= 0;
1325 whowas_memory_usage(&ww
, &wwm
);
1327 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
1329 target_p
= ptr
->data
;
1330 if(MyConnect(target_p
))
1332 local_client_conf_count
++;
1338 users_invited_count
+= rb_dlink_list_length(&target_p
->user
->invited
);
1339 user_channels
+= rb_dlink_list_length(&target_p
->user
->channel
);
1340 if(target_p
->user
->away
)
1343 away_memory
+= (strlen(target_p
->user
->away
) + 1);
1348 /* Count up all channels, ban lists, except lists, Invex lists */
1349 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
1353 channel_memory
+= (strlen(chptr
->chname
) + sizeof(struct Channel
));
1355 channel_users
+= rb_dlink_list_length(&chptr
->members
);
1356 channel_invites
+= rb_dlink_list_length(&chptr
->invites
);
1358 RB_DLINK_FOREACH(rb_dlink
, chptr
->banlist
.head
)
1362 channel_ban_memory
+= sizeof(rb_dlink_node
) + sizeof(struct Ban
);
1365 RB_DLINK_FOREACH(rb_dlink
, chptr
->exceptlist
.head
)
1369 channel_except_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1372 RB_DLINK_FOREACH(rb_dlink
, chptr
->invexlist
.head
)
1376 channel_invex_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1379 RB_DLINK_FOREACH(rb_dlink
, chptr
->quietlist
.head
)
1383 channel_quiet_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1387 /* count up all classes */
1389 class_count
= rb_dlink_list_length(&class_list
) + 1;
1391 rb_count_rb_linebuf_memory(&linebuf_count
, &linebuf_memory_used
);
1393 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1394 "z :Users %u(%lu) Invites %u(%lu)",
1396 (unsigned long) users_counted
* sizeof(struct User
),
1397 users_invited_count
,
1398 (unsigned long) users_invited_count
* sizeof(rb_dlink_node
));
1400 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1401 "z :User channels %u(%lu) Aways %u(%d)",
1403 (unsigned long) user_channels
* sizeof(rb_dlink_node
),
1404 aways_counted
, (int) away_memory
);
1406 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1407 "z :Attached confs %u(%lu)",
1408 local_client_conf_count
,
1409 (unsigned long) local_client_conf_count
* sizeof(rb_dlink_node
));
1411 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1412 "z :Conflines %u(%d)", conf_count
, (int) conf_memory
);
1414 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1415 "z :Classes %u(%lu)",
1417 (unsigned long) class_count
* sizeof(struct Class
));
1419 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1420 "z :Channels %u(%d)",
1421 channel_count
, (int) channel_memory
);
1423 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1424 "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)",
1425 channel_bans
, (int) channel_ban_memory
,
1426 channel_except
, (int) channel_except_memory
,
1427 channel_invex
, (int) channel_invex_memory
,
1428 channel_quiets
, (int) channel_quiet_memory
);
1430 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1431 "z :Channel members %u(%lu) invite %u(%lu)",
1433 (unsigned long) channel_users
* sizeof(rb_dlink_node
),
1435 (unsigned long) channel_invites
* sizeof(rb_dlink_node
));
1437 total_channel_memory
= channel_memory
+
1438 channel_ban_memory
+
1439 channel_users
* sizeof(rb_dlink_node
) + channel_invites
* sizeof(rb_dlink_node
);
1441 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1442 "z :Whowas array %ld(%ld)",
1443 (long)ww
, (long)wwm
);
1447 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1448 "z :Hash: client %u(%ld) chan %u(%ld)",
1449 U_MAX
, (long)(U_MAX
* sizeof(rb_dlink_list
)),
1450 CH_MAX
, (long)(CH_MAX
* sizeof(rb_dlink_list
)));
1452 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1453 "z :linebuf %ld(%ld)",
1454 (long)linebuf_count
, (long)linebuf_memory_used
);
1456 count_scache(&number_servers_cached
, &mem_servers_cached
);
1458 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1459 "z :scache %ld(%ld)",
1460 (long)number_servers_cached
, (long)mem_servers_cached
);
1462 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1463 "z :hostname hash %d(%ld)",
1464 HOST_MAX
, (long)HOST_MAX
* sizeof(rb_dlink_list
));
1466 total_memory
= totww
+ total_channel_memory
+ conf_memory
+
1467 class_count
* sizeof(struct Class
);
1469 total_memory
+= mem_servers_cached
;
1470 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1471 "z :Total: whowas %d channel %d conf %d",
1472 (int) totww
, (int) total_channel_memory
,
1475 count_local_client_memory(&local_client_count
, &local_client_memory_used
);
1476 total_memory
+= local_client_memory_used
;
1478 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1479 "z :Local client Memory in use: %ld(%ld)",
1480 (long)local_client_count
, (long)local_client_memory_used
);
1483 count_remote_client_memory(&remote_client_count
, &remote_client_memory_used
);
1484 total_memory
+= remote_client_memory_used
;
1486 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1487 "z :Remote client Memory in use: %ld(%ld)",
1488 (long)remote_client_count
,
1489 (long)remote_client_memory_used
);
1493 stats_ziplinks (struct Client
*source_p
)
1496 struct Client
*target_p
;
1497 struct ZipStats
*zipstats
;
1499 char buf
[128], buf1
[128];
1500 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1502 target_p
= ptr
->data
;
1503 if(IsCapable (target_p
, CAP_ZIP
))
1505 zipstats
= target_p
->localClient
->zipstats
;
1506 sprintf(buf
, "%.2f%%", zipstats
->out_ratio
);
1507 sprintf(buf1
, "%.2f%%", zipstats
->in_ratio
);
1508 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1509 "Z :ZipLinks stats for %s send[%s compression "
1510 "(%llu kB data/%llu kB wire)] recv[%s compression "
1511 "(%llu kB data/%llu kB wire)]",
1513 buf
, zipstats
->out
>> 10,
1514 zipstats
->out_wire
>> 10, buf1
,
1515 zipstats
->in
>> 10, zipstats
->in_wire
>> 10);
1520 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1521 "Z :%u ziplink(s)", sent_data
);
1525 stats_servlinks (struct Client
*source_p
)
1527 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1528 long uptime
, sendK
, receiveK
;
1529 struct Client
*target_p
;
1534 if(ConfigServerHide
.flatten_links
&& !IsOper (source_p
) &&
1535 !IsExemptShide(source_p
))
1537 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1538 form_str (ERR_NOPRIVILEGES
));
1542 sendK
= receiveK
= 0;
1544 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1546 target_p
= ptr
->data
;
1549 sendK
+= target_p
->localClient
->sendK
;
1550 receiveK
+= target_p
->localClient
->receiveK
;
1552 sendto_one(source_p
, Sformat
,
1553 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1555 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1556 (int) target_p
->localClient
->sendM
,
1557 (int) target_p
->localClient
->sendK
,
1558 (int) target_p
->localClient
->receiveM
,
1559 (int) target_p
->localClient
->receiveK
,
1560 rb_current_time() - target_p
->localClient
->firsttime
,
1561 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1562 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1563 IsOper (source_p
) ? show_capabilities (target_p
) : "TS");
1566 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1567 "? :%u total server(s)", j
);
1569 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((sendK
)));
1570 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1571 "? :Sent total : %s %s",
1572 buf
, _GMKs (sendK
));
1573 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((receiveK
)));
1574 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1575 "? :Recv total : %s %s",
1576 buf
, _GMKs (receiveK
));
1578 uptime
= (rb_current_time() - startup_time
);
1579 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1580 _GMKv (me
.localClient
->sendK
),
1581 _GMKs (me
.localClient
->sendK
),
1582 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1583 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server send: %s", buf
);
1584 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1585 _GMKv (me
.localClient
->receiveK
),
1586 _GMKs (me
.localClient
->receiveK
),
1587 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1588 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server recv: %s", buf
);
1592 stats_l_should_show_oper(struct Client
*target_p
)
1594 return (!IsOperInvis(target_p
));
1598 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1603 char statchar
= parv
[1][0];
1605 /* this is def targeted at us somehow.. */
1606 if(parc
> 2 && !EmptyString(parv
[2]))
1608 /* directed at us generically? */
1609 if(match(parv
[2], me
.name
) ||
1610 (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1618 wilds
= strchr(name
, '*') || strchr(name
, '?');
1621 /* must be directed at a specific person thats not us */
1622 if(!doall
&& !wilds
)
1624 struct Client
*target_p
;
1626 if(MyClient(source_p
))
1627 target_p
= find_named_person(name
);
1629 target_p
= find_person(name
);
1631 if(target_p
!= NULL
)
1633 stats_spy(source_p
, statchar
, target_p
->name
);
1634 stats_l_client(source_p
, target_p
, statchar
);
1637 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1638 form_str(ERR_NOSUCHSERVER
),
1650 stats_spy(source_p
, statchar
, name
);
1654 /* local opers get everyone */
1655 if(MyOper(source_p
))
1657 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
, NULL
);
1658 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1662 /* they still need themselves if theyre local.. */
1663 if(MyClient(source_p
))
1664 stats_l_client(source_p
, source_p
, statchar
);
1666 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
, stats_l_should_show_oper
);
1669 if (!ConfigServerHide
.flatten_links
|| IsOper(source_p
) ||
1670 IsExemptShide(source_p
))
1671 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
, NULL
);
1676 /* ok, at this point theyre looking for a specific client whos on
1677 * our server.. but it contains a wildcard. --fl
1679 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1685 stats_l_list(struct Client
*source_p
, const char *name
, bool doall
, bool wilds
,
1686 rb_dlink_list
* list
, char statchar
, bool (*check_fn
)(struct Client
*target_p
))
1689 struct Client
*target_p
;
1691 /* send information about connections which match. note, we
1692 * dont need tests for IsInvisible(), because non-opers will
1693 * never get here for normal clients --fl
1695 RB_DLINK_FOREACH(ptr
, list
->head
)
1697 target_p
= ptr
->data
;
1699 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1702 if (check_fn
== NULL
|| check_fn(target_p
))
1703 stats_l_client(source_p
, target_p
, statchar
);
1708 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1711 if(IsAnyServer(target_p
))
1713 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1715 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1716 (int) target_p
->localClient
->sendM
,
1717 (int) target_p
->localClient
->sendK
,
1718 (int) target_p
->localClient
->receiveM
,
1719 (int) target_p
->localClient
->receiveK
,
1720 rb_current_time() - target_p
->localClient
->firsttime
,
1721 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1722 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1723 IsOper(source_p
) ? show_capabilities(target_p
) : "-");
1728 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1729 show_ip(source_p
, target_p
) ?
1730 (IsUpper(statchar
) ?
1731 get_client_name(target_p
, SHOW_IP
) :
1732 get_client_name(target_p
, HIDE_IP
)) :
1733 get_client_name(target_p
, MASK_IP
),
1734 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1735 (int) target_p
->localClient
->sendM
,
1736 (int) target_p
->localClient
->sendK
,
1737 (int) target_p
->localClient
->receiveM
,
1738 (int) target_p
->localClient
->receiveK
,
1739 rb_current_time() - target_p
->localClient
->firsttime
,
1740 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1741 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1747 rb_dump_fd_callback(int fd
, const char *desc
, void *data
)
1749 struct Client
*source_p
= data
;
1750 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "F :fd %-3d desc '%s'", fd
, desc
);
1754 stats_comm(struct Client
*source_p
)
1756 rb_dump_fd(rb_dump_fd_callback
, source_p
);
1762 * inputs - pointer to client doing the /stats
1763 * - char letter they are doing /stats on
1766 * This little helper function reports to opers if configured.
1769 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1773 data
.client
= source_p
;
1775 data
.arg2
= (int) statchar
;
1778 call_hook(doing_stats_hook
, &data
);
1785 * input - pointer to client doing stats
1787 * side effects - call hook doing_stats_p
1790 stats_p_spy (struct Client
*source_p
)
1794 data
.client
= source_p
;
1795 data
.arg1
= data
.arg2
= NULL
;
1797 call_hook(doing_stats_p_hook
, &data
);