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 "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 */
36 #include "msg.h" /* Message */
37 #include "hostmask.h" /* report_mtrie_conf_links */
38 #include "numeric.h" /* ERR_xxx */
39 #include "scache.h" /* list_scache */
40 #include "send.h" /* sendto_one */
41 #include "commio.h" /* highest_fd */
42 #include "s_conf.h" /* ConfItem */
43 #include "s_serv.h" /* hunt_server */
44 #include "s_stats.h" /* tstats */
45 #include "s_user.h" /* show_opers */
46 #include "event.h" /* events */
47 #include "blacklist.h" /* dnsbl stuff */
52 #include "s_newconf.h"
55 static int m_stats (struct Client
*, struct Client
*, int, const char **);
57 struct Message stats_msgtab
= {
58 "STATS", 0, 0, 0, MFLG_SLOW
,
59 {mg_unreg
, {m_stats
, 2}, {m_stats
, 3}, mg_ignore
, mg_ignore
, {m_stats
, 2}}
63 int doing_stats_p_hook
;
65 mapi_clist_av1 stats_clist
[] = { &stats_msgtab
, NULL
};
66 mapi_hlist_av1 stats_hlist
[] = {
67 { "doing_stats", &doing_stats_hook
},
68 { "doing_stats_p", &doing_stats_p_hook
},
72 DECLARE_MODULE_AV1(stats
, NULL
, NULL
, stats_clist
, stats_hlist
, NULL
, "$Revision: 1608 $");
74 const char *Lformat
= "%s %u %u %u %u %u :%u %u %s";
76 static void stats_l_list(struct Client
*s
, const char *, int, int, dlink_list
*, char);
77 static void stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
80 static void stats_spy(struct Client
*, char, const char *);
81 static void stats_p_spy(struct Client
*);
83 /* Heres our struct for the stats table */
92 static void stats_dns_servers (struct Client
*);
93 static void stats_delay(struct Client
*);
94 static void stats_hash(struct Client
*);
95 static void stats_connect(struct Client
*);
96 static void stats_tdeny(struct Client
*);
97 static void stats_deny(struct Client
*);
98 static void stats_exempt(struct Client
*);
99 static void stats_events(struct Client
*);
100 static void stats_glines(struct Client
*);
101 static void stats_pending_glines(struct Client
*);
102 static void stats_hubleaf(struct Client
*);
103 static void stats_auth(struct Client
*);
104 static void stats_tklines(struct Client
*);
105 static void stats_klines(struct Client
*);
106 static void stats_messages(struct Client
*);
107 static void stats_dnsbl(struct Client
*);
108 static void stats_oper(struct Client
*);
109 static void stats_operedup(struct Client
*);
110 static void stats_ports(struct Client
*);
111 static void stats_tresv(struct Client
*);
112 static void stats_resv(struct Client
*);
113 static void stats_usage(struct Client
*);
114 static void stats_tstats(struct Client
*);
115 static void stats_uptime(struct Client
*);
116 static void stats_shared(struct Client
*);
117 static void stats_servers(struct Client
*);
118 static void stats_tgecos(struct Client
*);
119 static void stats_gecos(struct Client
*);
120 static void stats_class(struct Client
*);
121 static void stats_memory(struct Client
*);
122 static void stats_servlinks(struct Client
*);
123 static void stats_ltrace(struct Client
*, int, const char **);
124 static void stats_ziplinks(struct Client
*);
126 /* This table contains the possible stats items, in order:
127 * stats letter, function to call, operonly? adminonly?
128 * case only matters in the stats letter column.. -- fl_
130 static struct StatsStruct stats_cmd_table
[] = {
131 /* letter function need_oper need_admin */
132 {'a', stats_dns_servers
, 1, 1, },
133 {'A', stats_dns_servers
, 1, 1, },
134 {'b', stats_delay
, 1, 1, },
135 {'B', stats_hash
, 1, 1, },
136 {'c', stats_connect
, 0, 0, },
137 {'C', stats_connect
, 0, 0, },
138 {'d', stats_tdeny
, 1, 0, },
139 {'D', stats_deny
, 1, 0, },
140 {'e', stats_exempt
, 1, 0, },
141 {'E', stats_events
, 1, 1, },
142 {'f', comm_dump
, 1, 1, },
143 {'F', comm_dump
, 1, 1, },
144 {'g', stats_pending_glines
, 1, 0, },
145 {'G', stats_glines
, 1, 0, },
146 {'h', stats_hubleaf
, 0, 0, },
147 {'H', stats_hubleaf
, 0, 0, },
148 {'i', stats_auth
, 0, 0, },
149 {'I', stats_auth
, 0, 0, },
150 {'k', stats_tklines
, 0, 0, },
151 {'K', stats_klines
, 0, 0, },
152 {'l', stats_ltrace
, 0, 0, },
153 {'L', stats_ltrace
, 0, 0, },
154 {'m', stats_messages
, 0, 0, },
155 {'M', stats_messages
, 0, 0, },
156 {'n', stats_dnsbl
, 0, 0, },
157 {'o', stats_oper
, 0, 0, },
158 {'O', stats_oper
, 0, 0, },
159 {'p', stats_operedup
, 0, 0, },
160 {'P', stats_ports
, 0, 0, },
161 {'q', stats_tresv
, 1, 0, },
162 {'Q', stats_resv
, 1, 0, },
163 {'r', stats_usage
, 1, 0, },
164 {'R', stats_usage
, 1, 0, },
165 {'t', stats_tstats
, 1, 0, },
166 {'T', stats_tstats
, 1, 0, },
167 {'u', stats_uptime
, 0, 0, },
168 {'U', stats_shared
, 1, 0, },
169 {'v', stats_servers
, 0, 0, },
170 {'V', stats_servers
, 0, 0, },
171 {'x', stats_tgecos
, 1, 0, },
172 {'X', stats_gecos
, 1, 0, },
173 {'y', stats_class
, 0, 0, },
174 {'Y', stats_class
, 0, 0, },
175 {'z', stats_memory
, 1, 0, },
176 {'Z', stats_ziplinks
, 1, 0, },
177 {'?', stats_servlinks
, 0, 0, },
178 {(char) 0, (void (*)()) 0, 0, 0, }
183 * parv[0] = sender prefix
184 * parv[1] = stat letter/command
185 * parv[2] = (if present) server/mask in stats L, or target
187 * This will search the tables for the appropriate stats letter,
188 * if found execute it.
191 m_stats(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
193 static time_t last_used
= 0;
197 statchar
= parv
[1][0];
199 if(MyClient(source_p
) && !IsOper(source_p
))
201 /* Check the user is actually allowed to do /stats, and isnt flooding */
202 if((last_used
+ ConfigFileEntry
.pace_wait
) > CurrentTime
)
204 /* safe enough to give this on a local connect only */
205 sendto_one(source_p
, form_str(RPL_LOAD2HI
),
206 me
.name
, source_p
->name
, "STATS");
207 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
208 form_str(RPL_ENDOFSTATS
), statchar
);
212 last_used
= CurrentTime
;
215 if(hunt_server (client_p
, source_p
, ":%s STATS %s :%s", 2, parc
, parv
) != HUNTED_ISME
)
218 if((statchar
!= 'L') && (statchar
!= 'l'))
219 stats_spy(source_p
, statchar
, NULL
);
221 for (i
= 0; stats_cmd_table
[i
].handler
; i
++)
223 if(stats_cmd_table
[i
].letter
== statchar
)
225 /* The stats table says what privs are needed, so check --fl_ */
226 /* Called for remote clients and for local opers, so check need_admin
229 if(stats_cmd_table
[i
].need_oper
&& !IsOper(source_p
))
231 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
232 form_str (ERR_NOPRIVILEGES
));
235 if(stats_cmd_table
[i
].need_admin
&& !IsOperAdmin(source_p
))
237 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
238 me
.name
, source_p
->name
, "admin");
242 /* Blah, stats L needs the parameters, none of the others do.. */
243 if(statchar
== 'L' || statchar
== 'l')
244 stats_cmd_table
[i
].handler (source_p
, parc
, parv
);
246 stats_cmd_table
[i
].handler (source_p
);
250 /* Send the end of stats notice, and the stats_spy */
251 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
252 form_str(RPL_ENDOFSTATS
), statchar
);
258 stats_dns_servers (struct Client
*source_p
)
260 report_dns_servers (source_p
);
264 stats_delay(struct Client
*source_p
)
267 struct DictionaryIter iter
;
269 DICTIONARY_FOREACH(nd
, &iter
, nd_dict
)
271 sendto_one_notice(source_p
, ":Delaying: %s for %ld",
272 nd
->name
, (long) nd
->expire
);
277 stats_hash(struct Client
*source_p
)
279 hash_stats(source_p
);
283 stats_connect(struct Client
*source_p
)
286 struct server_conf
*server_p
;
290 if((ConfigFileEntry
.stats_c_oper_only
||
291 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
294 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
295 form_str(ERR_NOPRIVILEGES
));
299 DLINK_FOREACH(ptr
, server_conf_list
.head
)
301 server_p
= ptr
->data
;
303 if(ServerConfIllegal(server_p
))
311 if(ServerConfAutoconn(server_p
))
313 if(ServerConfTb(server_p
))
315 if(ServerConfCompressed(server_p
))
324 sendto_one_numeric(source_p
, RPL_STATSCLINE
,
325 form_str(RPL_STATSCLINE
),
326 #ifndef HIDE_SERVERS_IPS
332 server_p
->port
, server_p
->class_name
);
338 * input - client to report to
340 * side effects - client is given temp dline list.
343 stats_tdeny (struct Client
*source_p
)
345 char *host
, *pass
, *user
, *oper_reason
;
346 struct AddressRec
*arec
;
347 struct ConfItem
*aconf
;
350 for (i
= 0; i
< ATABLE_SIZE
; i
++)
352 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
354 if(arec
->type
== CONF_DLINE
)
358 if(!(aconf
->flags
& CONF_FLAGS_TEMPORARY
))
361 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
363 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
364 form_str (RPL_STATSDLINE
),
366 oper_reason
? "|" : "",
367 oper_reason
? oper_reason
: "");
375 * input - client to report to
377 * side effects - client is given dline list.
380 stats_deny (struct Client
*source_p
)
382 char *host
, *pass
, *user
, *oper_reason
;
383 struct AddressRec
*arec
;
384 struct ConfItem
*aconf
;
387 for (i
= 0; i
< ATABLE_SIZE
; i
++)
389 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
391 if(arec
->type
== CONF_DLINE
)
395 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
398 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
400 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
401 form_str (RPL_STATSDLINE
),
403 oper_reason
? "|" : "",
404 oper_reason
? oper_reason
: "");
413 * input - client to report to
415 * side effects - client is given list of exempt blocks
418 stats_exempt(struct Client
*source_p
)
420 char *name
, *host
, *pass
, *user
, *classname
;
421 struct AddressRec
*arec
;
422 struct ConfItem
*aconf
;
425 if(ConfigFileEntry
.stats_e_disabled
)
427 sendto_one_numeric(source_p
, ERR_DISABLED
,
428 form_str(ERR_DISABLED
), "STATS e");
432 for (i
= 0; i
< ATABLE_SIZE
; i
++)
434 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
436 if(arec
->type
== CONF_EXEMPTDLINE
)
439 get_printable_conf (aconf
, &name
, &host
, &pass
,
440 &user
, &port
, &classname
);
442 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
443 form_str(RPL_STATSDLINE
),
444 'e', host
, pass
, "", "");
451 stats_events (struct Client
*source_p
)
453 show_events (source_p
);
456 /* stats_pending_glines()
458 * input - client pointer
460 * side effects - client is shown list of pending glines
463 stats_pending_glines (struct Client
*source_p
)
465 if(ConfigFileEntry
.glines
)
467 dlink_node
*pending_node
;
468 struct gline_pending
*glp_ptr
;
469 char timebuffer
[MAX_DATE_STRING
];
472 DLINK_FOREACH (pending_node
, pending_glines
.head
)
474 glp_ptr
= pending_node
->data
;
476 tmptr
= localtime (&glp_ptr
->time_request1
);
477 strftime (timebuffer
, MAX_DATE_STRING
, "%Y/%m/%d %H:%M:%S", tmptr
);
479 sendto_one_notice(source_p
,
480 ":1) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
482 glp_ptr
->oper_user1
, glp_ptr
->oper_host1
,
483 glp_ptr
->oper_server1
, timebuffer
,
484 glp_ptr
->user
, glp_ptr
->host
, glp_ptr
->reason1
);
486 if(glp_ptr
->oper_nick2
[0])
488 tmptr
= localtime (&glp_ptr
->time_request2
);
489 strftime (timebuffer
, MAX_DATE_STRING
, "%Y/%m/%d %H:%M:%S", tmptr
);
490 sendto_one_notice(source_p
,
491 ":2) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
493 glp_ptr
->oper_user2
, glp_ptr
->oper_host2
,
494 glp_ptr
->oper_server2
, timebuffer
,
495 glp_ptr
->user
, glp_ptr
->host
, glp_ptr
->reason2
);
499 if(dlink_list_length (&pending_glines
) > 0)
500 sendto_one_notice(source_p
, ":End of Pending G-lines");
503 sendto_one_notice(source_p
, ":This server does not support G-Lines");
509 * input - client pointer
511 * side effects - client is shown list of glines
514 stats_glines (struct Client
*source_p
)
516 if(ConfigFileEntry
.glines
)
518 dlink_node
*gline_node
;
519 struct ConfItem
*kill_ptr
;
521 DLINK_FOREACH_PREV (gline_node
, glines
.tail
)
523 kill_ptr
= gline_node
->data
;
525 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
526 form_str(RPL_STATSKLINE
), 'G',
527 kill_ptr
->host
? kill_ptr
->host
: "*",
528 kill_ptr
->user
? kill_ptr
->user
: "*",
529 kill_ptr
->passwd
? kill_ptr
->passwd
: "No Reason",
530 kill_ptr
->spasswd
? "|" : "",
531 kill_ptr
->spasswd
? kill_ptr
->spasswd
: "");
535 sendto_one_notice(source_p
, ":This server does not support G-Lines");
540 stats_hubleaf(struct Client
*source_p
)
542 struct remote_conf
*hub_p
;
545 if((ConfigFileEntry
.stats_h_oper_only
||
546 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
549 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
550 form_str (ERR_NOPRIVILEGES
));
554 DLINK_FOREACH(ptr
, hubleaf_conf_list
.head
)
558 if(hub_p
->flags
& CONF_HUB
)
559 sendto_one_numeric(source_p
, RPL_STATSHLINE
,
560 form_str(RPL_STATSHLINE
),
561 hub_p
->host
, hub_p
->server
);
563 sendto_one_numeric(source_p
, RPL_STATSLLINE
,
564 form_str(RPL_STATSLLINE
),
565 hub_p
->host
, hub_p
->server
);
571 stats_auth (struct Client
*source_p
)
573 /* Oper only, if unopered, return ERR_NOPRIVS */
574 if((ConfigFileEntry
.stats_i_oper_only
== 2) && !IsOper (source_p
))
575 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
576 form_str (ERR_NOPRIVILEGES
));
578 /* If unopered, Only return matching auth blocks */
579 else if((ConfigFileEntry
.stats_i_oper_only
== 1) && !IsOper (source_p
))
581 struct ConfItem
*aconf
;
582 char *name
, *host
, *pass
, *user
, *classname
;
585 if(MyConnect (source_p
))
586 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
587 (struct sockaddr
*)&source_p
->localClient
->ip
,
589 source_p
->localClient
->ip
.ss_family
,
592 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_CLIENT
,
593 0, source_p
->username
);
598 get_printable_conf (aconf
, &name
, &host
, &pass
, &user
, &port
, &classname
);
600 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
601 name
, show_iline_prefix(source_p
, aconf
, user
),
602 host
, port
, classname
);
605 /* Theyre opered, or allowed to see all auth blocks */
607 report_auth (source_p
);
612 stats_tklines(struct Client
*source_p
)
614 /* Oper only, if unopered, return ERR_NOPRIVS */
615 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
616 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
617 form_str (ERR_NOPRIVILEGES
));
619 /* If unopered, Only return matching klines */
620 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
622 struct ConfItem
*aconf
;
623 char *host
, *pass
, *user
, *oper_reason
;
625 if(MyConnect (source_p
))
626 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
627 (struct sockaddr
*)&source_p
->localClient
->ip
,
629 source_p
->localClient
->ip
.ss_family
,
632 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
633 0, source_p
->username
);
638 /* dont report a permanent kline as a tkline */
639 if((aconf
->flags
& CONF_FLAGS_TEMPORARY
) == 0)
642 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
644 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
645 form_str(RPL_STATSKLINE
), aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
646 host
, user
, pass
, oper_reason
? "|" : "",
647 oper_reason
? oper_reason
: "");
649 /* Theyre opered, or allowed to see all klines */
652 struct ConfItem
*aconf
;
655 char *user
, *host
, *pass
, *oper_reason
;
657 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
659 DLINK_FOREACH(ptr
, temp_klines
[i
].head
)
663 get_printable_kline(source_p
, aconf
, &host
, &pass
,
664 &user
, &oper_reason
);
666 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
667 form_str(RPL_STATSKLINE
),
668 'k', host
, user
, pass
,
669 oper_reason
? "|" : "",
670 oper_reason
? oper_reason
: "");
677 stats_klines(struct Client
*source_p
)
679 /* Oper only, if unopered, return ERR_NOPRIVS */
680 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
681 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
682 form_str (ERR_NOPRIVILEGES
));
684 /* If unopered, Only return matching klines */
685 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
687 struct ConfItem
*aconf
;
688 char *host
, *pass
, *user
, *oper_reason
;
690 /* search for a kline */
691 if(MyConnect (source_p
))
692 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
693 (struct sockaddr
*)&source_p
->localClient
->ip
,
695 source_p
->localClient
->ip
.ss_family
,
698 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
699 0, source_p
->username
);
704 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
706 sendto_one_numeric(source_p
, RPL_STATSKLINE
, form_str(RPL_STATSKLINE
),
707 aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
708 host
, user
, pass
, oper_reason
? "|" : "",
709 oper_reason
? oper_reason
: "");
711 /* Theyre opered, or allowed to see all klines */
713 report_Klines (source_p
);
717 stats_messages(struct Client
*source_p
)
719 report_messages(source_p
);
723 stats_dnsbl(struct Client
*source_p
)
726 struct Blacklist
*blptr
;
728 DLINK_FOREACH(ptr
, blacklist_list
.head
)
732 /* use RPL_STATSDEBUG for now -- jilles */
733 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "n :%d %s %s (%d)",
736 blptr
->status
& CONF_ILLEGAL
? "disabled" : "active",
742 stats_oper(struct Client
*source_p
)
744 struct oper_conf
*oper_p
;
747 if(!IsOper(source_p
) && ConfigFileEntry
.stats_o_oper_only
)
749 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
750 form_str (ERR_NOPRIVILEGES
));
754 DLINK_FOREACH(ptr
, oper_conf_list
.head
)
758 sendto_one_numeric(source_p
, RPL_STATSOLINE
,
759 form_str(RPL_STATSOLINE
),
760 oper_p
->username
, oper_p
->host
, oper_p
->name
,
761 IsOper(source_p
) ? get_oper_privs(oper_p
->flags
) : "0", "-1");
768 * input - client pointer
770 * side effects - client is shown a list of active opers
773 stats_operedup (struct Client
*source_p
)
775 struct Client
*target_p
;
776 dlink_node
*oper_ptr
;
777 unsigned int count
= 0;
779 DLINK_FOREACH (oper_ptr
, oper_list
.head
)
781 target_p
= oper_ptr
->data
;
783 if(IsOperInvis(target_p
) && !IsOper(source_p
))
786 if(target_p
->user
->away
)
791 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
793 target_p
->name
, target_p
->username
,
797 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
798 "p :%u staff members", count
);
800 stats_p_spy (source_p
);
804 stats_ports (struct Client
*source_p
)
806 if(!IsOper (source_p
) && ConfigFileEntry
.stats_P_oper_only
)
807 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
808 form_str (ERR_NOPRIVILEGES
));
810 show_ports (source_p
);
814 stats_tresv(struct Client
*source_p
)
816 struct ConfItem
*aconf
;
820 DLINK_FOREACH(ptr
, resv_conf_list
.head
)
824 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
825 form_str(RPL_STATSQLINE
),
826 'q', aconf
->port
, aconf
->name
, aconf
->passwd
);
829 HASH_WALK(i
, R_MAX
, ptr
, resvTable
)
833 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
834 form_str(RPL_STATSQLINE
),
835 'q', aconf
->port
, aconf
->name
, aconf
->passwd
);
842 stats_resv(struct Client
*source_p
)
844 struct ConfItem
*aconf
;
848 DLINK_FOREACH(ptr
, resv_conf_list
.head
)
852 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
853 form_str(RPL_STATSQLINE
),
854 'Q', aconf
->port
, aconf
->name
, aconf
->passwd
);
857 HASH_WALK(i
, R_MAX
, ptr
, resvTable
)
861 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
862 form_str(RPL_STATSQLINE
),
863 'Q', aconf
->port
, aconf
->name
, aconf
->passwd
);
869 stats_usage (struct Client
*source_p
)
884 if(getrusage(RUSAGE_SELF
, &rus
) == -1)
886 sendto_one_notice(source_p
, ":Getruseage error: %s.",
890 secs
= rus
.ru_utime
.tv_sec
+ rus
.ru_stime
.tv_sec
;
894 rup
= (CurrentTime
- startup_time
) * hzz
;
898 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
899 "R :CPU Secs %d:%d User %d:%d System %d:%d",
900 (int) (secs
/ 60), (int) (secs
% 60),
901 (int) (rus
.ru_utime
.tv_sec
/ 60),
902 (int) (rus
.ru_utime
.tv_sec
% 60),
903 (int) (rus
.ru_stime
.tv_sec
/ 60),
904 (int) (rus
.ru_stime
.tv_sec
% 60));
905 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
906 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
907 rus
.ru_maxrss
, (rus
.ru_ixrss
/ rup
),
908 (rus
.ru_idrss
/ rup
), (rus
.ru_isrss
/ rup
));
909 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
910 "R :Swaps %d Reclaims %d Faults %d",
911 (int) rus
.ru_nswap
, (int) rus
.ru_minflt
, (int) rus
.ru_majflt
);
912 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
913 "R :Block in %d out %d",
914 (int) rus
.ru_inblock
, (int) rus
.ru_oublock
);
915 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
916 "R :Msg Rcv %d Send %d",
917 (int) rus
.ru_msgrcv
, (int) rus
.ru_msgsnd
);
918 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
919 "R :Signals %d Context Vol. %d Invol %d",
920 (int) rus
.ru_nsignals
, (int) rus
.ru_nvcsw
,
921 (int) rus
.ru_nivcsw
);
925 stats_tstats (struct Client
*source_p
)
931 stats_uptime (struct Client
*source_p
)
935 now
= CurrentTime
- startup_time
;
936 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
937 form_str (RPL_STATSUPTIME
),
938 now
/ 86400, (now
/ 3600) % 24,
939 (now
/ 60) % 60, now
% 60);
940 sendto_one_numeric(source_p
, RPL_STATSCONN
,
941 form_str (RPL_STATSCONN
),
942 MaxConnectionCount
, MaxClientCount
,
943 Count
.totalrestartcount
);
951 static struct shared_flags shared_flagtable
[] =
953 { SHARED_PKLINE
, 'K' },
954 { SHARED_TKLINE
, 'k' },
955 { SHARED_UNKLINE
, 'U' },
956 { SHARED_PXLINE
, 'X' },
957 { SHARED_TXLINE
, 'x' },
958 { SHARED_UNXLINE
, 'Y' },
959 { SHARED_PRESV
, 'Q' },
960 { SHARED_TRESV
, 'q' },
961 { SHARED_UNRESV
, 'R' },
962 { SHARED_LOCOPS
, 'L' },
963 { SHARED_REHASH
, 'H' },
969 stats_shared (struct Client
*source_p
)
971 struct remote_conf
*shared_p
;
977 DLINK_FOREACH(ptr
, shared_conf_list
.head
)
979 shared_p
= ptr
->data
;
985 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
987 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
988 *p
++ = shared_flagtable
[i
].letter
;
993 sendto_one_numeric(source_p
, RPL_STATSULINE
,
994 form_str(RPL_STATSULINE
),
995 shared_p
->server
, shared_p
->username
,
996 shared_p
->host
, buf
);
999 DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
1001 shared_p
= ptr
->data
;
1007 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1009 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1010 *p
++ = shared_flagtable
[i
].letter
;
1015 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1016 form_str(RPL_STATSULINE
),
1017 shared_p
->server
, "*", "*", buf
);
1023 * input - client pointer
1025 * side effects - client is shown lists of who connected servers
1028 stats_servers (struct Client
*source_p
)
1030 struct Client
*target_p
;
1033 int days
, hours
, minutes
;
1036 if(ConfigServerHide
.flatten_links
&& !IsOper(source_p
) &&
1037 !IsExemptShide(source_p
))
1039 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1040 form_str (ERR_NOPRIVILEGES
));
1044 DLINK_FOREACH (ptr
, serv_list
.head
)
1046 target_p
= ptr
->data
;
1049 seconds
= CurrentTime
- target_p
->localClient
->firsttime
;
1051 days
= (int) (seconds
/ 86400);
1053 hours
= (int) (seconds
/ 3600);
1055 minutes
= (int) (seconds
/ 60);
1058 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1059 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1060 "Connected: %d day%s, %d:%02d:%02d",
1062 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
1063 (int) (CurrentTime
- target_p
->localClient
->lasttime
),
1064 (int) linebuf_len (&target_p
->localClient
->buf_sendq
),
1065 days
, (days
== 1) ? "" : "s", hours
, minutes
,
1069 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1070 "V :%d Server(s)", j
);
1074 stats_tgecos(struct Client
*source_p
)
1076 struct ConfItem
*aconf
;
1079 DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1084 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1085 form_str(RPL_STATSXLINE
),
1086 'x', aconf
->port
, aconf
->name
,
1092 stats_gecos(struct Client
*source_p
)
1094 struct ConfItem
*aconf
;
1097 DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1102 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1103 form_str(RPL_STATSXLINE
),
1104 'X', aconf
->port
, aconf
->name
,
1110 stats_class(struct Client
*source_p
)
1112 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOper(source_p
))
1113 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1114 form_str (ERR_NOPRIVILEGES
));
1116 report_classes(source_p
);
1120 stats_memory (struct Client
*source_p
)
1122 count_memory (source_p
);
1126 stats_ziplinks (struct Client
*source_p
)
1129 struct Client
*target_p
;
1132 DLINK_FOREACH (ptr
, serv_list
.head
)
1134 target_p
= ptr
->data
;
1135 if(IsCapable (target_p
, CAP_ZIP
))
1137 /* we use memcpy(3) and a local copy of the structure to
1138 * work around a register use bug on GCC on the SPARC.
1139 * -jmallett, 04/27/2002
1141 struct ZipStats zipstats
;
1142 memcpy (&zipstats
, &target_p
->localClient
->zipstats
,
1143 sizeof (struct ZipStats
));
1144 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1145 "Z :ZipLinks stats for %s send[%.2f%% compression "
1146 "(%lu kB data/%lu kB wire)] recv[%.2f%% compression "
1147 "(%lu kB data/%lu kB wire)]",
1149 zipstats
.out_ratio
, zipstats
.outK
, zipstats
.outK_wire
,
1150 zipstats
.in_ratio
, zipstats
.inK
, zipstats
.inK_wire
);
1155 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1156 "Z :%u ziplink(s)", sent_data
);
1160 stats_servlinks (struct Client
*source_p
)
1162 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1163 long uptime
, sendK
, receiveK
;
1164 struct Client
*target_p
;
1168 if(ConfigServerHide
.flatten_links
&& !IsOper (source_p
) &&
1169 !IsExemptShide(source_p
))
1171 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1172 form_str (ERR_NOPRIVILEGES
));
1176 sendK
= receiveK
= 0;
1178 DLINK_FOREACH (ptr
, serv_list
.head
)
1180 target_p
= ptr
->data
;
1183 sendK
+= target_p
->localClient
->sendK
;
1184 receiveK
+= target_p
->localClient
->receiveK
;
1186 sendto_one(source_p
, Sformat
,
1187 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1188 get_server_name(target_p
, SHOW_IP
),
1189 (int) linebuf_len (&target_p
->localClient
->buf_sendq
),
1190 (int) target_p
->localClient
->sendM
,
1191 (int) target_p
->localClient
->sendK
,
1192 (int) target_p
->localClient
->receiveM
,
1193 (int) target_p
->localClient
->receiveK
,
1194 CurrentTime
- target_p
->localClient
->firsttime
,
1195 (CurrentTime
> target_p
->localClient
->lasttime
) ?
1196 (CurrentTime
- target_p
->localClient
->lasttime
) : 0,
1197 IsOper (source_p
) ? show_capabilities (target_p
) : "TS");
1200 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1201 "? :%u total server(s)", j
);
1203 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1204 "? :Sent total : %7.2f %s",
1205 _GMKv (sendK
), _GMKs (sendK
));
1206 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1207 "? :Recv total : %7.2f %s",
1208 _GMKv (receiveK
), _GMKs (receiveK
));
1210 uptime
= (CurrentTime
- startup_time
);
1212 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1213 "? :Server send: %7.2f %s (%4.1f K/s)",
1214 _GMKv (me
.localClient
->sendK
),
1215 _GMKs (me
.localClient
->sendK
),
1216 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1217 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1218 "? :Server recv: %7.2f %s (%4.1f K/s)",
1219 _GMKv (me
.localClient
->receiveK
),
1220 _GMKs (me
.localClient
->receiveK
),
1221 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1225 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1230 char statchar
= parv
[1][0];
1232 /* this is def targeted at us somehow.. */
1233 if(parc
> 2 && !EmptyString(parv
[2]))
1235 /* directed at us generically? */
1236 if(match(parv
[2], me
.name
) ||
1237 (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1245 wilds
= strchr(name
, '*') || strchr(name
, '?');
1248 /* must be directed at a specific person thats not us */
1249 if(!doall
&& !wilds
)
1251 struct Client
*target_p
;
1253 if(MyClient(source_p
))
1254 target_p
= find_named_person(name
);
1256 target_p
= find_person(name
);
1258 if(target_p
!= NULL
)
1260 stats_spy(source_p
, statchar
, target_p
->name
);
1261 stats_l_client(source_p
, target_p
, statchar
);
1264 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1265 form_str(ERR_NOSUCHSERVER
),
1277 stats_spy(source_p
, statchar
, name
);
1281 /* local opers get everyone */
1282 if(MyOper(source_p
))
1284 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
);
1285 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
);
1289 /* they still need themselves if theyre local.. */
1290 if(MyClient(source_p
))
1291 stats_l_client(source_p
, source_p
, statchar
);
1293 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
);
1296 if (!ConfigServerHide
.flatten_links
|| IsOper(source_p
) ||
1297 IsExemptShide(source_p
))
1298 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
);
1303 /* ok, at this point theyre looking for a specific client whos on
1304 * our server.. but it contains a wildcard. --fl
1306 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
);
1313 stats_l_list(struct Client
*source_p
, const char *name
, int doall
, int wilds
,
1314 dlink_list
* list
, char statchar
)
1317 struct Client
*target_p
;
1319 /* send information about connections which match. note, we
1320 * dont need tests for IsInvisible(), because non-opers will
1321 * never get here for normal clients --fl
1323 DLINK_FOREACH(ptr
, list
->head
)
1325 target_p
= ptr
->data
;
1327 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1330 stats_l_client(source_p
, target_p
, statchar
);
1335 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1338 if(IsAnyServer(target_p
))
1340 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1341 get_server_name(target_p
, SHOW_IP
),
1342 (int) linebuf_len(&target_p
->localClient
->buf_sendq
),
1343 (int) target_p
->localClient
->sendM
,
1344 (int) target_p
->localClient
->sendK
,
1345 (int) target_p
->localClient
->receiveM
,
1346 (int) target_p
->localClient
->receiveK
,
1347 CurrentTime
- target_p
->localClient
->firsttime
,
1348 (CurrentTime
> target_p
->localClient
->lasttime
) ?
1349 (CurrentTime
- target_p
->localClient
->lasttime
) : 0,
1350 IsOper(source_p
) ? show_capabilities(target_p
) : "-");
1355 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1356 show_ip(source_p
, target_p
) ?
1357 (IsUpper(statchar
) ?
1358 get_client_name(target_p
, SHOW_IP
) :
1359 get_client_name(target_p
, HIDE_IP
)) :
1360 get_client_name(target_p
, MASK_IP
),
1361 (int) linebuf_len(&target_p
->localClient
->buf_sendq
),
1362 (int) target_p
->localClient
->sendM
,
1363 (int) target_p
->localClient
->sendK
,
1364 (int) target_p
->localClient
->receiveM
,
1365 (int) target_p
->localClient
->receiveK
,
1366 CurrentTime
- target_p
->localClient
->firsttime
,
1367 (CurrentTime
> target_p
->localClient
->lasttime
) ?
1368 (CurrentTime
- target_p
->localClient
->lasttime
) : 0,
1376 * inputs - pointer to client doing the /stats
1377 * - char letter they are doing /stats on
1380 * This little helper function reports to opers if configured.
1381 * personally, I don't see why opers need to see stats requests
1382 * at all. They are just "noise" to an oper, and users can't do
1383 * any damage with stats requests now anyway. So, why show them?
1387 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1391 data
.client
= source_p
;
1393 data
.arg2
= (int) statchar
;
1395 call_hook(doing_stats_hook
, &data
);
1400 * input - pointer to client doing stats
1402 * side effects - call hook doing_stats_p
1405 stats_p_spy (struct Client
*source_p
)
1409 data
.client
= source_p
;
1410 data
.arg1
= data
.arg2
= NULL
;
1412 call_hook(doing_stats_p_hook
, &data
);