/[svn]/ircd-hybrid/trunk/modules/m_stats.c
ViewVC logotype

Contents of /ircd-hybrid/trunk/modules/m_stats.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5985 - (show annotations)
Tue May 26 18:52:42 2015 UTC (7 years, 2 months ago) by michael
File MIME type: text/x-chdr
File size: 47734 byte(s)
- Added 'xline_exempt' to auth{} block flags

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

Properties

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

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