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_hubleaf(struct Client
*);
108 static void stats_auth(struct Client
*);
109 static void stats_tklines(struct Client
*);
110 static void stats_klines(struct Client
*);
111 static void stats_messages(struct Client
*);
112 static void stats_dnsbl(struct Client
*);
113 static void stats_oper(struct Client
*);
114 static void stats_privset(struct Client
*);
115 static void stats_operedup(struct Client
*);
116 static void stats_ports(struct Client
*);
117 static void stats_tresv(struct Client
*);
118 static void stats_resv(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_shared(struct Client
*);
124 static void stats_servers(struct Client
*);
125 static void stats_tgecos(struct Client
*);
126 static void stats_gecos(struct Client
*);
127 static void stats_class(struct Client
*);
128 static void stats_memory(struct Client
*);
129 static void stats_servlinks(struct Client
*);
130 static void stats_ltrace(struct Client
*, int, const char **);
131 static void stats_ziplinks(struct Client
*);
132 static void stats_comm(struct Client
*);
133 static void stats_capability(struct Client
*);
135 #define HANDLER_NORM(fn, admin, priv) \
136 { { .handler = fn }, .need_parv = false, .need_priv = priv, .need_admin = admin }
137 #define HANDLER_PARV(fn, admin, priv) \
138 { { .handler_parv = fn }, .need_parv = true, .need_priv = priv, .need_admin = admin }
140 /* This table contains the possible stats items, in order:
141 * stats letter, function to call, operonly? adminonly? --fl_
143 * Previously in this table letters were a column. I fixed it to use modern
144 * C initalisers so we don't have to iterate anymore
147 static struct stats_cmd stats_cmd_table
[256] = {
148 /* letter handler admin priv */
149 ['a'] = HANDLER_NORM(stats_dns_servers
, true, NULL
),
150 ['A'] = HANDLER_NORM(stats_dns_servers
, true, NULL
),
151 ['b'] = HANDLER_NORM(stats_delay
, true, NULL
),
152 ['B'] = HANDLER_NORM(stats_hash
, true, NULL
),
153 ['c'] = HANDLER_NORM(stats_connect
, false, NULL
),
154 ['C'] = HANDLER_NORM(stats_capability
, false, "oper:general"),
155 ['d'] = HANDLER_NORM(stats_tdeny
, false, "oper:general"),
156 ['D'] = HANDLER_NORM(stats_deny
, false, "oper:general"),
157 ['e'] = HANDLER_NORM(stats_exempt
, false, "oper:general"),
158 ['E'] = HANDLER_NORM(stats_events
, true, NULL
),
159 ['f'] = HANDLER_NORM(stats_comm
, true, NULL
),
160 ['F'] = HANDLER_NORM(stats_comm
, true, NULL
),
161 ['g'] = HANDLER_NORM(stats_prop_klines
, false, "oper:general"),
162 ['h'] = HANDLER_NORM(stats_hubleaf
, false, NULL
),
163 ['H'] = HANDLER_NORM(stats_hubleaf
, false, NULL
),
164 ['i'] = HANDLER_NORM(stats_auth
, false, NULL
),
165 ['I'] = HANDLER_NORM(stats_auth
, false, NULL
),
166 ['k'] = HANDLER_NORM(stats_tklines
, false, NULL
),
167 ['K'] = HANDLER_NORM(stats_klines
, false, NULL
),
168 ['l'] = HANDLER_PARV(stats_ltrace
, false, NULL
),
169 ['L'] = HANDLER_PARV(stats_ltrace
, false, NULL
),
170 ['m'] = HANDLER_NORM(stats_messages
, false, NULL
),
171 ['M'] = HANDLER_NORM(stats_messages
, false, NULL
),
172 ['n'] = HANDLER_NORM(stats_dnsbl
, false, NULL
),
173 ['o'] = HANDLER_NORM(stats_oper
, false, NULL
),
174 ['O'] = HANDLER_NORM(stats_privset
, false, "oper:privs"),
175 ['p'] = HANDLER_NORM(stats_operedup
, false, NULL
),
176 ['P'] = HANDLER_NORM(stats_ports
, false, NULL
),
177 ['q'] = HANDLER_NORM(stats_tresv
, false, "oper:general"),
178 ['Q'] = HANDLER_NORM(stats_resv
, false, "oper:general"),
179 ['r'] = HANDLER_NORM(stats_usage
, false, "oper:general"),
180 ['R'] = HANDLER_NORM(stats_usage
, false, "oper:general"),
181 ['s'] = HANDLER_NORM(stats_ssld
, true, NULL
),
182 ['S'] = HANDLER_NORM(stats_ssld
, true, NULL
),
183 ['t'] = HANDLER_NORM(stats_tstats
, false, "oper:general"),
184 ['T'] = HANDLER_NORM(stats_tstats
, false, "oper:general"),
185 ['u'] = HANDLER_NORM(stats_uptime
, false, NULL
),
186 ['U'] = HANDLER_NORM(stats_shared
, false, "oper:general"),
187 ['v'] = HANDLER_NORM(stats_servers
, false, NULL
),
188 ['V'] = HANDLER_NORM(stats_servers
, false, NULL
),
189 ['x'] = HANDLER_NORM(stats_tgecos
, false, "oper:general"),
190 ['X'] = HANDLER_NORM(stats_gecos
, false, "oper:general"),
191 ['y'] = HANDLER_NORM(stats_class
, false, NULL
),
192 ['Y'] = HANDLER_NORM(stats_class
, false, NULL
),
193 ['z'] = HANDLER_NORM(stats_memory
, false, "oper:general"),
194 ['Z'] = HANDLER_NORM(stats_ziplinks
, false, "oper:general"),
195 ['?'] = HANDLER_NORM(stats_servlinks
, false, NULL
),
200 * Modified heavily by Elizafox
201 * parv[1] = stat letter/command
202 * parv[2] = (if present) server/mask in stats L, or target
204 * This will search the tables for the appropriate stats letter,
205 * if found execute it.
208 m_stats(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
210 static time_t last_used
= 0;
211 struct stats_cmd
*cmd
;
212 unsigned char statchar
;
215 statchar
= parv
[1][0];
217 if(MyClient(source_p
) && !IsOperGeneral(source_p
) && parc
> 2)
219 /* Check the user is actually allowed to do /stats, and isnt flooding */
220 if((last_used
+ ConfigFileEntry
.pace_wait
) > rb_current_time())
222 /* safe enough to give this on a local connect only */
223 sendto_one(source_p
, form_str(RPL_LOAD2HI
),
224 me
.name
, source_p
->name
, "STATS");
225 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
226 form_str(RPL_ENDOFSTATS
), statchar
);
230 last_used
= rb_current_time();
233 if(hunt_server(client_p
, source_p
, ":%s STATS %s :%s", 2, parc
, parv
) != HUNTED_ISME
)
236 if(tolower(statchar
) != 'l')
238 did_stats
= stats_spy(source_p
, statchar
, NULL
);
240 /* if did_stats is true, a module grabbed this STATS request */
245 cmd
= &stats_cmd_table
[statchar
];
246 if(cmd
->handler
!= NULL
)
248 /* The stats table says what privs are needed, so check --fl_ */
249 const char *missing_priv
= NULL
;
250 if(cmd
->need_admin
&& !IsOperAdmin(source_p
))
251 missing_priv
= "admin";
252 else if(cmd
->need_priv
&& !HasPrivilege(source_p
, cmd
->need_priv
))
253 missing_priv
= cmd
->need_priv
;
255 if(missing_priv
!= NULL
)
257 if(!IsOper(source_p
))
259 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
260 form_str(ERR_NOPRIVILEGES
));
264 if(!strncmp(missing_priv
, "oper:", 5))
266 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
267 me
.name
, source_p
->name
, missing_priv
);
273 cmd
->handler_parv(source_p
, parc
, parv
);
275 cmd
->handler(source_p
);
279 /* Send the end of stats notice, and the stats_spy */
280 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
281 form_str(RPL_ENDOFSTATS
), statchar
);
285 stats_dns_servers (struct Client
*source_p
)
289 RB_DLINK_FOREACH(n
, nameservers
.head
)
291 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "A %s", (char *)n
->data
);
296 stats_delay(struct Client
*source_p
)
299 rb_dictionary_iter iter
;
301 RB_DICTIONARY_FOREACH(nd
, &iter
, nd_dict
)
303 sendto_one_notice(source_p
, ":Delaying: %s for %ld",
304 nd
->name
, (long) nd
->expire
);
309 stats_hash_cb(const char *buf
, void *client_p
)
311 sendto_one_numeric(client_p
, RPL_STATSDEBUG
, "B :%s", buf
);
315 stats_hash(struct Client
*source_p
)
317 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "B :%-30s %-15s %-10s %-10s %-10s %-10s",
318 "NAME", "TYPE", "OBJECTS", "DEPTH SUM", "AVG DEPTH", "MAX DEPTH");
320 rb_dictionary_stats_walk(stats_hash_cb
, source_p
);
321 rb_radixtree_stats_walk(stats_hash_cb
, source_p
);
325 stats_connect(struct Client
*source_p
)
327 static char buf
[BUFSIZE
];
328 struct server_conf
*server_p
;
332 if((ConfigFileEntry
.stats_c_oper_only
||
333 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
334 !IsOperGeneral(source_p
))
336 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
337 form_str(ERR_NOPRIVILEGES
));
341 RB_DLINK_FOREACH(ptr
, server_conf_list
.head
)
343 server_p
= ptr
->data
;
345 if(ServerConfIllegal(server_p
))
350 if(IsOperGeneral(source_p
))
352 if(ServerConfAutoconn(server_p
))
354 if(ServerConfSCTP(server_p
))
356 if(ServerConfSSL(server_p
))
358 if(ServerConfTb(server_p
))
360 if(ServerConfCompressed(server_p
))
369 sendto_one_numeric(source_p
, RPL_STATSCLINE
,
370 form_str(RPL_STATSCLINE
),
373 server_p
->port
, server_p
->class_name
,
374 server_p
->certfp
? server_p
->certfp
: "*");
380 * input - client to report to
382 * side effects - client is given temp dline list.
385 stats_tdeny (struct Client
*source_p
)
387 char *host
, *pass
, *user
, *oper_reason
;
388 struct AddressRec
*arec
;
389 struct ConfItem
*aconf
;
392 for (i
= 0; i
< ATABLE_SIZE
; i
++)
394 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
396 if(arec
->type
== CONF_DLINE
)
400 if(!(aconf
->flags
& CONF_FLAGS_TEMPORARY
))
403 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
405 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
406 form_str (RPL_STATSDLINE
),
408 oper_reason
? "|" : "",
409 oper_reason
? oper_reason
: "");
417 * input - client to report to
419 * side effects - client is given dline list.
422 stats_deny (struct Client
*source_p
)
424 char *host
, *pass
, *user
, *oper_reason
;
425 struct AddressRec
*arec
;
426 struct ConfItem
*aconf
;
429 for (i
= 0; i
< ATABLE_SIZE
; i
++)
431 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
433 if(arec
->type
== CONF_DLINE
)
437 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
440 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
442 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
443 form_str (RPL_STATSDLINE
),
445 oper_reason
? "|" : "",
446 oper_reason
? oper_reason
: "");
455 * input - client to report to
457 * side effects - client is given list of exempt blocks
460 stats_exempt(struct Client
*source_p
)
462 char *name
, *host
, *user
, *classname
;
464 struct AddressRec
*arec
;
465 struct ConfItem
*aconf
;
468 if(ConfigFileEntry
.stats_e_disabled
)
470 sendto_one_numeric(source_p
, ERR_DISABLED
,
471 form_str(ERR_DISABLED
), "STATS e");
475 for (i
= 0; i
< ATABLE_SIZE
; i
++)
477 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
479 if(arec
->type
== CONF_EXEMPTDLINE
)
482 get_printable_conf (aconf
, &name
, &host
, &pass
,
483 &user
, &port
, &classname
);
485 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
486 form_str(RPL_STATSDLINE
),
487 'e', host
, pass
, "", "");
494 stats_events_cb(char *str
, void *ptr
)
496 sendto_one_numeric(ptr
, RPL_STATSDEBUG
, "E :%s", str
);
500 stats_events (struct Client
*source_p
)
502 rb_dump_events(stats_events_cb
, source_p
);
506 stats_prop_klines(struct Client
*source_p
)
508 struct ConfItem
*aconf
;
510 char *user
, *host
, *pass
, *oper_reason
;
512 RB_DLINK_FOREACH(ptr
, prop_bans
.head
)
516 /* Skip non-klines and deactivated klines. */
517 if(aconf
->status
!= CONF_KILL
)
520 get_printable_kline(source_p
, aconf
, &host
, &pass
,
521 &user
, &oper_reason
);
523 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
524 form_str(RPL_STATSKLINE
),
525 'g', host
, user
, pass
,
526 oper_reason
? "|" : "",
527 oper_reason
? oper_reason
: "");
532 stats_hubleaf(struct Client
*source_p
)
534 struct remote_conf
*hub_p
;
537 if((ConfigFileEntry
.stats_h_oper_only
||
538 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
539 !IsOperGeneral(source_p
))
541 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
542 form_str (ERR_NOPRIVILEGES
));
546 RB_DLINK_FOREACH(ptr
, hubleaf_conf_list
.head
)
550 if(hub_p
->flags
& CONF_HUB
)
551 sendto_one_numeric(source_p
, RPL_STATSHLINE
,
552 form_str(RPL_STATSHLINE
),
553 hub_p
->host
, hub_p
->server
);
555 sendto_one_numeric(source_p
, RPL_STATSLLINE
,
556 form_str(RPL_STATSLLINE
),
557 hub_p
->host
, hub_p
->server
);
563 stats_auth (struct Client
*source_p
)
565 /* Oper only, if unopered, return ERR_NOPRIVS */
566 if((ConfigFileEntry
.stats_i_oper_only
== 2) && !IsOperGeneral (source_p
))
567 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
568 form_str (ERR_NOPRIVILEGES
));
570 /* If unopered, Only return matching auth blocks */
571 else if((ConfigFileEntry
.stats_i_oper_only
== 1) && !IsOperGeneral (source_p
))
573 struct ConfItem
*aconf
;
574 char *name
, *host
, *user
, *classname
;
575 const char *pass
= "*";
578 if(MyConnect (source_p
))
579 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
580 (struct sockaddr
*)&source_p
->localClient
->ip
,
582 GET_SS_FAMILY(&source_p
->localClient
->ip
),
583 source_p
->username
, NULL
);
585 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_CLIENT
,
586 0, source_p
->username
, NULL
);
591 get_printable_conf (aconf
, &name
, &host
, &pass
, &user
, &port
, &classname
);
592 if(!EmptyString(aconf
->spasswd
))
593 pass
= aconf
->spasswd
;
595 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
596 name
, pass
, show_iline_prefix(source_p
, aconf
, user
),
597 host
, port
, classname
);
600 /* Theyre opered, or allowed to see all auth blocks */
602 report_auth (source_p
);
607 stats_tklines(struct Client
*source_p
)
609 /* Oper only, if unopered, return ERR_NOPRIVS */
610 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOperGeneral (source_p
))
611 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
612 form_str (ERR_NOPRIVILEGES
));
614 /* If unopered, Only return matching klines */
615 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOperGeneral (source_p
))
617 struct ConfItem
*aconf
;
618 char *host
, *pass
, *user
, *oper_reason
;
620 if(MyConnect (source_p
))
621 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
622 (struct sockaddr
*)&source_p
->localClient
->ip
,
624 GET_SS_FAMILY(&source_p
->localClient
->ip
),
625 source_p
->username
, NULL
);
627 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
628 0, source_p
->username
, NULL
);
633 /* dont report a permanent kline as a tkline */
634 if((aconf
->flags
& CONF_FLAGS_TEMPORARY
) == 0)
637 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
639 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
640 form_str(RPL_STATSKLINE
), (aconf
->flags
& CONF_FLAGS_TEMPORARY
) ? 'k' : 'K',
641 host
, user
, pass
, oper_reason
? "|" : "",
642 oper_reason
? oper_reason
: "");
644 /* Theyre opered, or allowed to see all klines */
647 struct ConfItem
*aconf
;
650 char *user
, *host
, *pass
, *oper_reason
;
652 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
654 RB_DLINK_FOREACH(ptr
, temp_klines
[i
].head
)
658 get_printable_kline(source_p
, aconf
, &host
, &pass
,
659 &user
, &oper_reason
);
661 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
662 form_str(RPL_STATSKLINE
),
663 'k', host
, user
, pass
,
664 oper_reason
? "|" : "",
665 oper_reason
? oper_reason
: "");
673 * inputs - Client to report to, mask
675 * side effects - Reports configured K-lines to client_p.
678 report_Klines(struct Client
*source_p
)
680 char *host
, *pass
, *user
, *oper_reason
;
681 struct AddressRec
*arec
;
682 struct ConfItem
*aconf
= NULL
;
685 for (i
= 0; i
< ATABLE_SIZE
; i
++)
687 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
689 if(arec
->type
== CONF_KILL
)
693 /* its a tempkline, theyre reported elsewhere */
694 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
697 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
698 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
699 form_str(RPL_STATSKLINE
),
700 'K', host
, user
, pass
,
701 oper_reason
? "|" : "",
702 oper_reason
? oper_reason
: "");
709 stats_klines(struct Client
*source_p
)
711 /* Oper only, if unopered, return ERR_NOPRIVS */
712 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOperGeneral (source_p
))
713 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
714 form_str (ERR_NOPRIVILEGES
));
716 /* If unopered, Only return matching klines */
717 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOperGeneral (source_p
))
719 struct ConfItem
*aconf
;
720 char *host
, *pass
, *user
, *oper_reason
;
722 /* search for a kline */
723 if(MyConnect (source_p
))
724 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
725 (struct sockaddr
*)&source_p
->localClient
->ip
,
727 GET_SS_FAMILY(&source_p
->localClient
->ip
),
728 source_p
->username
, NULL
);
730 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
731 0, source_p
->username
, NULL
);
736 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
738 sendto_one_numeric(source_p
, RPL_STATSKLINE
, form_str(RPL_STATSKLINE
),
739 (aconf
->flags
& CONF_FLAGS_TEMPORARY
) ? 'k' : 'K',
740 host
, user
, pass
, oper_reason
? "|" : "",
741 oper_reason
? oper_reason
: "");
743 /* Theyre opered, or allowed to see all klines */
745 report_Klines (source_p
);
749 stats_messages(struct Client
*source_p
)
751 rb_dictionary_iter iter
;
754 RB_DICTIONARY_FOREACH(msg
, &iter
, cmd_dict
)
756 s_assert(msg
->cmd
!= NULL
);
757 sendto_one_numeric(source_p
, RPL_STATSCOMMANDS
,
758 form_str(RPL_STATSCOMMANDS
),
759 msg
->cmd
, msg
->count
,
760 msg
->bytes
, msg
->rcount
);
765 stats_dnsbl(struct Client
*source_p
)
767 rb_dictionary_iter iter
;
768 struct DNSBLEntryStats
*stats
;
770 if(dnsbl_stats
== NULL
)
773 RB_DICTIONARY_FOREACH(stats
, &iter
, dnsbl_stats
)
775 /* use RPL_STATSDEBUG for now -- jilles */
776 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "n :%d %s",
777 stats
->hits
, (const char *)iter
.cur
->key
);
782 stats_oper(struct Client
*source_p
)
784 struct oper_conf
*oper_p
;
787 if(!IsOperGeneral(source_p
) && ConfigFileEntry
.stats_o_oper_only
)
789 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
790 form_str (ERR_NOPRIVILEGES
));
794 RB_DLINK_FOREACH(ptr
, oper_conf_list
.head
)
798 sendto_one_numeric(source_p
, RPL_STATSOLINE
,
799 form_str(RPL_STATSOLINE
),
800 oper_p
->username
, oper_p
->host
, oper_p
->name
,
801 HasPrivilege(source_p
, "oper:privs") ? oper_p
->privset
->name
: "0", "-1");
806 stats_capability_walk(const char *line
, void *data
)
808 struct Client
*client_p
= data
;
810 sendto_one_numeric(client_p
, RPL_STATSDEBUG
, "C :%s", line
);
814 stats_capability(struct Client
*client_p
)
816 capability_index_stats(stats_capability_walk
, client_p
);
820 stats_privset(struct Client
*source_p
)
822 privilegeset_report(source_p
);
827 * input - client pointer
829 * side effects - client is shown a list of active opers
832 stats_operedup (struct Client
*source_p
)
834 struct Client
*target_p
;
835 rb_dlink_node
*oper_ptr
;
836 unsigned int count
= 0;
838 RB_DLINK_FOREACH (oper_ptr
, oper_list
.head
)
840 target_p
= oper_ptr
->data
;
842 if(!SeesOper(target_p
, source_p
))
845 if(target_p
->user
->away
)
850 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
852 target_p
->name
, target_p
->username
,
856 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
857 "p :%u staff members", count
);
859 stats_p_spy (source_p
);
863 stats_ports (struct Client
*source_p
)
865 if(!IsOperGeneral (source_p
) && ConfigFileEntry
.stats_P_oper_only
)
866 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
867 form_str (ERR_NOPRIVILEGES
));
869 show_ports (source_p
);
873 stats_tresv(struct Client
*source_p
)
875 struct ConfItem
*aconf
;
876 rb_radixtree_iteration_state state
;
879 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
883 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
884 form_str(RPL_STATSQLINE
),
885 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
888 RB_RADIXTREE_FOREACH(aconf
, &state
, resv_tree
)
891 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
892 form_str(RPL_STATSQLINE
),
893 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
899 stats_resv(struct Client
*source_p
)
901 struct ConfItem
*aconf
;
902 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
)
959 if(getrusage(RUSAGE_SELF
, &rus
) == -1)
961 sendto_one_notice(source_p
, ":Getruseage error: %s.",
965 secs
= rus
.ru_utime
.tv_sec
+ rus
.ru_stime
.tv_sec
;
969 rup
= (rb_current_time() - startup_time
) * hzz
;
973 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
974 "R :CPU Secs %d:%02d User %d:%02d System %d:%02d",
975 (int) (secs
/ 60), (int) (secs
% 60),
976 (int) (rus
.ru_utime
.tv_sec
/ 60),
977 (int) (rus
.ru_utime
.tv_sec
% 60),
978 (int) (rus
.ru_stime
.tv_sec
/ 60),
979 (int) (rus
.ru_stime
.tv_sec
% 60));
980 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
981 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
982 rus
.ru_maxrss
, (rus
.ru_ixrss
/ rup
),
983 (rus
.ru_idrss
/ rup
), (rus
.ru_isrss
/ rup
));
984 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
985 "R :Swaps %d Reclaims %d Faults %d",
986 (int) rus
.ru_nswap
, (int) rus
.ru_minflt
, (int) rus
.ru_majflt
);
987 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
988 "R :Block in %d out %d",
989 (int) rus
.ru_inblock
, (int) rus
.ru_oublock
);
990 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
991 "R :Msg Rcv %d Send %d",
992 (int) rus
.ru_msgrcv
, (int) rus
.ru_msgsnd
);
993 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
994 "R :Signals %d Context Vol. %d Invol %d",
995 (int) rus
.ru_nsignals
, (int) rus
.ru_nvcsw
,
996 (int) rus
.ru_nivcsw
);
1001 stats_tstats (struct Client
*source_p
)
1003 struct Client
*target_p
;
1004 struct ServerStatistics sp
;
1007 memcpy(&sp
, &ServerStats
, sizeof(struct ServerStatistics
));
1009 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1011 target_p
= ptr
->data
;
1013 sp
.is_sbs
+= target_p
->localClient
->sendB
;
1014 sp
.is_sbr
+= target_p
->localClient
->receiveB
;
1015 sp
.is_sti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
1019 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
1021 target_p
= ptr
->data
;
1023 sp
.is_cbs
+= target_p
->localClient
->sendB
;
1024 sp
.is_cbr
+= target_p
->localClient
->receiveB
;
1025 sp
.is_cti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
1029 RB_DLINK_FOREACH(ptr
, unknown_list
.head
)
1034 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1035 "T :accepts %u refused %u", sp
.is_ac
, sp
.is_ref
);
1036 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1037 "T :rejected %u delaying %lu",
1038 sp
.is_rej
, delay_exit_length());
1039 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1040 "T :throttled refused %u throttle list size %lu", sp
.is_thr
, throttle_size());
1041 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1042 "T :nicks being delayed %lu",
1044 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1045 "T :unknown commands %u prefixes %u",
1046 sp
.is_unco
, sp
.is_unpf
);
1047 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1048 "T :nick collisions %u saves %u unknown closes %u",
1049 sp
.is_kill
, sp
.is_save
, sp
.is_ni
);
1050 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1051 "T :wrong direction %u empty %u",
1052 sp
.is_wrdi
, sp
.is_empt
);
1053 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1054 "T :numerics seen %u", sp
.is_num
);
1055 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1056 "T :tgchange blocked msgs %u restricted addrs %lu",
1057 sp
.is_tgch
, rb_dlink_list_length(&tgchange_list
));
1058 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1059 "T :ratelimit blocked commands %u", sp
.is_rl
);
1060 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1061 "T :auth successes %u fails %u",
1062 sp
.is_asuc
, sp
.is_abad
);
1063 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1064 "T :sasl successes %u fails %u",
1065 sp
.is_ssuc
, sp
.is_sbad
);
1066 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "T :Client Server");
1067 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1068 "T :connected %u %u", sp
.is_cl
, sp
.is_sv
);
1069 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1070 "T :bytes sent %lluK %lluK",
1073 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1074 "T :bytes recv %lluK %lluK",
1077 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1078 "T :time connected %llu %llu",
1079 sp
.is_cti
, sp
.is_sti
);
1083 stats_uptime (struct Client
*source_p
)
1087 now
= rb_current_time() - startup_time
;
1088 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
1089 form_str (RPL_STATSUPTIME
),
1090 (int)(now
/ 86400), (int)((now
/ 3600) % 24),
1091 (int)((now
/ 60) % 60), (int)(now
% 60));
1092 sendto_one_numeric(source_p
, RPL_STATSCONN
,
1093 form_str (RPL_STATSCONN
),
1094 MaxConnectionCount
, MaxClientCount
,
1095 Count
.totalrestartcount
);
1103 static struct shared_flags shared_flagtable
[] =
1105 { SHARED_PKLINE
, 'K' },
1106 { SHARED_TKLINE
, 'k' },
1107 { SHARED_UNKLINE
, 'U' },
1108 { SHARED_PXLINE
, 'X' },
1109 { SHARED_TXLINE
, 'x' },
1110 { SHARED_UNXLINE
, 'Y' },
1111 { SHARED_PRESV
, 'Q' },
1112 { SHARED_TRESV
, 'q' },
1113 { SHARED_UNRESV
, 'R' },
1114 { SHARED_LOCOPS
, 'L' },
1115 { SHARED_REHASH
, 'H' },
1116 { SHARED_TDLINE
, 'd' },
1117 { SHARED_PDLINE
, 'D' },
1118 { SHARED_UNDLINE
, 'E' },
1119 { SHARED_GRANT
, 'G' },
1120 { SHARED_DIE
, 'I' },
1126 stats_shared (struct Client
*source_p
)
1128 struct remote_conf
*shared_p
;
1130 char buf
[sizeof(shared_flagtable
)/sizeof(shared_flagtable
[0])];
1134 RB_DLINK_FOREACH(ptr
, shared_conf_list
.head
)
1136 shared_p
= ptr
->data
;
1142 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1144 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1145 *p
++ = shared_flagtable
[i
].letter
;
1150 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1151 form_str(RPL_STATSULINE
),
1152 shared_p
->server
, shared_p
->username
,
1153 shared_p
->host
, buf
);
1156 RB_DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
1158 shared_p
= ptr
->data
;
1164 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1166 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1167 *p
++ = shared_flagtable
[i
].letter
;
1172 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1173 form_str(RPL_STATSULINE
),
1174 shared_p
->server
, "*", "*", buf
);
1180 * input - client pointer
1182 * side effects - client is shown lists of who connected servers
1185 stats_servers (struct Client
*source_p
)
1187 struct Client
*target_p
;
1190 int days
, hours
, minutes
;
1193 if(ConfigServerHide
.flatten_links
&& !IsOperGeneral(source_p
) &&
1194 !IsExemptShide(source_p
))
1196 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1197 form_str (ERR_NOPRIVILEGES
));
1201 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1203 target_p
= ptr
->data
;
1206 seconds
= rb_current_time() - target_p
->localClient
->firsttime
;
1208 days
= (int) (seconds
/ 86400);
1210 hours
= (int) (seconds
/ 3600);
1212 minutes
= (int) (seconds
/ 60);
1215 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1216 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1217 "Connected: %d day%s, %d:%02d:%02d",
1219 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
1220 (int) (rb_current_time() - target_p
->localClient
->lasttime
),
1221 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1222 days
, (days
== 1) ? "" : "s", hours
, minutes
,
1226 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1227 "V :%d Server(s)", j
);
1231 stats_tgecos(struct Client
*source_p
)
1233 struct ConfItem
*aconf
;
1236 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1241 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1242 form_str(RPL_STATSXLINE
),
1243 'x', aconf
->port
, aconf
->host
,
1249 stats_gecos(struct Client
*source_p
)
1251 struct ConfItem
*aconf
;
1254 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1259 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1260 form_str(RPL_STATSXLINE
),
1261 'X', aconf
->port
, aconf
->host
,
1267 stats_class(struct Client
*source_p
)
1269 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOperGeneral(source_p
))
1270 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1271 form_str (ERR_NOPRIVILEGES
));
1273 report_classes(source_p
);
1277 stats_memory (struct Client
*source_p
)
1279 struct Client
*target_p
;
1280 struct Channel
*chptr
;
1281 rb_dlink_node
*rb_dlink
;
1283 int channel_count
= 0;
1284 int local_client_conf_count
= 0; /* local client conf links */
1285 int users_counted
= 0; /* user structs */
1287 int channel_users
= 0;
1288 int channel_invites
= 0;
1289 int channel_bans
= 0;
1290 int channel_except
= 0;
1291 int channel_invex
= 0;
1292 int channel_quiets
= 0;
1294 int class_count
= 0; /* classes */
1295 int conf_count
= 0; /* conf lines */
1296 int users_invited_count
= 0; /* users invited */
1297 int user_channels
= 0; /* users in channels */
1298 int aways_counted
= 0;
1299 size_t number_servers_cached
; /* number of servers cached by scache */
1301 size_t channel_memory
= 0;
1302 size_t channel_ban_memory
= 0;
1303 size_t channel_except_memory
= 0;
1304 size_t channel_invex_memory
= 0;
1305 size_t channel_quiet_memory
= 0;
1307 size_t away_memory
= 0; /* memory used by aways */
1308 size_t ww
= 0; /* whowas array count */
1309 size_t wwm
= 0; /* whowas array memory used */
1310 size_t conf_memory
= 0; /* memory used by conf lines */
1311 size_t mem_servers_cached
; /* memory used by scache */
1313 size_t linebuf_count
= 0;
1314 size_t linebuf_memory_used
= 0;
1316 size_t total_channel_memory
= 0;
1319 size_t local_client_count
= 0;
1320 size_t local_client_memory_used
= 0;
1322 size_t remote_client_count
= 0;
1323 size_t remote_client_memory_used
= 0;
1325 size_t total_memory
= 0;
1327 whowas_memory_usage(&ww
, &wwm
);
1329 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
1331 target_p
= ptr
->data
;
1332 if(MyConnect(target_p
))
1334 local_client_conf_count
++;
1340 users_invited_count
+= rb_dlink_list_length(&target_p
->user
->invited
);
1341 user_channels
+= rb_dlink_list_length(&target_p
->user
->channel
);
1342 if(target_p
->user
->away
)
1345 away_memory
+= (strlen(target_p
->user
->away
) + 1);
1350 /* Count up all channels, ban lists, except lists, Invex lists */
1351 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
1355 channel_memory
+= (strlen(chptr
->chname
) + sizeof(struct Channel
));
1357 channel_users
+= rb_dlink_list_length(&chptr
->members
);
1358 channel_invites
+= rb_dlink_list_length(&chptr
->invites
);
1360 RB_DLINK_FOREACH(rb_dlink
, chptr
->banlist
.head
)
1364 channel_ban_memory
+= sizeof(rb_dlink_node
) + sizeof(struct Ban
);
1367 RB_DLINK_FOREACH(rb_dlink
, chptr
->exceptlist
.head
)
1371 channel_except_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1374 RB_DLINK_FOREACH(rb_dlink
, chptr
->invexlist
.head
)
1378 channel_invex_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1381 RB_DLINK_FOREACH(rb_dlink
, chptr
->quietlist
.head
)
1385 channel_quiet_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1389 /* count up all classes */
1391 class_count
= rb_dlink_list_length(&class_list
) + 1;
1393 rb_count_rb_linebuf_memory(&linebuf_count
, &linebuf_memory_used
);
1395 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1396 "z :Users %u(%lu) Invites %u(%lu)",
1398 (unsigned long) users_counted
* sizeof(struct User
),
1399 users_invited_count
,
1400 (unsigned long) users_invited_count
* sizeof(rb_dlink_node
));
1402 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1403 "z :User channels %u(%lu) Aways %u(%d)",
1405 (unsigned long) user_channels
* sizeof(rb_dlink_node
),
1406 aways_counted
, (int) away_memory
);
1408 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1409 "z :Attached confs %u(%lu)",
1410 local_client_conf_count
,
1411 (unsigned long) local_client_conf_count
* sizeof(rb_dlink_node
));
1413 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1414 "z :Conflines %u(%d)", conf_count
, (int) conf_memory
);
1416 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1417 "z :Classes %u(%lu)",
1419 (unsigned long) class_count
* sizeof(struct Class
));
1421 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1422 "z :Channels %u(%d)",
1423 channel_count
, (int) channel_memory
);
1425 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1426 "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)",
1427 channel_bans
, (int) channel_ban_memory
,
1428 channel_except
, (int) channel_except_memory
,
1429 channel_invex
, (int) channel_invex_memory
,
1430 channel_quiets
, (int) channel_quiet_memory
);
1432 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1433 "z :Channel members %u(%lu) invite %u(%lu)",
1435 (unsigned long) channel_users
* sizeof(rb_dlink_node
),
1437 (unsigned long) channel_invites
* sizeof(rb_dlink_node
));
1439 total_channel_memory
= channel_memory
+
1440 channel_ban_memory
+
1441 channel_users
* sizeof(rb_dlink_node
) + channel_invites
* sizeof(rb_dlink_node
);
1443 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1444 "z :Whowas array %ld(%ld)",
1445 (long)ww
, (long)wwm
);
1449 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1450 "z :Hash: client %u(%ld) chan %u(%ld)",
1451 U_MAX
, (long)(U_MAX
* sizeof(rb_dlink_list
)),
1452 CH_MAX
, (long)(CH_MAX
* sizeof(rb_dlink_list
)));
1454 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1455 "z :linebuf %ld(%ld)",
1456 (long)linebuf_count
, (long)linebuf_memory_used
);
1458 count_scache(&number_servers_cached
, &mem_servers_cached
);
1460 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1461 "z :scache %ld(%ld)",
1462 (long)number_servers_cached
, (long)mem_servers_cached
);
1464 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1465 "z :hostname hash %d(%ld)",
1466 HOST_MAX
, (long)HOST_MAX
* sizeof(rb_dlink_list
));
1468 total_memory
= totww
+ total_channel_memory
+ conf_memory
+
1469 class_count
* sizeof(struct Class
);
1471 total_memory
+= mem_servers_cached
;
1472 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1473 "z :Total: whowas %d channel %d conf %d",
1474 (int) totww
, (int) total_channel_memory
,
1477 count_local_client_memory(&local_client_count
, &local_client_memory_used
);
1478 total_memory
+= local_client_memory_used
;
1480 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1481 "z :Local client Memory in use: %ld(%ld)",
1482 (long)local_client_count
, (long)local_client_memory_used
);
1485 count_remote_client_memory(&remote_client_count
, &remote_client_memory_used
);
1486 total_memory
+= remote_client_memory_used
;
1488 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1489 "z :Remote client Memory in use: %ld(%ld)",
1490 (long)remote_client_count
,
1491 (long)remote_client_memory_used
);
1495 stats_ziplinks (struct Client
*source_p
)
1498 struct Client
*target_p
;
1499 struct ZipStats
*zipstats
;
1501 char buf
[128], buf1
[128];
1502 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1504 target_p
= ptr
->data
;
1505 if(IsCapable (target_p
, CAP_ZIP
))
1507 zipstats
= target_p
->localClient
->zipstats
;
1508 sprintf(buf
, "%.2f%%", zipstats
->out_ratio
);
1509 sprintf(buf1
, "%.2f%%", zipstats
->in_ratio
);
1510 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1511 "Z :ZipLinks stats for %s send[%s compression "
1512 "(%llu kB data/%llu kB wire)] recv[%s compression "
1513 "(%llu kB data/%llu kB wire)]",
1515 buf
, zipstats
->out
>> 10,
1516 zipstats
->out_wire
>> 10, buf1
,
1517 zipstats
->in
>> 10, zipstats
->in_wire
>> 10);
1522 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1523 "Z :%u ziplink(s)", sent_data
);
1527 stats_servlinks (struct Client
*source_p
)
1529 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1530 long uptime
, sendK
, receiveK
;
1531 struct Client
*target_p
;
1536 if(ConfigServerHide
.flatten_links
&& !IsOperGeneral (source_p
) &&
1537 !IsExemptShide(source_p
))
1539 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1540 form_str (ERR_NOPRIVILEGES
));
1544 sendK
= receiveK
= 0;
1546 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1548 target_p
= ptr
->data
;
1551 sendK
+= target_p
->localClient
->sendK
;
1552 receiveK
+= target_p
->localClient
->receiveK
;
1554 sendto_one(source_p
, Sformat
,
1555 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1557 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1558 (int) target_p
->localClient
->sendM
,
1559 (int) target_p
->localClient
->sendK
,
1560 (int) target_p
->localClient
->receiveM
,
1561 (int) target_p
->localClient
->receiveK
,
1562 rb_current_time() - target_p
->localClient
->firsttime
,
1563 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1564 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1565 IsOperGeneral (source_p
) ? show_capabilities (target_p
) : "TS");
1568 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1569 "? :%u total server(s)", j
);
1571 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((sendK
)));
1572 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1573 "? :Sent total : %s %s",
1574 buf
, _GMKs (sendK
));
1575 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((receiveK
)));
1576 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1577 "? :Recv total : %s %s",
1578 buf
, _GMKs (receiveK
));
1580 uptime
= (rb_current_time() - startup_time
);
1581 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1582 _GMKv (me
.localClient
->sendK
),
1583 _GMKs (me
.localClient
->sendK
),
1584 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1585 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server send: %s", buf
);
1586 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1587 _GMKv (me
.localClient
->receiveK
),
1588 _GMKs (me
.localClient
->receiveK
),
1589 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1590 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server recv: %s", buf
);
1594 stats_l_should_show_oper(struct Client
*source_p
, struct Client
*target_p
)
1596 return SeesOper(target_p
, source_p
);
1600 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1605 char statchar
= parv
[1][0];
1607 /* this is def targeted at us somehow.. */
1608 if(parc
> 2 && !EmptyString(parv
[2]))
1610 /* directed at us generically? */
1611 if(match(parv
[2], me
.name
) ||
1612 (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1620 wilds
= strchr(name
, '*') || strchr(name
, '?');
1623 /* must be directed at a specific person thats not us */
1624 if(!doall
&& !wilds
)
1626 struct Client
*target_p
;
1628 if(MyClient(source_p
))
1629 target_p
= find_named_person(name
);
1631 target_p
= find_person(name
);
1633 if(target_p
!= NULL
)
1635 stats_spy(source_p
, statchar
, target_p
->name
);
1636 stats_l_client(source_p
, target_p
, statchar
);
1639 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1640 form_str(ERR_NOSUCHSERVER
),
1652 stats_spy(source_p
, statchar
, name
);
1656 /* local opers get everyone */
1657 if(MyOper(source_p
))
1659 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
, NULL
);
1660 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1664 /* they still need themselves if theyre local.. */
1665 if(MyClient(source_p
))
1666 stats_l_client(source_p
, source_p
, statchar
);
1668 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
, stats_l_should_show_oper
);
1671 if (!ConfigServerHide
.flatten_links
|| IsOperGeneral(source_p
) ||
1672 IsExemptShide(source_p
))
1673 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
, NULL
);
1678 /* ok, at this point theyre looking for a specific client whos on
1679 * our server.. but it contains a wildcard. --fl
1681 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1687 stats_l_list(struct Client
*source_p
, const char *name
, bool doall
, bool wilds
,
1688 rb_dlink_list
* list
, char statchar
, bool (*check_fn
)(struct Client
*source_p
, struct Client
*target_p
))
1691 struct Client
*target_p
;
1693 /* send information about connections which match. note, we
1694 * dont need tests for IsInvisible(), because non-opers will
1695 * never get here for normal clients --fl
1697 RB_DLINK_FOREACH(ptr
, list
->head
)
1699 target_p
= ptr
->data
;
1701 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1704 if (check_fn
== NULL
|| check_fn(source_p
, target_p
))
1705 stats_l_client(source_p
, target_p
, statchar
);
1710 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1713 if(IsAnyServer(target_p
))
1715 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1717 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1718 (int) target_p
->localClient
->sendM
,
1719 (int) target_p
->localClient
->sendK
,
1720 (int) target_p
->localClient
->receiveM
,
1721 (int) target_p
->localClient
->receiveK
,
1722 rb_current_time() - target_p
->localClient
->firsttime
,
1723 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1724 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1725 IsOperGeneral(source_p
) ? show_capabilities(target_p
) : "-");
1730 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1731 show_ip(source_p
, target_p
) ?
1732 (IsUpper(statchar
) ?
1733 get_client_name(target_p
, SHOW_IP
) :
1734 get_client_name(target_p
, HIDE_IP
)) :
1735 get_client_name(target_p
, MASK_IP
),
1736 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1737 (int) target_p
->localClient
->sendM
,
1738 (int) target_p
->localClient
->sendK
,
1739 (int) target_p
->localClient
->receiveM
,
1740 (int) target_p
->localClient
->receiveK
,
1741 rb_current_time() - target_p
->localClient
->firsttime
,
1742 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1743 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1749 rb_dump_fd_callback(int fd
, const char *desc
, void *data
)
1751 struct Client
*source_p
= data
;
1752 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "F :fd %-3d desc '%s'", fd
, desc
);
1756 stats_comm(struct Client
*source_p
)
1758 rb_dump_fd(rb_dump_fd_callback
, source_p
);
1764 * inputs - pointer to client doing the /stats
1765 * - char letter they are doing /stats on
1768 * This little helper function reports to opers if configured.
1771 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1775 data
.client
= source_p
;
1777 data
.arg2
= (int) statchar
;
1780 call_hook(doing_stats_hook
, &data
);
1787 * input - pointer to client doing stats
1789 * side effects - call hook doing_stats_p
1792 stats_p_spy (struct Client
*source_p
)
1796 data
.client
= source_p
;
1797 data
.arg1
= data
.arg2
= NULL
;
1799 call_hook(doing_stats_p_hook
, &data
);