/[svn]/branches/newio/modules/m_stats.c
ViewVC logotype

Contents of /branches/newio/modules/m_stats.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2420 - (show annotations)
Tue Jul 23 17:45:56 2013 UTC (9 years ago) by michael
File MIME type: text/x-chdr
File size: 52877 byte(s)
- Fixed misc. compile warnings

1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_stats.c: Sends the user statistics or config information.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "list.h" /* dlink_node/dlink_list */
27 #include "client.h" /* Client */
28 #include "irc_string.h"
29 #include "ircd.h" /* me */
30 #include "listener.h" /* show_ports */
31 #include "s_gline.h"
32 #include "conf.h"
33 #include "conf_class.h"
34 #include "hostmask.h"
35 #include "numeric.h" /* ERR_xxx */
36 #include "send.h" /* sendto_one */
37 #include "s_bsd.h" /* highest_fd */
38 #include "s_misc.h" /* serv_info */
39 #include "s_serv.h" /* hunt_server */
40 #include "s_user.h" /* show_opers */
41 #include "dbuf.h"
42 #include "hook.h"
43 #include "parse.h"
44 #include "modules.h"
45 #include "resv.h" /* report_resv */
46 #include "whowas.h"
47 #include "watch.h"
48 #include "irc_res.h"
49 #include "motd.h"
50 #include "msgq.h"
51
52
53 const char *from, *to;
54
55 static const struct shared_flags
56 {
57 const unsigned int type;
58 const unsigned char letter;
59 } flag_table[] = {
60 { SHARED_KLINE, 'K' },
61 { SHARED_UNKLINE, 'U' },
62 { SHARED_XLINE, 'X' },
63 { SHARED_UNXLINE, 'Y' },
64 { SHARED_RESV, 'Q' },
65 { SHARED_UNRESV, 'R' },
66 { SHARED_LOCOPS, 'L' },
67 { SHARED_DLINE, 'D' },
68 { SHARED_UNDLINE, 'E' },
69 { 0, '\0' }
70 };
71
72 /*
73 * inputs - pointer to client requesting confitem report
74 * - ConfType to report
75 * output - none
76 * side effects -
77 */
78 static void
79 report_confitem_types(struct Client *source_p, enum maskitem_type type)
80 {
81 dlink_node *ptr = NULL;
82 struct MaskItem *conf = NULL;
83 const struct shared_flags *shared = NULL;
84 char buf[12];
85 char *p = NULL;
86
87 switch (type)
88 {
89 case CONF_XLINE:
90 DLINK_FOREACH(ptr, xconf_items.head)
91 {
92 conf = ptr->data;
93
94 sendto_one(source_p, form_str(RPL_STATSXLINE),
95 me.name, source_p->name,
96 conf->until ? 'x': 'X', conf->count,
97 conf->name, conf->reason);
98 }
99 break;
100
101 case CONF_ULINE:
102 shared = flag_table;
103 DLINK_FOREACH(ptr, uconf_items.head)
104 {
105 conf = ptr->data;
106
107 p = buf;
108
109 *p++ = 'c';
110 for (; shared->type; ++shared)
111 if (shared->type & conf->flags)
112 *p++ = shared->letter;
113 else
114 *p++ = ToLower(shared->letter);
115
116 sendto_one(source_p, form_str(RPL_STATSULINE),
117 me.name, source_p->name, conf->name,
118 conf->user?conf->user: "*",
119 conf->host?conf->host: "*", buf);
120 }
121
122 shared = flag_table;
123 DLINK_FOREACH(ptr, cluster_items.head)
124 {
125 conf = ptr->data;
126
127 p = buf;
128
129 *p++ = 'C';
130 for (; shared->type; ++shared)
131 if (shared->type & conf->flags)
132 *p++ = shared->letter;
133 else
134 *p++ = ToLower(shared->letter);
135
136 sendto_one(source_p, form_str(RPL_STATSULINE),
137 me.name, source_p->name, conf->name,
138 "*", "*", buf);
139 }
140
141 break;
142
143 case CONF_OPER:
144 DLINK_FOREACH(ptr, oconf_items.head)
145 {
146 conf = ptr->data;
147
148 /* Don't allow non opers to see oper privs */
149 if (HasUMode(source_p, UMODE_OPER))
150 sendto_one(source_p, form_str(RPL_STATSOLINE),
151 me.name, source_p->name, 'O', conf->count, conf->user, conf->host,
152 conf->name, oper_privs_as_string(conf->port),
153 conf->class ? conf->class->name : "<default>");
154 else
155 sendto_one(source_p, form_str(RPL_STATSOLINE),
156 me.name, source_p->name, 'O', conf->count, conf->user, conf->host,
157 conf->name, "0",
158 conf->class ? conf->class->name : "<default>");
159 }
160 break;
161
162 case CONF_SERVICE:
163 DLINK_FOREACH(ptr, service_items.head)
164 {
165 conf = ptr->data;
166 sendto_one(source_p, form_str(RPL_STATSSERVICE),
167 me.name, source_p->name, 'S', "*", conf->name, 0, 0);
168 }
169 break;
170
171 case CONF_SERVER:
172 DLINK_FOREACH(ptr, server_items.head)
173 {
174 p = buf;
175 conf = ptr->data;
176
177 buf[0] = '\0';
178
179 if (IsConfAllowAutoConn(conf))
180 *p++ = 'A';
181 if (IsConfSSL(conf))
182 *p++ = 'S';
183 if (buf[0] == '\0')
184 *p++ = '*';
185
186 *p = '\0';
187
188 /*
189 * Allow admins to see actual ips unless hide_server_ips is enabled
190 */
191 if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN))
192 sendto_one(source_p, form_str(RPL_STATSCLINE),
193 me.name, source_p->name, 'C', conf->host,
194 buf, conf->name, conf->port,
195 conf->class ? conf->class->name : "<default>");
196 else
197 sendto_one(source_p, form_str(RPL_STATSCLINE),
198 me.name, source_p->name, 'C',
199 "*@127.0.0.1", buf, conf->name, conf->port,
200 conf->class ? conf->class->name : "<default>");
201 }
202 break;
203
204 default:
205 break;
206 }
207 }
208
209 /* report_resv()
210 *
211 * inputs - pointer to client pointer to report to.
212 * output - NONE
213 * side effects - report all resvs to client.
214 */
215 static void
216 report_resv(struct Client *source_p)
217 {
218 dlink_node *ptr = NULL;
219 struct MaskItem *conf = NULL;
220
221 DLINK_FOREACH(ptr, cresv_items.head)
222 {
223 conf = ptr->data;
224 sendto_one(source_p, form_str(RPL_STATSQLINE),
225 me.name, source_p->name,
226 conf->until ? 'q' : 'Q', conf->count,
227 conf->name, conf->reason);
228 }
229
230 DLINK_FOREACH(ptr, nresv_items.head)
231 {
232 conf = ptr->data;
233 sendto_one(source_p, form_str(RPL_STATSQLINE),
234 me.name, source_p->name,
235 conf->until ? 'q' : 'Q', conf->count,
236 conf->name, conf->reason);
237 }
238 }
239
240 /*
241 * This is part of the STATS replies. There is no offical numeric for this
242 * since this isnt an official command, in much the same way as HASH isnt.
243 * It is also possible that some systems wont support this call or have
244 * different field names for "struct rusage".
245 * -avalon
246 */
247 static void
248 stats_usage(struct Client *source_p, int parc, char *parv[])
249 {
250 struct rusage rus;
251 time_t secs;
252 time_t rup;
253 #ifdef hz
254 # define hzz hz
255 #else
256 # ifdef HZ
257 # define hzz HZ
258 # else
259 int hzz = 1;
260 # endif
261 #endif
262
263 if (getrusage(RUSAGE_SELF, &rus) == -1)
264 {
265 sendto_one(source_p, ":%s NOTICE %s :Getruseage error: %s",
266 me.name, source_p->name, strerror(errno));
267 return;
268 }
269
270 secs = rus.ru_utime.tv_sec + rus.ru_stime.tv_sec;
271
272 if (secs == 0)
273 secs = 1;
274
275 rup = (CurrentTime - me.localClient->since) * hzz;
276
277 if (rup == 0)
278 rup = 1;
279
280 sendto_one(source_p,
281 ":%s %d %s R :CPU Secs %d:%02d User %d:%02d System %d:%02d",
282 me.name, RPL_STATSDEBUG, source_p->name, (int)(secs/60), (int)(secs%60),
283 (int)(rus.ru_utime.tv_sec/60), (int)(rus.ru_utime.tv_sec%60),
284 (int)(rus.ru_stime.tv_sec/60), (int)(rus.ru_stime.tv_sec%60));
285 sendto_one(source_p, ":%s %d %s R :RSS %ld ShMem %ld Data %ld Stack %ld",
286 me.name, RPL_STATSDEBUG, source_p->name, rus.ru_maxrss,
287 (rus.ru_ixrss / rup), (rus.ru_idrss / rup),
288 (rus.ru_isrss / rup));
289 sendto_one(source_p, ":%s %d %s R :Swaps %d Reclaims %d Faults %d",
290 me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_nswap,
291 (int)rus.ru_minflt, (int)rus.ru_majflt);
292 sendto_one(source_p, ":%s %d %s R :Block in %d out %d",
293 me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_inblock,
294 (int)rus.ru_oublock);
295 sendto_one(source_p, ":%s %d %s R :Msg Rcv %d Send %d",
296 me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_msgrcv,
297 (int)rus.ru_msgsnd);
298 sendto_one(source_p, ":%s %d %s R :Signals %d Context Vol. %d Invol %d",
299 me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_nsignals,
300 (int)rus.ru_nvcsw, (int)rus.ru_nivcsw);
301 }
302
303 static void
304 stats_memory(struct Client *source_p, int parc, char *parv[])
305 {
306 const dlink_node *gptr = NULL;
307 const dlink_node *dlink = NULL;
308
309 unsigned int local_client_conf_count = 0; /* local client conf links */
310 unsigned int users_counted = 0; /* user structs */
311
312 unsigned int channel_members = 0;
313 unsigned int channel_invites = 0;
314 unsigned int channel_bans = 0;
315 unsigned int channel_except = 0;
316 unsigned int channel_invex = 0;
317
318 unsigned int wwu = 0; /* whowas users */
319 unsigned int class_count = 0; /* classes */
320 unsigned int aways_counted = 0;
321 unsigned int number_ips_stored; /* number of ip addresses hashed */
322
323 uint64_t channel_memory = 0;
324 uint64_t channel_ban_memory = 0;
325 uint64_t channel_except_memory = 0;
326 uint64_t channel_invex_memory = 0;
327
328 uint64_t wwm = 0; /* whowas array memory used */
329 uint64_t conf_memory = 0; /* memory used by conf lines */
330 uint64_t mem_ips_stored; /* memory used by ip address hash */
331
332 uint64_t total_channel_memory = 0;
333 uint64_t totww = 0;
334
335 unsigned int local_client_count = 0;
336 unsigned int remote_client_count = 0;
337
338 uint64_t local_client_memory_used = 0;
339 uint64_t remote_client_memory_used = 0;
340
341 uint64_t total_memory = 0;
342 unsigned int topic_count = 0;
343
344 unsigned int watch_list_headers = 0; /* watchlist headers */
345 unsigned int watch_list_entries = 0; /* watchlist entries */
346 uint64_t watch_list_memory = 0; /* watchlist memory used */
347
348
349 DLINK_FOREACH(gptr, global_client_list.head)
350 {
351 struct Client *target_p = gptr->data;
352
353 if (MyConnect(target_p))
354 {
355 ++local_client_count;
356 local_client_conf_count += dlink_list_length(&target_p->localClient->confs);
357 watch_list_entries += dlink_list_length(&target_p->localClient->watches);
358 }
359 else
360 ++remote_client_count;
361
362 if (IsClient(target_p))
363 {
364 ++users_counted;
365
366 if (target_p->away[0])
367 ++aways_counted;
368 }
369 }
370
371 /* Count up all channels, ban lists, except lists, Invex lists */
372 channel_memory = dlink_list_length(&global_channel_list) *
373 sizeof(struct Channel);
374 DLINK_FOREACH(gptr, global_channel_list.head)
375 {
376 const struct Ban *actualBan;
377 const struct Channel *chptr = gptr->data;
378
379 channel_members += dlink_list_length(&chptr->members);
380 channel_invites += dlink_list_length(&chptr->invites);
381
382 if (chptr->topic[0])
383 ++topic_count;
384
385 channel_bans += dlink_list_length(&chptr->banlist);
386 channel_ban_memory += dlink_list_length(&chptr->banlist) * sizeof(struct Ban);
387
388 DLINK_FOREACH(dlink, chptr->banlist.head)
389 {
390 actualBan = dlink->data;
391 assert(actualBan->who);
392
393 channel_ban_memory += actualBan->len + 1;
394 channel_ban_memory += strlen(actualBan->who) + 1;
395 }
396
397 channel_except += dlink_list_length(&chptr->exceptlist);
398 channel_except_memory += dlink_list_length(&chptr->exceptlist) * sizeof(struct Ban);
399
400 DLINK_FOREACH(dlink, chptr->exceptlist.head)
401 {
402 actualBan = dlink->data;
403 assert(actualBan->who);
404
405 channel_except_memory += actualBan->len + 1;
406 channel_except_memory += strlen(actualBan->who) + 1;
407 }
408
409 channel_invex += dlink_list_length(&chptr->invexlist);
410 channel_invex_memory += dlink_list_length(&chptr->invexlist) * sizeof(struct Ban);
411
412 DLINK_FOREACH(dlink, chptr->invexlist.head)
413 {
414 actualBan = dlink->data;
415 assert(actualBan->who);
416
417 channel_invex_memory += actualBan->len + 1;
418 channel_invex_memory += strlen(actualBan->who) + 1;
419 }
420 }
421
422 #if 0
423 /* XXX THIS has to be fixed !!!! -db */
424 /* count up all config items */
425 DLINK_FOREACH(dlink, ConfigItemList.head)
426 {
427 aconf = dlink->data;
428 conf_memory += aconf->host ? strlen(aconf->host)+1 : 0;
429 conf_memory += aconf->passwd ? strlen(aconf->passwd)+1 : 0;
430 conf_memory += aconf->name ? strlen(aconf->name)+1 : 0;
431 conf_memory += sizeof(struct AccessItem);
432 }
433 #endif
434 /* count up all classes */
435 class_count = dlink_list_length(class_get_list());
436
437 whowas_count_memory(&wwu, &wwm);
438 watch_count_memory(&watch_list_headers, &watch_list_memory);
439
440 sendto_one(source_p, ":%s %d %s z :WATCH headers %u(%llu) entries %d(%u)",
441 me.name, RPL_STATSDEBUG, source_p->name, watch_list_headers,
442 watch_list_memory, watch_list_entries,
443 watch_list_entries * sizeof(dlink_node) * 2);
444
445 sendto_one(source_p, ":%s %d %s z :Clients %u(%u)",
446 me.name, RPL_STATSDEBUG, source_p->name, users_counted,
447 (users_counted * sizeof(struct Client)));
448
449 sendto_one(source_p, ":%s %d %s z :User aways %u",
450 me.name, RPL_STATSDEBUG, source_p->name,
451 aways_counted);
452
453 sendto_one(source_p, ":%s %d %s z :Attached confs %u(%llu)",
454 me.name, RPL_STATSDEBUG, source_p->name,
455 local_client_conf_count,
456 (unsigned long long)(local_client_conf_count * sizeof(dlink_node)));
457
458 sendto_one(source_p, ":%s %d %s z :Resv channels %u(%lu) nicks %u(%lu)",
459 me.name, RPL_STATSDEBUG, source_p->name,
460 dlink_list_length(&cresv_items),
461 dlink_list_length(&cresv_items) * sizeof(struct MaskItem),
462 dlink_list_length(&nresv_items),
463 dlink_list_length(&nresv_items) * sizeof(struct MaskItem));
464
465 sendto_one(source_p, ":%s %d %s z :Classes %u(%llu)",
466 me.name, RPL_STATSDEBUG, source_p->name,
467 class_count, (unsigned long long)(class_count * sizeof(struct ClassItem)));
468
469 sendto_one(source_p, ":%s %d %s z :Channels %u(%llu) Topics %u(%u)",
470 me.name, RPL_STATSDEBUG, source_p->name,
471 dlink_list_length(&global_channel_list),
472 channel_memory, topic_count, topic_count *
473 (TOPICLEN + 1 + USERHOST_REPLYLEN));
474
475 sendto_one(source_p, ":%s %d %s z :Bans %u(%llu)",
476 me.name, RPL_STATSDEBUG, source_p->name,
477 channel_bans, channel_ban_memory);
478
479 sendto_one(source_p, ":%s %d %s z :Exceptions %u(%llu)",
480 me.name, RPL_STATSDEBUG, source_p->name,
481 channel_except, channel_except_memory);
482
483 sendto_one(source_p, ":%s %d %s z :Invex %u(%llu)",
484 me.name, RPL_STATSDEBUG, source_p->name,
485 channel_invex, channel_invex_memory);
486
487 sendto_one(source_p, ":%s %d %s z :Channel members %u(%llu) invites %u(%llu)",
488 me.name, RPL_STATSDEBUG, source_p->name, channel_members,
489 (unsigned long long)(channel_members * sizeof(struct Membership)),
490 channel_invites, (unsigned long long)channel_invites *
491 sizeof(dlink_node) * 2);
492
493 total_channel_memory = channel_memory + channel_ban_memory +
494 channel_members * sizeof(struct Membership) +
495 (channel_invites * sizeof(dlink_node)*2);
496
497 sendto_one(source_p, ":%s %d %s z :Whowas users %u(%llu)",
498 me.name, RPL_STATSDEBUG, source_p->name,
499 wwu, (unsigned long long)(wwu * sizeof(struct Client)));
500
501 sendto_one(source_p, ":%s %d %s z :Whowas array %u(%llu)",
502 me.name, RPL_STATSDEBUG, source_p->name,
503 NICKNAMEHISTORYLENGTH, wwm);
504
505 totww = wwu * sizeof(struct Client) + wwm;
506
507 motd_memory_count(source_p);
508 count_ip_hash(&number_ips_stored,&mem_ips_stored);
509 sendto_one(source_p, ":%s %d %s z :iphash %u(%llu)",
510 me.name, RPL_STATSDEBUG, source_p->name,
511 number_ips_stored, mem_ips_stored);
512
513 total_memory = totww + total_channel_memory + conf_memory + class_count *
514 sizeof(struct ClassItem);
515 sendto_one(source_p, ":%s %d %s z :Total: whowas %llu channel %llu conf %llu",
516 me.name, RPL_STATSDEBUG, source_p->name, totww,
517 total_channel_memory, conf_memory);
518
519 local_client_memory_used = local_client_count*(sizeof(struct Client) + sizeof(struct Connection));
520 total_memory += local_client_memory_used;
521 sendto_one(source_p, ":%s %d %s z :Local client Memory in use: %u(%llu)",
522 me.name, RPL_STATSDEBUG, source_p->name, local_client_count,
523 local_client_memory_used);
524
525 remote_client_memory_used = remote_client_count * sizeof(struct Client);
526 total_memory += remote_client_memory_used;
527 sendto_one(source_p, ":%s %d %s z :Remote client Memory in use: %u(%llu)",
528 me.name, RPL_STATSDEBUG, source_p->name, remote_client_count,
529 remote_client_memory_used);
530
531 sendto_one(source_p,
532 ":%s %d %s z :TOTAL: %llu",
533 me.name, RPL_STATSDEBUG, source_p->name,
534 total_memory);
535 }
536
537 static void
538 stats_dns_servers(struct Client *source_p)
539 {
540 report_dns_servers(source_p);
541 }
542
543 static void
544 stats_connect(struct Client *source_p, int parc, char *parv[])
545 {
546 report_confitem_types(source_p, CONF_SERVER);
547 }
548
549 /* stats_deny()
550 *
551 * input - client to report to
552 * output - none
553 * side effects - client is given dline list.
554 */
555 static void
556 stats_deny(struct Client *source_p, int parc, char *parv[])
557 {
558 struct MaskItem *conf;
559 dlink_node *ptr = NULL;
560 unsigned int i = 0;
561
562
563 for (i = 0; i < ATABLE_SIZE; ++i)
564 {
565 DLINK_FOREACH(ptr, atable[i].head)
566 {
567 struct AddressRec *arec = ptr->data;
568
569 if (arec->type != CONF_DLINE)
570 continue;
571
572 conf = arec->conf;
573
574 /* dont report a tdline as a dline */
575 if (conf->until)
576 continue;
577
578 sendto_one(source_p, form_str(RPL_STATSDLINE),
579 from, to, 'D', conf->host, conf->reason);
580 }
581 }
582 }
583
584 /* stats_tdeny()
585 *
586 * input - client to report to
587 * output - none
588 * side effects - client is given dline list.
589 */
590 static void
591 stats_tdeny(struct Client *source_p, int parc, char *parv[])
592 {
593 struct MaskItem *conf = NULL;
594 dlink_node *ptr = NULL;
595 unsigned int i = 0;
596
597
598 for (i = 0; i < ATABLE_SIZE; ++i)
599 {
600 DLINK_FOREACH(ptr, atable[i].head)
601 {
602 struct AddressRec *arec = ptr->data;
603
604 if (arec->type != CONF_DLINE)
605 continue;
606
607 conf = arec->conf;
608
609 /* dont report a permanent dline as a tdline */
610 if (!conf->until)
611 continue;
612
613 sendto_one(source_p, form_str(RPL_STATSDLINE),
614 from, to, 'd', conf->host, conf->reason);
615 }
616 }
617 }
618
619 /* stats_exempt()
620 *
621 * input - client to report to
622 * output - none
623 * side effects - client is given list of exempt blocks
624 */
625 static void
626 stats_exempt(struct Client *source_p, int parc, char *parv[])
627 {
628 struct MaskItem *conf;
629 dlink_node *ptr = NULL;
630 unsigned int i = 0;
631
632 if (ConfigFileEntry.stats_e_disabled)
633 {
634 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
635 from, to);
636 return;
637 }
638
639
640 for (i = 0; i < ATABLE_SIZE; ++i)
641 {
642 DLINK_FOREACH(ptr, atable[i].head)
643 {
644 struct AddressRec *arec = ptr->data;
645
646 if (arec->type != CONF_EXEMPT)
647 continue;
648
649 conf = arec->conf;
650
651 sendto_one(source_p, form_str(RPL_STATSDLINE), from, to, 'e',
652 conf->host, "");
653 }
654 }
655 }
656
657 /* stats_pending_glines()
658 *
659 * input - client pointer
660 * output - none
661 * side effects - client is shown list of pending glines
662 */
663 static void
664 stats_pending_glines(struct Client *source_p, int parc, char *parv[])
665 {
666 const dlink_node *dn_ptr = NULL;
667 const struct gline_pending *glp_ptr = NULL;
668 char timebuffer[MAX_DATE_STRING] = { '\0' };
669 struct tm *tmptr = NULL;
670
671 if (!ConfigFileEntry.glines)
672 {
673 sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
674 from, to);
675 return;
676 }
677
678 if (dlink_list_length(&pending_glines[GLINE_PENDING_ADD_TYPE]) > 0)
679 sendto_one(source_p, ":%s NOTICE %s :Pending G-lines",
680 from, to);
681
682 DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_ADD_TYPE].head)
683 {
684 glp_ptr = dn_ptr->data;
685 tmptr = localtime(&glp_ptr->vote_1.time_request);
686 strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
687
688 sendto_one(source_p,
689 ":%s NOTICE %s :1) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
690 from, to, glp_ptr->vote_1.oper_nick,
691 glp_ptr->vote_1.oper_user, glp_ptr->vote_1.oper_host,
692 glp_ptr->vote_1.oper_server, timebuffer,
693 glp_ptr->user, glp_ptr->host, glp_ptr->vote_1.reason);
694
695 if (glp_ptr->vote_2.oper_nick[0] != '\0')
696 {
697 tmptr = localtime(&glp_ptr->vote_2.time_request);
698 strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
699 sendto_one(source_p,
700 ":%s NOTICE %s :2) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
701 from, to, glp_ptr->vote_2.oper_nick,
702 glp_ptr->vote_2.oper_user, glp_ptr->vote_2.oper_host,
703 glp_ptr->vote_2.oper_server, timebuffer,
704 glp_ptr->user, glp_ptr->host, glp_ptr->vote_2.reason);
705 }
706 }
707
708 sendto_one(source_p, ":%s NOTICE %s :End of Pending G-lines",
709 from, to);
710
711 if (dlink_list_length(&pending_glines[GLINE_PENDING_DEL_TYPE]) > 0)
712 sendto_one(source_p, ":%s NOTICE %s :Pending UNG-lines",
713 from, to);
714
715 DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_DEL_TYPE].head)
716 {
717 glp_ptr = dn_ptr->data;
718 tmptr = localtime(&glp_ptr->vote_1.time_request);
719 strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
720
721 sendto_one(source_p,
722 ":%s NOTICE %s :1) %s!%s@%s on %s requested ungline at %s for %s@%s [%s]",
723 from, to, glp_ptr->vote_1.oper_nick,
724 glp_ptr->vote_1.oper_user, glp_ptr->vote_1.oper_host,
725 glp_ptr->vote_1.oper_server, timebuffer,
726 glp_ptr->user, glp_ptr->host, glp_ptr->vote_1.reason);
727
728 if (glp_ptr->vote_2.oper_nick[0] != '\0')
729 {
730 tmptr = localtime(&glp_ptr->vote_2.time_request);
731 strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
732 sendto_one(source_p,
733 ":%s NOTICE %s :2) %s!%s@%s on %s requested ungline at %s for %s@%s [%s]",
734 from, to, glp_ptr->vote_2.oper_nick,
735 glp_ptr->vote_2.oper_user, glp_ptr->vote_2.oper_host,
736 glp_ptr->vote_2.oper_server, timebuffer,
737 glp_ptr->user, glp_ptr->host, glp_ptr->vote_2.reason);
738
739 }
740 }
741
742 sendto_one(source_p, ":%s NOTICE %s :End of Pending UNG-lines",
743 from, to);
744 }
745
746 /* stats_glines()
747 *
748 * input - client pointer
749 * output - none
750 * side effects - client is shown list of glines
751 */
752 static void
753 stats_glines(struct Client *source_p, int parc, char *parv[])
754 {
755 dlink_node *ptr = NULL;
756 unsigned int i = 0;
757
758 if (!ConfigFileEntry.glines)
759 {
760 sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
761 from, to);
762 return;
763 }
764
765 for (i = 0; i < ATABLE_SIZE; ++i)
766 {
767 DLINK_FOREACH(ptr, atable[i].head)
768 {
769 const struct AddressRec *arec = ptr->data;
770
771 if (arec->type == CONF_GLINE)
772 {
773 const struct MaskItem *conf = arec->conf;
774
775 sendto_one(source_p, form_str(RPL_STATSKLINE),
776 from, to, 'G',
777 conf->host ? conf->host : "*",
778 conf->user ? conf->user : "*",
779 conf->reason ? conf->reason : CONF_NOREASON);
780 }
781 }
782 }
783 }
784
785 static void
786 stats_hubleaf(struct Client *source_p, int parc, char *parv[])
787 {
788 const dlink_node *ptr = NULL, *dptr = NULL;
789
790 DLINK_FOREACH(ptr, server_items.head)
791 {
792 const struct MaskItem *conf = ptr->data;
793
794 DLINK_FOREACH(dptr, conf->hub_list.head)
795 sendto_one(source_p, form_str(RPL_STATSHLINE), me.name,
796 source_p->name, 'H', dptr->data, conf->name, 0, "*");
797 }
798
799 DLINK_FOREACH(ptr, server_items.head)
800 {
801 const struct MaskItem *conf = ptr->data;
802
803 DLINK_FOREACH(dptr, conf->leaf_list.head)
804 sendto_one(source_p, form_str(RPL_STATSLLINE), me.name,
805 source_p->name, 'L', dptr->data, conf->name, 0, "*");
806 }
807 }
808
809 /*
810 * show_iline_prefix()
811 *
812 * inputs - pointer to struct Client requesting output
813 * - pointer to struct MaskItem
814 * - name to which iline prefix will be prefixed to
815 * output - pointer to static string with prefixes listed in ascii form
816 * side effects - NONE
817 */
818 static const char *
819 show_iline_prefix(const struct Client *sptr, const struct MaskItem *conf)
820 {
821 static char prefix_of_host[USERLEN + 15];
822 char *prefix_ptr = prefix_of_host;
823
824 if (IsConfWebIRC(conf))
825 *prefix_ptr++ = '<';
826 if (IsNoTilde(conf))
827 *prefix_ptr++ = '-';
828 if (IsLimitIp(conf))
829 *prefix_ptr++ = '!';
830 if (IsNeedIdentd(conf))
831 *prefix_ptr++ = '+';
832 if (!IsNeedPassword(conf))
833 *prefix_ptr++ = '&';
834 if (IsConfExemptResv(conf))
835 *prefix_ptr++ = '$';
836 if (IsNoMatchIp(conf))
837 *prefix_ptr++ = '%';
838 if (IsConfDoSpoofIp(conf))
839 *prefix_ptr++ = '=';
840 if (MyOper(sptr) && IsConfExemptKline(conf))
841 *prefix_ptr++ = '^';
842 if (MyOper(sptr) && IsConfExemptGline(conf))
843 *prefix_ptr++ = '_';
844 if (MyOper(sptr) && IsConfExemptLimits(conf))
845 *prefix_ptr++ = '>';
846 if (IsConfCanFlood(conf))
847 *prefix_ptr++ = '|';
848
849 strlcpy(prefix_ptr, conf->user, USERLEN+1);
850
851 return prefix_of_host;
852 }
853
854 static void
855 report_auth(struct Client *client_p, int parc, char *parv[])
856 {
857 struct MaskItem *conf = NULL;
858 dlink_node *ptr = NULL;
859 unsigned int i;
860
861
862 for (i = 0; i < ATABLE_SIZE; ++i)
863 {
864 DLINK_FOREACH(ptr, atable[i].head)
865 {
866 struct AddressRec *arec = ptr->data;
867
868 if (arec->type != CONF_CLIENT)
869 continue;
870
871 conf = arec->conf;
872
873 if (!MyOper(client_p) && IsConfDoSpoofIp(conf))
874 continue;
875
876 /* We are doing a partial list, based on what matches the u@h of the
877 * sender, so prepare the strings for comparing --fl_
878 */
879 if (ConfigFileEntry.hide_spoof_ips)
880 sendto_one(client_p, form_str(RPL_STATSILINE), me.name,
881 client_p->name, 'I',
882 conf->name == NULL ? "*" : conf->name,
883 show_iline_prefix(client_p, conf),
884 IsConfDoSpoofIp(conf) ? "255.255.255.255" :
885 conf->host, conf->port,
886 conf->class ? conf->class->name : "<default>");
887
888 else
889 sendto_one(client_p, form_str(RPL_STATSILINE), me.name,
890 client_p->name, 'I',
891 conf->name == NULL ? "*" : conf->name,
892 show_iline_prefix(client_p, conf),
893 conf->host, conf->port,
894 conf->class ? conf->class->name : "<default>");
895 }
896 }
897 }
898
899 static void
900 stats_auth(struct Client *source_p, int parc, char *parv[])
901 {
902 /* Oper only, if unopered, return ERR_NOPRIVILEGES */
903 if ((ConfigFileEntry.stats_i_oper_only == 2) && !HasUMode(source_p, UMODE_OPER))
904 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
905 from, to);
906
907 /* If unopered, Only return matching auth blocks */
908 else if ((ConfigFileEntry.stats_i_oper_only == 1) && !HasUMode(source_p, UMODE_OPER))
909 {
910 struct MaskItem *conf;
911
912 if (MyConnect(source_p))
913 conf = find_conf_by_address(source_p->host,
914 &source_p->localClient->ip,
915 CONF_CLIENT,
916 source_p->localClient->aftype,
917 source_p->username,
918 source_p->localClient->passwd, 1);
919 else
920 conf = find_conf_by_address(source_p->host, NULL, CONF_CLIENT,
921 0, source_p->username, NULL, 1);
922
923 if (conf == NULL)
924 return;
925
926 sendto_one(source_p, form_str(RPL_STATSILINE), from,
927 to, 'I',
928 "*", show_iline_prefix(source_p, conf),
929 conf->host, conf->port,
930 conf->class ? conf->class->name : "<default>");
931 }
932 /* They are opered, or allowed to see all auth blocks */
933 else
934 report_auth(source_p, 0, NULL);
935 }
936
937 /* report_Klines()
938 * Inputs: Client to report to,
939 * type(==0 for perm, !=0 for temporary)
940 * mask
941 * Output: None
942 * Side effects: Reports configured K(or k)-lines to client_p.
943 */
944 static void
945 report_Klines(struct Client *client_p, int tkline)
946 {
947 struct MaskItem *conf = NULL;
948 unsigned int i = 0;
949 char c = '\0';
950 dlink_node *ptr = NULL;
951
952 if (tkline)
953 c = 'k';
954 else
955 c = 'K';
956
957 for (i = 0; i < ATABLE_SIZE; ++i)
958 {
959 DLINK_FOREACH(ptr, atable[i].head)
960 {
961 struct AddressRec *arec = ptr->data;
962
963 if (arec->type != CONF_KLINE)
964 continue;
965
966 conf = arec->conf;
967
968 if ((!tkline && conf->until) ||
969 (tkline && !conf->until))
970 continue;
971
972 if (HasUMode(client_p, UMODE_OPER))
973 sendto_one(client_p, form_str(RPL_STATSKLINE), me.name,
974 client_p->name, c, conf->host, conf->user,
975 conf->reason);
976 else
977 sendto_one(client_p, form_str(RPL_STATSKLINE), me.name,
978 client_p->name, c, conf->host, conf->user,
979 conf->reason);
980 }
981 }
982 }
983
984 static void
985 stats_tklines(struct Client *source_p, int parc, char *parv[])
986 {
987 /* Oper only, if unopered, return ERR_NOPRIVILEGES */
988 if ((ConfigFileEntry.stats_k_oper_only == 2) && !HasUMode(source_p, UMODE_OPER))
989 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
990 from, to);
991
992 /* If unopered, Only return matching klines */
993 else if ((ConfigFileEntry.stats_k_oper_only == 1) && !HasUMode(source_p, UMODE_OPER))
994 {
995 struct MaskItem *conf = NULL;
996
997 if (MyConnect(source_p))
998 conf = find_conf_by_address(source_p->host,
999 &source_p->localClient->ip,
1000 CONF_KLINE,
1001 source_p->localClient->aftype,
1002 source_p->username, NULL, 1);
1003 else
1004 conf = find_conf_by_address(source_p->host, NULL, CONF_KLINE,
1005 0, source_p->username, NULL, 1);
1006
1007 if (!conf)
1008 return;
1009
1010 /* dont report a permanent kline as a tkline */
1011 if (!conf->until)
1012 return;
1013
1014 sendto_one(source_p, form_str(RPL_STATSKLINE), from,
1015 to, 'k', conf->host, conf->user, conf->reason);
1016 }
1017 /* Theyre opered, or allowed to see all klines */
1018 else {
1019 report_Klines(source_p, 1);
1020 }
1021 }
1022
1023 static void
1024 stats_klines(struct Client *source_p, int parc, char *parv[])
1025 {
1026 /* Oper only, if unopered, return ERR_NOPRIVILEGES */
1027 if ((ConfigFileEntry.stats_k_oper_only == 2) && !HasUMode(source_p, UMODE_OPER))
1028 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1029 from, to);
1030
1031 /* If unopered, Only return matching klines */
1032 else if ((ConfigFileEntry.stats_k_oper_only == 1) && !HasUMode(source_p, UMODE_OPER))
1033 {
1034 struct MaskItem *conf = NULL;
1035
1036 /* search for a kline */
1037 if (MyConnect(source_p))
1038 conf = find_conf_by_address(source_p->host,
1039 &source_p->localClient->ip,
1040 CONF_KLINE,
1041 source_p->localClient->aftype,
1042 source_p->username, NULL, 0);
1043 else
1044 conf = find_conf_by_address(source_p->host, NULL, CONF_KLINE,
1045 0, source_p->username, NULL, 0);
1046
1047 if (!conf)
1048 return;
1049
1050 /* dont report a tkline as a kline */
1051 if (conf->until)
1052 return;
1053
1054 sendto_one(source_p, form_str(RPL_STATSKLINE), from,
1055 to, 'K', conf->host, conf->user, conf->reason);
1056 }
1057 /* Theyre opered, or allowed to see all klines */
1058 else
1059 report_Klines(source_p, 0);
1060 }
1061
1062 static void
1063 stats_messages(struct Client *source_p, int parc, char *parv[])
1064 {
1065 report_messages(source_p);
1066 }
1067
1068 static void
1069 stats_oper(struct Client *source_p, int parc, char *parv[])
1070 {
1071 if (!HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.stats_o_oper_only)
1072 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1073 from, to);
1074 else
1075 report_confitem_types(source_p, CONF_OPER);
1076 }
1077
1078 /* stats_operedup()
1079 *
1080 * input - client pointer
1081 * output - none
1082 * side effects - client is shown a list of active opers
1083 */
1084 static void
1085 stats_operedup(struct Client *source_p, int parc, char *parv[])
1086 {
1087 dlink_node *ptr;
1088
1089 DLINK_FOREACH(ptr, oper_list.head)
1090 {
1091 const struct Client *target_p = ptr->data;
1092
1093 if (HasUMode(target_p, UMODE_HIDDEN) && !HasUMode(source_p, UMODE_OPER))
1094 continue;
1095
1096 if (MyClient(source_p) && HasUMode(source_p, UMODE_OPER))
1097 sendto_one(source_p, ":%s %d %s p :[%c][%s] %s (%s@%s) Idle: %u",
1098 from, RPL_STATSDEBUG, to,
1099 HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O',
1100 oper_privs_as_string(target_p->localClient->operflags),
1101 target_p->name, target_p->username, target_p->host,
1102 idle_time_get(source_p, target_p));
1103 else
1104 sendto_one(source_p, ":%s %d %s p :[%c] %s (%s@%s) Idle: %u",
1105 from, RPL_STATSDEBUG, to,
1106 HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O',
1107 target_p->name, target_p->username, target_p->host,
1108 idle_time_get(source_p, target_p));
1109 }
1110
1111 sendto_one(source_p, ":%s %d %s p :%u OPER(s)",
1112 from, RPL_STATSDEBUG, to, dlink_list_length(&oper_list));
1113 }
1114
1115 static void
1116 stats_ports(struct Client *source_p, int parc, char *parv[])
1117 {
1118 if (!HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.stats_P_oper_only)
1119 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1120 from, to);
1121 else
1122 show_ports(source_p);
1123 }
1124
1125 static void
1126 stats_resv(struct Client *source_p, int parc, char *parv[])
1127 {
1128 report_resv(source_p);
1129 }
1130
1131 static void
1132 stats_service(struct Client *source_p, int parc, char *parv[])
1133 {
1134 report_confitem_types(source_p, CONF_SERVICE);
1135 }
1136
1137 static void
1138 stats_tstats(struct Client *source_p, int parc, char *parv[])
1139 {
1140 const struct Client *target_p = NULL;
1141 const dlink_node *ptr = NULL;
1142 struct ServerStatistics tmp;
1143 struct ServerStatistics *sp = &tmp;
1144
1145 memcpy(sp, &ServerStats, sizeof(struct ServerStatistics));
1146
1147 /*
1148 * must use the += operator. is_sv is not the number of currently
1149 * active server connections. Note the incrementation in
1150 * s_bsd.c:close_connection.
1151 */
1152 sp->is_sv += dlink_list_length(&serv_list);
1153
1154 DLINK_FOREACH(ptr, serv_list.head)
1155 {
1156 target_p = ptr->data;
1157
1158 sp->is_sbs += target_p->localClient->send.bytes;
1159 sp->is_sbr += target_p->localClient->recv.bytes;
1160 sp->is_sti += CurrentTime - target_p->localClient->firsttime;
1161 }
1162
1163 sp->is_cl += dlink_list_length(&local_client_list);
1164
1165 DLINK_FOREACH(ptr, local_client_list.head)
1166 {
1167 target_p = ptr->data;
1168
1169 sp->is_cbs += target_p->localClient->send.bytes;
1170 sp->is_cbr += target_p->localClient->recv.bytes;
1171 sp->is_cti += CurrentTime - target_p->localClient->firsttime;
1172 }
1173
1174 sp->is_ni += dlink_list_length(&unknown_list);
1175
1176 sendto_one(source_p, ":%s %d %s T :accepts %u refused %u",
1177 me.name, RPL_STATSDEBUG, source_p->name, sp->is_ac, sp->is_ref);
1178 sendto_one(source_p, ":%s %d %s T :unknown commands %u prefixes %u",
1179 me.name, RPL_STATSDEBUG, source_p->name, sp->is_unco, sp->is_unpf);
1180 sendto_one(source_p, ":%s %d %s T :nick collisions %u unknown closes %u",
1181 me.name, RPL_STATSDEBUG, source_p->name, sp->is_kill, sp->is_ni);
1182 sendto_one(source_p, ":%s %d %s T :wrong direction %u empty %u",
1183 me.name, RPL_STATSDEBUG, source_p->name, sp->is_wrdi, sp->is_empt);
1184 sendto_one(source_p, ":%s %d %s T :numerics seen %u",
1185 me.name, RPL_STATSDEBUG, source_p->name, sp->is_num);
1186 sendto_one(source_p, ":%s %d %s T :auth successes %u fails %u",
1187 me.name, RPL_STATSDEBUG, source_p->name, sp->is_asuc, sp->is_abad);
1188 sendto_one(source_p, ":%s %d %s T :Client Server",
1189 me.name, RPL_STATSDEBUG, source_p->name);
1190
1191 sendto_one(source_p, ":%s %d %s T :connected %u %u",
1192 me.name, RPL_STATSDEBUG, source_p->name,
1193 (unsigned int)sp->is_cl,
1194 (unsigned int)sp->is_sv);
1195 sendto_one(source_p, ":%s %d %s T :bytes sent %llu %llu",
1196 me.name, RPL_STATSDEBUG, source_p->name,
1197 sp->is_cbs, sp->is_sbs);
1198 sendto_one(source_p, ":%s %d %s T :bytes recv %llu %llu",
1199 me.name, RPL_STATSDEBUG, source_p->name,
1200 sp->is_cbr, sp->is_sbr);
1201 sendto_one(source_p, ":%s %d %s T :time connected %u %u",
1202 me.name, RPL_STATSDEBUG, source_p->name,
1203 (unsigned int)sp->is_cti,
1204 (unsigned int)sp->is_sti);
1205 }
1206
1207 static void
1208 stats_uptime(struct Client *source_p, int parc, char *parv[])
1209 {
1210 if (!HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.stats_u_oper_only)
1211 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1212 from, to);
1213 else
1214 {
1215 time_t now = CurrentTime - me.localClient->since;
1216
1217 sendto_one(source_p, form_str(RPL_STATSUPTIME), from, to,
1218 now / 86400, (now / 3600) % 24, (now / 60) % 60, now % 60);
1219
1220 if (!ConfigServerHide.disable_remote_commands || HasUMode(source_p, UMODE_OPER))
1221 sendto_one(source_p, form_str(RPL_STATSCONN), from, to,
1222 Count.max_loc_con, Count.max_loc_cli, Count.totalrestartcount);
1223 }
1224 }
1225
1226 static void
1227 stats_shared(struct Client *source_p, int parc, char *parv[])
1228 {
1229 report_confitem_types(source_p, CONF_ULINE);
1230 }
1231
1232 /* stats_servers()
1233 *
1234 * input - client pointer
1235 * output - none
1236 * side effects - client is shown lists of who connected servers
1237 */
1238 static void
1239 stats_servers(struct Client *source_p, int parc, char *parv[])
1240 {
1241 dlink_node *ptr = NULL;
1242
1243 DLINK_FOREACH(ptr, serv_list.head)
1244 {
1245 const struct Client *target_p = ptr->data;
1246
1247 sendto_one(source_p, ":%s %d %s v :%s (%s!%s@%s) Idle: %d",
1248 from, RPL_STATSDEBUG, to, target_p->name,
1249 (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
1250 "*", "*", (int)(CurrentTime - target_p->localClient->lasttime));
1251 }
1252
1253 sendto_one(source_p, ":%s %d %s v :%u Server(s)",
1254 from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list));
1255 }
1256
1257 static void
1258 stats_gecos(struct Client *source_p, int parc, char *parv[])
1259 {
1260 report_confitem_types(source_p, CONF_XLINE);
1261 }
1262
1263 static void
1264 stats_class(struct Client *source_p, int parc, char *parv[])
1265 {
1266 const dlink_node *ptr = NULL;
1267
1268 DLINK_FOREACH(ptr, class_get_list()->head)
1269 {
1270 const struct ClassItem *class = ptr->data;
1271
1272 sendto_one(source_p, form_str(RPL_STATSYLINE),
1273 me.name, source_p->name, 'Y',
1274 class->name, class->ping_freq,
1275 class->con_freq,
1276 class->max_total, class->max_sendq,
1277 class->max_recvq,
1278 class->ref_count,
1279 class->number_per_cidr, class->cidr_bitlen_ipv4,
1280 class->number_per_cidr, class->cidr_bitlen_ipv6,
1281 class->active ? "active" : "disabled");
1282 }
1283 }
1284
1285 static void
1286 stats_servlinks(struct Client *source_p, int parc, char *parv[])
1287 {
1288 uint64_t sendB = 0, recvB = 0;
1289 time_t uptime = 0;
1290 dlink_node *ptr = NULL;
1291
1292 if (ConfigServerHide.flatten_links && !HasUMode(source_p, UMODE_OPER))
1293 {
1294 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1295 from, to);
1296 return;
1297 }
1298
1299 DLINK_FOREACH(ptr, serv_list.head)
1300 {
1301 struct Client *target_p = ptr->data;
1302
1303 if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
1304 if (!HasUMode(source_p, UMODE_OPER))
1305 continue;
1306
1307 sendB += target_p->localClient->send.bytes;
1308 recvB += target_p->localClient->recv.bytes;
1309
1310 /* ":%s 211 %s %s %u %u %llu %u %llu :%u %u %s" */
1311 sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1312 from, to,
1313 get_client_name(target_p, HasUMode(source_p, UMODE_ADMIN) ? SHOW_IP : MASK_IP),
1314 MsgQLength(&target_p->localClient->sendQ),
1315 target_p->localClient->send.messages,
1316 target_p->localClient->send.bytes >> 10,
1317 target_p->localClient->recv.messages,
1318 target_p->localClient->recv.bytes >> 10,
1319 (unsigned)(CurrentTime - target_p->localClient->firsttime),
1320 (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since): 0,
1321 HasUMode(source_p, UMODE_OPER) ? show_capabilities(target_p) : "TS");
1322 }
1323
1324 sendB >>= 10;
1325 recvB >>= 10;
1326
1327 sendto_one(source_p, ":%s %d %s ? :%u total server(s)",
1328 from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list));
1329 sendto_one(source_p, ":%s %d %s ? :Sent total : %7.2f %s",
1330 from, RPL_STATSDEBUG, to,
1331 _GMKv(sendB), _GMKs(sendB));
1332 sendto_one(source_p, ":%s %d %s ? :Recv total : %7.2f %s",
1333 from, RPL_STATSDEBUG, to,
1334 _GMKv(recvB), _GMKs(recvB));
1335
1336 uptime = (CurrentTime - me.localClient->since);
1337
1338 sendto_one(source_p, ":%s %d %s ? :Server send: %7.2f %s (%4.1f K/s)",
1339 from, RPL_STATSDEBUG, to,
1340 _GMKv((me.localClient->send.bytes>>10)),
1341 _GMKs((me.localClient->send.bytes>>10)),
1342 (float)((float)((me.localClient->send.bytes) >> 10) /
1343 (float)uptime));
1344 sendto_one(source_p, ":%s %d %s ? :Server recv: %7.2f %s (%4.1f K/s)",
1345 from, RPL_STATSDEBUG, to,
1346 _GMKv((me.localClient->recv.bytes>>10)),
1347 _GMKs((me.localClient->recv.bytes>>10)),
1348 (float)((float)((me.localClient->recv.bytes) >> 10) /
1349 (float)uptime));
1350 }
1351
1352 /* parse_stats_args()
1353 *
1354 * inputs - arg count
1355 * - args
1356 * - doall flag
1357 * - wild card or not
1358 * output - pointer to name to use
1359 * side effects -
1360 * common parse routine for m_stats args
1361 *
1362 */
1363 static char *
1364 parse_stats_args(int parc, char *parv[], int *doall, int *wilds)
1365 {
1366 char *name;
1367
1368 if (parc > 2)
1369 {
1370 name = parv[2];
1371
1372 if (!irccmp(name, from))
1373 *doall = 2;
1374 else if (!match(name, from))
1375 *doall = 1;
1376
1377 *wilds = has_wildcards(name);
1378
1379 return name;
1380 }
1381
1382 return NULL;
1383 }
1384
1385 static void
1386 stats_L_list(struct Client *source_p,char *name, int doall, int wilds,
1387 dlink_list *list,char statchar)
1388 {
1389 dlink_node *ptr;
1390 struct Client *target_p;
1391
1392 /*
1393 * send info about connections which match, or all if the
1394 * mask matches from. Only restrictions are on those who
1395 * are invisible not being visible to 'foreigners' who use
1396 * a wild card based search to list it.
1397 */
1398 DLINK_FOREACH(ptr, list->head)
1399 {
1400 target_p = ptr->data;
1401
1402 if (HasUMode(target_p, UMODE_INVISIBLE) && (doall || wilds) &&
1403 !(MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) &&
1404 !HasUMode(target_p, UMODE_OPER) && (target_p != source_p))
1405 continue;
1406 if (!doall && wilds && match(name, target_p->name))
1407 continue;
1408 if (!(doall || wilds) && irccmp(name, target_p->name))
1409 continue;
1410
1411 /* This basically shows ips for our opers if its not a server/admin, or
1412 * its one of our admins. */
1413 if(MyClient(source_p) && HasUMode(source_p, UMODE_OPER) &&
1414 (HasUMode(source_p, UMODE_ADMIN) ||
1415 (!IsServer(target_p) && !HasUMode(target_p, UMODE_ADMIN) &&
1416 !IsHandshake(target_p) && !IsConnecting(target_p))))
1417 {
1418 sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1419 from, to,
1420 (IsUpper(statchar)) ?
1421 get_client_name(target_p, SHOW_IP) :
1422 get_client_name(target_p, HIDE_IP),
1423 MsgQLength(&target_p->localClient->sendQ),
1424 target_p->localClient->send.messages,
1425 target_p->localClient->send.bytes>>10,
1426 target_p->localClient->recv.messages,
1427 target_p->localClient->recv.bytes>>10,
1428 (unsigned)(CurrentTime - target_p->localClient->firsttime),
1429 (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0,
1430 IsServer(target_p) ? show_capabilities(target_p) : "-");
1431 }
1432 else
1433 {
1434 /* If its a hidden ip, an admin, or a server, mask the real IP */
1435 if(IsIPSpoof(target_p) || IsServer(target_p) || HasUMode(target_p, UMODE_ADMIN)
1436 || IsHandshake(target_p) || IsConnecting(target_p))
1437 sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1438 from, to,
1439 get_client_name(target_p, MASK_IP),
1440 MsgQLength(&target_p->localClient->sendQ),
1441 target_p->localClient->send.messages,
1442 target_p->localClient->send.bytes>>10,
1443 target_p->localClient->recv.messages,
1444 target_p->localClient->recv.bytes>>10,
1445 (unsigned)(CurrentTime - target_p->localClient->firsttime),
1446 (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0,
1447 IsServer(target_p) ? show_capabilities(target_p) : "-");
1448 else /* show the real IP */
1449 sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1450 from, to,
1451 (IsUpper(statchar)) ?
1452 get_client_name(target_p, SHOW_IP) :
1453 get_client_name(target_p, HIDE_IP),
1454 MsgQLength(&target_p->localClient->sendQ),
1455 target_p->localClient->send.messages,
1456 target_p->localClient->send.bytes>>10,
1457 target_p->localClient->recv.messages,
1458 target_p->localClient->recv.bytes>>10,
1459 (unsigned)(CurrentTime - target_p->localClient->firsttime),
1460 (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0,
1461 IsServer(target_p) ? show_capabilities(target_p) : "-");
1462 }
1463 }
1464 }
1465
1466 /*
1467 * stats_L
1468 *
1469 * inputs - pointer to client to report to
1470 * - doall flag
1471 * - wild card or not
1472 * output - NONE
1473 * side effects -
1474 */
1475 static void
1476 stats_L(struct Client *source_p,char *name,int doall,
1477 int wilds,char statchar)
1478 {
1479 stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar);
1480 stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar);
1481 stats_L_list(source_p, name, doall, wilds, &serv_list, statchar);
1482 }
1483
1484 static void
1485 stats_ltrace(struct Client *source_p, int parc, char *parv[])
1486 {
1487 int doall = 0;
1488 int wilds = 0;
1489 char *name = NULL;
1490 char statchar;
1491
1492 if ((name = parse_stats_args(parc, parv, &doall, &wilds)) != NULL)
1493 {
1494 statchar = parv[1][0];
1495
1496 stats_L(source_p, name, doall, wilds, statchar);
1497 }
1498 else
1499 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1500 from, to, "STATS");
1501 }
1502
1503 static const struct StatsStruct
1504 {
1505 const unsigned char letter;
1506 void (*handler)();
1507 const unsigned int need_oper;
1508 const unsigned int need_admin;
1509 } stats_cmd_table[] = {
1510 /* letter function need_oper need_admin */
1511 { 'a', stats_dns_servers, 1, 1 },
1512 { 'A', stats_dns_servers, 1, 1 },
1513 { 'c', stats_connect, 1, 0 },
1514 { 'C', stats_connect, 1, 0 },
1515 { 'd', stats_tdeny, 1, 0 },
1516 { 'D', stats_deny, 1, 0 },
1517 { 'e', stats_exempt, 1, 0 },
1518 { 'g', stats_pending_glines, 1, 0 },
1519 { 'G', stats_glines, 1, 0 },
1520 { 'h', stats_hooks, 1, 1 },
1521 { 'H', stats_hubleaf, 1, 0 },
1522 { 'i', stats_auth, 0, 0 },
1523 { 'I', stats_auth, 0, 0 },
1524 { 'k', stats_tklines, 0, 0 },
1525 { 'K', stats_klines, 0, 0 },
1526 { 'l', stats_ltrace, 1, 0 },
1527 { 'L', stats_ltrace, 1, 0 },
1528 { 'm', stats_messages, 0, 0 },
1529 { 'M', stats_messages, 0, 0 },
1530 { 'o', stats_oper, 0, 0 },
1531 { 'O', stats_oper, 0, 0 },
1532 { 'p', stats_operedup, 0, 0 },
1533 { 'P', stats_ports, 0, 0 },
1534 { 'q', stats_resv, 1, 0 },
1535 { 'Q', stats_resv, 1, 0 },
1536 { 'r', stats_usage, 1, 0 },
1537 { 'R', stats_usage, 1, 0 },
1538 { 's', stats_service, 1, 0 },
1539 { 'S', stats_service, 1, 0 },
1540 { 't', stats_tstats, 1, 0 },
1541 { 'T', motd_report, 1, 0 },
1542 { 'u', stats_uptime, 0, 0 },
1543 { 'U', stats_shared, 1, 0 },
1544 { 'v', stats_servers, 1, 0 },
1545 { 'x', stats_gecos, 1, 0 },
1546 { 'X', stats_gecos, 1, 0 },
1547 { 'y', stats_class, 1, 0 },
1548 { 'Y', stats_class, 1, 0 },
1549 { 'z', stats_memory, 1, 0 },
1550 { '?', stats_servlinks, 0, 0 },
1551 { '\0', NULL, 0, 0 }
1552 };
1553
1554 static int
1555 do_stats(struct Client *source_p, int parc, char *parv[])
1556 {
1557 const struct StatsStruct *tab = stats_cmd_table;
1558 const char statchar = *parv[1];
1559
1560 if (statchar == '\0')
1561 {
1562 sendto_one(source_p, form_str(RPL_ENDOFSTATS),
1563 from, to, '*');
1564 return 0;
1565 }
1566
1567 for (; tab->handler; ++tab)
1568 {
1569 if (tab->letter == statchar)
1570 {
1571 /* The stats table says what privs are needed, so check --fl_ */
1572 if ((tab->need_admin && !HasUMode(source_p, UMODE_ADMIN)) ||
1573 (tab->need_oper && !HasUMode(source_p, UMODE_OPER)))
1574 {
1575 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1576 from, to);
1577 break;
1578 }
1579
1580 sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE,
1581 "STATS %c requested by %s (%s@%s) [%s]",
1582 statchar, source_p->name, source_p->username,
1583 source_p->host, source_p->servptr->name);
1584 tab->handler(source_p, parc, parv);
1585 break;
1586 }
1587 }
1588
1589 sendto_one(source_p, form_str(RPL_ENDOFSTATS),
1590 from, to, statchar);
1591 return 0;
1592 }
1593
1594 /*
1595 * m_stats()
1596 * parv[0] = sender prefix
1597 * parv[1] = stat letter/command
1598 * parv[2] = (if present) server/mask in stats L
1599 *
1600 * This will search the tables for the appropriate stats letter/command,
1601 * if found execute it.
1602 */
1603 static int
1604 m_stats(struct Client *client_p, struct Client *source_p,
1605 int parc, char *parv[])
1606 {
1607 static time_t last_used = 0;
1608
1609 if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
1610 {
1611 from = me.id;
1612 to = source_p->id;
1613 }
1614 else
1615 {
1616 from = me.name;
1617 to = source_p->name;
1618 }
1619
1620 /* Check the user is actually allowed to do /stats, and isnt flooding */
1621 if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
1622 {
1623 sendto_one(source_p,form_str(RPL_LOAD2HI),
1624 from, to);
1625 return 0;
1626 }
1627
1628 last_used = CurrentTime;
1629
1630 /* Is the stats meant for us? */
1631 if (!ConfigServerHide.disable_remote_commands)
1632 if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
1633 parc, parv) != HUNTED_ISME)
1634 return 0;
1635
1636 return do_stats(source_p, parc, parv);
1637 }
1638
1639 /*
1640 * mo_stats()
1641 * parv[0] = sender prefix
1642 * parv[1] = stat letter/command
1643 * parv[2] = (if present) server/mask in stats L, or target
1644 *
1645 * This will search the tables for the appropriate stats letter,
1646 * if found execute it.
1647 */
1648 static int
1649 mo_stats(struct Client *client_p, struct Client *source_p,
1650 int parc, char *parv[])
1651 {
1652 if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
1653 parc, parv) != HUNTED_ISME)
1654 return 0;
1655
1656 if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
1657 {
1658 from = me.id;
1659 to = source_p->id;
1660 }
1661 else
1662 {
1663 from = me.name;
1664 to = source_p->name;
1665 }
1666
1667 return do_stats(source_p, parc, parv);
1668 }
1669
1670 static struct Message stats_msgtab =
1671 {
1672 "STATS", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
1673 { m_unregistered, m_stats, mo_stats, m_ignore, mo_stats, m_ignore }
1674 };
1675
1676 static void
1677 module_init(void)
1678 {
1679 mod_add_cmd(&stats_msgtab);
1680 }
1681
1682 static void
1683 module_exit(void)
1684 {
1685 mod_del_cmd(&stats_msgtab);
1686 }
1687
1688 struct module module_entry =
1689 {
1690 .node = { NULL, NULL, NULL },
1691 .name = NULL,
1692 .version = "$Revision$",
1693 .handle = NULL,
1694 .modinit = module_init,
1695 .modexit = module_exit,
1696 .flags = 0
1697 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28