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