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 147 2006-11-13 12:35:45Z spb $
28 #include "tools.h" /* dlink_node/dlink_list */
29 #include "class.h" /* report_classes */
30 #include "client.h" /* Client */
31 #include "common.h" /* TRUE/FALSE */
32 #include "irc_string.h"
33 #include "ircd.h" /* me */
34 #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 "commio.h" /* highest_fd */
41 #include "s_conf.h" /* ConfItem */
42 #include "s_serv.h" /* hunt_server */
43 #include "s_stats.h" /* tstats */
44 #include "s_user.h" /* show_opers */
45 #include "event.h" /* events */
46 #include "blacklist.h" /* dnsbl stuff */
51 #include "s_newconf.h"
54 static int m_stats (struct Client
*, struct Client
*, int, const char **);
56 struct Message stats_msgtab
= {
57 "STATS", 0, 0, 0, MFLG_SLOW
,
58 {mg_unreg
, {m_stats
, 2}, {m_stats
, 3}, mg_ignore
, mg_ignore
, {m_stats
, 2}}
62 int doing_stats_p_hook
;
64 mapi_clist_av1 stats_clist
[] = { &stats_msgtab
, NULL
};
65 mapi_hlist_av1 stats_hlist
[] = {
66 { "doing_stats", &doing_stats_hook
},
67 { "doing_stats_p", &doing_stats_p_hook
},
71 DECLARE_MODULE_AV1(stats
, NULL
, NULL
, stats_clist
, stats_hlist
, NULL
, "$Revision: 147 $");
73 const char *Lformat
= "%s %u %u %u %u %u :%u %u %s";
75 static void stats_l_list(struct Client
*s
, const char *, int, int, dlink_list
*, char);
76 static void stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
79 /* Heres our struct for the stats table */
88 static void stats_dns_servers (struct Client
*);
89 static void stats_delay(struct Client
*);
90 static void stats_hash(struct Client
*);
91 static void stats_connect(struct Client
*);
92 static void stats_tdeny(struct Client
*);
93 static void stats_deny(struct Client
*);
94 static void stats_exempt(struct Client
*);
95 static void stats_events(struct Client
*);
96 static void stats_hubleaf(struct Client
*);
97 static void stats_auth(struct Client
*);
98 static void stats_tklines(struct Client
*);
99 static void stats_klines(struct Client
*);
100 static void stats_messages(struct Client
*);
101 static void stats_dnsbl(struct Client
*);
102 static void stats_oper(struct Client
*);
103 static void stats_operedup(struct Client
*);
104 static void stats_ports(struct Client
*);
105 static void stats_tresv(struct Client
*);
106 static void stats_resv(struct Client
*);
107 static void stats_usage(struct Client
*);
108 static void stats_tstats(struct Client
*);
109 static void stats_uptime(struct Client
*);
110 static void stats_shared(struct Client
*);
111 static void stats_servers(struct Client
*);
112 static void stats_tgecos(struct Client
*);
113 static void stats_gecos(struct Client
*);
114 static void stats_class(struct Client
*);
115 static void stats_memory(struct Client
*);
116 static void stats_servlinks(struct Client
*);
117 static void stats_ltrace(struct Client
*, int, const char **);
118 static void stats_ziplinks(struct Client
*);
120 /* This table contains the possible stats items, in order:
121 * stats letter, function to call, operonly? adminonly?
122 * case only matters in the stats letter column.. -- fl_
124 static struct StatsStruct stats_cmd_table
[] = {
125 /* letter function need_oper need_admin */
126 {'a', stats_dns_servers
, 1, 1, },
127 {'A', stats_dns_servers
, 1, 1, },
128 {'b', stats_delay
, 1, 1, },
129 {'B', stats_hash
, 1, 1, },
130 {'c', stats_connect
, 0, 0, },
131 {'C', stats_connect
, 0, 0, },
132 {'d', stats_tdeny
, 1, 0, },
133 {'D', stats_deny
, 1, 0, },
134 {'e', stats_exempt
, 1, 0, },
135 {'E', stats_events
, 1, 1, },
136 {'f', comm_dump
, 1, 1, },
137 {'F', comm_dump
, 1, 1, },
138 {'h', stats_hubleaf
, 0, 0, },
139 {'H', stats_hubleaf
, 0, 0, },
140 {'i', stats_auth
, 0, 0, },
141 {'I', stats_auth
, 0, 0, },
142 {'k', stats_tklines
, 0, 0, },
143 {'K', stats_klines
, 0, 0, },
144 {'l', stats_ltrace
, 0, 0, },
145 {'L', stats_ltrace
, 0, 0, },
146 {'m', stats_messages
, 0, 0, },
147 {'M', stats_messages
, 0, 0, },
148 {'n', stats_dnsbl
, 0, 0, },
149 {'o', stats_oper
, 0, 0, },
150 {'O', stats_oper
, 0, 0, },
151 {'p', stats_operedup
, 0, 0, },
152 {'P', stats_ports
, 0, 0, },
153 {'q', stats_tresv
, 1, 0, },
154 {'Q', stats_resv
, 1, 0, },
155 {'r', stats_usage
, 1, 0, },
156 {'R', stats_usage
, 1, 0, },
157 {'t', stats_tstats
, 1, 0, },
158 {'T', stats_tstats
, 1, 0, },
159 {'u', stats_uptime
, 0, 0, },
160 {'U', stats_shared
, 1, 0, },
161 {'v', stats_servers
, 0, 0, },
162 {'V', stats_servers
, 0, 0, },
163 {'x', stats_tgecos
, 1, 0, },
164 {'X', stats_gecos
, 1, 0, },
165 {'y', stats_class
, 0, 0, },
166 {'Y', stats_class
, 0, 0, },
167 {'z', stats_memory
, 1, 0, },
168 {'Z', stats_ziplinks
, 1, 0, },
169 {'?', stats_servlinks
, 0, 0, },
170 {(char) 0, (void (*)()) 0, 0, 0, }
175 * parv[0] = sender prefix
176 * parv[1] = stat letter/command
177 * parv[2] = (if present) server/mask in stats L, or target
179 * This will search the tables for the appropriate stats letter,
180 * if found execute it.
183 m_stats(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
185 static time_t last_used
= 0;
189 statchar
= parv
[1][0];
191 if(MyClient(source_p
) && !IsOperStaffer(source_p
))
193 /* Check the user is actually allowed to do /stats, and isnt flooding */
194 if((last_used
+ ConfigFileEntry
.pace_wait
) > CurrentTime
)
196 /* safe enough to give this on a local connect only */
197 sendto_one(source_p
, form_str(RPL_LOAD2HI
),
198 me
.name
, source_p
->name
, "STATS");
199 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
200 form_str(RPL_ENDOFSTATS
), statchar
);
204 last_used
= CurrentTime
;
207 if(hunt_server (client_p
, source_p
, ":%s STATS %s :%s", 2, parc
, parv
) != HUNTED_ISME
)
210 for (i
= 0; stats_cmd_table
[i
].handler
; i
++)
212 if(stats_cmd_table
[i
].letter
== statchar
)
214 /* The stats table says what privs are needed, so check --fl_ */
215 /* Called for remote clients and for local opers, so check need_admin
218 if((stats_cmd_table
[i
].need_admin
&& !IsOperAdmin (source_p
)) ||
219 (stats_cmd_table
[i
].need_oper
&& !IsOper (source_p
)))
221 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
222 form_str (ERR_NOPRIVILEGES
));
226 /* Blah, stats L needs the parameters, none of the others do.. */
227 if(statchar
== 'L' || statchar
== 'l')
228 stats_cmd_table
[i
].handler (source_p
, parc
, parv
);
230 stats_cmd_table
[i
].handler (source_p
);
234 /* Send the end of stats notice, and the stats_spy */
235 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
236 form_str(RPL_ENDOFSTATS
), statchar
);
242 stats_dns_servers (struct Client
*source_p
)
244 report_dns_servers (source_p
);
248 stats_delay(struct Client
*source_p
)
254 HASH_WALK(i
, U_MAX
, ptr
, ndTable
)
257 sendto_one_notice(source_p
, "Delaying: %s for %ld",
258 nd
->name
, (long) nd
->expire
);
264 stats_hash(struct Client
*source_p
)
266 hash_stats(source_p
);
270 stats_connect(struct Client
*source_p
)
273 struct server_conf
*server_p
;
277 if((ConfigFileEntry
.stats_c_oper_only
||
278 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
279 !IsOperRouting(source_p
))
281 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
282 form_str(ERR_NOPRIVILEGES
));
286 DLINK_FOREACH(ptr
, server_conf_list
.head
)
288 server_p
= ptr
->data
;
290 if(ServerConfIllegal(server_p
))
296 if(IsOperRouting(source_p
))
298 if(ServerConfAutoconn(server_p
))
300 if(ServerConfTb(server_p
))
302 if(ServerConfCompressed(server_p
))
311 sendto_one_numeric(source_p
, RPL_STATSCLINE
,
312 form_str(RPL_STATSCLINE
),
313 #ifndef HIDE_SERVERS_IPS
319 server_p
->port
, server_p
->class_name
);
325 * input - client to report to
327 * side effects - client is given temp dline list.
330 stats_tdeny (struct Client
*source_p
)
332 char *host
, *pass
, *user
, *oper_reason
;
333 struct AddressRec
*arec
;
334 struct ConfItem
*aconf
;
337 for (i
= 0; i
< ATABLE_SIZE
; i
++)
339 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
341 if(arec
->type
== CONF_DLINE
)
345 if(!(aconf
->flags
& CONF_FLAGS_TEMPORARY
))
348 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
350 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
351 form_str (RPL_STATSDLINE
),
353 oper_reason
? "|" : "",
354 oper_reason
? oper_reason
: "");
362 * input - client to report to
364 * side effects - client is given dline list.
367 stats_deny (struct Client
*source_p
)
369 char *host
, *pass
, *user
, *oper_reason
;
370 struct AddressRec
*arec
;
371 struct ConfItem
*aconf
;
374 for (i
= 0; i
< ATABLE_SIZE
; i
++)
376 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
378 if(arec
->type
== CONF_DLINE
)
382 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
385 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
387 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
388 form_str (RPL_STATSDLINE
),
390 oper_reason
? "|" : "",
391 oper_reason
? oper_reason
: "");
400 * input - client to report to
402 * side effects - client is given list of exempt blocks
405 stats_exempt(struct Client
*source_p
)
407 char *name
, *host
, *pass
, *user
, *classname
;
408 struct AddressRec
*arec
;
409 struct ConfItem
*aconf
;
412 if(ConfigFileEntry
.stats_e_disabled
)
414 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
415 form_str (ERR_NOPRIVILEGES
));
419 for (i
= 0; i
< ATABLE_SIZE
; i
++)
421 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
423 if(arec
->type
== CONF_EXEMPTDLINE
)
426 get_printable_conf (aconf
, &name
, &host
, &pass
,
427 &user
, &port
, &classname
);
429 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
430 form_str(RPL_STATSDLINE
),
431 'e', host
, pass
, "", "");
438 stats_events (struct Client
*source_p
)
440 show_events (source_p
);
444 stats_hubleaf(struct Client
*source_p
)
446 struct remote_conf
*hub_p
;
449 if((ConfigFileEntry
.stats_h_oper_only
||
450 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
451 !IsOperRouting(source_p
))
453 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
454 form_str (ERR_NOPRIVILEGES
));
458 DLINK_FOREACH(ptr
, hubleaf_conf_list
.head
)
462 if(hub_p
->flags
& CONF_HUB
)
463 sendto_one_numeric(source_p
, RPL_STATSHLINE
,
464 form_str(RPL_STATSHLINE
),
465 hub_p
->host
, hub_p
->server
);
467 sendto_one_numeric(source_p
, RPL_STATSLLINE
,
468 form_str(RPL_STATSLLINE
),
469 hub_p
->host
, hub_p
->server
);
475 stats_auth (struct Client
*source_p
)
477 /* Oper only, if unopered, return ERR_NOPRIVS */
478 if((ConfigFileEntry
.stats_i_oper_only
== 2) && !IsOper (source_p
))
479 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
480 form_str (ERR_NOPRIVILEGES
));
482 /* If unopered, Only return matching auth blocks */
483 else if((ConfigFileEntry
.stats_i_oper_only
== 1) && !IsOper (source_p
))
485 struct ConfItem
*aconf
;
486 char *name
, *host
, *pass
, *user
, *classname
;
489 if(MyConnect (source_p
))
490 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
491 (struct sockaddr
*)&source_p
->localClient
->ip
,
493 source_p
->localClient
->ip
.ss_family
,
496 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_CLIENT
,
497 0, source_p
->username
);
502 get_printable_conf (aconf
, &name
, &host
, &pass
, &user
, &port
, &classname
);
504 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
505 name
, show_iline_prefix(source_p
, aconf
, user
),
506 host
, port
, classname
);
509 /* Theyre opered, or allowed to see all auth blocks */
511 report_auth (source_p
);
516 stats_tklines(struct Client
*source_p
)
518 /* Oper only, if unopered, return ERR_NOPRIVS */
519 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
520 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
521 form_str (ERR_NOPRIVILEGES
));
523 /* If unopered, Only return matching klines */
524 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
526 struct ConfItem
*aconf
;
527 char *host
, *pass
, *user
, *oper_reason
;
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
,
536 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
537 0, source_p
->username
);
542 /* dont report a permanent kline as a tkline */
543 if((aconf
->flags
& CONF_FLAGS_TEMPORARY
) == 0)
546 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
548 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
549 form_str(RPL_STATSKLINE
), 'k',
550 user
, pass
, oper_reason
? "|" : "",
551 oper_reason
? oper_reason
: "");
553 /* Theyre opered, or allowed to see all klines */
556 struct ConfItem
*aconf
;
559 char *user
, *host
, *pass
, *oper_reason
;
561 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
563 DLINK_FOREACH(ptr
, temp_klines
[i
].head
)
567 get_printable_kline(source_p
, aconf
, &host
, &pass
,
568 &user
, &oper_reason
);
570 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
571 form_str(RPL_STATSKLINE
),
572 'k', host
, user
, pass
,
573 oper_reason
? "|" : "",
574 oper_reason
? oper_reason
: "");
581 stats_klines(struct Client
*source_p
)
583 /* Oper only, if unopered, return ERR_NOPRIVS */
584 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
585 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
586 form_str (ERR_NOPRIVILEGES
));
588 /* If unopered, Only return matching klines */
589 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
591 struct ConfItem
*aconf
;
592 char *host
, *pass
, *user
, *oper_reason
;
594 /* search for a kline */
595 if(MyConnect (source_p
))
596 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
597 (struct sockaddr
*)&source_p
->localClient
->ip
,
599 source_p
->localClient
->ip
.ss_family
,
602 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
603 0, source_p
->username
);
608 /* dont report a tkline as a kline */
609 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
612 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
614 sendto_one_numeric(source_p
, RPL_STATSKLINE
, form_str(RPL_STATSKLINE
),
615 'K', host
, user
, pass
, oper_reason
? "|" : "",
616 oper_reason
? oper_reason
: "");
618 /* Theyre opered, or allowed to see all klines */
620 report_Klines (source_p
);
624 stats_messages(struct Client
*source_p
)
626 report_messages(source_p
);
630 stats_dnsbl(struct Client
*source_p
)
633 struct Blacklist
*blptr
;
635 DLINK_FOREACH(ptr
, blacklist_list
.head
)
639 /* use RPL_STATSDEBUG for now -- jilles */
640 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "n :%d %s %s (%d)",
643 blptr
->status
& CONF_ILLEGAL
? "disabled" : "active",
649 stats_oper(struct Client
*source_p
)
651 struct oper_conf
*oper_p
;
654 if(!IsOperStaffer(source_p
) && ConfigFileEntry
.stats_o_oper_only
)
656 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
657 form_str (ERR_NOPRIVILEGES
));
661 DLINK_FOREACH(ptr
, oper_conf_list
.head
)
665 sendto_one_numeric(source_p
, RPL_STATSOLINE
,
666 form_str(RPL_STATSOLINE
),
667 oper_p
->username
, oper_p
->host
, oper_p
->name
,
668 IsOperStaffer(source_p
) ? get_oper_privs(oper_p
->flags
) : "0", "-1");
675 * input - client pointer
677 * side effects - client is shown a list of active opers
680 stats_operedup (struct Client
*source_p
)
682 struct Client
*target_p
;
683 dlink_node
*oper_ptr
;
684 unsigned int count
= 0;
686 DLINK_FOREACH (oper_ptr
, oper_list
.head
)
688 target_p
= oper_ptr
->data
;
690 if(!IsHelper(target_p
))
693 if(target_p
->user
->away
)
698 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
700 target_p
->name
, target_p
->username
,
704 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
705 "p :%u staff members", count
);
709 stats_ports (struct Client
*source_p
)
711 if(!IsOper (source_p
) && ConfigFileEntry
.stats_P_oper_only
)
712 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
713 form_str (ERR_NOPRIVILEGES
));
715 show_ports (source_p
);
719 stats_tresv(struct Client
*source_p
)
721 struct ConfItem
*aconf
;
725 DLINK_FOREACH(ptr
, resv_conf_list
.head
)
729 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
730 form_str(RPL_STATSQLINE
),
731 'q', aconf
->port
, aconf
->name
, aconf
->passwd
);
734 HASH_WALK(i
, R_MAX
, ptr
, resvTable
)
738 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
739 form_str(RPL_STATSQLINE
),
740 'q', aconf
->port
, aconf
->name
, aconf
->passwd
);
747 stats_resv(struct Client
*source_p
)
749 struct ConfItem
*aconf
;
753 DLINK_FOREACH(ptr
, resv_conf_list
.head
)
757 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
758 form_str(RPL_STATSQLINE
),
759 'Q', aconf
->port
, aconf
->name
, aconf
->passwd
);
762 HASH_WALK(i
, R_MAX
, ptr
, resvTable
)
766 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
767 form_str(RPL_STATSQLINE
),
768 'Q', aconf
->port
, aconf
->name
, aconf
->passwd
);
774 stats_usage (struct Client
*source_p
)
789 if(getrusage(RUSAGE_SELF
, &rus
) == -1)
791 sendto_one_notice(source_p
, ":Getruseage error: %s.",
795 secs
= rus
.ru_utime
.tv_sec
+ rus
.ru_stime
.tv_sec
;
799 rup
= (CurrentTime
- startup_time
) * hzz
;
803 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
804 "R :CPU Secs %d:%d User %d:%d System %d:%d",
805 (int) (secs
/ 60), (int) (secs
% 60),
806 (int) (rus
.ru_utime
.tv_sec
/ 60),
807 (int) (rus
.ru_utime
.tv_sec
% 60),
808 (int) (rus
.ru_stime
.tv_sec
/ 60),
809 (int) (rus
.ru_stime
.tv_sec
% 60));
810 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
811 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
812 rus
.ru_maxrss
, (rus
.ru_ixrss
/ rup
),
813 (rus
.ru_idrss
/ rup
), (rus
.ru_isrss
/ rup
));
814 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
815 "R :Swaps %d Reclaims %d Faults %d",
816 (int) rus
.ru_nswap
, (int) rus
.ru_minflt
, (int) rus
.ru_majflt
);
817 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
818 "R :Block in %d out %d",
819 (int) rus
.ru_inblock
, (int) rus
.ru_oublock
);
820 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
821 "R :Msg Rcv %d Send %d",
822 (int) rus
.ru_msgrcv
, (int) rus
.ru_msgsnd
);
823 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
824 "R :Signals %d Context Vol. %d Invol %d",
825 (int) rus
.ru_nsignals
, (int) rus
.ru_nvcsw
,
826 (int) rus
.ru_nivcsw
);
830 stats_tstats (struct Client
*source_p
)
836 stats_uptime (struct Client
*source_p
)
840 now
= CurrentTime
- startup_time
;
841 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
842 form_str (RPL_STATSUPTIME
),
843 now
/ 86400, (now
/ 3600) % 24,
844 (now
/ 60) % 60, now
% 60);
845 sendto_one_numeric(source_p
, RPL_STATSCONN
,
846 form_str (RPL_STATSCONN
),
847 MaxConnectionCount
, MaxClientCount
,
848 Count
.totalrestartcount
);
856 static struct shared_flags shared_flagtable
[] =
858 { SHARED_PKLINE
, 'K' },
859 { SHARED_TKLINE
, 'k' },
860 { SHARED_UNKLINE
, 'U' },
861 { SHARED_PXLINE
, 'X' },
862 { SHARED_TXLINE
, 'x' },
863 { SHARED_UNXLINE
, 'Y' },
864 { SHARED_PRESV
, 'Q' },
865 { SHARED_TRESV
, 'q' },
866 { SHARED_UNRESV
, 'R' },
867 { SHARED_PDLINE
, 'D' },
868 { SHARED_TDLINE
, 'd' },
869 { SHARED_UNDLINE
, 'E' },
870 { SHARED_REHASH
, 'H' },
876 stats_shared (struct Client
*source_p
)
878 struct remote_conf
*shared_p
;
884 DLINK_FOREACH(ptr
, shared_conf_list
.head
)
886 shared_p
= ptr
->data
;
892 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
894 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
895 *p
++ = shared_flagtable
[i
].letter
;
900 sendto_one_numeric(source_p
, RPL_STATSULINE
,
901 form_str(RPL_STATSULINE
),
902 shared_p
->server
, shared_p
->username
,
903 shared_p
->host
, buf
);
906 DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
908 shared_p
= ptr
->data
;
914 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
916 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
917 *p
++ = shared_flagtable
[i
].letter
;
922 sendto_one_numeric(source_p
, RPL_STATSULINE
,
923 form_str(RPL_STATSULINE
),
924 shared_p
->server
, "*", "*", buf
);
930 * input - client pointer
932 * side effects - client is shown lists of who connected servers
935 stats_servers (struct Client
*source_p
)
937 struct Client
*target_p
;
940 int days
, hours
, minutes
;
943 if(ConfigServerHide
.flatten_links
&& !IsOperRouting(source_p
) &&
944 !IsExemptShide(source_p
))
946 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
947 form_str (ERR_NOPRIVILEGES
));
951 DLINK_FOREACH (ptr
, serv_list
.head
)
953 target_p
= ptr
->data
;
956 seconds
= CurrentTime
- target_p
->localClient
->firsttime
;
958 days
= (int) (seconds
/ 86400);
960 hours
= (int) (seconds
/ 3600);
962 minutes
= (int) (seconds
/ 60);
965 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
966 "V :%s (%s!*@*) Idle: %d SendQ: %d "
967 "Connected: %d day%s, %d:%02d:%02d",
969 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
970 (int) (CurrentTime
- target_p
->localClient
->lasttime
),
971 (int) linebuf_len (&target_p
->localClient
->buf_sendq
),
972 days
, (days
== 1) ? "" : "s", hours
, minutes
,
976 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
977 "V :%d Server(s)", j
);
981 stats_tgecos(struct Client
*source_p
)
983 struct ConfItem
*aconf
;
986 DLINK_FOREACH(ptr
, xline_conf_list
.head
)
991 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
992 form_str(RPL_STATSXLINE
),
993 'x', aconf
->port
, aconf
->name
,
999 stats_gecos(struct Client
*source_p
)
1001 struct ConfItem
*aconf
;
1004 DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1009 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1010 form_str(RPL_STATSXLINE
),
1011 'X', aconf
->port
, aconf
->name
,
1017 stats_class(struct Client
*source_p
)
1019 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOperStaffer(source_p
))
1020 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1021 form_str (ERR_NOPRIVILEGES
));
1023 report_classes(source_p
);
1027 stats_memory (struct Client
*source_p
)
1029 count_memory (source_p
);
1033 stats_ziplinks (struct Client
*source_p
)
1036 struct Client
*target_p
;
1039 DLINK_FOREACH (ptr
, serv_list
.head
)
1041 target_p
= ptr
->data
;
1042 if(IsCapable (target_p
, CAP_ZIP
))
1044 /* we use memcpy(3) and a local copy of the structure to
1045 * work around a register use bug on GCC on the SPARC.
1046 * -jmallett, 04/27/2002
1048 struct ZipStats zipstats
;
1049 memcpy (&zipstats
, &target_p
->localClient
->zipstats
,
1050 sizeof (struct ZipStats
));
1051 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1052 "Z :ZipLinks stats for %s send[%.2f%% compression "
1053 "(%lu kB data/%lu kB wire)] recv[%.2f%% compression "
1054 "(%lu kB data/%lu kB wire)]",
1056 zipstats
.out_ratio
, zipstats
.outK
, zipstats
.outK_wire
,
1057 zipstats
.in_ratio
, zipstats
.inK
, zipstats
.inK_wire
);
1062 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1063 "Z :%u ziplink(s)", sent_data
);
1067 stats_servlinks (struct Client
*source_p
)
1069 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1070 long uptime
, sendK
, receiveK
;
1071 struct Client
*target_p
;
1075 if(ConfigServerHide
.flatten_links
&& !IsOper (source_p
) &&
1076 !IsExemptShide(source_p
))
1078 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1079 form_str (ERR_NOPRIVILEGES
));
1083 sendK
= receiveK
= 0;
1085 DLINK_FOREACH (ptr
, serv_list
.head
)
1087 target_p
= ptr
->data
;
1090 sendK
+= target_p
->localClient
->sendK
;
1091 receiveK
+= target_p
->localClient
->receiveK
;
1093 sendto_one(source_p
, Sformat
,
1094 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1095 get_server_name(target_p
, SHOW_IP
),
1096 (int) linebuf_len (&target_p
->localClient
->buf_sendq
),
1097 (int) target_p
->localClient
->sendM
,
1098 (int) target_p
->localClient
->sendK
,
1099 (int) target_p
->localClient
->receiveM
,
1100 (int) target_p
->localClient
->receiveK
,
1101 CurrentTime
- target_p
->localClient
->firsttime
,
1102 (CurrentTime
> target_p
->localClient
->lasttime
) ?
1103 (CurrentTime
- target_p
->localClient
->lasttime
) : 0,
1104 IsOper (source_p
) ? show_capabilities (target_p
) : "TS");
1107 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1108 "? :%u total server(s)", j
);
1110 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1111 "? :Sent total : %7.2f %s",
1112 _GMKv (sendK
), _GMKs (sendK
));
1113 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1114 "? :Recv total : %7.2f %s",
1115 _GMKv (receiveK
), _GMKs (receiveK
));
1117 uptime
= (CurrentTime
- startup_time
);
1119 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1120 "? :Server send: %7.2f %s (%4.1f K/s)",
1121 _GMKv (me
.localClient
->sendK
),
1122 _GMKs (me
.localClient
->sendK
),
1123 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1124 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1125 "? :Server recv: %7.2f %s (%4.1f K/s)",
1126 _GMKv (me
.localClient
->receiveK
),
1127 _GMKs (me
.localClient
->receiveK
),
1128 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1132 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1137 char statchar
= parv
[1][0];
1139 /* this is def targeted at us somehow.. */
1140 if(parc
> 2 && !EmptyString(parv
[2]))
1142 /* directed at us generically? */
1143 if(match(parv
[2], me
.name
) ||
1144 (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1152 wilds
= strchr(name
, '*') || strchr(name
, '?');
1155 /* must be directed at a specific person thats not us */
1156 if(!doall
&& !wilds
)
1158 struct Client
*target_p
;
1160 if(MyClient(source_p
))
1161 target_p
= find_named_person(name
);
1163 target_p
= find_person(name
);
1165 if(target_p
!= NULL
)
1167 stats_l_client(source_p
, target_p
, statchar
);
1170 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1171 form_str(ERR_NOSUCHSERVER
),
1185 /* local opers get everyone */
1186 if(MyOper(source_p
))
1188 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
);
1189 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
);
1193 /* they still need themselves if theyre local.. */
1194 if(MyClient(source_p
))
1195 stats_l_client(source_p
, source_p
, statchar
);
1197 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
);
1200 if (!ConfigServerHide
.flatten_links
|| IsOperRouting(source_p
) ||
1201 IsExemptShide(source_p
))
1202 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
);
1207 /* ok, at this point theyre looking for a specific client whos on
1208 * our server.. but it contains a wildcard. --fl
1210 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
);
1217 stats_l_list(struct Client
*source_p
, const char *name
, int doall
, int wilds
,
1218 dlink_list
* list
, char statchar
)
1221 struct Client
*target_p
;
1223 /* send information about connections which match. note, we
1224 * dont need tests for IsInvisible(), because non-opers will
1225 * never get here for normal clients --fl
1227 DLINK_FOREACH(ptr
, list
->head
)
1229 target_p
= ptr
->data
;
1231 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1234 stats_l_client(source_p
, target_p
, statchar
);
1239 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1242 if(IsAnyServer(target_p
))
1244 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1245 get_server_name(target_p
, SHOW_IP
),
1246 (int) linebuf_len(&target_p
->localClient
->buf_sendq
),
1247 (int) target_p
->localClient
->sendM
,
1248 (int) target_p
->localClient
->sendK
,
1249 (int) target_p
->localClient
->receiveM
,
1250 (int) target_p
->localClient
->receiveK
,
1251 CurrentTime
- target_p
->localClient
->firsttime
,
1252 (CurrentTime
> target_p
->localClient
->lasttime
) ?
1253 (CurrentTime
- target_p
->localClient
->lasttime
) : 0,
1254 IsOperStaffer(source_p
) ? show_capabilities(target_p
) : "-");
1259 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1260 show_ip(source_p
, target_p
) ?
1261 (IsUpper(statchar
) ?
1262 get_client_name(target_p
, SHOW_IP
) :
1263 get_client_name(target_p
, HIDE_IP
)) :
1264 get_client_name(target_p
, MASK_IP
),
1265 (int) linebuf_len(&target_p
->localClient
->buf_sendq
),
1266 (int) target_p
->localClient
->sendM
,
1267 (int) target_p
->localClient
->sendK
,
1268 (int) target_p
->localClient
->receiveM
,
1269 (int) target_p
->localClient
->receiveK
,
1270 CurrentTime
- target_p
->localClient
->firsttime
,
1271 (CurrentTime
> target_p
->localClient
->lasttime
) ?
1272 (CurrentTime
- target_p
->localClient
->lasttime
) : 0,