ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 2116
Committed: Sun May 26 11:44:01 2013 UTC (13 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 54234 byte(s)
Log Message:
- Got rid of CONF_CLASS enum type

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

Properties

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