ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 6306
Committed: Fri Jul 24 13:23:31 2015 UTC (8 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 48320 byte(s)
Log Message:
- Move show_events() from event.c to m_stats.c. Remove now unused prototypes.

File Contents

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

Properties

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