ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 6306
Committed: Fri Jul 24 13:23:31 2015 UTC (10 years, 1 month ago) by michael
Content type: text/x-csrc
File size: 48320 byte(s)
Log Message:
- Move show_events() from event.c to m_stats.c. Remove now unused prototypes.

File Contents

# Content
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 const dlink_node *node;
643
644 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
645 "E :Operation Next Execution");
646 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
647 "E :---------------------------------------------");
648
649 DLINK_FOREACH(node, event_get_list()->head)
650 {
651 const struct event *ev = node->data;
652
653 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
654 "E :%-30s %-4d seconds",
655 ev->name,
656 (int)(ev->next - CurrentTime));
657 }
658 }
659
660 static void
661 stats_hubleaf(struct Client *source_p, int parc, char *parv[])
662 {
663 const dlink_node *node = NULL, *dptr = NULL;
664
665 DLINK_FOREACH(node, server_items.head)
666 {
667 const struct MaskItem *conf = node->data;
668
669 DLINK_FOREACH(dptr, conf->hub_list.head)
670 sendto_one_numeric(source_p, &me, RPL_STATSHLINE, 'H', dptr->data, conf->name, 0, "*");
671 }
672
673 DLINK_FOREACH(node, server_items.head)
674 {
675 const struct MaskItem *conf = node->data;
676
677 DLINK_FOREACH(dptr, conf->leaf_list.head)
678 sendto_one_numeric(source_p, &me, RPL_STATSLLINE, 'L', dptr->data, conf->name, 0, "*");
679 }
680 }
681
682 /*
683 * show_iline_prefix()
684 *
685 * inputs - pointer to struct Client requesting output
686 * - pointer to struct MaskItem
687 * - name to which iline prefix will be prefixed to
688 * output - pointer to static string with prefixes listed in ascii form
689 * side effects - NONE
690 */
691 static const char *
692 show_iline_prefix(const struct Client *sptr, const struct MaskItem *conf)
693 {
694 static char prefix_of_host[USERLEN + 16];
695 char *prefix_ptr = prefix_of_host;
696
697 if (IsConfWebIRC(conf))
698 *prefix_ptr++ = '<';
699 if (IsNoTilde(conf))
700 *prefix_ptr++ = '-';
701 if (IsNeedIdentd(conf))
702 *prefix_ptr++ = '+';
703 if (!IsNeedPassword(conf))
704 *prefix_ptr++ = '&';
705 if (IsConfExemptResv(conf))
706 *prefix_ptr++ = '$';
707 if (IsConfDoSpoofIp(conf))
708 *prefix_ptr++ = '=';
709 if (MyOper(sptr) && IsConfExemptKline(conf))
710 *prefix_ptr++ = '^';
711 if (MyOper(sptr) && IsConfExemptXline(conf))
712 *prefix_ptr++ = '!';
713 if (MyOper(sptr) && IsConfExemptLimits(conf))
714 *prefix_ptr++ = '>';
715 if (IsConfCanFlood(conf))
716 *prefix_ptr++ = '|';
717
718 strlcpy(prefix_ptr, conf->user, USERLEN+1);
719
720 return prefix_of_host;
721 }
722
723 static void
724 report_auth(struct Client *source_p, int parc, char *parv[])
725 {
726 const struct MaskItem *conf = NULL;
727 const dlink_node *node = NULL;
728
729 for (unsigned int i = 0; i < ATABLE_SIZE; ++i)
730 {
731 DLINK_FOREACH(node, atable[i].head)
732 {
733 const struct AddressRec *arec = node->data;
734
735 if (arec->type != CONF_CLIENT)
736 continue;
737
738 conf = arec->conf;
739
740 if (!MyOper(source_p) && IsConfDoSpoofIp(conf))
741 continue;
742
743 sendto_one_numeric(source_p, &me, RPL_STATSILINE, 'I',
744 conf->name == NULL ? "*" : conf->name,
745 show_iline_prefix(source_p, conf),
746 conf->host, conf->port,
747 conf->class->name);
748 }
749 }
750 }
751
752 static void
753 stats_auth(struct Client *source_p, int parc, char *parv[])
754 {
755 /* Oper only, if unopered, return ERR_NOPRIVILEGES */
756 if (ConfigGeneral.stats_i_oper_only == 2 && !HasUMode(source_p, UMODE_OPER))
757 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
758
759 /* If unopered, only return matching auth blocks */
760 else if (ConfigGeneral.stats_i_oper_only == 1 && !HasUMode(source_p, UMODE_OPER))
761 {
762 const struct MaskItem *conf = NULL;
763
764 if (MyConnect(source_p))
765 conf = find_conf_by_address(source_p->host,
766 &source_p->connection->ip, CONF_CLIENT,
767 source_p->connection->aftype,
768 source_p->username,
769 source_p->connection->password, 1);
770 else
771 conf = find_conf_by_address(source_p->host, NULL, CONF_CLIENT, 0,
772 source_p->username, NULL, 1);
773
774 if (conf == NULL)
775 return;
776
777 sendto_one_numeric(source_p, &me, RPL_STATSILINE,
778 'I', "*", show_iline_prefix(source_p, conf),
779 conf->host, conf->port,
780 conf->class->name);
781 }
782 else /* They are opered, or allowed to see all auth blocks */
783 report_auth(source_p, 0, NULL);
784 }
785
786 /* report_Klines()
787 * Inputs: Client to report to,
788 * type(==0 for perm, !=0 for temporary)
789 * mask
790 * Output: None
791 * Side effects: Reports configured K(or k)-lines to source_p.
792 */
793 static void
794 report_Klines(struct Client *source_p, int tkline)
795 {
796 const struct MaskItem *conf = NULL;
797 const dlink_node *node = NULL;
798 char c = '\0';
799
800 if (tkline)
801 c = 'k';
802 else
803 c = 'K';
804
805 for (unsigned int i = 0; i < ATABLE_SIZE; ++i)
806 {
807 DLINK_FOREACH(node, atable[i].head)
808 {
809 const struct AddressRec *arec = node->data;
810
811 if (arec->type != CONF_KLINE)
812 continue;
813
814 conf = arec->conf;
815
816 if ((!tkline && conf->until) ||
817 (tkline && !conf->until))
818 continue;
819
820 sendto_one_numeric(source_p, &me, RPL_STATSKLINE, c, conf->host, conf->user,
821 conf->reason);
822 }
823 }
824 }
825
826 static void
827 stats_tklines(struct Client *source_p, int parc, char *parv[])
828 {
829 /* Oper only, if unopered, return ERR_NOPRIVILEGES */
830 if (ConfigGeneral.stats_k_oper_only == 2 && !HasUMode(source_p, UMODE_OPER))
831 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
832
833 /* If unopered, only return matching klines */
834 else if (ConfigGeneral.stats_k_oper_only == 1 && !HasUMode(source_p, UMODE_OPER))
835 {
836 const struct MaskItem *conf = NULL;
837
838 if (MyConnect(source_p))
839 conf = find_conf_by_address(source_p->host,
840 &source_p->connection->ip, CONF_KLINE,
841 source_p->connection->aftype,
842 source_p->username, NULL, 1);
843 else
844 conf = find_conf_by_address(source_p->host, NULL, CONF_KLINE, 0,
845 source_p->username, NULL, 1);
846
847 if (!conf)
848 return;
849
850 /* Don't report a permanent kline as temporary kline */
851 if (!conf->until)
852 return;
853
854 sendto_one_numeric(source_p, &me, RPL_STATSKLINE, 'k',
855 conf->host, conf->user, conf->reason);
856 }
857 else /* They are opered, or allowed to see all klines */
858 report_Klines(source_p, 1);
859 }
860
861 static void
862 stats_klines(struct Client *source_p, int parc, char *parv[])
863 {
864 /* Oper only, if unopered, return ERR_NOPRIVILEGES */
865 if (ConfigGeneral.stats_k_oper_only == 2 && !HasUMode(source_p, UMODE_OPER))
866 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
867
868 /* If unopered, only return matching klines */
869 else if (ConfigGeneral.stats_k_oper_only == 1 && !HasUMode(source_p, UMODE_OPER))
870 {
871 const struct MaskItem *conf = NULL;
872
873 /* Search for a kline */
874 if (MyConnect(source_p))
875 conf = find_conf_by_address(source_p->host,
876 &source_p->connection->ip, CONF_KLINE,
877 source_p->connection->aftype,
878 source_p->username, NULL, 0);
879 else
880 conf = find_conf_by_address(source_p->host, NULL, CONF_KLINE, 0,
881 source_p->username, NULL, 0);
882
883 if (!conf)
884 return;
885
886 /* Don't report a temporary kline as permanent kline */
887 if (conf->until)
888 return;
889
890 sendto_one_numeric(source_p, &me, RPL_STATSKLINE, 'K',
891 conf->host, conf->user, conf->reason);
892 }
893 else /* They are opered, or allowed to see all klines */
894 report_Klines(source_p, 0);
895 }
896
897 static void
898 stats_messages(struct Client *source_p, int parc, char *parv[])
899 {
900 if (!HasUMode(source_p, UMODE_OPER) && ConfigGeneral.stats_m_oper_only)
901 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
902 else
903 report_messages(source_p);
904 }
905
906 static void
907 stats_oper(struct Client *source_p, int parc, char *parv[])
908 {
909 if (!HasUMode(source_p, UMODE_OPER) && ConfigGeneral.stats_o_oper_only)
910 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
911 else
912 report_confitem_types(source_p, CONF_OPER);
913 }
914
915 /* stats_operedup()
916 *
917 * input - client pointer
918 * output - none
919 * side effects - client is shown a list of active opers
920 */
921 static void
922 stats_operedup(struct Client *source_p, int parc, char *parv[])
923 {
924 const dlink_node *node = NULL;
925 unsigned int opercount = 0;
926 char buf[IRCD_BUFSIZE] = "";
927
928 DLINK_FOREACH(node, oper_list.head)
929 {
930 const struct Client *target_p = node->data;
931
932 if (HasUMode(target_p, UMODE_HIDDEN) && !HasUMode(source_p, UMODE_OPER))
933 continue;
934
935 if (HasUMode(source_p, UMODE_OPER) || !HasUMode(target_p, UMODE_HIDEIDLE))
936 snprintf(buf, sizeof(buf), "%u", client_get_idle_time(source_p, target_p));
937 else
938 strlcpy(buf, "n/a", sizeof(buf));
939
940 if (MyClient(source_p) && HasUMode(source_p, UMODE_OPER))
941 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
942 "p :[%c][%s] %s (%s@%s) Idle: %s",
943 HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O',
944 oper_privs_as_string(target_p->connection->operflags),
945 target_p->name, target_p->username, target_p->host, buf);
946 else
947 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
948 "p :[%c] %s (%s@%s) Idle: %s",
949 HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O',
950 target_p->name, target_p->username, target_p->host, buf);
951 ++opercount;
952 }
953
954 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
955 "p :%u OPER(s)", opercount);
956 }
957
958 static void
959 stats_ports(struct Client *source_p, int parc, char *parv[])
960 {
961 if (!HasUMode(source_p, UMODE_OPER) && ConfigGeneral.stats_P_oper_only)
962 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
963 else
964 show_ports(source_p);
965 }
966
967 static void
968 stats_resv(struct Client *source_p, int parc, char *parv[])
969 {
970 report_resv(source_p);
971 }
972
973 static void
974 stats_service(struct Client *source_p, int parc, char *parv[])
975 {
976 report_confitem_types(source_p, CONF_SERVICE);
977 }
978
979 static void
980 stats_tstats(struct Client *source_p, int parc, char *parv[])
981 {
982 const dlink_node *node = NULL;
983 struct ServerStatistics tmp;
984 struct ServerStatistics *sp = &tmp;
985
986 memcpy(sp, &ServerStats, sizeof(struct ServerStatistics));
987
988 /*
989 * must use the += operator. is_sv is not the number of currently
990 * active server connections. Note the incrementation in
991 * s_bsd.c:close_connection.
992 */
993 sp->is_sv += dlink_list_length(&local_server_list);
994
995 DLINK_FOREACH(node, local_server_list.head)
996 {
997 const struct Client *target_p = node->data;
998
999 sp->is_sbs += target_p->connection->send.bytes;
1000 sp->is_sbr += target_p->connection->recv.bytes;
1001 sp->is_sti += CurrentTime - target_p->connection->firsttime;
1002 }
1003
1004 sp->is_cl += dlink_list_length(&local_client_list);
1005
1006 DLINK_FOREACH(node, local_client_list.head)
1007 {
1008 const struct Client *target_p = node->data;
1009
1010 sp->is_cbs += target_p->connection->send.bytes;
1011 sp->is_cbr += target_p->connection->recv.bytes;
1012 sp->is_cti += CurrentTime - target_p->connection->firsttime;
1013 }
1014
1015 sp->is_ni += dlink_list_length(&unknown_list);
1016
1017 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1018 "t :accepts %u refused %u",
1019 sp->is_ac, sp->is_ref);
1020 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1021 "t :unknown commands %u prefixes %u",
1022 sp->is_unco, sp->is_unpf);
1023 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1024 "t :nick collisions %u unknown closes %u",
1025 sp->is_kill, sp->is_ni);
1026 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1027 "t :wrong direction %u empty %u",
1028 sp->is_wrdi, sp->is_empt);
1029 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1030 "t :numerics seen %u",
1031 sp->is_num);
1032 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1033 "t :auth successes %u fails %u",
1034 sp->is_asuc, sp->is_abad);
1035 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1036 "t :Client Server");
1037 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1038 "t :connected %u %u",
1039 (unsigned int)sp->is_cl,
1040 (unsigned int)sp->is_sv);
1041 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1042 "t :bytes sent %llu %llu",
1043 sp->is_cbs, sp->is_sbs);
1044 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1045 "t :bytes recv %llu %llu",
1046 sp->is_cbr, sp->is_sbr);
1047 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1048 "t :time connected %u %u",
1049 (unsigned int)sp->is_cti,
1050 (unsigned int)sp->is_sti);
1051 }
1052
1053 static void
1054 stats_uptime(struct Client *source_p, int parc, char *parv[])
1055 {
1056 if (!HasUMode(source_p, UMODE_OPER) && ConfigGeneral.stats_u_oper_only)
1057 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
1058 else
1059 {
1060 time_t now = CurrentTime - me.connection->since;
1061
1062 sendto_one_numeric(source_p, &me, RPL_STATSUPTIME, now / 86400,
1063 (now / 3600) % 24, (now / 60) % 60, now % 60);
1064
1065 if (!ConfigServerHide.disable_remote_commands || HasUMode(source_p, UMODE_OPER))
1066 sendto_one_numeric(source_p, &me, RPL_STATSCONN, Count.max_loc_con,
1067 Count.max_loc_cli, Count.totalrestartcount);
1068 }
1069 }
1070
1071 static void
1072 stats_shared(struct Client *source_p, int parc, char *parv[])
1073 {
1074 report_confitem_types(source_p, CONF_ULINE);
1075 }
1076
1077 /* stats_servers()
1078 *
1079 * input - client pointer
1080 * output - none
1081 * side effects - client is shown lists of who connected servers
1082 */
1083 static void
1084 stats_servers(struct Client *source_p, int parc, char *parv[])
1085 {
1086 const dlink_node *node = NULL;
1087
1088 DLINK_FOREACH(node, local_server_list.head)
1089 {
1090 const struct Client *target_p = node->data;
1091
1092 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1093 "v :%s (%s!%s@%s) Idle: %d",
1094 target_p->name,
1095 (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
1096 "*", "*", (int)(CurrentTime - target_p->connection->lasttime));
1097 }
1098
1099 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1100 "v :%u Server(s)",
1101 dlink_list_length(&local_server_list));
1102 }
1103
1104 static void
1105 stats_gecos(struct Client *source_p, int parc, char *parv[])
1106 {
1107 report_confitem_types(source_p, CONF_XLINE);
1108 }
1109
1110 static void
1111 stats_class(struct Client *source_p, int parc, char *parv[])
1112 {
1113 const dlink_node *node = NULL;
1114
1115 DLINK_FOREACH(node, class_get_list()->head)
1116 {
1117 const struct ClassItem *class = node->data;
1118
1119 sendto_one_numeric(source_p, &me, RPL_STATSYLINE, 'Y',
1120 class->name, class->ping_freq,
1121 class->con_freq,
1122 class->max_total, class->max_sendq,
1123 class->max_recvq,
1124 class->ref_count,
1125 class->number_per_cidr, class->cidr_bitlen_ipv4,
1126 class->number_per_cidr, class->cidr_bitlen_ipv6,
1127 class->active ? "active" : "disabled");
1128 }
1129 }
1130
1131 static void
1132 stats_servlinks(struct Client *source_p, int parc, char *parv[])
1133 {
1134 uint64_t sendB = 0, recvB = 0;
1135 time_t uptime = 0;
1136 dlink_node *node = NULL;
1137
1138 if (ConfigServerHide.flatten_links && !HasUMode(source_p, UMODE_OPER))
1139 {
1140 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
1141 return;
1142 }
1143
1144 DLINK_FOREACH(node, local_server_list.head)
1145 {
1146 struct Client *target_p = node->data;
1147
1148 if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
1149 if (!HasUMode(source_p, UMODE_OPER))
1150 continue;
1151
1152 sendB += target_p->connection->send.bytes;
1153 recvB += target_p->connection->recv.bytes;
1154
1155 /* ":%s 211 %s %s %u %u %llu %u %llu :%u %u %s" */
1156 sendto_one_numeric(source_p, &me, RPL_STATSLINKINFO,
1157 get_client_name(target_p, HasUMode(source_p, UMODE_ADMIN) ? SHOW_IP : MASK_IP),
1158 dbuf_length(&target_p->connection->buf_sendq),
1159 target_p->connection->send.messages,
1160 target_p->connection->send.bytes >> 10,
1161 target_p->connection->recv.messages,
1162 target_p->connection->recv.bytes >> 10,
1163 (unsigned int)(CurrentTime - target_p->connection->firsttime),
1164 (CurrentTime > target_p->connection->since) ? (unsigned int)(CurrentTime - target_p->connection->since) : 0,
1165 HasUMode(source_p, UMODE_OPER) ? show_capabilities(target_p) : "TS");
1166 }
1167
1168 sendB >>= 10;
1169 recvB >>= 10;
1170
1171 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, "? :%u total server(s)",
1172 dlink_list_length(&local_server_list));
1173 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, "? :Sent total: %7.2f %s",
1174 _GMKv(sendB), _GMKs(sendB));
1175 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, "? :Recv total: %7.2f %s",
1176 _GMKv(recvB), _GMKs(recvB));
1177
1178 uptime = (CurrentTime - me.connection->since);
1179
1180 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1181 "? :Server send: %7.2f %s (%4.1f K/s)",
1182 _GMKv((me.connection->send.bytes>>10)),
1183 _GMKs((me.connection->send.bytes>>10)),
1184 (float)((float)((me.connection->send.bytes) >> 10) /
1185 (float)uptime));
1186 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1187 "? :Server recv: %7.2f %s (%4.1f K/s)",
1188 _GMKv((me.connection->recv.bytes>>10)),
1189 _GMKs((me.connection->recv.bytes>>10)),
1190 (float)((float)((me.connection->recv.bytes) >> 10) /
1191 (float)uptime));
1192 }
1193
1194 /* parse_stats_args()
1195 *
1196 * inputs - arg count
1197 * - args
1198 * - doall flag
1199 * - wild card or not
1200 * output - pointer to name to use
1201 * side effects -
1202 * common parse routine for m_stats args
1203 *
1204 */
1205 static const char *
1206 parse_stats_args(struct Client *source_p, int parc, char *parv[], int *doall, int *wilds)
1207 {
1208 if (parc > 2)
1209 {
1210 const char *name = parv[2];
1211
1212 if (!irccmp(name, ID_or_name(&me, source_p)))
1213 *doall = 2;
1214 else if (!match(name, ID_or_name(&me, source_p)))
1215 *doall = 1;
1216
1217 *wilds = has_wildcards(name);
1218
1219 return name;
1220 }
1221
1222 return NULL;
1223 }
1224
1225 static void
1226 stats_L_list(struct Client *source_p, const char *name, int doall, int wilds,
1227 dlink_list *list, const char statchar)
1228 {
1229 dlink_node *node = NULL;
1230
1231 /*
1232 * Send info about connections which match, or all if the
1233 * mask matches from. Only restrictions are on those who
1234 * are invisible not being visible to 'foreigners' who use
1235 * a wild card based search to list it.
1236 */
1237 DLINK_FOREACH(node, list->head)
1238 {
1239 struct Client *target_p = node->data;
1240
1241 if (HasUMode(target_p, UMODE_INVISIBLE) && (doall || wilds) &&
1242 !(MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) &&
1243 !HasUMode(target_p, UMODE_OPER) && (target_p != source_p))
1244 continue;
1245
1246 if (!doall && wilds && match(name, target_p->name))
1247 continue;
1248
1249 if (!(doall || wilds) && irccmp(name, target_p->name))
1250 continue;
1251
1252 /*
1253 * This basically shows ips for our opers if it's not a server/admin, or
1254 * it's one of our admins.
1255 */
1256 if (MyClient(source_p) && HasUMode(source_p, UMODE_OPER) &&
1257 (HasUMode(source_p, UMODE_ADMIN) ||
1258 (!IsServer(target_p) && !HasUMode(target_p, UMODE_ADMIN) &&
1259 !IsHandshake(target_p) && !IsConnecting(target_p))))
1260 {
1261 sendto_one_numeric(source_p, &me, RPL_STATSLINKINFO,
1262 (IsUpper(statchar)) ?
1263 get_client_name(target_p, SHOW_IP) :
1264 get_client_name(target_p, HIDE_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 }
1274 else
1275 {
1276 /* If it's a server, mask the real IP */
1277 if (IsServer(target_p) || IsHandshake(target_p) || IsConnecting(target_p))
1278 sendto_one_numeric(source_p, &me, RPL_STATSLINKINFO,
1279 get_client_name(target_p, MASK_IP),
1280 dbuf_length(&target_p->connection->buf_sendq),
1281 target_p->connection->send.messages,
1282 target_p->connection->send.bytes>>10,
1283 target_p->connection->recv.messages,
1284 target_p->connection->recv.bytes>>10,
1285 (unsigned int)(CurrentTime - target_p->connection->firsttime),
1286 (CurrentTime > target_p->connection->since) ? (unsigned int)(CurrentTime - target_p->connection->since):0,
1287 IsServer(target_p) ? show_capabilities(target_p) : "-");
1288 else /* show the real IP */
1289 sendto_one_numeric(source_p, &me, RPL_STATSLINKINFO,
1290 (IsUpper(statchar)) ?
1291 get_client_name(target_p, SHOW_IP) :
1292 get_client_name(target_p, HIDE_IP),
1293 dbuf_length(&target_p->connection->buf_sendq),
1294 target_p->connection->send.messages,
1295 target_p->connection->send.bytes>>10,
1296 target_p->connection->recv.messages,
1297 target_p->connection->recv.bytes>>10,
1298 (unsigned int)(CurrentTime - target_p->connection->firsttime),
1299 (CurrentTime > target_p->connection->since) ? (unsigned int)(CurrentTime - target_p->connection->since):0,
1300 IsServer(target_p) ? show_capabilities(target_p) : "-");
1301 }
1302 }
1303 }
1304
1305 /*
1306 * stats_L
1307 *
1308 * inputs - pointer to client to report to
1309 * - doall flag
1310 * - wild card or not
1311 * output - NONE
1312 * side effects -
1313 */
1314 static void
1315 stats_L(struct Client *source_p, const char *name, int doall,
1316 int wilds, const char statchar)
1317 {
1318 stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar);
1319 stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar);
1320 stats_L_list(source_p, name, doall, wilds, &local_server_list, statchar);
1321 }
1322
1323 static void
1324 stats_ltrace(struct Client *source_p, int parc, char *parv[])
1325 {
1326 int doall = 0;
1327 int wilds = 0;
1328 const char *name = NULL;
1329
1330 if ((name = parse_stats_args(source_p, parc, parv, &doall, &wilds)))
1331 {
1332 const char statchar = *parv[1];
1333 stats_L(source_p, name, doall, wilds, statchar);
1334 }
1335 else
1336 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "STATS");
1337 }
1338
1339 static const struct StatsStruct
1340 {
1341 const unsigned char letter;
1342 void (*handler)(struct Client *, int, char *[]);
1343 const unsigned int need_oper;
1344 const unsigned int need_admin;
1345 } stats_cmd_table[] = {
1346 /* letter function need_oper need_admin */
1347 { 'a', stats_dns_servers, 1, 1 },
1348 { 'A', stats_dns_servers, 1, 1 },
1349 { 'c', stats_connect, 1, 0 },
1350 { 'C', stats_connect, 1, 0 },
1351 { 'd', stats_tdeny, 1, 0 },
1352 { 'D', stats_deny, 1, 0 },
1353 { 'e', stats_exempt, 1, 0 },
1354 { 'E', stats_events, 1, 1 },
1355 { 'f', fd_dump, 1, 1 },
1356 { 'F', fd_dump, 1, 1 },
1357 { 'h', stats_hubleaf, 1, 1 },
1358 { 'H', stats_hubleaf, 1, 0 },
1359 { 'i', stats_auth, 0, 0 },
1360 { 'I', stats_auth, 0, 0 },
1361 { 'k', stats_tklines, 0, 0 },
1362 { 'K', stats_klines, 0, 0 },
1363 { 'l', stats_ltrace, 1, 0 },
1364 { 'L', stats_ltrace, 1, 0 },
1365 { 'm', stats_messages, 0, 0 },
1366 { 'M', stats_messages, 0, 0 },
1367 { 'o', stats_oper, 0, 0 },
1368 { 'O', stats_oper, 0, 0 },
1369 { 'p', stats_operedup, 0, 0 },
1370 { 'P', stats_ports, 0, 0 },
1371 { 'q', stats_resv, 1, 0 },
1372 { 'Q', stats_resv, 1, 0 },
1373 { 'r', stats_usage, 1, 0 },
1374 { 'R', stats_usage, 1, 0 },
1375 { 's', stats_service, 1, 0 },
1376 { 'S', stats_service, 1, 0 },
1377 { 't', stats_tstats, 1, 0 },
1378 { 'T', motd_report, 1, 0 },
1379 { 'u', stats_uptime, 0, 0 },
1380 { 'U', stats_shared, 1, 0 },
1381 { 'v', stats_servers, 1, 0 },
1382 { 'x', stats_gecos, 1, 0 },
1383 { 'X', stats_gecos, 1, 0 },
1384 { 'y', stats_class, 1, 0 },
1385 { 'Y', stats_class, 1, 0 },
1386 { 'z', stats_memory, 1, 0 },
1387 { '?', stats_servlinks, 0, 0 },
1388 { '\0', NULL, 0, 0 }
1389 };
1390
1391 static void
1392 do_stats(struct Client *source_p, int parc, char *parv[])
1393 {
1394 const char statchar = *parv[1];
1395
1396 if (statchar == '\0')
1397 {
1398 sendto_one_numeric(source_p, &me, RPL_ENDOFSTATS, '*');
1399 return;
1400 }
1401
1402 for (const struct StatsStruct *tab = stats_cmd_table; tab->handler; ++tab)
1403 {
1404 if (tab->letter == statchar)
1405 {
1406 /* The stats table says what privs are needed, so check --fl_ */
1407 if ((tab->need_admin && !HasUMode(source_p, UMODE_ADMIN)) ||
1408 (tab->need_oper && !HasUMode(source_p, UMODE_OPER)))
1409 {
1410 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
1411 break;
1412 }
1413
1414 sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE,
1415 "STATS %c requested by %s (%s@%s) [%s]",
1416 statchar, source_p->name, source_p->username,
1417 source_p->host, source_p->servptr->name);
1418 tab->handler(source_p, parc, parv);
1419 break;
1420 }
1421 }
1422
1423 sendto_one_numeric(source_p, &me, RPL_ENDOFSTATS, statchar);
1424 }
1425
1426 /*
1427 * m_stats()
1428 * parv[0] = command
1429 * parv[1] = stat letter/command
1430 * parv[2] = (if present) server/mask in stats L
1431 */
1432 static int
1433 m_stats(struct Client *source_p, int parc, char *parv[])
1434 {
1435 static time_t last_used = 0;
1436
1437 /* Check the user is actually allowed to do /stats, and isn't flooding */
1438 if ((last_used + ConfigGeneral.pace_wait) > CurrentTime)
1439 {
1440 sendto_one_numeric(source_p, &me, RPL_LOAD2HI, "STATS");
1441 return 0;
1442 }
1443
1444 last_used = CurrentTime;
1445
1446 /* Is the stats meant for us? */
1447 if (!ConfigServerHide.disable_remote_commands)
1448 if (hunt_server(source_p, ":%s STATS %s :%s", 2, parc, parv) != HUNTED_ISME)
1449 return 0;
1450
1451 do_stats(source_p, parc, parv);
1452 return 0;
1453 }
1454
1455 /*
1456 * ms_stats()
1457 * parv[0] = command
1458 * parv[1] = stat letter/command
1459 * parv[2] = (if present) server/mask in stats L, or target
1460 */
1461 static int
1462 ms_stats(struct Client *source_p, int parc, char *parv[])
1463 {
1464 if (hunt_server(source_p, ":%s STATS %s :%s", 2, parc, parv) != HUNTED_ISME)
1465 return 0;
1466
1467 do_stats(source_p, parc, parv);
1468 return 0;
1469 }
1470
1471 static struct Message stats_msgtab =
1472 {
1473 .cmd = "STATS",
1474 .args_min = 2,
1475 .args_max = MAXPARA,
1476 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
1477 .handlers[CLIENT_HANDLER] = m_stats,
1478 .handlers[SERVER_HANDLER] = ms_stats,
1479 .handlers[ENCAP_HANDLER] = m_ignore,
1480 .handlers[OPER_HANDLER] = ms_stats
1481 };
1482
1483 static void
1484 module_init(void)
1485 {
1486 mod_add_cmd(&stats_msgtab);
1487 }
1488
1489 static void
1490 module_exit(void)
1491 {
1492 mod_del_cmd(&stats_msgtab);
1493 }
1494
1495 struct module module_entry =
1496 {
1497 .version = "$Revision$",
1498 .modinit = module_init,
1499 .modexit = module_exit,
1500 };

Properties

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