ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 1178
Committed: Mon Aug 15 08:11:31 2011 UTC (14 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_stats.c
File size: 47121 byte(s)
Log Message:
- Cleanup and restore older parts of the irc-command parser.
  Gives back ability to specify maximum amount of parameters
  that are processed within a command.

File Contents

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

Properties

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