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

Properties

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