ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_stats.c
Revision: 442
Committed: Sat Feb 11 23:14:21 2006 UTC (20 years, 6 months ago) by adx
Content type: text/x-csrc
File size: 44574 byte(s)
Log Message:
+ massive rewrite of module init/deinit/version headers,
  we are introducing a new module manager which deals with static
  and dynamic modules exactly the same way. (New possibilities
  include loading/unloading statically compiled modules and
  mixing static/dynamic ones in one build.)

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

Properties

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