ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 1312
Committed: Mon Mar 26 16:07:20 2012 UTC (12 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_stats.c
File size: 46255 byte(s)
Log Message:
- client.h: remove servlink leftovers

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

Properties

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