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 static void stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
77 static void stats_spy(struct Client
*, char, const char *);
78 static void stats_p_spy(struct Client
*);
80 /* Heres our struct for the stats table */
84 void (*handler
) (struct Client
*source_p
);
89 static void stats_dns_servers(struct Client
*);
90 static void stats_delay(struct Client
*);
91 static void stats_hash(struct Client
*);
92 static void stats_connect(struct Client
*);
93 static void stats_tdeny(struct Client
*);
94 static void stats_deny(struct Client
*);
95 static void stats_exempt(struct Client
*);
96 static void stats_events(struct Client
*);
97 static void stats_prop_klines(struct Client
*);
98 static void stats_hubleaf(struct Client
*);
99 static void stats_auth(struct Client
*);
100 static void stats_tklines(struct Client
*);
101 static void stats_klines(struct Client
*);
102 static void stats_messages(struct Client
*);
103 static void stats_dnsbl(struct Client
*);
104 static void stats_oper(struct Client
*);
105 static void stats_privset(struct Client
*);
106 static void stats_operedup(struct Client
*);
107 static void stats_ports(struct Client
*);
108 static void stats_tresv(struct Client
*);
109 static void stats_resv(struct Client
*);
110 static void stats_usage(struct Client
*);
111 static void stats_tstats(struct Client
*);
112 static void stats_uptime(struct Client
*);
113 static void stats_shared(struct Client
*);
114 static void stats_servers(struct Client
*);
115 static void stats_tgecos(struct Client
*);
116 static void stats_gecos(struct Client
*);
117 static void stats_class(struct Client
*);
118 static void stats_memory(struct Client
*);
119 static void stats_servlinks(struct Client
*);
120 static void stats_ltrace(struct Client
*, int, const char **);
121 static void stats_ziplinks(struct Client
*);
122 static void stats_comm(struct Client
*);
123 /* This table contains the possible stats items, in order:
124 * stats letter, function to call, operonly? adminonly?
125 * case only matters in the stats letter column.. -- fl_
127 static struct StatsStruct stats_cmd_table
[] = {
128 /* letter function need_oper need_admin */
129 {'a', stats_dns_servers
, 1, 1, },
130 {'A', stats_dns_servers
, 1, 1, },
131 {'b', stats_delay
, 1, 1, },
132 {'B', stats_hash
, 1, 1, },
133 {'c', stats_connect
, 0, 0, },
134 {'C', stats_connect
, 0, 0, },
135 {'d', stats_tdeny
, 1, 0, },
136 {'D', stats_deny
, 1, 0, },
137 {'e', stats_exempt
, 1, 0, },
138 {'E', stats_events
, 1, 1, },
139 {'f', stats_comm
, 1, 1, },
140 {'F', stats_comm
, 1, 1, },
141 {'g', stats_prop_klines
, 1, 0, },
142 {'h', stats_hubleaf
, 0, 0, },
143 {'H', stats_hubleaf
, 0, 0, },
144 {'i', stats_auth
, 0, 0, },
145 {'I', stats_auth
, 0, 0, },
146 {'k', stats_tklines
, 0, 0, },
147 {'K', stats_klines
, 0, 0, },
148 {'l', NULL
/* special */, 0, 0, },
149 {'L', NULL
/* special */, 0, 0, },
150 {'m', stats_messages
, 0, 0, },
151 {'M', stats_messages
, 0, 0, },
152 {'n', stats_dnsbl
, 0, 0, },
153 {'o', stats_oper
, 0, 0, },
154 {'O', stats_privset
, 1, 0, },
155 {'p', stats_operedup
, 0, 0, },
156 {'P', stats_ports
, 0, 0, },
157 {'q', stats_tresv
, 1, 0, },
158 {'Q', stats_resv
, 1, 0, },
159 {'r', stats_usage
, 1, 0, },
160 {'R', stats_usage
, 1, 0, },
161 {'t', stats_tstats
, 1, 0, },
162 {'T', stats_tstats
, 1, 0, },
163 {'u', stats_uptime
, 0, 0, },
164 {'U', stats_shared
, 1, 0, },
165 {'v', stats_servers
, 0, 0, },
166 {'V', stats_servers
, 0, 0, },
167 {'x', stats_tgecos
, 1, 0, },
168 {'X', stats_gecos
, 1, 0, },
169 {'y', stats_class
, 0, 0, },
170 {'Y', stats_class
, 0, 0, },
171 {'z', stats_memory
, 1, 0, },
172 {'Z', stats_ziplinks
, 1, 0, },
173 {'?', stats_servlinks
, 0, 0, },
174 {(char) 0, (void (*)()) 0, 0, 0, }
179 * parv[1] = stat letter/command
180 * parv[2] = (if present) server/mask in stats L, or target
182 * This will search the tables for the appropriate stats letter,
183 * if found execute it.
186 m_stats(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
188 static time_t last_used
= 0;
192 statchar
= parv
[1][0];
194 if(MyClient(source_p
) && !IsOper(source_p
))
196 /* Check the user is actually allowed to do /stats, and isnt flooding */
197 if((last_used
+ ConfigFileEntry
.pace_wait
) > rb_current_time())
199 /* safe enough to give this on a local connect only */
200 sendto_one(source_p
, form_str(RPL_LOAD2HI
),
201 me
.name
, source_p
->name
, "STATS");
202 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
203 form_str(RPL_ENDOFSTATS
), statchar
);
207 last_used
= rb_current_time();
210 if(hunt_server (client_p
, source_p
, ":%s STATS %s :%s", 2, parc
, parv
) != HUNTED_ISME
)
213 if((statchar
!= 'L') && (statchar
!= 'l'))
214 stats_spy(source_p
, statchar
, NULL
);
216 for (i
= 0; stats_cmd_table
[i
].letter
; i
++)
218 if(stats_cmd_table
[i
].letter
== statchar
)
220 /* The stats table says what privs are needed, so check --fl_ */
221 /* Called for remote clients and for local opers, so check need_admin
224 if(stats_cmd_table
[i
].need_oper
&& !IsOper(source_p
))
226 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
227 form_str (ERR_NOPRIVILEGES
));
230 if(stats_cmd_table
[i
].need_admin
&& !IsOperAdmin(source_p
))
232 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
233 me
.name
, source_p
->name
, "admin");
237 /* Blah, stats L needs the parameters, none of the others do.. */
238 if(statchar
== 'L' || statchar
== 'l')
239 stats_ltrace (source_p
, parc
, parv
);
241 stats_cmd_table
[i
].handler (source_p
);
245 /* Send the end of stats notice, and the stats_spy */
246 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
247 form_str(RPL_ENDOFSTATS
), statchar
);
253 stats_dns_servers (struct Client
*source_p
)
255 report_dns_servers (source_p
);
259 stats_delay(struct Client
*source_p
)
262 struct DictionaryIter iter
;
264 DICTIONARY_FOREACH(nd
, &iter
, nd_dict
)
266 sendto_one_notice(source_p
, ":Delaying: %s for %ld",
267 nd
->name
, (long) nd
->expire
);
272 stats_hash(struct Client
*source_p
)
274 hash_stats(source_p
);
278 stats_connect(struct Client
*source_p
)
281 struct server_conf
*server_p
;
285 if((ConfigFileEntry
.stats_c_oper_only
||
286 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
289 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
290 form_str(ERR_NOPRIVILEGES
));
294 RB_DLINK_FOREACH(ptr
, server_conf_list
.head
)
296 server_p
= ptr
->data
;
298 if(ServerConfIllegal(server_p
))
306 if(ServerConfAutoconn(server_p
))
308 if(ServerConfSSL(server_p
))
310 if(ServerConfTb(server_p
))
312 if(ServerConfCompressed(server_p
))
321 sendto_one_numeric(source_p
, RPL_STATSCLINE
,
322 form_str(RPL_STATSCLINE
),
325 server_p
->port
, server_p
->class_name
);
331 * input - client to report to
333 * side effects - client is given temp dline list.
336 stats_tdeny (struct Client
*source_p
)
338 char *host
, *pass
, *user
, *oper_reason
;
339 struct AddressRec
*arec
;
340 struct ConfItem
*aconf
;
343 for (i
= 0; i
< ATABLE_SIZE
; i
++)
345 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
347 if(arec
->type
== CONF_DLINE
)
351 if(!(aconf
->flags
& CONF_FLAGS_TEMPORARY
))
354 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
356 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
357 form_str (RPL_STATSDLINE
),
359 oper_reason
? "|" : "",
360 oper_reason
? oper_reason
: "");
368 * input - client to report to
370 * side effects - client is given dline list.
373 stats_deny (struct Client
*source_p
)
375 char *host
, *pass
, *user
, *oper_reason
;
376 struct AddressRec
*arec
;
377 struct ConfItem
*aconf
;
380 for (i
= 0; i
< ATABLE_SIZE
; i
++)
382 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
384 if(arec
->type
== CONF_DLINE
)
388 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
391 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
393 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
394 form_str (RPL_STATSDLINE
),
396 oper_reason
? "|" : "",
397 oper_reason
? oper_reason
: "");
406 * input - client to report to
408 * side effects - client is given list of exempt blocks
411 stats_exempt(struct Client
*source_p
)
413 char *name
, *host
, *pass
, *user
, *classname
;
414 struct AddressRec
*arec
;
415 struct ConfItem
*aconf
;
418 if(ConfigFileEntry
.stats_e_disabled
)
420 sendto_one_numeric(source_p
, ERR_DISABLED
,
421 form_str(ERR_DISABLED
), "STATS e");
425 for (i
= 0; i
< ATABLE_SIZE
; i
++)
427 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
429 if(arec
->type
== CONF_EXEMPTDLINE
)
432 get_printable_conf (aconf
, &name
, &host
, &pass
,
433 &user
, &port
, &classname
);
435 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
436 form_str(RPL_STATSDLINE
),
437 'e', host
, pass
, "", "");
444 stats_events_cb(char *str
, void *ptr
)
446 sendto_one_numeric(ptr
, RPL_STATSDEBUG
, "E :%s", str
);
450 stats_events (struct Client
*source_p
)
452 rb_dump_events(stats_events_cb
, source_p
);
456 stats_prop_klines(struct Client
*source_p
)
458 struct ConfItem
*aconf
;
460 char *user
, *host
, *pass
, *oper_reason
;
462 RB_DLINK_FOREACH(ptr
, prop_bans
.head
)
466 /* Skip non-klines and deactivated klines. */
467 if(aconf
->status
!= CONF_KILL
)
470 get_printable_kline(source_p
, aconf
, &host
, &pass
,
471 &user
, &oper_reason
);
473 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
474 form_str(RPL_STATSKLINE
),
475 'g', host
, user
, pass
,
476 oper_reason
? "|" : "",
477 oper_reason
? oper_reason
: "");
482 stats_hubleaf(struct Client
*source_p
)
484 struct remote_conf
*hub_p
;
487 if((ConfigFileEntry
.stats_h_oper_only
||
488 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
491 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
492 form_str (ERR_NOPRIVILEGES
));
496 RB_DLINK_FOREACH(ptr
, hubleaf_conf_list
.head
)
500 if(hub_p
->flags
& CONF_HUB
)
501 sendto_one_numeric(source_p
, RPL_STATSHLINE
,
502 form_str(RPL_STATSHLINE
),
503 hub_p
->host
, hub_p
->server
);
505 sendto_one_numeric(source_p
, RPL_STATSLLINE
,
506 form_str(RPL_STATSLLINE
),
507 hub_p
->host
, hub_p
->server
);
513 stats_auth (struct Client
*source_p
)
515 /* Oper only, if unopered, return ERR_NOPRIVS */
516 if((ConfigFileEntry
.stats_i_oper_only
== 2) && !IsOper (source_p
))
517 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
518 form_str (ERR_NOPRIVILEGES
));
520 /* If unopered, Only return matching auth blocks */
521 else if((ConfigFileEntry
.stats_i_oper_only
== 1) && !IsOper (source_p
))
523 struct ConfItem
*aconf
;
524 char *name
, *host
, *pass
= "*", *user
, *classname
;
527 if(MyConnect (source_p
))
528 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
529 (struct sockaddr
*)&source_p
->localClient
->ip
,
531 source_p
->localClient
->ip
.ss_family
,
532 source_p
->username
, NULL
);
534 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_CLIENT
,
535 0, source_p
->username
, NULL
);
540 get_printable_conf (aconf
, &name
, &host
, &pass
, &user
, &port
, &classname
);
541 if(!EmptyString(aconf
->spasswd
))
542 pass
= aconf
->spasswd
;
544 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
545 name
, pass
, show_iline_prefix(source_p
, aconf
, user
),
546 host
, port
, classname
);
549 /* Theyre opered, or allowed to see all auth blocks */
551 report_auth (source_p
);
556 stats_tklines(struct Client
*source_p
)
558 /* Oper only, if unopered, return ERR_NOPRIVS */
559 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
560 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
561 form_str (ERR_NOPRIVILEGES
));
563 /* If unopered, Only return matching klines */
564 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
566 struct ConfItem
*aconf
;
567 char *host
, *pass
, *user
, *oper_reason
;
569 if(MyConnect (source_p
))
570 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
571 (struct sockaddr
*)&source_p
->localClient
->ip
,
573 source_p
->localClient
->ip
.ss_family
,
574 source_p
->username
, NULL
);
576 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
577 0, source_p
->username
, NULL
);
582 /* dont report a permanent kline as a tkline */
583 if((aconf
->flags
& CONF_FLAGS_TEMPORARY
) == 0)
586 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
588 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
589 form_str(RPL_STATSKLINE
), aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
590 host
, user
, pass
, oper_reason
? "|" : "",
591 oper_reason
? oper_reason
: "");
593 /* Theyre opered, or allowed to see all klines */
596 struct ConfItem
*aconf
;
599 char *user
, *host
, *pass
, *oper_reason
;
601 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
603 RB_DLINK_FOREACH(ptr
, temp_klines
[i
].head
)
607 get_printable_kline(source_p
, aconf
, &host
, &pass
,
608 &user
, &oper_reason
);
610 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
611 form_str(RPL_STATSKLINE
),
612 'k', host
, user
, pass
,
613 oper_reason
? "|" : "",
614 oper_reason
? oper_reason
: "");
621 stats_klines(struct Client
*source_p
)
623 /* Oper only, if unopered, return ERR_NOPRIVS */
624 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
625 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
626 form_str (ERR_NOPRIVILEGES
));
628 /* If unopered, Only return matching klines */
629 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
631 struct ConfItem
*aconf
;
632 char *host
, *pass
, *user
, *oper_reason
;
634 /* search for a kline */
635 if(MyConnect (source_p
))
636 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
637 (struct sockaddr
*)&source_p
->localClient
->ip
,
639 source_p
->localClient
->ip
.ss_family
,
640 source_p
->username
, NULL
);
642 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
643 0, source_p
->username
, NULL
);
648 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
650 sendto_one_numeric(source_p
, RPL_STATSKLINE
, form_str(RPL_STATSKLINE
),
651 aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
652 host
, user
, pass
, oper_reason
? "|" : "",
653 oper_reason
? oper_reason
: "");
655 /* Theyre opered, or allowed to see all klines */
657 report_Klines (source_p
);
661 stats_messages(struct Client
*source_p
)
663 report_messages(source_p
);
667 stats_dnsbl(struct Client
*source_p
)
670 struct Blacklist
*blptr
;
672 RB_DLINK_FOREACH(ptr
, blacklist_list
.head
)
676 /* use RPL_STATSDEBUG for now -- jilles */
677 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "n :%d %s %s (%d)",
680 blptr
->status
& CONF_ILLEGAL
? "disabled" : "active",
686 stats_oper(struct Client
*source_p
)
688 struct oper_conf
*oper_p
;
691 if(!IsOper(source_p
) && ConfigFileEntry
.stats_o_oper_only
)
693 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
694 form_str (ERR_NOPRIVILEGES
));
698 RB_DLINK_FOREACH(ptr
, oper_conf_list
.head
)
702 sendto_one_numeric(source_p
, RPL_STATSOLINE
,
703 form_str(RPL_STATSOLINE
),
704 oper_p
->username
, oper_p
->host
, oper_p
->name
,
705 IsOper(source_p
) ? oper_p
->privset
->name
: "0", "-1");
710 stats_privset(struct Client
*source_p
)
712 privilegeset_report(source_p
);
717 * input - client pointer
719 * side effects - client is shown a list of active opers
722 stats_operedup (struct Client
*source_p
)
724 struct Client
*target_p
;
725 rb_dlink_node
*oper_ptr
;
726 unsigned int count
= 0;
728 RB_DLINK_FOREACH (oper_ptr
, oper_list
.head
)
730 target_p
= oper_ptr
->data
;
732 if(IsOperInvis(target_p
) && !IsOper(source_p
))
735 if(target_p
->user
->away
)
740 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
742 target_p
->name
, target_p
->username
,
746 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
747 "p :%u staff members", count
);
749 stats_p_spy (source_p
);
753 stats_ports (struct Client
*source_p
)
755 if(!IsOper (source_p
) && ConfigFileEntry
.stats_P_oper_only
)
756 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
757 form_str (ERR_NOPRIVILEGES
));
759 show_ports (source_p
);
763 stats_tresv(struct Client
*source_p
)
765 struct ConfItem
*aconf
;
769 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
773 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
774 form_str(RPL_STATSQLINE
),
775 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
778 HASH_WALK(i
, R_MAX
, ptr
, resvTable
)
782 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
783 form_str(RPL_STATSQLINE
),
784 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
791 stats_resv(struct Client
*source_p
)
793 struct ConfItem
*aconf
;
797 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
801 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
802 form_str(RPL_STATSQLINE
),
803 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
806 HASH_WALK(i
, R_MAX
, ptr
, resvTable
)
810 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
811 form_str(RPL_STATSQLINE
),
812 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
818 stats_usage (struct Client
*source_p
)
833 if(getrusage(RUSAGE_SELF
, &rus
) == -1)
835 sendto_one_notice(source_p
, ":Getruseage error: %s.",
839 secs
= rus
.ru_utime
.tv_sec
+ rus
.ru_stime
.tv_sec
;
843 rup
= (rb_current_time() - startup_time
) * hzz
;
847 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
848 "R :CPU Secs %d:%d User %d:%d System %d:%d",
849 (int) (secs
/ 60), (int) (secs
% 60),
850 (int) (rus
.ru_utime
.tv_sec
/ 60),
851 (int) (rus
.ru_utime
.tv_sec
% 60),
852 (int) (rus
.ru_stime
.tv_sec
/ 60),
853 (int) (rus
.ru_stime
.tv_sec
% 60));
854 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
855 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
856 rus
.ru_maxrss
, (rus
.ru_ixrss
/ rup
),
857 (rus
.ru_idrss
/ rup
), (rus
.ru_isrss
/ rup
));
858 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
859 "R :Swaps %d Reclaims %d Faults %d",
860 (int) rus
.ru_nswap
, (int) rus
.ru_minflt
, (int) rus
.ru_majflt
);
861 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
862 "R :Block in %d out %d",
863 (int) rus
.ru_inblock
, (int) rus
.ru_oublock
);
864 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
865 "R :Msg Rcv %d Send %d",
866 (int) rus
.ru_msgrcv
, (int) rus
.ru_msgsnd
);
867 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
868 "R :Signals %d Context Vol. %d Invol %d",
869 (int) rus
.ru_nsignals
, (int) rus
.ru_nvcsw
,
870 (int) rus
.ru_nivcsw
);
874 stats_tstats (struct Client
*source_p
)
876 struct Client
*target_p
;
877 struct ServerStatistics sp
;
880 memcpy(&sp
, &ServerStats
, sizeof(struct ServerStatistics
));
882 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
884 target_p
= ptr
->data
;
886 sp
.is_sbs
+= target_p
->localClient
->sendB
;
887 sp
.is_sbr
+= target_p
->localClient
->receiveB
;
888 sp
.is_sti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
892 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
894 target_p
= ptr
->data
;
896 sp
.is_cbs
+= target_p
->localClient
->sendB
;
897 sp
.is_cbr
+= target_p
->localClient
->receiveB
;
898 sp
.is_cti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
902 RB_DLINK_FOREACH(ptr
, unknown_list
.head
)
907 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
908 "T :accepts %u refused %u", sp
.is_ac
, sp
.is_ref
);
909 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
910 "T :rejected %u delaying %lu",
911 sp
.is_rej
, delay_exit_length());
912 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
913 "T :throttled refused %u throttle list size %lu", sp
.is_thr
, throttle_size());
914 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
915 "T :nicks being delayed %lu",
917 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
918 "T :unknown commands %u prefixes %u",
919 sp
.is_unco
, sp
.is_unpf
);
920 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
921 "T :nick collisions %u saves %u unknown closes %u",
922 sp
.is_kill
, sp
.is_save
, sp
.is_ni
);
923 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
924 "T :wrong direction %u empty %u",
925 sp
.is_wrdi
, sp
.is_empt
);
926 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
927 "T :numerics seen %u", sp
.is_num
);
928 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
929 "T :tgchange blocked msgs %u restricted addrs %lu",
930 sp
.is_tgch
, rb_dlink_list_length(&tgchange_list
));
931 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
932 "T :auth successes %u fails %u",
933 sp
.is_asuc
, sp
.is_abad
);
934 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
935 "T :sasl successes %u fails %u",
936 sp
.is_ssuc
, sp
.is_sbad
);
937 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "T :Client Server");
938 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
939 "T :connected %u %u", sp
.is_cl
, sp
.is_sv
);
940 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
941 "T :bytes sent %lluK %lluK",
944 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
945 "T :bytes recv %lluK %lluK",
948 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
949 "T :time connected %llu %llu",
950 sp
.is_cti
, sp
.is_sti
);
954 stats_uptime (struct Client
*source_p
)
958 now
= rb_current_time() - startup_time
;
959 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
960 form_str (RPL_STATSUPTIME
),
961 now
/ 86400, (now
/ 3600) % 24,
962 (now
/ 60) % 60, now
% 60);
963 sendto_one_numeric(source_p
, RPL_STATSCONN
,
964 form_str (RPL_STATSCONN
),
965 MaxConnectionCount
, MaxClientCount
,
966 Count
.totalrestartcount
);
974 static struct shared_flags shared_flagtable
[] =
976 { SHARED_PKLINE
, 'K' },
977 { SHARED_TKLINE
, 'k' },
978 { SHARED_UNKLINE
, 'U' },
979 { SHARED_PXLINE
, 'X' },
980 { SHARED_TXLINE
, 'x' },
981 { SHARED_UNXLINE
, 'Y' },
982 { SHARED_PRESV
, 'Q' },
983 { SHARED_TRESV
, 'q' },
984 { SHARED_UNRESV
, 'R' },
985 { SHARED_LOCOPS
, 'L' },
986 { SHARED_REHASH
, 'H' },
987 { SHARED_TDLINE
, 'd' },
988 { SHARED_PDLINE
, 'D' },
989 { SHARED_UNDLINE
, 'E' },
995 stats_shared (struct Client
*source_p
)
997 struct remote_conf
*shared_p
;
999 char buf
[sizeof(shared_flagtable
)/sizeof(shared_flagtable
[0])];
1003 RB_DLINK_FOREACH(ptr
, shared_conf_list
.head
)
1005 shared_p
= ptr
->data
;
1011 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1013 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1014 *p
++ = shared_flagtable
[i
].letter
;
1019 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1020 form_str(RPL_STATSULINE
),
1021 shared_p
->server
, shared_p
->username
,
1022 shared_p
->host
, buf
);
1025 RB_DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
1027 shared_p
= ptr
->data
;
1033 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1035 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1036 *p
++ = shared_flagtable
[i
].letter
;
1041 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1042 form_str(RPL_STATSULINE
),
1043 shared_p
->server
, "*", "*", buf
);
1049 * input - client pointer
1051 * side effects - client is shown lists of who connected servers
1054 stats_servers (struct Client
*source_p
)
1056 struct Client
*target_p
;
1059 int days
, hours
, minutes
;
1062 if(ConfigServerHide
.flatten_links
&& !IsOper(source_p
) &&
1063 !IsExemptShide(source_p
))
1065 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1066 form_str (ERR_NOPRIVILEGES
));
1070 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1072 target_p
= ptr
->data
;
1075 seconds
= rb_current_time() - target_p
->localClient
->firsttime
;
1077 days
= (int) (seconds
/ 86400);
1079 hours
= (int) (seconds
/ 3600);
1081 minutes
= (int) (seconds
/ 60);
1084 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1085 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1086 "Connected: %d day%s, %d:%02d:%02d",
1088 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
1089 (int) (rb_current_time() - target_p
->localClient
->lasttime
),
1090 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1091 days
, (days
== 1) ? "" : "s", hours
, minutes
,
1095 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1096 "V :%d Server(s)", j
);
1100 stats_tgecos(struct Client
*source_p
)
1102 struct ConfItem
*aconf
;
1105 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1110 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1111 form_str(RPL_STATSXLINE
),
1112 'x', aconf
->port
, aconf
->host
,
1118 stats_gecos(struct Client
*source_p
)
1120 struct ConfItem
*aconf
;
1123 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1128 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1129 form_str(RPL_STATSXLINE
),
1130 'X', aconf
->port
, aconf
->host
,
1136 stats_class(struct Client
*source_p
)
1138 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOper(source_p
))
1139 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1140 form_str (ERR_NOPRIVILEGES
));
1142 report_classes(source_p
);
1146 stats_memory (struct Client
*source_p
)
1148 struct Client
*target_p
;
1149 struct Channel
*chptr
;
1150 struct Ban
*actualBan
;
1151 rb_dlink_node
*rb_dlink
;
1153 int channel_count
= 0;
1154 int local_client_conf_count
= 0; /* local client conf links */
1155 int users_counted
= 0; /* user structs */
1157 int channel_users
= 0;
1158 int channel_invites
= 0;
1159 int channel_bans
= 0;
1160 int channel_except
= 0;
1161 int channel_invex
= 0;
1162 int channel_quiets
= 0;
1164 int class_count
= 0; /* classes */
1165 int conf_count
= 0; /* conf lines */
1166 int users_invited_count
= 0; /* users invited */
1167 int user_channels
= 0; /* users in channels */
1168 int aways_counted
= 0;
1169 size_t number_servers_cached
; /* number of servers cached by scache */
1171 size_t channel_memory
= 0;
1172 size_t channel_ban_memory
= 0;
1173 size_t channel_except_memory
= 0;
1174 size_t channel_invex_memory
= 0;
1175 size_t channel_quiet_memory
= 0;
1177 size_t away_memory
= 0; /* memory used by aways */
1178 size_t ww
= 0; /* whowas array count */
1179 size_t wwm
= 0; /* whowas array memory used */
1180 size_t conf_memory
= 0; /* memory used by conf lines */
1181 size_t mem_servers_cached
; /* memory used by scache */
1183 size_t linebuf_count
= 0;
1184 size_t linebuf_memory_used
= 0;
1186 size_t total_channel_memory
= 0;
1189 size_t local_client_count
= 0;
1190 size_t local_client_memory_used
= 0;
1192 size_t remote_client_count
= 0;
1193 size_t remote_client_memory_used
= 0;
1195 size_t total_memory
= 0;
1197 count_whowas_memory(&ww
, &wwm
);
1199 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
1201 target_p
= ptr
->data
;
1202 if(MyConnect(target_p
))
1204 local_client_conf_count
++;
1210 users_invited_count
+= rb_dlink_list_length(&target_p
->user
->invited
);
1211 user_channels
+= rb_dlink_list_length(&target_p
->user
->channel
);
1212 if(target_p
->user
->away
)
1215 away_memory
+= (strlen(target_p
->user
->away
) + 1);
1220 /* Count up all channels, ban lists, except lists, Invex lists */
1221 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
1225 channel_memory
+= (strlen(chptr
->chname
) + sizeof(struct Channel
));
1227 channel_users
+= rb_dlink_list_length(&chptr
->members
);
1228 channel_invites
+= rb_dlink_list_length(&chptr
->invites
);
1230 RB_DLINK_FOREACH(rb_dlink
, chptr
->banlist
.head
)
1232 actualBan
= rb_dlink
->data
;
1235 channel_ban_memory
+= sizeof(rb_dlink_node
) + sizeof(struct Ban
);
1238 RB_DLINK_FOREACH(rb_dlink
, chptr
->exceptlist
.head
)
1240 actualBan
= rb_dlink
->data
;
1243 channel_except_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1246 RB_DLINK_FOREACH(rb_dlink
, chptr
->invexlist
.head
)
1248 actualBan
= rb_dlink
->data
;
1251 channel_invex_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1254 RB_DLINK_FOREACH(rb_dlink
, chptr
->quietlist
.head
)
1256 actualBan
= rb_dlink
->data
;
1259 channel_quiet_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1263 /* count up all classes */
1265 class_count
= rb_dlink_list_length(&class_list
) + 1;
1267 rb_count_rb_linebuf_memory(&linebuf_count
, &linebuf_memory_used
);
1269 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1270 "z :Users %u(%lu) Invites %u(%lu)",
1272 (unsigned long) users_counted
* sizeof(struct User
),
1273 users_invited_count
,
1274 (unsigned long) users_invited_count
* sizeof(rb_dlink_node
));
1276 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1277 "z :User channels %u(%lu) Aways %u(%d)",
1279 (unsigned long) user_channels
* sizeof(rb_dlink_node
),
1280 aways_counted
, (int) away_memory
);
1282 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1283 "z :Attached confs %u(%lu)",
1284 local_client_conf_count
,
1285 (unsigned long) local_client_conf_count
* sizeof(rb_dlink_node
));
1287 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1288 "z :Conflines %u(%d)", conf_count
, (int) conf_memory
);
1290 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1291 "z :Classes %u(%lu)",
1293 (unsigned long) class_count
* sizeof(struct Class
));
1295 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1296 "z :Channels %u(%d)",
1297 channel_count
, (int) channel_memory
);
1299 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1300 "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)",
1301 channel_bans
, (int) channel_ban_memory
,
1302 channel_except
, (int) channel_except_memory
,
1303 channel_invex
, (int) channel_invex_memory
,
1304 channel_quiets
, (int) channel_quiet_memory
);
1306 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1307 "z :Channel members %u(%lu) invite %u(%lu)",
1309 (unsigned long) channel_users
* sizeof(rb_dlink_node
),
1311 (unsigned long) channel_invites
* sizeof(rb_dlink_node
));
1313 total_channel_memory
= channel_memory
+
1314 channel_ban_memory
+
1315 channel_users
* sizeof(rb_dlink_node
) + channel_invites
* sizeof(rb_dlink_node
);
1317 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1318 "z :Whowas array %ld(%ld)",
1319 (long)ww
, (long)wwm
);
1323 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1324 "z :Hash: client %u(%ld) chan %u(%ld)",
1325 U_MAX
, (long)(U_MAX
* sizeof(rb_dlink_list
)),
1326 CH_MAX
, (long)(CH_MAX
* sizeof(rb_dlink_list
)));
1328 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1329 "z :linebuf %ld(%ld)",
1330 (long)linebuf_count
, (long)linebuf_memory_used
);
1332 count_scache(&number_servers_cached
, &mem_servers_cached
);
1334 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1335 "z :scache %ld(%ld)",
1336 (long)number_servers_cached
, (long)mem_servers_cached
);
1338 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1339 "z :hostname hash %d(%ld)",
1340 HOST_MAX
, (long)HOST_MAX
* sizeof(rb_dlink_list
));
1342 total_memory
= totww
+ total_channel_memory
+ conf_memory
+
1343 class_count
* sizeof(struct Class
);
1345 total_memory
+= mem_servers_cached
;
1346 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1347 "z :Total: whowas %d channel %d conf %d",
1348 (int) totww
, (int) total_channel_memory
,
1351 count_local_client_memory(&local_client_count
, &local_client_memory_used
);
1352 total_memory
+= local_client_memory_used
;
1354 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1355 "z :Local client Memory in use: %ld(%ld)",
1356 (long)local_client_count
, (long)local_client_memory_used
);
1359 count_remote_client_memory(&remote_client_count
, &remote_client_memory_used
);
1360 total_memory
+= remote_client_memory_used
;
1362 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1363 "z :Remote client Memory in use: %ld(%ld)",
1364 (long)remote_client_count
,
1365 (long)remote_client_memory_used
);
1369 stats_ziplinks (struct Client
*source_p
)
1372 struct Client
*target_p
;
1373 struct ZipStats
*zipstats
;
1375 char buf
[128], buf1
[128];
1376 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1378 target_p
= ptr
->data
;
1379 if(IsCapable (target_p
, CAP_ZIP
))
1381 zipstats
= target_p
->localClient
->zipstats
;
1382 sprintf(buf
, "%.2f%%", zipstats
->out_ratio
);
1383 sprintf(buf1
, "%.2f%%", zipstats
->in_ratio
);
1384 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1385 "Z :ZipLinks stats for %s send[%s compression "
1386 "(%llu kB data/%llu kB wire)] recv[%s compression "
1387 "(%llu kB data/%llu kB wire)]",
1389 buf
, zipstats
->out
>> 10,
1390 zipstats
->out_wire
>> 10, buf1
,
1391 zipstats
->in
>> 10, zipstats
->in_wire
>> 10);
1396 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1397 "Z :%u ziplink(s)", sent_data
);
1401 stats_servlinks (struct Client
*source_p
)
1403 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1404 long uptime
, sendK
, receiveK
;
1405 struct Client
*target_p
;
1410 if(ConfigServerHide
.flatten_links
&& !IsOper (source_p
) &&
1411 !IsExemptShide(source_p
))
1413 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1414 form_str (ERR_NOPRIVILEGES
));
1418 sendK
= receiveK
= 0;
1420 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1422 target_p
= ptr
->data
;
1425 sendK
+= target_p
->localClient
->sendK
;
1426 receiveK
+= target_p
->localClient
->receiveK
;
1428 sendto_one(source_p
, Sformat
,
1429 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1431 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1432 (int) target_p
->localClient
->sendM
,
1433 (int) target_p
->localClient
->sendK
,
1434 (int) target_p
->localClient
->receiveM
,
1435 (int) target_p
->localClient
->receiveK
,
1436 rb_current_time() - target_p
->localClient
->firsttime
,
1437 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1438 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1439 IsOper (source_p
) ? show_capabilities (target_p
) : "TS");
1442 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1443 "? :%u total server(s)", j
);
1445 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((sendK
)));
1446 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1447 "? :Sent total : %s %s",
1448 buf
, _GMKs (sendK
));
1449 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((receiveK
)));
1450 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1451 "? :Recv total : %s %s",
1452 buf
, _GMKs (receiveK
));
1454 uptime
= (rb_current_time() - startup_time
);
1455 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1456 _GMKv (me
.localClient
->sendK
),
1457 _GMKs (me
.localClient
->sendK
),
1458 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1459 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server send: %s", buf
);
1460 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1461 _GMKv (me
.localClient
->receiveK
),
1462 _GMKs (me
.localClient
->receiveK
),
1463 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1464 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server recv: %s", buf
);
1468 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1473 char statchar
= parv
[1][0];
1475 /* this is def targeted at us somehow.. */
1476 if(parc
> 2 && !EmptyString(parv
[2]))
1478 /* directed at us generically? */
1479 if(match(parv
[2], me
.name
) ||
1480 (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1488 wilds
= strchr(name
, '*') || strchr(name
, '?');
1491 /* must be directed at a specific person thats not us */
1492 if(!doall
&& !wilds
)
1494 struct Client
*target_p
;
1496 if(MyClient(source_p
))
1497 target_p
= find_named_person(name
);
1499 target_p
= find_person(name
);
1501 if(target_p
!= NULL
)
1503 stats_spy(source_p
, statchar
, target_p
->name
);
1504 stats_l_client(source_p
, target_p
, statchar
);
1507 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1508 form_str(ERR_NOSUCHSERVER
),
1520 stats_spy(source_p
, statchar
, name
);
1524 /* local opers get everyone */
1525 if(MyOper(source_p
))
1527 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
);
1528 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
);
1532 /* they still need themselves if theyre local.. */
1533 if(MyClient(source_p
))
1534 stats_l_client(source_p
, source_p
, statchar
);
1536 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
);
1539 if (!ConfigServerHide
.flatten_links
|| IsOper(source_p
) ||
1540 IsExemptShide(source_p
))
1541 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
);
1546 /* ok, at this point theyre looking for a specific client whos on
1547 * our server.. but it contains a wildcard. --fl
1549 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
);
1556 stats_l_list(struct Client
*source_p
, const char *name
, int doall
, int wilds
,
1557 rb_dlink_list
* list
, char statchar
)
1560 struct Client
*target_p
;
1562 /* send information about connections which match. note, we
1563 * dont need tests for IsInvisible(), because non-opers will
1564 * never get here for normal clients --fl
1566 RB_DLINK_FOREACH(ptr
, list
->head
)
1568 target_p
= ptr
->data
;
1570 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1573 stats_l_client(source_p
, target_p
, statchar
);
1578 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1581 if(IsAnyServer(target_p
))
1583 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1585 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1586 (int) target_p
->localClient
->sendM
,
1587 (int) target_p
->localClient
->sendK
,
1588 (int) target_p
->localClient
->receiveM
,
1589 (int) target_p
->localClient
->receiveK
,
1590 rb_current_time() - target_p
->localClient
->firsttime
,
1591 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1592 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1593 IsOper(source_p
) ? show_capabilities(target_p
) : "-");
1598 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1599 show_ip(source_p
, target_p
) ?
1600 (IsUpper(statchar
) ?
1601 get_client_name(target_p
, SHOW_IP
) :
1602 get_client_name(target_p
, HIDE_IP
)) :
1603 get_client_name(target_p
, MASK_IP
),
1604 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1605 (int) target_p
->localClient
->sendM
,
1606 (int) target_p
->localClient
->sendK
,
1607 (int) target_p
->localClient
->receiveM
,
1608 (int) target_p
->localClient
->receiveK
,
1609 rb_current_time() - target_p
->localClient
->firsttime
,
1610 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1611 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1617 rb_dump_fd_callback(int fd
, const char *desc
, void *data
)
1619 struct Client
*source_p
= data
;
1620 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "F :fd %-3d desc '%s'", fd
, desc
);
1624 stats_comm(struct Client
*source_p
)
1626 rb_dump_fd(rb_dump_fd_callback
, source_p
);
1632 * inputs - pointer to client doing the /stats
1633 * - char letter they are doing /stats on
1636 * This little helper function reports to opers if configured.
1637 * personally, I don't see why opers need to see stats requests
1638 * at all. They are just "noise" to an oper, and users can't do
1639 * any damage with stats requests now anyway. So, why show them?
1643 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1647 data
.client
= source_p
;
1649 data
.arg2
= (int) statchar
;
1651 call_hook(doing_stats_hook
, &data
);
1656 * input - pointer to client doing stats
1658 * side effects - call hook doing_stats_p
1661 stats_p_spy (struct Client
*source_p
)
1665 data
.client
= source_p
;
1666 data
.arg1
= data
.arg2
= NULL
;
1668 call_hook(doing_stats_p_hook
, &data
);