/[svn]/ircd-hybrid-7.2/modules/m_stats.c
ViewVC logotype

Contents of /ircd-hybrid-7.2/modules/m_stats.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 584 - (show annotations)
Sun May 7 15:26:45 2006 UTC (14 years, 8 months ago) by michael
File MIME type: text/x-chdr
File size: 43616 byte(s)
- Added new general::stats_e_disabled configuration option.  Known from RB,
  all it does is to disable "STATS e", which is a good idea if you have any
  exempted server ips.
- Updated RELNOTES

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 "tools.h" /* dlink_node/dlink_list */
27 #include "handlers.h" /* m_pass prototype */
28 #include "client.h" /* Client */
29 #include "common.h" /* TRUE/FALSE */
30 #include "irc_string.h"
31 #include "ircd.h" /* me */
32 #include "listener.h" /* show_ports */
33 #include "s_gline.h"
34 #include "ircd_handler.h"
35 #include "msg.h" /* Message */
36 #include "hostmask.h"
37 #include "numeric.h" /* ERR_xxx */
38 #include "send.h" /* sendto_one */
39 #include "fdlist.h" /* PF and friends */
40 #include "s_bsd.h" /* highest_fd */
41 #include "s_conf.h" /* AccessItem, report_configured_links */
42 #include "s_misc.h" /* serv_info */
43 #include "s_serv.h" /* hunt_server */
44 #include "s_stats.h" /* tstats */
45 #include "s_user.h" /* show_opers */
46 #include "event.h" /* events */
47 #include "dbuf.h"
48 #include "parse.h"
49 #include "modules.h"
50 #include "hook.h"
51 #include "resv.h" /* report_resv */
52 #include "whowas.h"
53 #include "list.h"
54
55 static void do_stats(struct Client *, int, char **);
56 static void m_stats(struct Client *, struct Client *, int, char *[]);
57 static void mo_stats(struct Client *, struct Client *, int, char *[]);
58 static void ms_stats(struct Client *, struct Client *, int, char *[]);
59
60 struct Message stats_msgtab = {
61 "STATS", 0, 0, 2, 0, MFLG_SLOW, 0,
62 { m_unregistered, m_stats, ms_stats, m_ignore, mo_stats, m_ignore }
63 };
64
65 #ifndef STATIC_MODULES
66 const char *_version = "$Revision$";
67 static struct Callback *stats_cb;
68
69 static void *
70 va_stats(va_list args)
71 {
72 struct Client *source_p = va_arg(args, struct Client *);
73 int parc = va_arg(args, int);
74 char **parv = va_arg(args, char **);
75
76 do_stats(source_p, parc, parv);
77 return NULL;
78 }
79
80 void
81 _modinit(void)
82 {
83 stats_cb = register_callback("doing_stats", va_stats);
84 mod_add_cmd(&stats_msgtab);
85 }
86
87 void
88 _moddeinit(void)
89 {
90 mod_del_cmd(&stats_msgtab);
91 uninstall_hook(stats_cb, va_stats);
92 }
93 #endif
94
95 static char *parse_stats_args(int, char **, int *, int *);
96 static void stats_L(struct Client *, char *, int, int, char);
97 static void stats_L_list(struct Client *s, char *, int, int, dlink_list *, char);
98
99 static void stats_dns_servers(struct Client *);
100 static void stats_connect(struct Client *);
101 static void stats_deny(struct Client *);
102 static void stats_tdeny(struct Client *);
103 static void stats_exempt(struct Client *);
104 static void stats_events(struct Client *);
105 static void stats_pending_glines(struct Client *);
106 static void stats_glines(struct Client *);
107 static void stats_gdeny(struct Client *);
108 static void stats_hubleaf(struct Client *);
109 static void stats_auth(struct Client *);
110 static void stats_tklines(struct Client *);
111 static void stats_klines(struct Client *);
112 static void stats_messages(struct Client *);
113 static void stats_oper(struct Client *);
114 static void stats_operedup(struct Client *);
115 static void stats_ports(struct Client *);
116 static void stats_resv(struct Client *);
117 static void stats_usage(struct Client *);
118 static void stats_tstats(struct Client *);
119 static void stats_uptime(struct Client *);
120 static void stats_shared(struct Client *);
121 static void stats_servers(struct Client *);
122 static void stats_gecos(struct Client *);
123 static void stats_class(struct Client *);
124 static void stats_memory(struct Client *);
125 static void stats_servlinks(struct Client *);
126 static void stats_ltrace(struct Client *, int, char **);
127 static void stats_ziplinks(struct Client *);
128
129 /* This table contains the possible stats items, in order:
130 * /stats name, function to call, operonly? adminonly? /stats letter
131 * case only matters in the stats letter column.. -- fl_ */
132 static const struct StatsStruct
133 {
134 const unsigned char letter;
135 void (*handler)();
136 const unsigned int need_oper;
137 const unsigned int need_admin;
138 } stats_cmd_table[] = {
139 /* letter function need_oper need_admin */
140 { 'a', stats_dns_servers, 1, 1, },
141 { 'A', stats_dns_servers, 1, 1, },
142 { 'c', stats_connect, 1, 0, },
143 { 'C', stats_connect, 1, 0, },
144 { 'd', stats_tdeny, 1, 0, },
145 { 'D', stats_deny, 1, 0, },
146 { 'e', stats_exempt, 1, 0, },
147 { 'E', stats_events, 1, 1, },
148 { 'f', fd_dump, 1, 1, },
149 { 'F', fd_dump, 1, 1, },
150 { 'g', stats_pending_glines, 1, 0, },
151 { 'G', stats_glines, 1, 0, },
152 { 'h', stats_hooks, 1, 1, },
153 { 'H', stats_hubleaf, 1, 0, },
154 { 'i', stats_auth, 0, 0, },
155 { 'I', stats_auth, 0, 0, },
156 { 'k', stats_tklines, 0, 0, },
157 { 'K', stats_klines, 0, 0, },
158 { 'l', stats_ltrace, 1, 0, },
159 { 'L', stats_ltrace, 1, 0, },
160 { 'm', stats_messages, 0, 0, },
161 { 'M', stats_messages, 0, 0, },
162 { 'o', stats_oper, 0, 0, },
163 { 'O', stats_oper, 0, 0, },
164 { 'p', stats_operedup, 0, 0, },
165 { 'P', stats_ports, 0, 0, },
166 { 'q', stats_resv, 1, 0, },
167 { 'Q', stats_resv, 1, 0, },
168 { 'r', stats_usage, 1, 0, },
169 { 'R', stats_usage, 1, 0, },
170 { 't', stats_tstats, 1, 0, },
171 { 'T', stats_tstats, 1, 0, },
172 { 'u', stats_uptime, 0, 0, },
173 { 'U', stats_shared, 1, 0, },
174 { 'v', stats_servers, 1, 0, },
175 { 'V', stats_gdeny, 1, 0, },
176 { 'x', stats_gecos, 1, 0, },
177 { 'X', stats_gecos, 1, 0, },
178 { 'y', stats_class, 1, 0, },
179 { 'Y', stats_class, 1, 0, },
180 { 'z', stats_memory, 1, 0, },
181 { 'Z', stats_ziplinks, 1, 0, },
182 { '?', stats_servlinks, 0, 0, },
183 { '\0', (void(*)())0, 0, 0, }
184 };
185
186 const char *from, *to;
187
188 static void
189 do_stats(struct Client *source_p, int parc, char **parv)
190 {
191 char statchar = *parv[1];
192 int i;
193
194 if (statchar == '\0')
195 {
196 sendto_one(source_p, form_str(RPL_ENDOFSTATS),
197 from, to, '*');
198 return;
199 }
200
201 for (i = 0; stats_cmd_table[i].handler; i++)
202 {
203 if (stats_cmd_table[i].letter == statchar)
204 {
205 /* The stats table says what privs are needed, so check --fl_ */
206 if ((stats_cmd_table[i].need_admin && !IsAdmin(source_p)) ||
207 (stats_cmd_table[i].need_oper && !IsOper(source_p)))
208 {
209 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
210 from, to);
211 break;
212 }
213
214 /* Blah, stats L needs the parameters, none of the others do.. */
215 if (statchar == 'L' || statchar == 'l')
216 stats_cmd_table[i].handler(source_p, parc, parv);
217 else
218 stats_cmd_table[i].handler(source_p);
219
220 break;
221 }
222 }
223
224 sendto_one(source_p, form_str(RPL_ENDOFSTATS),
225 from, to, statchar);
226 }
227
228 /*
229 * m_stats()
230 * parv[0] = sender prefix
231 * parv[1] = stat letter/command
232 * parv[2] = (if present) server/mask in stats L
233 *
234 * This will search the tables for the appropriate stats letter/command,
235 * if found execute it.
236 */
237 static void
238 m_stats(struct Client *client_p, struct Client *source_p,
239 int parc, char *parv[])
240 {
241 static time_t last_used = 0;
242
243 /* Is the stats meant for us? */
244 if (!ConfigFileEntry.disable_remote)
245 if (hunt_server(client_p,source_p,":%s STATS %s :%s",2,parc,parv) != HUNTED_ISME)
246 return;
247
248 if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
249 {
250 from = me.id;
251 to = source_p->id;
252 }
253 else
254 {
255 from = me.name;
256 to = source_p->name;
257 }
258
259 /* Check the user is actually allowed to do /stats, and isnt flooding */
260 if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
261 {
262 sendto_one(source_p,form_str(RPL_LOAD2HI),
263 from, to);
264 return;
265 }
266 else
267 last_used = CurrentTime;
268
269 #ifdef STATIC_MODULES
270 do_stats(source_p, parc, parv);
271 #else
272 execute_callback(stats_cb, source_p, parc, parv);
273 #endif
274 }
275
276 /*
277 * mo_stats()
278 * parv[0] = sender prefix
279 * parv[1] = stat letter/command
280 * parv[2] = (if present) server/mask in stats L, or target
281 *
282 * This will search the tables for the appropriate stats letter,
283 * if found execute it.
284 */
285 static void
286 mo_stats(struct Client *client_p, struct Client *source_p,
287 int parc, char *parv[])
288 {
289 if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
290 parc, parv) != HUNTED_ISME)
291 return;
292
293 if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
294 {
295 from = me.id;
296 to = source_p->id;
297 }
298 else
299 {
300 from = me.name;
301 to = source_p->name;
302 }
303
304 #ifdef STATIC_MODULES
305 do_stats(source_p, parc, parv);
306 #else
307 execute_callback(stats_cb, source_p, parc, parv);
308 #endif
309 }
310
311 /*
312 * This is part of the STATS replies. There is no offical numeric for this
313 * since this isnt an official command, in much the same way as HASH isnt.
314 * It is also possible that some systems wont support this call or have
315 * different field names for "struct rusage".
316 * -avalon
317 */
318 static void
319 send_usage(struct Client *source_p)
320 {
321 #ifndef _WIN32
322 struct rusage rus;
323 time_t secs;
324 time_t rup;
325 #ifdef hz
326 # define hzz hz
327 #else
328 # ifdef HZ
329 # define hzz HZ
330 # else
331 int hzz = 1;
332 # endif
333 #endif
334
335 if (getrusage(RUSAGE_SELF, &rus) == -1)
336 {
337 sendto_one(source_p, ":%s NOTICE %s :Getruseage error: %s",
338 me.name, source_p->name, strerror(errno));
339 return;
340 }
341
342 secs = rus.ru_utime.tv_sec + rus.ru_stime.tv_sec;
343
344 if (secs == 0)
345 secs = 1;
346
347 rup = (CurrentTime - me.since) * hzz;
348
349 if (rup == 0)
350 rup = 1;
351
352 sendto_one(source_p,
353 ":%s %d %s R :CPU Secs %d:%d User %d:%d System %d:%d",
354 me.name, RPL_STATSDEBUG, source_p->name, (int)(secs/60), (int)(secs%60),
355 (int)(rus.ru_utime.tv_sec/60), (int)(rus.ru_utime.tv_sec%60),
356 (int)(rus.ru_stime.tv_sec/60), (int)(rus.ru_stime.tv_sec%60));
357 sendto_one(source_p, ":%s %d %s R :RSS %ld ShMem %ld Data %ld Stack %ld",
358 me.name, RPL_STATSDEBUG, source_p->name, rus.ru_maxrss,
359 (rus.ru_ixrss / rup), (rus.ru_idrss / rup),
360 (rus.ru_isrss / rup));
361 sendto_one(source_p, ":%s %d %s R :Swaps %d Reclaims %d Faults %d",
362 me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_nswap,
363 (int)rus.ru_minflt, (int)rus.ru_majflt);
364 sendto_one(source_p, ":%s %d %s R :Block in %d out %d",
365 me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_inblock,
366 (int)rus.ru_oublock);
367 sendto_one(source_p, ":%s %d %s R :Msg Rcv %d Send %d",
368 me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_msgrcv,
369 (int)rus.ru_msgsnd);
370 sendto_one(source_p, ":%s %d %s R :Signals %d Context Vol. %d Invol %d",
371 me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_nsignals,
372 (int)rus.ru_nvcsw, (int)rus.ru_nivcsw);
373 #endif
374 }
375
376 static void
377 count_memory(struct Client *source_p)
378 {
379 const dlink_node *gptr = NULL;
380 const dlink_node *dlink = NULL;
381
382 int local_client_conf_count = 0; /* local client conf links */
383 int users_counted = 0; /* user structs */
384
385 int channel_users = 0; /* XXX */
386 int channel_invites = 0;
387 int channel_bans = 0;
388 int channel_except = 0;
389 int channel_invex = 0;
390
391 int wwu = 0; /* whowas users */
392 int class_count = 0; /* classes */
393 int users_invited_count = 0; /* users invited */
394 int aways_counted = 0;
395 int number_ips_stored; /* number of ip addresses hashed */
396
397 unsigned long channel_memory = 0;
398 size_t channel_ban_memory = 0;
399 size_t channel_except_memory = 0;
400 size_t channel_invex_memory = 0;
401
402 unsigned int safelist_count = 0;
403 size_t safelist_memory = 0;
404
405 unsigned long away_memory = 0; /* memory used by aways */
406 unsigned long wwm = 0; /* whowas array memory used */
407 unsigned long conf_memory = 0; /* memory used by conf lines */
408 unsigned long mem_ips_stored; /* memory used by ip address hash */
409
410 unsigned long client_hash_table_size = 0;
411 unsigned long channel_hash_table_size = 0;
412 unsigned long resv_hash_table_size = 0;
413 unsigned long id_hash_table_size = 0;
414 unsigned long total_channel_memory = 0;
415 unsigned long totww = 0;
416
417 unsigned int local_client_count = 0;
418 unsigned int remote_client_count = 0;
419
420 unsigned int local_client_memory_used = 0;
421 unsigned int remote_client_memory_used = 0;
422
423 unsigned long total_memory = 0;
424 unsigned int topic_count = 0;
425
426 count_whowas_memory(&wwu, &wwm);
427
428 DLINK_FOREACH(gptr, global_client_list.head)
429 {
430 struct Client *target_p = gptr->data;
431
432 if (MyConnect(target_p))
433 {
434 ++local_client_count;
435 local_client_conf_count += dlink_list_length(&target_p->localClient->confs);
436 users_invited_count += dlink_list_length(&target_p->localClient->invited);
437 }
438 else
439 ++remote_client_count;
440
441 if (IsClient(target_p))
442 {
443 ++users_counted;
444
445 if (target_p->away != NULL)
446 {
447 ++aways_counted;
448 away_memory += strlen(target_p->away) + 1;
449 }
450 }
451 }
452
453 /* Count up all channels, ban lists, except lists, Invex lists */
454 channel_memory = dlink_list_length(&global_channel_list) *
455 sizeof(struct Channel);
456 DLINK_FOREACH(gptr, global_channel_list.head)
457 {
458 struct Ban *actualBan;
459 struct Channel *chptr = gptr->data;
460
461 channel_users += dlink_list_length(&chptr->members);
462 channel_invites += dlink_list_length(&chptr->invites);
463
464 if (chptr->topic != NULL)
465 ++topic_count;
466
467 if ((channel_bans = dlink_list_length(&chptr->banlist)))
468 {
469 channel_ban_memory = channel_bans * sizeof(struct Ban);
470
471 DLINK_FOREACH(dlink, chptr->banlist.head)
472 {
473 actualBan = dlink->data;
474 assert(actualBan->who);
475
476 channel_ban_memory += actualBan->len + 3;
477 channel_ban_memory += strlen(actualBan->who) + 1;
478 }
479 }
480
481 if ((channel_except = dlink_list_length(&chptr->exceptlist)))
482 {
483 channel_except_memory = channel_except * sizeof(struct Ban);
484
485 DLINK_FOREACH(dlink, chptr->exceptlist.head)
486 {
487 actualBan = dlink->data;
488 assert(actualBan->who);
489
490 channel_except_memory += actualBan->len + 3;
491 channel_except_memory += strlen(actualBan->who) + 1;
492 }
493 }
494
495 if ((channel_invex = dlink_list_length(&chptr->invexlist)))
496 {
497 channel_invex_memory = channel_invex * sizeof(struct Ban);
498
499 DLINK_FOREACH(dlink, chptr->invexlist.head)
500 {
501 actualBan = dlink->data;
502 assert(actualBan->who);
503
504 channel_invex_memory += actualBan->len + 3;
505 channel_invex_memory += strlen(actualBan->who) + 1;
506 }
507 }
508 }
509
510 if ((safelist_count = dlink_list_length(&listing_client_list)))
511 {
512 safelist_memory = safelist_count * sizeof(struct ListTask);
513 DLINK_FOREACH(gptr, listing_client_list.head)
514 {
515 struct Client *acptr = gptr->data;
516
517 DLINK_FOREACH(dlink, acptr->localClient->list_task->show_mask.head)
518 safelist_memory += strlen(dlink->data);
519
520 DLINK_FOREACH(dlink, acptr->localClient->list_task->hide_mask.head)
521 safelist_memory += strlen(dlink->data);
522 }
523 }
524
525 #if 0
526 /* XXX THIS has to be fixed !!!! -db */
527 /* count up all config items */
528 DLINK_FOREACH(dlink, ConfigItemList.head)
529 {
530 aconf = dlink->data;
531 conf_memory += aconf->host ? strlen(aconf->host)+1 : 0;
532 conf_memory += aconf->passwd ? strlen(aconf->passwd)+1 : 0;
533 conf_memory += aconf->name ? strlen(aconf->name)+1 : 0;
534 conf_memory += sizeof(struct AccessItem);
535 }
536 #endif
537 /* count up all classes */
538 class_count = dlink_list_length(&class_items);
539
540 sendto_one(source_p, ":%s %d %s z :Clients %u(%lu) Invites %u(%lu)",
541 me.name, RPL_STATSDEBUG, source_p->name, users_counted,
542 (unsigned long)(users_counted * sizeof(struct Client)),
543 users_invited_count, (unsigned long)(users_invited_count * sizeof(dlink_node)));
544
545 sendto_one(source_p, ":%s %d %s z :User aways %u(%d)",
546 me.name, RPL_STATSDEBUG, source_p->name,
547 aways_counted, (int)away_memory);
548
549 sendto_one(source_p, ":%s %d %s z :Attached confs %u(%lu)",
550 me.name, RPL_STATSDEBUG, source_p->name,
551 local_client_conf_count,
552 (unsigned long)(local_client_conf_count * sizeof(dlink_node)));
553
554 /* XXX ConfigItemList fix */
555 #if 0
556 sendto_one(source_p, ":%s %d %s z :Conflines %lu(%d)",
557 me.name, RPL_STATSDEBUG, source_p->name,
558 dlink_list_length(&ConfigItemList), (int) conf_memory);
559 #endif
560
561 sendto_one(source_p, ":%s %d %s z :Resv channels %lu(%lu) nicks %lu(%lu)",
562 me.name, RPL_STATSDEBUG, source_p->name,
563 dlink_list_length(&resv_channel_list),
564 dlink_list_length(&resv_channel_list) * sizeof(struct ResvChannel),
565 dlink_list_length(&nresv_items),
566 dlink_list_length(&nresv_items) * sizeof(struct MatchItem));
567
568 sendto_one(source_p, ":%s %d %s z :Classes %u(%lu)",
569 me.name, RPL_STATSDEBUG, source_p->name,
570 class_count, (unsigned long)(class_count * sizeof(struct ClassItem)));
571
572 sendto_one(source_p, ":%s %d %s z :Channels %lu(%lu) Topics %u(%d)",
573 me.name, RPL_STATSDEBUG, source_p->name,
574 dlink_list_length(&global_channel_list),
575 channel_memory, topic_count, topic_count *
576 (TOPICLEN + 1 + USERHOST_REPLYLEN));
577
578 sendto_one(source_p, ":%s %d %s z :Bans %u(%u)",
579 me.name, RPL_STATSDEBUG, source_p->name,
580 channel_bans, channel_ban_memory);
581
582 sendto_one(source_p, ":%s %d %s z :Exceptions %u(%u)",
583 me.name, RPL_STATSDEBUG, source_p->name,
584 channel_except, channel_except_memory);
585
586 sendto_one(source_p, ":%s %d %s z :Invex %u(%u)",
587 me.name, RPL_STATSDEBUG, source_p->name,
588 channel_invex, channel_invex_memory);
589
590 sendto_one(source_p, ":%s %d %s z :Channel members %u(%lu) invite %u(%lu)",
591 me.name, RPL_STATSDEBUG, source_p->name, channel_users,
592 (unsigned long)(channel_users * sizeof(struct Membership)),
593 channel_invites, (unsigned long)channel_invites *
594 sizeof(dlink_node));
595
596 total_channel_memory = channel_memory + channel_ban_memory +
597 channel_users * sizeof(struct Membership) +
598 channel_invites * sizeof(dlink_node);
599
600 sendto_one(source_p, ":%s %d %s z :Safelist %u(%u)",
601 me.name, RPL_STATSDEBUG, source_p->name,
602 safelist_count, safelist_memory);
603
604 sendto_one(source_p, ":%s %d %s z :Whowas users %u(%lu)",
605 me.name, RPL_STATSDEBUG, source_p->name,
606 wwu, (unsigned long)(wwu * sizeof(struct Client)));
607
608 sendto_one(source_p, ":%s %d %s z :Whowas array %u(%d)",
609 me.name, RPL_STATSDEBUG, source_p->name,
610 NICKNAMEHISTORYLENGTH, (int)wwm);
611
612 totww = wwu * sizeof(struct Client) + wwm;
613 /****
614 client_hash_table_size = hash_get_client_table_size();
615 channel_hash_table_size = hash_get_channel_table_size();
616 resv_hash_table_size = hash_get_resv_table_size();
617 id_hash_table_size = hash_get_id_table_size();
618
619 sendto_one(source_p, ":%s %d %s z :Hash: client %u(%lu) chan %u(%lu) resv "
620 "%u(%lu) id %u(%lu)",
621 me.name, RPL_STATSDEBUG, source_p->name,
622 U_MAX, client_hash_table_size,
623 CH_MAX, channel_hash_table_size , R_MAX,
624 resv_hash_table_size, U_MAX, id_hash_table_size);
625 ****/
626 count_ip_hash(&number_ips_stored,&mem_ips_stored);
627 sendto_one(source_p, ":%s %d %s z :iphash %u(%d)",
628 me.name, RPL_STATSDEBUG, source_p->name,
629 number_ips_stored, (int)mem_ips_stored);
630
631 total_memory = totww + total_channel_memory + conf_memory + class_count *
632 sizeof(struct ClassItem);
633 total_memory += client_hash_table_size;
634 total_memory += channel_hash_table_size;
635 total_memory += resv_hash_table_size;
636 total_memory += id_hash_table_size;
637
638 sendto_one(source_p, ":%s %d %s z :Total: whowas %d channel %d conf %d",
639 me.name, RPL_STATSDEBUG, source_p->name, (int)totww,
640 (int)total_channel_memory, (int)conf_memory);
641
642 local_client_memory_used = local_client_count*(sizeof(struct Client) + sizeof(struct LocalUser));
643 total_memory += local_client_memory_used;
644 sendto_one(source_p, ":%s %d %s z :Local client Memory in use: %d(%d)",
645 me.name, RPL_STATSDEBUG, source_p->name, local_client_count,
646 local_client_memory_used);
647
648 remote_client_memory_used = remote_client_count * sizeof(struct Client);
649 total_memory += remote_client_memory_used;
650 sendto_one(source_p, ":%s %d %s z :Remote client Memory in use: %d(%d)",
651 me.name, RPL_STATSDEBUG, source_p->name, remote_client_count,
652 remote_client_memory_used);
653
654 block_heap_report_stats(source_p);
655
656 sendto_one(source_p,
657 ":%s %d %s z :TOTAL: %d Available: Current max RSS: %lu",
658 me.name, RPL_STATSDEBUG, source_p->name,
659 (int)total_memory, get_maxrss());
660 }
661
662 static void
663 stats_dns_servers(struct Client *source_p)
664 {
665 report_dns_servers(source_p);
666 }
667
668 static void
669 stats_connect(struct Client *source_p)
670 {
671 report_confitem_types(source_p, SERVER_TYPE, 0);
672 }
673
674 /* stats_deny()
675 *
676 * input - client to report to
677 * output - none
678 * side effects - client is given dline list.
679 */
680 static void
681 stats_deny(struct Client *source_p)
682 {
683 struct AddressRec *arec;
684 struct ConfItem *conf;
685 struct AccessItem *aconf;
686 int i;
687
688 for (i = 0; i < ATABLE_SIZE; i++)
689 {
690 for (arec = atable[i]; arec; arec=arec->next)
691 {
692 if (arec->type == CONF_DLINE)
693 {
694 aconf = arec->aconf;
695
696 /* dont report a tdline as a dline */
697 if (aconf->flags & CONF_FLAGS_TEMPORARY)
698 continue;
699
700 conf = unmap_conf_item(aconf);
701
702 sendto_one(source_p, form_str(RPL_STATSDLINE),
703 from, to, 'D', aconf->host, aconf->reason,
704 aconf->oper_reason);
705 }
706 }
707 }
708 }
709
710 /* stats_tdeny()
711 *
712 * input - client to report to
713 * output - none
714 * side effects - client is given dline list.
715 */
716 static void
717 stats_tdeny(struct Client *source_p)
718 {
719 struct AddressRec *arec;
720 struct ConfItem *conf;
721 struct AccessItem *aconf;
722 int i;
723
724 for (i = 0; i < ATABLE_SIZE; i++)
725 {
726 for (arec = atable[i]; arec; arec=arec->next)
727 {
728 if (arec->type == CONF_DLINE)
729 {
730 aconf = arec->aconf;
731
732 /* dont report a permanent dline as a tdline */
733 if (!(aconf->flags & CONF_FLAGS_TEMPORARY))
734 continue;
735
736 conf = unmap_conf_item(aconf);
737
738 sendto_one(source_p, form_str(RPL_STATSDLINE),
739 from, to, 'd', aconf->host, aconf->reason,
740 aconf->oper_reason);
741 }
742 }
743 }
744 }
745
746 /* stats_exempt()
747 *
748 * input - client to report to
749 * output - none
750 * side effects - client is given list of exempt blocks
751 */
752 static void
753 stats_exempt(struct Client *source_p)
754 {
755 struct AddressRec *arec;
756 struct ConfItem *conf;
757 struct AccessItem *aconf;
758 int i;
759
760 if (ConfigFileEntry.stats_e_disabled)
761 {
762 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
763 from, to);
764 return;
765 }
766
767 for (i = 0; i < ATABLE_SIZE; i++)
768 {
769 for (arec = atable[i]; arec; arec=arec->next)
770 {
771 if (arec->type == CONF_EXEMPTDLINE)
772 {
773 aconf = arec->aconf;
774
775 conf = unmap_conf_item(aconf);
776
777 sendto_one(source_p, form_str(RPL_STATSDLINE),
778 from, to, 'e', aconf->host,
779 aconf->reason, aconf->oper_reason);
780 }
781 }
782 }
783 }
784
785 static void
786 stats_events(struct Client *source_p)
787 {
788 show_events(source_p);
789 }
790
791 /* stats_pending_glines()
792 *
793 * input - client pointer
794 * output - none
795 * side effects - client is shown list of pending glines
796 */
797 static void
798 stats_pending_glines(struct Client *source_p)
799 {
800 #ifdef GLINE_VOTING
801 dlink_node *pending_node;
802 struct gline_pending *glp_ptr;
803 char timebuffer[MAX_DATE_STRING];
804 struct tm *tmptr;
805
806 if (!ConfigFileEntry.glines)
807 {
808 sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
809 from, to);
810 return;
811 }
812
813 if (dlink_list_length(&pending_glines) > 0)
814 sendto_one(source_p, ":%s NOTICE %s :Pending G-lines",
815 from, to);
816
817 DLINK_FOREACH(pending_node, pending_glines.head)
818 {
819 glp_ptr = pending_node->data;
820 tmptr = localtime(&glp_ptr->time_request1);
821 strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
822
823 sendto_one(source_p,
824 ":%s NOTICE %s :1) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
825 from, to, glp_ptr->oper_nick1,
826 glp_ptr->oper_user1, glp_ptr->oper_host1,
827 glp_ptr->oper_server1, timebuffer,
828 glp_ptr->user, glp_ptr->host, glp_ptr->reason1);
829
830 if (glp_ptr->oper_nick2[0] != '\0')
831 {
832 tmptr = localtime(&glp_ptr->time_request2);
833 strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
834 sendto_one(source_p,
835 ":%s NOTICE %s :2) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
836 from, to, glp_ptr->oper_nick2,
837 glp_ptr->oper_user2, glp_ptr->oper_host2,
838 glp_ptr->oper_server2, timebuffer,
839 glp_ptr->user, glp_ptr->host, glp_ptr->reason2);
840 }
841 }
842
843 sendto_one(source_p, ":%s NOTICE %s :End of Pending G-lines",
844 from, to);
845 #else
846 sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Line voting",
847 from, to);
848 #endif /* GLINE VOTING */
849 }
850
851 /* stats_glines()
852 *
853 * input - client pointer
854 * output - none
855 * side effects - client is shown list of glines
856 */
857 static void
858 stats_glines(struct Client *source_p)
859 {
860 struct AddressRec *arec = NULL;
861 int i = 0;
862
863 if (!ConfigFileEntry.glines)
864 {
865 sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
866 from, to);
867 return;
868 }
869
870 for (; i < ATABLE_SIZE; ++i)
871 {
872 for (arec = atable[i]; arec; arec=arec->next)
873 {
874 if (arec->type == CONF_GLINE)
875 {
876 const struct AccessItem *aconf = arec->aconf;
877
878 sendto_one(source_p, form_str(RPL_STATSKLINE),
879 from, to, "G",
880 aconf->host ? aconf->host : "*",
881 aconf->user ? aconf->user : "*",
882 aconf->reason ? aconf->reason : "No reason", "" );
883 }
884 }
885 }
886 }
887
888 /* stats_gdeny()
889 *
890 * input - client pointer
891 * outputs - none
892 * side effects - client is shown gline ACL
893 */
894 static void
895 stats_gdeny(struct Client *source_p)
896 {
897 if (!ConfigFileEntry.glines)
898 {
899 sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
900 from, to);
901 return;
902 }
903
904 report_confitem_types(source_p, GDENY_TYPE, 0);
905 }
906
907 static void
908 stats_hubleaf(struct Client *source_p)
909 {
910 report_confitem_types(source_p, HUB_TYPE, 0);
911 report_confitem_types(source_p, LEAF_TYPE, 0);
912 }
913
914 static void
915 stats_auth(struct Client *source_p)
916 {
917 /* Oper only, if unopered, return ERR_NOPRIVILEGES */
918 if ((ConfigFileEntry.stats_i_oper_only == 2) && !IsOper(source_p))
919 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
920 from, to);
921
922 /* If unopered, Only return matching auth blocks */
923 else if ((ConfigFileEntry.stats_i_oper_only == 1) && !IsOper(source_p))
924 {
925 struct ConfItem *conf;
926 struct AccessItem *aconf;
927
928 if (MyConnect(source_p))
929 aconf = find_conf_by_address(source_p->host,
930 &source_p->localClient->ip,
931 CONF_CLIENT,
932 source_p->localClient->aftype,
933 source_p->username,
934 source_p->localClient->passwd);
935 else
936 aconf = find_conf_by_address(source_p->host, NULL, CONF_CLIENT,
937 0, source_p->username, NULL);
938
939 if (aconf == NULL)
940 return;
941
942 conf = unmap_conf_item(aconf);
943
944 sendto_one(source_p, form_str(RPL_STATSILINE), from,
945 to, 'I',
946 "*", show_iline_prefix(source_p, aconf, aconf->user),
947 aconf->host, aconf->port,
948 aconf->class_ptr ? aconf->class_ptr->name : "<default>");
949 }
950 /* They are opered, or allowed to see all auth blocks */
951 else
952 report_auth(source_p);
953 }
954
955 static void
956 stats_tklines(struct Client *source_p)
957 {
958 struct ConfItem *conf;
959 /* Oper only, if unopered, return ERR_NOPRIVILEGES */
960 if ((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p))
961 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
962 from, to);
963
964 /* If unopered, Only return matching klines */
965 else if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p))
966 {
967 struct AccessItem *aconf;
968
969 if (MyConnect(source_p))
970 aconf = find_conf_by_address(source_p->host,
971 &source_p->localClient->ip,
972 CONF_KILL,
973 source_p->localClient->aftype,
974 source_p->username, NULL);
975 else
976 aconf = find_conf_by_address(source_p->host, NULL, CONF_KILL,
977 0, source_p->username, NULL);
978
979 if (aconf == NULL)
980 return;
981
982 /* dont report a permanent kline as a tkline */
983 if (!(aconf->flags & CONF_FLAGS_TEMPORARY))
984 return;
985
986 conf = unmap_conf_item(aconf);
987
988 sendto_one(source_p, form_str(RPL_STATSKLINE), from,
989 to, "k", aconf->host, aconf->user, aconf->reason, "");
990 }
991 /* Theyre opered, or allowed to see all klines */
992 else {
993 report_Klines(source_p, 1);
994 report_confitem_types(source_p, RKLINE_TYPE, 1);
995 }
996 }
997
998 static void
999 stats_klines(struct Client *source_p)
1000 {
1001 /* Oper only, if unopered, return ERR_NOPRIVILEGES */
1002 if ((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p))
1003 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1004 from, to);
1005
1006 /* If unopered, Only return matching klines */
1007 else if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p))
1008 {
1009 struct AccessItem *aconf;
1010
1011 /* search for a kline */
1012 if (MyConnect(source_p))
1013 aconf = find_conf_by_address(source_p->host,
1014 &source_p->localClient->ip,
1015 CONF_KILL,
1016 source_p->localClient->aftype,
1017 source_p->username, NULL);
1018 else
1019 aconf = find_conf_by_address(source_p->host, NULL, CONF_KILL,
1020 0, source_p->username, NULL);
1021
1022 if (aconf == NULL)
1023 return;
1024
1025 /* dont report a tkline as a kline */
1026 if (aconf->flags & CONF_FLAGS_TEMPORARY)
1027 return;
1028
1029 sendto_one(source_p, form_str(RPL_STATSKLINE), from,
1030 to, "K", aconf->host, aconf->user, aconf->reason,
1031 aconf->oper_reason);
1032 }
1033 /* Theyre opered, or allowed to see all klines */
1034 else {
1035 report_Klines(source_p, 0);
1036 report_confitem_types(source_p, RKLINE_TYPE, 0);
1037 }
1038 }
1039
1040 static void
1041 stats_messages(struct Client *source_p)
1042 {
1043 report_messages(source_p);
1044 }
1045
1046 static void
1047 stats_oper(struct Client *source_p)
1048 {
1049 if (!IsOper(source_p) && ConfigFileEntry.stats_o_oper_only)
1050 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1051 from, to);
1052 else
1053 report_confitem_types(source_p, OPER_TYPE, 0);
1054 }
1055
1056 /* stats_operedup()
1057 *
1058 * input - client pointer
1059 * output - none
1060 * side effects - client is shown a list of active opers
1061 */
1062 static void
1063 stats_operedup(struct Client *source_p)
1064 {
1065 dlink_node *ptr;
1066
1067 DLINK_FOREACH(ptr, oper_list.head)
1068 {
1069 const struct Client *target_p = ptr->data;
1070
1071 if (IsOperHidden(target_p) && !IsOper(source_p))
1072 continue;
1073
1074 if (MyClient(source_p) && IsOper(source_p))
1075 sendto_one(source_p, ":%s %d %s p :[%c][%s] %s (%s@%s) Idle: %d",
1076 from, RPL_STATSDEBUG, to,
1077 IsAdmin(target_p) ?
1078 (IsOperHiddenAdmin(target_p) ? 'O' : 'A') : 'O',
1079 oper_privs_as_string(target_p->localClient->operflags),
1080 target_p->name, target_p->username, target_p->host,
1081 (int)(CurrentTime - target_p->localClient->last));
1082 else
1083 sendto_one(source_p, ":%s %d %s p :[%c] %s (%s@%s) Idle: %d",
1084 from, RPL_STATSDEBUG, to,
1085 IsAdmin(target_p) ?
1086 (IsOperHiddenAdmin(target_p) ? 'O' : 'A') : 'O',
1087 target_p->name, target_p->username, target_p->host,
1088 (int)(CurrentTime - target_p->localClient->last));
1089 }
1090
1091 sendto_one(source_p, ":%s %d %s p :%lu OPER(s)",
1092 from, RPL_STATSDEBUG, to, dlink_list_length(&oper_list));
1093 }
1094
1095 static void
1096 stats_ports(struct Client *source_p)
1097 {
1098 if (!IsOper(source_p) && ConfigFileEntry.stats_P_oper_only)
1099 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1100 from, to);
1101 else
1102 show_ports(source_p);
1103 }
1104
1105 static void
1106 stats_resv(struct Client *source_p)
1107 {
1108 report_resv(source_p);
1109 }
1110
1111 static void
1112 stats_usage(struct Client *source_p)
1113 {
1114 send_usage(source_p);
1115 }
1116
1117 static void
1118 stats_tstats(struct Client *source_p)
1119 {
1120 tstats(source_p);
1121 }
1122
1123 static void
1124 stats_uptime(struct Client *source_p)
1125 {
1126 time_t now = CurrentTime - me.since;
1127 sendto_one(source_p, form_str(RPL_STATSUPTIME), from, to,
1128 now/86400, (now/3600)%24, (now/60)%60, now%60);
1129 if (!ConfigFileEntry.disable_remote || IsOper(source_p))
1130 sendto_one(source_p, form_str(RPL_STATSCONN), from, to,
1131 MaxConnectionCount, MaxClientCount, Count.totalrestartcount);
1132 }
1133
1134 static void
1135 stats_shared(struct Client *source_p)
1136 {
1137 report_confitem_types(source_p, ULINE_TYPE, 0);
1138 }
1139
1140 /* stats_servers()
1141 *
1142 * input - client pointer
1143 * output - none
1144 * side effects - client is shown lists of who connected servers
1145 */
1146 static void
1147 stats_servers(struct Client *source_p)
1148 {
1149 struct Client *target_p;
1150 dlink_node *ptr;
1151 int j = 0;
1152
1153 DLINK_FOREACH(ptr, serv_list.head)
1154 {
1155 target_p = ptr->data;
1156
1157 j++;
1158
1159 sendto_one(source_p, ":%s %d %s v :%s (%s!%s@%s) Idle: %d",
1160 from, RPL_STATSDEBUG, to,
1161 target_p->name,
1162 (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
1163 "*", "*", (int)(CurrentTime - target_p->lasttime));
1164 }
1165
1166 sendto_one(source_p, ":%s %d %s v :%d Server(s)",
1167 from, RPL_STATSDEBUG, to, j);
1168 }
1169
1170 static void
1171 stats_gecos(struct Client *source_p)
1172 {
1173 report_confitem_types(source_p, XLINE_TYPE, 0);
1174 report_confitem_types(source_p, RXLINE_TYPE, 0);
1175 }
1176
1177 static void
1178 stats_class(struct Client *source_p)
1179 {
1180 report_confitem_types(source_p, CLASS_TYPE, 0);
1181 }
1182
1183 static void
1184 stats_memory(struct Client *source_p)
1185 {
1186 count_memory(source_p);
1187 }
1188
1189 static void
1190 stats_ziplinks(struct Client *source_p)
1191 {
1192 dlink_node *ptr;
1193 struct Client *target_p;
1194 unsigned int sent_data = 0;
1195
1196 DLINK_FOREACH(ptr, serv_list.head)
1197 {
1198 target_p = ptr->data;
1199
1200 if (IsCapable(target_p, CAP_ZIP))
1201 {
1202 /* we use memcpy(3) and a local copy of the structure to
1203 * work around a register use bug on GCC on the SPARC.
1204 * -jmallett, 04/27/2002
1205 */
1206 struct ZipStats zipstats;
1207 memcpy(&zipstats, &target_p->localClient->zipstats, sizeof (struct ZipStats));
1208
1209 sendto_one(source_p, ":%s %d %s Z :ZipLinks stats for %s send[%.2f%% "
1210 "compression (%lu bytes data/%lu bytes wire)] recv[%.2f%% "
1211 "compression (%lu bytes data/%lu bytes wire)]",
1212 from, RPL_STATSDEBUG, to, target_p->name,
1213 zipstats.out_ratio, zipstats.out, zipstats.out_wire,
1214 zipstats.in_ratio, zipstats.in, zipstats.in_wire);
1215 ++sent_data;
1216 }
1217 }
1218
1219 sendto_one(source_p, ":%s %d %s Z :%u ziplink(s)",
1220 from, RPL_STATSDEBUG, to, sent_data);
1221 }
1222
1223 static void
1224 stats_servlinks(struct Client *source_p)
1225 {
1226 uint64_t sendB = 0, recvB = 0;
1227 time_t uptime = 0;
1228 dlink_node *ptr = NULL;
1229
1230 if (ConfigServerHide.flatten_links && !IsOper(source_p))
1231 {
1232 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1233 from, to);
1234 return;
1235 }
1236
1237 DLINK_FOREACH(ptr, serv_list.head)
1238 {
1239 struct Client *target_p = ptr->data;
1240
1241 sendB += target_p->localClient->send.bytes;
1242 recvB += target_p->localClient->recv.bytes;
1243
1244 /* ":%s 211 %s %s %u %u %llu %u %llu :%u %u %s" */
1245 sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1246 from, to,
1247 get_client_name(target_p, IsAdmin(source_p) ? SHOW_IP : MASK_IP),
1248 dbuf_length(&target_p->localClient->buf_sendq),
1249 target_p->localClient->send.messages,
1250 target_p->localClient->send.bytes >> 10,
1251 target_p->localClient->recv.messages,
1252 target_p->localClient->recv.bytes >> 10,
1253 (unsigned)(CurrentTime - target_p->firsttime),
1254 (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since): 0,
1255 IsOper(source_p) ? show_capabilities(target_p) : "TS");
1256 }
1257
1258 sendB >>= 10;
1259 recvB >>= 10;
1260
1261 sendto_one(source_p, ":%s %d %s ? :%u total server(s)",
1262 from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list));
1263 sendto_one(source_p, ":%s %d %s ? :Sent total : %7.2f %s",
1264 from, RPL_STATSDEBUG, to,
1265 _GMKv(sendB), _GMKs(sendB));
1266 sendto_one(source_p, ":%s %d %s ? :Recv total : %7.2f %s",
1267 from, RPL_STATSDEBUG, to,
1268 _GMKv(recvB), _GMKs(recvB));
1269
1270 uptime = (CurrentTime - me.since);
1271
1272 sendto_one(source_p, ":%s %d %s ? :Server send: %7.2f %s (%4.1f K/s)",
1273 from, RPL_STATSDEBUG, to,
1274 _GMKv((me.localClient->send.bytes>>10)),
1275 _GMKs((me.localClient->send.bytes>>10)),
1276 (float)((float)((me.localClient->send.bytes) >> 10) /
1277 (float)uptime));
1278 sendto_one(source_p, ":%s %d %s ? :Server recv: %7.2f %s (%4.1f K/s)",
1279 from, RPL_STATSDEBUG, to,
1280 _GMKv((me.localClient->recv.bytes>>10)),
1281 _GMKs((me.localClient->recv.bytes>>10)),
1282 (float)((float)((me.localClient->recv.bytes) >> 10) /
1283 (float)uptime));
1284 }
1285
1286 static void
1287 stats_ltrace(struct Client *source_p, int parc, char *parv[])
1288 {
1289 int doall = 0;
1290 int wilds = 0;
1291 char *name = NULL;
1292 char statchar;
1293
1294 if ((name = parse_stats_args(parc, parv, &doall, &wilds)) != NULL)
1295 {
1296 statchar = parv[1][0];
1297
1298 stats_L(source_p, name, doall, wilds, statchar);
1299 }
1300 else
1301 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1302 from, to, "STATS");
1303 }
1304
1305 /*
1306 * ms_stats - STATS message handler
1307 * parv[0] = sender prefix
1308 * parv[1] = statistics selector (defaults to Message frequency)
1309 * parv[2] = server name (current server defaulted, if omitted)
1310 */
1311 static void
1312 ms_stats(struct Client *client_p, struct Client *source_p,
1313 int parc, char *parv[])
1314 {
1315 if (hunt_server(client_p,source_p,":%s STATS %s :%s",2,parc,parv)!=HUNTED_ISME)
1316 return;
1317
1318 if (IsClient(source_p))
1319 mo_stats(client_p, source_p, parc, parv);
1320 }
1321
1322 /*
1323 * stats_L
1324 *
1325 * inputs - pointer to client to report to
1326 * - doall flag
1327 * - wild card or not
1328 * output - NONE
1329 * side effects -
1330 */
1331 static void
1332 stats_L(struct Client *source_p,char *name,int doall,
1333 int wilds,char statchar)
1334 {
1335 stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar);
1336 stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar);
1337 stats_L_list(source_p, name, doall, wilds, &serv_list, statchar);
1338 }
1339
1340 static void
1341 stats_L_list(struct Client *source_p,char *name, int doall, int wilds,
1342 dlink_list *list,char statchar)
1343 {
1344 dlink_node *ptr;
1345 struct Client *target_p;
1346
1347 /*
1348 * send info about connections which match, or all if the
1349 * mask matches from. Only restrictions are on those who
1350 * are invisible not being visible to 'foreigners' who use
1351 * a wild card based search to list it.
1352 */
1353 DLINK_FOREACH(ptr, list->head)
1354 {
1355 target_p = ptr->data;
1356
1357 if (IsInvisible(target_p) && (doall || wilds) &&
1358 !(MyConnect(source_p) && IsOper(source_p)) &&
1359 !IsOper(target_p) && (target_p != source_p))
1360 continue;
1361 if (!doall && wilds && !match(name, target_p->name))
1362 continue;
1363 if (!(doall || wilds) && irccmp(name, target_p->name))
1364 continue;
1365
1366 /* This basically shows ips for our opers if its not a server/admin, or
1367 * its one of our admins. */
1368 if(MyClient(source_p) && IsOper(source_p) &&
1369 (IsAdmin(source_p) ||
1370 (!IsServer(target_p) && !IsAdmin(target_p) &&
1371 !IsHandshake(target_p) && !IsConnecting(target_p))))
1372 {
1373 sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1374 from, to,
1375 (IsUpper(statchar)) ?
1376 get_client_name(target_p, SHOW_IP) :
1377 get_client_name(target_p, HIDE_IP),
1378 dbuf_length(&target_p->localClient->buf_sendq),
1379 target_p->localClient->send.messages,
1380 target_p->localClient->send.bytes>>10,
1381 target_p->localClient->recv.messages,
1382 target_p->localClient->recv.bytes>>10,
1383 (unsigned)(CurrentTime - target_p->firsttime),
1384 (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1385 IsServer(target_p) ? show_capabilities(target_p) : "-");
1386 }
1387 else
1388 {
1389 /* If its a hidden ip, an admin, or a server, mask the real IP */
1390 if(IsIPSpoof(target_p) || IsServer(target_p) || IsAdmin(target_p)
1391 || IsHandshake(target_p) || IsConnecting(target_p))
1392 sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1393 from, to,
1394 get_client_name(target_p, MASK_IP),
1395 dbuf_length(&target_p->localClient->buf_sendq),
1396 target_p->localClient->send.messages,
1397 target_p->localClient->send.bytes>>10,
1398 target_p->localClient->recv.messages,
1399 target_p->localClient->recv.bytes>>10,
1400 (unsigned)(CurrentTime - target_p->firsttime),
1401 (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1402 IsServer(target_p) ? show_capabilities(target_p) : "-");
1403 else /* show the real IP */
1404 sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1405 from, to,
1406 (IsUpper(statchar)) ?
1407 get_client_name(target_p, SHOW_IP) :
1408 get_client_name(target_p, HIDE_IP),
1409 dbuf_length(&target_p->localClient->buf_sendq),
1410 target_p->localClient->send.messages,
1411 target_p->localClient->send.bytes>>10,
1412 target_p->localClient->recv.messages,
1413 target_p->localClient->recv.bytes>>10,
1414 (unsigned)(CurrentTime - target_p->firsttime),
1415 (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1416 IsServer(target_p) ? show_capabilities(target_p) : "-");
1417 }
1418 }
1419 }
1420
1421 /* parse_stats_args()
1422 *
1423 * inputs - arg count
1424 * - args
1425 * - doall flag
1426 * - wild card or not
1427 * output - pointer to name to use
1428 * side effects -
1429 * common parse routine for m_stats args
1430 *
1431 */
1432 static char *
1433 parse_stats_args(int parc, char *parv[], int *doall, int *wilds)
1434 {
1435 char *name;
1436
1437 if (parc > 2)
1438 {
1439 name = parv[2];
1440
1441 if (!irccmp(name, from))
1442 *doall = 2;
1443 else if (match(name, from))
1444 *doall = 1;
1445
1446 if (strchr(name, '*') ||
1447 strchr(name, '?'))
1448 *wilds = 1;
1449
1450 return(name);
1451 }
1452 else
1453 return(NULL);
1454 }

Properties

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

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