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_admin
&& !IsOperAdmin (source_p
)) ||
230 (stats_cmd_table
[i
].need_oper
&& !IsOper (source_p
)))
232 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
233 form_str (ERR_NOPRIVILEGES
));
237 /* Blah, stats L needs the parameters, none of the others do.. */
238 if(statchar
== 'L' || statchar
== 'l')
239 stats_cmd_table
[i
].handler (source_p
, parc
, parv
);
241 stats_cmd_table
[i
].handler (source_p
);
245 /* Send the end of stats notice, and the stats_spy */
246 sendto_one_numeric(source_p
, RPL_ENDOFSTATS
,
247 form_str(RPL_ENDOFSTATS
), statchar
);
253 stats_dns_servers (struct Client
*source_p
)
255 report_dns_servers (source_p
);
259 stats_delay(struct Client
*source_p
)
262 struct DictionaryIter iter
;
264 DICTIONARY_FOREACH(nd
, &iter
, nd_dict
)
266 sendto_one_notice(source_p
, ":Delaying: %s for %ld",
267 nd
->name
, (long) nd
->expire
);
272 stats_hash(struct Client
*source_p
)
274 hash_stats(source_p
);
278 stats_connect(struct Client
*source_p
)
281 struct server_conf
*server_p
;
285 if((ConfigFileEntry
.stats_c_oper_only
||
286 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
289 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
290 form_str(ERR_NOPRIVILEGES
));
294 DLINK_FOREACH(ptr
, server_conf_list
.head
)
296 server_p
= ptr
->data
;
298 if(ServerConfIllegal(server_p
))
306 if(ServerConfAutoconn(server_p
))
308 if(ServerConfTb(server_p
))
310 if(ServerConfCompressed(server_p
))
319 sendto_one_numeric(source_p
, RPL_STATSCLINE
,
320 form_str(RPL_STATSCLINE
),
321 #ifndef HIDE_SERVERS_IPS
327 server_p
->port
, server_p
->class_name
);
333 * input - client to report to
335 * side effects - client is given temp dline list.
338 stats_tdeny (struct Client
*source_p
)
340 char *host
, *pass
, *user
, *oper_reason
;
341 struct AddressRec
*arec
;
342 struct ConfItem
*aconf
;
345 for (i
= 0; i
< ATABLE_SIZE
; i
++)
347 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
349 if(arec
->type
== CONF_DLINE
)
353 if(!(aconf
->flags
& CONF_FLAGS_TEMPORARY
))
356 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
358 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
359 form_str (RPL_STATSDLINE
),
361 oper_reason
? "|" : "",
362 oper_reason
? oper_reason
: "");
370 * input - client to report to
372 * side effects - client is given dline list.
375 stats_deny (struct Client
*source_p
)
377 char *host
, *pass
, *user
, *oper_reason
;
378 struct AddressRec
*arec
;
379 struct ConfItem
*aconf
;
382 for (i
= 0; i
< ATABLE_SIZE
; i
++)
384 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
386 if(arec
->type
== CONF_DLINE
)
390 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
393 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
395 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
396 form_str (RPL_STATSDLINE
),
398 oper_reason
? "|" : "",
399 oper_reason
? oper_reason
: "");
408 * input - client to report to
410 * side effects - client is given list of exempt blocks
413 stats_exempt(struct Client
*source_p
)
415 char *name
, *host
, *pass
, *user
, *classname
;
416 struct AddressRec
*arec
;
417 struct ConfItem
*aconf
;
420 if(ConfigFileEntry
.stats_e_disabled
)
422 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
423 form_str (ERR_NOPRIVILEGES
));
427 for (i
= 0; i
< ATABLE_SIZE
; i
++)
429 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
431 if(arec
->type
== CONF_EXEMPTDLINE
)
434 get_printable_conf (aconf
, &name
, &host
, &pass
,
435 &user
, &port
, &classname
);
437 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
438 form_str(RPL_STATSDLINE
),
439 'e', host
, pass
, "", "");
446 stats_events (struct Client
*source_p
)
448 show_events (source_p
);
451 /* stats_pending_glines()
453 * input - client pointer
455 * side effects - client is shown list of pending glines
458 stats_pending_glines (struct Client
*source_p
)
460 if(ConfigFileEntry
.glines
)
462 dlink_node
*pending_node
;
463 struct gline_pending
*glp_ptr
;
464 char timebuffer
[MAX_DATE_STRING
];
467 DLINK_FOREACH (pending_node
, pending_glines
.head
)
469 glp_ptr
= pending_node
->data
;
471 tmptr
= localtime (&glp_ptr
->time_request1
);
472 strftime (timebuffer
, MAX_DATE_STRING
, "%Y/%m/%d %H:%M:%S", tmptr
);
474 sendto_one_notice(source_p
,
475 ":1) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
477 glp_ptr
->oper_user1
, glp_ptr
->oper_host1
,
478 glp_ptr
->oper_server1
, timebuffer
,
479 glp_ptr
->user
, glp_ptr
->host
, glp_ptr
->reason1
);
481 if(glp_ptr
->oper_nick2
[0])
483 tmptr
= localtime (&glp_ptr
->time_request2
);
484 strftime (timebuffer
, MAX_DATE_STRING
, "%Y/%m/%d %H:%M:%S", tmptr
);
485 sendto_one_notice(source_p
,
486 ":2) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
488 glp_ptr
->oper_user2
, glp_ptr
->oper_host2
,
489 glp_ptr
->oper_server2
, timebuffer
,
490 glp_ptr
->user
, glp_ptr
->host
, glp_ptr
->reason2
);
494 if(dlink_list_length (&pending_glines
) > 0)
495 sendto_one_notice(source_p
, ":End of Pending G-lines");
498 sendto_one_notice(source_p
, ":This server does not support G-Lines");
504 * input - client pointer
506 * side effects - client is shown list of glines
509 stats_glines (struct Client
*source_p
)
511 if(ConfigFileEntry
.glines
)
513 dlink_node
*gline_node
;
514 struct ConfItem
*kill_ptr
;
516 DLINK_FOREACH_PREV (gline_node
, glines
.tail
)
518 kill_ptr
= gline_node
->data
;
520 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
521 form_str(RPL_STATSKLINE
), 'G',
522 kill_ptr
->host
? kill_ptr
->host
: "*",
523 kill_ptr
->user
? kill_ptr
->user
: "*",
524 kill_ptr
->passwd
? kill_ptr
->passwd
: "No Reason",
525 kill_ptr
->spasswd
? "|" : "",
526 kill_ptr
->spasswd
? kill_ptr
->spasswd
: "");
530 sendto_one_notice(source_p
, ":This server does not support G-Lines");
535 stats_hubleaf(struct Client
*source_p
)
537 struct remote_conf
*hub_p
;
540 if((ConfigFileEntry
.stats_h_oper_only
||
541 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
544 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
545 form_str (ERR_NOPRIVILEGES
));
549 DLINK_FOREACH(ptr
, hubleaf_conf_list
.head
)
553 if(hub_p
->flags
& CONF_HUB
)
554 sendto_one_numeric(source_p
, RPL_STATSHLINE
,
555 form_str(RPL_STATSHLINE
),
556 hub_p
->host
, hub_p
->server
);
558 sendto_one_numeric(source_p
, RPL_STATSLLINE
,
559 form_str(RPL_STATSLLINE
),
560 hub_p
->host
, hub_p
->server
);
566 stats_auth (struct Client
*source_p
)
568 /* Oper only, if unopered, return ERR_NOPRIVS */
569 if((ConfigFileEntry
.stats_i_oper_only
== 2) && !IsOper (source_p
))
570 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
571 form_str (ERR_NOPRIVILEGES
));
573 /* If unopered, Only return matching auth blocks */
574 else if((ConfigFileEntry
.stats_i_oper_only
== 1) && !IsOper (source_p
))
576 struct ConfItem
*aconf
;
577 char *name
, *host
, *pass
, *user
, *classname
;
580 if(MyConnect (source_p
))
581 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
582 (struct sockaddr
*)&source_p
->localClient
->ip
,
584 source_p
->localClient
->ip
.ss_family
,
587 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_CLIENT
,
588 0, source_p
->username
);
593 get_printable_conf (aconf
, &name
, &host
, &pass
, &user
, &port
, &classname
);
595 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
596 name
, show_iline_prefix(source_p
, aconf
, user
),
597 host
, port
, classname
);
600 /* Theyre opered, or allowed to see all auth blocks */
602 report_auth (source_p
);
607 stats_tklines(struct Client
*source_p
)
609 /* Oper only, if unopered, return ERR_NOPRIVS */
610 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
611 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
612 form_str (ERR_NOPRIVILEGES
));
614 /* If unopered, Only return matching klines */
615 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
617 struct ConfItem
*aconf
;
618 char *host
, *pass
, *user
, *oper_reason
;
620 if(MyConnect (source_p
))
621 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
622 (struct sockaddr
*)&source_p
->localClient
->ip
,
624 source_p
->localClient
->ip
.ss_family
,
627 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
628 0, source_p
->username
);
633 /* dont report a permanent kline as a tkline */
634 if((aconf
->flags
& CONF_FLAGS_TEMPORARY
) == 0)
637 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
639 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
640 form_str(RPL_STATSKLINE
), aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
641 host
, user
, pass
, oper_reason
? "|" : "",
642 oper_reason
? oper_reason
: "");
644 /* Theyre opered, or allowed to see all klines */
647 struct ConfItem
*aconf
;
650 char *user
, *host
, *pass
, *oper_reason
;
652 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
654 DLINK_FOREACH(ptr
, temp_klines
[i
].head
)
658 get_printable_kline(source_p
, aconf
, &host
, &pass
,
659 &user
, &oper_reason
);
661 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
662 form_str(RPL_STATSKLINE
),
663 'k', host
, user
, pass
,
664 oper_reason
? "|" : "",
665 oper_reason
? oper_reason
: "");
672 stats_klines(struct Client
*source_p
)
674 /* Oper only, if unopered, return ERR_NOPRIVS */
675 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
676 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
677 form_str (ERR_NOPRIVILEGES
));
679 /* If unopered, Only return matching klines */
680 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
682 struct ConfItem
*aconf
;
683 char *host
, *pass
, *user
, *oper_reason
;
685 /* search for a kline */
686 if(MyConnect (source_p
))
687 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
688 (struct sockaddr
*)&source_p
->localClient
->ip
,
690 source_p
->localClient
->ip
.ss_family
,
693 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
694 0, source_p
->username
);
699 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
701 sendto_one_numeric(source_p
, RPL_STATSKLINE
, form_str(RPL_STATSKLINE
),
702 aconf
->flags
& CONF_FLAGS_TEMPORARY
? 'k' : 'K',
703 host
, user
, pass
, oper_reason
? "|" : "",
704 oper_reason
? oper_reason
: "");
706 /* Theyre opered, or allowed to see all klines */
708 report_Klines (source_p
);
712 stats_messages(struct Client
*source_p
)
714 report_messages(source_p
);
718 stats_dnsbl(struct Client
*source_p
)
721 struct Blacklist
*blptr
;
723 DLINK_FOREACH(ptr
, blacklist_list
.head
)
727 /* use RPL_STATSDEBUG for now -- jilles */
728 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "n :%d %s %s (%d)",
731 blptr
->status
& CONF_ILLEGAL
? "disabled" : "active",
737 stats_oper(struct Client
*source_p
)
739 struct oper_conf
*oper_p
;
742 if(!IsOper(source_p
) && ConfigFileEntry
.stats_o_oper_only
)
744 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
745 form_str (ERR_NOPRIVILEGES
));
749 DLINK_FOREACH(ptr
, oper_conf_list
.head
)
753 sendto_one_numeric(source_p
, RPL_STATSOLINE
,
754 form_str(RPL_STATSOLINE
),
755 oper_p
->username
, oper_p
->host
, oper_p
->name
,
756 IsOper(source_p
) ? get_oper_privs(oper_p
->flags
) : "0", "-1");
763 * input - client pointer
765 * side effects - client is shown a list of active opers
768 stats_operedup (struct Client
*source_p
)
770 struct Client
*target_p
;
771 dlink_node
*oper_ptr
;
772 unsigned int count
= 0;
774 DLINK_FOREACH (oper_ptr
, oper_list
.head
)
776 target_p
= oper_ptr
->data
;
778 if(IsOperInvis(target_p
) && !IsOper(source_p
))
781 if(target_p
->user
->away
)
786 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
788 target_p
->name
, target_p
->username
,
792 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
793 "p :%u staff members", count
);
795 stats_p_spy (source_p
);
799 stats_ports (struct Client
*source_p
)
801 if(!IsOper (source_p
) && ConfigFileEntry
.stats_P_oper_only
)
802 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
803 form_str (ERR_NOPRIVILEGES
));
805 show_ports (source_p
);
809 stats_tresv(struct Client
*source_p
)
811 struct ConfItem
*aconf
;
815 DLINK_FOREACH(ptr
, resv_conf_list
.head
)
819 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
820 form_str(RPL_STATSQLINE
),
821 'q', aconf
->port
, aconf
->name
, aconf
->passwd
);
824 HASH_WALK(i
, R_MAX
, ptr
, resvTable
)
828 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
829 form_str(RPL_STATSQLINE
),
830 'q', aconf
->port
, aconf
->name
, aconf
->passwd
);
837 stats_resv(struct Client
*source_p
)
839 struct ConfItem
*aconf
;
843 DLINK_FOREACH(ptr
, resv_conf_list
.head
)
847 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
848 form_str(RPL_STATSQLINE
),
849 'Q', aconf
->port
, aconf
->name
, aconf
->passwd
);
852 HASH_WALK(i
, R_MAX
, ptr
, resvTable
)
856 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
857 form_str(RPL_STATSQLINE
),
858 'Q', aconf
->port
, aconf
->name
, aconf
->passwd
);
864 stats_usage (struct Client
*source_p
)
879 if(getrusage(RUSAGE_SELF
, &rus
) == -1)
881 sendto_one_notice(source_p
, ":Getruseage error: %s.",
885 secs
= rus
.ru_utime
.tv_sec
+ rus
.ru_stime
.tv_sec
;
889 rup
= (CurrentTime
- startup_time
) * hzz
;
893 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
894 "R :CPU Secs %d:%d User %d:%d System %d:%d",
895 (int) (secs
/ 60), (int) (secs
% 60),
896 (int) (rus
.ru_utime
.tv_sec
/ 60),
897 (int) (rus
.ru_utime
.tv_sec
% 60),
898 (int) (rus
.ru_stime
.tv_sec
/ 60),
899 (int) (rus
.ru_stime
.tv_sec
% 60));
900 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
901 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
902 rus
.ru_maxrss
, (rus
.ru_ixrss
/ rup
),
903 (rus
.ru_idrss
/ rup
), (rus
.ru_isrss
/ rup
));
904 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
905 "R :Swaps %d Reclaims %d Faults %d",
906 (int) rus
.ru_nswap
, (int) rus
.ru_minflt
, (int) rus
.ru_majflt
);
907 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
908 "R :Block in %d out %d",
909 (int) rus
.ru_inblock
, (int) rus
.ru_oublock
);
910 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
911 "R :Msg Rcv %d Send %d",
912 (int) rus
.ru_msgrcv
, (int) rus
.ru_msgsnd
);
913 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
914 "R :Signals %d Context Vol. %d Invol %d",
915 (int) rus
.ru_nsignals
, (int) rus
.ru_nvcsw
,
916 (int) rus
.ru_nivcsw
);
920 stats_tstats (struct Client
*source_p
)
926 stats_uptime (struct Client
*source_p
)
930 now
= CurrentTime
- startup_time
;
931 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
932 form_str (RPL_STATSUPTIME
),
933 now
/ 86400, (now
/ 3600) % 24,
934 (now
/ 60) % 60, now
% 60);
935 sendto_one_numeric(source_p
, RPL_STATSCONN
,
936 form_str (RPL_STATSCONN
),
937 MaxConnectionCount
, MaxClientCount
,
938 Count
.totalrestartcount
);
946 static struct shared_flags shared_flagtable
[] =
948 { SHARED_PKLINE
, 'K' },
949 { SHARED_TKLINE
, 'k' },
950 { SHARED_UNKLINE
, 'U' },
951 { SHARED_PXLINE
, 'X' },
952 { SHARED_TXLINE
, 'x' },
953 { SHARED_UNXLINE
, 'Y' },
954 { SHARED_PRESV
, 'Q' },
955 { SHARED_TRESV
, 'q' },
956 { SHARED_UNRESV
, 'R' },
957 { SHARED_LOCOPS
, 'L' },
958 { SHARED_REHASH
, 'H' },
964 stats_shared (struct Client
*source_p
)
966 struct remote_conf
*shared_p
;
972 DLINK_FOREACH(ptr
, shared_conf_list
.head
)
974 shared_p
= ptr
->data
;
980 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
982 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
983 *p
++ = shared_flagtable
[i
].letter
;
988 sendto_one_numeric(source_p
, RPL_STATSULINE
,
989 form_str(RPL_STATSULINE
),
990 shared_p
->server
, shared_p
->username
,
991 shared_p
->host
, buf
);
994 DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
996 shared_p
= ptr
->data
;
1002 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1004 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1005 *p
++ = shared_flagtable
[i
].letter
;
1010 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1011 form_str(RPL_STATSULINE
),
1012 shared_p
->server
, "*", "*", buf
);
1018 * input - client pointer
1020 * side effects - client is shown lists of who connected servers
1023 stats_servers (struct Client
*source_p
)
1025 struct Client
*target_p
;
1028 int days
, hours
, minutes
;
1031 if(ConfigServerHide
.flatten_links
&& !IsOper(source_p
) &&
1032 !IsExemptShide(source_p
))
1034 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1035 form_str (ERR_NOPRIVILEGES
));
1039 DLINK_FOREACH (ptr
, serv_list
.head
)
1041 target_p
= ptr
->data
;
1044 seconds
= CurrentTime
- target_p
->localClient
->firsttime
;
1046 days
= (int) (seconds
/ 86400);
1048 hours
= (int) (seconds
/ 3600);
1050 minutes
= (int) (seconds
/ 60);
1053 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1054 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1055 "Connected: %d day%s, %d:%02d:%02d",
1057 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
1058 (int) (CurrentTime
- target_p
->localClient
->lasttime
),
1059 (int) linebuf_len (&target_p
->localClient
->buf_sendq
),
1060 days
, (days
== 1) ? "" : "s", hours
, minutes
,
1064 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1065 "V :%d Server(s)", j
);
1069 stats_tgecos(struct Client
*source_p
)
1071 struct ConfItem
*aconf
;
1074 DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1079 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1080 form_str(RPL_STATSXLINE
),
1081 'x', aconf
->port
, aconf
->name
,
1087 stats_gecos(struct Client
*source_p
)
1089 struct ConfItem
*aconf
;
1092 DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1097 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1098 form_str(RPL_STATSXLINE
),
1099 'X', aconf
->port
, aconf
->name
,
1105 stats_class(struct Client
*source_p
)
1107 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOper(source_p
))
1108 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1109 form_str (ERR_NOPRIVILEGES
));
1111 report_classes(source_p
);
1115 stats_memory (struct Client
*source_p
)
1117 count_memory (source_p
);
1121 stats_ziplinks (struct Client
*source_p
)
1124 struct Client
*target_p
;
1127 DLINK_FOREACH (ptr
, serv_list
.head
)
1129 target_p
= ptr
->data
;
1130 if(IsCapable (target_p
, CAP_ZIP
))
1132 /* we use memcpy(3) and a local copy of the structure to
1133 * work around a register use bug on GCC on the SPARC.
1134 * -jmallett, 04/27/2002
1136 struct ZipStats zipstats
;
1137 memcpy (&zipstats
, &target_p
->localClient
->zipstats
,
1138 sizeof (struct ZipStats
));
1139 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1140 "Z :ZipLinks stats for %s send[%.2f%% compression "
1141 "(%lu kB data/%lu kB wire)] recv[%.2f%% compression "
1142 "(%lu kB data/%lu kB wire)]",
1144 zipstats
.out_ratio
, zipstats
.outK
, zipstats
.outK_wire
,
1145 zipstats
.in_ratio
, zipstats
.inK
, zipstats
.inK_wire
);
1150 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1151 "Z :%u ziplink(s)", sent_data
);
1155 stats_servlinks (struct Client
*source_p
)
1157 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1158 long uptime
, sendK
, receiveK
;
1159 struct Client
*target_p
;
1163 if(ConfigServerHide
.flatten_links
&& !IsOper (source_p
) &&
1164 !IsExemptShide(source_p
))
1166 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1167 form_str (ERR_NOPRIVILEGES
));
1171 sendK
= receiveK
= 0;
1173 DLINK_FOREACH (ptr
, serv_list
.head
)
1175 target_p
= ptr
->data
;
1178 sendK
+= target_p
->localClient
->sendK
;
1179 receiveK
+= target_p
->localClient
->receiveK
;
1181 sendto_one(source_p
, Sformat
,
1182 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1183 get_server_name(target_p
, SHOW_IP
),
1184 (int) linebuf_len (&target_p
->localClient
->buf_sendq
),
1185 (int) target_p
->localClient
->sendM
,
1186 (int) target_p
->localClient
->sendK
,
1187 (int) target_p
->localClient
->receiveM
,
1188 (int) target_p
->localClient
->receiveK
,
1189 CurrentTime
- target_p
->localClient
->firsttime
,
1190 (CurrentTime
> target_p
->localClient
->lasttime
) ?
1191 (CurrentTime
- target_p
->localClient
->lasttime
) : 0,
1192 IsOper (source_p
) ? show_capabilities (target_p
) : "TS");
1195 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1196 "? :%u total server(s)", j
);
1198 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1199 "? :Sent total : %7.2f %s",
1200 _GMKv (sendK
), _GMKs (sendK
));
1201 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1202 "? :Recv total : %7.2f %s",
1203 _GMKv (receiveK
), _GMKs (receiveK
));
1205 uptime
= (CurrentTime
- startup_time
);
1207 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1208 "? :Server send: %7.2f %s (%4.1f K/s)",
1209 _GMKv (me
.localClient
->sendK
),
1210 _GMKs (me
.localClient
->sendK
),
1211 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1212 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1213 "? :Server recv: %7.2f %s (%4.1f K/s)",
1214 _GMKv (me
.localClient
->receiveK
),
1215 _GMKs (me
.localClient
->receiveK
),
1216 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1220 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1225 char statchar
= parv
[1][0];
1227 /* this is def targeted at us somehow.. */
1228 if(parc
> 2 && !EmptyString(parv
[2]))
1230 /* directed at us generically? */
1231 if(match(parv
[2], me
.name
) ||
1232 (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1240 wilds
= strchr(name
, '*') || strchr(name
, '?');
1243 /* must be directed at a specific person thats not us */
1244 if(!doall
&& !wilds
)
1246 struct Client
*target_p
;
1248 if(MyClient(source_p
))
1249 target_p
= find_named_person(name
);
1251 target_p
= find_person(name
);
1253 if(target_p
!= NULL
)
1255 stats_spy(source_p
, statchar
, target_p
->name
);
1256 stats_l_client(source_p
, target_p
, statchar
);
1259 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1260 form_str(ERR_NOSUCHSERVER
),
1272 stats_spy(source_p
, statchar
, name
);
1276 /* local opers get everyone */
1277 if(MyOper(source_p
))
1279 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
);
1280 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
);
1284 /* they still need themselves if theyre local.. */
1285 if(MyClient(source_p
))
1286 stats_l_client(source_p
, source_p
, statchar
);
1288 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
);
1291 if (!ConfigServerHide
.flatten_links
|| IsOper(source_p
) ||
1292 IsExemptShide(source_p
))
1293 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
);
1298 /* ok, at this point theyre looking for a specific client whos on
1299 * our server.. but it contains a wildcard. --fl
1301 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
);
1308 stats_l_list(struct Client
*source_p
, const char *name
, int doall
, int wilds
,
1309 dlink_list
* list
, char statchar
)
1312 struct Client
*target_p
;
1314 /* send information about connections which match. note, we
1315 * dont need tests for IsInvisible(), because non-opers will
1316 * never get here for normal clients --fl
1318 DLINK_FOREACH(ptr
, list
->head
)
1320 target_p
= ptr
->data
;
1322 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1325 stats_l_client(source_p
, target_p
, statchar
);
1330 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1333 if(IsAnyServer(target_p
))
1335 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1336 get_server_name(target_p
, SHOW_IP
),
1337 (int) linebuf_len(&target_p
->localClient
->buf_sendq
),
1338 (int) target_p
->localClient
->sendM
,
1339 (int) target_p
->localClient
->sendK
,
1340 (int) target_p
->localClient
->receiveM
,
1341 (int) target_p
->localClient
->receiveK
,
1342 CurrentTime
- target_p
->localClient
->firsttime
,
1343 (CurrentTime
> target_p
->localClient
->lasttime
) ?
1344 (CurrentTime
- target_p
->localClient
->lasttime
) : 0,
1345 IsOper(source_p
) ? show_capabilities(target_p
) : "-");
1350 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1351 show_ip(source_p
, target_p
) ?
1352 (IsUpper(statchar
) ?
1353 get_client_name(target_p
, SHOW_IP
) :
1354 get_client_name(target_p
, HIDE_IP
)) :
1355 get_client_name(target_p
, MASK_IP
),
1356 (int) linebuf_len(&target_p
->localClient
->buf_sendq
),
1357 (int) target_p
->localClient
->sendM
,
1358 (int) target_p
->localClient
->sendK
,
1359 (int) target_p
->localClient
->receiveM
,
1360 (int) target_p
->localClient
->receiveK
,
1361 CurrentTime
- target_p
->localClient
->firsttime
,
1362 (CurrentTime
> target_p
->localClient
->lasttime
) ?
1363 (CurrentTime
- target_p
->localClient
->lasttime
) : 0,
1371 * inputs - pointer to client doing the /stats
1372 * - char letter they are doing /stats on
1375 * This little helper function reports to opers if configured.
1376 * personally, I don't see why opers need to see stats requests
1377 * at all. They are just "noise" to an oper, and users can't do
1378 * any damage with stats requests now anyway. So, why show them?
1382 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1386 data
.client
= source_p
;
1388 data
.arg2
= (int) statchar
;
1390 call_hook(doing_stats_hook
, &data
);
1395 * input - pointer to client doing stats
1397 * side effects - call hook doing_stats_p
1400 stats_p_spy (struct Client
*source_p
)
1404 data
.client
= source_p
;
1405 data
.arg1
= data
.arg2
= NULL
;
1407 call_hook(doing_stats_p_hook
, &data
);