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 */
28 #include "common.h" /* TRUE/FALSE */
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 int m_stats (struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
54 struct Message stats_msgtab
= {
56 {mg_unreg
, {m_stats
, 2}, {m_stats
, 3}, mg_ignore
, mg_ignore
, {m_stats
, 2}}
60 int doing_stats_p_hook
;
62 mapi_clist_av1 stats_clist
[] = { &stats_msgtab
, NULL
};
63 mapi_hlist_av1 stats_hlist
[] = {
64 { "doing_stats", &doing_stats_hook
},
65 { "doing_stats_p", &doing_stats_p_hook
},
69 DECLARE_MODULE_AV2(stats
, NULL
, NULL
, stats_clist
, stats_hlist
, NULL
, NULL
, NULL
, NULL
);
71 const char *Lformat
= "%s %u %u %u %u %u :%u %u %s";
73 static void stats_l_list(struct Client
*s
, const char *, int, int, rb_dlink_list
*, char,
74 int (*check_fn
)(struct Client
*target_p
));
75 static void stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
78 static int stats_spy(struct Client
*, char, const char *);
79 static void stats_p_spy(struct Client
*);
81 /* Heres our struct for the stats table */
85 void (*handler
) (struct Client
*source_p
);
90 static void stats_dns_servers(struct Client
*);
91 static void stats_delay(struct Client
*);
92 static void stats_hash(struct Client
*);
93 static void stats_connect(struct Client
*);
94 static void stats_tdeny(struct Client
*);
95 static void stats_deny(struct Client
*);
96 static void stats_exempt(struct Client
*);
97 static void stats_events(struct Client
*);
98 static void stats_prop_klines(struct Client
*);
99 static void stats_hubleaf(struct Client
*);
100 static void stats_auth(struct Client
*);
101 static void stats_tklines(struct Client
*);
102 static void stats_klines(struct Client
*);
103 static void stats_messages(struct Client
*);
104 static void stats_dnsbl(struct Client
*);
105 static void stats_oper(struct Client
*);
106 static void stats_privset(struct Client
*);
107 static void stats_operedup(struct Client
*);
108 static void stats_ports(struct Client
*);
109 static void stats_tresv(struct Client
*);
110 static void stats_resv(struct Client
*);
111 static void stats_ssld(struct Client
*);
112 static void stats_usage(struct Client
*);
113 static void stats_tstats(struct Client
*);
114 static void stats_uptime(struct Client
*);
115 static void stats_shared(struct Client
*);
116 static void stats_servers(struct Client
*);
117 static void stats_tgecos(struct Client
*);
118 static void stats_gecos(struct Client
*);
119 static void stats_class(struct Client
*);
120 static void stats_memory(struct Client
*);
121 static void stats_servlinks(struct Client
*);
122 static void stats_ltrace(struct Client
*, int, const char **);
123 static void stats_ziplinks(struct Client
*);
124 static void stats_comm(struct Client
*);
125 static void stats_capability(struct Client
*);
127 /* This table contains the possible stats items, in order:
128 * stats letter, function to call, operonly? adminonly?
129 * case only matters in the stats letter column.. -- fl_
131 static struct StatsStruct stats_cmd_table
[] = {
132 /* letter function need_oper need_admin */
133 {'a', stats_dns_servers
, 1, 1, },
134 {'A', stats_dns_servers
, 1, 1, },
135 {'b', stats_delay
, 1, 1, },
136 {'B', stats_hash
, 1, 1, },
137 {'c', stats_connect
, 0, 0, },
138 {'C', stats_capability
, 1, 0, },
139 {'d', stats_tdeny
, 1, 0, },
140 {'D', stats_deny
, 1, 0, },
141 {'e', stats_exempt
, 1, 0, },
142 {'E', stats_events
, 1, 1, },
143 {'f', stats_comm
, 1, 1, },
144 {'F', stats_comm
, 1, 1, },
145 {'g', stats_prop_klines
, 1, 0, },
146 {'h', stats_hubleaf
, 0, 0, },
147 {'H', stats_hubleaf
, 0, 0, },
148 {'i', stats_auth
, 0, 0, },
149 {'I', stats_auth
, 0, 0, },
150 {'k', stats_tklines
, 0, 0, },
151 {'K', stats_klines
, 0, 0, },
152 {'l', NULL
/* special */, 0, 0, },
153 {'L', NULL
/* special */, 0, 0, },
154 {'m', stats_messages
, 0, 0, },
155 {'M', stats_messages
, 0, 0, },
156 {'n', stats_dnsbl
, 0, 0, },
157 {'o', stats_oper
, 0, 0, },
158 {'O', stats_privset
, 1, 0, },
159 {'p', stats_operedup
, 0, 0, },
160 {'P', stats_ports
, 0, 0, },
161 {'q', stats_tresv
, 1, 0, },
162 {'Q', stats_resv
, 1, 0, },
163 {'r', stats_usage
, 1, 0, },
164 {'R', stats_usage
, 1, 0, },
165 {'s', stats_ssld
, 1, 1, },
166 {'S', stats_ssld
, 1, 1, },
167 {'t', stats_tstats
, 1, 0, },
168 {'T', stats_tstats
, 1, 0, },
169 {'u', stats_uptime
, 0, 0, },
170 {'U', stats_shared
, 1, 0, },
171 {'v', stats_servers
, 0, 0, },
172 {'V', stats_servers
, 0, 0, },
173 {'x', stats_tgecos
, 1, 0, },
174 {'X', stats_gecos
, 1, 0, },
175 {'y', stats_class
, 0, 0, },
176 {'Y', stats_class
, 0, 0, },
177 {'z', stats_memory
, 1, 0, },
178 {'Z', stats_ziplinks
, 1, 0, },
179 {'?', stats_servlinks
, 0, 0, },
180 {(char) 0, (void (*)()) 0, 0, 0, }
185 * parv[1] = stat letter/command
186 * parv[2] = (if present) server/mask in stats L, or target
188 * This will search the tables for the appropriate stats letter,
189 * if found execute it.
192 m_stats(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
194 static time_t last_used
= 0;
199 statchar
= parv
[1][0];
201 if(MyClient(source_p
) && !IsOper(source_p
))
203 /* Check the user is actually allowed to do /stats, and isnt flooding */
204 if((last_used
+ ConfigFileEntry
.pace_wait
) > rb_current_time())
206 /* safe enough to give this on a local connect only */
207 sendto_one(source_p
, form_str(RPL_LOAD2HI
),
208 me
.name
, source_p
->name
, "STATS");
209 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
210 form_str(RPL_ENDOFSTATS
), statchar
);
214 last_used
= rb_current_time();
217 if(hunt_server (client_p
, source_p
, ":%s STATS %s :%s", 2, parc
, parv
) != HUNTED_ISME
)
220 if((statchar
!= 'L') && (statchar
!= 'l'))
221 did_stats
= stats_spy(source_p
, statchar
, NULL
);
223 /* if did_stats is true, a module grabbed this STATS request */
227 for (i
= 0; stats_cmd_table
[i
].letter
; i
++)
229 if(stats_cmd_table
[i
].letter
== statchar
)
231 /* The stats table says what privs are needed, so check --fl_ */
232 /* Called for remote clients and for local opers, so check need_admin
235 if(stats_cmd_table
[i
].need_oper
&& !IsOper(source_p
))
237 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
238 form_str (ERR_NOPRIVILEGES
));
241 if(stats_cmd_table
[i
].need_admin
&& !IsOperAdmin(source_p
))
243 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
244 me
.name
, source_p
->name
, "admin");
248 /* Blah, stats L needs the parameters, none of the others do.. */
249 if(statchar
== 'L' || statchar
== 'l')
250 stats_ltrace (source_p
, parc
, parv
);
252 stats_cmd_table
[i
].handler (source_p
);
257 /* Send the end of stats notice, and the stats_spy */
258 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
259 form_str(RPL_ENDOFSTATS
), statchar
);
265 stats_dns_servers (struct Client
*source_p
)
267 report_dns_servers (source_p
);
271 stats_delay(struct Client
*source_p
)
274 struct DictionaryIter iter
;
276 DICTIONARY_FOREACH(nd
, &iter
, nd_dict
)
278 sendto_one_notice(source_p
, ":Delaying: %s for %ld",
279 nd
->name
, (long) nd
->expire
);
284 stats_hash_cb(const char *buf
, void *client_p
)
286 sendto_one_numeric(client_p
, RPL_STATSDEBUG
, "B :%s", buf
);
290 stats_hash(struct Client
*source_p
)
292 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "B :%-30s %-15s %-10s %-10s %-10s %-10s",
293 "NAME", "TYPE", "OBJECTS", "DEPTH SUM", "AVG DEPTH", "MAX DEPTH");
295 rb_dictionary_stats_walk(stats_hash_cb
, source_p
);
296 rb_radixtree_stats_walk(stats_hash_cb
, source_p
);
300 stats_connect(struct Client
*source_p
)
303 struct server_conf
*server_p
;
307 if((ConfigFileEntry
.stats_c_oper_only
||
308 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
311 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
312 form_str(ERR_NOPRIVILEGES
));
316 RB_DLINK_FOREACH(ptr
, server_conf_list
.head
)
318 server_p
= ptr
->data
;
320 if(ServerConfIllegal(server_p
))
327 if(ServerConfAutoconn(server_p
))
329 if(ServerConfSSL(server_p
))
331 if(ServerConfTb(server_p
))
333 if(ServerConfCompressed(server_p
))
342 sendto_one_numeric(source_p
, RPL_STATSCLINE
,
343 form_str(RPL_STATSCLINE
),
346 server_p
->port
, server_p
->class_name
);
352 * input - client to report to
354 * side effects - client is given temp dline list.
357 stats_tdeny (struct Client
*source_p
)
359 char *host
, *pass
, *user
, *oper_reason
;
360 struct AddressRec
*arec
;
361 struct ConfItem
*aconf
;
364 for (i
= 0; i
< ATABLE_SIZE
; i
++)
366 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
368 if(arec
->type
== CONF_DLINE
)
372 if(!(aconf
->flags
& CONF_FLAGS_TEMPORARY
))
375 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
377 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
378 form_str (RPL_STATSDLINE
),
380 oper_reason
? "|" : "",
381 oper_reason
? oper_reason
: "");
389 * input - client to report to
391 * side effects - client is given dline list.
394 stats_deny (struct Client
*source_p
)
396 char *host
, *pass
, *user
, *oper_reason
;
397 struct AddressRec
*arec
;
398 struct ConfItem
*aconf
;
401 for (i
= 0; i
< ATABLE_SIZE
; i
++)
403 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
405 if(arec
->type
== CONF_DLINE
)
409 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
412 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
414 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
415 form_str (RPL_STATSDLINE
),
417 oper_reason
? "|" : "",
418 oper_reason
? oper_reason
: "");
427 * input - client to report to
429 * side effects - client is given list of exempt blocks
432 stats_exempt(struct Client
*source_p
)
434 char *name
, *host
, *user
, *classname
;
436 struct AddressRec
*arec
;
437 struct ConfItem
*aconf
;
440 if(ConfigFileEntry
.stats_e_disabled
)
442 sendto_one_numeric(source_p
, ERR_DISABLED
,
443 form_str(ERR_DISABLED
), "STATS e");
447 for (i
= 0; i
< ATABLE_SIZE
; i
++)
449 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
451 if(arec
->type
== CONF_EXEMPTDLINE
)
454 get_printable_conf (aconf
, &name
, &host
, &pass
,
455 &user
, &port
, &classname
);
457 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
458 form_str(RPL_STATSDLINE
),
459 'e', host
, pass
, "", "");
466 stats_events_cb(char *str
, void *ptr
)
468 sendto_one_numeric(ptr
, RPL_STATSDEBUG
, "E :%s", str
);
472 stats_events (struct Client
*source_p
)
474 rb_dump_events(stats_events_cb
, source_p
);
478 stats_prop_klines(struct Client
*source_p
)
480 struct ConfItem
*aconf
;
482 char *user
, *host
, *pass
, *oper_reason
;
484 RB_DLINK_FOREACH(ptr
, prop_bans
.head
)
488 /* Skip non-klines and deactivated klines. */
489 if(aconf
->status
!= CONF_KILL
)
492 get_printable_kline(source_p
, aconf
, &host
, &pass
,
493 &user
, &oper_reason
);
495 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
496 form_str(RPL_STATSKLINE
),
497 'g', host
, user
, pass
,
498 oper_reason
? "|" : "",
499 oper_reason
? oper_reason
: "");
504 stats_hubleaf(struct Client
*source_p
)
506 struct remote_conf
*hub_p
;
509 if((ConfigFileEntry
.stats_h_oper_only
||
510 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
513 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
514 form_str (ERR_NOPRIVILEGES
));
518 RB_DLINK_FOREACH(ptr
, hubleaf_conf_list
.head
)
522 if(hub_p
->flags
& CONF_HUB
)
523 sendto_one_numeric(source_p
, RPL_STATSHLINE
,
524 form_str(RPL_STATSHLINE
),
525 hub_p
->host
, hub_p
->server
);
527 sendto_one_numeric(source_p
, RPL_STATSLLINE
,
528 form_str(RPL_STATSLLINE
),
529 hub_p
->host
, hub_p
->server
);
535 stats_auth (struct Client
*source_p
)
537 /* Oper only, if unopered, return ERR_NOPRIVS */
538 if((ConfigFileEntry
.stats_i_oper_only
== 2) && !IsOper (source_p
))
539 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
540 form_str (ERR_NOPRIVILEGES
));
542 /* If unopered, Only return matching auth blocks */
543 else if((ConfigFileEntry
.stats_i_oper_only
== 1) && !IsOper (source_p
))
545 struct ConfItem
*aconf
;
546 char *name
, *host
, *user
, *classname
;
547 const char *pass
= "*";
550 if(MyConnect (source_p
))
551 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
552 (struct sockaddr
*)&source_p
->localClient
->ip
,
554 source_p
->localClient
->ip
.ss_family
,
555 source_p
->username
, NULL
);
557 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_CLIENT
,
558 0, source_p
->username
, NULL
);
563 get_printable_conf (aconf
, &name
, &host
, &pass
, &user
, &port
, &classname
);
564 if(!EmptyString(aconf
->spasswd
))
565 pass
= aconf
->spasswd
;
567 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
568 name
, pass
, show_iline_prefix(source_p
, aconf
, user
),
569 host
, port
, classname
);
572 /* Theyre opered, or allowed to see all auth blocks */
574 report_auth (source_p
);
579 stats_tklines(struct Client
*source_p
)
581 /* Oper only, if unopered, return ERR_NOPRIVS */
582 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
583 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
584 form_str (ERR_NOPRIVILEGES
));
586 /* If unopered, Only return matching klines */
587 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
589 struct ConfItem
*aconf
;
590 char *host
, *pass
, *user
, *oper_reason
;
592 if(MyConnect (source_p
))
593 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
594 (struct sockaddr
*)&source_p
->localClient
->ip
,
596 source_p
->localClient
->ip
.ss_family
,
597 source_p
->username
, NULL
);
599 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
600 0, source_p
->username
, NULL
);
605 /* dont report a permanent kline as a tkline */
606 if((aconf
->flags
& CONF_FLAGS_TEMPORARY
) == 0)
609 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
611 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
612 form_str(RPL_STATSKLINE
), aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
613 host
, user
, pass
, oper_reason
? "|" : "",
614 oper_reason
? oper_reason
: "");
616 /* Theyre opered, or allowed to see all klines */
619 struct ConfItem
*aconf
;
622 char *user
, *host
, *pass
, *oper_reason
;
624 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
626 RB_DLINK_FOREACH(ptr
, temp_klines
[i
].head
)
630 get_printable_kline(source_p
, aconf
, &host
, &pass
,
631 &user
, &oper_reason
);
633 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
634 form_str(RPL_STATSKLINE
),
635 'k', host
, user
, pass
,
636 oper_reason
? "|" : "",
637 oper_reason
? oper_reason
: "");
645 * inputs - Client to report to, mask
647 * side effects - Reports configured K-lines to client_p.
650 report_Klines(struct Client
*source_p
)
652 char *host
, *pass
, *user
, *oper_reason
;
653 struct AddressRec
*arec
;
654 struct ConfItem
*aconf
= NULL
;
657 for (i
= 0; i
< ATABLE_SIZE
; i
++)
659 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
661 if(arec
->type
== CONF_KILL
)
665 /* its a tempkline, theyre reported elsewhere */
666 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
669 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
670 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
671 form_str(RPL_STATSKLINE
),
672 'K', host
, user
, pass
,
673 oper_reason
? "|" : "",
674 oper_reason
? oper_reason
: "");
681 stats_klines(struct Client
*source_p
)
683 /* Oper only, if unopered, return ERR_NOPRIVS */
684 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
685 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
686 form_str (ERR_NOPRIVILEGES
));
688 /* If unopered, Only return matching klines */
689 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
691 struct ConfItem
*aconf
;
692 char *host
, *pass
, *user
, *oper_reason
;
694 /* search for a kline */
695 if(MyConnect (source_p
))
696 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
697 (struct sockaddr
*)&source_p
->localClient
->ip
,
699 source_p
->localClient
->ip
.ss_family
,
700 source_p
->username
, NULL
);
702 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
703 0, source_p
->username
, NULL
);
708 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
710 sendto_one_numeric(source_p
, RPL_STATSKLINE
, form_str(RPL_STATSKLINE
),
711 aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
712 host
, user
, pass
, oper_reason
? "|" : "",
713 oper_reason
? oper_reason
: "");
715 /* Theyre opered, or allowed to see all klines */
717 report_Klines (source_p
);
721 stats_messages(struct Client
*source_p
)
723 struct DictionaryIter iter
;
725 struct alias_entry
*amsg
;
727 DICTIONARY_FOREACH(msg
, &iter
, cmd_dict
)
729 s_assert(msg
->cmd
!= NULL
);
730 sendto_one_numeric(source_p
, RPL_STATSCOMMANDS
,
731 form_str(RPL_STATSCOMMANDS
),
732 msg
->cmd
, msg
->count
,
733 msg
->bytes
, msg
->rcount
);
736 DICTIONARY_FOREACH(amsg
, &iter
, alias_dict
)
738 s_assert(amsg
->name
!= NULL
);
739 sendto_one_numeric(source_p
, RPL_STATSCOMMANDS
,
740 form_str(RPL_STATSCOMMANDS
),
741 amsg
->name
, amsg
->hits
, 0L, 0);
746 stats_dnsbl(struct Client
*source_p
)
749 struct Blacklist
*blptr
;
751 RB_DLINK_FOREACH(ptr
, blacklist_list
.head
)
755 /* use RPL_STATSDEBUG for now -- jilles */
756 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "n :%d %s %s (%d)",
759 blptr
->status
& CONF_ILLEGAL
? "disabled" : "active",
765 stats_oper(struct Client
*source_p
)
767 struct oper_conf
*oper_p
;
770 if(!IsOper(source_p
) && ConfigFileEntry
.stats_o_oper_only
)
772 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
773 form_str (ERR_NOPRIVILEGES
));
777 RB_DLINK_FOREACH(ptr
, oper_conf_list
.head
)
781 sendto_one_numeric(source_p
, RPL_STATSOLINE
,
782 form_str(RPL_STATSOLINE
),
783 oper_p
->username
, oper_p
->host
, oper_p
->name
,
784 IsOper(source_p
) ? oper_p
->privset
->name
: "0", "-1");
789 stats_capability_walk(const char *line
, void *data
)
791 struct Client
*client_p
= data
;
793 sendto_one_numeric(client_p
, RPL_STATSDEBUG
, "C :%s", line
);
797 stats_capability(struct Client
*client_p
)
799 capability_index_stats(stats_capability_walk
, client_p
);
803 stats_privset(struct Client
*source_p
)
805 privilegeset_report(source_p
);
810 * input - client pointer
812 * side effects - client is shown a list of active opers
815 stats_operedup (struct Client
*source_p
)
817 struct Client
*target_p
;
818 rb_dlink_node
*oper_ptr
;
819 unsigned int count
= 0;
821 RB_DLINK_FOREACH (oper_ptr
, oper_list
.head
)
823 target_p
= oper_ptr
->data
;
825 if(IsOperInvis(target_p
) && !IsOper(source_p
))
828 if(target_p
->user
->away
)
833 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
835 target_p
->name
, target_p
->username
,
839 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
840 "p :%u staff members", count
);
842 stats_p_spy (source_p
);
846 stats_ports (struct Client
*source_p
)
848 if(!IsOper (source_p
) && ConfigFileEntry
.stats_P_oper_only
)
849 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
850 form_str (ERR_NOPRIVILEGES
));
852 show_ports (source_p
);
856 stats_tresv(struct Client
*source_p
)
858 struct ConfItem
*aconf
;
859 struct rb_radixtree_iteration_state state
;
863 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
867 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
868 form_str(RPL_STATSQLINE
),
869 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
872 RB_RADIXTREE_FOREACH(aconf
, &state
, resv_tree
)
875 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
876 form_str(RPL_STATSQLINE
),
877 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
883 stats_resv(struct Client
*source_p
)
885 struct ConfItem
*aconf
;
886 struct rb_radixtree_iteration_state state
;
890 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
894 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
895 form_str(RPL_STATSQLINE
),
896 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
899 RB_RADIXTREE_FOREACH(aconf
, &state
, resv_tree
)
902 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
903 form_str(RPL_STATSQLINE
),
904 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
909 stats_ssld_foreach(void *data
, pid_t pid
, int cli_count
, enum ssld_status status
, const char *version
)
911 struct Client
*source_p
= data
;
913 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
916 status
== SSLD_DEAD
? 'D' : (status
== SSLD_SHUTDOWN
? 'S' : 'A'),
922 stats_ssld(struct Client
*source_p
)
924 ssld_foreach_info(stats_ssld_foreach
, source_p
);
928 stats_usage (struct Client
*source_p
)
943 if(getrusage(RUSAGE_SELF
, &rus
) == -1)
945 sendto_one_notice(source_p
, ":Getruseage error: %s.",
949 secs
= rus
.ru_utime
.tv_sec
+ rus
.ru_stime
.tv_sec
;
953 rup
= (rb_current_time() - startup_time
) * hzz
;
957 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
958 "R :CPU Secs %d:%02d User %d:%02d System %d:%02d",
959 (int) (secs
/ 60), (int) (secs
% 60),
960 (int) (rus
.ru_utime
.tv_sec
/ 60),
961 (int) (rus
.ru_utime
.tv_sec
% 60),
962 (int) (rus
.ru_stime
.tv_sec
/ 60),
963 (int) (rus
.ru_stime
.tv_sec
% 60));
964 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
965 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
966 rus
.ru_maxrss
, (rus
.ru_ixrss
/ rup
),
967 (rus
.ru_idrss
/ rup
), (rus
.ru_isrss
/ rup
));
968 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
969 "R :Swaps %d Reclaims %d Faults %d",
970 (int) rus
.ru_nswap
, (int) rus
.ru_minflt
, (int) rus
.ru_majflt
);
971 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
972 "R :Block in %d out %d",
973 (int) rus
.ru_inblock
, (int) rus
.ru_oublock
);
974 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
975 "R :Msg Rcv %d Send %d",
976 (int) rus
.ru_msgrcv
, (int) rus
.ru_msgsnd
);
977 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
978 "R :Signals %d Context Vol. %d Invol %d",
979 (int) rus
.ru_nsignals
, (int) rus
.ru_nvcsw
,
980 (int) rus
.ru_nivcsw
);
984 stats_tstats (struct Client
*source_p
)
986 struct Client
*target_p
;
987 struct ServerStatistics sp
;
990 memcpy(&sp
, &ServerStats
, sizeof(struct ServerStatistics
));
992 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
994 target_p
= ptr
->data
;
996 sp
.is_sbs
+= target_p
->localClient
->sendB
;
997 sp
.is_sbr
+= target_p
->localClient
->receiveB
;
998 sp
.is_sti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
1002 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
1004 target_p
= ptr
->data
;
1006 sp
.is_cbs
+= target_p
->localClient
->sendB
;
1007 sp
.is_cbr
+= target_p
->localClient
->receiveB
;
1008 sp
.is_cti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
1012 RB_DLINK_FOREACH(ptr
, unknown_list
.head
)
1017 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1018 "T :accepts %u refused %u", sp
.is_ac
, sp
.is_ref
);
1019 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1020 "T :rejected %u delaying %lu",
1021 sp
.is_rej
, delay_exit_length());
1022 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1023 "T :throttled refused %u throttle list size %lu", sp
.is_thr
, throttle_size());
1024 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1025 "T :nicks being delayed %lu",
1027 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1028 "T :unknown commands %u prefixes %u",
1029 sp
.is_unco
, sp
.is_unpf
);
1030 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1031 "T :nick collisions %u saves %u unknown closes %u",
1032 sp
.is_kill
, sp
.is_save
, sp
.is_ni
);
1033 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1034 "T :wrong direction %u empty %u",
1035 sp
.is_wrdi
, sp
.is_empt
);
1036 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1037 "T :numerics seen %u", sp
.is_num
);
1038 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1039 "T :tgchange blocked msgs %u restricted addrs %lu",
1040 sp
.is_tgch
, rb_dlink_list_length(&tgchange_list
));
1041 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1042 "T :ratelimit blocked commands %u", sp
.is_rl
);
1043 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1044 "T :auth successes %u fails %u",
1045 sp
.is_asuc
, sp
.is_abad
);
1046 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1047 "T :sasl successes %u fails %u",
1048 sp
.is_ssuc
, sp
.is_sbad
);
1049 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "T :Client Server");
1050 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1051 "T :connected %u %u", sp
.is_cl
, sp
.is_sv
);
1052 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1053 "T :bytes sent %lluK %lluK",
1056 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1057 "T :bytes recv %lluK %lluK",
1060 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1061 "T :time connected %llu %llu",
1062 sp
.is_cti
, sp
.is_sti
);
1066 stats_uptime (struct Client
*source_p
)
1070 now
= rb_current_time() - startup_time
;
1071 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
1072 form_str (RPL_STATSUPTIME
),
1073 (int)(now
/ 86400), (int)((now
/ 3600) % 24),
1074 (int)((now
/ 60) % 60), (int)(now
% 60));
1075 sendto_one_numeric(source_p
, RPL_STATSCONN
,
1076 form_str (RPL_STATSCONN
),
1077 MaxConnectionCount
, MaxClientCount
,
1078 Count
.totalrestartcount
);
1086 static struct shared_flags shared_flagtable
[] =
1088 { SHARED_PKLINE
, 'K' },
1089 { SHARED_TKLINE
, 'k' },
1090 { SHARED_UNKLINE
, 'U' },
1091 { SHARED_PXLINE
, 'X' },
1092 { SHARED_TXLINE
, 'x' },
1093 { SHARED_UNXLINE
, 'Y' },
1094 { SHARED_PRESV
, 'Q' },
1095 { SHARED_TRESV
, 'q' },
1096 { SHARED_UNRESV
, 'R' },
1097 { SHARED_LOCOPS
, 'L' },
1098 { SHARED_REHASH
, 'H' },
1099 { SHARED_TDLINE
, 'd' },
1100 { SHARED_PDLINE
, 'D' },
1101 { SHARED_UNDLINE
, 'E' },
1102 { SHARED_GRANT
, 'G' },
1103 { SHARED_DIE
, 'I' },
1109 stats_shared (struct Client
*source_p
)
1111 struct remote_conf
*shared_p
;
1113 char buf
[sizeof(shared_flagtable
)/sizeof(shared_flagtable
[0])];
1117 RB_DLINK_FOREACH(ptr
, shared_conf_list
.head
)
1119 shared_p
= ptr
->data
;
1125 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1127 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1128 *p
++ = shared_flagtable
[i
].letter
;
1133 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1134 form_str(RPL_STATSULINE
),
1135 shared_p
->server
, shared_p
->username
,
1136 shared_p
->host
, buf
);
1139 RB_DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
1141 shared_p
= ptr
->data
;
1147 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1149 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1150 *p
++ = shared_flagtable
[i
].letter
;
1155 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1156 form_str(RPL_STATSULINE
),
1157 shared_p
->server
, "*", "*", buf
);
1163 * input - client pointer
1165 * side effects - client is shown lists of who connected servers
1168 stats_servers (struct Client
*source_p
)
1170 struct Client
*target_p
;
1173 int days
, hours
, minutes
;
1176 if(ConfigServerHide
.flatten_links
&& !IsOper(source_p
) &&
1177 !IsExemptShide(source_p
))
1179 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1180 form_str (ERR_NOPRIVILEGES
));
1184 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1186 target_p
= ptr
->data
;
1189 seconds
= rb_current_time() - target_p
->localClient
->firsttime
;
1191 days
= (int) (seconds
/ 86400);
1193 hours
= (int) (seconds
/ 3600);
1195 minutes
= (int) (seconds
/ 60);
1198 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1199 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1200 "Connected: %d day%s, %d:%02d:%02d",
1202 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
1203 (int) (rb_current_time() - target_p
->localClient
->lasttime
),
1204 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1205 days
, (days
== 1) ? "" : "s", hours
, minutes
,
1209 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1210 "V :%d Server(s)", j
);
1214 stats_tgecos(struct Client
*source_p
)
1216 struct ConfItem
*aconf
;
1219 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1224 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1225 form_str(RPL_STATSXLINE
),
1226 'x', aconf
->port
, aconf
->host
,
1232 stats_gecos(struct Client
*source_p
)
1234 struct ConfItem
*aconf
;
1237 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1242 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1243 form_str(RPL_STATSXLINE
),
1244 'X', aconf
->port
, aconf
->host
,
1250 stats_class(struct Client
*source_p
)
1252 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOper(source_p
))
1253 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1254 form_str (ERR_NOPRIVILEGES
));
1256 report_classes(source_p
);
1260 stats_memory (struct Client
*source_p
)
1262 struct Client
*target_p
;
1263 struct Channel
*chptr
;
1264 rb_dlink_node
*rb_dlink
;
1266 int channel_count
= 0;
1267 int local_client_conf_count
= 0; /* local client conf links */
1268 int users_counted
= 0; /* user structs */
1270 int channel_users
= 0;
1271 int channel_invites
= 0;
1272 int channel_bans
= 0;
1273 int channel_except
= 0;
1274 int channel_invex
= 0;
1275 int channel_quiets
= 0;
1277 int class_count
= 0; /* classes */
1278 int conf_count
= 0; /* conf lines */
1279 int users_invited_count
= 0; /* users invited */
1280 int user_channels
= 0; /* users in channels */
1281 int aways_counted
= 0;
1282 size_t number_servers_cached
; /* number of servers cached by scache */
1284 size_t channel_memory
= 0;
1285 size_t channel_ban_memory
= 0;
1286 size_t channel_except_memory
= 0;
1287 size_t channel_invex_memory
= 0;
1288 size_t channel_quiet_memory
= 0;
1290 size_t away_memory
= 0; /* memory used by aways */
1291 size_t ww
= 0; /* whowas array count */
1292 size_t wwm
= 0; /* whowas array memory used */
1293 size_t conf_memory
= 0; /* memory used by conf lines */
1294 size_t mem_servers_cached
; /* memory used by scache */
1296 size_t linebuf_count
= 0;
1297 size_t linebuf_memory_used
= 0;
1299 size_t total_channel_memory
= 0;
1302 size_t local_client_count
= 0;
1303 size_t local_client_memory_used
= 0;
1305 size_t remote_client_count
= 0;
1306 size_t remote_client_memory_used
= 0;
1308 size_t total_memory
= 0;
1310 whowas_memory_usage(&ww
, &wwm
);
1312 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
1314 target_p
= ptr
->data
;
1315 if(MyConnect(target_p
))
1317 local_client_conf_count
++;
1323 users_invited_count
+= rb_dlink_list_length(&target_p
->user
->invited
);
1324 user_channels
+= rb_dlink_list_length(&target_p
->user
->channel
);
1325 if(target_p
->user
->away
)
1328 away_memory
+= (strlen(target_p
->user
->away
) + 1);
1333 /* Count up all channels, ban lists, except lists, Invex lists */
1334 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
1338 channel_memory
+= (strlen(chptr
->chname
) + sizeof(struct Channel
));
1340 channel_users
+= rb_dlink_list_length(&chptr
->members
);
1341 channel_invites
+= rb_dlink_list_length(&chptr
->invites
);
1343 RB_DLINK_FOREACH(rb_dlink
, chptr
->banlist
.head
)
1347 channel_ban_memory
+= sizeof(rb_dlink_node
) + sizeof(struct Ban
);
1350 RB_DLINK_FOREACH(rb_dlink
, chptr
->exceptlist
.head
)
1354 channel_except_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1357 RB_DLINK_FOREACH(rb_dlink
, chptr
->invexlist
.head
)
1361 channel_invex_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1364 RB_DLINK_FOREACH(rb_dlink
, chptr
->quietlist
.head
)
1368 channel_quiet_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1372 /* count up all classes */
1374 class_count
= rb_dlink_list_length(&class_list
) + 1;
1376 rb_count_rb_linebuf_memory(&linebuf_count
, &linebuf_memory_used
);
1378 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1379 "z :Users %u(%lu) Invites %u(%lu)",
1381 (unsigned long) users_counted
* sizeof(struct User
),
1382 users_invited_count
,
1383 (unsigned long) users_invited_count
* sizeof(rb_dlink_node
));
1385 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1386 "z :User channels %u(%lu) Aways %u(%d)",
1388 (unsigned long) user_channels
* sizeof(rb_dlink_node
),
1389 aways_counted
, (int) away_memory
);
1391 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1392 "z :Attached confs %u(%lu)",
1393 local_client_conf_count
,
1394 (unsigned long) local_client_conf_count
* sizeof(rb_dlink_node
));
1396 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1397 "z :Conflines %u(%d)", conf_count
, (int) conf_memory
);
1399 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1400 "z :Classes %u(%lu)",
1402 (unsigned long) class_count
* sizeof(struct Class
));
1404 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1405 "z :Channels %u(%d)",
1406 channel_count
, (int) channel_memory
);
1408 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1409 "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)",
1410 channel_bans
, (int) channel_ban_memory
,
1411 channel_except
, (int) channel_except_memory
,
1412 channel_invex
, (int) channel_invex_memory
,
1413 channel_quiets
, (int) channel_quiet_memory
);
1415 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1416 "z :Channel members %u(%lu) invite %u(%lu)",
1418 (unsigned long) channel_users
* sizeof(rb_dlink_node
),
1420 (unsigned long) channel_invites
* sizeof(rb_dlink_node
));
1422 total_channel_memory
= channel_memory
+
1423 channel_ban_memory
+
1424 channel_users
* sizeof(rb_dlink_node
) + channel_invites
* sizeof(rb_dlink_node
);
1426 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1427 "z :Whowas array %ld(%ld)",
1428 (long)ww
, (long)wwm
);
1432 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1433 "z :Hash: client %u(%ld) chan %u(%ld)",
1434 U_MAX
, (long)(U_MAX
* sizeof(rb_dlink_list
)),
1435 CH_MAX
, (long)(CH_MAX
* sizeof(rb_dlink_list
)));
1437 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1438 "z :linebuf %ld(%ld)",
1439 (long)linebuf_count
, (long)linebuf_memory_used
);
1441 count_scache(&number_servers_cached
, &mem_servers_cached
);
1443 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1444 "z :scache %ld(%ld)",
1445 (long)number_servers_cached
, (long)mem_servers_cached
);
1447 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1448 "z :hostname hash %d(%ld)",
1449 HOST_MAX
, (long)HOST_MAX
* sizeof(rb_dlink_list
));
1451 total_memory
= totww
+ total_channel_memory
+ conf_memory
+
1452 class_count
* sizeof(struct Class
);
1454 total_memory
+= mem_servers_cached
;
1455 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1456 "z :Total: whowas %d channel %d conf %d",
1457 (int) totww
, (int) total_channel_memory
,
1460 count_local_client_memory(&local_client_count
, &local_client_memory_used
);
1461 total_memory
+= local_client_memory_used
;
1463 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1464 "z :Local client Memory in use: %ld(%ld)",
1465 (long)local_client_count
, (long)local_client_memory_used
);
1468 count_remote_client_memory(&remote_client_count
, &remote_client_memory_used
);
1469 total_memory
+= remote_client_memory_used
;
1471 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1472 "z :Remote client Memory in use: %ld(%ld)",
1473 (long)remote_client_count
,
1474 (long)remote_client_memory_used
);
1478 stats_ziplinks (struct Client
*source_p
)
1481 struct Client
*target_p
;
1482 struct ZipStats
*zipstats
;
1484 char buf
[128], buf1
[128];
1485 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1487 target_p
= ptr
->data
;
1488 if(IsCapable (target_p
, CAP_ZIP
))
1490 zipstats
= target_p
->localClient
->zipstats
;
1491 sprintf(buf
, "%.2f%%", zipstats
->out_ratio
);
1492 sprintf(buf1
, "%.2f%%", zipstats
->in_ratio
);
1493 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1494 "Z :ZipLinks stats for %s send[%s compression "
1495 "(%llu kB data/%llu kB wire)] recv[%s compression "
1496 "(%llu kB data/%llu kB wire)]",
1498 buf
, zipstats
->out
>> 10,
1499 zipstats
->out_wire
>> 10, buf1
,
1500 zipstats
->in
>> 10, zipstats
->in_wire
>> 10);
1505 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1506 "Z :%u ziplink(s)", sent_data
);
1510 stats_servlinks (struct Client
*source_p
)
1512 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1513 long uptime
, sendK
, receiveK
;
1514 struct Client
*target_p
;
1519 if(ConfigServerHide
.flatten_links
&& !IsOper (source_p
) &&
1520 !IsExemptShide(source_p
))
1522 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1523 form_str (ERR_NOPRIVILEGES
));
1527 sendK
= receiveK
= 0;
1529 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1531 target_p
= ptr
->data
;
1534 sendK
+= target_p
->localClient
->sendK
;
1535 receiveK
+= target_p
->localClient
->receiveK
;
1537 sendto_one(source_p
, Sformat
,
1538 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1540 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1541 (int) target_p
->localClient
->sendM
,
1542 (int) target_p
->localClient
->sendK
,
1543 (int) target_p
->localClient
->receiveM
,
1544 (int) target_p
->localClient
->receiveK
,
1545 rb_current_time() - target_p
->localClient
->firsttime
,
1546 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1547 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1548 IsOper (source_p
) ? show_capabilities (target_p
) : "TS");
1551 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1552 "? :%u total server(s)", j
);
1554 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((sendK
)));
1555 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1556 "? :Sent total : %s %s",
1557 buf
, _GMKs (sendK
));
1558 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((receiveK
)));
1559 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1560 "? :Recv total : %s %s",
1561 buf
, _GMKs (receiveK
));
1563 uptime
= (rb_current_time() - startup_time
);
1564 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1565 _GMKv (me
.localClient
->sendK
),
1566 _GMKs (me
.localClient
->sendK
),
1567 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1568 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server send: %s", buf
);
1569 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1570 _GMKv (me
.localClient
->receiveK
),
1571 _GMKs (me
.localClient
->receiveK
),
1572 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1573 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server recv: %s", buf
);
1577 stats_l_should_show_oper(struct Client
*target_p
)
1579 if (IsOperInvis(target_p
))
1586 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1591 char statchar
= parv
[1][0];
1593 /* this is def targeted at us somehow.. */
1594 if(parc
> 2 && !EmptyString(parv
[2]))
1596 /* directed at us generically? */
1597 if(match(parv
[2], me
.name
) ||
1598 (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1606 wilds
= strchr(name
, '*') || strchr(name
, '?');
1609 /* must be directed at a specific person thats not us */
1610 if(!doall
&& !wilds
)
1612 struct Client
*target_p
;
1614 if(MyClient(source_p
))
1615 target_p
= find_named_person(name
);
1617 target_p
= find_person(name
);
1619 if(target_p
!= NULL
)
1621 stats_spy(source_p
, statchar
, target_p
->name
);
1622 stats_l_client(source_p
, target_p
, statchar
);
1625 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1626 form_str(ERR_NOSUCHSERVER
),
1638 stats_spy(source_p
, statchar
, name
);
1642 /* local opers get everyone */
1643 if(MyOper(source_p
))
1645 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
, NULL
);
1646 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1650 /* they still need themselves if theyre local.. */
1651 if(MyClient(source_p
))
1652 stats_l_client(source_p
, source_p
, statchar
);
1654 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
, stats_l_should_show_oper
);
1657 if (!ConfigServerHide
.flatten_links
|| IsOper(source_p
) ||
1658 IsExemptShide(source_p
))
1659 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
, NULL
);
1664 /* ok, at this point theyre looking for a specific client whos on
1665 * our server.. but it contains a wildcard. --fl
1667 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1673 stats_l_list(struct Client
*source_p
, const char *name
, int doall
, int wilds
,
1674 rb_dlink_list
* list
, char statchar
, int (*check_fn
)(struct Client
*target_p
))
1677 struct Client
*target_p
;
1679 /* send information about connections which match. note, we
1680 * dont need tests for IsInvisible(), because non-opers will
1681 * never get here for normal clients --fl
1683 RB_DLINK_FOREACH(ptr
, list
->head
)
1685 target_p
= ptr
->data
;
1687 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1690 if (check_fn
== NULL
|| check_fn(target_p
))
1691 stats_l_client(source_p
, target_p
, statchar
);
1696 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1699 if(IsAnyServer(target_p
))
1701 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1703 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1704 (int) target_p
->localClient
->sendM
,
1705 (int) target_p
->localClient
->sendK
,
1706 (int) target_p
->localClient
->receiveM
,
1707 (int) target_p
->localClient
->receiveK
,
1708 rb_current_time() - target_p
->localClient
->firsttime
,
1709 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1710 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1711 IsOper(source_p
) ? show_capabilities(target_p
) : "-");
1716 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1717 show_ip(source_p
, target_p
) ?
1718 (IsUpper(statchar
) ?
1719 get_client_name(target_p
, SHOW_IP
) :
1720 get_client_name(target_p
, HIDE_IP
)) :
1721 get_client_name(target_p
, MASK_IP
),
1722 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1723 (int) target_p
->localClient
->sendM
,
1724 (int) target_p
->localClient
->sendK
,
1725 (int) target_p
->localClient
->receiveM
,
1726 (int) target_p
->localClient
->receiveK
,
1727 rb_current_time() - target_p
->localClient
->firsttime
,
1728 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1729 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1735 rb_dump_fd_callback(int fd
, const char *desc
, void *data
)
1737 struct Client
*source_p
= data
;
1738 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "F :fd %-3d desc '%s'", fd
, desc
);
1742 stats_comm(struct Client
*source_p
)
1744 rb_dump_fd(rb_dump_fd_callback
, source_p
);
1750 * inputs - pointer to client doing the /stats
1751 * - char letter they are doing /stats on
1754 * This little helper function reports to opers if configured.
1755 * personally, I don't see why opers need to see stats requests
1756 * at all. They are just "noise" to an oper, and users can't do
1757 * any damage with stats requests now anyway. So, why show them?
1761 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1765 data
.client
= source_p
;
1767 data
.arg2
= (int) statchar
;
1770 call_hook(doing_stats_hook
, &data
);
1777 * input - pointer to client doing stats
1779 * side effects - call hook doing_stats_p
1782 stats_p_spy (struct Client
*source_p
)
1786 data
.client
= source_p
;
1787 data
.arg1
= data
.arg2
= NULL
;
1789 call_hook(doing_stats_p_hook
, &data
);