/[svn]/branches/newio/modules/m_stats.c
ViewVC logotype

Contents of /branches/newio/modules/m_stats.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2417 - (show annotations)
Sun Jul 21 18:11:50 2013 UTC (9 years ago) by michael
File MIME type: text/x-chdr
File size: 53607 byte(s)
- Change command message handlers to int type

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

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28