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 */
42 #include "s_stats.h" /* tstats */
43 #include "s_user.h" /* show_opers */
44 #include "blacklist.h" /* dnsbl stuff */
48 #include "s_newconf.h"
52 static int m_stats (struct Client
*, struct Client
*, int, const char **);
54 struct Message stats_msgtab
= {
55 "STATS", 0, 0, 0, MFLG_SLOW
,
56 {mg_unreg
, {m_stats
, 2}, {m_stats
, 3}, mg_ignore
, mg_ignore
, {m_stats
, 2}}
60 int doing_stats_p_hook
;
62 mapi_clist_av1 stats_clist
[] = { &stats_msgtab
, NULL
};
63 mapi_hlist_av1 stats_hlist
[] = {
64 { "doing_stats", &doing_stats_hook
},
65 { "doing_stats_p", &doing_stats_p_hook
},
69 DECLARE_MODULE_AV1(stats
, NULL
, NULL
, stats_clist
, stats_hlist
, NULL
, "$Revision: 1608 $");
71 const char *Lformat
= "%s %u %u %u %u %u :%u %u %s";
73 static void stats_l_list(struct Client
*s
, const char *, int, int, rb_dlink_list
*, char);
74 static void stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
77 static void stats_spy(struct Client
*, char, const char *);
78 static void stats_p_spy(struct Client
*);
80 /* Heres our struct for the stats table */
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_glines(struct Client
*);
98 static void stats_pending_glines(struct Client
*);
99 static void stats_hubleaf(struct Client
*);
100 static void stats_auth(struct Client
*);
101 static void stats_tklines(struct Client
*);
102 static void stats_klines(struct Client
*);
103 static void stats_messages(struct Client
*);
104 static void stats_dnsbl(struct Client
*);
105 static void stats_oper(struct Client
*);
106 static void stats_operedup(struct Client
*);
107 static void stats_ports(struct Client
*);
108 static void stats_tresv(struct Client
*);
109 static void stats_resv(struct Client
*);
110 static void stats_usage(struct Client
*);
111 static void stats_tstats(struct Client
*);
112 static void stats_uptime(struct Client
*);
113 static void stats_shared(struct Client
*);
114 static void stats_servers(struct Client
*);
115 static void stats_tgecos(struct Client
*);
116 static void stats_gecos(struct Client
*);
117 static void stats_class(struct Client
*);
118 static void stats_memory(struct Client
*);
119 static void stats_servlinks(struct Client
*);
120 static void stats_ltrace(struct Client
*, int, const char **);
121 static void stats_ziplinks(struct Client
*);
122 static void stats_comm(struct Client
*);
123 /* This table contains the possible stats items, in order:
124 * stats letter, function to call, operonly? adminonly?
125 * case only matters in the stats letter column.. -- fl_
127 static struct StatsStruct stats_cmd_table
[] = {
128 /* letter function need_oper need_admin */
129 {'a', stats_dns_servers
, 1, 1, },
130 {'A', stats_dns_servers
, 1, 1, },
131 {'b', stats_delay
, 1, 1, },
132 {'B', stats_hash
, 1, 1, },
133 {'c', stats_connect
, 0, 0, },
134 {'C', stats_connect
, 0, 0, },
135 {'d', stats_tdeny
, 1, 0, },
136 {'D', stats_deny
, 1, 0, },
137 {'e', stats_exempt
, 1, 0, },
138 {'E', stats_events
, 1, 1, },
139 {'f', stats_comm
, 1, 1, },
140 {'F', stats_comm
, 1, 1, },
141 {'g', stats_pending_glines
, 1, 0, },
142 {'G', stats_glines
, 1, 0, },
143 {'h', stats_hubleaf
, 0, 0, },
144 {'H', stats_hubleaf
, 0, 0, },
145 {'i', stats_auth
, 0, 0, },
146 {'I', stats_auth
, 0, 0, },
147 {'k', stats_tklines
, 0, 0, },
148 {'K', stats_klines
, 0, 0, },
149 {'l', stats_ltrace
, 0, 0, },
150 {'L', stats_ltrace
, 0, 0, },
151 {'m', stats_messages
, 0, 0, },
152 {'M', stats_messages
, 0, 0, },
153 {'n', stats_dnsbl
, 0, 0, },
154 {'o', stats_oper
, 0, 0, },
155 {'O', stats_oper
, 0, 0, },
156 {'p', stats_operedup
, 0, 0, },
157 {'P', stats_ports
, 0, 0, },
158 {'q', stats_tresv
, 1, 0, },
159 {'Q', stats_resv
, 1, 0, },
160 {'r', stats_usage
, 1, 0, },
161 {'R', stats_usage
, 1, 0, },
162 {'t', stats_tstats
, 1, 0, },
163 {'T', stats_tstats
, 1, 0, },
164 {'u', stats_uptime
, 0, 0, },
165 {'U', stats_shared
, 1, 0, },
166 {'v', stats_servers
, 0, 0, },
167 {'V', stats_servers
, 0, 0, },
168 {'x', stats_tgecos
, 1, 0, },
169 {'X', stats_gecos
, 1, 0, },
170 {'y', stats_class
, 0, 0, },
171 {'Y', stats_class
, 0, 0, },
172 {'z', stats_memory
, 1, 0, },
173 {'Z', stats_ziplinks
, 1, 0, },
174 {'?', stats_servlinks
, 0, 0, },
175 {(char) 0, (void (*)()) 0, 0, 0, }
180 * parv[0] = sender prefix
181 * parv[1] = stat letter/command
182 * parv[2] = (if present) server/mask in stats L, or target
184 * This will search the tables for the appropriate stats letter,
185 * if found execute it.
188 m_stats(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
190 static time_t last_used
= 0;
194 statchar
= parv
[1][0];
196 if(MyClient(source_p
) && !IsOper(source_p
))
198 /* Check the user is actually allowed to do /stats, and isnt flooding */
199 if((last_used
+ ConfigFileEntry
.pace_wait
) > rb_current_time())
201 /* safe enough to give this on a local connect only */
202 sendto_one(source_p
, form_str(RPL_LOAD2HI
),
203 me
.name
, source_p
->name
, "STATS");
204 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
205 form_str(RPL_ENDOFSTATS
), statchar
);
209 last_used
= rb_current_time();
212 if(hunt_server (client_p
, source_p
, ":%s STATS %s :%s", 2, parc
, parv
) != HUNTED_ISME
)
215 if((statchar
!= 'L') && (statchar
!= 'l'))
216 stats_spy(source_p
, statchar
, NULL
);
218 for (i
= 0; stats_cmd_table
[i
].handler
; i
++)
220 if(stats_cmd_table
[i
].letter
== statchar
)
222 /* The stats table says what privs are needed, so check --fl_ */
223 /* Called for remote clients and for local opers, so check need_admin
226 if(stats_cmd_table
[i
].need_oper
&& !IsOper(source_p
))
228 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
229 form_str (ERR_NOPRIVILEGES
));
232 if(stats_cmd_table
[i
].need_admin
&& !IsOperAdmin(source_p
))
234 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
235 me
.name
, source_p
->name
, "admin");
239 /* Blah, stats L needs the parameters, none of the others do.. */
240 if(statchar
== 'L' || statchar
== 'l')
241 stats_cmd_table
[i
].handler (source_p
, parc
, parv
);
243 stats_cmd_table
[i
].handler (source_p
);
247 /* Send the end of stats notice, and the stats_spy */
248 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
249 form_str(RPL_ENDOFSTATS
), statchar
);
255 stats_dns_servers (struct Client
*source_p
)
257 report_dns_servers (source_p
);
261 stats_delay(struct Client
*source_p
)
264 struct DictionaryIter iter
;
266 DICTIONARY_FOREACH(nd
, &iter
, nd_dict
)
268 sendto_one_notice(source_p
, ":Delaying: %s for %ld",
269 nd
->name
, (long) nd
->expire
);
274 stats_hash(struct Client
*source_p
)
276 hash_stats(source_p
);
280 stats_connect(struct Client
*source_p
)
283 struct server_conf
*server_p
;
287 if((ConfigFileEntry
.stats_c_oper_only
||
288 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
291 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
292 form_str(ERR_NOPRIVILEGES
));
296 RB_DLINK_FOREACH(ptr
, server_conf_list
.head
)
298 server_p
= ptr
->data
;
300 if(ServerConfIllegal(server_p
))
308 if(ServerConfAutoconn(server_p
))
310 if(ServerConfTb(server_p
))
312 if(ServerConfCompressed(server_p
))
321 sendto_one_numeric(source_p
, RPL_STATSCLINE
,
322 form_str(RPL_STATSCLINE
),
323 #ifndef HIDE_SERVERS_IPS
329 server_p
->port
, server_p
->class_name
);
335 * input - client to report to
337 * side effects - client is given temp dline list.
340 stats_tdeny (struct Client
*source_p
)
342 char *host
, *pass
, *user
, *oper_reason
;
343 struct AddressRec
*arec
;
344 struct ConfItem
*aconf
;
347 for (i
= 0; i
< ATABLE_SIZE
; i
++)
349 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
351 if(arec
->type
== CONF_DLINE
)
355 if(!(aconf
->flags
& CONF_FLAGS_TEMPORARY
))
358 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
360 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
361 form_str (RPL_STATSDLINE
),
363 oper_reason
? "|" : "",
364 oper_reason
? oper_reason
: "");
372 * input - client to report to
374 * side effects - client is given dline list.
377 stats_deny (struct Client
*source_p
)
379 char *host
, *pass
, *user
, *oper_reason
;
380 struct AddressRec
*arec
;
381 struct ConfItem
*aconf
;
384 for (i
= 0; i
< ATABLE_SIZE
; i
++)
386 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
388 if(arec
->type
== CONF_DLINE
)
392 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
395 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
397 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
398 form_str (RPL_STATSDLINE
),
400 oper_reason
? "|" : "",
401 oper_reason
? oper_reason
: "");
410 * input - client to report to
412 * side effects - client is given list of exempt blocks
415 stats_exempt(struct Client
*source_p
)
417 char *name
, *host
, *pass
, *user
, *classname
;
418 struct AddressRec
*arec
;
419 struct ConfItem
*aconf
;
422 if(ConfigFileEntry
.stats_e_disabled
)
424 sendto_one_numeric(source_p
, ERR_DISABLED
,
425 form_str(ERR_DISABLED
), "STATS e");
429 for (i
= 0; i
< ATABLE_SIZE
; i
++)
431 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
433 if(arec
->type
== CONF_EXEMPTDLINE
)
436 get_printable_conf (aconf
, &name
, &host
, &pass
,
437 &user
, &port
, &classname
);
439 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
440 form_str(RPL_STATSDLINE
),
441 'e', host
, pass
, "", "");
448 stats_events_cb(char *str
, void *ptr
)
450 sendto_one_numeric(ptr
, RPL_STATSDEBUG
, "E :%s", str
);
454 stats_events (struct Client
*source_p
)
456 rb_dump_events(stats_events_cb
, source_p
);
457 send_pop_queue(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 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
958 "T :accepts %u refused %u",
959 sp
.is_ac
, sp
.is_ref
);
960 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
961 "T :rejected %u delaying %lu",
962 sp
.is_rej
, delay_exit_length());
963 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
964 "T :nicks being delayed %lu", get_nd_count());
965 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
966 "T :unknown commands %u prefixes %u",
967 sp
.is_unco
, sp
.is_unpf
);
968 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
969 "T :nick collisions %u saves %u unknown closes %u",
970 sp
.is_kill
, sp
.is_save
, sp
.is_ni
);
971 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
972 "T :wrong direction %u empty %u",
973 sp
.is_wrdi
, sp
.is_empt
);
974 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
975 "T :numerics seen %u",
977 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
978 "T :auth successes %u fails %u",
979 sp
.is_asuc
, sp
.is_abad
);
980 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "T :Client Server");
981 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
982 "T :connected %u %u",
984 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
985 "T :bytes sent %lluK %lluK",
988 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
989 "T :bytes recv %lluK %lluK",
992 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
993 "T :time connected %lu %lu",
994 sp
.is_cti
, sp
.is_sti
);
998 stats_uptime (struct Client
*source_p
)
1002 now
= rb_current_time() - startup_time
;
1003 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
1004 form_str (RPL_STATSUPTIME
),
1005 now
/ 86400, (now
/ 3600) % 24,
1006 (now
/ 60) % 60, now
% 60);
1007 sendto_one_numeric(source_p
, RPL_STATSCONN
,
1008 form_str (RPL_STATSCONN
),
1009 MaxConnectionCount
, MaxClientCount
,
1010 Count
.totalrestartcount
);
1018 static struct shared_flags shared_flagtable
[] =
1020 { SHARED_PKLINE
, 'K' },
1021 { SHARED_TKLINE
, 'k' },
1022 { SHARED_UNKLINE
, 'U' },
1023 { SHARED_PXLINE
, 'X' },
1024 { SHARED_TXLINE
, 'x' },
1025 { SHARED_UNXLINE
, 'Y' },
1026 { SHARED_PRESV
, 'Q' },
1027 { SHARED_TRESV
, 'q' },
1028 { SHARED_UNRESV
, 'R' },
1029 { SHARED_LOCOPS
, 'L' },
1030 { SHARED_REHASH
, 'H' },
1036 stats_shared (struct Client
*source_p
)
1038 struct remote_conf
*shared_p
;
1044 RB_DLINK_FOREACH(ptr
, shared_conf_list
.head
)
1046 shared_p
= ptr
->data
;
1052 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1054 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1055 *p
++ = shared_flagtable
[i
].letter
;
1060 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1061 form_str(RPL_STATSULINE
),
1062 shared_p
->server
, shared_p
->username
,
1063 shared_p
->host
, buf
);
1066 RB_DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
1068 shared_p
= ptr
->data
;
1074 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1076 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1077 *p
++ = shared_flagtable
[i
].letter
;
1082 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1083 form_str(RPL_STATSULINE
),
1084 shared_p
->server
, "*", "*", buf
);
1090 * input - client pointer
1092 * side effects - client is shown lists of who connected servers
1095 stats_servers (struct Client
*source_p
)
1097 struct Client
*target_p
;
1100 int days
, hours
, minutes
;
1103 if(ConfigServerHide
.flatten_links
&& !IsOper(source_p
) &&
1104 !IsExemptShide(source_p
))
1106 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1107 form_str (ERR_NOPRIVILEGES
));
1111 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1113 target_p
= ptr
->data
;
1116 seconds
= rb_current_time() - target_p
->localClient
->firsttime
;
1118 days
= (int) (seconds
/ 86400);
1120 hours
= (int) (seconds
/ 3600);
1122 minutes
= (int) (seconds
/ 60);
1125 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1126 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1127 "Connected: %d day%s, %d:%02d:%02d",
1129 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
1130 (int) (rb_current_time() - target_p
->localClient
->lasttime
),
1131 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1132 days
, (days
== 1) ? "" : "s", hours
, minutes
,
1136 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1137 "V :%d Server(s)", j
);
1141 stats_tgecos(struct Client
*source_p
)
1143 struct ConfItem
*aconf
;
1146 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1151 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1152 form_str(RPL_STATSXLINE
),
1153 'x', aconf
->port
, aconf
->name
,
1159 stats_gecos(struct Client
*source_p
)
1161 struct ConfItem
*aconf
;
1164 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1169 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1170 form_str(RPL_STATSXLINE
),
1171 'X', aconf
->port
, aconf
->name
,
1177 stats_class(struct Client
*source_p
)
1179 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOper(source_p
))
1180 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1181 form_str (ERR_NOPRIVILEGES
));
1183 report_classes(source_p
);
1187 stats_memory (struct Client
*source_p
)
1189 count_memory (source_p
);
1193 stats_ziplinks (struct Client
*source_p
)
1196 struct Client
*target_p
;
1199 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1201 target_p
= ptr
->data
;
1202 if(IsCapable (target_p
, CAP_ZIP
))
1204 /* we use memcpy(3) and a local copy of the structure to
1205 * work around a register use bug on GCC on the SPARC.
1206 * -jmallett, 04/27/2002
1208 struct ZipStats zipstats
;
1209 memcpy (&zipstats
, &target_p
->localClient
->zipstats
,
1210 sizeof (struct ZipStats
));
1211 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1212 "Z :ZipLinks stats for %s send[%.2f%% compression "
1213 "(%lu kB data/%lu kB wire)] recv[%.2f%% compression "
1214 "(%lu kB data/%lu kB wire)]",
1216 zipstats
.out_ratio
, zipstats
.outK
, zipstats
.outK_wire
,
1217 zipstats
.in_ratio
, zipstats
.inK
, zipstats
.inK_wire
);
1222 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1223 "Z :%u ziplink(s)", sent_data
);
1227 stats_servlinks (struct Client
*source_p
)
1229 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1230 long uptime
, sendK
, receiveK
;
1231 struct Client
*target_p
;
1235 if(ConfigServerHide
.flatten_links
&& !IsOper (source_p
) &&
1236 !IsExemptShide(source_p
))
1238 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1239 form_str (ERR_NOPRIVILEGES
));
1243 sendK
= receiveK
= 0;
1245 RB_DLINK_FOREACH (ptr
, serv_list
.head
)
1247 target_p
= ptr
->data
;
1250 sendK
+= target_p
->localClient
->sendK
;
1251 receiveK
+= target_p
->localClient
->receiveK
;
1253 sendto_one(source_p
, Sformat
,
1254 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1255 get_server_name(target_p
, SHOW_IP
),
1256 (int) rb_linebuf_len (&target_p
->localClient
->buf_sendq
),
1257 (int) target_p
->localClient
->sendM
,
1258 (int) target_p
->localClient
->sendK
,
1259 (int) target_p
->localClient
->receiveM
,
1260 (int) target_p
->localClient
->receiveK
,
1261 rb_current_time() - target_p
->localClient
->firsttime
,
1262 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1263 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1264 IsOper (source_p
) ? show_capabilities (target_p
) : "TS");
1267 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1268 "? :%u total server(s)", j
);
1270 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1271 "? :Sent total : %7.2f %s",
1272 _GMKv (sendK
), _GMKs (sendK
));
1273 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1274 "? :Recv total : %7.2f %s",
1275 _GMKv (receiveK
), _GMKs (receiveK
));
1277 uptime
= (rb_current_time() - startup_time
);
1279 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1280 "? :Server send: %7.2f %s (%4.1f K/s)",
1281 _GMKv (me
.localClient
->sendK
),
1282 _GMKs (me
.localClient
->sendK
),
1283 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1284 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1285 "? :Server recv: %7.2f %s (%4.1f K/s)",
1286 _GMKv (me
.localClient
->receiveK
),
1287 _GMKs (me
.localClient
->receiveK
),
1288 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1292 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1297 char statchar
= parv
[1][0];
1299 /* this is def targeted at us somehow.. */
1300 if(parc
> 2 && !EmptyString(parv
[2]))
1302 /* directed at us generically? */
1303 if(match(parv
[2], me
.name
) ||
1304 (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1312 wilds
= strchr(name
, '*') || strchr(name
, '?');
1315 /* must be directed at a specific person thats not us */
1316 if(!doall
&& !wilds
)
1318 struct Client
*target_p
;
1320 if(MyClient(source_p
))
1321 target_p
= find_named_person(name
);
1323 target_p
= find_person(name
);
1325 if(target_p
!= NULL
)
1327 stats_spy(source_p
, statchar
, target_p
->name
);
1328 stats_l_client(source_p
, target_p
, statchar
);
1331 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1332 form_str(ERR_NOSUCHSERVER
),
1344 stats_spy(source_p
, statchar
, name
);
1348 /* local opers get everyone */
1349 if(MyOper(source_p
))
1351 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
);
1352 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
);
1356 /* they still need themselves if theyre local.. */
1357 if(MyClient(source_p
))
1358 stats_l_client(source_p
, source_p
, statchar
);
1360 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
);
1363 if (!ConfigServerHide
.flatten_links
|| IsOper(source_p
) ||
1364 IsExemptShide(source_p
))
1365 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
);
1370 /* ok, at this point theyre looking for a specific client whos on
1371 * our server.. but it contains a wildcard. --fl
1373 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
);
1380 stats_l_list(struct Client
*source_p
, const char *name
, int doall
, int wilds
,
1381 rb_dlink_list
* list
, char statchar
)
1384 struct Client
*target_p
;
1386 /* send information about connections which match. note, we
1387 * dont need tests for IsInvisible(), because non-opers will
1388 * never get here for normal clients --fl
1390 RB_DLINK_FOREACH(ptr
, list
->head
)
1392 target_p
= ptr
->data
;
1394 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1397 stats_l_client(source_p
, target_p
, statchar
);
1402 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1405 if(IsAnyServer(target_p
))
1407 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1408 get_server_name(target_p
, SHOW_IP
),
1409 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1410 (int) target_p
->localClient
->sendM
,
1411 (int) target_p
->localClient
->sendK
,
1412 (int) target_p
->localClient
->receiveM
,
1413 (int) target_p
->localClient
->receiveK
,
1414 rb_current_time() - target_p
->localClient
->firsttime
,
1415 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1416 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1417 IsOper(source_p
) ? show_capabilities(target_p
) : "-");
1422 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1423 show_ip(source_p
, target_p
) ?
1424 (IsUpper(statchar
) ?
1425 get_client_name(target_p
, SHOW_IP
) :
1426 get_client_name(target_p
, HIDE_IP
)) :
1427 get_client_name(target_p
, MASK_IP
),
1428 (int) rb_linebuf_len(&target_p
->localClient
->buf_sendq
),
1429 (int) target_p
->localClient
->sendM
,
1430 (int) target_p
->localClient
->sendK
,
1431 (int) target_p
->localClient
->receiveM
,
1432 (int) target_p
->localClient
->receiveK
,
1433 rb_current_time() - target_p
->localClient
->firsttime
,
1434 (rb_current_time() > target_p
->localClient
->lasttime
) ?
1435 (rb_current_time() - target_p
->localClient
->lasttime
) : 0,
1441 rb_dump_fd_callback(int fd
, const char *desc
, void *data
)
1443 struct Client
*source_p
= data
;
1444 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "F :fd %-3d desc '%s'", fd
, desc
);
1448 stats_comm(struct Client
*source_p
)
1450 rb_dump_fd(rb_dump_fd_callback
, source_p
);
1451 send_pop_queue(source_p
);
1457 * inputs - pointer to client doing the /stats
1458 * - char letter they are doing /stats on
1461 * This little helper function reports to opers if configured.
1462 * personally, I don't see why opers need to see stats requests
1463 * at all. They are just "noise" to an oper, and users can't do
1464 * any damage with stats requests now anyway. So, why show them?
1468 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1472 data
.client
= source_p
;
1474 data
.arg2
= (int) statchar
;
1476 call_hook(doing_stats_hook
, &data
);
1481 * input - pointer to client doing stats
1483 * side effects - call hook doing_stats_p
1486 stats_p_spy (struct Client
*source_p
)
1490 data
.client
= source_p
;
1491 data
.arg1
= data
.arg2
= NULL
;
1493 call_hook(doing_stats_p_hook
, &data
);