ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 3347
Committed: Sun Apr 20 14:03:06 2014 UTC (9 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 52779 byte(s)
Log Message:
- Moved files:
  s_user.c -> user.c
  s_misc.c -> misc.c
  s_serv.c -> server.c

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

Properties

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