ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 1294
Committed: Wed Feb 22 20:48:30 2012 UTC (13 years, 6 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_stats.c
File size: 47394 byte(s)
Log Message:
- Add user mode +H which simply hides operator status to other users.
  This solution replaces current method of hidding operator status where the
  admin mode is not sent to other servers unless hidden_administrator is disabled.
- m_who() now takes care whether an operator is hidden or not

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

Properties

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