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
, *pass
, *user
, *classname
;
416 struct AddressRec
*arec
;
417 struct ConfItem
*aconf
;
420 if(ConfigFileEntry
.stats_e_disabled
)
422 sendto_one_numeric(source_p
, ERR_DISABLED
,
423 form_str(ERR_DISABLED
), "STATS e");
427 for (i
= 0; i
< ATABLE_SIZE
; i
++)
429 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
431 if(arec
->type
== CONF_EXEMPTDLINE
)
434 get_printable_conf (aconf
, &name
, &host
, &pass
,
435 &user
, &port
, &classname
);
437 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
438 form_str(RPL_STATSDLINE
),
439 'e', host
, pass
, "", "");
446 stats_events_cb(char *str
, void *ptr
)
448 sendto_one_numeric(ptr
, RPL_STATSDEBUG
, "E :%s", str
);
452 stats_events (struct Client
*source_p
)
454 rb_dump_events(stats_events_cb
, source_p
);
458 stats_prop_klines(struct Client
*source_p
)
460 struct ConfItem
*aconf
;
462 char *user
, *host
, *pass
, *oper_reason
;
464 RB_DLINK_FOREACH(ptr
, prop_bans
.head
)
468 /* Skip non-klines and deactivated klines. */
469 if(aconf
->status
!= CONF_KILL
)
472 get_printable_kline(source_p
, aconf
, &host
, &pass
,
473 &user
, &oper_reason
);
475 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
476 form_str(RPL_STATSKLINE
),
477 'g', host
, user
, pass
,
478 oper_reason
? "|" : "",
479 oper_reason
? oper_reason
: "");
484 stats_hubleaf(struct Client
*source_p
)
486 struct remote_conf
*hub_p
;
489 if((ConfigFileEntry
.stats_h_oper_only
||
490 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
493 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
494 form_str (ERR_NOPRIVILEGES
));
498 RB_DLINK_FOREACH(ptr
, hubleaf_conf_list
.head
)
502 if(hub_p
->flags
& CONF_HUB
)
503 sendto_one_numeric(source_p
, RPL_STATSHLINE
,
504 form_str(RPL_STATSHLINE
),
505 hub_p
->host
, hub_p
->server
);
507 sendto_one_numeric(source_p
, RPL_STATSLLINE
,
508 form_str(RPL_STATSLLINE
),
509 hub_p
->host
, hub_p
->server
);
515 stats_auth (struct Client
*source_p
)
517 /* Oper only, if unopered, return ERR_NOPRIVS */
518 if((ConfigFileEntry
.stats_i_oper_only
== 2) && !IsOper (source_p
))
519 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
520 form_str (ERR_NOPRIVILEGES
));
522 /* If unopered, Only return matching auth blocks */
523 else if((ConfigFileEntry
.stats_i_oper_only
== 1) && !IsOper (source_p
))
525 struct ConfItem
*aconf
;
526 char *name
, *host
, *pass
= "*", *user
, *classname
;
529 if(MyConnect (source_p
))
530 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
531 (struct sockaddr
*)&source_p
->localClient
->ip
,
533 source_p
->localClient
->ip
.ss_family
,
534 source_p
->username
, NULL
);
536 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_CLIENT
,
537 0, source_p
->username
, NULL
);
542 get_printable_conf (aconf
, &name
, &host
, &pass
, &user
, &port
, &classname
);
543 if(!EmptyString(aconf
->spasswd
))
544 pass
= aconf
->spasswd
;
546 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
547 name
, pass
, show_iline_prefix(source_p
, aconf
, user
),
548 host
, port
, classname
);
551 /* Theyre opered, or allowed to see all auth blocks */
553 report_auth (source_p
);
558 stats_tklines(struct Client
*source_p
)
560 /* Oper only, if unopered, return ERR_NOPRIVS */
561 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
562 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
563 form_str (ERR_NOPRIVILEGES
));
565 /* If unopered, Only return matching klines */
566 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
568 struct ConfItem
*aconf
;
569 char *host
, *pass
, *user
, *oper_reason
;
571 if(MyConnect (source_p
))
572 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
573 (struct sockaddr
*)&source_p
->localClient
->ip
,
575 source_p
->localClient
->ip
.ss_family
,
576 source_p
->username
, NULL
);
578 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
579 0, source_p
->username
, NULL
);
584 /* dont report a permanent kline as a tkline */
585 if((aconf
->flags
& CONF_FLAGS_TEMPORARY
) == 0)
588 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
590 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
591 form_str(RPL_STATSKLINE
), aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
592 host
, user
, pass
, oper_reason
? "|" : "",
593 oper_reason
? oper_reason
: "");
595 /* Theyre opered, or allowed to see all klines */
598 struct ConfItem
*aconf
;
601 char *user
, *host
, *pass
, *oper_reason
;
603 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
605 RB_DLINK_FOREACH(ptr
, temp_klines
[i
].head
)
609 get_printable_kline(source_p
, aconf
, &host
, &pass
,
610 &user
, &oper_reason
);
612 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
613 form_str(RPL_STATSKLINE
),
614 'k', host
, user
, pass
,
615 oper_reason
? "|" : "",
616 oper_reason
? oper_reason
: "");
623 stats_klines(struct Client
*source_p
)
625 /* Oper only, if unopered, return ERR_NOPRIVS */
626 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
627 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
628 form_str (ERR_NOPRIVILEGES
));
630 /* If unopered, Only return matching klines */
631 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
633 struct ConfItem
*aconf
;
634 char *host
, *pass
, *user
, *oper_reason
;
636 /* search for a kline */
637 if(MyConnect (source_p
))
638 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
639 (struct sockaddr
*)&source_p
->localClient
->ip
,
641 source_p
->localClient
->ip
.ss_family
,
642 source_p
->username
, NULL
);
644 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
645 0, source_p
->username
, NULL
);
650 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
652 sendto_one_numeric(source_p
, RPL_STATSKLINE
, form_str(RPL_STATSKLINE
),
653 aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
654 host
, user
, pass
, oper_reason
? "|" : "",
655 oper_reason
? oper_reason
: "");
657 /* Theyre opered, or allowed to see all klines */
659 report_Klines (source_p
);
663 stats_messages(struct Client
*source_p
)
665 report_messages(source_p
);
669 stats_dnsbl(struct Client
*source_p
)
672 struct Blacklist
*blptr
;
674 RB_DLINK_FOREACH(ptr
, blacklist_list
.head
)
678 /* use RPL_STATSDEBUG for now -- jilles */
679 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "n :%d %s %s (%d)",
682 blptr
->status
& CONF_ILLEGAL
? "disabled" : "active",
688 stats_oper(struct Client
*source_p
)
690 struct oper_conf
*oper_p
;
693 if(!IsOper(source_p
) && ConfigFileEntry
.stats_o_oper_only
)
695 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
696 form_str (ERR_NOPRIVILEGES
));
700 RB_DLINK_FOREACH(ptr
, oper_conf_list
.head
)
704 sendto_one_numeric(source_p
, RPL_STATSOLINE
,
705 form_str(RPL_STATSOLINE
),
706 oper_p
->username
, oper_p
->host
, oper_p
->name
,
707 IsOper(source_p
) ? oper_p
->privset
->name
: "0", "-1");
712 stats_capability_walk(const char *line
, void *data
)
714 struct Client
*client_p
= data
;
716 sendto_one_numeric(client_p
, RPL_STATSDEBUG
, "C :%s", line
);
720 stats_capability(struct Client
*client_p
)
722 capability_index_stats(stats_capability_walk
, client_p
);
726 stats_privset(struct Client
*source_p
)
728 privilegeset_report(source_p
);
733 * input - client pointer
735 * side effects - client is shown a list of active opers
738 stats_operedup (struct Client
*source_p
)
740 struct Client
*target_p
;
741 rb_dlink_node
*oper_ptr
;
742 unsigned int count
= 0;
744 RB_DLINK_FOREACH (oper_ptr
, oper_list
.head
)
746 target_p
= oper_ptr
->data
;
748 if(IsOperInvis(target_p
) && !IsOper(source_p
))
751 if(target_p
->user
->away
)
756 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
758 target_p
->name
, target_p
->username
,
762 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
763 "p :%u staff members", count
);
765 stats_p_spy (source_p
);
769 stats_ports (struct Client
*source_p
)
771 if(!IsOper (source_p
) && ConfigFileEntry
.stats_P_oper_only
)
772 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
773 form_str (ERR_NOPRIVILEGES
));
775 show_ports (source_p
);
779 stats_tresv(struct Client
*source_p
)
781 struct ConfItem
*aconf
;
785 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
789 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
790 form_str(RPL_STATSQLINE
),
791 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
794 HASH_WALK(i
, R_MAX
, ptr
, resvTable
)
798 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
799 form_str(RPL_STATSQLINE
),
800 'q', aconf
->port
, aconf
->host
, aconf
->passwd
);
807 stats_resv(struct Client
*source_p
)
809 struct ConfItem
*aconf
;
813 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
817 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
818 form_str(RPL_STATSQLINE
),
819 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
822 HASH_WALK(i
, R_MAX
, ptr
, resvTable
)
826 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
827 form_str(RPL_STATSQLINE
),
828 'Q', aconf
->port
, aconf
->host
, aconf
->passwd
);
834 stats_usage (struct Client
*source_p
)
849 if(getrusage(RUSAGE_SELF
, &rus
) == -1)
851 sendto_one_notice(source_p
, ":Getruseage error: %s.",
855 secs
= rus
.ru_utime
.tv_sec
+ rus
.ru_stime
.tv_sec
;
859 rup
= (rb_current_time() - startup_time
) * hzz
;
863 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
864 "R :CPU Secs %d:%02d User %d:%02d System %d:%02d",
865 (int) (secs
/ 60), (int) (secs
% 60),
866 (int) (rus
.ru_utime
.tv_sec
/ 60),
867 (int) (rus
.ru_utime
.tv_sec
% 60),
868 (int) (rus
.ru_stime
.tv_sec
/ 60),
869 (int) (rus
.ru_stime
.tv_sec
% 60));
870 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
871 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
872 rus
.ru_maxrss
, (rus
.ru_ixrss
/ rup
),
873 (rus
.ru_idrss
/ rup
), (rus
.ru_isrss
/ rup
));
874 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
875 "R :Swaps %d Reclaims %d Faults %d",
876 (int) rus
.ru_nswap
, (int) rus
.ru_minflt
, (int) rus
.ru_majflt
);
877 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
878 "R :Block in %d out %d",
879 (int) rus
.ru_inblock
, (int) rus
.ru_oublock
);
880 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
881 "R :Msg Rcv %d Send %d",
882 (int) rus
.ru_msgrcv
, (int) rus
.ru_msgsnd
);
883 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
884 "R :Signals %d Context Vol. %d Invol %d",
885 (int) rus
.ru_nsignals
, (int) rus
.ru_nvcsw
,
886 (int) rus
.ru_nivcsw
);
890 stats_tstats (struct Client
*source_p
)
892 struct Client
*target_p
;
893 struct ServerStatistics sp
;
896 memcpy(&sp
, &ServerStats
, sizeof(struct ServerStatistics
));
898 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
900 target_p
= ptr
->data
;
902 sp
.is_sbs
+= target_p
->localClient
->sendB
;
903 sp
.is_sbr
+= target_p
->localClient
->receiveB
;
904 sp
.is_sti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
908 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
910 target_p
= ptr
->data
;
912 sp
.is_cbs
+= target_p
->localClient
->sendB
;
913 sp
.is_cbr
+= target_p
->localClient
->receiveB
;
914 sp
.is_cti
+= (unsigned long long)(rb_current_time() - target_p
->localClient
->firsttime
);
918 RB_DLINK_FOREACH(ptr
, unknown_list
.head
)
923 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
924 "T :accepts %u refused %u", sp
.is_ac
, sp
.is_ref
);
925 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
926 "T :rejected %u delaying %lu",
927 sp
.is_rej
, delay_exit_length());
928 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
929 "T :throttled refused %u throttle list size %lu", sp
.is_thr
, throttle_size());
930 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
931 "T :nicks being delayed %lu",
933 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
934 "T :unknown commands %u prefixes %u",
935 sp
.is_unco
, sp
.is_unpf
);
936 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
937 "T :nick collisions %u saves %u unknown closes %u",
938 sp
.is_kill
, sp
.is_save
, sp
.is_ni
);
939 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
940 "T :wrong direction %u empty %u",
941 sp
.is_wrdi
, sp
.is_empt
);
942 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
943 "T :numerics seen %u", sp
.is_num
);
944 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
945 "T :tgchange blocked msgs %u restricted addrs %lu",
946 sp
.is_tgch
, rb_dlink_list_length(&tgchange_list
));
947 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
948 "T :ratelimit blocked commands %u", sp
.is_rl
);
949 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
950 "T :auth successes %u fails %u",
951 sp
.is_asuc
, sp
.is_abad
);
952 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
953 "T :sasl successes %u fails %u",
954 sp
.is_ssuc
, sp
.is_sbad
);
955 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "T :Client Server");
956 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
957 "T :connected %u %u", sp
.is_cl
, sp
.is_sv
);
958 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
959 "T :bytes sent %lluK %lluK",
962 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
963 "T :bytes recv %lluK %lluK",
966 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
967 "T :time connected %llu %llu",
968 sp
.is_cti
, sp
.is_sti
);
972 stats_uptime (struct Client
*source_p
)
976 now
= rb_current_time() - startup_time
;
977 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
978 form_str (RPL_STATSUPTIME
),
979 (int)(now
/ 86400), (int)((now
/ 3600) % 24),
980 (int)((now
/ 60) % 60), (int)(now
% 60));
981 sendto_one_numeric(source_p
, RPL_STATSCONN
,
982 form_str (RPL_STATSCONN
),
983 MaxConnectionCount
, MaxClientCount
,
984 Count
.totalrestartcount
);
992 static struct shared_flags shared_flagtable
[] =
994 { SHARED_PKLINE
, 'K' },
995 { SHARED_TKLINE
, 'k' },
996 { SHARED_UNKLINE
, 'U' },
997 { SHARED_PXLINE
, 'X' },
998 { SHARED_TXLINE
, 'x' },
999 { SHARED_UNXLINE
, 'Y' },
1000 { SHARED_PRESV
, 'Q' },
1001 { SHARED_TRESV
, 'q' },
1002 { SHARED_UNRESV
, 'R' },
1003 { SHARED_LOCOPS
, 'L' },
1004 { SHARED_REHASH
, 'H' },
1005 { SHARED_TDLINE
, 'd' },
1006 { SHARED_PDLINE
, 'D' },
1007 { SHARED_UNDLINE
, 'E' },
1013 stats_shared (struct Client
*source_p
)
1015 struct remote_conf
*shared_p
;
1017 char buf
[sizeof(shared_flagtable
)/sizeof(shared_flagtable
[0])];
1021 RB_DLINK_FOREACH(ptr
, shared_conf_list
.head
)
1023 shared_p
= ptr
->data
;
1029 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1031 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1032 *p
++ = shared_flagtable
[i
].letter
;
1037 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1038 form_str(RPL_STATSULINE
),
1039 shared_p
->server
, shared_p
->username
,
1040 shared_p
->host
, buf
);
1043 RB_DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
1045 shared_p
= ptr
->data
;
1051 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1053 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1054 *p
++ = shared_flagtable
[i
].letter
;
1059 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1060 form_str(RPL_STATSULINE
),
1061 shared_p
->server
, "*", "*", buf
);
1067 * input - client pointer
1069 * side effects - client is shown lists of who connected servers
1072 stats_servers (struct Client
*source_p
)
1074 struct Client
*target_p
;
1077 int days
, hours
, minutes
;
1080 if(ConfigServerHide
.flatten_links
&& !IsOper(source_p
) &&
1081 !IsExemptShide(source_p
))
1083 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1084 form_str (ERR_NOPRIVILEGES
));
1088 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1090 target_p
= ptr
->data
;
1093 seconds
= rb_current_time() - target_p
->localClient
->firsttime
;
1095 days
= (int) (seconds
/ 86400);
1097 hours
= (int) (seconds
/ 3600);
1099 minutes
= (int) (seconds
/ 60);
1102 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1103 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1104 "Connected: %d day%s, %d:%02d:%02d",
1106 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
1107 (int) (rb_current_time() - target_p
->localClient
->lasttime
),
1108 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1109 days
, (days
== 1) ? "" : "s", hours
, minutes
,
1113 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1114 "V :%d Server(s)", j
);
1118 stats_tgecos(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_gecos(struct Client
*source_p
)
1138 struct ConfItem
*aconf
;
1141 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1146 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1147 form_str(RPL_STATSXLINE
),
1148 'X', aconf
->port
, aconf
->host
,
1154 stats_class(struct Client
*source_p
)
1156 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOper(source_p
))
1157 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1158 form_str (ERR_NOPRIVILEGES
));
1160 report_classes(source_p
);
1164 stats_memory (struct Client
*source_p
)
1166 struct Client
*target_p
;
1167 struct Channel
*chptr
;
1168 rb_dlink_node
*rb_dlink
;
1170 int channel_count
= 0;
1171 int local_client_conf_count
= 0; /* local client conf links */
1172 int users_counted
= 0; /* user structs */
1174 int channel_users
= 0;
1175 int channel_invites
= 0;
1176 int channel_bans
= 0;
1177 int channel_except
= 0;
1178 int channel_invex
= 0;
1179 int channel_quiets
= 0;
1181 int class_count
= 0; /* classes */
1182 int conf_count
= 0; /* conf lines */
1183 int users_invited_count
= 0; /* users invited */
1184 int user_channels
= 0; /* users in channels */
1185 int aways_counted
= 0;
1186 size_t number_servers_cached
; /* number of servers cached by scache */
1188 size_t channel_memory
= 0;
1189 size_t channel_ban_memory
= 0;
1190 size_t channel_except_memory
= 0;
1191 size_t channel_invex_memory
= 0;
1192 size_t channel_quiet_memory
= 0;
1194 size_t away_memory
= 0; /* memory used by aways */
1195 size_t ww
= 0; /* whowas array count */
1196 size_t wwm
= 0; /* whowas array memory used */
1197 size_t conf_memory
= 0; /* memory used by conf lines */
1198 size_t mem_servers_cached
; /* memory used by scache */
1200 size_t linebuf_count
= 0;
1201 size_t linebuf_memory_used
= 0;
1203 size_t total_channel_memory
= 0;
1206 size_t local_client_count
= 0;
1207 size_t local_client_memory_used
= 0;
1209 size_t remote_client_count
= 0;
1210 size_t remote_client_memory_used
= 0;
1212 size_t total_memory
= 0;
1214 count_whowas_memory(&ww
, &wwm
);
1216 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
1218 target_p
= ptr
->data
;
1219 if(MyConnect(target_p
))
1221 local_client_conf_count
++;
1227 users_invited_count
+= rb_dlink_list_length(&target_p
->user
->invited
);
1228 user_channels
+= rb_dlink_list_length(&target_p
->user
->channel
);
1229 if(target_p
->user
->away
)
1232 away_memory
+= (strlen(target_p
->user
->away
) + 1);
1237 /* Count up all channels, ban lists, except lists, Invex lists */
1238 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
1242 channel_memory
+= (strlen(chptr
->chname
) + sizeof(struct Channel
));
1244 channel_users
+= rb_dlink_list_length(&chptr
->members
);
1245 channel_invites
+= rb_dlink_list_length(&chptr
->invites
);
1247 RB_DLINK_FOREACH(rb_dlink
, chptr
->banlist
.head
)
1251 channel_ban_memory
+= sizeof(rb_dlink_node
) + sizeof(struct Ban
);
1254 RB_DLINK_FOREACH(rb_dlink
, chptr
->exceptlist
.head
)
1258 channel_except_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1261 RB_DLINK_FOREACH(rb_dlink
, chptr
->invexlist
.head
)
1265 channel_invex_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1268 RB_DLINK_FOREACH(rb_dlink
, chptr
->quietlist
.head
)
1272 channel_quiet_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1276 /* count up all classes */
1278 class_count
= rb_dlink_list_length(&class_list
) + 1;
1280 rb_count_rb_linebuf_memory(&linebuf_count
, &linebuf_memory_used
);
1282 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1283 "z :Users %u(%lu) Invites %u(%lu)",
1285 (unsigned long) users_counted
* sizeof(struct User
),
1286 users_invited_count
,
1287 (unsigned long) users_invited_count
* sizeof(rb_dlink_node
));
1289 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1290 "z :User channels %u(%lu) Aways %u(%d)",
1292 (unsigned long) user_channels
* sizeof(rb_dlink_node
),
1293 aways_counted
, (int) away_memory
);
1295 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1296 "z :Attached confs %u(%lu)",
1297 local_client_conf_count
,
1298 (unsigned long) local_client_conf_count
* sizeof(rb_dlink_node
));
1300 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1301 "z :Conflines %u(%d)", conf_count
, (int) conf_memory
);
1303 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1304 "z :Classes %u(%lu)",
1306 (unsigned long) class_count
* sizeof(struct Class
));
1308 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1309 "z :Channels %u(%d)",
1310 channel_count
, (int) channel_memory
);
1312 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1313 "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)",
1314 channel_bans
, (int) channel_ban_memory
,
1315 channel_except
, (int) channel_except_memory
,
1316 channel_invex
, (int) channel_invex_memory
,
1317 channel_quiets
, (int) channel_quiet_memory
);
1319 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1320 "z :Channel members %u(%lu) invite %u(%lu)",
1322 (unsigned long) channel_users
* sizeof(rb_dlink_node
),
1324 (unsigned long) channel_invites
* sizeof(rb_dlink_node
));
1326 total_channel_memory
= channel_memory
+
1327 channel_ban_memory
+
1328 channel_users
* sizeof(rb_dlink_node
) + channel_invites
* sizeof(rb_dlink_node
);
1330 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1331 "z :Whowas array %ld(%ld)",
1332 (long)ww
, (long)wwm
);
1336 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1337 "z :Hash: client %u(%ld) chan %u(%ld)",
1338 U_MAX
, (long)(U_MAX
* sizeof(rb_dlink_list
)),
1339 CH_MAX
, (long)(CH_MAX
* sizeof(rb_dlink_list
)));
1341 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1342 "z :linebuf %ld(%ld)",
1343 (long)linebuf_count
, (long)linebuf_memory_used
);
1345 count_scache(&number_servers_cached
, &mem_servers_cached
);
1347 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1348 "z :scache %ld(%ld)",
1349 (long)number_servers_cached
, (long)mem_servers_cached
);
1351 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1352 "z :hostname hash %d(%ld)",
1353 HOST_MAX
, (long)HOST_MAX
* sizeof(rb_dlink_list
));
1355 total_memory
= totww
+ total_channel_memory
+ conf_memory
+
1356 class_count
* sizeof(struct Class
);
1358 total_memory
+= mem_servers_cached
;
1359 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1360 "z :Total: whowas %d channel %d conf %d",
1361 (int) totww
, (int) total_channel_memory
,
1364 count_local_client_memory(&local_client_count
, &local_client_memory_used
);
1365 total_memory
+= local_client_memory_used
;
1367 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1368 "z :Local client Memory in use: %ld(%ld)",
1369 (long)local_client_count
, (long)local_client_memory_used
);
1372 count_remote_client_memory(&remote_client_count
, &remote_client_memory_used
);
1373 total_memory
+= remote_client_memory_used
;
1375 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1376 "z :Remote client Memory in use: %ld(%ld)",
1377 (long)remote_client_count
,
1378 (long)remote_client_memory_used
);
1382 stats_ziplinks (struct Client
*source_p
)
1385 struct Client
*target_p
;
1386 struct ZipStats
*zipstats
;
1388 char buf
[128], buf1
[128];
1389 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1391 target_p
= ptr
->data
;
1392 if(IsCapable (target_p
, CAP_ZIP
))
1394 zipstats
= target_p
->localClient
->zipstats
;
1395 sprintf(buf
, "%.2f%%", zipstats
->out_ratio
);
1396 sprintf(buf1
, "%.2f%%", zipstats
->in_ratio
);
1397 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1398 "Z :ZipLinks stats for %s send[%s compression "
1399 "(%llu kB data/%llu kB wire)] recv[%s compression "
1400 "(%llu kB data/%llu kB wire)]",
1402 buf
, zipstats
->out
>> 10,
1403 zipstats
->out_wire
>> 10, buf1
,
1404 zipstats
->in
>> 10, zipstats
->in_wire
>> 10);
1409 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1410 "Z :%u ziplink(s)", sent_data
);
1414 stats_servlinks (struct Client
*source_p
)
1416 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1417 long uptime
, sendK
, receiveK
;
1418 struct Client
*target_p
;
1423 if(ConfigServerHide
.flatten_links
&& !IsOper (source_p
) &&
1424 !IsExemptShide(source_p
))
1426 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1427 form_str (ERR_NOPRIVILEGES
));
1431 sendK
= receiveK
= 0;
1433 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1435 target_p
= ptr
->data
;
1438 sendK
+= target_p
->localClient
->sendK
;
1439 receiveK
+= target_p
->localClient
->receiveK
;
1441 sendto_one(source_p
, Sformat
,
1442 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1444 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1445 (int) target_p
->localClient
->sendM
,
1446 (int) target_p
->localClient
->sendK
,
1447 (int) target_p
->localClient
->receiveM
,
1448 (int) target_p
->localClient
->receiveK
,
1449 rb_current_time() - target_p
->localClient
->firsttime
,
1450 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1451 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1452 IsOper (source_p
) ? show_capabilities (target_p
) : "TS");
1455 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1456 "? :%u total server(s)", j
);
1458 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((sendK
)));
1459 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1460 "? :Sent total : %s %s",
1461 buf
, _GMKs (sendK
));
1462 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((receiveK
)));
1463 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1464 "? :Recv total : %s %s",
1465 buf
, _GMKs (receiveK
));
1467 uptime
= (rb_current_time() - startup_time
);
1468 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1469 _GMKv (me
.localClient
->sendK
),
1470 _GMKs (me
.localClient
->sendK
),
1471 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1472 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server send: %s", buf
);
1473 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1474 _GMKv (me
.localClient
->receiveK
),
1475 _GMKs (me
.localClient
->receiveK
),
1476 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1477 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server recv: %s", buf
);
1481 stats_l_should_show_oper(struct Client
*target_p
)
1483 if (IsOperInvis(target_p
))
1490 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1495 char statchar
= parv
[1][0];
1497 /* this is def targeted at us somehow.. */
1498 if(parc
> 2 && !EmptyString(parv
[2]))
1500 /* directed at us generically? */
1501 if(match(parv
[2], me
.name
) ||
1502 (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1510 wilds
= strchr(name
, '*') || strchr(name
, '?');
1513 /* must be directed at a specific person thats not us */
1514 if(!doall
&& !wilds
)
1516 struct Client
*target_p
;
1518 if(MyClient(source_p
))
1519 target_p
= find_named_person(name
);
1521 target_p
= find_person(name
);
1523 if(target_p
!= NULL
)
1525 stats_spy(source_p
, statchar
, target_p
->name
);
1526 stats_l_client(source_p
, target_p
, statchar
);
1529 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1530 form_str(ERR_NOSUCHSERVER
),
1542 stats_spy(source_p
, statchar
, name
);
1546 /* local opers get everyone */
1547 if(MyOper(source_p
))
1549 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
, NULL
);
1550 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1554 /* they still need themselves if theyre local.. */
1555 if(MyClient(source_p
))
1556 stats_l_client(source_p
, source_p
, statchar
);
1558 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
, stats_l_should_show_oper
);
1561 if (!ConfigServerHide
.flatten_links
|| IsOper(source_p
) ||
1562 IsExemptShide(source_p
))
1563 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
, NULL
);
1568 /* ok, at this point theyre looking for a specific client whos on
1569 * our server.. but it contains a wildcard. --fl
1571 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
, NULL
);
1577 stats_l_list(struct Client
*source_p
, const char *name
, int doall
, int wilds
,
1578 rb_dlink_list
* list
, char statchar
, int (*check_fn
)(struct Client
*target_p
))
1581 struct Client
*target_p
;
1583 /* send information about connections which match. note, we
1584 * dont need tests for IsInvisible(), because non-opers will
1585 * never get here for normal clients --fl
1587 RB_DLINK_FOREACH(ptr
, list
->head
)
1589 target_p
= ptr
->data
;
1591 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1594 if (check_fn
== NULL
|| check_fn(target_p
))
1595 stats_l_client(source_p
, target_p
, statchar
);
1600 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1603 if(IsAnyServer(target_p
))
1605 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1607 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1608 (int) target_p
->localClient
->sendM
,
1609 (int) target_p
->localClient
->sendK
,
1610 (int) target_p
->localClient
->receiveM
,
1611 (int) target_p
->localClient
->receiveK
,
1612 rb_current_time() - target_p
->localClient
->firsttime
,
1613 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1614 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1615 IsOper(source_p
) ? show_capabilities(target_p
) : "-");
1620 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1621 show_ip(source_p
, target_p
) ?
1622 (IsUpper(statchar
) ?
1623 get_client_name(target_p
, SHOW_IP
) :
1624 get_client_name(target_p
, HIDE_IP
)) :
1625 get_client_name(target_p
, MASK_IP
),
1626 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1627 (int) target_p
->localClient
->sendM
,
1628 (int) target_p
->localClient
->sendK
,
1629 (int) target_p
->localClient
->receiveM
,
1630 (int) target_p
->localClient
->receiveK
,
1631 rb_current_time() - target_p
->localClient
->firsttime
,
1632 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1633 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1639 rb_dump_fd_callback(int fd
, const char *desc
, void *data
)
1641 struct Client
*source_p
= data
;
1642 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "F :fd %-3d desc '%s'", fd
, desc
);
1646 stats_comm(struct Client
*source_p
)
1648 rb_dump_fd(rb_dump_fd_callback
, source_p
);
1654 * inputs - pointer to client doing the /stats
1655 * - char letter they are doing /stats on
1658 * This little helper function reports to opers if configured.
1659 * personally, I don't see why opers need to see stats requests
1660 * at all. They are just "noise" to an oper, and users can't do
1661 * any damage with stats requests now anyway. So, why show them?
1665 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1669 data
.client
= source_p
;
1671 data
.arg2
= (int) statchar
;
1673 call_hook(doing_stats_hook
, &data
);
1678 * input - pointer to client doing stats
1680 * side effects - call hook doing_stats_p
1683 stats_p_spy (struct Client
*source_p
)
1687 data
.client
= source_p
;
1688 data
.arg1
= data
.arg2
= NULL
;
1690 call_hook(doing_stats_p_hook
, &data
);