/[svn]/ircd-hybrid/branches/8.2.x/modules/m_stats.c
ViewVC logotype

Contents of /ircd-hybrid/branches/8.2.x/modules/m_stats.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6364 - (show annotations)
Wed Aug 19 09:59:43 2015 UTC (4 years, 10 months ago) by michael
File MIME type: text/x-chdr
File size: 48301 byte(s)
- Remove unused header includes

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

Properties

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

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