ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_stats.c
Revision: 3517
Committed: Mon May 12 17:35:07 2014 UTC (11 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 52946 byte(s)
Log Message:
- m_stats.c:stats_operedup(): don't show idle time if operator is +q

File Contents

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

Properties

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