ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_stats.c
Revision: 234
Committed: Sat Nov 5 08:38:19 2005 UTC (20 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 44906 byte(s)
Log Message:
- Cleaned up report_memory() a bit more. user_invite_count is actually
  the same as channel_invite_count.

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

Properties

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