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