ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 958
Committed: Tue Jul 28 21:36:41 2009 UTC (16 years, 1 month ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/modules/m_stats.c
File size: 47970 byte(s)
Log Message:
- show pending gunglines in STATS g

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

Properties

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