ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 7355
Committed: Mon Feb 22 18:59:13 2016 UTC (8 years, 1 month ago) by michael
Content type: text/x-csrc
File size: 47938 byte(s)
Log Message:
- Cleanup more conversion specifiers

File Contents

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

Properties

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