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