ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 1028
Committed: Sun Nov 8 13:03:38 2009 UTC (15 years, 9 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/modules/m_stats.c
File size: 46831 byte(s)
Log Message:
- move ircd-hybrid-7.2 to trunk

File Contents

# User Rev Content
1 adx 30 /*
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 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26 michael 1011 #include "list.h" /* dlink_node/dlink_list */
27     #include "balloc.h"
28 adx 30 #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 "parse.h"
49     #include "modules.h"
50     #include "hook.h"
51     #include "resv.h" /* report_resv */
52     #include "whowas.h"
53 michael 884 #include "watch.h"
54 adx 30
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 knight 31 const char *_version = "$Revision$";
67 adx 30 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 michael 948 { '\0', NULL, 0, 0, }
184 adx 30 };
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     struct rusage rus;
322     time_t secs;
323     time_t rup;
324     #ifdef hz
325     # define hzz hz
326     #else
327     # ifdef HZ
328     # define hzz HZ
329     # else
330     int hzz = 1;
331     # endif
332     #endif
333    
334     if (getrusage(RUSAGE_SELF, &rus) == -1)
335     {
336     sendto_one(source_p, ":%s NOTICE %s :Getruseage error: %s",
337     me.name, source_p->name, strerror(errno));
338     return;
339     }
340    
341     secs = rus.ru_utime.tv_sec + rus.ru_stime.tv_sec;
342    
343     if (secs == 0)
344     secs = 1;
345    
346     rup = (CurrentTime - me.since) * hzz;
347    
348     if (rup == 0)
349     rup = 1;
350    
351     sendto_one(source_p,
352     ":%s %d %s R :CPU Secs %d:%d User %d:%d System %d:%d",
353     me.name, RPL_STATSDEBUG, source_p->name, (int)(secs/60), (int)(secs%60),
354     (int)(rus.ru_utime.tv_sec/60), (int)(rus.ru_utime.tv_sec%60),
355     (int)(rus.ru_stime.tv_sec/60), (int)(rus.ru_stime.tv_sec%60));
356     sendto_one(source_p, ":%s %d %s R :RSS %ld ShMem %ld Data %ld Stack %ld",
357     me.name, RPL_STATSDEBUG, source_p->name, rus.ru_maxrss,
358     (rus.ru_ixrss / rup), (rus.ru_idrss / rup),
359     (rus.ru_isrss / rup));
360     sendto_one(source_p, ":%s %d %s R :Swaps %d Reclaims %d Faults %d",
361     me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_nswap,
362     (int)rus.ru_minflt, (int)rus.ru_majflt);
363     sendto_one(source_p, ":%s %d %s R :Block in %d out %d",
364     me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_inblock,
365     (int)rus.ru_oublock);
366     sendto_one(source_p, ":%s %d %s R :Msg Rcv %d Send %d",
367     me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_msgrcv,
368     (int)rus.ru_msgsnd);
369     sendto_one(source_p, ":%s %d %s R :Signals %d Context Vol. %d Invol %d",
370     me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_nsignals,
371     (int)rus.ru_nvcsw, (int)rus.ru_nivcsw);
372     }
373    
374     static void
375     count_memory(struct Client *source_p)
376     {
377     const dlink_node *gptr = NULL;
378     const dlink_node *dlink = NULL;
379    
380 michael 948 unsigned int local_client_conf_count = 0; /* local client conf links */
381     unsigned int users_counted = 0; /* user structs */
382 adx 30
383 michael 1017 unsigned int channel_members = 0;
384 michael 948 unsigned int channel_invites = 0;
385     unsigned int channel_bans = 0;
386     unsigned int channel_except = 0;
387     unsigned int channel_invex = 0;
388 adx 30
389 michael 948 unsigned int wwu = 0; /* whowas users */
390     unsigned int class_count = 0; /* classes */
391     unsigned int aways_counted = 0;
392     unsigned int number_ips_stored; /* number of ip addresses hashed */
393 adx 30
394 michael 948 uint64_t channel_memory = 0;
395     uint64_t channel_ban_memory = 0;
396     uint64_t channel_except_memory = 0;
397     uint64_t channel_invex_memory = 0;
398 adx 30
399     unsigned int safelist_count = 0;
400 michael 948 uint64_t safelist_memory = 0;
401 adx 30
402 michael 948 uint64_t away_memory = 0; /* memory used by aways */
403     uint64_t wwm = 0; /* whowas array memory used */
404     uint64_t conf_memory = 0; /* memory used by conf lines */
405     uint64_t mem_ips_stored; /* memory used by ip address hash */
406 adx 30
407 michael 948 uint64_t total_channel_memory = 0;
408     uint64_t totww = 0;
409 adx 30
410     unsigned int local_client_count = 0;
411     unsigned int remote_client_count = 0;
412    
413 michael 948 uint64_t local_client_memory_used = 0;
414     uint64_t remote_client_memory_used = 0;
415 adx 30
416 michael 948 uint64_t total_memory = 0;
417 adx 30 unsigned int topic_count = 0;
418    
419 michael 1017 unsigned int watch_list_headers = 0; /* watchlist headers */
420     unsigned int watch_list_entries = 0; /* watchlist entries */
421     uint64_t watch_list_memory = 0; /* watchlist memory used */
422 michael 884
423 adx 30
424     DLINK_FOREACH(gptr, global_client_list.head)
425     {
426     struct Client *target_p = gptr->data;
427    
428     if (MyConnect(target_p))
429     {
430     ++local_client_count;
431     local_client_conf_count += dlink_list_length(&target_p->localClient->confs);
432 michael 1017 watch_list_entries += dlink_list_length(&target_p->localClient->watches);
433 adx 30 }
434     else
435     ++remote_client_count;
436    
437     if (IsClient(target_p))
438     {
439     ++users_counted;
440    
441     if (target_p->away != NULL)
442     {
443     ++aways_counted;
444     away_memory += strlen(target_p->away) + 1;
445     }
446     }
447     }
448    
449     /* Count up all channels, ban lists, except lists, Invex lists */
450     channel_memory = dlink_list_length(&global_channel_list) *
451     sizeof(struct Channel);
452     DLINK_FOREACH(gptr, global_channel_list.head)
453     {
454 michael 948 const struct Ban *actualBan;
455     const struct Channel *chptr = gptr->data;
456 adx 30
457 michael 1017 channel_members += dlink_list_length(&chptr->members);
458 adx 30 channel_invites += dlink_list_length(&chptr->invites);
459    
460     if (chptr->topic != NULL)
461     ++topic_count;
462    
463 michael 1017 channel_bans += dlink_list_length(&chptr->banlist);
464     channel_ban_memory += dlink_list_length(&chptr->banlist) * sizeof(struct Ban);
465    
466     DLINK_FOREACH(dlink, chptr->banlist.head)
467 adx 30 {
468 michael 1017 actualBan = dlink->data;
469     assert(actualBan->who);
470 adx 30
471 michael 1017 channel_ban_memory += actualBan->len + 1;
472     channel_ban_memory += strlen(actualBan->who) + 1;
473 adx 30 }
474    
475 michael 1017 channel_except += dlink_list_length(&chptr->exceptlist);
476     channel_except_memory += dlink_list_length(&chptr->exceptlist) * sizeof(struct Ban);
477    
478     DLINK_FOREACH(dlink, chptr->exceptlist.head)
479 adx 30 {
480 michael 1017 actualBan = dlink->data;
481     assert(actualBan->who);
482 adx 30
483 michael 1017 channel_except_memory += actualBan->len + 1;
484     channel_except_memory += strlen(actualBan->who) + 1;
485 adx 30 }
486    
487 michael 1017 channel_invex += dlink_list_length(&chptr->invexlist);
488     channel_invex_memory += dlink_list_length(&chptr->invexlist) * sizeof(struct Ban);
489    
490     DLINK_FOREACH(dlink, chptr->invexlist.head)
491 adx 30 {
492 michael 1017 actualBan = dlink->data;
493     assert(actualBan->who);
494 adx 30
495 michael 1017 channel_invex_memory += actualBan->len + 1;
496     channel_invex_memory += strlen(actualBan->who) + 1;
497 adx 30 }
498     }
499    
500     if ((safelist_count = dlink_list_length(&listing_client_list)))
501     {
502     safelist_memory = safelist_count * sizeof(struct ListTask);
503     DLINK_FOREACH(gptr, listing_client_list.head)
504     {
505 michael 948 const struct Client *acptr = gptr->data;
506 adx 30
507     DLINK_FOREACH(dlink, acptr->localClient->list_task->show_mask.head)
508     safelist_memory += strlen(dlink->data);
509    
510     DLINK_FOREACH(dlink, acptr->localClient->list_task->hide_mask.head)
511     safelist_memory += strlen(dlink->data);
512     }
513     }
514    
515     #if 0
516     /* XXX THIS has to be fixed !!!! -db */
517     /* count up all config items */
518     DLINK_FOREACH(dlink, ConfigItemList.head)
519     {
520     aconf = dlink->data;
521     conf_memory += aconf->host ? strlen(aconf->host)+1 : 0;
522     conf_memory += aconf->passwd ? strlen(aconf->passwd)+1 : 0;
523     conf_memory += aconf->name ? strlen(aconf->name)+1 : 0;
524     conf_memory += sizeof(struct AccessItem);
525     }
526     #endif
527     /* count up all classes */
528     class_count = dlink_list_length(&class_items);
529    
530 michael 1017 count_whowas_memory(&wwu, &wwm);
531     watch_count_memory(&watch_list_headers, &watch_list_memory);
532 michael 884
533     sendto_one(source_p, ":%s %d %s z :WATCH headers %u(%u) entries %d(%d)",
534 michael 1017 me.name, RPL_STATSDEBUG, source_p->name, watch_list_headers,
535     watch_list_memory, watch_list_entries,
536     watch_list_entries * sizeof(dlink_node) * 2);
537 michael 884
538     sendto_one(source_p, ":%s %d %s z :Clients %u(%u)",
539 adx 30 me.name, RPL_STATSDEBUG, source_p->name, users_counted,
540 michael 884 (users_counted * sizeof(struct Client)));
541 adx 30
542 michael 948 sendto_one(source_p, ":%s %d %s z :User aways %u(%llu)",
543 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
544 michael 948 aways_counted, away_memory);
545 adx 30
546 michael 948 sendto_one(source_p, ":%s %d %s z :Attached confs %u(%llu)",
547 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
548     local_client_conf_count,
549 michael 948 (unsigned long long)(local_client_conf_count * sizeof(dlink_node)));
550 adx 30
551     sendto_one(source_p, ":%s %d %s z :Resv channels %lu(%lu) nicks %lu(%lu)",
552     me.name, RPL_STATSDEBUG, source_p->name,
553     dlink_list_length(&resv_channel_list),
554     dlink_list_length(&resv_channel_list) * sizeof(struct ResvChannel),
555     dlink_list_length(&nresv_items),
556     dlink_list_length(&nresv_items) * sizeof(struct MatchItem));
557    
558 michael 948 sendto_one(source_p, ":%s %d %s z :Classes %u(%llu)",
559 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
560 michael 948 class_count, (unsigned long long)(class_count * sizeof(struct ClassItem)));
561 adx 30
562 michael 948 sendto_one(source_p, ":%s %d %s z :Channels %lu(%llu) Topics %u(%d)",
563 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
564     dlink_list_length(&global_channel_list),
565     channel_memory, topic_count, topic_count *
566     (TOPICLEN + 1 + USERHOST_REPLYLEN));
567    
568 michael 948 sendto_one(source_p, ":%s %d %s z :Bans %u(%llu)",
569 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
570     channel_bans, channel_ban_memory);
571    
572 michael 948 sendto_one(source_p, ":%s %d %s z :Exceptions %u(%llu)",
573 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
574     channel_except, channel_except_memory);
575    
576 michael 948 sendto_one(source_p, ":%s %d %s z :Invex %u(%llu)",
577 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
578     channel_invex, channel_invex_memory);
579    
580 michael 948 sendto_one(source_p, ":%s %d %s z :Channel members %u(%llu) invites %u(%llu)",
581 michael 1017 me.name, RPL_STATSDEBUG, source_p->name, channel_members,
582     (unsigned long long)(channel_members * sizeof(struct Membership)),
583 michael 948 channel_invites, (unsigned long long)channel_invites *
584 michael 884 sizeof(dlink_node) * 2);
585 adx 30
586     total_channel_memory = channel_memory + channel_ban_memory +
587 michael 1017 channel_members * sizeof(struct Membership) +
588 michael 884 (channel_invites * sizeof(dlink_node)*2);
589 adx 30
590 michael 948 sendto_one(source_p, ":%s %d %s z :Safelist %u(%llu)",
591 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
592     safelist_count, safelist_memory);
593    
594 michael 948 sendto_one(source_p, ":%s %d %s z :Whowas users %u(%llu)",
595 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
596 michael 948 wwu, (unsigned long long)(wwu * sizeof(struct Client)));
597 adx 30
598 michael 948 sendto_one(source_p, ":%s %d %s z :Whowas array %u(%llu)",
599 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
600 michael 948 NICKNAMEHISTORYLENGTH, wwm);
601 adx 30
602     totww = wwu * sizeof(struct Client) + wwm;
603    
604     count_ip_hash(&number_ips_stored,&mem_ips_stored);
605 michael 948 sendto_one(source_p, ":%s %d %s z :iphash %u(%llu)",
606 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
607 michael 948 number_ips_stored, mem_ips_stored);
608 adx 30
609     total_memory = totww + total_channel_memory + conf_memory + class_count *
610     sizeof(struct ClassItem);
611 michael 948 sendto_one(source_p, ":%s %d %s z :Total: whowas %llu channel %llu conf %llu",
612     me.name, RPL_STATSDEBUG, source_p->name, totww,
613     total_channel_memory, conf_memory);
614 adx 30
615     local_client_memory_used = local_client_count*(sizeof(struct Client) + sizeof(struct LocalUser));
616     total_memory += local_client_memory_used;
617 michael 948 sendto_one(source_p, ":%s %d %s z :Local client Memory in use: %d(%llu)",
618 adx 30 me.name, RPL_STATSDEBUG, source_p->name, local_client_count,
619     local_client_memory_used);
620    
621     remote_client_memory_used = remote_client_count * sizeof(struct Client);
622     total_memory += remote_client_memory_used;
623 michael 948 sendto_one(source_p, ":%s %d %s z :Remote client Memory in use: %d(%llu)",
624 adx 30 me.name, RPL_STATSDEBUG, source_p->name, remote_client_count,
625     remote_client_memory_used);
626    
627     block_heap_report_stats(source_p);
628    
629     sendto_one(source_p,
630 michael 948 ":%s %d %s z :TOTAL: %llu",
631 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
632 michael 948 total_memory);
633 adx 30 }
634    
635     static void
636     stats_dns_servers(struct Client *source_p)
637     {
638     report_dns_servers(source_p);
639     }
640    
641     static void
642     stats_connect(struct Client *source_p)
643     {
644     report_confitem_types(source_p, SERVER_TYPE, 0);
645     }
646    
647     /* stats_deny()
648     *
649     * input - client to report to
650     * output - none
651     * side effects - client is given dline list.
652     */
653     static void
654     stats_deny(struct Client *source_p)
655     {
656     struct AddressRec *arec;
657     struct ConfItem *conf;
658     struct AccessItem *aconf;
659     int i;
660    
661     for (i = 0; i < ATABLE_SIZE; i++)
662     {
663     for (arec = atable[i]; arec; arec=arec->next)
664     {
665     if (arec->type == CONF_DLINE)
666     {
667     aconf = arec->aconf;
668    
669     /* dont report a tdline as a dline */
670     if (aconf->flags & CONF_FLAGS_TEMPORARY)
671     continue;
672    
673     conf = unmap_conf_item(aconf);
674    
675     sendto_one(source_p, form_str(RPL_STATSDLINE),
676     from, to, 'D', aconf->host, aconf->reason,
677     aconf->oper_reason);
678     }
679     }
680     }
681     }
682    
683     /* stats_tdeny()
684     *
685     * input - client to report to
686     * output - none
687     * side effects - client is given dline list.
688     */
689     static void
690     stats_tdeny(struct Client *source_p)
691     {
692     struct AddressRec *arec;
693     struct ConfItem *conf;
694     struct AccessItem *aconf;
695     int i;
696    
697     for (i = 0; i < ATABLE_SIZE; i++)
698     {
699     for (arec = atable[i]; arec; arec=arec->next)
700     {
701     if (arec->type == CONF_DLINE)
702     {
703     aconf = arec->aconf;
704    
705     /* dont report a permanent dline as a tdline */
706     if (!(aconf->flags & CONF_FLAGS_TEMPORARY))
707     continue;
708    
709     conf = unmap_conf_item(aconf);
710    
711     sendto_one(source_p, form_str(RPL_STATSDLINE),
712     from, to, 'd', aconf->host, aconf->reason,
713     aconf->oper_reason);
714     }
715     }
716     }
717     }
718    
719     /* stats_exempt()
720     *
721     * input - client to report to
722     * output - none
723     * side effects - client is given list of exempt blocks
724     */
725     static void
726     stats_exempt(struct Client *source_p)
727     {
728     struct AddressRec *arec;
729     struct ConfItem *conf;
730     struct AccessItem *aconf;
731     int i;
732    
733 michael 584 if (ConfigFileEntry.stats_e_disabled)
734     {
735     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
736     from, to);
737     return;
738     }
739    
740 adx 30 for (i = 0; i < ATABLE_SIZE; i++)
741     {
742     for (arec = atable[i]; arec; arec=arec->next)
743     {
744     if (arec->type == CONF_EXEMPTDLINE)
745     {
746     aconf = arec->aconf;
747    
748     conf = unmap_conf_item(aconf);
749    
750     sendto_one(source_p, form_str(RPL_STATSDLINE),
751     from, to, 'e', aconf->host,
752     aconf->reason, aconf->oper_reason);
753     }
754     }
755     }
756     }
757    
758     static void
759     stats_events(struct Client *source_p)
760     {
761     show_events(source_p);
762     }
763    
764     /* stats_pending_glines()
765     *
766     * input - client pointer
767     * output - none
768     * side effects - client is shown list of pending glines
769     */
770     static void
771     stats_pending_glines(struct Client *source_p)
772     {
773 michael 958 const dlink_node *dn_ptr = NULL;
774 michael 988 const struct gline_pending *glp_ptr = NULL;
775 michael 958 char timebuffer[MAX_DATE_STRING] = { '\0' };
776     struct tm *tmptr = NULL;
777 adx 30
778     if (!ConfigFileEntry.glines)
779     {
780     sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
781     from, to);
782     return;
783     }
784    
785 michael 958 if (dlink_list_length(&pending_glines[GLINE_PENDING_ADD_TYPE]) > 0)
786 adx 30 sendto_one(source_p, ":%s NOTICE %s :Pending G-lines",
787     from, to);
788    
789 michael 958 DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_ADD_TYPE].head)
790 adx 30 {
791 michael 958 glp_ptr = dn_ptr->data;
792     tmptr = localtime(&glp_ptr->vote_1.time_request);
793 adx 30 strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
794    
795     sendto_one(source_p,
796     ":%s NOTICE %s :1) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
797 michael 958 from, to, glp_ptr->vote_1.oper_nick,
798     glp_ptr->vote_1.oper_user, glp_ptr->vote_1.oper_host,
799     glp_ptr->vote_1.oper_server, timebuffer,
800     glp_ptr->user, glp_ptr->host, glp_ptr->vote_1.reason);
801 adx 30
802 michael 988 if (glp_ptr->vote_2.oper_nick[0] != '\0')
803 adx 30 {
804 michael 958 tmptr = localtime(&glp_ptr->vote_2.time_request);
805 adx 30 strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
806     sendto_one(source_p,
807     ":%s NOTICE %s :2) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
808 michael 958 from, to, glp_ptr->vote_2.oper_nick,
809     glp_ptr->vote_2.oper_user, glp_ptr->vote_2.oper_host,
810     glp_ptr->vote_2.oper_server, timebuffer,
811     glp_ptr->user, glp_ptr->host, glp_ptr->vote_2.reason);
812 adx 30 }
813     }
814    
815     sendto_one(source_p, ":%s NOTICE %s :End of Pending G-lines",
816     from, to);
817 michael 958
818     if (dlink_list_length(&pending_glines[GLINE_PENDING_DEL_TYPE]) > 0)
819     sendto_one(source_p, ":%s NOTICE %s :Pending UNG-lines",
820     from, to);
821    
822     DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_DEL_TYPE].head)
823     {
824     glp_ptr = dn_ptr->data;
825     tmptr = localtime(&glp_ptr->vote_1.time_request);
826     strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
827    
828     sendto_one(source_p,
829     ":%s NOTICE %s :1) %s!%s@%s on %s requested ungline at %s for %s@%s [%s]",
830     from, to, glp_ptr->vote_1.oper_nick,
831     glp_ptr->vote_1.oper_user, glp_ptr->vote_1.oper_host,
832     glp_ptr->vote_1.oper_server, timebuffer,
833     glp_ptr->user, glp_ptr->host, glp_ptr->vote_1.reason);
834    
835 michael 988 if (glp_ptr->vote_2.oper_nick[0] != '\0')
836 michael 958 {
837     tmptr = localtime(&glp_ptr->vote_2.time_request);
838     strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
839     sendto_one(source_p,
840     ":%s NOTICE %s :2) %s!%s@%s on %s requested ungline at %s for %s@%s [%s]",
841     from, to, glp_ptr->vote_2.oper_nick,
842     glp_ptr->vote_2.oper_user, glp_ptr->vote_2.oper_host,
843     glp_ptr->vote_2.oper_server, timebuffer,
844     glp_ptr->user, glp_ptr->host, glp_ptr->vote_2.reason);
845    
846     }
847     }
848    
849     sendto_one(source_p, ":%s NOTICE %s :End of Pending UNG-lines",
850     from, to);
851 adx 30 }
852    
853     /* stats_glines()
854     *
855     * input - client pointer
856     * output - none
857     * side effects - client is shown list of glines
858     */
859     static void
860     stats_glines(struct Client *source_p)
861     {
862     struct AddressRec *arec = NULL;
863     int i = 0;
864    
865     if (!ConfigFileEntry.glines)
866     {
867     sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
868     from, to);
869     return;
870     }
871    
872     for (; i < ATABLE_SIZE; ++i)
873     {
874 michael 884 for (arec = atable[i]; arec; arec = arec->next)
875 adx 30 {
876     if (arec->type == CONF_GLINE)
877     {
878     const struct AccessItem *aconf = arec->aconf;
879    
880     sendto_one(source_p, form_str(RPL_STATSKLINE),
881     from, to, "G",
882     aconf->host ? aconf->host : "*",
883     aconf->user ? aconf->user : "*",
884     aconf->reason ? aconf->reason : "No reason", "" );
885     }
886     }
887     }
888     }
889    
890     /* stats_gdeny()
891     *
892     * input - client pointer
893     * outputs - none
894     * side effects - client is shown gline ACL
895     */
896     static void
897     stats_gdeny(struct Client *source_p)
898     {
899     if (!ConfigFileEntry.glines)
900     {
901     sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
902     from, to);
903     return;
904     }
905    
906     report_confitem_types(source_p, GDENY_TYPE, 0);
907     }
908    
909     static void
910     stats_hubleaf(struct Client *source_p)
911     {
912     report_confitem_types(source_p, HUB_TYPE, 0);
913     report_confitem_types(source_p, LEAF_TYPE, 0);
914     }
915    
916     static void
917     stats_auth(struct Client *source_p)
918     {
919     /* Oper only, if unopered, return ERR_NOPRIVILEGES */
920     if ((ConfigFileEntry.stats_i_oper_only == 2) && !IsOper(source_p))
921     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
922     from, to);
923    
924     /* If unopered, Only return matching auth blocks */
925     else if ((ConfigFileEntry.stats_i_oper_only == 1) && !IsOper(source_p))
926     {
927     struct ConfItem *conf;
928     struct AccessItem *aconf;
929    
930     if (MyConnect(source_p))
931     aconf = find_conf_by_address(source_p->host,
932     &source_p->localClient->ip,
933     CONF_CLIENT,
934     source_p->localClient->aftype,
935     source_p->username,
936     source_p->localClient->passwd);
937     else
938     aconf = find_conf_by_address(source_p->host, NULL, CONF_CLIENT,
939     0, source_p->username, NULL);
940    
941     if (aconf == NULL)
942     return;
943    
944     conf = unmap_conf_item(aconf);
945    
946     sendto_one(source_p, form_str(RPL_STATSILINE), from,
947     to, 'I',
948     "*", show_iline_prefix(source_p, aconf, aconf->user),
949     aconf->host, aconf->port,
950     aconf->class_ptr ? aconf->class_ptr->name : "<default>");
951     }
952     /* They are opered, or allowed to see all auth blocks */
953     else
954     report_auth(source_p);
955     }
956    
957     static void
958     stats_tklines(struct Client *source_p)
959     {
960     struct ConfItem *conf;
961     /* Oper only, if unopered, return ERR_NOPRIVILEGES */
962     if ((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p))
963     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
964     from, to);
965    
966     /* If unopered, Only return matching klines */
967     else if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p))
968     {
969     struct AccessItem *aconf;
970    
971     if (MyConnect(source_p))
972     aconf = find_conf_by_address(source_p->host,
973     &source_p->localClient->ip,
974     CONF_KILL,
975     source_p->localClient->aftype,
976     source_p->username, NULL);
977     else
978     aconf = find_conf_by_address(source_p->host, NULL, CONF_KILL,
979     0, source_p->username, NULL);
980    
981     if (aconf == NULL)
982     return;
983    
984     /* dont report a permanent kline as a tkline */
985     if (!(aconf->flags & CONF_FLAGS_TEMPORARY))
986     return;
987    
988     conf = unmap_conf_item(aconf);
989    
990     sendto_one(source_p, form_str(RPL_STATSKLINE), from,
991     to, "k", aconf->host, aconf->user, aconf->reason, "");
992     }
993     /* Theyre opered, or allowed to see all klines */
994     else {
995     report_Klines(source_p, 1);
996     report_confitem_types(source_p, RKLINE_TYPE, 1);
997     }
998     }
999    
1000     static void
1001     stats_klines(struct Client *source_p)
1002     {
1003     /* Oper only, if unopered, return ERR_NOPRIVILEGES */
1004     if ((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p))
1005     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1006     from, to);
1007    
1008     /* If unopered, Only return matching klines */
1009     else if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p))
1010     {
1011     struct AccessItem *aconf;
1012    
1013     /* search for a kline */
1014 michael 560 if (MyConnect(source_p))
1015 adx 30 aconf = find_conf_by_address(source_p->host,
1016     &source_p->localClient->ip,
1017     CONF_KILL,
1018     source_p->localClient->aftype,
1019     source_p->username, NULL);
1020     else
1021     aconf = find_conf_by_address(source_p->host, NULL, CONF_KILL,
1022     0, source_p->username, NULL);
1023    
1024 michael 560 if (aconf == NULL)
1025 adx 30 return;
1026    
1027     /* dont report a tkline as a kline */
1028 michael 560 if (aconf->flags & CONF_FLAGS_TEMPORARY)
1029 adx 30 return;
1030    
1031     sendto_one(source_p, form_str(RPL_STATSKLINE), from,
1032     to, "K", aconf->host, aconf->user, aconf->reason,
1033     aconf->oper_reason);
1034     }
1035     /* Theyre opered, or allowed to see all klines */
1036     else {
1037     report_Klines(source_p, 0);
1038     report_confitem_types(source_p, RKLINE_TYPE, 0);
1039     }
1040     }
1041    
1042     static void
1043     stats_messages(struct Client *source_p)
1044     {
1045     report_messages(source_p);
1046     }
1047    
1048     static void
1049     stats_oper(struct Client *source_p)
1050     {
1051     if (!IsOper(source_p) && ConfigFileEntry.stats_o_oper_only)
1052     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1053     from, to);
1054     else
1055     report_confitem_types(source_p, OPER_TYPE, 0);
1056     }
1057    
1058     /* stats_operedup()
1059     *
1060     * input - client pointer
1061     * output - none
1062     * side effects - client is shown a list of active opers
1063     */
1064     static void
1065     stats_operedup(struct Client *source_p)
1066     {
1067     dlink_node *ptr;
1068    
1069     DLINK_FOREACH(ptr, oper_list.head)
1070     {
1071     const struct Client *target_p = ptr->data;
1072    
1073     if (IsOperHidden(target_p) && !IsOper(source_p))
1074     continue;
1075    
1076     if (MyClient(source_p) && IsOper(source_p))
1077     sendto_one(source_p, ":%s %d %s p :[%c][%s] %s (%s@%s) Idle: %d",
1078     from, RPL_STATSDEBUG, to,
1079     IsAdmin(target_p) ?
1080     (IsOperHiddenAdmin(target_p) ? 'O' : 'A') : 'O',
1081     oper_privs_as_string(target_p->localClient->operflags),
1082     target_p->name, target_p->username, target_p->host,
1083     (int)(CurrentTime - target_p->localClient->last));
1084     else
1085     sendto_one(source_p, ":%s %d %s p :[%c] %s (%s@%s) Idle: %d",
1086     from, RPL_STATSDEBUG, to,
1087     IsAdmin(target_p) ?
1088     (IsOperHiddenAdmin(target_p) ? 'O' : 'A') : 'O',
1089     target_p->name, target_p->username, target_p->host,
1090     (int)(CurrentTime - target_p->localClient->last));
1091     }
1092    
1093     sendto_one(source_p, ":%s %d %s p :%lu OPER(s)",
1094     from, RPL_STATSDEBUG, to, dlink_list_length(&oper_list));
1095     }
1096    
1097     static void
1098     stats_ports(struct Client *source_p)
1099     {
1100     if (!IsOper(source_p) && ConfigFileEntry.stats_P_oper_only)
1101     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1102     from, to);
1103     else
1104     show_ports(source_p);
1105     }
1106    
1107     static void
1108     stats_resv(struct Client *source_p)
1109     {
1110     report_resv(source_p);
1111     }
1112    
1113     static void
1114     stats_usage(struct Client *source_p)
1115     {
1116     send_usage(source_p);
1117     }
1118    
1119     static void
1120     stats_tstats(struct Client *source_p)
1121     {
1122 michael 896 const struct Client *target_p = NULL;
1123     const dlink_node *ptr = NULL;
1124     struct ServerStatistics *sp;
1125     struct ServerStatistics tmp;
1126    
1127     sp = &tmp;
1128     memcpy(sp, &ServerStats, sizeof(struct ServerStatistics));
1129    
1130     /*
1131     * must use the += operator. is_sv is not the number of currently
1132     * active server connections. Note the incrementation in
1133     * s_bsd.c:close_connection.
1134     */
1135     sp->is_sv += dlink_list_length(&serv_list);
1136    
1137     DLINK_FOREACH(ptr, serv_list.head)
1138     {
1139     target_p = ptr->data;
1140    
1141     sp->is_sbs += target_p->localClient->send.bytes;
1142     sp->is_sbr += target_p->localClient->recv.bytes;
1143     sp->is_sti += CurrentTime - target_p->firsttime;
1144     }
1145    
1146     sp->is_cl += dlink_list_length(&local_client_list);
1147    
1148     DLINK_FOREACH(ptr, local_client_list.head)
1149     {
1150     target_p = ptr->data;
1151    
1152     sp->is_cbs += target_p->localClient->send.bytes;
1153     sp->is_cbr += target_p->localClient->recv.bytes;
1154     sp->is_cti += CurrentTime - target_p->firsttime;
1155     }
1156    
1157     sp->is_ni += dlink_list_length(&unknown_list);
1158    
1159     sendto_one(source_p, ":%s %d %s T :accepts %u refused %u",
1160     me.name, RPL_STATSDEBUG, source_p->name, sp->is_ac, sp->is_ref);
1161     sendto_one(source_p, ":%s %d %s T :unknown commands %u prefixes %u",
1162     me.name, RPL_STATSDEBUG, source_p->name, sp->is_unco, sp->is_unpf);
1163     sendto_one(source_p, ":%s %d %s T :nick collisions %u unknown closes %u",
1164     me.name, RPL_STATSDEBUG, source_p->name, sp->is_kill, sp->is_ni);
1165     sendto_one(source_p, ":%s %d %s T :wrong direction %u empty %u",
1166     me.name, RPL_STATSDEBUG, source_p->name, sp->is_wrdi, sp->is_empt);
1167     sendto_one(source_p, ":%s %d %s T :numerics seen %u",
1168     me.name, RPL_STATSDEBUG, source_p->name, sp->is_num);
1169     sendto_one(source_p, ":%s %d %s T :auth successes %u fails %u",
1170     me.name, RPL_STATSDEBUG, source_p->name, sp->is_asuc, sp->is_abad);
1171     sendto_one(source_p, ":%s %d %s T :Client Server",
1172     me.name, RPL_STATSDEBUG, source_p->name);
1173    
1174     sendto_one(source_p, ":%s %d %s T :connected %u %u",
1175     me.name, RPL_STATSDEBUG, source_p->name,
1176     (unsigned int)sp->is_cl,
1177     (unsigned int)sp->is_sv);
1178     sendto_one(source_p, ":%s %d %s T :bytes sent %llu %llu",
1179     me.name, RPL_STATSDEBUG, source_p->name,
1180     sp->is_cbs, sp->is_sbs);
1181     sendto_one(source_p, ":%s %d %s T :bytes recv %llu %llu",
1182     me.name, RPL_STATSDEBUG, source_p->name,
1183     sp->is_cbr, sp->is_sbr);
1184     sendto_one(source_p, ":%s %d %s T :time connected %u %u",
1185     me.name, RPL_STATSDEBUG, source_p->name,
1186     (unsigned int)sp->is_cti,
1187     (unsigned int)sp->is_sti);
1188 adx 30 }
1189    
1190     static void
1191     stats_uptime(struct Client *source_p)
1192     {
1193     time_t now = CurrentTime - me.since;
1194     sendto_one(source_p, form_str(RPL_STATSUPTIME), from, to,
1195     now/86400, (now/3600)%24, (now/60)%60, now%60);
1196     if (!ConfigFileEntry.disable_remote || IsOper(source_p))
1197     sendto_one(source_p, form_str(RPL_STATSCONN), from, to,
1198     MaxConnectionCount, MaxClientCount, Count.totalrestartcount);
1199     }
1200    
1201     static void
1202     stats_shared(struct Client *source_p)
1203     {
1204     report_confitem_types(source_p, ULINE_TYPE, 0);
1205     }
1206    
1207     /* stats_servers()
1208     *
1209     * input - client pointer
1210     * output - none
1211     * side effects - client is shown lists of who connected servers
1212     */
1213     static void
1214     stats_servers(struct Client *source_p)
1215     {
1216     struct Client *target_p;
1217     dlink_node *ptr;
1218     int j = 0;
1219    
1220     DLINK_FOREACH(ptr, serv_list.head)
1221     {
1222     target_p = ptr->data;
1223    
1224     j++;
1225    
1226     sendto_one(source_p, ":%s %d %s v :%s (%s!%s@%s) Idle: %d",
1227     from, RPL_STATSDEBUG, to,
1228     target_p->name,
1229     (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
1230     "*", "*", (int)(CurrentTime - target_p->lasttime));
1231     }
1232    
1233     sendto_one(source_p, ":%s %d %s v :%d Server(s)",
1234     from, RPL_STATSDEBUG, to, j);
1235     }
1236    
1237     static void
1238     stats_gecos(struct Client *source_p)
1239     {
1240     report_confitem_types(source_p, XLINE_TYPE, 0);
1241     report_confitem_types(source_p, RXLINE_TYPE, 0);
1242     }
1243    
1244     static void
1245     stats_class(struct Client *source_p)
1246     {
1247     report_confitem_types(source_p, CLASS_TYPE, 0);
1248     }
1249    
1250     static void
1251     stats_memory(struct Client *source_p)
1252     {
1253     count_memory(source_p);
1254     }
1255    
1256     static void
1257     stats_ziplinks(struct Client *source_p)
1258     {
1259 michael 948 dlink_node *ptr = NULL;
1260 adx 30 unsigned int sent_data = 0;
1261    
1262     DLINK_FOREACH(ptr, serv_list.head)
1263     {
1264 michael 948 const struct Client *target_p = ptr->data;
1265 adx 30
1266     if (IsCapable(target_p, CAP_ZIP))
1267     {
1268     /* we use memcpy(3) and a local copy of the structure to
1269     * work around a register use bug on GCC on the SPARC.
1270     * -jmallett, 04/27/2002
1271     */
1272     struct ZipStats zipstats;
1273    
1274 michael 948 memcpy(&zipstats, &target_p->localClient->zipstats, sizeof(zipstats));
1275    
1276 adx 30 sendto_one(source_p, ":%s %d %s Z :ZipLinks stats for %s send[%.2f%% "
1277 michael 948 "compression (%llu bytes data/%llu bytes wire)] recv[%.2f%% "
1278     "compression (%llu bytes data/%llu bytes wire)]",
1279 adx 30 from, RPL_STATSDEBUG, to, target_p->name,
1280 michael 560 zipstats.out_ratio, zipstats.out, zipstats.out_wire,
1281     zipstats.in_ratio, zipstats.in, zipstats.in_wire);
1282 adx 30 ++sent_data;
1283     }
1284     }
1285    
1286     sendto_one(source_p, ":%s %d %s Z :%u ziplink(s)",
1287     from, RPL_STATSDEBUG, to, sent_data);
1288     }
1289    
1290     static void
1291     stats_servlinks(struct Client *source_p)
1292     {
1293     uint64_t sendB = 0, recvB = 0;
1294     time_t uptime = 0;
1295 michael 560 dlink_node *ptr = NULL;
1296 adx 30
1297     if (ConfigServerHide.flatten_links && !IsOper(source_p))
1298     {
1299     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1300     from, to);
1301     return;
1302     }
1303    
1304     DLINK_FOREACH(ptr, serv_list.head)
1305     {
1306 michael 560 struct Client *target_p = ptr->data;
1307 adx 30
1308     sendB += target_p->localClient->send.bytes;
1309     recvB += target_p->localClient->recv.bytes;
1310    
1311     /* ":%s 211 %s %s %u %u %llu %u %llu :%u %u %s" */
1312     sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1313     from, to,
1314     get_client_name(target_p, IsAdmin(source_p) ? SHOW_IP : MASK_IP),
1315     dbuf_length(&target_p->localClient->buf_sendq),
1316     target_p->localClient->send.messages,
1317     target_p->localClient->send.bytes >> 10,
1318     target_p->localClient->recv.messages,
1319     target_p->localClient->recv.bytes >> 10,
1320     (unsigned)(CurrentTime - target_p->firsttime),
1321     (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since): 0,
1322     IsOper(source_p) ? show_capabilities(target_p) : "TS");
1323     }
1324    
1325     sendB >>= 10;
1326     recvB >>= 10;
1327    
1328     sendto_one(source_p, ":%s %d %s ? :%u total server(s)",
1329 michael 560 from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list));
1330 adx 30 sendto_one(source_p, ":%s %d %s ? :Sent total : %7.2f %s",
1331     from, RPL_STATSDEBUG, to,
1332 michael 560 _GMKv(sendB), _GMKs(sendB));
1333 adx 30 sendto_one(source_p, ":%s %d %s ? :Recv total : %7.2f %s",
1334     from, RPL_STATSDEBUG, to,
1335 michael 560 _GMKv(recvB), _GMKs(recvB));
1336 adx 30
1337     uptime = (CurrentTime - me.since);
1338    
1339     sendto_one(source_p, ":%s %d %s ? :Server send: %7.2f %s (%4.1f K/s)",
1340     from, RPL_STATSDEBUG, to,
1341 michael 560 _GMKv((me.localClient->send.bytes>>10)),
1342     _GMKs((me.localClient->send.bytes>>10)),
1343     (float)((float)((me.localClient->send.bytes) >> 10) /
1344     (float)uptime));
1345 adx 30 sendto_one(source_p, ":%s %d %s ? :Server recv: %7.2f %s (%4.1f K/s)",
1346     from, RPL_STATSDEBUG, to,
1347 michael 560 _GMKv((me.localClient->recv.bytes>>10)),
1348     _GMKs((me.localClient->recv.bytes>>10)),
1349     (float)((float)((me.localClient->recv.bytes) >> 10) /
1350     (float)uptime));
1351 adx 30 }
1352    
1353     static void
1354     stats_ltrace(struct Client *source_p, int parc, char *parv[])
1355     {
1356     int doall = 0;
1357     int wilds = 0;
1358     char *name = NULL;
1359     char statchar;
1360    
1361     if ((name = parse_stats_args(parc, parv, &doall, &wilds)) != NULL)
1362     {
1363     statchar = parv[1][0];
1364    
1365     stats_L(source_p, name, doall, wilds, statchar);
1366     }
1367     else
1368     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1369     from, to, "STATS");
1370     }
1371    
1372     /*
1373     * ms_stats - STATS message handler
1374     * parv[0] = sender prefix
1375     * parv[1] = statistics selector (defaults to Message frequency)
1376     * parv[2] = server name (current server defaulted, if omitted)
1377     */
1378     static void
1379     ms_stats(struct Client *client_p, struct Client *source_p,
1380     int parc, char *parv[])
1381     {
1382     if (hunt_server(client_p,source_p,":%s STATS %s :%s",2,parc,parv)!=HUNTED_ISME)
1383     return;
1384    
1385     if (IsClient(source_p))
1386     mo_stats(client_p, source_p, parc, parv);
1387     }
1388    
1389     /*
1390     * stats_L
1391     *
1392     * inputs - pointer to client to report to
1393     * - doall flag
1394     * - wild card or not
1395     * output - NONE
1396     * side effects -
1397     */
1398     static void
1399     stats_L(struct Client *source_p,char *name,int doall,
1400     int wilds,char statchar)
1401     {
1402     stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar);
1403     stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar);
1404     stats_L_list(source_p, name, doall, wilds, &serv_list, statchar);
1405     }
1406    
1407     static void
1408     stats_L_list(struct Client *source_p,char *name, int doall, int wilds,
1409     dlink_list *list,char statchar)
1410     {
1411     dlink_node *ptr;
1412     struct Client *target_p;
1413    
1414     /*
1415     * send info about connections which match, or all if the
1416     * mask matches from. Only restrictions are on those who
1417     * are invisible not being visible to 'foreigners' who use
1418     * a wild card based search to list it.
1419     */
1420     DLINK_FOREACH(ptr, list->head)
1421     {
1422     target_p = ptr->data;
1423    
1424     if (IsInvisible(target_p) && (doall || wilds) &&
1425     !(MyConnect(source_p) && IsOper(source_p)) &&
1426     !IsOper(target_p) && (target_p != source_p))
1427     continue;
1428     if (!doall && wilds && !match(name, target_p->name))
1429     continue;
1430     if (!(doall || wilds) && irccmp(name, target_p->name))
1431     continue;
1432    
1433     /* This basically shows ips for our opers if its not a server/admin, or
1434     * its one of our admins. */
1435     if(MyClient(source_p) && IsOper(source_p) &&
1436     (IsAdmin(source_p) ||
1437     (!IsServer(target_p) && !IsAdmin(target_p) &&
1438     !IsHandshake(target_p) && !IsConnecting(target_p))))
1439     {
1440     sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1441     from, to,
1442     (IsUpper(statchar)) ?
1443     get_client_name(target_p, SHOW_IP) :
1444     get_client_name(target_p, HIDE_IP),
1445     dbuf_length(&target_p->localClient->buf_sendq),
1446     target_p->localClient->send.messages,
1447     target_p->localClient->send.bytes>>10,
1448     target_p->localClient->recv.messages,
1449     target_p->localClient->recv.bytes>>10,
1450     (unsigned)(CurrentTime - target_p->firsttime),
1451     (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1452     IsServer(target_p) ? show_capabilities(target_p) : "-");
1453     }
1454     else
1455     {
1456     /* If its a hidden ip, an admin, or a server, mask the real IP */
1457     if(IsIPSpoof(target_p) || IsServer(target_p) || IsAdmin(target_p)
1458     || IsHandshake(target_p) || IsConnecting(target_p))
1459     sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1460     from, to,
1461     get_client_name(target_p, MASK_IP),
1462     dbuf_length(&target_p->localClient->buf_sendq),
1463     target_p->localClient->send.messages,
1464     target_p->localClient->send.bytes>>10,
1465     target_p->localClient->recv.messages,
1466     target_p->localClient->recv.bytes>>10,
1467     (unsigned)(CurrentTime - target_p->firsttime),
1468     (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1469     IsServer(target_p) ? show_capabilities(target_p) : "-");
1470     else /* show the real IP */
1471     sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1472     from, to,
1473     (IsUpper(statchar)) ?
1474     get_client_name(target_p, SHOW_IP) :
1475     get_client_name(target_p, HIDE_IP),
1476     dbuf_length(&target_p->localClient->buf_sendq),
1477     target_p->localClient->send.messages,
1478     target_p->localClient->send.bytes>>10,
1479     target_p->localClient->recv.messages,
1480     target_p->localClient->recv.bytes>>10,
1481     (unsigned)(CurrentTime - target_p->firsttime),
1482     (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1483     IsServer(target_p) ? show_capabilities(target_p) : "-");
1484     }
1485     }
1486     }
1487    
1488     /* parse_stats_args()
1489     *
1490     * inputs - arg count
1491     * - args
1492     * - doall flag
1493     * - wild card or not
1494     * output - pointer to name to use
1495     * side effects -
1496     * common parse routine for m_stats args
1497     *
1498     */
1499     static char *
1500     parse_stats_args(int parc, char *parv[], int *doall, int *wilds)
1501     {
1502     char *name;
1503    
1504     if (parc > 2)
1505     {
1506     name = parv[2];
1507    
1508     if (!irccmp(name, from))
1509     *doall = 2;
1510     else if (match(name, from))
1511     *doall = 1;
1512    
1513     if (strchr(name, '*') ||
1514     strchr(name, '?'))
1515     *wilds = 1;
1516    
1517     return(name);
1518     }
1519     else
1520     return(NULL);
1521     }

Properties

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