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
24 * $Id: m_stats.c 1608 2006-06-04 02:11:40Z jilles $
28 #include "class.h" /* report_classes */
29 #include "client.h" /* Client */
30 #include "common.h" /* TRUE/FALSE */
32 #include "ircd.h" /* me */
33 #include "listener.h" /* show_ports */
34 #include "msg.h" /* Message */
35 #include "hostmask.h" /* report_mtrie_conf_links */
36 #include "numeric.h" /* ERR_xxx */
37 #include "scache.h" /* list_scache */
38 #include "send.h" /* sendto_one */
39 #include "s_conf.h" /* ConfItem */
40 #include "s_serv.h" /* hunt_server */
42 #include "s_user.h" /* show_opers */
43 #include "blacklist.h" /* dnsbl stuff */
47 #include "s_newconf.h"
51 #include "irc_radixtree.h"
53 static int m_stats (struct Client
*, struct Client
*, int, const char **);
55 struct Message stats_msgtab
= {
56 "STATS", 0, 0, 0, MFLG_SLOW
,
57 {mg_unreg
, {m_stats
, 2}, {m_stats
, 3}, mg_ignore
, mg_ignore
, {m_stats
, 2}}
61 int doing_stats_p_hook
;
63 mapi_clist_av1 stats_clist
[] = { &stats_msgtab
, NULL
};
64 mapi_hlist_av1 stats_hlist
[] = {
65 { "doing_stats", &doing_stats_hook
},
66 { "doing_stats_p", &doing_stats_p_hook
},
70 DECLARE_MODULE_AV1(stats
, NULL
, NULL
, stats_clist
, stats_hlist
, NULL
, "$Revision: 1608 $");
72 const char *Lformat
= "%s %u %u %u %u %u :%u %u %s";
74 static void stats_l_list(struct Client
*s
, const char *, int, int, rb_dlink_list
*, char,
75 int (*check_fn
)(struct Client
*target_p
));
76 static void stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
79 static int stats_spy(struct Client
*, char, const char *);
80 static void stats_p_spy(struct Client
*);
82 /* Heres our struct for the stats table */
86 void (*handler
) (struct Client
*source_p
);
91 static void stats_dns_servers(struct Client
*);
92 static void stats_delay(struct Client
*);
93 static void stats_hash(struct Client
*);
94 static void stats_connect(struct Client
*);
95 static void stats_tdeny(struct Client
*);
96 static void stats_deny(struct Client
*);
97 static void stats_exempt(struct Client
*);
98 static void stats_events(struct Client
*);
99 static void stats_prop_klines(struct Client
*);
100 static void stats_hubleaf(struct Client
*);
101 static void stats_auth(struct Client
*);
102 static void stats_tklines(struct Client
*);
103 static void stats_klines(struct Client
*);
104 static void stats_messages(struct Client
*);
105 static void stats_dnsbl(struct Client
*);
106 static void stats_oper(struct Client
*);
107 static void stats_privset(struct Client
*);
108 static void stats_operedup(struct Client
*);
109 static void stats_ports(struct Client
*);
110 static void stats_tresv(struct Client
*);
111 static void stats_resv(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 {'t', stats_tstats
, 1, 0, },
166 {'T', stats_tstats
, 1, 0, },
167 {'u', stats_uptime
, 0, 0, },
168 {'U', stats_shared
, 1, 0, },
169 {'v', stats_servers
, 0, 0, },
170 {'V', stats_servers
, 0, 0, },
171 {'x', stats_tgecos
, 1, 0, },
172 {'X', stats_gecos
, 1, 0, },
173 {'y', stats_class
, 0, 0, },
174 {'Y', stats_class
, 0, 0, },
175 {'z', stats_memory
, 1, 0, },
176 {'Z', stats_ziplinks
, 1, 0, },
177 {'?', stats_servlinks
, 0, 0, },
178 {(char) 0, (void (*)()) 0, 0, 0, }
183 * parv[1] = stat letter/command
184 * parv[2] = (if present) server/mask in stats L, or target
186 * This will search the tables for the appropriate stats letter,
187 * if found execute it.
190 m_stats(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
192 static time_t last_used
= 0;
197 statchar
= parv
[1][0];
199 if(MyClient(source_p
) && !IsOper(source_p
))
201 /* Check the user is actually allowed to do /stats, and isnt flooding */
202 if((last_used
+ ConfigFileEntry
.pace_wait
) > rb_current_time())
204 /* safe enough to give this on a local connect only */
205 sendto_one(source_p
, form_str(RPL_LOAD2HI
),
206 me
.name
, source_p
->name
, "STATS");
207 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
208 form_str(RPL_ENDOFSTATS
), statchar
);
212 last_used
= rb_current_time();
215 if(hunt_server (client_p
, source_p
, ":%s STATS %s :%s", 2, parc
, parv
) != HUNTED_ISME
)
218 if((statchar
!= 'L') && (statchar
!= 'l'))
219 did_stats
= stats_spy(source_p
, statchar
, NULL
);
221 /* if did_stats is true, a module grabbed this STATS request */
225 for (i
= 0; stats_cmd_table
[i
].letter
; i
++)
227 if(stats_cmd_table
[i
].letter
== statchar
)
229 /* The stats table says what privs are needed, so check --fl_ */
230 /* Called for remote clients and for local opers, so check need_admin
233 if(stats_cmd_table
[i
].need_oper
&& !IsOper(source_p
))
235 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
236 form_str (ERR_NOPRIVILEGES
));
239 if(stats_cmd_table
[i
].need_admin
&& !IsOperAdmin(source_p
))
241 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
242 me
.name
, source_p
->name
, "admin");
246 /* Blah, stats L needs the parameters, none of the others do.. */
247 if(statchar
== 'L' || statchar
== 'l')
248 stats_ltrace (source_p
, parc
, parv
);
250 stats_cmd_table
[i
].handler (source_p
);
255 /* Send the end of stats notice, and the stats_spy */
256 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
257 form_str(RPL_ENDOFSTATS
), statchar
);
263 stats_dns_servers (struct Client
*source_p
)
265 report_dns_servers (source_p
);
269 stats_delay(struct Client
*source_p
)
272 struct DictionaryIter iter
;
274 DICTIONARY_FOREACH(nd
, &iter
, nd_dict
)
276 sendto_one_notice(source_p
, ":Delaying: %s for %ld",
277 nd
->name
, (long) nd
->expire
);
282 stats_hash_cb(const char *buf
, void *client_p
)
284 sendto_one_numeric(client_p
, RPL_STATSDEBUG
, "B :%s", buf
);
288 stats_hash(struct Client
*source_p
)
290 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "B :%-30s %-15s %-10s %-10s %-10s %-10s",
291 "NAME", "TYPE", "OBJECTS", "DEPTH SUM", "AVG DEPTH", "MAX DEPTH");
293 irc_dictionary_stats_walk(stats_hash_cb
, source_p
);
294 irc_radixtree_stats_walk(stats_hash_cb
, source_p
);
298 stats_connect(struct Client
*source_p
)
301 struct server_conf
*server_p
;
305 if((ConfigFileEntry
.stats_c_oper_only
||
306 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
309 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
310 form_str(ERR_NOPRIVILEGES
));
314 RB_DLINK_FOREACH(ptr
, server_conf_list
.head
)
316 server_p
= ptr
->data
;
318 if(ServerConfIllegal(server_p
))
325 if(ServerConfAutoconn(server_p
))
327 if(ServerConfSSL(server_p
))
329 if(ServerConfTb(server_p
))
331 if(ServerConfCompressed(server_p
))
340 sendto_one_numeric(source_p
, RPL_STATSCLINE
,
341 form_str(RPL_STATSCLINE
),
344 server_p
->port
, server_p
->class_name
);
350 * input - client to report to
352 * side effects - client is given temp dline list.
355 stats_tdeny (struct Client
*source_p
)
357 char *host
, *pass
, *user
, *oper_reason
;
358 struct AddressRec
*arec
;
359 struct ConfItem
*aconf
;
362 for (i
= 0; i
< ATABLE_SIZE
; i
++)
364 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
366 if(arec
->type
== CONF_DLINE
)
370 if(!(aconf
->flags
& CONF_FLAGS_TEMPORARY
))
373 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
375 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
376 form_str (RPL_STATSDLINE
),
378 oper_reason
? "|" : "",
379 oper_reason
? oper_reason
: "");
387 * input - client to report to
389 * side effects - client is given dline list.
392 stats_deny (struct Client
*source_p
)
394 char *host
, *pass
, *user
, *oper_reason
;
395 struct AddressRec
*arec
;
396 struct ConfItem
*aconf
;
399 for (i
= 0; i
< ATABLE_SIZE
; i
++)
401 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
403 if(arec
->type
== CONF_DLINE
)
407 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
410 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
412 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
413 form_str (RPL_STATSDLINE
),
415 oper_reason
? "|" : "",
416 oper_reason
? oper_reason
: "");
425 * input - client to report to
427 * side effects - client is given list of exempt blocks
430 stats_exempt(struct Client
*source_p
)
432 char *name
, *host
, *user
, *classname
;
434 struct AddressRec
*arec
;
435 struct ConfItem
*aconf
;
438 if(ConfigFileEntry
.stats_e_disabled
)
440 sendto_one_numeric(source_p
, ERR_DISABLED
,
441 form_str(ERR_DISABLED
), "STATS e");
445 for (i
= 0; i
< ATABLE_SIZE
; i
++)
447 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
449 if(arec
->type
== CONF_EXEMPTDLINE
)
452 get_printable_conf (aconf
, &name
, &host
, &pass
,
453 &user
, &port
, &classname
);
455 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
456 form_str(RPL_STATSDLINE
),
457 'e', host
, pass
, "", "");
464 stats_events_cb(char *str
, void *ptr
)
466 sendto_one_numeric(ptr
, RPL_STATSDEBUG
, "E :%s", str
);
470 stats_events (struct Client
*source_p
)
472 rb_dump_events(stats_events_cb
, source_p
);
476 stats_prop_klines(struct Client
*source_p
)
478 struct ConfItem
*aconf
;
480 char *user
, *host
, *pass
, *oper_reason
;
482 RB_DLINK_FOREACH(ptr
, prop_bans
.head
)
486 /* Skip non-klines and deactivated klines. */
487 if(aconf
->status
!= CONF_KILL
)
490 get_printable_kline(source_p
, aconf
, &host
, &pass
,
491 &user
, &oper_reason
);
493 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
494 form_str(RPL_STATSKLINE
),
495 'g', host
, user
, pass
,
496 oper_reason
? "|" : "",
497 oper_reason
? oper_reason
: "");
502 stats_hubleaf(struct Client
*source_p
)
504 struct remote_conf
*hub_p
;
507 if((ConfigFileEntry
.stats_h_oper_only
||
508 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
511 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
512 form_str (ERR_NOPRIVILEGES
));
516 RB_DLINK_FOREACH(ptr
, hubleaf_conf_list
.head
)
520 if(hub_p
->flags
& CONF_HUB
)
521 sendto_one_numeric(source_p
, RPL_STATSHLINE
,
522 form_str(RPL_STATSHLINE
),
523 hub_p
->host
, hub_p
->server
);
525 sendto_one_numeric(source_p
, RPL_STATSLLINE
,
526 form_str(RPL_STATSLLINE
),
527 hub_p
->host
, hub_p
->server
);
533 stats_auth (struct Client
*source_p
)
535 /* Oper only, if unopered, return ERR_NOPRIVS */
536 if((ConfigFileEntry
.stats_i_oper_only
== 2) && !IsOper (source_p
))
537 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
538 form_str (ERR_NOPRIVILEGES
));
540 /* If unopered, Only return matching auth blocks */
541 else if((ConfigFileEntry
.stats_i_oper_only
== 1) && !IsOper (source_p
))
543 struct ConfItem
*aconf
;
544 char *name
, *host
, *user
, *classname
;
545 const char *pass
= "*";
548 if(MyConnect (source_p
))
549 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
550 (struct sockaddr
*)&source_p
->localClient
->ip
,
552 source_p
->localClient
->ip
.ss_family
,
553 source_p
->username
, NULL
);
555 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_CLIENT
,
556 0, source_p
->username
, NULL
);
561 get_printable_conf (aconf
, &name
, &host
, &pass
, &user
, &port
, &classname
);
562 if(!EmptyString(aconf
->spasswd
))
563 pass
= aconf
->spasswd
;
565 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
566 name
, pass
, show_iline_prefix(source_p
, aconf
, user
),
567 host
, port
, classname
);
570 /* Theyre opered, or allowed to see all auth blocks */
572 report_auth (source_p
);
577 stats_tklines(struct Client
*source_p
)
579 /* Oper only, if unopered, return ERR_NOPRIVS */
580 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
581 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
582 form_str (ERR_NOPRIVILEGES
));
584 /* If unopered, Only return matching klines */
585 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
587 struct ConfItem
*aconf
;
588 char *host
, *pass
, *user
, *oper_reason
;
590 if(MyConnect (source_p
))
591 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
592 (struct sockaddr
*)&source_p
->localClient
->ip
,
594 source_p
->localClient
->ip
.ss_family
,
595 source_p
->username
, NULL
);
597 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
598 0, source_p
->username
, NULL
);
603 /* dont report a permanent kline as a tkline */
604 if((aconf
->flags
& CONF_FLAGS_TEMPORARY
) == 0)
607 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
609 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
610 form_str(RPL_STATSKLINE
), aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
611 host
, user
, pass
, oper_reason
? "|" : "",
612 oper_reason
? oper_reason
: "");
614 /* Theyre opered, or allowed to see all klines */
617 struct ConfItem
*aconf
;
620 char *user
, *host
, *pass
, *oper_reason
;
622 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
624 RB_DLINK_FOREACH(ptr
, temp_klines
[i
].head
)
628 get_printable_kline(source_p
, aconf
, &host
, &pass
,
629 &user
, &oper_reason
);
631 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
632 form_str(RPL_STATSKLINE
),
633 'k', host
, user
, pass
,
634 oper_reason
? "|" : "",
635 oper_reason
? oper_reason
: "");
643 * inputs - Client to report to, mask
645 * side effects - Reports configured K-lines to client_p.
648 report_Klines(struct Client
*source_p
)
650 char *host
, *pass
, *user
, *oper_reason
;
651 struct AddressRec
*arec
;
652 struct ConfItem
*aconf
= NULL
;
655 for (i
= 0; i
< ATABLE_SIZE
; i
++)
657 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
659 if(arec
->type
== CONF_KILL
)
663 /* its a tempkline, theyre reported elsewhere */
664 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
667 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
668 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
669 form_str(RPL_STATSKLINE
),
670 'K', host
, user
, pass
,
671 oper_reason
? "|" : "",
672 oper_reason
? oper_reason
: "");
679 stats_klines(struct Client
*source_p
)
681 /* Oper only, if unopered, return ERR_NOPRIVS */
682 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
683 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
684 form_str (ERR_NOPRIVILEGES
));
686 /* If unopered, Only return matching klines */
687 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
689 struct ConfItem
*aconf
;
690 char *host
, *pass
, *user
, *oper_reason
;
692 /* search for a kline */
693 if(MyConnect (source_p
))
694 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
695 (struct sockaddr
*)&source_p
->localClient
->ip
,
697 source_p
->localClient
->ip
.ss_family
,
698 source_p
->username
, NULL
);
700 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
701 0, source_p
->username
, NULL
);
706 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
708 sendto_one_numeric(source_p
, RPL_STATSKLINE
, form_str(RPL_STATSKLINE
),
709 aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
710 host
, user
, pass
, oper_reason
? "|" : "",
711 oper_reason
? oper_reason
: "");
713 /* Theyre opered, or allowed to see all klines */
715 report_Klines (source_p
);
719 stats_messages(struct Client
*source_p
)
721 report_messages(source_p
);
725 stats_dnsbl(struct Client
*source_p
)
728 struct Blacklist
*blptr
;
730 RB_DLINK_FOREACH(ptr
, blacklist_list
.head
)
734 /* use RPL_STATSDEBUG for now -- jilles */
735 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "n :%d %s %s (%d)",
738 blptr
->status
& CONF_ILLEGAL
? "disabled" : "active",
744 stats_oper(struct Client
*source_p
)
746 struct oper_conf
*oper_p
;
749 if(!IsOper(source_p
) && ConfigFileEntry
.stats_o_oper_only
)
751 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
752 form_str (ERR_NOPRIVILEGES
));
756 RB_DLINK_FOREACH(ptr
, oper_conf_list
.head
)
760 sendto_one_numeric(source_p
, RPL_STATSOLINE
,
761 form_str(RPL_STATSOLINE
),
762 oper_p
->username
, oper_p
->host
, oper_p
->name
,
763 IsOper(source_p
) ? oper_p
->privset
->name
: "0", "-1");
768 stats_capability_walk(const char *line
, void *data
)
770 struct Client
*client_p
= data
;
772 sendto_one_numeric(client_p
, RPL_STATSDEBUG
, "C :%s", line
);
776 stats_capability(struct Client
*client_p
)
778 capability_index_stats(stats_capability_walk
, client_p
);
782 stats_privset(struct Client
*source_p
)
784 privilegeset_report(source_p
);
789 * input - client pointer
791 * side effects - client is shown a list of active opers
794 stats_operedup (struct Client
*source_p
)
796 struct Client
*target_p
;
797 rb_dlink_node
*oper_ptr
;
798 unsigned int count
= 0;
800 RB_DLINK_FOREACH (oper_ptr
, oper_list
.head
)
802 target_p
= oper_ptr
->data
;
804 if(IsOperInvis(target_p
) && !IsOper(source_p
))
807 if(target_p
->user
->away
)
812 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
814 target_p
->name
, target_p
->username
,
818 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
819 "p :%u staff members", count
);
821 stats_p_spy (source_p
);
825 stats_ports (struct Client
*source_p
)
827 if(!IsOper (source_p
) && ConfigFileEntry
.stats_P_oper_only
)
828 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
829 form_str (ERR_NOPRIVILEGES
));
831 show_ports (source_p
);
835 stats_tresv(struct Client
*source_p
)
837 struct ConfItem
*aconf
;
838 struct irc_radixtree_iteration_state state
;
842 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
846 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
847 form_str(RPL_STATSQLINE
),
848 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
851 IRC_RADIXTREE_FOREACH(aconf
, &state
, resv_tree
)
854 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
855 form_str(RPL_STATSQLINE
),
856 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
862 stats_resv(struct Client
*source_p
)
864 struct ConfItem
*aconf
;
865 struct irc_radixtree_iteration_state state
;
869 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
873 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
874 form_str(RPL_STATSQLINE
),
875 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
878 IRC_RADIXTREE_FOREACH(aconf
, &state
, resv_tree
)
881 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
882 form_str(RPL_STATSQLINE
),
883 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
888 stats_usage (struct Client
*source_p
)
903 if(getrusage(RUSAGE_SELF
, &rus
) == -1)
905 sendto_one_notice(source_p
, ":Getruseage error: %s.",
909 secs
= rus
.ru_utime
.tv_sec
+ rus
.ru_stime
.tv_sec
;
913 rup
= (rb_current_time() - startup_time
) * hzz
;
917 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
918 "R :CPU Secs %d:%02d User %d:%02d System %d:%02d",
919 (int) (secs
/ 60), (int) (secs
% 60),
920 (int) (rus
.ru_utime
.tv_sec
/ 60),
921 (int) (rus
.ru_utime
.tv_sec
% 60),
922 (int) (rus
.ru_stime
.tv_sec
/ 60),
923 (int) (rus
.ru_stime
.tv_sec
% 60));
924 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
925 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
926 rus
.ru_maxrss
, (rus
.ru_ixrss
/ rup
),
927 (rus
.ru_idrss
/ rup
), (rus
.ru_isrss
/ rup
));
928 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
929 "R :Swaps %d Reclaims %d Faults %d",
930 (int) rus
.ru_nswap
, (int) rus
.ru_minflt
, (int) rus
.ru_majflt
);
931 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
932 "R :Block in %d out %d",
933 (int) rus
.ru_inblock
, (int) rus
.ru_oublock
);
934 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
935 "R :Msg Rcv %d Send %d",
936 (int) rus
.ru_msgrcv
, (int) rus
.ru_msgsnd
);
937 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
938 "R :Signals %d Context Vol. %d Invol %d",
939 (int) rus
.ru_nsignals
, (int) rus
.ru_nvcsw
,
940 (int) rus
.ru_nivcsw
);
944 stats_tstats (struct Client
*source_p
)
946 struct Client
*target_p
;
947 struct ServerStatistics sp
;
950 memcpy(&sp
, &ServerStats
, sizeof(struct ServerStatistics
));
952 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
954 target_p
= ptr
->data
;
956 sp
.is_sbs
+= target_p
->localClient
->sendB
;
957 sp
.is_sbr
+= target_p
->localClient
->receiveB
;
958 sp
.is_sti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
962 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
964 target_p
= ptr
->data
;
966 sp
.is_cbs
+= target_p
->localClient
->sendB
;
967 sp
.is_cbr
+= target_p
->localClient
->receiveB
;
968 sp
.is_cti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
972 RB_DLINK_FOREACH(ptr
, unknown_list
.head
)
977 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
978 "T :accepts %u refused %u", sp
.is_ac
, sp
.is_ref
);
979 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
980 "T :rejected %u delaying %lu",
981 sp
.is_rej
, delay_exit_length());
982 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
983 "T :throttled refused %u throttle list size %lu", sp
.is_thr
, throttle_size());
984 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
985 "T :nicks being delayed %lu",
987 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
988 "T :unknown commands %u prefixes %u",
989 sp
.is_unco
, sp
.is_unpf
);
990 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
991 "T :nick collisions %u saves %u unknown closes %u",
992 sp
.is_kill
, sp
.is_save
, sp
.is_ni
);
993 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
994 "T :wrong direction %u empty %u",
995 sp
.is_wrdi
, sp
.is_empt
);
996 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
997 "T :numerics seen %u", sp
.is_num
);
998 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
999 "T :tgchange blocked msgs %u restricted addrs %lu",
1000 sp
.is_tgch
, rb_dlink_list_length(&tgchange_list
));
1001 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1002 "T :ratelimit blocked commands %u", sp
.is_rl
);
1003 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1004 "T :auth successes %u fails %u",
1005 sp
.is_asuc
, sp
.is_abad
);
1006 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1007 "T :sasl successes %u fails %u",
1008 sp
.is_ssuc
, sp
.is_sbad
);
1009 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "T :Client Server");
1010 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1011 "T :connected %u %u", sp
.is_cl
, sp
.is_sv
);
1012 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1013 "T :bytes sent %lluK %lluK",
1016 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1017 "T :bytes recv %lluK %lluK",
1020 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1021 "T :time connected %llu %llu",
1022 sp
.is_cti
, sp
.is_sti
);
1026 stats_uptime (struct Client
*source_p
)
1030 now
= rb_current_time() - startup_time
;
1031 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
1032 form_str (RPL_STATSUPTIME
),
1033 (int)(now
/ 86400), (int)((now
/ 3600) % 24),
1034 (int)((now
/ 60) % 60), (int)(now
% 60));
1035 sendto_one_numeric(source_p
, RPL_STATSCONN
,
1036 form_str (RPL_STATSCONN
),
1037 MaxConnectionCount
, MaxClientCount
,
1038 Count
.totalrestartcount
);
1046 static struct shared_flags shared_flagtable
[] =
1048 { SHARED_PKLINE
, 'K' },
1049 { SHARED_TKLINE
, 'k' },
1050 { SHARED_UNKLINE
, 'U' },
1051 { SHARED_PXLINE
, 'X' },
1052 { SHARED_TXLINE
, 'x' },
1053 { SHARED_UNXLINE
, 'Y' },
1054 { SHARED_PRESV
, 'Q' },
1055 { SHARED_TRESV
, 'q' },
1056 { SHARED_UNRESV
, 'R' },
1057 { SHARED_LOCOPS
, 'L' },
1058 { SHARED_REHASH
, 'H' },
1059 { SHARED_TDLINE
, 'd' },
1060 { SHARED_PDLINE
, 'D' },
1061 { SHARED_UNDLINE
, 'E' },
1062 { SHARED_GRANT
, 'G' },
1063 { SHARED_DIE
, 'I' },
1069 stats_shared (struct Client
*source_p
)
1071 struct remote_conf
*shared_p
;
1073 char buf
[sizeof(shared_flagtable
)/sizeof(shared_flagtable
[0])];
1077 RB_DLINK_FOREACH(ptr
, shared_conf_list
.head
)
1079 shared_p
= ptr
->data
;
1085 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1087 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1088 *p
++ = shared_flagtable
[i
].letter
;
1093 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1094 form_str(RPL_STATSULINE
),
1095 shared_p
->server
, shared_p
->username
,
1096 shared_p
->host
, buf
);
1099 RB_DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
1101 shared_p
= ptr
->data
;
1107 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1109 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1110 *p
++ = shared_flagtable
[i
].letter
;
1115 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1116 form_str(RPL_STATSULINE
),
1117 shared_p
->server
, "*", "*", buf
);
1123 * input - client pointer
1125 * side effects - client is shown lists of who connected servers
1128 stats_servers (struct Client
*source_p
)
1130 struct Client
*target_p
;
1133 int days
, hours
, minutes
;
1136 if(ConfigServerHide
.flatten_links
&& !IsOper(source_p
) &&
1137 !IsExemptShide(source_p
))
1139 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1140 form_str (ERR_NOPRIVILEGES
));
1144 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1146 target_p
= ptr
->data
;
1149 seconds
= rb_current_time() - target_p
->localClient
->firsttime
;
1151 days
= (int) (seconds
/ 86400);
1153 hours
= (int) (seconds
/ 3600);
1155 minutes
= (int) (seconds
/ 60);
1158 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1159 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1160 "Connected: %d day%s, %d:%02d:%02d",
1162 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
1163 (int) (rb_current_time() - target_p
->localClient
->lasttime
),
1164 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1165 days
, (days
== 1) ? "" : "s", hours
, minutes
,
1169 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1170 "V :%d Server(s)", j
);
1174 stats_tgecos(struct Client
*source_p
)
1176 struct ConfItem
*aconf
;
1179 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1184 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1185 form_str(RPL_STATSXLINE
),
1186 'x', aconf
->port
, aconf
->host
,
1192 stats_gecos(struct Client
*source_p
)
1194 struct ConfItem
*aconf
;
1197 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1202 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1203 form_str(RPL_STATSXLINE
),
1204 'X', aconf
->port
, aconf
->host
,
1210 stats_class(struct Client
*source_p
)
1212 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOper(source_p
))
1213 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1214 form_str (ERR_NOPRIVILEGES
));
1216 report_classes(source_p
);
1220 stats_memory (struct Client
*source_p
)
1222 struct Client
*target_p
;
1223 struct Channel
*chptr
;
1224 rb_dlink_node
*rb_dlink
;
1226 int channel_count
= 0;
1227 int local_client_conf_count
= 0; /* local client conf links */
1228 int users_counted
= 0; /* user structs */
1230 int channel_users
= 0;
1231 int channel_invites
= 0;
1232 int channel_bans
= 0;
1233 int channel_except
= 0;
1234 int channel_invex
= 0;
1235 int channel_quiets
= 0;
1237 int class_count
= 0; /* classes */
1238 int conf_count
= 0; /* conf lines */
1239 int users_invited_count
= 0; /* users invited */
1240 int user_channels
= 0; /* users in channels */
1241 int aways_counted
= 0;
1242 size_t number_servers_cached
; /* number of servers cached by scache */
1244 size_t channel_memory
= 0;
1245 size_t channel_ban_memory
= 0;
1246 size_t channel_except_memory
= 0;
1247 size_t channel_invex_memory
= 0;
1248 size_t channel_quiet_memory
= 0;
1250 size_t away_memory
= 0; /* memory used by aways */
1251 size_t ww
= 0; /* whowas array count */
1252 size_t wwm
= 0; /* whowas array memory used */
1253 size_t conf_memory
= 0; /* memory used by conf lines */
1254 size_t mem_servers_cached
; /* memory used by scache */
1256 size_t linebuf_count
= 0;
1257 size_t linebuf_memory_used
= 0;
1259 size_t total_channel_memory
= 0;
1262 size_t local_client_count
= 0;
1263 size_t local_client_memory_used
= 0;
1265 size_t remote_client_count
= 0;
1266 size_t remote_client_memory_used
= 0;
1268 size_t total_memory
= 0;
1270 count_whowas_memory(&ww
, &wwm
);
1272 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
1274 target_p
= ptr
->data
;
1275 if(MyConnect(target_p
))
1277 local_client_conf_count
++;
1283 users_invited_count
+= rb_dlink_list_length(&target_p
->user
->invited
);
1284 user_channels
+= rb_dlink_list_length(&target_p
->user
->channel
);
1285 if(target_p
->user
->away
)
1288 away_memory
+= (strlen(target_p
->user
->away
) + 1);
1293 /* Count up all channels, ban lists, except lists, Invex lists */
1294 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
1298 channel_memory
+= (strlen(chptr
->chname
) + sizeof(struct Channel
));
1300 channel_users
+= rb_dlink_list_length(&chptr
->members
);
1301 channel_invites
+= rb_dlink_list_length(&chptr
->invites
);
1303 RB_DLINK_FOREACH(rb_dlink
, chptr
->banlist
.head
)
1307 channel_ban_memory
+= sizeof(rb_dlink_node
) + sizeof(struct Ban
);
1310 RB_DLINK_FOREACH(rb_dlink
, chptr
->exceptlist
.head
)
1314 channel_except_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1317 RB_DLINK_FOREACH(rb_dlink
, chptr
->invexlist
.head
)
1321 channel_invex_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1324 RB_DLINK_FOREACH(rb_dlink
, chptr
->quietlist
.head
)
1328 channel_quiet_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1332 /* count up all classes */
1334 class_count
= rb_dlink_list_length(&class_list
) + 1;
1336 rb_count_rb_linebuf_memory(&linebuf_count
, &linebuf_memory_used
);
1338 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1339 "z :Users %u(%lu) Invites %u(%lu)",
1341 (unsigned long) users_counted
* sizeof(struct User
),
1342 users_invited_count
,
1343 (unsigned long) users_invited_count
* sizeof(rb_dlink_node
));
1345 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1346 "z :User channels %u(%lu) Aways %u(%d)",
1348 (unsigned long) user_channels
* sizeof(rb_dlink_node
),
1349 aways_counted
, (int) away_memory
);
1351 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1352 "z :Attached confs %u(%lu)",
1353 local_client_conf_count
,
1354 (unsigned long) local_client_conf_count
* sizeof(rb_dlink_node
));
1356 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1357 "z :Conflines %u(%d)", conf_count
, (int) conf_memory
);
1359 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1360 "z :Classes %u(%lu)",
1362 (unsigned long) class_count
* sizeof(struct Class
));
1364 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1365 "z :Channels %u(%d)",
1366 channel_count
, (int) channel_memory
);
1368 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1369 "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)",
1370 channel_bans
, (int) channel_ban_memory
,
1371 channel_except
, (int) channel_except_memory
,
1372 channel_invex
, (int) channel_invex_memory
,
1373 channel_quiets
, (int) channel_quiet_memory
);
1375 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1376 "z :Channel members %u(%lu) invite %u(%lu)",
1378 (unsigned long) channel_users
* sizeof(rb_dlink_node
),
1380 (unsigned long) channel_invites
* sizeof(rb_dlink_node
));
1382 total_channel_memory
= channel_memory
+
1383 channel_ban_memory
+
1384 channel_users
* sizeof(rb_dlink_node
) + channel_invites
* sizeof(rb_dlink_node
);
1386 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1387 "z :Whowas array %ld(%ld)",
1388 (long)ww
, (long)wwm
);
1392 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1393 "z :Hash: client %u(%ld) chan %u(%ld)",
1394 U_MAX
, (long)(U_MAX
* sizeof(rb_dlink_list
)),
1395 CH_MAX
, (long)(CH_MAX
* sizeof(rb_dlink_list
)));
1397 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1398 "z :linebuf %ld(%ld)",
1399 (long)linebuf_count
, (long)linebuf_memory_used
);
1401 count_scache(&number_servers_cached
, &mem_servers_cached
);
1403 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1404 "z :scache %ld(%ld)",
1405 (long)number_servers_cached
, (long)mem_servers_cached
);
1407 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1408 "z :hostname hash %d(%ld)",
1409 HOST_MAX
, (long)HOST_MAX
* sizeof(rb_dlink_list
));
1411 total_memory
= totww
+ total_channel_memory
+ conf_memory
+
1412 class_count
* sizeof(struct Class
);
1414 total_memory
+= mem_servers_cached
;
1415 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1416 "z :Total: whowas %d channel %d conf %d",
1417 (int) totww
, (int) total_channel_memory
,
1420 count_local_client_memory(&local_client_count
, &local_client_memory_used
);
1421 total_memory
+= local_client_memory_used
;
1423 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1424 "z :Local client Memory in use: %ld(%ld)",
1425 (long)local_client_count
, (long)local_client_memory_used
);
1428 count_remote_client_memory(&remote_client_count
, &remote_client_memory_used
);
1429 total_memory
+= remote_client_memory_used
;
1431 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1432 "z :Remote client Memory in use: %ld(%ld)",
1433 (long)remote_client_count
,
1434 (long)remote_client_memory_used
);
1438 stats_ziplinks (struct Client
*source_p
)
1441 struct Client
*target_p
;
1442 struct ZipStats
*zipstats
;
1444 char buf
[128], buf1
[128];
1445 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1447 target_p
= ptr
->data
;
1448 if(IsCapable (target_p
, CAP_ZIP
))
1450 zipstats
= target_p
->localClient
->zipstats
;
1451 sprintf(buf
, "%.2f%%", zipstats
->out_ratio
);
1452 sprintf(buf1
, "%.2f%%", zipstats
->in_ratio
);
1453 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1454 "Z :ZipLinks stats for %s send[%s compression "
1455 "(%llu kB data/%llu kB wire)] recv[%s compression "
1456 "(%llu kB data/%llu kB wire)]",
1458 buf
, zipstats
->out
>> 10,
1459 zipstats
->out_wire
>> 10, buf1
,
1460 zipstats
->in
>> 10, zipstats
->in_wire
>> 10);
1465 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1466 "Z :%u ziplink(s)", sent_data
);
1470 stats_servlinks (struct Client
*source_p
)
1472 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1473 long uptime
, sendK
, receiveK
;
1474 struct Client
*target_p
;
1479 if(ConfigServerHide
.flatten_links
&& !IsOper (source_p
) &&
1480 !IsExemptShide(source_p
))
1482 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1483 form_str (ERR_NOPRIVILEGES
));
1487 sendK
= receiveK
= 0;
1489 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1491 target_p
= ptr
->data
;
1494 sendK
+= target_p
->localClient
->sendK
;
1495 receiveK
+= target_p
->localClient
->receiveK
;
1497 sendto_one(source_p
, Sformat
,
1498 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1500 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1501 (int) target_p
->localClient
->sendM
,
1502 (int) target_p
->localClient
->sendK
,
1503 (int) target_p
->localClient
->receiveM
,
1504 (int) target_p
->localClient
->receiveK
,
1505 rb_current_time() - target_p
->localClient
->firsttime
,
1506 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1507 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1508 IsOper (source_p
) ? show_capabilities (target_p
) : "TS");
1511 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1512 "? :%u total server(s)", j
);
1514 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((sendK
)));
1515 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1516 "? :Sent total : %s %s",
1517 buf
, _GMKs (sendK
));
1518 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((receiveK
)));
1519 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1520 "? :Recv total : %s %s",
1521 buf
, _GMKs (receiveK
));
1523 uptime
= (rb_current_time() - startup_time
);
1524 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1525 _GMKv (me
.localClient
->sendK
),
1526 _GMKs (me
.localClient
->sendK
),
1527 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1528 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server send: %s", buf
);
1529 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1530 _GMKv (me
.localClient
->receiveK
),
1531 _GMKs (me
.localClient
->receiveK
),
1532 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1533 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server recv: %s", buf
);
1537 stats_l_should_show_oper(struct Client
*target_p
)
1539 if (IsOperInvis(target_p
))
1546 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1551 char statchar
= parv
[1][0];
1553 /* this is def targeted at us somehow.. */
1554 if(parc
> 2 && !EmptyString(parv
[2]))
1556 /* directed at us generically? */
1557 if(match(parv
[2], me
.name
) ||
1558 (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1566 wilds
= strchr(name
, '*') || strchr(name
, '?');
1569 /* must be directed at a specific person thats not us */
1570 if(!doall
&& !wilds
)
1572 struct Client
*target_p
;
1574 if(MyClient(source_p
))
1575 target_p
= find_named_person(name
);
1577 target_p
= find_person(name
);
1579 if(target_p
!= NULL
)
1581 stats_spy(source_p
, statchar
, target_p
->name
);
1582 stats_l_client(source_p
, target_p
, statchar
);
1585 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1586 form_str(ERR_NOSUCHSERVER
),
1598 stats_spy(source_p
, statchar
, name
);
1602 /* local opers get everyone */
1603 if(MyOper(source_p
))
1605 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
, NULL
);
1606 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1610 /* they still need themselves if theyre local.. */
1611 if(MyClient(source_p
))
1612 stats_l_client(source_p
, source_p
, statchar
);
1614 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
, stats_l_should_show_oper
);
1617 if (!ConfigServerHide
.flatten_links
|| IsOper(source_p
) ||
1618 IsExemptShide(source_p
))
1619 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
, NULL
);
1624 /* ok, at this point theyre looking for a specific client whos on
1625 * our server.. but it contains a wildcard. --fl
1627 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1633 stats_l_list(struct Client
*source_p
, const char *name
, int doall
, int wilds
,
1634 rb_dlink_list
* list
, char statchar
, int (*check_fn
)(struct Client
*target_p
))
1637 struct Client
*target_p
;
1639 /* send information about connections which match. note, we
1640 * dont need tests for IsInvisible(), because non-opers will
1641 * never get here for normal clients --fl
1643 RB_DLINK_FOREACH(ptr
, list
->head
)
1645 target_p
= ptr
->data
;
1647 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1650 if (check_fn
== NULL
|| check_fn(target_p
))
1651 stats_l_client(source_p
, target_p
, statchar
);
1656 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1659 if(IsAnyServer(target_p
))
1661 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1663 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1664 (int) target_p
->localClient
->sendM
,
1665 (int) target_p
->localClient
->sendK
,
1666 (int) target_p
->localClient
->receiveM
,
1667 (int) target_p
->localClient
->receiveK
,
1668 rb_current_time() - target_p
->localClient
->firsttime
,
1669 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1670 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1671 IsOper(source_p
) ? show_capabilities(target_p
) : "-");
1676 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1677 show_ip(source_p
, target_p
) ?
1678 (IsUpper(statchar
) ?
1679 get_client_name(target_p
, SHOW_IP
) :
1680 get_client_name(target_p
, HIDE_IP
)) :
1681 get_client_name(target_p
, MASK_IP
),
1682 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1683 (int) target_p
->localClient
->sendM
,
1684 (int) target_p
->localClient
->sendK
,
1685 (int) target_p
->localClient
->receiveM
,
1686 (int) target_p
->localClient
->receiveK
,
1687 rb_current_time() - target_p
->localClient
->firsttime
,
1688 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1689 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1695 rb_dump_fd_callback(int fd
, const char *desc
, void *data
)
1697 struct Client
*source_p
= data
;
1698 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "F :fd %-3d desc '%s'", fd
, desc
);
1702 stats_comm(struct Client
*source_p
)
1704 rb_dump_fd(rb_dump_fd_callback
, source_p
);
1710 * inputs - pointer to client doing the /stats
1711 * - char letter they are doing /stats on
1714 * This little helper function reports to opers if configured.
1715 * personally, I don't see why opers need to see stats requests
1716 * at all. They are just "noise" to an oper, and users can't do
1717 * any damage with stats requests now anyway. So, why show them?
1721 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1725 data
.client
= source_p
;
1727 data
.arg2
= (int) statchar
;
1730 call_hook(doing_stats_hook
, &data
);
1737 * input - pointer to client doing stats
1739 * side effects - call hook doing_stats_p
1742 stats_p_spy (struct Client
*source_p
)
1746 data
.client
= source_p
;
1747 data
.arg1
= data
.arg2
= NULL
;
1749 call_hook(doing_stats_p_hook
, &data
);