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"
52 static int m_stats (struct Client
*, struct Client
*, int, const char **);
54 struct Message stats_msgtab
= {
55 "STATS", 0, 0, 0, MFLG_SLOW
,
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_AV1(stats
, NULL
, NULL
, stats_clist
, stats_hlist
, NULL
, "$Revision: 1608 $");
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 void 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_usage(struct Client
*);
112 static void stats_tstats(struct Client
*);
113 static void stats_uptime(struct Client
*);
114 static void stats_shared(struct Client
*);
115 static void stats_servers(struct Client
*);
116 static void stats_tgecos(struct Client
*);
117 static void stats_gecos(struct Client
*);
118 static void stats_class(struct Client
*);
119 static void stats_memory(struct Client
*);
120 static void stats_servlinks(struct Client
*);
121 static void stats_ltrace(struct Client
*, int, const char **);
122 static void stats_ziplinks(struct Client
*);
123 static void stats_comm(struct Client
*);
124 static void stats_capability(struct Client
*);
126 /* This table contains the possible stats items, in order:
127 * stats letter, function to call, operonly? adminonly?
128 * case only matters in the stats letter column.. -- fl_
130 static struct StatsStruct stats_cmd_table
[] = {
131 /* letter function need_oper need_admin */
132 {'a', stats_dns_servers
, 1, 1, },
133 {'A', stats_dns_servers
, 1, 1, },
134 {'b', stats_delay
, 1, 1, },
135 {'B', stats_hash
, 1, 1, },
136 {'c', stats_connect
, 0, 0, },
137 {'C', stats_capability
, 1, 0, },
138 {'d', stats_tdeny
, 1, 0, },
139 {'D', stats_deny
, 1, 0, },
140 {'e', stats_exempt
, 1, 0, },
141 {'E', stats_events
, 1, 1, },
142 {'f', stats_comm
, 1, 1, },
143 {'F', stats_comm
, 1, 1, },
144 {'g', stats_prop_klines
, 1, 0, },
145 {'h', stats_hubleaf
, 0, 0, },
146 {'H', stats_hubleaf
, 0, 0, },
147 {'i', stats_auth
, 0, 0, },
148 {'I', stats_auth
, 0, 0, },
149 {'k', stats_tklines
, 0, 0, },
150 {'K', stats_klines
, 0, 0, },
151 {'l', NULL
/* special */, 0, 0, },
152 {'L', NULL
/* special */, 0, 0, },
153 {'m', stats_messages
, 0, 0, },
154 {'M', stats_messages
, 0, 0, },
155 {'n', stats_dnsbl
, 0, 0, },
156 {'o', stats_oper
, 0, 0, },
157 {'O', stats_privset
, 1, 0, },
158 {'p', stats_operedup
, 0, 0, },
159 {'P', stats_ports
, 0, 0, },
160 {'q', stats_tresv
, 1, 0, },
161 {'Q', stats_resv
, 1, 0, },
162 {'r', stats_usage
, 1, 0, },
163 {'R', stats_usage
, 1, 0, },
164 {'t', stats_tstats
, 1, 0, },
165 {'T', stats_tstats
, 1, 0, },
166 {'u', stats_uptime
, 0, 0, },
167 {'U', stats_shared
, 1, 0, },
168 {'v', stats_servers
, 0, 0, },
169 {'V', stats_servers
, 0, 0, },
170 {'x', stats_tgecos
, 1, 0, },
171 {'X', stats_gecos
, 1, 0, },
172 {'y', stats_class
, 0, 0, },
173 {'Y', stats_class
, 0, 0, },
174 {'z', stats_memory
, 1, 0, },
175 {'Z', stats_ziplinks
, 1, 0, },
176 {'?', stats_servlinks
, 0, 0, },
177 {(char) 0, (void (*)()) 0, 0, 0, }
182 * parv[1] = stat letter/command
183 * parv[2] = (if present) server/mask in stats L, or target
185 * This will search the tables for the appropriate stats letter,
186 * if found execute it.
189 m_stats(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
191 static time_t last_used
= 0;
195 statchar
= parv
[1][0];
197 if(MyClient(source_p
) && !IsOper(source_p
))
199 /* Check the user is actually allowed to do /stats, and isnt flooding */
200 if((last_used
+ ConfigFileEntry
.pace_wait
) > rb_current_time())
202 /* safe enough to give this on a local connect only */
203 sendto_one(source_p
, form_str(RPL_LOAD2HI
),
204 me
.name
, source_p
->name
, "STATS");
205 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
206 form_str(RPL_ENDOFSTATS
), statchar
);
210 last_used
= rb_current_time();
213 if(hunt_server (client_p
, source_p
, ":%s STATS %s :%s", 2, parc
, parv
) != HUNTED_ISME
)
216 if((statchar
!= 'L') && (statchar
!= 'l'))
217 stats_spy(source_p
, statchar
, NULL
);
219 for (i
= 0; stats_cmd_table
[i
].letter
; i
++)
221 if(stats_cmd_table
[i
].letter
== statchar
)
223 /* The stats table says what privs are needed, so check --fl_ */
224 /* Called for remote clients and for local opers, so check need_admin
227 if(stats_cmd_table
[i
].need_oper
&& !IsOper(source_p
))
229 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
230 form_str (ERR_NOPRIVILEGES
));
233 if(stats_cmd_table
[i
].need_admin
&& !IsOperAdmin(source_p
))
235 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
236 me
.name
, source_p
->name
, "admin");
240 /* Blah, stats L needs the parameters, none of the others do.. */
241 if(statchar
== 'L' || statchar
== 'l')
242 stats_ltrace (source_p
, parc
, parv
);
244 stats_cmd_table
[i
].handler (source_p
);
248 /* Send the end of stats notice, and the stats_spy */
249 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
250 form_str(RPL_ENDOFSTATS
), statchar
);
256 stats_dns_servers (struct Client
*source_p
)
258 report_dns_servers (source_p
);
262 stats_delay(struct Client
*source_p
)
265 struct DictionaryIter iter
;
267 DICTIONARY_FOREACH(nd
, &iter
, nd_dict
)
269 sendto_one_notice(source_p
, ":Delaying: %s for %ld",
270 nd
->name
, (long) nd
->expire
);
275 stats_hash(struct Client
*source_p
)
277 hash_stats(source_p
);
281 stats_connect(struct Client
*source_p
)
284 struct server_conf
*server_p
;
288 if((ConfigFileEntry
.stats_c_oper_only
||
289 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
292 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
293 form_str(ERR_NOPRIVILEGES
));
297 RB_DLINK_FOREACH(ptr
, server_conf_list
.head
)
299 server_p
= ptr
->data
;
301 if(ServerConfIllegal(server_p
))
308 if(ServerConfAutoconn(server_p
))
310 if(ServerConfSSL(server_p
))
312 if(ServerConfTb(server_p
))
314 if(ServerConfCompressed(server_p
))
323 sendto_one_numeric(source_p
, RPL_STATSCLINE
,
324 form_str(RPL_STATSCLINE
),
327 server_p
->port
, server_p
->class_name
);
333 * input - client to report to
335 * side effects - client is given temp dline list.
338 stats_tdeny (struct Client
*source_p
)
340 char *host
, *pass
, *user
, *oper_reason
;
341 struct AddressRec
*arec
;
342 struct ConfItem
*aconf
;
345 for (i
= 0; i
< ATABLE_SIZE
; i
++)
347 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
349 if(arec
->type
== CONF_DLINE
)
353 if(!(aconf
->flags
& CONF_FLAGS_TEMPORARY
))
356 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
358 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
359 form_str (RPL_STATSDLINE
),
361 oper_reason
? "|" : "",
362 oper_reason
? oper_reason
: "");
370 * input - client to report to
372 * side effects - client is given dline list.
375 stats_deny (struct Client
*source_p
)
377 char *host
, *pass
, *user
, *oper_reason
;
378 struct AddressRec
*arec
;
379 struct ConfItem
*aconf
;
382 for (i
= 0; i
< ATABLE_SIZE
; i
++)
384 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
386 if(arec
->type
== CONF_DLINE
)
390 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
393 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
395 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
396 form_str (RPL_STATSDLINE
),
398 oper_reason
? "|" : "",
399 oper_reason
? oper_reason
: "");
408 * input - client to report to
410 * side effects - client is given list of exempt blocks
413 stats_exempt(struct Client
*source_p
)
415 char *name
, *host
, *user
, *classname
;
417 struct AddressRec
*arec
;
418 struct ConfItem
*aconf
;
421 if(ConfigFileEntry
.stats_e_disabled
)
423 sendto_one_numeric(source_p
, ERR_DISABLED
,
424 form_str(ERR_DISABLED
), "STATS e");
428 for (i
= 0; i
< ATABLE_SIZE
; i
++)
430 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
432 if(arec
->type
== CONF_EXEMPTDLINE
)
435 get_printable_conf (aconf
, &name
, &host
, &pass
,
436 &user
, &port
, &classname
);
438 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
439 form_str(RPL_STATSDLINE
),
440 'e', host
, pass
, "", "");
447 stats_events_cb(char *str
, void *ptr
)
449 sendto_one_numeric(ptr
, RPL_STATSDEBUG
, "E :%s", str
);
453 stats_events (struct Client
*source_p
)
455 rb_dump_events(stats_events_cb
, source_p
);
459 stats_prop_klines(struct Client
*source_p
)
461 struct ConfItem
*aconf
;
463 char *user
, *host
, *pass
, *oper_reason
;
465 RB_DLINK_FOREACH(ptr
, prop_bans
.head
)
469 /* Skip non-klines and deactivated klines. */
470 if(aconf
->status
!= CONF_KILL
)
473 get_printable_kline(source_p
, aconf
, &host
, &pass
,
474 &user
, &oper_reason
);
476 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
477 form_str(RPL_STATSKLINE
),
478 'g', host
, user
, pass
,
479 oper_reason
? "|" : "",
480 oper_reason
? oper_reason
: "");
485 stats_hubleaf(struct Client
*source_p
)
487 struct remote_conf
*hub_p
;
490 if((ConfigFileEntry
.stats_h_oper_only
||
491 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
494 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
495 form_str (ERR_NOPRIVILEGES
));
499 RB_DLINK_FOREACH(ptr
, hubleaf_conf_list
.head
)
503 if(hub_p
->flags
& CONF_HUB
)
504 sendto_one_numeric(source_p
, RPL_STATSHLINE
,
505 form_str(RPL_STATSHLINE
),
506 hub_p
->host
, hub_p
->server
);
508 sendto_one_numeric(source_p
, RPL_STATSLLINE
,
509 form_str(RPL_STATSLLINE
),
510 hub_p
->host
, hub_p
->server
);
516 stats_auth (struct Client
*source_p
)
518 /* Oper only, if unopered, return ERR_NOPRIVS */
519 if((ConfigFileEntry
.stats_i_oper_only
== 2) && !IsOper (source_p
))
520 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
521 form_str (ERR_NOPRIVILEGES
));
523 /* If unopered, Only return matching auth blocks */
524 else if((ConfigFileEntry
.stats_i_oper_only
== 1) && !IsOper (source_p
))
526 struct ConfItem
*aconf
;
527 char *name
, *host
, *user
, *classname
;
528 const char *pass
= "*";
531 if(MyConnect (source_p
))
532 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
533 (struct sockaddr
*)&source_p
->localClient
->ip
,
535 source_p
->localClient
->ip
.ss_family
,
536 source_p
->username
, NULL
);
538 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_CLIENT
,
539 0, source_p
->username
, NULL
);
544 get_printable_conf (aconf
, &name
, &host
, &pass
, &user
, &port
, &classname
);
545 if(!EmptyString(aconf
->spasswd
))
546 pass
= aconf
->spasswd
;
548 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
549 name
, pass
, show_iline_prefix(source_p
, aconf
, user
),
550 host
, port
, classname
);
553 /* Theyre opered, or allowed to see all auth blocks */
555 report_auth (source_p
);
560 stats_tklines(struct Client
*source_p
)
562 /* Oper only, if unopered, return ERR_NOPRIVS */
563 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
564 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
565 form_str (ERR_NOPRIVILEGES
));
567 /* If unopered, Only return matching klines */
568 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
570 struct ConfItem
*aconf
;
571 char *host
, *pass
, *user
, *oper_reason
;
573 if(MyConnect (source_p
))
574 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
575 (struct sockaddr
*)&source_p
->localClient
->ip
,
577 source_p
->localClient
->ip
.ss_family
,
578 source_p
->username
, NULL
);
580 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
581 0, source_p
->username
, NULL
);
586 /* dont report a permanent kline as a tkline */
587 if((aconf
->flags
& CONF_FLAGS_TEMPORARY
) == 0)
590 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
592 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
593 form_str(RPL_STATSKLINE
), aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
594 host
, user
, pass
, oper_reason
? "|" : "",
595 oper_reason
? oper_reason
: "");
597 /* Theyre opered, or allowed to see all klines */
600 struct ConfItem
*aconf
;
603 char *user
, *host
, *pass
, *oper_reason
;
605 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
607 RB_DLINK_FOREACH(ptr
, temp_klines
[i
].head
)
611 get_printable_kline(source_p
, aconf
, &host
, &pass
,
612 &user
, &oper_reason
);
614 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
615 form_str(RPL_STATSKLINE
),
616 'k', host
, user
, pass
,
617 oper_reason
? "|" : "",
618 oper_reason
? oper_reason
: "");
625 stats_klines(struct Client
*source_p
)
627 /* Oper only, if unopered, return ERR_NOPRIVS */
628 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
629 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
630 form_str (ERR_NOPRIVILEGES
));
632 /* If unopered, Only return matching klines */
633 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
635 struct ConfItem
*aconf
;
636 char *host
, *pass
, *user
, *oper_reason
;
638 /* search for a kline */
639 if(MyConnect (source_p
))
640 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
641 (struct sockaddr
*)&source_p
->localClient
->ip
,
643 source_p
->localClient
->ip
.ss_family
,
644 source_p
->username
, NULL
);
646 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
647 0, source_p
->username
, NULL
);
652 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
654 sendto_one_numeric(source_p
, RPL_STATSKLINE
, form_str(RPL_STATSKLINE
),
655 aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
656 host
, user
, pass
, oper_reason
? "|" : "",
657 oper_reason
? oper_reason
: "");
659 /* Theyre opered, or allowed to see all klines */
661 report_Klines (source_p
);
665 stats_messages(struct Client
*source_p
)
667 report_messages(source_p
);
671 stats_dnsbl(struct Client
*source_p
)
674 struct Blacklist
*blptr
;
676 RB_DLINK_FOREACH(ptr
, blacklist_list
.head
)
680 /* use RPL_STATSDEBUG for now -- jilles */
681 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "n :%d %s %s (%d)",
684 blptr
->status
& CONF_ILLEGAL
? "disabled" : "active",
690 stats_oper(struct Client
*source_p
)
692 struct oper_conf
*oper_p
;
695 if(!IsOper(source_p
) && ConfigFileEntry
.stats_o_oper_only
)
697 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
698 form_str (ERR_NOPRIVILEGES
));
702 RB_DLINK_FOREACH(ptr
, oper_conf_list
.head
)
706 sendto_one_numeric(source_p
, RPL_STATSOLINE
,
707 form_str(RPL_STATSOLINE
),
708 oper_p
->username
, oper_p
->host
, oper_p
->name
,
709 IsOper(source_p
) ? oper_p
->privset
->name
: "0", "-1");
714 stats_capability_walk(const char *line
, void *data
)
716 struct Client
*client_p
= data
;
718 sendto_one_numeric(client_p
, RPL_STATSDEBUG
, "C :%s", line
);
722 stats_capability(struct Client
*client_p
)
724 capability_index_stats(stats_capability_walk
, client_p
);
728 stats_privset(struct Client
*source_p
)
730 privilegeset_report(source_p
);
735 * input - client pointer
737 * side effects - client is shown a list of active opers
740 stats_operedup (struct Client
*source_p
)
742 struct Client
*target_p
;
743 rb_dlink_node
*oper_ptr
;
744 unsigned int count
= 0;
746 RB_DLINK_FOREACH (oper_ptr
, oper_list
.head
)
748 target_p
= oper_ptr
->data
;
750 if(IsOperInvis(target_p
) && !IsOper(source_p
))
753 if(target_p
->user
->away
)
758 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
760 target_p
->name
, target_p
->username
,
764 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
765 "p :%u staff members", count
);
767 stats_p_spy (source_p
);
771 stats_ports (struct Client
*source_p
)
773 if(!IsOper (source_p
) && ConfigFileEntry
.stats_P_oper_only
)
774 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
775 form_str (ERR_NOPRIVILEGES
));
777 show_ports (source_p
);
781 stats_tresv(struct Client
*source_p
)
783 struct ConfItem
*aconf
;
787 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
791 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
792 form_str(RPL_STATSQLINE
),
793 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
796 HASH_WALK(i
, R_MAX
, ptr
, resvTable
)
800 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
801 form_str(RPL_STATSQLINE
),
802 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
809 stats_resv(struct Client
*source_p
)
811 struct ConfItem
*aconf
;
815 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
819 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
820 form_str(RPL_STATSQLINE
),
821 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
824 HASH_WALK(i
, R_MAX
, ptr
, resvTable
)
828 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
829 form_str(RPL_STATSQLINE
),
830 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
836 stats_usage (struct Client
*source_p
)
851 if(getrusage(RUSAGE_SELF
, &rus
) == -1)
853 sendto_one_notice(source_p
, ":Getruseage error: %s.",
857 secs
= rus
.ru_utime
.tv_sec
+ rus
.ru_stime
.tv_sec
;
861 rup
= (rb_current_time() - startup_time
) * hzz
;
865 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
866 "R :CPU Secs %d:%02d User %d:%02d System %d:%02d",
867 (int) (secs
/ 60), (int) (secs
% 60),
868 (int) (rus
.ru_utime
.tv_sec
/ 60),
869 (int) (rus
.ru_utime
.tv_sec
% 60),
870 (int) (rus
.ru_stime
.tv_sec
/ 60),
871 (int) (rus
.ru_stime
.tv_sec
% 60));
872 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
873 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
874 rus
.ru_maxrss
, (rus
.ru_ixrss
/ rup
),
875 (rus
.ru_idrss
/ rup
), (rus
.ru_isrss
/ rup
));
876 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
877 "R :Swaps %d Reclaims %d Faults %d",
878 (int) rus
.ru_nswap
, (int) rus
.ru_minflt
, (int) rus
.ru_majflt
);
879 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
880 "R :Block in %d out %d",
881 (int) rus
.ru_inblock
, (int) rus
.ru_oublock
);
882 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
883 "R :Msg Rcv %d Send %d",
884 (int) rus
.ru_msgrcv
, (int) rus
.ru_msgsnd
);
885 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
886 "R :Signals %d Context Vol. %d Invol %d",
887 (int) rus
.ru_nsignals
, (int) rus
.ru_nvcsw
,
888 (int) rus
.ru_nivcsw
);
892 stats_tstats (struct Client
*source_p
)
894 struct Client
*target_p
;
895 struct ServerStatistics sp
;
898 memcpy(&sp
, &ServerStats
, sizeof(struct ServerStatistics
));
900 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
902 target_p
= ptr
->data
;
904 sp
.is_sbs
+= target_p
->localClient
->sendB
;
905 sp
.is_sbr
+= target_p
->localClient
->receiveB
;
906 sp
.is_sti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
910 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
912 target_p
= ptr
->data
;
914 sp
.is_cbs
+= target_p
->localClient
->sendB
;
915 sp
.is_cbr
+= target_p
->localClient
->receiveB
;
916 sp
.is_cti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
920 RB_DLINK_FOREACH(ptr
, unknown_list
.head
)
925 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
926 "T :accepts %u refused %u", sp
.is_ac
, sp
.is_ref
);
927 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
928 "T :rejected %u delaying %lu",
929 sp
.is_rej
, delay_exit_length());
930 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
931 "T :throttled refused %u throttle list size %lu", sp
.is_thr
, throttle_size());
932 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
933 "T :nicks being delayed %lu",
935 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
936 "T :unknown commands %u prefixes %u",
937 sp
.is_unco
, sp
.is_unpf
);
938 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
939 "T :nick collisions %u saves %u unknown closes %u",
940 sp
.is_kill
, sp
.is_save
, sp
.is_ni
);
941 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
942 "T :wrong direction %u empty %u",
943 sp
.is_wrdi
, sp
.is_empt
);
944 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
945 "T :numerics seen %u", sp
.is_num
);
946 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
947 "T :tgchange blocked msgs %u restricted addrs %lu",
948 sp
.is_tgch
, rb_dlink_list_length(&tgchange_list
));
949 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
950 "T :ratelimit blocked commands %u", sp
.is_rl
);
951 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
952 "T :auth successes %u fails %u",
953 sp
.is_asuc
, sp
.is_abad
);
954 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
955 "T :sasl successes %u fails %u",
956 sp
.is_ssuc
, sp
.is_sbad
);
957 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "T :Client Server");
958 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
959 "T :connected %u %u", sp
.is_cl
, sp
.is_sv
);
960 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
961 "T :bytes sent %lluK %lluK",
964 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
965 "T :bytes recv %lluK %lluK",
968 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
969 "T :time connected %llu %llu",
970 sp
.is_cti
, sp
.is_sti
);
974 stats_uptime (struct Client
*source_p
)
978 now
= rb_current_time() - startup_time
;
979 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
980 form_str (RPL_STATSUPTIME
),
981 (int)(now
/ 86400), (int)((now
/ 3600) % 24),
982 (int)((now
/ 60) % 60), (int)(now
% 60));
983 sendto_one_numeric(source_p
, RPL_STATSCONN
,
984 form_str (RPL_STATSCONN
),
985 MaxConnectionCount
, MaxClientCount
,
986 Count
.totalrestartcount
);
994 static struct shared_flags shared_flagtable
[] =
996 { SHARED_PKLINE
, 'K' },
997 { SHARED_TKLINE
, 'k' },
998 { SHARED_UNKLINE
, 'U' },
999 { SHARED_PXLINE
, 'X' },
1000 { SHARED_TXLINE
, 'x' },
1001 { SHARED_UNXLINE
, 'Y' },
1002 { SHARED_PRESV
, 'Q' },
1003 { SHARED_TRESV
, 'q' },
1004 { SHARED_UNRESV
, 'R' },
1005 { SHARED_LOCOPS
, 'L' },
1006 { SHARED_REHASH
, 'H' },
1007 { SHARED_TDLINE
, 'd' },
1008 { SHARED_PDLINE
, 'D' },
1009 { SHARED_UNDLINE
, 'E' },
1015 stats_shared (struct Client
*source_p
)
1017 struct remote_conf
*shared_p
;
1019 char buf
[sizeof(shared_flagtable
)/sizeof(shared_flagtable
[0])];
1023 RB_DLINK_FOREACH(ptr
, shared_conf_list
.head
)
1025 shared_p
= ptr
->data
;
1031 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1033 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1034 *p
++ = shared_flagtable
[i
].letter
;
1039 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1040 form_str(RPL_STATSULINE
),
1041 shared_p
->server
, shared_p
->username
,
1042 shared_p
->host
, buf
);
1045 RB_DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
1047 shared_p
= ptr
->data
;
1053 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1055 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1056 *p
++ = shared_flagtable
[i
].letter
;
1061 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1062 form_str(RPL_STATSULINE
),
1063 shared_p
->server
, "*", "*", buf
);
1069 * input - client pointer
1071 * side effects - client is shown lists of who connected servers
1074 stats_servers (struct Client
*source_p
)
1076 struct Client
*target_p
;
1079 int days
, hours
, minutes
;
1082 if(ConfigServerHide
.flatten_links
&& !IsOper(source_p
) &&
1083 !IsExemptShide(source_p
))
1085 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1086 form_str (ERR_NOPRIVILEGES
));
1090 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1092 target_p
= ptr
->data
;
1095 seconds
= rb_current_time() - target_p
->localClient
->firsttime
;
1097 days
= (int) (seconds
/ 86400);
1099 hours
= (int) (seconds
/ 3600);
1101 minutes
= (int) (seconds
/ 60);
1104 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1105 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1106 "Connected: %d day%s, %d:%02d:%02d",
1108 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
1109 (int) (rb_current_time() - target_p
->localClient
->lasttime
),
1110 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1111 days
, (days
== 1) ? "" : "s", hours
, minutes
,
1115 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1116 "V :%d Server(s)", j
);
1120 stats_tgecos(struct Client
*source_p
)
1122 struct ConfItem
*aconf
;
1125 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1130 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1131 form_str(RPL_STATSXLINE
),
1132 'x', aconf
->port
, aconf
->host
,
1138 stats_gecos(struct Client
*source_p
)
1140 struct ConfItem
*aconf
;
1143 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1148 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1149 form_str(RPL_STATSXLINE
),
1150 'X', aconf
->port
, aconf
->host
,
1156 stats_class(struct Client
*source_p
)
1158 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOper(source_p
))
1159 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1160 form_str (ERR_NOPRIVILEGES
));
1162 report_classes(source_p
);
1166 stats_memory (struct Client
*source_p
)
1168 struct Client
*target_p
;
1169 struct Channel
*chptr
;
1170 rb_dlink_node
*rb_dlink
;
1172 int channel_count
= 0;
1173 int local_client_conf_count
= 0; /* local client conf links */
1174 int users_counted
= 0; /* user structs */
1176 int channel_users
= 0;
1177 int channel_invites
= 0;
1178 int channel_bans
= 0;
1179 int channel_except
= 0;
1180 int channel_invex
= 0;
1181 int channel_quiets
= 0;
1183 int class_count
= 0; /* classes */
1184 int conf_count
= 0; /* conf lines */
1185 int users_invited_count
= 0; /* users invited */
1186 int user_channels
= 0; /* users in channels */
1187 int aways_counted
= 0;
1188 size_t number_servers_cached
; /* number of servers cached by scache */
1190 size_t channel_memory
= 0;
1191 size_t channel_ban_memory
= 0;
1192 size_t channel_except_memory
= 0;
1193 size_t channel_invex_memory
= 0;
1194 size_t channel_quiet_memory
= 0;
1196 size_t away_memory
= 0; /* memory used by aways */
1197 size_t ww
= 0; /* whowas array count */
1198 size_t wwm
= 0; /* whowas array memory used */
1199 size_t conf_memory
= 0; /* memory used by conf lines */
1200 size_t mem_servers_cached
; /* memory used by scache */
1202 size_t linebuf_count
= 0;
1203 size_t linebuf_memory_used
= 0;
1205 size_t total_channel_memory
= 0;
1208 size_t local_client_count
= 0;
1209 size_t local_client_memory_used
= 0;
1211 size_t remote_client_count
= 0;
1212 size_t remote_client_memory_used
= 0;
1214 size_t total_memory
= 0;
1216 count_whowas_memory(&ww
, &wwm
);
1218 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
1220 target_p
= ptr
->data
;
1221 if(MyConnect(target_p
))
1223 local_client_conf_count
++;
1229 users_invited_count
+= rb_dlink_list_length(&target_p
->user
->invited
);
1230 user_channels
+= rb_dlink_list_length(&target_p
->user
->channel
);
1231 if(target_p
->user
->away
)
1234 away_memory
+= (strlen(target_p
->user
->away
) + 1);
1239 /* Count up all channels, ban lists, except lists, Invex lists */
1240 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
1244 channel_memory
+= (strlen(chptr
->chname
) + sizeof(struct Channel
));
1246 channel_users
+= rb_dlink_list_length(&chptr
->members
);
1247 channel_invites
+= rb_dlink_list_length(&chptr
->invites
);
1249 RB_DLINK_FOREACH(rb_dlink
, chptr
->banlist
.head
)
1253 channel_ban_memory
+= sizeof(rb_dlink_node
) + sizeof(struct Ban
);
1256 RB_DLINK_FOREACH(rb_dlink
, chptr
->exceptlist
.head
)
1260 channel_except_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1263 RB_DLINK_FOREACH(rb_dlink
, chptr
->invexlist
.head
)
1267 channel_invex_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1270 RB_DLINK_FOREACH(rb_dlink
, chptr
->quietlist
.head
)
1274 channel_quiet_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1278 /* count up all classes */
1280 class_count
= rb_dlink_list_length(&class_list
) + 1;
1282 rb_count_rb_linebuf_memory(&linebuf_count
, &linebuf_memory_used
);
1284 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1285 "z :Users %u(%lu) Invites %u(%lu)",
1287 (unsigned long) users_counted
* sizeof(struct User
),
1288 users_invited_count
,
1289 (unsigned long) users_invited_count
* sizeof(rb_dlink_node
));
1291 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1292 "z :User channels %u(%lu) Aways %u(%d)",
1294 (unsigned long) user_channels
* sizeof(rb_dlink_node
),
1295 aways_counted
, (int) away_memory
);
1297 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1298 "z :Attached confs %u(%lu)",
1299 local_client_conf_count
,
1300 (unsigned long) local_client_conf_count
* sizeof(rb_dlink_node
));
1302 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1303 "z :Conflines %u(%d)", conf_count
, (int) conf_memory
);
1305 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1306 "z :Classes %u(%lu)",
1308 (unsigned long) class_count
* sizeof(struct Class
));
1310 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1311 "z :Channels %u(%d)",
1312 channel_count
, (int) channel_memory
);
1314 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1315 "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)",
1316 channel_bans
, (int) channel_ban_memory
,
1317 channel_except
, (int) channel_except_memory
,
1318 channel_invex
, (int) channel_invex_memory
,
1319 channel_quiets
, (int) channel_quiet_memory
);
1321 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1322 "z :Channel members %u(%lu) invite %u(%lu)",
1324 (unsigned long) channel_users
* sizeof(rb_dlink_node
),
1326 (unsigned long) channel_invites
* sizeof(rb_dlink_node
));
1328 total_channel_memory
= channel_memory
+
1329 channel_ban_memory
+
1330 channel_users
* sizeof(rb_dlink_node
) + channel_invites
* sizeof(rb_dlink_node
);
1332 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1333 "z :Whowas array %ld(%ld)",
1334 (long)ww
, (long)wwm
);
1338 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1339 "z :Hash: client %u(%ld) chan %u(%ld)",
1340 U_MAX
, (long)(U_MAX
* sizeof(rb_dlink_list
)),
1341 CH_MAX
, (long)(CH_MAX
* sizeof(rb_dlink_list
)));
1343 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1344 "z :linebuf %ld(%ld)",
1345 (long)linebuf_count
, (long)linebuf_memory_used
);
1347 count_scache(&number_servers_cached
, &mem_servers_cached
);
1349 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1350 "z :scache %ld(%ld)",
1351 (long)number_servers_cached
, (long)mem_servers_cached
);
1353 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1354 "z :hostname hash %d(%ld)",
1355 HOST_MAX
, (long)HOST_MAX
* sizeof(rb_dlink_list
));
1357 total_memory
= totww
+ total_channel_memory
+ conf_memory
+
1358 class_count
* sizeof(struct Class
);
1360 total_memory
+= mem_servers_cached
;
1361 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1362 "z :Total: whowas %d channel %d conf %d",
1363 (int) totww
, (int) total_channel_memory
,
1366 count_local_client_memory(&local_client_count
, &local_client_memory_used
);
1367 total_memory
+= local_client_memory_used
;
1369 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1370 "z :Local client Memory in use: %ld(%ld)",
1371 (long)local_client_count
, (long)local_client_memory_used
);
1374 count_remote_client_memory(&remote_client_count
, &remote_client_memory_used
);
1375 total_memory
+= remote_client_memory_used
;
1377 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1378 "z :Remote client Memory in use: %ld(%ld)",
1379 (long)remote_client_count
,
1380 (long)remote_client_memory_used
);
1384 stats_ziplinks (struct Client
*source_p
)
1387 struct Client
*target_p
;
1388 struct ZipStats
*zipstats
;
1390 char buf
[128], buf1
[128];
1391 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1393 target_p
= ptr
->data
;
1394 if(IsCapable (target_p
, CAP_ZIP
))
1396 zipstats
= target_p
->localClient
->zipstats
;
1397 sprintf(buf
, "%.2f%%", zipstats
->out_ratio
);
1398 sprintf(buf1
, "%.2f%%", zipstats
->in_ratio
);
1399 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1400 "Z :ZipLinks stats for %s send[%s compression "
1401 "(%llu kB data/%llu kB wire)] recv[%s compression "
1402 "(%llu kB data/%llu kB wire)]",
1404 buf
, zipstats
->out
>> 10,
1405 zipstats
->out_wire
>> 10, buf1
,
1406 zipstats
->in
>> 10, zipstats
->in_wire
>> 10);
1411 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1412 "Z :%u ziplink(s)", sent_data
);
1416 stats_servlinks (struct Client
*source_p
)
1418 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1419 long uptime
, sendK
, receiveK
;
1420 struct Client
*target_p
;
1425 if(ConfigServerHide
.flatten_links
&& !IsOper (source_p
) &&
1426 !IsExemptShide(source_p
))
1428 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1429 form_str (ERR_NOPRIVILEGES
));
1433 sendK
= receiveK
= 0;
1435 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1437 target_p
= ptr
->data
;
1440 sendK
+= target_p
->localClient
->sendK
;
1441 receiveK
+= target_p
->localClient
->receiveK
;
1443 sendto_one(source_p
, Sformat
,
1444 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1446 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1447 (int) target_p
->localClient
->sendM
,
1448 (int) target_p
->localClient
->sendK
,
1449 (int) target_p
->localClient
->receiveM
,
1450 (int) target_p
->localClient
->receiveK
,
1451 rb_current_time() - target_p
->localClient
->firsttime
,
1452 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1453 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1454 IsOper (source_p
) ? show_capabilities (target_p
) : "TS");
1457 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1458 "? :%u total server(s)", j
);
1460 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((sendK
)));
1461 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1462 "? :Sent total : %s %s",
1463 buf
, _GMKs (sendK
));
1464 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((receiveK
)));
1465 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1466 "? :Recv total : %s %s",
1467 buf
, _GMKs (receiveK
));
1469 uptime
= (rb_current_time() - startup_time
);
1470 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1471 _GMKv (me
.localClient
->sendK
),
1472 _GMKs (me
.localClient
->sendK
),
1473 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1474 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server send: %s", buf
);
1475 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1476 _GMKv (me
.localClient
->receiveK
),
1477 _GMKs (me
.localClient
->receiveK
),
1478 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1479 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server recv: %s", buf
);
1483 stats_l_should_show_oper(struct Client
*target_p
)
1485 if (IsOperInvis(target_p
))
1492 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1497 char statchar
= parv
[1][0];
1499 /* this is def targeted at us somehow.. */
1500 if(parc
> 2 && !EmptyString(parv
[2]))
1502 /* directed at us generically? */
1503 if(match(parv
[2], me
.name
) ||
1504 (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1512 wilds
= strchr(name
, '*') || strchr(name
, '?');
1515 /* must be directed at a specific person thats not us */
1516 if(!doall
&& !wilds
)
1518 struct Client
*target_p
;
1520 if(MyClient(source_p
))
1521 target_p
= find_named_person(name
);
1523 target_p
= find_person(name
);
1525 if(target_p
!= NULL
)
1527 stats_spy(source_p
, statchar
, target_p
->name
);
1528 stats_l_client(source_p
, target_p
, statchar
);
1531 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1532 form_str(ERR_NOSUCHSERVER
),
1544 stats_spy(source_p
, statchar
, name
);
1548 /* local opers get everyone */
1549 if(MyOper(source_p
))
1551 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
, NULL
);
1552 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1556 /* they still need themselves if theyre local.. */
1557 if(MyClient(source_p
))
1558 stats_l_client(source_p
, source_p
, statchar
);
1560 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
, stats_l_should_show_oper
);
1563 if (!ConfigServerHide
.flatten_links
|| IsOper(source_p
) ||
1564 IsExemptShide(source_p
))
1565 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
, NULL
);
1570 /* ok, at this point theyre looking for a specific client whos on
1571 * our server.. but it contains a wildcard. --fl
1573 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1579 stats_l_list(struct Client
*source_p
, const char *name
, int doall
, int wilds
,
1580 rb_dlink_list
* list
, char statchar
, int (*check_fn
)(struct Client
*target_p
))
1583 struct Client
*target_p
;
1585 /* send information about connections which match. note, we
1586 * dont need tests for IsInvisible(), because non-opers will
1587 * never get here for normal clients --fl
1589 RB_DLINK_FOREACH(ptr
, list
->head
)
1591 target_p
= ptr
->data
;
1593 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1596 if (check_fn
== NULL
|| check_fn(target_p
))
1597 stats_l_client(source_p
, target_p
, statchar
);
1602 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1605 if(IsAnyServer(target_p
))
1607 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1609 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1610 (int) target_p
->localClient
->sendM
,
1611 (int) target_p
->localClient
->sendK
,
1612 (int) target_p
->localClient
->receiveM
,
1613 (int) target_p
->localClient
->receiveK
,
1614 rb_current_time() - target_p
->localClient
->firsttime
,
1615 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1616 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1617 IsOper(source_p
) ? show_capabilities(target_p
) : "-");
1622 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1623 show_ip(source_p
, target_p
) ?
1624 (IsUpper(statchar
) ?
1625 get_client_name(target_p
, SHOW_IP
) :
1626 get_client_name(target_p
, HIDE_IP
)) :
1627 get_client_name(target_p
, MASK_IP
),
1628 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1629 (int) target_p
->localClient
->sendM
,
1630 (int) target_p
->localClient
->sendK
,
1631 (int) target_p
->localClient
->receiveM
,
1632 (int) target_p
->localClient
->receiveK
,
1633 rb_current_time() - target_p
->localClient
->firsttime
,
1634 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1635 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1641 rb_dump_fd_callback(int fd
, const char *desc
, void *data
)
1643 struct Client
*source_p
= data
;
1644 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "F :fd %-3d desc '%s'", fd
, desc
);
1648 stats_comm(struct Client
*source_p
)
1650 rb_dump_fd(rb_dump_fd_callback
, source_p
);
1656 * inputs - pointer to client doing the /stats
1657 * - char letter they are doing /stats on
1660 * This little helper function reports to opers if configured.
1661 * personally, I don't see why opers need to see stats requests
1662 * at all. They are just "noise" to an oper, and users can't do
1663 * any damage with stats requests now anyway. So, why show them?
1667 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1671 data
.client
= source_p
;
1673 data
.arg2
= (int) statchar
;
1675 call_hook(doing_stats_hook
, &data
);
1680 * input - pointer to client doing stats
1682 * side effects - call hook doing_stats_p
1685 stats_p_spy (struct Client
*source_p
)
1689 data
.client
= source_p
;
1690 data
.arg1
= data
.arg2
= NULL
;
1692 call_hook(doing_stats_p_hook
, &data
);