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' },
991 { SHARED_MODULE
, 'M' },
997 stats_shared (struct Client
*source_p
)
999 struct remote_conf
*shared_p
;
1001 char buf
[sizeof(shared_flagtable
)/sizeof(shared_flagtable
[0])];
1005 RB_DLINK_FOREACH(ptr
, shared_conf_list
.head
)
1007 shared_p
= ptr
->data
;
1013 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1015 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1016 *p
++ = shared_flagtable
[i
].letter
;
1021 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1022 form_str(RPL_STATSULINE
),
1023 shared_p
->server
, shared_p
->username
,
1024 shared_p
->host
, buf
);
1027 RB_DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
1029 shared_p
= ptr
->data
;
1035 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1037 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1038 *p
++ = shared_flagtable
[i
].letter
;
1043 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1044 form_str(RPL_STATSULINE
),
1045 shared_p
->server
, "*", "*", buf
);
1051 * input - client pointer
1053 * side effects - client is shown lists of who connected servers
1056 stats_servers (struct Client
*source_p
)
1058 struct Client
*target_p
;
1061 int days
, hours
, minutes
;
1064 if(ConfigServerHide
.flatten_links
&& !IsOper(source_p
) &&
1065 !IsExemptShide(source_p
))
1067 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1068 form_str (ERR_NOPRIVILEGES
));
1072 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1074 target_p
= ptr
->data
;
1077 seconds
= rb_current_time() - target_p
->localClient
->firsttime
;
1079 days
= (int) (seconds
/ 86400);
1081 hours
= (int) (seconds
/ 3600);
1083 minutes
= (int) (seconds
/ 60);
1086 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1087 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1088 "Connected: %d day%s, %d:%02d:%02d",
1090 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
1091 (int) (rb_current_time() - target_p
->localClient
->lasttime
),
1092 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1093 days
, (days
== 1) ? "" : "s", hours
, minutes
,
1097 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1098 "V :%d Server(s)", j
);
1102 stats_tgecos(struct Client
*source_p
)
1104 struct ConfItem
*aconf
;
1107 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1112 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1113 form_str(RPL_STATSXLINE
),
1114 'x', aconf
->port
, aconf
->host
,
1120 stats_gecos(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_class(struct Client
*source_p
)
1140 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOper(source_p
))
1141 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1142 form_str (ERR_NOPRIVILEGES
));
1144 report_classes(source_p
);
1148 stats_memory (struct Client
*source_p
)
1150 struct Client
*target_p
;
1151 struct Channel
*chptr
;
1152 struct Ban
*actualBan
;
1153 rb_dlink_node
*rb_dlink
;
1155 int channel_count
= 0;
1156 int local_client_conf_count
= 0; /* local client conf links */
1157 int users_counted
= 0; /* user structs */
1159 int channel_users
= 0;
1160 int channel_invites
= 0;
1161 int channel_bans
= 0;
1162 int channel_except
= 0;
1163 int channel_invex
= 0;
1164 int channel_quiets
= 0;
1166 int class_count
= 0; /* classes */
1167 int conf_count
= 0; /* conf lines */
1168 int users_invited_count
= 0; /* users invited */
1169 int user_channels
= 0; /* users in channels */
1170 int aways_counted
= 0;
1171 size_t number_servers_cached
; /* number of servers cached by scache */
1173 size_t channel_memory
= 0;
1174 size_t channel_ban_memory
= 0;
1175 size_t channel_except_memory
= 0;
1176 size_t channel_invex_memory
= 0;
1177 size_t channel_quiet_memory
= 0;
1179 size_t away_memory
= 0; /* memory used by aways */
1180 size_t ww
= 0; /* whowas array count */
1181 size_t wwm
= 0; /* whowas array memory used */
1182 size_t conf_memory
= 0; /* memory used by conf lines */
1183 size_t mem_servers_cached
; /* memory used by scache */
1185 size_t linebuf_count
= 0;
1186 size_t linebuf_memory_used
= 0;
1188 size_t total_channel_memory
= 0;
1191 size_t local_client_count
= 0;
1192 size_t local_client_memory_used
= 0;
1194 size_t remote_client_count
= 0;
1195 size_t remote_client_memory_used
= 0;
1197 size_t total_memory
= 0;
1199 count_whowas_memory(&ww
, &wwm
);
1201 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
1203 target_p
= ptr
->data
;
1204 if(MyConnect(target_p
))
1206 local_client_conf_count
++;
1212 users_invited_count
+= rb_dlink_list_length(&target_p
->user
->invited
);
1213 user_channels
+= rb_dlink_list_length(&target_p
->user
->channel
);
1214 if(target_p
->user
->away
)
1217 away_memory
+= (strlen(target_p
->user
->away
) + 1);
1222 /* Count up all channels, ban lists, except lists, Invex lists */
1223 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
1227 channel_memory
+= (strlen(chptr
->chname
) + sizeof(struct Channel
));
1229 channel_users
+= rb_dlink_list_length(&chptr
->members
);
1230 channel_invites
+= rb_dlink_list_length(&chptr
->invites
);
1232 RB_DLINK_FOREACH(rb_dlink
, chptr
->banlist
.head
)
1234 actualBan
= rb_dlink
->data
;
1237 channel_ban_memory
+= sizeof(rb_dlink_node
) + sizeof(struct Ban
);
1240 RB_DLINK_FOREACH(rb_dlink
, chptr
->exceptlist
.head
)
1242 actualBan
= rb_dlink
->data
;
1245 channel_except_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1248 RB_DLINK_FOREACH(rb_dlink
, chptr
->invexlist
.head
)
1250 actualBan
= rb_dlink
->data
;
1253 channel_invex_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1256 RB_DLINK_FOREACH(rb_dlink
, chptr
->quietlist
.head
)
1258 actualBan
= rb_dlink
->data
;
1261 channel_quiet_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1265 /* count up all classes */
1267 class_count
= rb_dlink_list_length(&class_list
) + 1;
1269 rb_count_rb_linebuf_memory(&linebuf_count
, &linebuf_memory_used
);
1271 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1272 "z :Users %u(%lu) Invites %u(%lu)",
1274 (unsigned long) users_counted
* sizeof(struct User
),
1275 users_invited_count
,
1276 (unsigned long) users_invited_count
* sizeof(rb_dlink_node
));
1278 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1279 "z :User channels %u(%lu) Aways %u(%d)",
1281 (unsigned long) user_channels
* sizeof(rb_dlink_node
),
1282 aways_counted
, (int) away_memory
);
1284 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1285 "z :Attached confs %u(%lu)",
1286 local_client_conf_count
,
1287 (unsigned long) local_client_conf_count
* sizeof(rb_dlink_node
));
1289 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1290 "z :Conflines %u(%d)", conf_count
, (int) conf_memory
);
1292 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1293 "z :Classes %u(%lu)",
1295 (unsigned long) class_count
* sizeof(struct Class
));
1297 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1298 "z :Channels %u(%d)",
1299 channel_count
, (int) channel_memory
);
1301 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1302 "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)",
1303 channel_bans
, (int) channel_ban_memory
,
1304 channel_except
, (int) channel_except_memory
,
1305 channel_invex
, (int) channel_invex_memory
,
1306 channel_quiets
, (int) channel_quiet_memory
);
1308 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1309 "z :Channel members %u(%lu) invite %u(%lu)",
1311 (unsigned long) channel_users
* sizeof(rb_dlink_node
),
1313 (unsigned long) channel_invites
* sizeof(rb_dlink_node
));
1315 total_channel_memory
= channel_memory
+
1316 channel_ban_memory
+
1317 channel_users
* sizeof(rb_dlink_node
) + channel_invites
* sizeof(rb_dlink_node
);
1319 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1320 "z :Whowas array %ld(%ld)",
1321 (long)ww
, (long)wwm
);
1325 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1326 "z :Hash: client %u(%ld) chan %u(%ld)",
1327 U_MAX
, (long)(U_MAX
* sizeof(rb_dlink_list
)),
1328 CH_MAX
, (long)(CH_MAX
* sizeof(rb_dlink_list
)));
1330 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1331 "z :linebuf %ld(%ld)",
1332 (long)linebuf_count
, (long)linebuf_memory_used
);
1334 count_scache(&number_servers_cached
, &mem_servers_cached
);
1336 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1337 "z :scache %ld(%ld)",
1338 (long)number_servers_cached
, (long)mem_servers_cached
);
1340 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1341 "z :hostname hash %d(%ld)",
1342 HOST_MAX
, (long)HOST_MAX
* sizeof(rb_dlink_list
));
1344 total_memory
= totww
+ total_channel_memory
+ conf_memory
+
1345 class_count
* sizeof(struct Class
);
1347 total_memory
+= mem_servers_cached
;
1348 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1349 "z :Total: whowas %d channel %d conf %d",
1350 (int) totww
, (int) total_channel_memory
,
1353 count_local_client_memory(&local_client_count
, &local_client_memory_used
);
1354 total_memory
+= local_client_memory_used
;
1356 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1357 "z :Local client Memory in use: %ld(%ld)",
1358 (long)local_client_count
, (long)local_client_memory_used
);
1361 count_remote_client_memory(&remote_client_count
, &remote_client_memory_used
);
1362 total_memory
+= remote_client_memory_used
;
1364 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1365 "z :Remote client Memory in use: %ld(%ld)",
1366 (long)remote_client_count
,
1367 (long)remote_client_memory_used
);
1371 stats_ziplinks (struct Client
*source_p
)
1374 struct Client
*target_p
;
1375 struct ZipStats
*zipstats
;
1377 char buf
[128], buf1
[128];
1378 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1380 target_p
= ptr
->data
;
1381 if(IsCapable (target_p
, CAP_ZIP
))
1383 zipstats
= target_p
->localClient
->zipstats
;
1384 sprintf(buf
, "%.2f%%", zipstats
->out_ratio
);
1385 sprintf(buf1
, "%.2f%%", zipstats
->in_ratio
);
1386 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1387 "Z :ZipLinks stats for %s send[%s compression "
1388 "(%llu kB data/%llu kB wire)] recv[%s compression "
1389 "(%llu kB data/%llu kB wire)]",
1391 buf
, zipstats
->out
>> 10,
1392 zipstats
->out_wire
>> 10, buf1
,
1393 zipstats
->in
>> 10, zipstats
->in_wire
>> 10);
1398 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1399 "Z :%u ziplink(s)", sent_data
);
1403 stats_servlinks (struct Client
*source_p
)
1405 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1406 long uptime
, sendK
, receiveK
;
1407 struct Client
*target_p
;
1412 if(ConfigServerHide
.flatten_links
&& !IsOper (source_p
) &&
1413 !IsExemptShide(source_p
))
1415 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1416 form_str (ERR_NOPRIVILEGES
));
1420 sendK
= receiveK
= 0;
1422 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1424 target_p
= ptr
->data
;
1427 sendK
+= target_p
->localClient
->sendK
;
1428 receiveK
+= target_p
->localClient
->receiveK
;
1430 sendto_one(source_p
, Sformat
,
1431 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1433 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1434 (int) target_p
->localClient
->sendM
,
1435 (int) target_p
->localClient
->sendK
,
1436 (int) target_p
->localClient
->receiveM
,
1437 (int) target_p
->localClient
->receiveK
,
1438 rb_current_time() - target_p
->localClient
->firsttime
,
1439 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1440 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1441 IsOper (source_p
) ? show_capabilities (target_p
) : "TS");
1444 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1445 "? :%u total server(s)", j
);
1447 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((sendK
)));
1448 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1449 "? :Sent total : %s %s",
1450 buf
, _GMKs (sendK
));
1451 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((receiveK
)));
1452 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1453 "? :Recv total : %s %s",
1454 buf
, _GMKs (receiveK
));
1456 uptime
= (rb_current_time() - startup_time
);
1457 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1458 _GMKv (me
.localClient
->sendK
),
1459 _GMKs (me
.localClient
->sendK
),
1460 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1461 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server send: %s", buf
);
1462 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1463 _GMKv (me
.localClient
->receiveK
),
1464 _GMKs (me
.localClient
->receiveK
),
1465 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1466 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server recv: %s", buf
);
1470 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1475 char statchar
= parv
[1][0];
1477 /* this is def targeted at us somehow.. */
1478 if(parc
> 2 && !EmptyString(parv
[2]))
1480 /* directed at us generically? */
1481 if(match(parv
[2], me
.name
) ||
1482 (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1490 wilds
= strchr(name
, '*') || strchr(name
, '?');
1493 /* must be directed at a specific person thats not us */
1494 if(!doall
&& !wilds
)
1496 struct Client
*target_p
;
1498 if(MyClient(source_p
))
1499 target_p
= find_named_person(name
);
1501 target_p
= find_person(name
);
1503 if(target_p
!= NULL
)
1505 stats_spy(source_p
, statchar
, target_p
->name
);
1506 stats_l_client(source_p
, target_p
, statchar
);
1509 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1510 form_str(ERR_NOSUCHSERVER
),
1522 stats_spy(source_p
, statchar
, name
);
1526 /* local opers get everyone */
1527 if(MyOper(source_p
))
1529 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
);
1530 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
);
1534 /* they still need themselves if theyre local.. */
1535 if(MyClient(source_p
))
1536 stats_l_client(source_p
, source_p
, statchar
);
1538 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
);
1541 if (!ConfigServerHide
.flatten_links
|| IsOper(source_p
) ||
1542 IsExemptShide(source_p
))
1543 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
);
1548 /* ok, at this point theyre looking for a specific client whos on
1549 * our server.. but it contains a wildcard. --fl
1551 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
);
1558 stats_l_list(struct Client
*source_p
, const char *name
, int doall
, int wilds
,
1559 rb_dlink_list
* list
, char statchar
)
1562 struct Client
*target_p
;
1564 /* send information about connections which match. note, we
1565 * dont need tests for IsInvisible(), because non-opers will
1566 * never get here for normal clients --fl
1568 RB_DLINK_FOREACH(ptr
, list
->head
)
1570 target_p
= ptr
->data
;
1572 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1575 stats_l_client(source_p
, target_p
, statchar
);
1580 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1583 if(IsAnyServer(target_p
))
1585 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1587 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1588 (int) target_p
->localClient
->sendM
,
1589 (int) target_p
->localClient
->sendK
,
1590 (int) target_p
->localClient
->receiveM
,
1591 (int) target_p
->localClient
->receiveK
,
1592 rb_current_time() - target_p
->localClient
->firsttime
,
1593 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1594 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1595 IsOper(source_p
) ? show_capabilities(target_p
) : "-");
1600 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1601 show_ip(source_p
, target_p
) ?
1602 (IsUpper(statchar
) ?
1603 get_client_name(target_p
, SHOW_IP
) :
1604 get_client_name(target_p
, HIDE_IP
)) :
1605 get_client_name(target_p
, MASK_IP
),
1606 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1607 (int) target_p
->localClient
->sendM
,
1608 (int) target_p
->localClient
->sendK
,
1609 (int) target_p
->localClient
->receiveM
,
1610 (int) target_p
->localClient
->receiveK
,
1611 rb_current_time() - target_p
->localClient
->firsttime
,
1612 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1613 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1619 rb_dump_fd_callback(int fd
, const char *desc
, void *data
)
1621 struct Client
*source_p
= data
;
1622 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "F :fd %-3d desc '%s'", fd
, desc
);
1626 stats_comm(struct Client
*source_p
)
1628 rb_dump_fd(rb_dump_fd_callback
, source_p
);
1634 * inputs - pointer to client doing the /stats
1635 * - char letter they are doing /stats on
1638 * This little helper function reports to opers if configured.
1639 * personally, I don't see why opers need to see stats requests
1640 * at all. They are just "noise" to an oper, and users can't do
1641 * any damage with stats requests now anyway. So, why show them?
1645 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1649 data
.client
= source_p
;
1651 data
.arg2
= (int) statchar
;
1653 call_hook(doing_stats_hook
, &data
);
1658 * input - pointer to client doing stats
1660 * side effects - call hook doing_stats_p
1663 stats_p_spy (struct Client
*source_p
)
1667 data
.client
= source_p
;
1668 data
.arg1
= data
.arg2
= NULL
;
1670 call_hook(doing_stats_p_hook
, &data
);