ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_stats.c
Revision: 3283
Committed: Tue Apr 8 16:39:50 2014 UTC (10 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/modules/m_stats.c
File size: 52765 byte(s)
Log Message:
- Style corrections/constification

File Contents

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

Properties

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