]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_stats.c
notify_banned_client cleaned up
[irc/rqf/shadowircd.git] / modules / m_stats.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd).
3 * m_stats.c: Sends the user statistics or config information.
4 *
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
8 *
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.
13 *
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.
18 *
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
22 * USA
23 *
24 * $Id: m_stats.c 1608 2006-06-04 02:11:40Z jilles $
25 */
26
27#include "stdinc.h"
212380e3 28#include "class.h" /* report_classes */
29#include "client.h" /* Client */
30#include "common.h" /* TRUE/FALSE */
13ae2f4b 31#include "match.h"
212380e3 32#include "ircd.h" /* me */
33#include "listener.h" /* show_ports */
212380e3 34#include "msg.h" /* Message */
35#include "hostmask.h" /* report_mtrie_conf_links */
36#include "numeric.h" /* ERR_xxx */
37#include "scache.h" /* list_scache */
38#include "send.h" /* sendto_one */
212380e3 39#include "s_conf.h" /* ConfItem */
40#include "s_serv.h" /* hunt_server */
83251205 41#include "s_stats.h"
212380e3 42#include "s_user.h" /* show_opers */
212380e3 43#include "blacklist.h" /* dnsbl stuff */
212380e3 44#include "parse.h"
45#include "modules.h"
46#include "hook.h"
47#include "s_newconf.h"
48#include "hash.h"
83251205
VY
49#include "reject.h"
50#include "whowas.h"
212380e3 51
52static int m_stats (struct Client *, struct Client *, int, const char **);
53
54struct Message stats_msgtab = {
55 "STATS", 0, 0, 0, MFLG_SLOW,
56 {mg_unreg, {m_stats, 2}, {m_stats, 3}, mg_ignore, mg_ignore, {m_stats, 2}}
57};
58
59int doing_stats_hook;
60int doing_stats_p_hook;
61
62mapi_clist_av1 stats_clist[] = { &stats_msgtab, NULL };
63mapi_hlist_av1 stats_hlist[] = {
64 { "doing_stats", &doing_stats_hook },
65 { "doing_stats_p", &doing_stats_p_hook },
66 { NULL, NULL }
67};
68
69DECLARE_MODULE_AV1(stats, NULL, NULL, stats_clist, stats_hlist, NULL, "$Revision: 1608 $");
70
71const char *Lformat = "%s %u %u %u %u %u :%u %u %s";
72
08d11e34 73static void stats_l_list(struct Client *s, const char *, int, int, rb_dlink_list *, char);
212380e3 74static void stats_l_client(struct Client *source_p, struct Client *target_p,
75 char statchar);
76
77static void stats_spy(struct Client *, char, const char *);
78static void stats_p_spy(struct Client *);
79
80/* Heres our struct for the stats table */
81struct StatsStruct
82{
83 char letter;
4a4ea261 84 void (*handler) (struct Client *source_p);
212380e3 85 int need_oper;
86 int need_admin;
87};
88
4a4ea261 89static void stats_dns_servers(struct Client *);
212380e3 90static void stats_delay(struct Client *);
91static void stats_hash(struct Client *);
92static void stats_connect(struct Client *);
93static void stats_tdeny(struct Client *);
94static void stats_deny(struct Client *);
95static void stats_exempt(struct Client *);
96static void stats_events(struct Client *);
212380e3 97static void stats_hubleaf(struct Client *);
98static void stats_auth(struct Client *);
99static void stats_tklines(struct Client *);
100static void stats_klines(struct Client *);
101static void stats_messages(struct Client *);
102static void stats_dnsbl(struct Client *);
103static void stats_oper(struct Client *);
104static void stats_operedup(struct Client *);
105static void stats_ports(struct Client *);
106static void stats_tresv(struct Client *);
107static void stats_resv(struct Client *);
108static void stats_usage(struct Client *);
109static void stats_tstats(struct Client *);
110static void stats_uptime(struct Client *);
111static void stats_shared(struct Client *);
112static void stats_servers(struct Client *);
113static void stats_tgecos(struct Client *);
114static void stats_gecos(struct Client *);
115static void stats_class(struct Client *);
116static void stats_memory(struct Client *);
117static void stats_servlinks(struct Client *);
118static void stats_ltrace(struct Client *, int, const char **);
119static void stats_ziplinks(struct Client *);
b8127271 120static void stats_comm(struct Client *);
212380e3 121/* This table contains the possible stats items, in order:
122 * stats letter, function to call, operonly? adminonly?
123 * case only matters in the stats letter column.. -- fl_
124 */
125static struct StatsStruct stats_cmd_table[] = {
126 /* letter function need_oper need_admin */
127 {'a', stats_dns_servers, 1, 1, },
128 {'A', stats_dns_servers, 1, 1, },
129 {'b', stats_delay, 1, 1, },
130 {'B', stats_hash, 1, 1, },
131 {'c', stats_connect, 0, 0, },
132 {'C', stats_connect, 0, 0, },
133 {'d', stats_tdeny, 1, 0, },
134 {'D', stats_deny, 1, 0, },
135 {'e', stats_exempt, 1, 0, },
136 {'E', stats_events, 1, 1, },
b8127271
VY
137 {'f', stats_comm, 1, 1, },
138 {'F', stats_comm, 1, 1, },
212380e3 139 {'h', stats_hubleaf, 0, 0, },
140 {'H', stats_hubleaf, 0, 0, },
141 {'i', stats_auth, 0, 0, },
142 {'I', stats_auth, 0, 0, },
143 {'k', stats_tklines, 0, 0, },
144 {'K', stats_klines, 0, 0, },
4a4ea261
JT
145 {'l', NULL /* special */, 0, 0, },
146 {'L', NULL /* special */, 0, 0, },
212380e3 147 {'m', stats_messages, 0, 0, },
148 {'M', stats_messages, 0, 0, },
149 {'n', stats_dnsbl, 0, 0, },
150 {'o', stats_oper, 0, 0, },
151 {'O', stats_oper, 0, 0, },
152 {'p', stats_operedup, 0, 0, },
153 {'P', stats_ports, 0, 0, },
154 {'q', stats_tresv, 1, 0, },
155 {'Q', stats_resv, 1, 0, },
156 {'r', stats_usage, 1, 0, },
157 {'R', stats_usage, 1, 0, },
158 {'t', stats_tstats, 1, 0, },
159 {'T', stats_tstats, 1, 0, },
160 {'u', stats_uptime, 0, 0, },
161 {'U', stats_shared, 1, 0, },
162 {'v', stats_servers, 0, 0, },
163 {'V', stats_servers, 0, 0, },
164 {'x', stats_tgecos, 1, 0, },
165 {'X', stats_gecos, 1, 0, },
166 {'y', stats_class, 0, 0, },
167 {'Y', stats_class, 0, 0, },
168 {'z', stats_memory, 1, 0, },
169 {'Z', stats_ziplinks, 1, 0, },
170 {'?', stats_servlinks, 0, 0, },
171 {(char) 0, (void (*)()) 0, 0, 0, }
172};
173
174/*
175 * m_stats by fl_
176 * parv[0] = sender prefix
177 * parv[1] = stat letter/command
178 * parv[2] = (if present) server/mask in stats L, or target
179 *
180 * This will search the tables for the appropriate stats letter,
181 * if found execute it.
182 */
183static int
184m_stats(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
185{
186 static time_t last_used = 0;
187 int i;
188 char statchar;
189
190 statchar = parv[1][0];
191
192 if(MyClient(source_p) && !IsOper(source_p))
193 {
194 /* Check the user is actually allowed to do /stats, and isnt flooding */
9f6bbe3c 195 if((last_used + ConfigFileEntry.pace_wait) > rb_current_time())
212380e3 196 {
197 /* safe enough to give this on a local connect only */
198 sendto_one(source_p, form_str(RPL_LOAD2HI),
199 me.name, source_p->name, "STATS");
200 sendto_one_numeric(source_p, RPL_ENDOFSTATS,
201 form_str(RPL_ENDOFSTATS), statchar);
202 return 0;
203 }
204 else
9f6bbe3c 205 last_used = rb_current_time();
212380e3 206 }
207
208 if(hunt_server (client_p, source_p, ":%s STATS %s :%s", 2, parc, parv) != HUNTED_ISME)
209 return 0;
210
211 if((statchar != 'L') && (statchar != 'l'))
212 stats_spy(source_p, statchar, NULL);
213
4a4ea261 214 for (i = 0; stats_cmd_table[i].letter; i++)
212380e3 215 {
216 if(stats_cmd_table[i].letter == statchar)
217 {
218 /* The stats table says what privs are needed, so check --fl_ */
219 /* Called for remote clients and for local opers, so check need_admin
220 * and need_oper
221 */
ff74c93a 222 if(stats_cmd_table[i].need_oper && !IsOper(source_p))
212380e3 223 {
224 sendto_one_numeric(source_p, ERR_NOPRIVILEGES,
225 form_str (ERR_NOPRIVILEGES));
226 break;
227 }
ff74c93a
JT
228 if(stats_cmd_table[i].need_admin && !IsOperAdmin(source_p))
229 {
230 sendto_one(source_p, form_str(ERR_NOPRIVS),
231 me.name, source_p->name, "admin");
232 break;
233 }
212380e3 234
235 /* Blah, stats L needs the parameters, none of the others do.. */
236 if(statchar == 'L' || statchar == 'l')
4a4ea261 237 stats_ltrace (source_p, parc, parv);
212380e3 238 else
239 stats_cmd_table[i].handler (source_p);
240 }
241 }
242
243 /* Send the end of stats notice, and the stats_spy */
244 sendto_one_numeric(source_p, RPL_ENDOFSTATS,
245 form_str(RPL_ENDOFSTATS), statchar);
246
247 return 0;
248}
249
250static void
251stats_dns_servers (struct Client *source_p)
252{
253 report_dns_servers (source_p);
254}
255
256static void
257stats_delay(struct Client *source_p)
258{
259 struct nd_entry *nd;
b37021a4 260 struct DictionaryIter iter;
212380e3 261
b37021a4 262 DICTIONARY_FOREACH(nd, &iter, nd_dict)
212380e3 263 {
d1264ac8 264 sendto_one_notice(source_p, ":Delaying: %s for %ld",
212380e3 265 nd->name, (long) nd->expire);
266 }
212380e3 267}
268
269static void
270stats_hash(struct Client *source_p)
271{
272 hash_stats(source_p);
273}
274
275static void
276stats_connect(struct Client *source_p)
277{
278 static char buf[5];
279 struct server_conf *server_p;
280 char *s;
08d11e34 281 rb_dlink_node *ptr;
212380e3 282
283 if((ConfigFileEntry.stats_c_oper_only ||
284 (ConfigServerHide.flatten_links && !IsExemptShide(source_p))) &&
285 !IsOper(source_p))
286 {
287 sendto_one_numeric(source_p, ERR_NOPRIVILEGES,
288 form_str(ERR_NOPRIVILEGES));
289 return;
290 }
291
08d11e34 292 RB_DLINK_FOREACH(ptr, server_conf_list.head)
212380e3 293 {
294 server_p = ptr->data;
295
296 if(ServerConfIllegal(server_p))
297 continue;
298
299 buf[0] = '\0';
300 s = buf;
301
302 if(IsOper(source_p))
303 {
304 if(ServerConfAutoconn(server_p))
305 *s++ = 'A';
b717a466 306 if(ServerConfSSL(server_p))
92b89763 307 *s++ = 'S';
212380e3 308 if(ServerConfTb(server_p))
309 *s++ = 'T';
310 if(ServerConfCompressed(server_p))
311 *s++ = 'Z';
312 }
313
314 if(!buf[0])
315 *s++ = '*';
316
317 *s = '\0';
318
319 sendto_one_numeric(source_p, RPL_STATSCLINE,
320 form_str(RPL_STATSCLINE),
321#ifndef HIDE_SERVERS_IPS
322 server_p->host,
323#else
324 "*@127.0.0.1",
325#endif
326 buf, server_p->name,
327 server_p->port, server_p->class_name);
328 }
329}
330
331/* stats_tdeny()
332 *
333 * input - client to report to
334 * output - none
335 * side effects - client is given temp dline list.
336 */
337static void
338stats_tdeny (struct Client *source_p)
339{
340 char *host, *pass, *user, *oper_reason;
341 struct AddressRec *arec;
342 struct ConfItem *aconf;
343 int i;
344
345 for (i = 0; i < ATABLE_SIZE; i++)
346 {
347 for (arec = atable[i]; arec; arec = arec->next)
348 {
349 if(arec->type == CONF_DLINE)
350 {
351 aconf = arec->aconf;
352
353 if(!(aconf->flags & CONF_FLAGS_TEMPORARY))
354 continue;
355
356 get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason);
357
358 sendto_one_numeric(source_p, RPL_STATSDLINE,
359 form_str (RPL_STATSDLINE),
360 'd', host, pass,
361 oper_reason ? "|" : "",
362 oper_reason ? oper_reason : "");
363 }
364 }
365 }
366}
367
368/* stats_deny()
369 *
370 * input - client to report to
371 * output - none
372 * side effects - client is given dline list.
373 */
374static void
375stats_deny (struct Client *source_p)
376{
377 char *host, *pass, *user, *oper_reason;
378 struct AddressRec *arec;
379 struct ConfItem *aconf;
380 int i;
381
382 for (i = 0; i < ATABLE_SIZE; i++)
383 {
384 for (arec = atable[i]; arec; arec = arec->next)
385 {
386 if(arec->type == CONF_DLINE)
387 {
388 aconf = arec->aconf;
389
390 if(aconf->flags & CONF_FLAGS_TEMPORARY)
391 continue;
392
393 get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason);
394
395 sendto_one_numeric(source_p, RPL_STATSDLINE,
396 form_str (RPL_STATSDLINE),
397 'D', host, pass,
398 oper_reason ? "|" : "",
399 oper_reason ? oper_reason : "");
400 }
401 }
402 }
403}
404
405
406/* stats_exempt()
407 *
408 * input - client to report to
409 * output - none
410 * side effects - client is given list of exempt blocks
411 */
412static void
413stats_exempt(struct Client *source_p)
414{
415 char *name, *host, *pass, *user, *classname;
416 struct AddressRec *arec;
417 struct ConfItem *aconf;
418 int i, port;
419
420 if(ConfigFileEntry.stats_e_disabled)
421 {
889b0321
JT
422 sendto_one_numeric(source_p, ERR_DISABLED,
423 form_str(ERR_DISABLED), "STATS e");
212380e3 424 return;
425 }
426
427 for (i = 0; i < ATABLE_SIZE; i++)
428 {
429 for (arec = atable[i]; arec; arec = arec->next)
430 {
431 if(arec->type == CONF_EXEMPTDLINE)
432 {
433 aconf = arec->aconf;
434 get_printable_conf (aconf, &name, &host, &pass,
435 &user, &port, &classname);
436
437 sendto_one_numeric(source_p, RPL_STATSDLINE,
438 form_str(RPL_STATSDLINE),
439 'e', host, pass, "", "");
440 }
441 }
442 }}
443
444
9df69d5b
JT
445static void
446stats_events_cb(char *str, void *ptr)
447{
448 sendto_one_numeric(ptr, RPL_STATSDEBUG, "E :%s", str);
449}
450
451static void
452stats_events (struct Client *source_p)
453{
454 rb_dump_events(stats_events_cb, source_p);
212380e3 455}
456
212380e3 457static void
458stats_hubleaf(struct Client *source_p)
459{
460 struct remote_conf *hub_p;
08d11e34 461 rb_dlink_node *ptr;
212380e3 462
463 if((ConfigFileEntry.stats_h_oper_only ||
464 (ConfigServerHide.flatten_links && !IsExemptShide(source_p))) &&
465 !IsOper(source_p))
466 {
467 sendto_one_numeric(source_p, ERR_NOPRIVILEGES,
468 form_str (ERR_NOPRIVILEGES));
469 return;
470 }
471
08d11e34 472 RB_DLINK_FOREACH(ptr, hubleaf_conf_list.head)
212380e3 473 {
474 hub_p = ptr->data;
475
476 if(hub_p->flags & CONF_HUB)
477 sendto_one_numeric(source_p, RPL_STATSHLINE,
478 form_str(RPL_STATSHLINE),
479 hub_p->host, hub_p->server);
480 else
481 sendto_one_numeric(source_p, RPL_STATSLLINE,
482 form_str(RPL_STATSLLINE),
483 hub_p->host, hub_p->server);
484 }
485}
486
487
488static void
489stats_auth (struct Client *source_p)
490{
491 /* Oper only, if unopered, return ERR_NOPRIVS */
492 if((ConfigFileEntry.stats_i_oper_only == 2) && !IsOper (source_p))
493 sendto_one_numeric(source_p, ERR_NOPRIVILEGES,
494 form_str (ERR_NOPRIVILEGES));
495
496 /* If unopered, Only return matching auth blocks */
497 else if((ConfigFileEntry.stats_i_oper_only == 1) && !IsOper (source_p))
498 {
499 struct ConfItem *aconf;
969a1ae6 500 char *name, *host, *pass = "*", *user, *classname;
212380e3 501 int port;
502
503 if(MyConnect (source_p))
504 aconf = find_conf_by_address (source_p->host, source_p->sockhost, NULL,
505 (struct sockaddr *)&source_p->localClient->ip,
506 CONF_CLIENT,
507 source_p->localClient->ip.ss_family,
969a1ae6 508 source_p->username, NULL);
212380e3 509 else
510 aconf = find_conf_by_address (source_p->host, NULL, NULL, NULL, CONF_CLIENT,
969a1ae6 511 0, source_p->username, NULL);
212380e3 512
513 if(aconf == NULL)
514 return;
515
516 get_printable_conf (aconf, &name, &host, &pass, &user, &port, &classname);
969a1ae6
VY
517 if(!EmptyString(aconf->spasswd))
518 pass = aconf->spasswd;
212380e3 519
520 sendto_one_numeric(source_p, RPL_STATSILINE, form_str(RPL_STATSILINE),
969a1ae6 521 name, pass, show_iline_prefix(source_p, aconf, user),
212380e3 522 host, port, classname);
523 }
524
525 /* Theyre opered, or allowed to see all auth blocks */
526 else
527 report_auth (source_p);
528}
529
530
531static void
532stats_tklines(struct Client *source_p)
533{
534 /* Oper only, if unopered, return ERR_NOPRIVS */
535 if((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper (source_p))
536 sendto_one_numeric(source_p, ERR_NOPRIVILEGES,
537 form_str (ERR_NOPRIVILEGES));
538
539 /* If unopered, Only return matching klines */
540 else if((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper (source_p))
541 {
542 struct ConfItem *aconf;
543 char *host, *pass, *user, *oper_reason;
544
545 if(MyConnect (source_p))
546 aconf = find_conf_by_address (source_p->host, source_p->sockhost, NULL,
547 (struct sockaddr *)&source_p->localClient->ip,
548 CONF_KILL,
549 source_p->localClient->ip.ss_family,
969a1ae6 550 source_p->username, NULL);
212380e3 551 else
552 aconf = find_conf_by_address (source_p->host, NULL, NULL, NULL, CONF_KILL,
969a1ae6 553 0, source_p->username, NULL);
212380e3 554
555 if(aconf == NULL)
556 return;
557
558 /* dont report a permanent kline as a tkline */
559 if((aconf->flags & CONF_FLAGS_TEMPORARY) == 0)
560 return;
561
562 get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason);
563
564 sendto_one_numeric(source_p, RPL_STATSKLINE,
8eee9ee1
JT
565 form_str(RPL_STATSKLINE), aconf->flags & CONF_FLAGS_TEMPORARY ? 'k' : 'K',
566 host, user, pass, oper_reason ? "|" : "",
212380e3 567 oper_reason ? oper_reason : "");
568 }
569 /* Theyre opered, or allowed to see all klines */
570 else
571 {
572 struct ConfItem *aconf;
08d11e34 573 rb_dlink_node *ptr;
212380e3 574 int i;
575 char *user, *host, *pass, *oper_reason;
576
577 for(i = 0; i < LAST_TEMP_TYPE; i++)
578 {
08d11e34 579 RB_DLINK_FOREACH(ptr, temp_klines[i].head)
212380e3 580 {
581 aconf = ptr->data;
582
583 get_printable_kline(source_p, aconf, &host, &pass,
584 &user, &oper_reason);
585
586 sendto_one_numeric(source_p, RPL_STATSKLINE,
587 form_str(RPL_STATSKLINE),
588 'k', host, user, pass,
589 oper_reason ? "|" : "",
590 oper_reason ? oper_reason : "");
591 }
592 }
593 }
594}
595
596static void
597stats_klines(struct Client *source_p)
598{
599 /* Oper only, if unopered, return ERR_NOPRIVS */
600 if((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper (source_p))
601 sendto_one_numeric(source_p, ERR_NOPRIVILEGES,
602 form_str (ERR_NOPRIVILEGES));
603
604 /* If unopered, Only return matching klines */
605 else if((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper (source_p))
606 {
607 struct ConfItem *aconf;
608 char *host, *pass, *user, *oper_reason;
609
610 /* search for a kline */
611 if(MyConnect (source_p))
612 aconf = find_conf_by_address (source_p->host, source_p->sockhost, NULL,
613 (struct sockaddr *)&source_p->localClient->ip,
614 CONF_KILL,
615 source_p->localClient->ip.ss_family,
969a1ae6 616 source_p->username, NULL);
212380e3 617 else
618 aconf = find_conf_by_address (source_p->host, NULL, NULL, NULL, CONF_KILL,
969a1ae6 619 0, source_p->username, NULL);
212380e3 620
621 if(aconf == NULL)
622 return;
623
212380e3 624 get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason);
625
626 sendto_one_numeric(source_p, RPL_STATSKLINE, form_str(RPL_STATSKLINE),
8eee9ee1
JT
627 aconf->flags & CONF_FLAGS_TEMPORARY ? 'k' : 'K',
628 host, user, pass, oper_reason ? "|" : "",
212380e3 629 oper_reason ? oper_reason : "");
630 }
631 /* Theyre opered, or allowed to see all klines */
632 else
633 report_Klines (source_p);
634}
635
636static void
637stats_messages(struct Client *source_p)
638{
639 report_messages(source_p);
640}
641
642static void
643stats_dnsbl(struct Client *source_p)
644{
08d11e34 645 rb_dlink_node *ptr;
212380e3 646 struct Blacklist *blptr;
647
08d11e34 648 RB_DLINK_FOREACH(ptr, blacklist_list.head)
212380e3 649 {
650 blptr = ptr->data;
651
652 /* use RPL_STATSDEBUG for now -- jilles */
653 sendto_one_numeric(source_p, RPL_STATSDEBUG, "n :%d %s %s (%d)",
654 blptr->hits,
655 blptr->host,
656 blptr->status & CONF_ILLEGAL ? "disabled" : "active",
657 blptr->refcount);
658 }
659}
660
661static void
662stats_oper(struct Client *source_p)
663{
664 struct oper_conf *oper_p;
08d11e34 665 rb_dlink_node *ptr;
212380e3 666
667 if(!IsOper(source_p) && ConfigFileEntry.stats_o_oper_only)
668 {
669 sendto_one_numeric(source_p, ERR_NOPRIVILEGES,
670 form_str (ERR_NOPRIVILEGES));
671 return;
672 }
673
08d11e34 674 RB_DLINK_FOREACH(ptr, oper_conf_list.head)
212380e3 675 {
676 oper_p = ptr->data;
677
678 sendto_one_numeric(source_p, RPL_STATSOLINE,
679 form_str(RPL_STATSOLINE),
680 oper_p->username, oper_p->host, oper_p->name,
681 IsOper(source_p) ? get_oper_privs(oper_p->flags) : "0", "-1");
682 }
683}
684
685
686/* stats_operedup()
687 *
688 * input - client pointer
689 * output - none
690 * side effects - client is shown a list of active opers
691 */
692static void
693stats_operedup (struct Client *source_p)
694{
695 struct Client *target_p;
08d11e34 696 rb_dlink_node *oper_ptr;
212380e3 697 unsigned int count = 0;
698
08d11e34 699 RB_DLINK_FOREACH (oper_ptr, oper_list.head)
212380e3 700 {
701 target_p = oper_ptr->data;
702
703 if(IsOperInvis(target_p) && !IsOper(source_p))
704 continue;
705
706 if(target_p->user->away)
707 continue;
708
709 count++;
710
711 sendto_one_numeric(source_p, RPL_STATSDEBUG,
712 "p :%s (%s@%s)",
713 target_p->name, target_p->username,
714 target_p->host);
715 }
716
717 sendto_one_numeric(source_p, RPL_STATSDEBUG,
718 "p :%u staff members", count);
719
720 stats_p_spy (source_p);
721}
722
723static void
724stats_ports (struct Client *source_p)
725{
726 if(!IsOper (source_p) && ConfigFileEntry.stats_P_oper_only)
727 sendto_one_numeric(source_p, ERR_NOPRIVILEGES,
728 form_str (ERR_NOPRIVILEGES));
729 else
730 show_ports (source_p);
731}
732
733static void
734stats_tresv(struct Client *source_p)
735{
736 struct ConfItem *aconf;
08d11e34 737 rb_dlink_node *ptr;
212380e3 738 int i;
739
08d11e34 740 RB_DLINK_FOREACH(ptr, resv_conf_list.head)
212380e3 741 {
742 aconf = ptr->data;
743 if(aconf->hold)
744 sendto_one_numeric(source_p, RPL_STATSQLINE,
745 form_str(RPL_STATSQLINE),
746 'q', aconf->port, aconf->name, aconf->passwd);
747 }
748
749 HASH_WALK(i, R_MAX, ptr, resvTable)
750 {
751 aconf = ptr->data;
752 if(aconf->hold)
753 sendto_one_numeric(source_p, RPL_STATSQLINE,
754 form_str(RPL_STATSQLINE),
755 'q', aconf->port, aconf->name, aconf->passwd);
756 }
757 HASH_WALK_END
758}
759
760
761static void
762stats_resv(struct Client *source_p)
763{
764 struct ConfItem *aconf;
08d11e34 765 rb_dlink_node *ptr;
212380e3 766 int i;
767
08d11e34 768 RB_DLINK_FOREACH(ptr, resv_conf_list.head)
212380e3 769 {
770 aconf = ptr->data;
771 if(!aconf->hold)
772 sendto_one_numeric(source_p, RPL_STATSQLINE,
773 form_str(RPL_STATSQLINE),
774 'Q', aconf->port, aconf->name, aconf->passwd);
775 }
776
777 HASH_WALK(i, R_MAX, ptr, resvTable)
778 {
779 aconf = ptr->data;
780 if(!aconf->hold)
781 sendto_one_numeric(source_p, RPL_STATSQLINE,
782 form_str(RPL_STATSQLINE),
783 'Q', aconf->port, aconf->name, aconf->passwd);
784 }
785 HASH_WALK_END
786}
787
788static void
789stats_usage (struct Client *source_p)
790{
791 struct rusage rus;
792 time_t secs;
793 time_t rup;
794#ifdef hz
795# define hzz hz
796#else
797# ifdef HZ
798# define hzz HZ
799# else
800 int hzz = 1;
801# endif
802#endif
803
804 if(getrusage(RUSAGE_SELF, &rus) == -1)
805 {
806 sendto_one_notice(source_p, ":Getruseage error: %s.",
807 strerror(errno));
808 return;
809 }
810 secs = rus.ru_utime.tv_sec + rus.ru_stime.tv_sec;
811 if(0 == secs)
812 secs = 1;
813
9f6bbe3c 814 rup = (rb_current_time() - startup_time) * hzz;
212380e3 815 if(0 == rup)
816 rup = 1;
817
818 sendto_one_numeric(source_p, RPL_STATSDEBUG,
819 "R :CPU Secs %d:%d User %d:%d System %d:%d",
820 (int) (secs / 60), (int) (secs % 60),
821 (int) (rus.ru_utime.tv_sec / 60),
822 (int) (rus.ru_utime.tv_sec % 60),
823 (int) (rus.ru_stime.tv_sec / 60),
824 (int) (rus.ru_stime.tv_sec % 60));
825 sendto_one_numeric(source_p, RPL_STATSDEBUG,
826 "R :RSS %ld ShMem %ld Data %ld Stack %ld",
827 rus.ru_maxrss, (rus.ru_ixrss / rup),
828 (rus.ru_idrss / rup), (rus.ru_isrss / rup));
829 sendto_one_numeric(source_p, RPL_STATSDEBUG,
830 "R :Swaps %d Reclaims %d Faults %d",
831 (int) rus.ru_nswap, (int) rus.ru_minflt, (int) rus.ru_majflt);
832 sendto_one_numeric(source_p, RPL_STATSDEBUG,
833 "R :Block in %d out %d",
834 (int) rus.ru_inblock, (int) rus.ru_oublock);
835 sendto_one_numeric(source_p, RPL_STATSDEBUG,
836 "R :Msg Rcv %d Send %d",
837 (int) rus.ru_msgrcv, (int) rus.ru_msgsnd);
838 sendto_one_numeric(source_p, RPL_STATSDEBUG,
839 "R :Signals %d Context Vol. %d Invol %d",
840 (int) rus.ru_nsignals, (int) rus.ru_nvcsw,
841 (int) rus.ru_nivcsw);
842}
843
21c9d815
VY
844static void
845stats_tstats (struct Client *source_p)
846{
83251205
VY
847 struct Client *target_p;
848 struct ServerStatistics sp;
849 rb_dlink_node *ptr;
850
851 memcpy(&sp, &ServerStats, sizeof(struct ServerStatistics));
852
b717a466
JT
853 RB_DLINK_FOREACH(ptr, serv_list.head)
854 {
855 target_p = ptr->data;
856
857 sp.is_sbs += target_p->localClient->sendB;
858 sp.is_sbr += target_p->localClient->receiveB;
859 sp.is_sti += rb_current_time() - target_p->localClient->firsttime;
860 sp.is_sv++;
861 }
862
863 RB_DLINK_FOREACH(ptr, lclient_list.head)
864 {
865 target_p = ptr->data;
866
867 sp.is_cbs += target_p->localClient->sendB;
868 sp.is_cbr += target_p->localClient->receiveB;
869 sp.is_cti += rb_current_time() - target_p->localClient->firsttime;
870 sp.is_cl++;
83251205
VY
871 }
872
873 RB_DLINK_FOREACH(ptr, unknown_list.head)
874 {
875 sp.is_ni++;
876 }
877
878 sendto_one_numeric(source_p, RPL_STATSDEBUG,
879 "T :accepts %u refused %u", sp.is_ac, sp.is_ref);
880 sendto_one_numeric(source_p, RPL_STATSDEBUG,
881 "T :rejected %u delaying %lu",
882 sp.is_rej, rb_dlink_list_length(&delay_exit));
883 sendto_one_numeric(source_p, RPL_STATSDEBUG,
884 "T :nicks being delayed %lu",
885 get_nd_count());
886 sendto_one_numeric(source_p, RPL_STATSDEBUG,
887 "T :unknown commands %u prefixes %u",
888 sp.is_unco, sp.is_unpf);
889 sendto_one_numeric(source_p, RPL_STATSDEBUG,
890 "T :nick collisions %u saves %u unknown closes %u",
891 sp.is_kill, sp.is_save, sp.is_ni);
892 sendto_one_numeric(source_p, RPL_STATSDEBUG,
893 "T :wrong direction %u empty %u",
894 sp.is_wrdi, sp.is_empt);
895 sendto_one_numeric(source_p, RPL_STATSDEBUG,
896 "T :numerics seen %u", sp.is_num);
897 sendto_one_numeric(source_p, RPL_STATSDEBUG,
898 "T :tgchange blocked msgs %u restricted addrs %lu",
899 sp.is_tgch, rb_dlink_list_length(&tgchange_list));
900 sendto_one_numeric(source_p, RPL_STATSDEBUG,
901 "T :auth successes %u fails %u",
902 sp.is_asuc, sp.is_abad);
903 sendto_one_numeric(source_p, RPL_STATSDEBUG,
904 "T :sasl successes %u fails %u",
905 sp.is_ssuc, sp.is_sbad);
906 sendto_one_numeric(source_p, RPL_STATSDEBUG, "T :Client Server");
907 sendto_one_numeric(source_p, RPL_STATSDEBUG,
908 "T :connected %u %u", sp.is_cl, sp.is_sv);
b717a466
JT
909 sendto_one_numeric(source_p, RPL_STATSDEBUG,
910 "T :bytes sent %lluK %lluK",
911 sp.is_cbs / 1024,
912 sp.is_sbs / 1024);
913 sendto_one_numeric(source_p, RPL_STATSDEBUG,
914 "T :bytes recv %lluK %lluK",
915 sp.is_cbr / 1024,
477035a4 916 sp.is_sbr / 1024);
b717a466
JT
917 sendto_one_numeric(source_p, RPL_STATSDEBUG,
918 "T :time connected %lu %lu",
8a78afe4 919 (long int)sp.is_cti, (long int)sp.is_sti);
212380e3 920}
921
922static void
923stats_uptime (struct Client *source_p)
924{
925 time_t now;
926
9f6bbe3c 927 now = rb_current_time() - startup_time;
212380e3 928 sendto_one_numeric(source_p, RPL_STATSUPTIME,
929 form_str (RPL_STATSUPTIME),
930 now / 86400, (now / 3600) % 24,
931 (now / 60) % 60, now % 60);
932 sendto_one_numeric(source_p, RPL_STATSCONN,
933 form_str (RPL_STATSCONN),
934 MaxConnectionCount, MaxClientCount,
935 Count.totalrestartcount);
936}
937
938struct shared_flags
939{
940 int flag;
941 char letter;
942};
943static struct shared_flags shared_flagtable[] =
944{
945 { SHARED_PKLINE, 'K' },
946 { SHARED_TKLINE, 'k' },
947 { SHARED_UNKLINE, 'U' },
948 { SHARED_PXLINE, 'X' },
949 { SHARED_TXLINE, 'x' },
950 { SHARED_UNXLINE, 'Y' },
951 { SHARED_PRESV, 'Q' },
952 { SHARED_TRESV, 'q' },
953 { SHARED_UNRESV, 'R' },
954 { SHARED_LOCOPS, 'L' },
955 { SHARED_REHASH, 'H' },
45be325c
VY
956 { SHARED_TDLINE, 'd' },
957 { SHARED_PDLINE, 'D' },
958 { SHARED_UNDLINE, 'E' },
212380e3 959 { 0, '\0'}
960};
961
962
963static void
964stats_shared (struct Client *source_p)
965{
966 struct remote_conf *shared_p;
08d11e34 967 rb_dlink_node *ptr;
212380e3 968 char buf[15];
969 char *p;
970 int i;
971
08d11e34 972 RB_DLINK_FOREACH(ptr, shared_conf_list.head)
212380e3 973 {
974 shared_p = ptr->data;
975
976 p = buf;
977
978 *p++ = 'c';
979
980 for(i = 0; shared_flagtable[i].flag != 0; i++)
981 {
982 if(shared_p->flags & shared_flagtable[i].flag)
983 *p++ = shared_flagtable[i].letter;
984 }
985
986 *p = '\0';
987
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);
992 }
993
08d11e34 994 RB_DLINK_FOREACH(ptr, cluster_conf_list.head)
212380e3 995 {
996 shared_p = ptr->data;
997
998 p = buf;
999
1000 *p++ = 'C';
1001
1002 for(i = 0; shared_flagtable[i].flag != 0; i++)
1003 {
1004 if(shared_p->flags & shared_flagtable[i].flag)
1005 *p++ = shared_flagtable[i].letter;
1006 }
1007
1008 *p = '\0';
1009
1010 sendto_one_numeric(source_p, RPL_STATSULINE,
1011 form_str(RPL_STATSULINE),
1012 shared_p->server, "*", "*", buf);
1013 }
1014}
1015
1016/* stats_servers()
1017 *
1018 * input - client pointer
1019 * output - none
1020 * side effects - client is shown lists of who connected servers
1021 */
1022static void
1023stats_servers (struct Client *source_p)
1024{
1025 struct Client *target_p;
08d11e34 1026 rb_dlink_node *ptr;
212380e3 1027 time_t seconds;
1028 int days, hours, minutes;
1029 int j = 0;
1030
1031 if(ConfigServerHide.flatten_links && !IsOper(source_p) &&
1032 !IsExemptShide(source_p))
1033 {
1034 sendto_one_numeric(source_p, ERR_NOPRIVILEGES,
1035 form_str (ERR_NOPRIVILEGES));
1036 return;
1037 }
1038
08d11e34 1039 RB_DLINK_FOREACH (ptr, serv_list.head)
212380e3 1040 {
1041 target_p = ptr->data;
1042
1043 j++;
9f6bbe3c 1044 seconds = rb_current_time() - target_p->localClient->firsttime;
212380e3 1045
1046 days = (int) (seconds / 86400);
1047 seconds %= 86400;
1048 hours = (int) (seconds / 3600);
1049 seconds %= 3600;
1050 minutes = (int) (seconds / 60);
1051 seconds %= 60;
1052
1053 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1054 "V :%s (%s!*@*) Idle: %d SendQ: %d "
1055 "Connected: %d day%s, %d:%02d:%02d",
1056 target_p->name,
1057 (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
9f6bbe3c 1058 (int) (rb_current_time() - target_p->localClient->lasttime),
e6871258 1059 (int) rb_linebuf_len (&target_p->localClient->buf_sendq),
212380e3 1060 days, (days == 1) ? "" : "s", hours, minutes,
1061 (int) seconds);
1062 }
1063
1064 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1065 "V :%d Server(s)", j);
1066}
1067
1068static void
1069stats_tgecos(struct Client *source_p)
1070{
1071 struct ConfItem *aconf;
08d11e34 1072 rb_dlink_node *ptr;
212380e3 1073
08d11e34 1074 RB_DLINK_FOREACH(ptr, xline_conf_list.head)
212380e3 1075 {
1076 aconf = ptr->data;
1077
1078 if(aconf->hold)
1079 sendto_one_numeric(source_p, RPL_STATSXLINE,
1080 form_str(RPL_STATSXLINE),
1081 'x', aconf->port, aconf->name,
1082 aconf->passwd);
1083 }
1084}
1085
1086static void
1087stats_gecos(struct Client *source_p)
1088{
1089 struct ConfItem *aconf;
08d11e34 1090 rb_dlink_node *ptr;
212380e3 1091
08d11e34 1092 RB_DLINK_FOREACH(ptr, xline_conf_list.head)
212380e3 1093 {
1094 aconf = ptr->data;
1095
1096 if(!aconf->hold)
1097 sendto_one_numeric(source_p, RPL_STATSXLINE,
1098 form_str(RPL_STATSXLINE),
1099 'X', aconf->port, aconf->name,
1100 aconf->passwd);
1101 }
1102}
1103
1104static void
1105stats_class(struct Client *source_p)
1106{
1107 if(ConfigFileEntry.stats_y_oper_only && !IsOper(source_p))
1108 sendto_one_numeric(source_p, ERR_NOPRIVILEGES,
1109 form_str (ERR_NOPRIVILEGES));
1110 else
1111 report_classes(source_p);
1112}
1113
1114static void
1115stats_memory (struct Client *source_p)
1116{
83251205
VY
1117 struct Client *target_p;
1118 struct Channel *chptr;
1119 struct Ban *actualBan;
1120 rb_dlink_node *rb_dlink;
1121 rb_dlink_node *ptr;
1122 int channel_count = 0;
1123 int local_client_conf_count = 0; /* local client conf links */
1124 int users_counted = 0; /* user structs */
1125
1126 int channel_users = 0;
1127 int channel_invites = 0;
1128 int channel_bans = 0;
1129 int channel_except = 0;
1130 int channel_invex = 0;
1131 int channel_quiets = 0;
1132
1133 int class_count = 0; /* classes */
1134 int conf_count = 0; /* conf lines */
1135 int users_invited_count = 0; /* users invited */
1136 int user_channels = 0; /* users in channels */
1137 int aways_counted = 0;
1138 size_t number_servers_cached; /* number of servers cached by scache */
1139
1140 size_t channel_memory = 0;
1141 size_t channel_ban_memory = 0;
1142 size_t channel_except_memory = 0;
1143 size_t channel_invex_memory = 0;
1144 size_t channel_quiet_memory = 0;
1145
1146 size_t away_memory = 0; /* memory used by aways */
1147 size_t ww = 0; /* whowas array count */
1148 size_t wwm = 0; /* whowas array memory used */
1149 size_t conf_memory = 0; /* memory used by conf lines */
1150 size_t mem_servers_cached; /* memory used by scache */
1151
1152 size_t linebuf_count = 0;
1153 size_t linebuf_memory_used = 0;
1154
1155 size_t total_channel_memory = 0;
1156 size_t totww = 0;
1157
1158 size_t local_client_count = 0;
1159 size_t local_client_memory_used = 0;
1160
1161 size_t remote_client_count = 0;
1162 size_t remote_client_memory_used = 0;
1163
1164 size_t total_memory = 0;
1165
1166 count_whowas_memory(&ww, &wwm);
1167
1168 RB_DLINK_FOREACH(ptr, global_client_list.head)
1169 {
1170 target_p = ptr->data;
1171 if(MyConnect(target_p))
1172 {
1173 local_client_conf_count++;
1174 }
1175
1176 if(target_p->user)
1177 {
1178 users_counted++;
1179 users_invited_count += rb_dlink_list_length(&target_p->user->invited);
1180 user_channels += rb_dlink_list_length(&target_p->user->channel);
1181 if(target_p->user->away)
1182 {
1183 aways_counted++;
1184 away_memory += (strlen(target_p->user->away) + 1);
1185 }
1186 }
1187 }
1188
1189 /* Count up all channels, ban lists, except lists, Invex lists */
1190 RB_DLINK_FOREACH(ptr, global_channel_list.head)
1191 {
1192 chptr = ptr->data;
1193 channel_count++;
1194 channel_memory += (strlen(chptr->chname) + sizeof(struct Channel));
1195
1196 channel_users += rb_dlink_list_length(&chptr->members);
1197 channel_invites += rb_dlink_list_length(&chptr->invites);
1198
1199 RB_DLINK_FOREACH(rb_dlink, chptr->banlist.head)
1200 {
1201 actualBan = rb_dlink->data;
1202 channel_bans++;
1203
1204 channel_ban_memory += sizeof(rb_dlink_node) + sizeof(struct Ban);
1205 }
1206
1207 RB_DLINK_FOREACH(rb_dlink, chptr->exceptlist.head)
1208 {
1209 actualBan = rb_dlink->data;
1210 channel_except++;
1211
1212 channel_except_memory += (sizeof(rb_dlink_node) + sizeof(struct Ban));
1213 }
1214
1215 RB_DLINK_FOREACH(rb_dlink, chptr->invexlist.head)
1216 {
1217 actualBan = rb_dlink->data;
1218 channel_invex++;
1219
1220 channel_invex_memory += (sizeof(rb_dlink_node) + sizeof(struct Ban));
1221 }
1222
1223 RB_DLINK_FOREACH(rb_dlink, chptr->quietlist.head)
1224 {
1225 actualBan = rb_dlink->data;
1226 channel_quiets++;
1227
1228 channel_quiet_memory += (sizeof(rb_dlink_node) + sizeof(struct Ban));
1229 }
1230 }
1231
1232 /* count up all classes */
1233
1234 class_count = rb_dlink_list_length(&class_list) + 1;
1235
1236 rb_count_rb_linebuf_memory(&linebuf_count, &linebuf_memory_used);
1237
1238 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1239 "z :Users %u(%lu) Invites %u(%lu)",
1240 users_counted,
1241 (unsigned long) users_counted * sizeof(struct User),
1242 users_invited_count,
1243 (unsigned long) users_invited_count * sizeof(rb_dlink_node));
1244
1245 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1246 "z :User channels %u(%lu) Aways %u(%d)",
1247 user_channels,
1248 (unsigned long) user_channels * sizeof(rb_dlink_node),
1249 aways_counted, (int) away_memory);
1250
1251 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1252 "z :Attached confs %u(%lu)",
1253 local_client_conf_count,
1254 (unsigned long) local_client_conf_count * sizeof(rb_dlink_node));
1255
1256 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1257 "z :Conflines %u(%d)", conf_count, (int) conf_memory);
1258
1259 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1260 "z :Classes %u(%lu)",
1261 class_count,
1262 (unsigned long) class_count * sizeof(struct Class));
1263
1264 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1265 "z :Channels %u(%d)",
1266 channel_count, (int) channel_memory);
1267
1268 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1269 "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)",
1270 channel_bans, (int) channel_ban_memory,
1271 channel_except, (int) channel_except_memory,
1272 channel_invex, (int) channel_invex_memory,
1273 channel_quiets, (int) channel_quiet_memory);
1274
1275 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1276 "z :Channel members %u(%lu) invite %u(%lu)",
1277 channel_users,
1278 (unsigned long) channel_users * sizeof(rb_dlink_node),
1279 channel_invites,
1280 (unsigned long) channel_invites * sizeof(rb_dlink_node));
1281
1282 total_channel_memory = channel_memory +
1283 channel_ban_memory +
1284 channel_users * sizeof(rb_dlink_node) + channel_invites * sizeof(rb_dlink_node);
1285
1286 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1287 "z :Whowas array %ld(%ld)",
1288 (long)ww, (long)wwm);
1289
1290 totww = wwm;
1291
1292 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1293 "z :Hash: client %u(%ld) chan %u(%ld)",
1294 U_MAX, (long)(U_MAX * sizeof(rb_dlink_list)),
1295 CH_MAX, (long)(CH_MAX * sizeof(rb_dlink_list)));
1296
1297 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1298 "z :linebuf %ld(%ld)",
1299 (long)linebuf_count, (long)linebuf_memory_used);
1300
1301 count_scache(&number_servers_cached, &mem_servers_cached);
1302
1303 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1304 "z :scache %ld(%ld)",
1305 (long)number_servers_cached, (long)mem_servers_cached);
1306
1307 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1308 "z :hostname hash %d(%ld)",
1309 HOST_MAX, (long)HOST_MAX * sizeof(rb_dlink_list));
1310
1311 total_memory = totww + total_channel_memory + conf_memory +
1312 class_count * sizeof(struct Class);
1313
1314 total_memory += mem_servers_cached;
1315 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1316 "z :Total: whowas %d channel %d conf %d",
1317 (int) totww, (int) total_channel_memory,
1318 (int) conf_memory);
1319
1320 count_local_client_memory(&local_client_count, &local_client_memory_used);
1321 total_memory += local_client_memory_used;
1322
1323 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1324 "z :Local client Memory in use: %ld(%ld)",
1325 (long)local_client_count, (long)local_client_memory_used);
1326
1327
1328 count_remote_client_memory(&remote_client_count, &remote_client_memory_used);
1329 total_memory += remote_client_memory_used;
1330
1331 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1332 "z :Remote client Memory in use: %ld(%ld)",
1333 (long)remote_client_count,
1334 (long)remote_client_memory_used);
212380e3 1335}
1336
1337static void
1338stats_ziplinks (struct Client *source_p)
1339{
08d11e34 1340 rb_dlink_node *ptr;
212380e3 1341 struct Client *target_p;
6b7c7401 1342 struct ZipStats *zipstats;
212380e3 1343 int sent_data = 0;
eeb13d32 1344 char buf[128], buf1[128];
08d11e34 1345 RB_DLINK_FOREACH (ptr, serv_list.head)
212380e3 1346 {
1347 target_p = ptr->data;
1348 if(IsCapable (target_p, CAP_ZIP))
1349 {
6b7c7401
VY
1350 zipstats = target_p->localClient->zipstats;
1351 sprintf(buf, "%.2f%%", zipstats->out_ratio);
1352 sprintf(buf1, "%.2f%%", zipstats->in_ratio);
212380e3 1353 sendto_one_numeric(source_p, RPL_STATSDEBUG,
eeb13d32 1354 "Z :ZipLinks stats for %s send[%s compression "
6b7c7401
VY
1355 "(%llu kB data/%llu kB wire)] recv[%s compression "
1356 "(%llu kB data/%llu kB wire)]",
212380e3 1357 target_p->name,
6b7c7401
VY
1358 buf, zipstats->out >> 10,
1359 zipstats->out_wire >> 10, buf1,
1360 zipstats->in >> 10, zipstats->in_wire >> 10);
212380e3 1361 sent_data++;
1362 }
1363 }
1364
1365 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1366 "Z :%u ziplink(s)", sent_data);
1367}
1368
1369static void
1370stats_servlinks (struct Client *source_p)
1371{
1372 static char Sformat[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
1373 long uptime, sendK, receiveK;
1374 struct Client *target_p;
08d11e34 1375 rb_dlink_node *ptr;
212380e3 1376 int j = 0;
eeb13d32 1377 char buf[128];
212380e3 1378
1379 if(ConfigServerHide.flatten_links && !IsOper (source_p) &&
1380 !IsExemptShide(source_p))
1381 {
1382 sendto_one_numeric(source_p, ERR_NOPRIVILEGES,
1383 form_str (ERR_NOPRIVILEGES));
1384 return;
1385 }
1386
1387 sendK = receiveK = 0;
1388
08d11e34 1389 RB_DLINK_FOREACH (ptr, serv_list.head)
212380e3 1390 {
1391 target_p = ptr->data;
1392
1393 j++;
1394 sendK += target_p->localClient->sendK;
1395 receiveK += target_p->localClient->receiveK;
1396
1397 sendto_one(source_p, Sformat,
1398 get_id(&me, source_p), RPL_STATSLINKINFO, get_id(source_p, source_p),
1399 get_server_name(target_p, SHOW_IP),
f781a345 1400 (int) rb_linebuf_len (&target_p->localClient->buf_sendq),
212380e3 1401 (int) target_p->localClient->sendM,
1402 (int) target_p->localClient->sendK,
1403 (int) target_p->localClient->receiveM,
1404 (int) target_p->localClient->receiveK,
9f6bbe3c
VY
1405 rb_current_time() - target_p->localClient->firsttime,
1406 (rb_current_time() > target_p->localClient->lasttime) ?
1407 (rb_current_time() - target_p->localClient->lasttime) : 0,
212380e3 1408 IsOper (source_p) ? show_capabilities (target_p) : "TS");
1409 }
1410
1411 sendto_one_numeric(source_p, RPL_STATSDEBUG,
1412 "? :%u total server(s)", j);
1413
eeb13d32 1414 snprintf(buf, sizeof buf, "%7.2f", _GMKv ((sendK)));
212380e3 1415 sendto_one_numeric(source_p, RPL_STATSDEBUG,
eeb13d32
JT
1416 "? :Sent total : %s %s",
1417 buf, _GMKs (sendK));
1418 snprintf(buf, sizeof buf, "%7.2f", _GMKv ((receiveK)));
212380e3 1419 sendto_one_numeric(source_p, RPL_STATSDEBUG,
eeb13d32
JT
1420 "? :Recv total : %s %s",
1421 buf, _GMKs (receiveK));
212380e3 1422
9f6bbe3c 1423 uptime = (rb_current_time() - startup_time);
eeb13d32 1424 snprintf(buf, sizeof buf, "%7.2f %s (%4.1f K/s)",
212380e3 1425 _GMKv (me.localClient->sendK),
1426 _GMKs (me.localClient->sendK),
1427 (float) ((float) me.localClient->sendK / (float) uptime));
eeb13d32
JT
1428 sendto_one_numeric(source_p, RPL_STATSDEBUG, "? :Server send: %s", buf);
1429 snprintf(buf, sizeof buf, "%7.2f %s (%4.1f K/s)",
212380e3 1430 _GMKv (me.localClient->receiveK),
1431 _GMKs (me.localClient->receiveK),
1432 (float) ((float) me.localClient->receiveK / (float) uptime));
eeb13d32 1433 sendto_one_numeric(source_p, RPL_STATSDEBUG, "? :Server recv: %s", buf);
212380e3 1434}
1435
1436static void
1437stats_ltrace(struct Client *source_p, int parc, const char *parv[])
1438{
1439 int doall = 0;
1440 int wilds = 0;
1441 const char *name;
1442 char statchar = parv[1][0];
1443
1444 /* this is def targeted at us somehow.. */
1445 if(parc > 2 && !EmptyString(parv[2]))
1446 {
1447 /* directed at us generically? */
1448 if(match(parv[2], me.name) ||
1449 (!MyClient(source_p) && !irccmp(parv[2], me.id)))
1450 {
1451 name = me.name;
1452 doall = 1;
1453 }
1454 else
1455 {
1456 name = parv[2];
1457 wilds = strchr(name, '*') || strchr(name, '?');
1458 }
1459
1460 /* must be directed at a specific person thats not us */
1461 if(!doall && !wilds)
1462 {
1463 struct Client *target_p;
1464
1465 if(MyClient(source_p))
1466 target_p = find_named_person(name);
1467 else
1468 target_p = find_person(name);
1469
1470 if(target_p != NULL)
1471 {
1472 stats_spy(source_p, statchar, target_p->name);
1473 stats_l_client(source_p, target_p, statchar);
1474 }
1475 else
1476 sendto_one_numeric(source_p, ERR_NOSUCHSERVER,
1477 form_str(ERR_NOSUCHSERVER),
1478 name);
1479
1480 return;
1481 }
1482 }
1483 else
1484 {
1485 name = me.name;
1486 doall = 1;
1487 }
1488
1489 stats_spy(source_p, statchar, name);
1490
1491 if(doall)
1492 {
1493 /* local opers get everyone */
1494 if(MyOper(source_p))
1495 {
1496 stats_l_list(source_p, name, doall, wilds, &unknown_list, statchar);
1497 stats_l_list(source_p, name, doall, wilds, &lclient_list, statchar);
1498 }
1499 else
1500 {
1501 /* they still need themselves if theyre local.. */
1502 if(MyClient(source_p))
1503 stats_l_client(source_p, source_p, statchar);
1504
1505 stats_l_list(source_p, name, doall, wilds, &local_oper_list, statchar);
1506 }
1507
1508 if (!ConfigServerHide.flatten_links || IsOper(source_p) ||
1509 IsExemptShide(source_p))
1510 stats_l_list(source_p, name, doall, wilds, &serv_list, statchar);
1511
1512 return;
1513 }
1514
1515 /* ok, at this point theyre looking for a specific client whos on
1516 * our server.. but it contains a wildcard. --fl
1517 */
1518 stats_l_list(source_p, name, doall, wilds, &lclient_list, statchar);
1519
1520 return;
1521}
1522
1523
1524static void
1525stats_l_list(struct Client *source_p, const char *name, int doall, int wilds,
08d11e34 1526 rb_dlink_list * list, char statchar)
212380e3 1527{
08d11e34 1528 rb_dlink_node *ptr;
212380e3 1529 struct Client *target_p;
1530
1531 /* send information about connections which match. note, we
1532 * dont need tests for IsInvisible(), because non-opers will
1533 * never get here for normal clients --fl
1534 */
08d11e34 1535 RB_DLINK_FOREACH(ptr, list->head)
212380e3 1536 {
1537 target_p = ptr->data;
1538
1539 if(!doall && wilds && !match(name, target_p->name))
1540 continue;
1541
1542 stats_l_client(source_p, target_p, statchar);
1543 }
1544}
1545
1546void
1547stats_l_client(struct Client *source_p, struct Client *target_p,
1548 char statchar)
1549{
1550 if(IsAnyServer(target_p))
1551 {
1552 sendto_one_numeric(source_p, RPL_STATSLINKINFO, Lformat,
1553 get_server_name(target_p, SHOW_IP),
f781a345 1554 (int) rb_linebuf_len(&target_p->localClient->buf_sendq),
212380e3 1555 (int) target_p->localClient->sendM,
1556 (int) target_p->localClient->sendK,
1557 (int) target_p->localClient->receiveM,
1558 (int) target_p->localClient->receiveK,
9f6bbe3c
VY
1559 rb_current_time() - target_p->localClient->firsttime,
1560 (rb_current_time() > target_p->localClient->lasttime) ?
1561 (rb_current_time() - target_p->localClient->lasttime) : 0,
212380e3 1562 IsOper(source_p) ? show_capabilities(target_p) : "-");
1563 }
1564
1565 else
1566 {
1567 sendto_one_numeric(source_p, RPL_STATSLINKINFO, Lformat,
1568 show_ip(source_p, target_p) ?
1569 (IsUpper(statchar) ?
1570 get_client_name(target_p, SHOW_IP) :
1571 get_client_name(target_p, HIDE_IP)) :
1572 get_client_name(target_p, MASK_IP),
f781a345 1573 (int) rb_linebuf_len(&target_p->localClient->buf_sendq),
212380e3 1574 (int) target_p->localClient->sendM,
1575 (int) target_p->localClient->sendK,
1576 (int) target_p->localClient->receiveM,
1577 (int) target_p->localClient->receiveK,
9f6bbe3c
VY
1578 rb_current_time() - target_p->localClient->firsttime,
1579 (rb_current_time() > target_p->localClient->lasttime) ?
1580 (rb_current_time() - target_p->localClient->lasttime) : 0,
212380e3 1581 "-");
1582 }
1583}
1584
9df69d5b
JT
1585static void
1586rb_dump_fd_callback(int fd, const char *desc, void *data)
1587{
1588 struct Client *source_p = data;
1589 sendto_one_numeric(source_p, RPL_STATSDEBUG, "F :fd %-3d desc '%s'", fd, desc);
1590}
1591
1592static void
1593stats_comm(struct Client *source_p)
1594{
1595 rb_dump_fd(rb_dump_fd_callback, source_p);
b8127271
VY
1596}
1597
212380e3 1598/*
1599 * stats_spy
1600 *
1601 * inputs - pointer to client doing the /stats
1602 * - char letter they are doing /stats on
1603 * output - none
1604 * side effects -
1605 * This little helper function reports to opers if configured.
1606 * personally, I don't see why opers need to see stats requests
1607 * at all. They are just "noise" to an oper, and users can't do
1608 * any damage with stats requests now anyway. So, why show them?
1609 * -Dianora
1610 */
1611static void
1612stats_spy(struct Client *source_p, char statchar, const char *name)
1613{
1614 hook_data_int data;
1615
1616 data.client = source_p;
1617 data.arg1 = name;
1618 data.arg2 = (int) statchar;
1619
1620 call_hook(doing_stats_hook, &data);
1621}
1622
1623/* stats_p_spy()
1624 *
1625 * input - pointer to client doing stats
1626 * ouput -
1627 * side effects - call hook doing_stats_p
1628 */
1629static void
1630stats_p_spy (struct Client *source_p)
1631{
1632 hook_data data;
1633
1634 data.client = source_p;
1635 data.arg1 = data.arg2 = NULL;
1636
1637 call_hook(doing_stats_p_hook, &data);
1638}
1639