ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 3079
Committed: Sat Mar 1 17:22:03 2014 UTC (12 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 54121 byte(s)
Log Message:
- white-space changes / style cleanups

File Contents

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

Properties

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