ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 988
Committed: Sun Aug 16 14:00:36 2009 UTC (14 years, 8 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/modules/m_stats.c
File size: 47829 byte(s)
Log Message:
- removed remnants of --disable-gline-voting

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

Properties

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