ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_stats.c
Revision: 377
Committed: Wed Jan 25 10:48:24 2006 UTC (20 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 44626 byte(s)
Log Message:
- Removed death code. We don't have sth. like conf *lines* anymore

File Contents

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

Properties

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