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 */
31 #include "irc_string.h"
32 #include "ircd.h" /* me */
33 #include "listener.h" /* show_ports */
35 #include "msg.h" /* Message */
36 #include "hostmask.h" /* report_mtrie_conf_links */
37 #include "numeric.h" /* ERR_xxx */
38 #include "scache.h" /* list_scache */
39 #include "send.h" /* sendto_one */
40 #include "s_conf.h" /* ConfItem */
41 #include "s_serv.h" /* hunt_server */
43 #include "s_user.h" /* show_opers */
44 #include "blacklist.h" /* dnsbl stuff */
48 #include "s_newconf.h"
53 static int m_stats (struct Client
*, struct Client
*, int, const char **);
55 struct Message stats_msgtab
= {
56 "STATS", 0, 0, 0, MFLG_SLOW
,
57 {mg_unreg
, {m_stats
, 2}, {m_stats
, 3}, mg_ignore
, mg_ignore
, {m_stats
, 2}}
61 int doing_stats_p_hook
;
63 mapi_clist_av1 stats_clist
[] = { &stats_msgtab
, NULL
};
64 mapi_hlist_av1 stats_hlist
[] = {
65 { "doing_stats", &doing_stats_hook
},
66 { "doing_stats_p", &doing_stats_p_hook
},
70 DECLARE_MODULE_AV1(stats
, NULL
, NULL
, stats_clist
, stats_hlist
, NULL
, "$Revision: 1608 $");
72 const char *Lformat
= "%s %u %u %u %u %u :%u %u %s";
74 static void stats_l_list(struct Client
*s
, const char *, int, int, rb_dlink_list
*, char);
75 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 */
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_glines(struct Client
*);
99 static void stats_pending_glines(struct Client
*);
100 static void stats_hubleaf(struct Client
*);
101 static void stats_auth(struct Client
*);
102 static void stats_tklines(struct Client
*);
103 static void stats_klines(struct Client
*);
104 static void stats_messages(struct Client
*);
105 static void stats_dnsbl(struct Client
*);
106 static void stats_oper(struct Client
*);
107 static void stats_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 /* This table contains the possible stats items, in order:
125 * stats letter, function to call, operonly? adminonly?
126 * case only matters in the stats letter column.. -- fl_
128 static struct StatsStruct stats_cmd_table
[] = {
129 /* letter function need_oper need_admin */
130 {'a', stats_dns_servers
, 1, 1, },
131 {'A', stats_dns_servers
, 1, 1, },
132 {'b', stats_delay
, 1, 1, },
133 {'B', stats_hash
, 1, 1, },
134 {'c', stats_connect
, 0, 0, },
135 {'C', stats_connect
, 0, 0, },
136 {'d', stats_tdeny
, 1, 0, },
137 {'D', stats_deny
, 1, 0, },
138 {'e', stats_exempt
, 1, 0, },
139 {'E', stats_events
, 1, 1, },
140 {'f', stats_comm
, 1, 1, },
141 {'F', stats_comm
, 1, 1, },
142 {'g', stats_pending_glines
, 1, 0, },
143 {'G', stats_glines
, 1, 0, },
144 {'h', stats_hubleaf
, 0, 0, },
145 {'H', stats_hubleaf
, 0, 0, },
146 {'i', stats_auth
, 0, 0, },
147 {'I', stats_auth
, 0, 0, },
148 {'k', stats_tklines
, 0, 0, },
149 {'K', stats_klines
, 0, 0, },
150 {'l', stats_ltrace
, 0, 0, },
151 {'L', stats_ltrace
, 0, 0, },
152 {'m', stats_messages
, 0, 0, },
153 {'M', stats_messages
, 0, 0, },
154 {'n', stats_dnsbl
, 0, 0, },
155 {'o', stats_oper
, 0, 0, },
156 {'O', stats_oper
, 0, 0, },
157 {'p', stats_operedup
, 0, 0, },
158 {'P', stats_ports
, 0, 0, },
159 {'q', stats_tresv
, 1, 0, },
160 {'Q', stats_resv
, 1, 0, },
161 {'r', stats_usage
, 1, 0, },
162 {'R', stats_usage
, 1, 0, },
163 {'t', stats_tstats
, 1, 0, },
164 {'T', stats_tstats
, 1, 0, },
165 {'u', stats_uptime
, 0, 0, },
166 {'U', stats_shared
, 1, 0, },
167 {'v', stats_servers
, 0, 0, },
168 {'V', stats_servers
, 0, 0, },
169 {'x', stats_tgecos
, 1, 0, },
170 {'X', stats_gecos
, 1, 0, },
171 {'y', stats_class
, 0, 0, },
172 {'Y', stats_class
, 0, 0, },
173 {'z', stats_memory
, 1, 0, },
174 {'Z', stats_ziplinks
, 1, 0, },
175 {'?', stats_servlinks
, 0, 0, },
176 {(char) 0, (void (*)()) 0, 0, 0, }
181 * parv[0] = sender prefix
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
].handler
; 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_cmd_table
[i
].handler (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
))
309 if(ServerConfAutoconn(server_p
))
311 if(ServerConfTb(server_p
))
313 if(ServerConfCompressed(server_p
))
322 sendto_one_numeric(source_p
, RPL_STATSCLINE
,
323 form_str(RPL_STATSCLINE
),
324 #ifndef HIDE_SERVERS_IPS
330 server_p
->port
, server_p
->class_name
);
336 * input - client to report to
338 * side effects - client is given temp dline list.
341 stats_tdeny (struct Client
*source_p
)
343 char *host
, *pass
, *user
, *oper_reason
;
344 struct AddressRec
*arec
;
345 struct ConfItem
*aconf
;
348 for (i
= 0; i
< ATABLE_SIZE
; i
++)
350 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
352 if(arec
->type
== CONF_DLINE
)
356 if(!(aconf
->flags
& CONF_FLAGS_TEMPORARY
))
359 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
361 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
362 form_str (RPL_STATSDLINE
),
364 oper_reason
? "|" : "",
365 oper_reason
? oper_reason
: "");
373 * input - client to report to
375 * side effects - client is given dline list.
378 stats_deny (struct Client
*source_p
)
380 char *host
, *pass
, *user
, *oper_reason
;
381 struct AddressRec
*arec
;
382 struct ConfItem
*aconf
;
385 for (i
= 0; i
< ATABLE_SIZE
; i
++)
387 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
389 if(arec
->type
== CONF_DLINE
)
393 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
396 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
398 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
399 form_str (RPL_STATSDLINE
),
401 oper_reason
? "|" : "",
402 oper_reason
? oper_reason
: "");
411 * input - client to report to
413 * side effects - client is given list of exempt blocks
416 stats_exempt(struct Client
*source_p
)
418 char *name
, *host
, *pass
, *user
, *classname
;
419 struct AddressRec
*arec
;
420 struct ConfItem
*aconf
;
423 if(ConfigFileEntry
.stats_e_disabled
)
425 sendto_one_numeric(source_p
, ERR_DISABLED
,
426 form_str(ERR_DISABLED
), "STATS e");
430 for (i
= 0; i
< ATABLE_SIZE
; i
++)
432 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
434 if(arec
->type
== CONF_EXEMPTDLINE
)
437 get_printable_conf (aconf
, &name
, &host
, &pass
,
438 &user
, &port
, &classname
);
440 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
441 form_str(RPL_STATSDLINE
),
442 'e', host
, pass
, "", "");
449 stats_events_cb(char *str
, void *ptr
)
451 sendto_one_numeric(ptr
, RPL_STATSDEBUG
, "E :%s", str
);
455 stats_events (struct Client
*source_p
)
457 rb_dump_events(stats_events_cb
, source_p
);
460 /* stats_pending_glines()
462 * input - client pointer
464 * side effects - client is shown list of pending glines
467 stats_pending_glines (struct Client
*source_p
)
469 if(ConfigFileEntry
.glines
)
471 rb_dlink_node
*pending_node
;
472 struct gline_pending
*glp_ptr
;
473 char timebuffer
[MAX_DATE_STRING
];
476 RB_DLINK_FOREACH (pending_node
, pending_glines
.head
)
478 glp_ptr
= pending_node
->data
;
480 tmptr
= localtime (&glp_ptr
->time_request1
);
481 strftime (timebuffer
, MAX_DATE_STRING
, "%Y/%m/%d %H:%M:%S", tmptr
);
483 sendto_one_notice(source_p
,
484 ":1) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
486 glp_ptr
->oper_user1
, glp_ptr
->oper_host1
,
487 glp_ptr
->oper_server1
, timebuffer
,
488 glp_ptr
->user
, glp_ptr
->host
, glp_ptr
->reason1
);
490 if(glp_ptr
->oper_nick2
[0])
492 tmptr
= localtime (&glp_ptr
->time_request2
);
493 strftime (timebuffer
, MAX_DATE_STRING
, "%Y/%m/%d %H:%M:%S", tmptr
);
494 sendto_one_notice(source_p
,
495 ":2) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
497 glp_ptr
->oper_user2
, glp_ptr
->oper_host2
,
498 glp_ptr
->oper_server2
, timebuffer
,
499 glp_ptr
->user
, glp_ptr
->host
, glp_ptr
->reason2
);
503 if(rb_dlink_list_length (&pending_glines
) > 0)
504 sendto_one_notice(source_p
, ":End of Pending G-lines");
507 sendto_one_notice(source_p
, ":This server does not support G-Lines");
513 * input - client pointer
515 * side effects - client is shown list of glines
518 stats_glines (struct Client
*source_p
)
520 if(ConfigFileEntry
.glines
)
522 rb_dlink_node
*gline_node
;
523 struct ConfItem
*kill_ptr
;
525 RB_DLINK_FOREACH_PREV (gline_node
, glines
.tail
)
527 kill_ptr
= gline_node
->data
;
529 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
530 form_str(RPL_STATSKLINE
), 'G',
531 kill_ptr
->host
? kill_ptr
->host
: "*",
532 kill_ptr
->user
? kill_ptr
->user
: "*",
533 kill_ptr
->passwd
? kill_ptr
->passwd
: "No Reason",
534 kill_ptr
->spasswd
? "|" : "",
535 kill_ptr
->spasswd
? kill_ptr
->spasswd
: "");
539 sendto_one_notice(source_p
, ":This server does not support G-Lines");
544 stats_hubleaf(struct Client
*source_p
)
546 struct remote_conf
*hub_p
;
549 if((ConfigFileEntry
.stats_h_oper_only
||
550 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
553 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
554 form_str (ERR_NOPRIVILEGES
));
558 RB_DLINK_FOREACH(ptr
, hubleaf_conf_list
.head
)
562 if(hub_p
->flags
& CONF_HUB
)
563 sendto_one_numeric(source_p
, RPL_STATSHLINE
,
564 form_str(RPL_STATSHLINE
),
565 hub_p
->host
, hub_p
->server
);
567 sendto_one_numeric(source_p
, RPL_STATSLLINE
,
568 form_str(RPL_STATSLLINE
),
569 hub_p
->host
, hub_p
->server
);
575 stats_auth (struct Client
*source_p
)
577 /* Oper only, if unopered, return ERR_NOPRIVS */
578 if((ConfigFileEntry
.stats_i_oper_only
== 2) && !IsOper (source_p
))
579 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
580 form_str (ERR_NOPRIVILEGES
));
582 /* If unopered, Only return matching auth blocks */
583 else if((ConfigFileEntry
.stats_i_oper_only
== 1) && !IsOper (source_p
))
585 struct ConfItem
*aconf
;
586 char *name
, *host
, *pass
, *user
, *classname
;
589 if(MyConnect (source_p
))
590 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
591 (struct sockaddr
*)&source_p
->localClient
->ip
,
593 source_p
->localClient
->ip
.ss_family
,
596 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_CLIENT
,
597 0, source_p
->username
);
602 get_printable_conf (aconf
, &name
, &host
, &pass
, &user
, &port
, &classname
);
604 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
605 name
, show_iline_prefix(source_p
, aconf
, user
),
606 host
, port
, classname
);
609 /* Theyre opered, or allowed to see all auth blocks */
611 report_auth (source_p
);
616 stats_tklines(struct Client
*source_p
)
618 /* Oper only, if unopered, return ERR_NOPRIVS */
619 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
620 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
621 form_str (ERR_NOPRIVILEGES
));
623 /* If unopered, Only return matching klines */
624 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
626 struct ConfItem
*aconf
;
627 char *host
, *pass
, *user
, *oper_reason
;
629 if(MyConnect (source_p
))
630 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
631 (struct sockaddr
*)&source_p
->localClient
->ip
,
633 source_p
->localClient
->ip
.ss_family
,
636 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
637 0, source_p
->username
);
642 /* dont report a permanent kline as a tkline */
643 if((aconf
->flags
& CONF_FLAGS_TEMPORARY
) == 0)
646 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
648 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
649 form_str(RPL_STATSKLINE
), aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
650 host
, user
, pass
, oper_reason
? "|" : "",
651 oper_reason
? oper_reason
: "");
653 /* Theyre opered, or allowed to see all klines */
656 struct ConfItem
*aconf
;
659 char *user
, *host
, *pass
, *oper_reason
;
661 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
663 RB_DLINK_FOREACH(ptr
, temp_klines
[i
].head
)
667 get_printable_kline(source_p
, aconf
, &host
, &pass
,
668 &user
, &oper_reason
);
670 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
671 form_str(RPL_STATSKLINE
),
672 'k', host
, user
, pass
,
673 oper_reason
? "|" : "",
674 oper_reason
? oper_reason
: "");
681 stats_klines(struct Client
*source_p
)
683 /* Oper only, if unopered, return ERR_NOPRIVS */
684 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
685 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
686 form_str (ERR_NOPRIVILEGES
));
688 /* If unopered, Only return matching klines */
689 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
691 struct ConfItem
*aconf
;
692 char *host
, *pass
, *user
, *oper_reason
;
694 /* search for a kline */
695 if(MyConnect (source_p
))
696 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
697 (struct sockaddr
*)&source_p
->localClient
->ip
,
699 source_p
->localClient
->ip
.ss_family
,
702 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
703 0, source_p
->username
);
708 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
710 sendto_one_numeric(source_p
, RPL_STATSKLINE
, form_str(RPL_STATSKLINE
),
711 aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
712 host
, user
, pass
, oper_reason
? "|" : "",
713 oper_reason
? oper_reason
: "");
715 /* Theyre opered, or allowed to see all klines */
717 report_Klines (source_p
);
721 stats_messages(struct Client
*source_p
)
723 report_messages(source_p
);
727 stats_dnsbl(struct Client
*source_p
)
730 struct Blacklist
*blptr
;
732 RB_DLINK_FOREACH(ptr
, blacklist_list
.head
)
736 /* use RPL_STATSDEBUG for now -- jilles */
737 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "n :%d %s %s (%d)",
740 blptr
->status
& CONF_ILLEGAL
? "disabled" : "active",
746 stats_oper(struct Client
*source_p
)
748 struct oper_conf
*oper_p
;
751 if(!IsOper(source_p
) && ConfigFileEntry
.stats_o_oper_only
)
753 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
754 form_str (ERR_NOPRIVILEGES
));
758 RB_DLINK_FOREACH(ptr
, oper_conf_list
.head
)
762 sendto_one_numeric(source_p
, RPL_STATSOLINE
,
763 form_str(RPL_STATSOLINE
),
764 oper_p
->username
, oper_p
->host
, oper_p
->name
,
765 IsOper(source_p
) ? get_oper_privs(oper_p
->flags
) : "0", "-1");
772 * input - client pointer
774 * side effects - client is shown a list of active opers
777 stats_operedup (struct Client
*source_p
)
779 struct Client
*target_p
;
780 rb_dlink_node
*oper_ptr
;
781 unsigned int count
= 0;
783 RB_DLINK_FOREACH (oper_ptr
, oper_list
.head
)
785 target_p
= oper_ptr
->data
;
787 if(IsOperInvis(target_p
) && !IsOper(source_p
))
790 if(target_p
->user
->away
)
795 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
797 target_p
->name
, target_p
->username
,
801 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
802 "p :%u staff members", count
);
804 stats_p_spy (source_p
);
808 stats_ports (struct Client
*source_p
)
810 if(!IsOper (source_p
) && ConfigFileEntry
.stats_P_oper_only
)
811 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
812 form_str (ERR_NOPRIVILEGES
));
814 show_ports (source_p
);
818 stats_tresv(struct Client
*source_p
)
820 struct ConfItem
*aconf
;
824 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
828 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
829 form_str(RPL_STATSQLINE
),
830 'q', aconf
->port
, aconf
->name
, aconf
->passwd
);
833 HASH_WALK(i
, R_MAX
, ptr
, resvTable
)
837 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
838 form_str(RPL_STATSQLINE
),
839 'q', aconf
->port
, aconf
->name
, aconf
->passwd
);
846 stats_resv(struct Client
*source_p
)
848 struct ConfItem
*aconf
;
852 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
856 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
857 form_str(RPL_STATSQLINE
),
858 'Q', aconf
->port
, aconf
->name
, aconf
->passwd
);
861 HASH_WALK(i
, R_MAX
, ptr
, resvTable
)
865 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
866 form_str(RPL_STATSQLINE
),
867 'Q', aconf
->port
, aconf
->name
, aconf
->passwd
);
873 stats_usage (struct Client
*source_p
)
888 if(getrusage(RUSAGE_SELF
, &rus
) == -1)
890 sendto_one_notice(source_p
, ":Getruseage error: %s.",
894 secs
= rus
.ru_utime
.tv_sec
+ rus
.ru_stime
.tv_sec
;
898 rup
= (rb_current_time() - startup_time
) * hzz
;
902 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
903 "R :CPU Secs %d:%d User %d:%d System %d:%d",
904 (int) (secs
/ 60), (int) (secs
% 60),
905 (int) (rus
.ru_utime
.tv_sec
/ 60),
906 (int) (rus
.ru_utime
.tv_sec
% 60),
907 (int) (rus
.ru_stime
.tv_sec
/ 60),
908 (int) (rus
.ru_stime
.tv_sec
% 60));
909 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
910 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
911 rus
.ru_maxrss
, (rus
.ru_ixrss
/ rup
),
912 (rus
.ru_idrss
/ rup
), (rus
.ru_isrss
/ rup
));
913 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
914 "R :Swaps %d Reclaims %d Faults %d",
915 (int) rus
.ru_nswap
, (int) rus
.ru_minflt
, (int) rus
.ru_majflt
);
916 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
917 "R :Block in %d out %d",
918 (int) rus
.ru_inblock
, (int) rus
.ru_oublock
);
919 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
920 "R :Msg Rcv %d Send %d",
921 (int) rus
.ru_msgrcv
, (int) rus
.ru_msgsnd
);
922 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
923 "R :Signals %d Context Vol. %d Invol %d",
924 (int) rus
.ru_nsignals
, (int) rus
.ru_nvcsw
,
925 (int) rus
.ru_nivcsw
);
929 stats_tstats (struct Client
*source_p
)
931 struct Client
*target_p
;
932 struct ServerStatistics sp
;
935 memcpy(&sp
, &ServerStats
, sizeof(struct ServerStatistics
));
937 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
939 target_p
= ptr
->data
;
941 sp
.is_sbs
+= target_p
->localClient
->sendB
;
942 sp
.is_sbr
+= target_p
->localClient
->receiveB
;
943 sp
.is_sti
+= rb_current_time() - target_p
->localClient
->firsttime
;
947 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
949 target_p
= ptr
->data
;
951 sp
.is_cbs
+= target_p
->localClient
->sendB
;
952 sp
.is_cbr
+= target_p
->localClient
->receiveB
;
953 sp
.is_cti
+= rb_current_time() - target_p
->localClient
->firsttime
;
957 RB_DLINK_FOREACH(ptr
, unknown_list
.head
)
962 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
963 "T :accepts %u refused %u", sp
.is_ac
, sp
.is_ref
);
964 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
965 "T :rejected %u delaying %lu",
966 sp
.is_rej
, rb_dlink_list_length(&delay_exit
));
967 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
968 "T :nicks being delayed %lu",
970 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
971 "T :unknown commands %u prefixes %u",
972 sp
.is_unco
, sp
.is_unpf
);
973 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
974 "T :nick collisions %u saves %u unknown closes %u",
975 sp
.is_kill
, sp
.is_save
, sp
.is_ni
);
976 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
977 "T :wrong direction %u empty %u",
978 sp
.is_wrdi
, sp
.is_empt
);
979 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
980 "T :numerics seen %u", sp
.is_num
);
981 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
982 "T :tgchange blocked msgs %u restricted addrs %lu",
983 sp
.is_tgch
, rb_dlink_list_length(&tgchange_list
));
984 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
985 "T :auth successes %u fails %u",
986 sp
.is_asuc
, sp
.is_abad
);
987 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
988 "T :sasl successes %u fails %u",
989 sp
.is_ssuc
, sp
.is_sbad
);
990 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "T :Client Server");
991 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
992 "T :connected %u %u", sp
.is_cl
, sp
.is_sv
);
993 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
994 "T :bytes sent %lluK %lluK",
997 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
998 "T :bytes recv %lluK %lluK",
1001 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1002 "T :time connected %lu %lu",
1003 sp
.is_cti
, sp
.is_sti
);
1007 stats_uptime (struct Client
*source_p
)
1011 now
= rb_current_time() - startup_time
;
1012 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
1013 form_str (RPL_STATSUPTIME
),
1014 now
/ 86400, (now
/ 3600) % 24,
1015 (now
/ 60) % 60, now
% 60);
1016 sendto_one_numeric(source_p
, RPL_STATSCONN
,
1017 form_str (RPL_STATSCONN
),
1018 MaxConnectionCount
, MaxClientCount
,
1019 Count
.totalrestartcount
);
1027 static struct shared_flags shared_flagtable
[] =
1029 { SHARED_PKLINE
, 'K' },
1030 { SHARED_TKLINE
, 'k' },
1031 { SHARED_UNKLINE
, 'U' },
1032 { SHARED_PXLINE
, 'X' },
1033 { SHARED_TXLINE
, 'x' },
1034 { SHARED_UNXLINE
, 'Y' },
1035 { SHARED_PRESV
, 'Q' },
1036 { SHARED_TRESV
, 'q' },
1037 { SHARED_UNRESV
, 'R' },
1038 { SHARED_LOCOPS
, 'L' },
1039 { SHARED_REHASH
, 'H' },
1045 stats_shared (struct Client
*source_p
)
1047 struct remote_conf
*shared_p
;
1053 RB_DLINK_FOREACH(ptr
, shared_conf_list
.head
)
1055 shared_p
= ptr
->data
;
1061 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1063 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1064 *p
++ = shared_flagtable
[i
].letter
;
1069 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1070 form_str(RPL_STATSULINE
),
1071 shared_p
->server
, shared_p
->username
,
1072 shared_p
->host
, buf
);
1075 RB_DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
1077 shared_p
= ptr
->data
;
1083 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1085 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1086 *p
++ = shared_flagtable
[i
].letter
;
1091 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1092 form_str(RPL_STATSULINE
),
1093 shared_p
->server
, "*", "*", buf
);
1099 * input - client pointer
1101 * side effects - client is shown lists of who connected servers
1104 stats_servers (struct Client
*source_p
)
1106 struct Client
*target_p
;
1109 int days
, hours
, minutes
;
1112 if(ConfigServerHide
.flatten_links
&& !IsOper(source_p
) &&
1113 !IsExemptShide(source_p
))
1115 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1116 form_str (ERR_NOPRIVILEGES
));
1120 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1122 target_p
= ptr
->data
;
1125 seconds
= rb_current_time() - target_p
->localClient
->firsttime
;
1127 days
= (int) (seconds
/ 86400);
1129 hours
= (int) (seconds
/ 3600);
1131 minutes
= (int) (seconds
/ 60);
1134 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1135 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1136 "Connected: %d day%s, %d:%02d:%02d",
1138 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
1139 (int) (rb_current_time() - target_p
->localClient
->lasttime
),
1140 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1141 days
, (days
== 1) ? "" : "s", hours
, minutes
,
1145 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1146 "V :%d Server(s)", j
);
1150 stats_tgecos(struct Client
*source_p
)
1152 struct ConfItem
*aconf
;
1155 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1160 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1161 form_str(RPL_STATSXLINE
),
1162 'x', aconf
->port
, aconf
->name
,
1168 stats_gecos(struct Client
*source_p
)
1170 struct ConfItem
*aconf
;
1173 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1178 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1179 form_str(RPL_STATSXLINE
),
1180 'X', aconf
->port
, aconf
->name
,
1186 stats_class(struct Client
*source_p
)
1188 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOper(source_p
))
1189 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1190 form_str (ERR_NOPRIVILEGES
));
1192 report_classes(source_p
);
1196 stats_memory (struct Client
*source_p
)
1198 struct Client
*target_p
;
1199 struct Channel
*chptr
;
1200 struct Ban
*actualBan
;
1201 rb_dlink_node
*rb_dlink
;
1203 int channel_count
= 0;
1204 int local_client_conf_count
= 0; /* local client conf links */
1205 int users_counted
= 0; /* user structs */
1207 int channel_users
= 0;
1208 int channel_invites
= 0;
1209 int channel_bans
= 0;
1210 int channel_except
= 0;
1211 int channel_invex
= 0;
1212 int channel_quiets
= 0;
1214 int class_count
= 0; /* classes */
1215 int conf_count
= 0; /* conf lines */
1216 int users_invited_count
= 0; /* users invited */
1217 int user_channels
= 0; /* users in channels */
1218 int aways_counted
= 0;
1219 size_t number_servers_cached
; /* number of servers cached by scache */
1221 size_t channel_memory
= 0;
1222 size_t channel_ban_memory
= 0;
1223 size_t channel_except_memory
= 0;
1224 size_t channel_invex_memory
= 0;
1225 size_t channel_quiet_memory
= 0;
1227 size_t away_memory
= 0; /* memory used by aways */
1228 size_t ww
= 0; /* whowas array count */
1229 size_t wwm
= 0; /* whowas array memory used */
1230 size_t conf_memory
= 0; /* memory used by conf lines */
1231 size_t mem_servers_cached
; /* memory used by scache */
1233 size_t linebuf_count
= 0;
1234 size_t linebuf_memory_used
= 0;
1236 size_t total_channel_memory
= 0;
1239 size_t local_client_count
= 0;
1240 size_t local_client_memory_used
= 0;
1242 size_t remote_client_count
= 0;
1243 size_t remote_client_memory_used
= 0;
1245 size_t total_memory
= 0;
1247 count_whowas_memory(&ww
, &wwm
);
1249 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
1251 target_p
= ptr
->data
;
1252 if(MyConnect(target_p
))
1254 local_client_conf_count
++;
1260 users_invited_count
+= rb_dlink_list_length(&target_p
->user
->invited
);
1261 user_channels
+= rb_dlink_list_length(&target_p
->user
->channel
);
1262 if(target_p
->user
->away
)
1265 away_memory
+= (strlen(target_p
->user
->away
) + 1);
1270 /* Count up all channels, ban lists, except lists, Invex lists */
1271 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
1275 channel_memory
+= (strlen(chptr
->chname
) + sizeof(struct Channel
));
1277 channel_users
+= rb_dlink_list_length(&chptr
->members
);
1278 channel_invites
+= rb_dlink_list_length(&chptr
->invites
);
1280 RB_DLINK_FOREACH(rb_dlink
, chptr
->banlist
.head
)
1282 actualBan
= rb_dlink
->data
;
1285 channel_ban_memory
+= sizeof(rb_dlink_node
) + sizeof(struct Ban
);
1288 RB_DLINK_FOREACH(rb_dlink
, chptr
->exceptlist
.head
)
1290 actualBan
= rb_dlink
->data
;
1293 channel_except_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1296 RB_DLINK_FOREACH(rb_dlink
, chptr
->invexlist
.head
)
1298 actualBan
= rb_dlink
->data
;
1301 channel_invex_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1304 RB_DLINK_FOREACH(rb_dlink
, chptr
->quietlist
.head
)
1306 actualBan
= rb_dlink
->data
;
1309 channel_quiet_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
1313 /* count up all classes */
1315 class_count
= rb_dlink_list_length(&class_list
) + 1;
1317 rb_count_rb_linebuf_memory(&linebuf_count
, &linebuf_memory_used
);
1319 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1320 "z :Users %u(%lu) Invites %u(%lu)",
1322 (unsigned long) users_counted
* sizeof(struct User
),
1323 users_invited_count
,
1324 (unsigned long) users_invited_count
* sizeof(rb_dlink_node
));
1326 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1327 "z :User channels %u(%lu) Aways %u(%d)",
1329 (unsigned long) user_channels
* sizeof(rb_dlink_node
),
1330 aways_counted
, (int) away_memory
);
1332 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1333 "z :Attached confs %u(%lu)",
1334 local_client_conf_count
,
1335 (unsigned long) local_client_conf_count
* sizeof(rb_dlink_node
));
1337 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1338 "z :Conflines %u(%d)", conf_count
, (int) conf_memory
);
1340 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1341 "z :Classes %u(%lu)",
1343 (unsigned long) class_count
* sizeof(struct Class
));
1345 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1346 "z :Channels %u(%d)",
1347 channel_count
, (int) channel_memory
);
1349 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1350 "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)",
1351 channel_bans
, (int) channel_ban_memory
,
1352 channel_except
, (int) channel_except_memory
,
1353 channel_invex
, (int) channel_invex_memory
,
1354 channel_quiets
, (int) channel_quiet_memory
);
1356 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1357 "z :Channel members %u(%lu) invite %u(%lu)",
1359 (unsigned long) channel_users
* sizeof(rb_dlink_node
),
1361 (unsigned long) channel_invites
* sizeof(rb_dlink_node
));
1363 total_channel_memory
= channel_memory
+
1364 channel_ban_memory
+
1365 channel_users
* sizeof(rb_dlink_node
) + channel_invites
* sizeof(rb_dlink_node
);
1367 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1368 "z :Whowas array %ld(%ld)",
1369 (long)ww
, (long)wwm
);
1373 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1374 "z :Hash: client %u(%ld) chan %u(%ld)",
1375 U_MAX
, (long)(U_MAX
* sizeof(rb_dlink_list
)),
1376 CH_MAX
, (long)(CH_MAX
* sizeof(rb_dlink_list
)));
1378 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1379 "z :linebuf %ld(%ld)",
1380 (long)linebuf_count
, (long)linebuf_memory_used
);
1382 count_scache(&number_servers_cached
, &mem_servers_cached
);
1384 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1385 "z :scache %ld(%ld)",
1386 (long)number_servers_cached
, (long)mem_servers_cached
);
1388 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1389 "z :hostname hash %d(%ld)",
1390 HOST_MAX
, (long)HOST_MAX
* sizeof(rb_dlink_list
));
1392 total_memory
= totww
+ total_channel_memory
+ conf_memory
+
1393 class_count
* sizeof(struct Class
);
1395 total_memory
+= mem_servers_cached
;
1396 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1397 "z :Total: whowas %d channel %d conf %d",
1398 (int) totww
, (int) total_channel_memory
,
1401 count_local_client_memory(&local_client_count
, &local_client_memory_used
);
1402 total_memory
+= local_client_memory_used
;
1404 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1405 "z :Local client Memory in use: %ld(%ld)",
1406 (long)local_client_count
, (long)local_client_memory_used
);
1409 count_remote_client_memory(&remote_client_count
, &remote_client_memory_used
);
1410 total_memory
+= remote_client_memory_used
;
1412 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1413 "z :Remote client Memory in use: %ld(%ld)",
1414 (long)remote_client_count
,
1415 (long)remote_client_memory_used
);
1419 stats_ziplinks (struct Client
*source_p
)
1422 struct Client
*target_p
;
1423 struct ZipStats
*zipstats
;
1425 char buf
[128], buf1
[128];
1426 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1428 target_p
= ptr
->data
;
1429 if(IsCapable (target_p
, CAP_ZIP
))
1431 zipstats
= target_p
->localClient
->zipstats
;
1432 sprintf(buf
, "%.2f%%", zipstats
->out_ratio
);
1433 sprintf(buf1
, "%.2f%%", zipstats
->in_ratio
);
1434 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1435 "Z :ZipLinks stats for %s send[%s compression "
1436 "(%llu kB data/%llu kB wire)] recv[%s compression "
1437 "(%llu kB data/%llu kB wire)]",
1439 buf
, zipstats
->out
>> 10,
1440 zipstats
->out_wire
>> 10, buf1
,
1441 zipstats
->in
>> 10, zipstats
->in_wire
>> 10);
1446 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1447 "Z :%u ziplink(s)", sent_data
);
1451 stats_servlinks (struct Client
*source_p
)
1453 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1454 long uptime
, sendK
, receiveK
;
1455 struct Client
*target_p
;
1460 if(ConfigServerHide
.flatten_links
&& !IsOper (source_p
) &&
1461 !IsExemptShide(source_p
))
1463 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1464 form_str (ERR_NOPRIVILEGES
));
1468 sendK
= receiveK
= 0;
1470 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1472 target_p
= ptr
->data
;
1475 sendK
+= target_p
->localClient
->sendK
;
1476 receiveK
+= target_p
->localClient
->receiveK
;
1478 sendto_one(source_p
, Sformat
,
1479 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1480 get_server_name(target_p
, SHOW_IP
),
1481 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1482 (int) target_p
->localClient
->sendM
,
1483 (int) target_p
->localClient
->sendK
,
1484 (int) target_p
->localClient
->receiveM
,
1485 (int) target_p
->localClient
->receiveK
,
1486 rb_current_time() - target_p
->localClient
->firsttime
,
1487 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1488 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1489 IsOper (source_p
) ? show_capabilities (target_p
) : "TS");
1492 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1493 "? :%u total server(s)", j
);
1495 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((sendK
)));
1496 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1497 "? :Sent total : %s %s",
1498 buf
, _GMKs (sendK
));
1499 snprintf(buf
, sizeof buf
, "%7.2f", _GMKv ((receiveK
)));
1500 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1501 "? :Recv total : %s %s",
1502 buf
, _GMKs (receiveK
));
1504 uptime
= (rb_current_time() - startup_time
);
1505 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1506 _GMKv (me
.localClient
->sendK
),
1507 _GMKs (me
.localClient
->sendK
),
1508 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1509 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server send: %s", buf
);
1510 snprintf(buf
, sizeof buf
, "%7.2f %s (%4.1f K/s)",
1511 _GMKv (me
.localClient
->receiveK
),
1512 _GMKs (me
.localClient
->receiveK
),
1513 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1514 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "? :Server recv: %s", buf
);
1518 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1523 char statchar
= parv
[1][0];
1525 /* this is def targeted at us somehow.. */
1526 if(parc
> 2 && !EmptyString(parv
[2]))
1528 /* directed at us generically? */
1529 if(match(parv
[2], me
.name
) ||
1530 (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1538 wilds
= strchr(name
, '*') || strchr(name
, '?');
1541 /* must be directed at a specific person thats not us */
1542 if(!doall
&& !wilds
)
1544 struct Client
*target_p
;
1546 if(MyClient(source_p
))
1547 target_p
= find_named_person(name
);
1549 target_p
= find_person(name
);
1551 if(target_p
!= NULL
)
1553 stats_spy(source_p
, statchar
, target_p
->name
);
1554 stats_l_client(source_p
, target_p
, statchar
);
1557 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1558 form_str(ERR_NOSUCHSERVER
),
1570 stats_spy(source_p
, statchar
, name
);
1574 /* local opers get everyone */
1575 if(MyOper(source_p
))
1577 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
);
1578 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
);
1582 /* they still need themselves if theyre local.. */
1583 if(MyClient(source_p
))
1584 stats_l_client(source_p
, source_p
, statchar
);
1586 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
);
1589 if (!ConfigServerHide
.flatten_links
|| IsOper(source_p
) ||
1590 IsExemptShide(source_p
))
1591 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
);
1596 /* ok, at this point theyre looking for a specific client whos on
1597 * our server.. but it contains a wildcard. --fl
1599 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
);
1606 stats_l_list(struct Client
*source_p
, const char *name
, int doall
, int wilds
,
1607 rb_dlink_list
* list
, char statchar
)
1610 struct Client
*target_p
;
1612 /* send information about connections which match. note, we
1613 * dont need tests for IsInvisible(), because non-opers will
1614 * never get here for normal clients --fl
1616 RB_DLINK_FOREACH(ptr
, list
->head
)
1618 target_p
= ptr
->data
;
1620 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1623 stats_l_client(source_p
, target_p
, statchar
);
1628 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1631 if(IsAnyServer(target_p
))
1633 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1634 get_server_name(target_p
, SHOW_IP
),
1635 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1636 (int) target_p
->localClient
->sendM
,
1637 (int) target_p
->localClient
->sendK
,
1638 (int) target_p
->localClient
->receiveM
,
1639 (int) target_p
->localClient
->receiveK
,
1640 rb_current_time() - target_p
->localClient
->firsttime
,
1641 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1642 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1643 IsOper(source_p
) ? show_capabilities(target_p
) : "-");
1648 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1649 show_ip(source_p
, target_p
) ?
1650 (IsUpper(statchar
) ?
1651 get_client_name(target_p
, SHOW_IP
) :
1652 get_client_name(target_p
, HIDE_IP
)) :
1653 get_client_name(target_p
, MASK_IP
),
1654 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1655 (int) target_p
->localClient
->sendM
,
1656 (int) target_p
->localClient
->sendK
,
1657 (int) target_p
->localClient
->receiveM
,
1658 (int) target_p
->localClient
->receiveK
,
1659 rb_current_time() - target_p
->localClient
->firsttime
,
1660 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1661 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1667 rb_dump_fd_callback(int fd
, const char *desc
, void *data
)
1669 struct Client
*source_p
= data
;
1670 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "F :fd %-3d desc '%s'", fd
, desc
);
1674 stats_comm(struct Client
*source_p
)
1676 rb_dump_fd(rb_dump_fd_callback
, source_p
);
1682 * inputs - pointer to client doing the /stats
1683 * - char letter they are doing /stats on
1686 * This little helper function reports to opers if configured.
1687 * personally, I don't see why opers need to see stats requests
1688 * at all. They are just "noise" to an oper, and users can't do
1689 * any damage with stats requests now anyway. So, why show them?
1693 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1697 data
.client
= source_p
;
1699 data
.arg2
= (int) statchar
;
1701 call_hook(doing_stats_hook
, &data
);
1706 * input - pointer to client doing stats
1708 * side effects - call hook doing_stats_p
1711 stats_p_spy (struct Client
*source_p
)
1715 data
.client
= source_p
;
1716 data
.arg1
= data
.arg2
= NULL
;
1718 call_hook(doing_stats_p_hook
, &data
);