ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_stats.c
Revision: 470
Committed: Fri Feb 17 05:07:43 2006 UTC (20 years, 5 months ago) by db
Content type: text/x-csrc
File size: 44321 byte(s)
Log Message:
- fix compile errors with moved modules.h
- fix a few missing includes, msg.h and parse.h


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

Properties

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