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
26 #include "tools.h" /* dlink_node/dlink_list */
27 #include "class.h" /* report_classes */
28 #include "client.h" /* Client */
29 #include "common.h" /* TRUE/FALSE */
30 #include "irc_string.h"
31 #include "ircd.h" /* me */
32 #include "listener.h" /* show_ports */
33 #include "msg.h" /* Message */
34 #include "hostmask.h" /* report_mtrie_conf_links */
35 #include "numeric.h" /* ERR_xxx */
36 #include "scache.h" /* list_scache */
37 #include "send.h" /* sendto_one */
38 #include "commio.h" /* highest_fd */
39 #include "s_conf.h" /* ConfItem */
40 #include "s_serv.h" /* hunt_server */
41 #include "s_stats.h" /* tstats */
42 #include "s_user.h" /* show_opers */
43 #include "event.h" /* events */
44 #include "blacklist.h" /* dnsbl stuff */
49 #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: 147 $");
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, dlink_list
*, char);
74 static void stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
77 static void stats_spy(struct Client
*, char, const char *);
78 static void stats_p_spy(struct Client
*);
80 /* Heres our struct for the stats table */
89 static void stats_dns_servers (struct Client
*);
90 static void stats_delay(struct Client
*);
91 static void stats_hash(struct Client
*);
92 static void stats_connect(struct Client
*);
93 static void stats_tdeny(struct Client
*);
94 static void stats_deny(struct Client
*);
95 static void stats_exempt(struct Client
*);
96 static void stats_events(struct Client
*);
97 static void stats_hubleaf(struct Client
*);
98 static void stats_auth(struct Client
*);
99 static void stats_tklines(struct Client
*);
100 static void stats_klines(struct Client
*);
101 static void stats_messages(struct Client
*);
102 static void stats_dnsbl(struct Client
*);
103 static void stats_oper(struct Client
*);
104 static void stats_operedup(struct Client
*);
105 static void stats_ports(struct Client
*);
106 static void stats_tresv(struct Client
*);
107 static void stats_resv(struct Client
*);
108 static void stats_usage(struct Client
*);
109 static void stats_tstats(struct Client
*);
110 static void stats_uptime(struct Client
*);
111 static void stats_shared(struct Client
*);
112 static void stats_servers(struct Client
*);
113 static void stats_tgecos(struct Client
*);
114 static void stats_gecos(struct Client
*);
115 static void stats_class(struct Client
*);
116 static void stats_memory(struct Client
*);
117 static void stats_servlinks(struct Client
*);
118 static void stats_ltrace(struct Client
*, int, const char **);
119 static void stats_ziplinks(struct Client
*);
121 /* This table contains the possible stats items, in order:
122 * stats letter, function to call, operonly? adminonly?
123 * case only matters in the stats letter column.. -- fl_
125 static struct StatsStruct stats_cmd_table
[] = {
126 /* letter function need_oper need_admin */
127 {'a', stats_dns_servers
, 1, 1, },
128 {'A', stats_dns_servers
, 1, 1, },
129 {'b', stats_delay
, 1, 1, },
130 {'B', stats_hash
, 1, 1, },
131 {'c', stats_connect
, 0, 0, },
132 {'C', stats_connect
, 0, 0, },
133 {'d', stats_tdeny
, 1, 0, },
134 {'D', stats_deny
, 1, 0, },
135 {'e', stats_exempt
, 1, 0, },
136 {'E', stats_events
, 1, 1, },
137 {'f', comm_dump
, 1, 1, },
138 {'F', comm_dump
, 1, 1, },
139 {'h', stats_hubleaf
, 0, 0, },
140 {'H', stats_hubleaf
, 0, 0, },
141 {'i', stats_auth
, 0, 0, },
142 {'I', stats_auth
, 0, 0, },
143 {'k', stats_tklines
, 0, 0, },
144 {'K', stats_klines
, 0, 0, },
145 {'l', stats_ltrace
, 0, 0, },
146 {'L', stats_ltrace
, 0, 0, },
147 {'m', stats_messages
, 0, 0, },
148 {'M', stats_messages
, 0, 0, },
149 {'n', stats_dnsbl
, 0, 0, },
150 {'o', stats_oper
, 0, 0, },
151 {'O', stats_oper
, 0, 0, },
152 {'p', stats_operedup
, 0, 0, },
153 {'P', stats_ports
, 0, 0, },
154 {'q', stats_tresv
, 1, 0, },
155 {'Q', stats_resv
, 1, 0, },
156 {'r', stats_usage
, 1, 0, },
157 {'R', stats_usage
, 1, 0, },
158 {'t', stats_tstats
, 1, 0, },
159 {'T', stats_tstats
, 1, 0, },
160 {'u', stats_uptime
, 0, 0, },
161 {'U', stats_shared
, 1, 0, },
162 {'v', stats_servers
, 0, 0, },
163 {'V', stats_servers
, 0, 0, },
164 {'x', stats_tgecos
, 1, 0, },
165 {'X', stats_gecos
, 1, 0, },
166 {'y', stats_class
, 0, 0, },
167 {'Y', stats_class
, 0, 0, },
168 {'z', stats_memory
, 1, 0, },
169 {'Z', stats_ziplinks
, 1, 0, },
170 {'?', stats_servlinks
, 0, 0, },
171 {(char) 0, (void (*)()) 0, 0, 0, }
176 * parv[0] = sender prefix
177 * parv[1] = stat letter/command
178 * parv[2] = (if present) server/mask in stats L, or target
180 * This will search the tables for the appropriate stats letter,
181 * if found execute it.
184 m_stats(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
186 static time_t last_used
= 0;
190 statchar
= parv
[1][0];
192 if(MyClient(source_p
) && !IsOperStaffer(source_p
))
194 /* Check the user is actually allowed to do /stats, and isnt flooding */
195 if((last_used
+ ConfigFileEntry
.pace_wait
) > CurrentTime
)
197 /* safe enough to give this on a local connect only */
198 sendto_one(source_p
, form_str(RPL_LOAD2HI
),
199 me
.name
, source_p
->name
, "STATS");
200 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
201 form_str(RPL_ENDOFSTATS
), statchar
);
205 last_used
= CurrentTime
;
208 if(hunt_server (client_p
, source_p
, ":%s STATS %s :%s", 2, parc
, parv
) != HUNTED_ISME
)
211 if((statchar
!= 'L') && (statchar
!= 'l'))
212 stats_spy(source_p
, statchar
, NULL
);
214 for (i
= 0; stats_cmd_table
[i
].handler
; i
++)
216 if(stats_cmd_table
[i
].letter
== statchar
)
218 /* The stats table says what privs are needed, so check --fl_ */
219 /* Called for remote clients and for local opers, so check need_admin
222 if((stats_cmd_table
[i
].need_admin
&& !IsOperAdmin (source_p
)) ||
223 (stats_cmd_table
[i
].need_oper
&& !IsOper (source_p
)))
225 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
226 form_str (ERR_NOPRIVILEGES
));
230 /* Blah, stats L needs the parameters, none of the others do.. */
231 if(statchar
== 'L' || statchar
== 'l')
232 stats_cmd_table
[i
].handler (source_p
, parc
, parv
);
234 stats_cmd_table
[i
].handler (source_p
);
238 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
239 form_str(RPL_ENDOFSTATS
), statchar
);
245 stats_dns_servers (struct Client
*source_p
)
247 report_dns_servers (source_p
);
251 stats_delay(struct Client
*source_p
)
257 HASH_WALK(i
, U_MAX
, ptr
, ndTable
)
260 sendto_one_notice(source_p
, "Delaying: %s for %ld",
261 nd
->name
, (long) nd
->expire
);
267 stats_hash(struct Client
*source_p
)
269 hash_stats(source_p
);
273 stats_connect(struct Client
*source_p
)
276 struct server_conf
*server_p
;
280 if((ConfigFileEntry
.stats_c_oper_only
||
281 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
282 !IsOperRouting(source_p
))
284 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
285 form_str(ERR_NOPRIVILEGES
));
289 DLINK_FOREACH(ptr
, server_conf_list
.head
)
291 server_p
= ptr
->data
;
293 if(ServerConfIllegal(server_p
))
299 if(IsOperRouting(source_p
))
301 if(ServerConfAutoconn(server_p
))
303 if(ServerConfTb(server_p
))
305 if(ServerConfCompressed(server_p
))
314 sendto_one_numeric(source_p
, RPL_STATSCLINE
,
315 form_str(RPL_STATSCLINE
),
316 #ifndef HIDE_SERVERS_IPS
322 server_p
->port
, server_p
->class_name
);
328 * input - client to report to
330 * side effects - client is given temp dline list.
333 stats_tdeny (struct Client
*source_p
)
335 char *host
, *pass
, *user
, *oper_reason
;
336 struct AddressRec
*arec
;
337 struct ConfItem
*aconf
;
340 for (i
= 0; i
< ATABLE_SIZE
; i
++)
342 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
344 if(arec
->type
== CONF_DLINE
)
348 if(!(aconf
->flags
& CONF_FLAGS_TEMPORARY
))
351 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
353 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
354 form_str (RPL_STATSDLINE
),
356 oper_reason
? "|" : "",
357 oper_reason
? oper_reason
: "");
365 * input - client to report to
367 * side effects - client is given dline list.
370 stats_deny (struct Client
*source_p
)
372 char *host
, *pass
, *user
, *oper_reason
;
373 struct AddressRec
*arec
;
374 struct ConfItem
*aconf
;
377 for (i
= 0; i
< ATABLE_SIZE
; i
++)
379 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
381 if(arec
->type
== CONF_DLINE
)
385 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
388 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
390 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
391 form_str (RPL_STATSDLINE
),
393 oper_reason
? "|" : "",
394 oper_reason
? oper_reason
: "");
403 * input - client to report to
405 * side effects - client is given list of exempt blocks
408 stats_exempt(struct Client
*source_p
)
410 char *name
, *host
, *pass
, *user
, *classname
;
411 struct AddressRec
*arec
;
412 struct ConfItem
*aconf
;
415 if(ConfigFileEntry
.stats_e_disabled
)
417 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
418 form_str (ERR_NOPRIVILEGES
));
422 for (i
= 0; i
< ATABLE_SIZE
; i
++)
424 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
426 if(arec
->type
== CONF_EXEMPTDLINE
)
429 get_printable_conf (aconf
, &name
, &host
, &pass
,
430 &user
, &port
, &classname
);
432 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
433 form_str(RPL_STATSDLINE
),
434 'e', host
, pass
, "", "");
441 stats_events (struct Client
*source_p
)
443 show_events (source_p
);
447 stats_hubleaf(struct Client
*source_p
)
449 struct remote_conf
*hub_p
;
452 if((ConfigFileEntry
.stats_h_oper_only
||
453 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
454 !IsOperRouting(source_p
))
456 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
457 form_str (ERR_NOPRIVILEGES
));
461 DLINK_FOREACH(ptr
, hubleaf_conf_list
.head
)
465 if(hub_p
->flags
& CONF_HUB
)
466 sendto_one_numeric(source_p
, RPL_STATSHLINE
,
467 form_str(RPL_STATSHLINE
),
468 hub_p
->host
, hub_p
->server
);
470 sendto_one_numeric(source_p
, RPL_STATSLLINE
,
471 form_str(RPL_STATSLLINE
),
472 hub_p
->host
, hub_p
->server
);
478 stats_auth (struct Client
*source_p
)
480 /* Oper only, if unopered, return ERR_NOPRIVS */
481 if((ConfigFileEntry
.stats_i_oper_only
== 2) && !IsOper (source_p
))
482 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
483 form_str (ERR_NOPRIVILEGES
));
485 /* If unopered, Only return matching auth blocks */
486 else if((ConfigFileEntry
.stats_i_oper_only
== 1) && !IsOper (source_p
))
488 struct ConfItem
*aconf
;
489 char *name
, *host
, *pass
, *user
, *classname
;
492 if(MyConnect (source_p
))
493 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
494 (struct sockaddr
*)&source_p
->localClient
->ip
,
496 source_p
->localClient
->ip
.ss_family
,
499 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_CLIENT
,
500 0, source_p
->username
);
505 get_printable_conf (aconf
, &name
, &host
, &pass
, &user
, &port
, &classname
);
507 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
508 name
, show_iline_prefix(source_p
, aconf
, user
),
509 host
, port
, classname
);
512 /* Theyre opered, or allowed to see all auth blocks */
514 report_auth (source_p
);
519 stats_tklines(struct Client
*source_p
)
521 /* Oper only, if unopered, return ERR_NOPRIVS */
522 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
523 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
524 form_str (ERR_NOPRIVILEGES
));
526 /* If unopered, Only return matching klines */
527 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
529 struct ConfItem
*aconf
;
530 char *host
, *pass
, *user
, *oper_reason
;
532 if(MyConnect (source_p
))
533 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
534 (struct sockaddr
*)&source_p
->localClient
->ip
,
536 source_p
->localClient
->ip
.ss_family
,
539 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
540 0, source_p
->username
);
545 /* dont report a permanent kline as a tkline */
546 if((aconf
->flags
& CONF_FLAGS_TEMPORARY
) == 0)
549 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
551 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
552 form_str(RPL_STATSKLINE
), 'k',
553 user
, pass
, oper_reason
? "|" : "",
554 oper_reason
? oper_reason
: "");
556 /* Theyre opered, or allowed to see all klines */
559 struct ConfItem
*aconf
;
562 char *user
, *host
, *pass
, *oper_reason
;
564 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
566 DLINK_FOREACH(ptr
, temp_klines
[i
].head
)
570 get_printable_kline(source_p
, aconf
, &host
, &pass
,
571 &user
, &oper_reason
);
573 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
574 form_str(RPL_STATSKLINE
),
575 'k', host
, user
, pass
,
576 oper_reason
? "|" : "",
577 oper_reason
? oper_reason
: "");
584 stats_klines(struct Client
*source_p
)
586 /* Oper only, if unopered, return ERR_NOPRIVS */
587 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
588 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
589 form_str (ERR_NOPRIVILEGES
));
591 /* If unopered, Only return matching klines */
592 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
594 struct ConfItem
*aconf
;
595 char *host
, *pass
, *user
, *oper_reason
;
597 /* search for a kline */
598 if(MyConnect (source_p
))
599 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
600 (struct sockaddr
*)&source_p
->localClient
->ip
,
602 source_p
->localClient
->ip
.ss_family
,
605 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
606 0, source_p
->username
);
611 /* dont report a tkline as a kline */
612 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
615 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
617 sendto_one_numeric(source_p
, RPL_STATSKLINE
, form_str(RPL_STATSKLINE
),
618 'K', host
, user
, pass
, oper_reason
? "|" : "",
619 oper_reason
? oper_reason
: "");
621 /* Theyre opered, or allowed to see all klines */
623 report_Klines (source_p
);
627 stats_messages(struct Client
*source_p
)
629 report_messages(source_p
);
633 stats_dnsbl(struct Client
*source_p
)
636 struct Blacklist
*blptr
;
638 DLINK_FOREACH(ptr
, blacklist_list
.head
)
642 /* use RPL_STATSDEBUG for now -- jilles */
643 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "n :%d %s %s (%d)",
646 blptr
->status
& CONF_ILLEGAL
? "disabled" : "active",
652 stats_oper(struct Client
*source_p
)
654 struct oper_conf
*oper_p
;
657 if(!IsOperStaffer(source_p
) && ConfigFileEntry
.stats_o_oper_only
)
659 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
660 form_str (ERR_NOPRIVILEGES
));
664 DLINK_FOREACH(ptr
, oper_conf_list
.head
)
668 sendto_one_numeric(source_p
, RPL_STATSOLINE
,
669 form_str(RPL_STATSOLINE
),
670 oper_p
->username
, oper_p
->host
, oper_p
->name
,
671 IsOperStaffer(source_p
) ? get_oper_privs(oper_p
->flags
) : "0", "-1");
678 * input - client pointer
680 * side effects - client is shown a list of active opers
683 stats_operedup (struct Client
*source_p
)
685 struct Client
*target_p
;
686 dlink_node
*oper_ptr
;
687 unsigned int count
= 0;
689 DLINK_FOREACH (oper_ptr
, oper_list
.head
)
691 target_p
= oper_ptr
->data
;
693 if(!IsHelper(target_p
))
696 if(target_p
->user
->away
)
701 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
703 target_p
->name
, target_p
->username
,
707 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
708 "p :%u staff members", count
);
712 stats_ports (struct Client
*source_p
)
714 if(!IsOper (source_p
) && ConfigFileEntry
.stats_P_oper_only
)
715 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
716 form_str (ERR_NOPRIVILEGES
));
718 show_ports (source_p
);
722 stats_tresv(struct Client
*source_p
)
724 struct ConfItem
*aconf
;
728 DLINK_FOREACH(ptr
, resv_conf_list
.head
)
732 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
733 form_str(RPL_STATSQLINE
),
734 'q', aconf
->port
, aconf
->name
, aconf
->passwd
);
737 HASH_WALK(i
, R_MAX
, ptr
, resvTable
)
741 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
742 form_str(RPL_STATSQLINE
),
743 'q', aconf
->port
, aconf
->name
, aconf
->passwd
);
750 stats_resv(struct Client
*source_p
)
752 struct ConfItem
*aconf
;
756 DLINK_FOREACH(ptr
, resv_conf_list
.head
)
760 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
761 form_str(RPL_STATSQLINE
),
762 'Q', aconf
->port
, aconf
->name
, aconf
->passwd
);
765 HASH_WALK(i
, R_MAX
, ptr
, resvTable
)
769 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
770 form_str(RPL_STATSQLINE
),
771 'Q', aconf
->port
, aconf
->name
, aconf
->passwd
);
777 stats_usage (struct Client
*source_p
)
792 if(getrusage(RUSAGE_SELF
, &rus
) == -1)
794 sendto_one_notice(source_p
, ":Getruseage error: %s.",
798 secs
= rus
.ru_utime
.tv_sec
+ rus
.ru_stime
.tv_sec
;
802 rup
= (CurrentTime
- startup_time
) * hzz
;
806 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
807 "R :CPU Secs %d:%d User %d:%d System %d:%d",
808 (int) (secs
/ 60), (int) (secs
% 60),
809 (int) (rus
.ru_utime
.tv_sec
/ 60),
810 (int) (rus
.ru_utime
.tv_sec
% 60),
811 (int) (rus
.ru_stime
.tv_sec
/ 60),
812 (int) (rus
.ru_stime
.tv_sec
% 60));
813 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
814 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
815 rus
.ru_maxrss
, (rus
.ru_ixrss
/ rup
),
816 (rus
.ru_idrss
/ rup
), (rus
.ru_isrss
/ rup
));
817 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
818 "R :Swaps %d Reclaims %d Faults %d",
819 (int) rus
.ru_nswap
, (int) rus
.ru_minflt
, (int) rus
.ru_majflt
);
820 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
821 "R :Block in %d out %d",
822 (int) rus
.ru_inblock
, (int) rus
.ru_oublock
);
823 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
824 "R :Msg Rcv %d Send %d",
825 (int) rus
.ru_msgrcv
, (int) rus
.ru_msgsnd
);
826 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
827 "R :Signals %d Context Vol. %d Invol %d",
828 (int) rus
.ru_nsignals
, (int) rus
.ru_nvcsw
,
829 (int) rus
.ru_nivcsw
);
833 stats_tstats (struct Client
*source_p
)
839 stats_uptime (struct Client
*source_p
)
843 now
= CurrentTime
- startup_time
;
844 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
845 form_str (RPL_STATSUPTIME
),
846 now
/ 86400, (now
/ 3600) % 24,
847 (now
/ 60) % 60, now
% 60);
848 sendto_one_numeric(source_p
, RPL_STATSCONN
,
849 form_str (RPL_STATSCONN
),
850 MaxConnectionCount
, MaxClientCount
,
851 Count
.totalrestartcount
);
859 static struct shared_flags shared_flagtable
[] =
861 { SHARED_PKLINE
, 'K' },
862 { SHARED_TKLINE
, 'k' },
863 { SHARED_UNKLINE
, 'U' },
864 { SHARED_PXLINE
, 'X' },
865 { SHARED_TXLINE
, 'x' },
866 { SHARED_UNXLINE
, 'Y' },
867 { SHARED_PRESV
, 'Q' },
868 { SHARED_TRESV
, 'q' },
869 { SHARED_UNRESV
, 'R' },
870 { SHARED_PDLINE
, 'D' },
871 { SHARED_TDLINE
, 'd' },
872 { SHARED_UNDLINE
, 'E' },
873 { SHARED_REHASH
, 'H' },
879 stats_shared (struct Client
*source_p
)
881 struct remote_conf
*shared_p
;
887 DLINK_FOREACH(ptr
, shared_conf_list
.head
)
889 shared_p
= ptr
->data
;
895 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
897 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
898 *p
++ = shared_flagtable
[i
].letter
;
903 sendto_one_numeric(source_p
, RPL_STATSULINE
,
904 form_str(RPL_STATSULINE
),
905 shared_p
->server
, shared_p
->username
,
906 shared_p
->host
, buf
);
909 DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
911 shared_p
= ptr
->data
;
917 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
919 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
920 *p
++ = shared_flagtable
[i
].letter
;
925 sendto_one_numeric(source_p
, RPL_STATSULINE
,
926 form_str(RPL_STATSULINE
),
927 shared_p
->server
, "*", "*", buf
);
933 * input - client pointer
935 * side effects - client is shown lists of who connected servers
938 stats_servers (struct Client
*source_p
)
940 struct Client
*target_p
;
943 int days
, hours
, minutes
;
946 if(ConfigServerHide
.flatten_links
&& !IsOperRouting(source_p
) &&
947 !IsExemptShide(source_p
))
949 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
950 form_str (ERR_NOPRIVILEGES
));
954 DLINK_FOREACH (ptr
, serv_list
.head
)
956 target_p
= ptr
->data
;
959 seconds
= CurrentTime
- target_p
->localClient
->firsttime
;
961 days
= (int) (seconds
/ 86400);
963 hours
= (int) (seconds
/ 3600);
965 minutes
= (int) (seconds
/ 60);
968 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
969 "V :%s (%s!*@*) Idle: %d SendQ: %d "
970 "Connected: %d day%s, %d:%02d:%02d",
972 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
973 (int) (CurrentTime
- target_p
->localClient
->lasttime
),
974 (int) linebuf_len (&target_p
->localClient
->buf_sendq
),
975 days
, (days
== 1) ? "" : "s", hours
, minutes
,
979 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
980 "V :%d Server(s)", j
);
984 stats_tgecos(struct Client
*source_p
)
986 struct ConfItem
*aconf
;
989 DLINK_FOREACH(ptr
, xline_conf_list
.head
)
994 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
995 form_str(RPL_STATSXLINE
),
996 'x', aconf
->port
, aconf
->name
,
1002 stats_gecos(struct Client
*source_p
)
1004 struct ConfItem
*aconf
;
1007 DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1012 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1013 form_str(RPL_STATSXLINE
),
1014 'X', aconf
->port
, aconf
->name
,
1020 stats_class(struct Client
*source_p
)
1022 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOperStaffer(source_p
))
1023 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1024 form_str (ERR_NOPRIVILEGES
));
1026 report_classes(source_p
);
1030 stats_memory (struct Client
*source_p
)
1032 count_memory (source_p
);
1036 stats_ziplinks (struct Client
*source_p
)
1039 struct Client
*target_p
;
1042 DLINK_FOREACH (ptr
, serv_list
.head
)
1044 target_p
= ptr
->data
;
1045 if(IsCapable (target_p
, CAP_ZIP
))
1047 /* we use memcpy(3) and a local copy of the structure to
1048 * work around a register use bug on GCC on the SPARC.
1049 * -jmallett, 04/27/2002
1051 struct ZipStats zipstats
;
1052 memcpy (&zipstats
, &target_p
->localClient
->zipstats
,
1053 sizeof (struct ZipStats
));
1054 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1055 "Z :ZipLinks stats for %s send[%.2f%% compression "
1056 "(%lu kB data/%lu kB wire)] recv[%.2f%% compression "
1057 "(%lu kB data/%lu kB wire)]",
1059 zipstats
.out_ratio
, zipstats
.outK
, zipstats
.outK_wire
,
1060 zipstats
.in_ratio
, zipstats
.inK
, zipstats
.inK_wire
);
1065 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1066 "Z :%u ziplink(s)", sent_data
);
1070 stats_servlinks (struct Client
*source_p
)
1072 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1073 long uptime
, sendK
, receiveK
;
1074 struct Client
*target_p
;
1078 if(ConfigServerHide
.flatten_links
&& !IsOper (source_p
) &&
1079 !IsExemptShide(source_p
))
1081 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1082 form_str (ERR_NOPRIVILEGES
));
1086 sendK
= receiveK
= 0;
1088 DLINK_FOREACH (ptr
, serv_list
.head
)
1090 target_p
= ptr
->data
;
1093 sendK
+= target_p
->localClient
->sendK
;
1094 receiveK
+= target_p
->localClient
->receiveK
;
1096 sendto_one(source_p
, Sformat
,
1097 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1098 get_server_name(target_p
, SHOW_IP
),
1099 (int) linebuf_len (&target_p
->localClient
->buf_sendq
),
1100 (int) target_p
->localClient
->sendM
,
1101 (int) target_p
->localClient
->sendK
,
1102 (int) target_p
->localClient
->receiveM
,
1103 (int) target_p
->localClient
->receiveK
,
1104 CurrentTime
- target_p
->localClient
->firsttime
,
1105 (CurrentTime
> target_p
->localClient
->lasttime
) ?
1106 (CurrentTime
- target_p
->localClient
->lasttime
) : 0,
1107 IsOper (source_p
) ? show_capabilities (target_p
) : "TS");
1110 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1111 "? :%u total server(s)", j
);
1113 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1114 "? :Sent total : %7.2f %s",
1115 _GMKv (sendK
), _GMKs (sendK
));
1116 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1117 "? :Recv total : %7.2f %s",
1118 _GMKv (receiveK
), _GMKs (receiveK
));
1120 uptime
= (CurrentTime
- startup_time
);
1122 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1123 "? :Server send: %7.2f %s (%4.1f K/s)",
1124 _GMKv (me
.localClient
->sendK
),
1125 _GMKs (me
.localClient
->sendK
),
1126 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1127 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1128 "? :Server recv: %7.2f %s (%4.1f K/s)",
1129 _GMKv (me
.localClient
->receiveK
),
1130 _GMKs (me
.localClient
->receiveK
),
1131 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1135 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1140 char statchar
= parv
[1][0];
1142 /* this is def targeted at us somehow.. */
1143 if(parc
> 2 && !EmptyString(parv
[2]))
1145 /* directed at us generically? */
1146 if(match(parv
[2], me
.name
) ||
1147 (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1155 wilds
= strchr(name
, '*') || strchr(name
, '?');
1158 /* must be directed at a specific person thats not us */
1159 if(!doall
&& !wilds
)
1161 struct Client
*target_p
;
1163 if(MyClient(source_p
))
1164 target_p
= find_named_person(name
);
1166 target_p
= find_person(name
);
1168 if(target_p
!= NULL
)
1170 stats_spy(source_p
, statchar
, target_p
->name
);
1171 stats_l_client(source_p
, target_p
, statchar
);
1174 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1175 form_str(ERR_NOSUCHSERVER
),
1187 stats_spy(source_p
, statchar
, name
);
1191 /* local opers get everyone */
1192 if(MyOper(source_p
))
1194 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
);
1195 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
);
1199 /* they still need themselves if theyre local.. */
1200 if(MyClient(source_p
))
1201 stats_l_client(source_p
, source_p
, statchar
);
1203 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
);
1206 if (!ConfigServerHide
.flatten_links
|| IsOperRouting(source_p
) ||
1207 IsExemptShide(source_p
))
1208 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
);
1213 /* ok, at this point theyre looking for a specific client whos on
1214 * our server.. but it contains a wildcard. --fl
1216 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
);
1223 stats_l_list(struct Client
*source_p
, const char *name
, int doall
, int wilds
,
1224 dlink_list
* list
, char statchar
)
1227 struct Client
*target_p
;
1229 /* send information about connections which match. note, we
1230 * dont need tests for IsInvisible(), because non-opers will
1231 * never get here for normal clients --fl
1233 DLINK_FOREACH(ptr
, list
->head
)
1235 target_p
= ptr
->data
;
1237 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1240 stats_l_client(source_p
, target_p
, statchar
);
1245 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1248 if(IsAnyServer(target_p
))
1250 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1251 get_server_name(target_p
, SHOW_IP
),
1252 (int) linebuf_len(&target_p
->localClient
->buf_sendq
),
1253 (int) target_p
->localClient
->sendM
,
1254 (int) target_p
->localClient
->sendK
,
1255 (int) target_p
->localClient
->receiveM
,
1256 (int) target_p
->localClient
->receiveK
,
1257 CurrentTime
- target_p
->localClient
->firsttime
,
1258 (CurrentTime
> target_p
->localClient
->lasttime
) ?
1259 (CurrentTime
- target_p
->localClient
->lasttime
) : 0,
1260 IsOperStaffer(source_p
) ? show_capabilities(target_p
) : "-");
1265 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1266 show_ip(source_p
, target_p
) ?
1267 (IsUpper(statchar
) ?
1268 get_client_name(target_p
, SHOW_IP
) :
1269 get_client_name(target_p
, HIDE_IP
)) :
1270 get_client_name(target_p
, MASK_IP
),
1271 (int) linebuf_len(&target_p
->localClient
->buf_sendq
),
1272 (int) target_p
->localClient
->sendM
,
1273 (int) target_p
->localClient
->sendK
,
1274 (int) target_p
->localClient
->receiveM
,
1275 (int) target_p
->localClient
->receiveK
,
1276 CurrentTime
- target_p
->localClient
->firsttime
,
1277 (CurrentTime
> target_p
->localClient
->lasttime
) ?
1278 (CurrentTime
- target_p
->localClient
->lasttime
) : 0,
1286 * inputs - pointer to client doing the /stats
1287 * - char letter they are doing /stats on
1290 * This little helper function reports to opers if configured.
1291 * personally, I don't see why opers need to see stats requests
1292 * at all. They are just "noise" to an oper, and users can't do
1293 * any damage with stats requests now anyway. So, why show them?
1297 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1301 data
.client
= source_p
;
1303 data
.arg2
= (int) statchar
;
1305 call_hook(doing_stats_hook
, &data
);