ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 1922
Committed: Tue Apr 30 15:08:42 2013 UTC (12 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 53453 byte(s)
Log Message:
- Moved report_confitem_types() to m_stats.c

File Contents

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

Properties

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