ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_stats.c
Revision: 1156
Committed: Tue Aug 9 20:29:20 2011 UTC (12 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 46888 byte(s)
Log Message:
- create ircd-hybrid-8 "branch"

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

Properties

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