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
)
265 HASH_WALK(i
, U_MAX
, ptr
, ndTable
)
268 sendto_one_notice(source_p
, "Delaying: %s for %ld",
269 nd
->name
, (long) nd
->expire
);
275 stats_hash(struct Client
*source_p
)
277 hash_stats(source_p
);
281 stats_connect(struct Client
*source_p
)
284 struct server_conf
*server_p
;
288 if((ConfigFileEntry
.stats_c_oper_only
||
289 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
292 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
293 form_str(ERR_NOPRIVILEGES
));
297 DLINK_FOREACH(ptr
, server_conf_list
.head
)
299 server_p
= ptr
->data
;
301 if(ServerConfIllegal(server_p
))
309 if(ServerConfAutoconn(server_p
))
311 if(ServerConfTb(server_p
))
313 if(ServerConfCompressed(server_p
))
322 sendto_one_numeric(source_p
, RPL_STATSCLINE
,
323 form_str(RPL_STATSCLINE
),
324 #ifndef HIDE_SERVERS_IPS
330 server_p
->port
, server_p
->class_name
);
336 * input - client to report to
338 * side effects - client is given temp dline list.
341 stats_tdeny (struct Client
*source_p
)
343 char *host
, *pass
, *user
, *oper_reason
;
344 struct AddressRec
*arec
;
345 struct ConfItem
*aconf
;
348 for (i
= 0; i
< ATABLE_SIZE
; i
++)
350 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
352 if(arec
->type
== CONF_DLINE
)
356 if(!(aconf
->flags
& CONF_FLAGS_TEMPORARY
))
359 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
361 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
362 form_str (RPL_STATSDLINE
),
364 oper_reason
? "|" : "",
365 oper_reason
? oper_reason
: "");
373 * input - client to report to
375 * side effects - client is given dline list.
378 stats_deny (struct Client
*source_p
)
380 char *host
, *pass
, *user
, *oper_reason
;
381 struct AddressRec
*arec
;
382 struct ConfItem
*aconf
;
385 for (i
= 0; i
< ATABLE_SIZE
; i
++)
387 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
389 if(arec
->type
== CONF_DLINE
)
393 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
396 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
398 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
399 form_str (RPL_STATSDLINE
),
401 oper_reason
? "|" : "",
402 oper_reason
? oper_reason
: "");
411 * input - client to report to
413 * side effects - client is given list of exempt blocks
416 stats_exempt(struct Client
*source_p
)
418 char *name
, *host
, *pass
, *user
, *classname
;
419 struct AddressRec
*arec
;
420 struct ConfItem
*aconf
;
423 if(ConfigFileEntry
.stats_e_disabled
)
425 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
426 form_str (ERR_NOPRIVILEGES
));
430 for (i
= 0; i
< ATABLE_SIZE
; i
++)
432 for (arec
= atable
[i
]; arec
; arec
= arec
->next
)
434 if(arec
->type
== CONF_EXEMPTDLINE
)
437 get_printable_conf (aconf
, &name
, &host
, &pass
,
438 &user
, &port
, &classname
);
440 sendto_one_numeric(source_p
, RPL_STATSDLINE
,
441 form_str(RPL_STATSDLINE
),
442 'e', host
, pass
, "", "");
449 stats_events (struct Client
*source_p
)
451 show_events (source_p
);
454 /* stats_pending_glines()
456 * input - client pointer
458 * side effects - client is shown list of pending glines
461 stats_pending_glines (struct Client
*source_p
)
463 if(ConfigFileEntry
.glines
)
465 dlink_node
*pending_node
;
466 struct gline_pending
*glp_ptr
;
467 char timebuffer
[MAX_DATE_STRING
];
470 DLINK_FOREACH (pending_node
, pending_glines
.head
)
472 glp_ptr
= pending_node
->data
;
474 tmptr
= localtime (&glp_ptr
->time_request1
);
475 strftime (timebuffer
, MAX_DATE_STRING
, "%Y/%m/%d %H:%M:%S", tmptr
);
477 sendto_one_notice(source_p
,
478 ":1) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
480 glp_ptr
->oper_user1
, glp_ptr
->oper_host1
,
481 glp_ptr
->oper_server1
, timebuffer
,
482 glp_ptr
->user
, glp_ptr
->host
, glp_ptr
->reason1
);
484 if(glp_ptr
->oper_nick2
[0])
486 tmptr
= localtime (&glp_ptr
->time_request2
);
487 strftime (timebuffer
, MAX_DATE_STRING
, "%Y/%m/%d %H:%M:%S", tmptr
);
488 sendto_one_notice(source_p
,
489 ":2) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
491 glp_ptr
->oper_user2
, glp_ptr
->oper_host2
,
492 glp_ptr
->oper_server2
, timebuffer
,
493 glp_ptr
->user
, glp_ptr
->host
, glp_ptr
->reason2
);
497 if(dlink_list_length (&pending_glines
) > 0)
498 sendto_one_notice(source_p
, ":End of Pending G-lines");
501 sendto_one_notice(source_p
, ":This server does not support G-Lines");
507 * input - client pointer
509 * side effects - client is shown list of glines
512 stats_glines (struct Client
*source_p
)
514 if(ConfigFileEntry
.glines
)
516 dlink_node
*gline_node
;
517 struct ConfItem
*kill_ptr
;
519 DLINK_FOREACH_PREV (gline_node
, glines
.tail
)
521 kill_ptr
= gline_node
->data
;
523 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
524 form_str(RPL_STATSKLINE
), 'G',
525 kill_ptr
->host
? kill_ptr
->host
: "*",
526 kill_ptr
->user
? kill_ptr
->user
: "*",
527 kill_ptr
->passwd
? kill_ptr
->passwd
: "No Reason",
528 kill_ptr
->spasswd
? "|" : "",
529 kill_ptr
->spasswd
? kill_ptr
->spasswd
: "");
533 sendto_one_notice(source_p
, ":This server does not support G-Lines");
538 stats_hubleaf(struct Client
*source_p
)
540 struct remote_conf
*hub_p
;
543 if((ConfigFileEntry
.stats_h_oper_only
||
544 (ConfigServerHide
.flatten_links
&& !IsExemptShide(source_p
))) &&
547 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
548 form_str (ERR_NOPRIVILEGES
));
552 DLINK_FOREACH(ptr
, hubleaf_conf_list
.head
)
556 if(hub_p
->flags
& CONF_HUB
)
557 sendto_one_numeric(source_p
, RPL_STATSHLINE
,
558 form_str(RPL_STATSHLINE
),
559 hub_p
->host
, hub_p
->server
);
561 sendto_one_numeric(source_p
, RPL_STATSLLINE
,
562 form_str(RPL_STATSLLINE
),
563 hub_p
->host
, hub_p
->server
);
569 stats_auth (struct Client
*source_p
)
571 /* Oper only, if unopered, return ERR_NOPRIVS */
572 if((ConfigFileEntry
.stats_i_oper_only
== 2) && !IsOper (source_p
))
573 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
574 form_str (ERR_NOPRIVILEGES
));
576 /* If unopered, Only return matching auth blocks */
577 else if((ConfigFileEntry
.stats_i_oper_only
== 1) && !IsOper (source_p
))
579 struct ConfItem
*aconf
;
580 char *name
, *host
, *pass
, *user
, *classname
;
583 if(MyConnect (source_p
))
584 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
585 (struct sockaddr
*)&source_p
->localClient
->ip
,
587 source_p
->localClient
->ip
.ss_family
,
590 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_CLIENT
,
591 0, source_p
->username
);
596 get_printable_conf (aconf
, &name
, &host
, &pass
, &user
, &port
, &classname
);
598 sendto_one_numeric(source_p
, RPL_STATSILINE
, form_str(RPL_STATSILINE
),
599 name
, show_iline_prefix(source_p
, aconf
, user
),
600 host
, port
, classname
);
603 /* Theyre opered, or allowed to see all auth blocks */
605 report_auth (source_p
);
610 stats_tklines(struct Client
*source_p
)
612 /* Oper only, if unopered, return ERR_NOPRIVS */
613 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
614 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
615 form_str (ERR_NOPRIVILEGES
));
617 /* If unopered, Only return matching klines */
618 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
620 struct ConfItem
*aconf
;
621 char *host
, *pass
, *user
, *oper_reason
;
623 if(MyConnect (source_p
))
624 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
625 (struct sockaddr
*)&source_p
->localClient
->ip
,
627 source_p
->localClient
->ip
.ss_family
,
630 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
631 0, source_p
->username
);
636 /* dont report a permanent kline as a tkline */
637 if((aconf
->flags
& CONF_FLAGS_TEMPORARY
) == 0)
640 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
642 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
643 form_str(RPL_STATSKLINE
), 'k',
644 user
, pass
, oper_reason
? "|" : "",
645 oper_reason
? oper_reason
: "");
647 /* Theyre opered, or allowed to see all klines */
650 struct ConfItem
*aconf
;
653 char *user
, *host
, *pass
, *oper_reason
;
655 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
657 DLINK_FOREACH(ptr
, temp_klines
[i
].head
)
661 get_printable_kline(source_p
, aconf
, &host
, &pass
,
662 &user
, &oper_reason
);
664 sendto_one_numeric(source_p
, RPL_STATSKLINE
,
665 form_str(RPL_STATSKLINE
),
666 'k', host
, user
, pass
,
667 oper_reason
? "|" : "",
668 oper_reason
? oper_reason
: "");
675 stats_klines(struct Client
*source_p
)
677 /* Oper only, if unopered, return ERR_NOPRIVS */
678 if((ConfigFileEntry
.stats_k_oper_only
== 2) && !IsOper (source_p
))
679 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
680 form_str (ERR_NOPRIVILEGES
));
682 /* If unopered, Only return matching klines */
683 else if((ConfigFileEntry
.stats_k_oper_only
== 1) && !IsOper (source_p
))
685 struct ConfItem
*aconf
;
686 char *host
, *pass
, *user
, *oper_reason
;
688 /* search for a kline */
689 if(MyConnect (source_p
))
690 aconf
= find_conf_by_address (source_p
->host
, source_p
->sockhost
, NULL
,
691 (struct sockaddr
*)&source_p
->localClient
->ip
,
693 source_p
->localClient
->ip
.ss_family
,
696 aconf
= find_conf_by_address (source_p
->host
, NULL
, NULL
, NULL
, CONF_KILL
,
697 0, source_p
->username
);
702 /* dont report a tkline as a kline */
703 if(aconf
->flags
& CONF_FLAGS_TEMPORARY
)
706 get_printable_kline(source_p
, aconf
, &host
, &pass
, &user
, &oper_reason
);
708 sendto_one_numeric(source_p
, RPL_STATSKLINE
, form_str(RPL_STATSKLINE
),
709 'K', host
, user
, pass
, oper_reason
? "|" : "",
710 oper_reason
? oper_reason
: "");
712 /* Theyre opered, or allowed to see all klines */
714 report_Klines (source_p
);
718 stats_messages(struct Client
*source_p
)
720 report_messages(source_p
);
724 stats_dnsbl(struct Client
*source_p
)
727 struct Blacklist
*blptr
;
729 DLINK_FOREACH(ptr
, blacklist_list
.head
)
733 /* use RPL_STATSDEBUG for now -- jilles */
734 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "n :%d %s %s (%d)",
737 blptr
->status
& CONF_ILLEGAL
? "disabled" : "active",
743 stats_oper(struct Client
*source_p
)
745 struct oper_conf
*oper_p
;
748 if(!IsOper(source_p
) && ConfigFileEntry
.stats_o_oper_only
)
750 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
751 form_str (ERR_NOPRIVILEGES
));
755 DLINK_FOREACH(ptr
, oper_conf_list
.head
)
759 sendto_one_numeric(source_p
, RPL_STATSOLINE
,
760 form_str(RPL_STATSOLINE
),
761 oper_p
->username
, oper_p
->host
, oper_p
->name
,
762 IsOper(source_p
) ? get_oper_privs(oper_p
->flags
) : "0", "-1");
769 * input - client pointer
771 * side effects - client is shown a list of active opers
774 stats_operedup (struct Client
*source_p
)
776 struct Client
*target_p
;
777 dlink_node
*oper_ptr
;
778 unsigned int count
= 0;
780 DLINK_FOREACH (oper_ptr
, oper_list
.head
)
782 target_p
= oper_ptr
->data
;
784 if(IsOperInvis(target_p
) && !IsOper(source_p
))
787 if(target_p
->user
->away
)
792 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
794 target_p
->name
, target_p
->username
,
798 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
799 "p :%u staff members", count
);
801 stats_p_spy (source_p
);
805 stats_ports (struct Client
*source_p
)
807 if(!IsOper (source_p
) && ConfigFileEntry
.stats_P_oper_only
)
808 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
809 form_str (ERR_NOPRIVILEGES
));
811 show_ports (source_p
);
815 stats_tresv(struct Client
*source_p
)
817 struct ConfItem
*aconf
;
821 DLINK_FOREACH(ptr
, resv_conf_list
.head
)
825 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
826 form_str(RPL_STATSQLINE
),
827 'q', aconf
->port
, aconf
->name
, aconf
->passwd
);
830 HASH_WALK(i
, R_MAX
, ptr
, resvTable
)
834 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
835 form_str(RPL_STATSQLINE
),
836 'q', aconf
->port
, aconf
->name
, aconf
->passwd
);
843 stats_resv(struct Client
*source_p
)
845 struct ConfItem
*aconf
;
849 DLINK_FOREACH(ptr
, resv_conf_list
.head
)
853 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
854 form_str(RPL_STATSQLINE
),
855 'Q', aconf
->port
, aconf
->name
, aconf
->passwd
);
858 HASH_WALK(i
, R_MAX
, ptr
, resvTable
)
862 sendto_one_numeric(source_p
, RPL_STATSQLINE
,
863 form_str(RPL_STATSQLINE
),
864 'Q', aconf
->port
, aconf
->name
, aconf
->passwd
);
870 stats_usage (struct Client
*source_p
)
885 if(getrusage(RUSAGE_SELF
, &rus
) == -1)
887 sendto_one_notice(source_p
, ":Getruseage error: %s.",
891 secs
= rus
.ru_utime
.tv_sec
+ rus
.ru_stime
.tv_sec
;
895 rup
= (CurrentTime
- startup_time
) * hzz
;
899 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
900 "R :CPU Secs %d:%d User %d:%d System %d:%d",
901 (int) (secs
/ 60), (int) (secs
% 60),
902 (int) (rus
.ru_utime
.tv_sec
/ 60),
903 (int) (rus
.ru_utime
.tv_sec
% 60),
904 (int) (rus
.ru_stime
.tv_sec
/ 60),
905 (int) (rus
.ru_stime
.tv_sec
% 60));
906 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
907 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
908 rus
.ru_maxrss
, (rus
.ru_ixrss
/ rup
),
909 (rus
.ru_idrss
/ rup
), (rus
.ru_isrss
/ rup
));
910 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
911 "R :Swaps %d Reclaims %d Faults %d",
912 (int) rus
.ru_nswap
, (int) rus
.ru_minflt
, (int) rus
.ru_majflt
);
913 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
914 "R :Block in %d out %d",
915 (int) rus
.ru_inblock
, (int) rus
.ru_oublock
);
916 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
917 "R :Msg Rcv %d Send %d",
918 (int) rus
.ru_msgrcv
, (int) rus
.ru_msgsnd
);
919 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
920 "R :Signals %d Context Vol. %d Invol %d",
921 (int) rus
.ru_nsignals
, (int) rus
.ru_nvcsw
,
922 (int) rus
.ru_nivcsw
);
926 stats_tstats (struct Client
*source_p
)
932 stats_uptime (struct Client
*source_p
)
936 now
= CurrentTime
- startup_time
;
937 sendto_one_numeric(source_p
, RPL_STATSUPTIME
,
938 form_str (RPL_STATSUPTIME
),
939 now
/ 86400, (now
/ 3600) % 24,
940 (now
/ 60) % 60, now
% 60);
941 sendto_one_numeric(source_p
, RPL_STATSCONN
,
942 form_str (RPL_STATSCONN
),
943 MaxConnectionCount
, MaxClientCount
,
944 Count
.totalrestartcount
);
952 static struct shared_flags shared_flagtable
[] =
954 { SHARED_PKLINE
, 'K' },
955 { SHARED_TKLINE
, 'k' },
956 { SHARED_UNKLINE
, 'U' },
957 { SHARED_PXLINE
, 'X' },
958 { SHARED_TXLINE
, 'x' },
959 { SHARED_UNXLINE
, 'Y' },
960 { SHARED_PRESV
, 'Q' },
961 { SHARED_TRESV
, 'q' },
962 { SHARED_UNRESV
, 'R' },
963 { SHARED_LOCOPS
, 'L' },
964 { SHARED_REHASH
, 'H' },
970 stats_shared (struct Client
*source_p
)
972 struct remote_conf
*shared_p
;
978 DLINK_FOREACH(ptr
, shared_conf_list
.head
)
980 shared_p
= ptr
->data
;
986 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
988 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
989 *p
++ = shared_flagtable
[i
].letter
;
994 sendto_one_numeric(source_p
, RPL_STATSULINE
,
995 form_str(RPL_STATSULINE
),
996 shared_p
->server
, shared_p
->username
,
997 shared_p
->host
, buf
);
1000 DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
1002 shared_p
= ptr
->data
;
1008 for(i
= 0; shared_flagtable
[i
].flag
!= 0; i
++)
1010 if(shared_p
->flags
& shared_flagtable
[i
].flag
)
1011 *p
++ = shared_flagtable
[i
].letter
;
1016 sendto_one_numeric(source_p
, RPL_STATSULINE
,
1017 form_str(RPL_STATSULINE
),
1018 shared_p
->server
, "*", "*", buf
);
1024 * input - client pointer
1026 * side effects - client is shown lists of who connected servers
1029 stats_servers (struct Client
*source_p
)
1031 struct Client
*target_p
;
1034 int days
, hours
, minutes
;
1037 if(ConfigServerHide
.flatten_links
&& !IsOper(source_p
) &&
1038 !IsExemptShide(source_p
))
1040 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1041 form_str (ERR_NOPRIVILEGES
));
1045 DLINK_FOREACH (ptr
, serv_list
.head
)
1047 target_p
= ptr
->data
;
1050 seconds
= CurrentTime
- target_p
->localClient
->firsttime
;
1052 days
= (int) (seconds
/ 86400);
1054 hours
= (int) (seconds
/ 3600);
1056 minutes
= (int) (seconds
/ 60);
1059 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1060 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1061 "Connected: %d day%s, %d:%02d:%02d",
1063 (target_p
->serv
->by
[0] ? target_p
->serv
->by
: "Remote."),
1064 (int) (CurrentTime
- target_p
->localClient
->lasttime
),
1065 (int) linebuf_len (&target_p
->localClient
->buf_sendq
),
1066 days
, (days
== 1) ? "" : "s", hours
, minutes
,
1070 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1071 "V :%d Server(s)", j
);
1075 stats_tgecos(struct Client
*source_p
)
1077 struct ConfItem
*aconf
;
1080 DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1085 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1086 form_str(RPL_STATSXLINE
),
1087 'x', aconf
->port
, aconf
->name
,
1093 stats_gecos(struct Client
*source_p
)
1095 struct ConfItem
*aconf
;
1098 DLINK_FOREACH(ptr
, xline_conf_list
.head
)
1103 sendto_one_numeric(source_p
, RPL_STATSXLINE
,
1104 form_str(RPL_STATSXLINE
),
1105 'X', aconf
->port
, aconf
->name
,
1111 stats_class(struct Client
*source_p
)
1113 if(ConfigFileEntry
.stats_y_oper_only
&& !IsOper(source_p
))
1114 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1115 form_str (ERR_NOPRIVILEGES
));
1117 report_classes(source_p
);
1121 stats_memory (struct Client
*source_p
)
1123 count_memory (source_p
);
1127 stats_ziplinks (struct Client
*source_p
)
1130 struct Client
*target_p
;
1133 DLINK_FOREACH (ptr
, serv_list
.head
)
1135 target_p
= ptr
->data
;
1136 if(IsCapable (target_p
, CAP_ZIP
))
1138 /* we use memcpy(3) and a local copy of the structure to
1139 * work around a register use bug on GCC on the SPARC.
1140 * -jmallett, 04/27/2002
1142 struct ZipStats zipstats
;
1143 memcpy (&zipstats
, &target_p
->localClient
->zipstats
,
1144 sizeof (struct ZipStats
));
1145 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1146 "Z :ZipLinks stats for %s send[%.2f%% compression "
1147 "(%lu kB data/%lu kB wire)] recv[%.2f%% compression "
1148 "(%lu kB data/%lu kB wire)]",
1150 zipstats
.out_ratio
, zipstats
.outK
, zipstats
.outK_wire
,
1151 zipstats
.in_ratio
, zipstats
.inK
, zipstats
.inK_wire
);
1156 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1157 "Z :%u ziplink(s)", sent_data
);
1161 stats_servlinks (struct Client
*source_p
)
1163 static char Sformat
[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1164 long uptime
, sendK
, receiveK
;
1165 struct Client
*target_p
;
1169 if(ConfigServerHide
.flatten_links
&& !IsOper (source_p
) &&
1170 !IsExemptShide(source_p
))
1172 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
,
1173 form_str (ERR_NOPRIVILEGES
));
1177 sendK
= receiveK
= 0;
1179 DLINK_FOREACH (ptr
, serv_list
.head
)
1181 target_p
= ptr
->data
;
1184 sendK
+= target_p
->localClient
->sendK
;
1185 receiveK
+= target_p
->localClient
->receiveK
;
1187 sendto_one(source_p
, Sformat
,
1188 get_id(&me
, source_p
), RPL_STATSLINKINFO
, get_id(source_p
, source_p
),
1189 get_server_name(target_p
, SHOW_IP
),
1190 (int) linebuf_len (&target_p
->localClient
->buf_sendq
),
1191 (int) target_p
->localClient
->sendM
,
1192 (int) target_p
->localClient
->sendK
,
1193 (int) target_p
->localClient
->receiveM
,
1194 (int) target_p
->localClient
->receiveK
,
1195 CurrentTime
- target_p
->localClient
->firsttime
,
1196 (CurrentTime
> target_p
->localClient
->lasttime
) ?
1197 (CurrentTime
- target_p
->localClient
->lasttime
) : 0,
1198 IsOper (source_p
) ? show_capabilities (target_p
) : "TS");
1201 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1202 "? :%u total server(s)", j
);
1204 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1205 "? :Sent total : %7.2f %s",
1206 _GMKv (sendK
), _GMKs (sendK
));
1207 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1208 "? :Recv total : %7.2f %s",
1209 _GMKv (receiveK
), _GMKs (receiveK
));
1211 uptime
= (CurrentTime
- startup_time
);
1213 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1214 "? :Server send: %7.2f %s (%4.1f K/s)",
1215 _GMKv (me
.localClient
->sendK
),
1216 _GMKs (me
.localClient
->sendK
),
1217 (float) ((float) me
.localClient
->sendK
/ (float) uptime
));
1218 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
1219 "? :Server recv: %7.2f %s (%4.1f K/s)",
1220 _GMKv (me
.localClient
->receiveK
),
1221 _GMKs (me
.localClient
->receiveK
),
1222 (float) ((float) me
.localClient
->receiveK
/ (float) uptime
));
1226 stats_ltrace(struct Client
*source_p
, int parc
, const char *parv
[])
1231 char statchar
= parv
[1][0];
1233 /* this is def targeted at us somehow.. */
1234 if(parc
> 2 && !EmptyString(parv
[2]))
1236 /* directed at us generically? */
1237 if(match(parv
[2], me
.name
) ||
1238 (!MyClient(source_p
) && !irccmp(parv
[2], me
.id
)))
1246 wilds
= strchr(name
, '*') || strchr(name
, '?');
1249 /* must be directed at a specific person thats not us */
1250 if(!doall
&& !wilds
)
1252 struct Client
*target_p
;
1254 if(MyClient(source_p
))
1255 target_p
= find_named_person(name
);
1257 target_p
= find_person(name
);
1259 if(target_p
!= NULL
)
1261 stats_spy(source_p
, statchar
, target_p
->name
);
1262 stats_l_client(source_p
, target_p
, statchar
);
1265 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1266 form_str(ERR_NOSUCHSERVER
),
1278 stats_spy(source_p
, statchar
, name
);
1282 /* local opers get everyone */
1283 if(MyOper(source_p
))
1285 stats_l_list(source_p
, name
, doall
, wilds
, &unknown_list
, statchar
);
1286 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
);
1290 /* they still need themselves if theyre local.. */
1291 if(MyClient(source_p
))
1292 stats_l_client(source_p
, source_p
, statchar
);
1294 stats_l_list(source_p
, name
, doall
, wilds
, &local_oper_list
, statchar
);
1297 if (!ConfigServerHide
.flatten_links
|| IsOper(source_p
) ||
1298 IsExemptShide(source_p
))
1299 stats_l_list(source_p
, name
, doall
, wilds
, &serv_list
, statchar
);
1304 /* ok, at this point theyre looking for a specific client whos on
1305 * our server.. but it contains a wildcard. --fl
1307 stats_l_list(source_p
, name
, doall
, wilds
, &lclient_list
, statchar
);
1314 stats_l_list(struct Client
*source_p
, const char *name
, int doall
, int wilds
,
1315 dlink_list
* list
, char statchar
)
1318 struct Client
*target_p
;
1320 /* send information about connections which match. note, we
1321 * dont need tests for IsInvisible(), because non-opers will
1322 * never get here for normal clients --fl
1324 DLINK_FOREACH(ptr
, list
->head
)
1326 target_p
= ptr
->data
;
1328 if(!doall
&& wilds
&& !match(name
, target_p
->name
))
1331 stats_l_client(source_p
, target_p
, statchar
);
1336 stats_l_client(struct Client
*source_p
, struct Client
*target_p
,
1339 if(IsAnyServer(target_p
))
1341 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1342 get_server_name(target_p
, SHOW_IP
),
1343 (int) linebuf_len(&target_p
->localClient
->buf_sendq
),
1344 (int) target_p
->localClient
->sendM
,
1345 (int) target_p
->localClient
->sendK
,
1346 (int) target_p
->localClient
->receiveM
,
1347 (int) target_p
->localClient
->receiveK
,
1348 CurrentTime
- target_p
->localClient
->firsttime
,
1349 (CurrentTime
> target_p
->localClient
->lasttime
) ?
1350 (CurrentTime
- target_p
->localClient
->lasttime
) : 0,
1351 IsOper(source_p
) ? show_capabilities(target_p
) : "-");
1356 sendto_one_numeric(source_p
, RPL_STATSLINKINFO
, Lformat
,
1357 show_ip(source_p
, target_p
) ?
1358 (IsUpper(statchar
) ?
1359 get_client_name(target_p
, SHOW_IP
) :
1360 get_client_name(target_p
, HIDE_IP
)) :
1361 get_client_name(target_p
, MASK_IP
),
1362 (int) linebuf_len(&target_p
->localClient
->buf_sendq
),
1363 (int) target_p
->localClient
->sendM
,
1364 (int) target_p
->localClient
->sendK
,
1365 (int) target_p
->localClient
->receiveM
,
1366 (int) target_p
->localClient
->receiveK
,
1367 CurrentTime
- target_p
->localClient
->firsttime
,
1368 (CurrentTime
> target_p
->localClient
->lasttime
) ?
1369 (CurrentTime
- target_p
->localClient
->lasttime
) : 0,
1377 * inputs - pointer to client doing the /stats
1378 * - char letter they are doing /stats on
1381 * This little helper function reports to opers if configured.
1382 * personally, I don't see why opers need to see stats requests
1383 * at all. They are just "noise" to an oper, and users can't do
1384 * any damage with stats requests now anyway. So, why show them?
1388 stats_spy(struct Client
*source_p
, char statchar
, const char *name
)
1392 data
.client
= source_p
;
1394 data
.arg2
= (int) statchar
;
1396 call_hook(doing_stats_hook
, &data
);
1401 * input - pointer to client doing stats
1403 * side effects - call hook doing_stats_p
1406 stats_p_spy (struct Client
*source_p
)
1410 data
.client
= source_p
;
1411 data
.arg1
= data
.arg2
= NULL
;
1413 call_hook(doing_stats_p_hook
, &data
);