ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 884
Committed: Sun Oct 28 18:22:55 2007 UTC (17 years, 10 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/modules/m_stats.c
File size: 43830 byte(s)
Log Message:
- show some watch statistics in STATS z

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

Properties

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