ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 5864
Committed: Tue Apr 28 12:23:30 2015 UTC (8 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 47516 byte(s)
Log Message:
- Removed useless zero initializers from the module_entry as suggested by Adam

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     show_events(source_p);
643     }
644    
645     static void
646 michael 1457 stats_hubleaf(struct Client *source_p, int parc, char *parv[])
647 adx 30 {
648 michael 4815 const dlink_node *node = NULL, *dptr = NULL;
649 michael 2118
650 michael 4815 DLINK_FOREACH(node, server_items.head)
651 michael 2118 {
652 michael 4815 const struct MaskItem *conf = node->data;
653 michael 2118
654     DLINK_FOREACH(dptr, conf->hub_list.head)
655 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSHLINE, 'H', dptr->data, conf->name, 0, "*");
656 michael 2118 }
657    
658 michael 4815 DLINK_FOREACH(node, server_items.head)
659 michael 2118 {
660 michael 4815 const struct MaskItem *conf = node->data;
661 michael 2118
662     DLINK_FOREACH(dptr, conf->leaf_list.head)
663 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSLLINE, 'L', dptr->data, conf->name, 0, "*");
664 michael 2118 }
665 adx 30 }
666    
667 michael 1372 /*
668     * show_iline_prefix()
669     *
670     * inputs - pointer to struct Client requesting output
671 michael 2820 * - pointer to struct MaskItem
672 michael 1372 * - name to which iline prefix will be prefixed to
673     * output - pointer to static string with prefixes listed in ascii form
674     * side effects - NONE
675     */
676     static const char *
677 michael 1632 show_iline_prefix(const struct Client *sptr, const struct MaskItem *conf)
678 michael 1372 {
679 michael 1715 static char prefix_of_host[USERLEN + 15];
680 michael 1372 char *prefix_ptr = prefix_of_host;
681    
682 michael 1715 if (IsConfWebIRC(conf))
683     *prefix_ptr++ = '<';
684 michael 1632 if (IsNoTilde(conf))
685 michael 1372 *prefix_ptr++ = '-';
686 michael 1632 if (IsNeedIdentd(conf))
687 michael 1372 *prefix_ptr++ = '+';
688 michael 1632 if (!IsNeedPassword(conf))
689 michael 1372 *prefix_ptr++ = '&';
690 michael 1632 if (IsConfExemptResv(conf))
691 michael 1372 *prefix_ptr++ = '$';
692 michael 1632 if (IsConfDoSpoofIp(conf))
693 michael 1372 *prefix_ptr++ = '=';
694 michael 1632 if (MyOper(sptr) && IsConfExemptKline(conf))
695 michael 1372 *prefix_ptr++ = '^';
696 michael 1632 if (MyOper(sptr) && IsConfExemptLimits(conf))
697 michael 1372 *prefix_ptr++ = '>';
698 michael 1632 if (IsConfCanFlood(conf))
699 michael 1372 *prefix_ptr++ = '|';
700    
701 michael 1632 strlcpy(prefix_ptr, conf->user, USERLEN+1);
702 michael 1372
703     return prefix_of_host;
704     }
705    
706 adx 30 static void
707 michael 3156 report_auth(struct Client *source_p, int parc, char *parv[])
708 michael 1372 {
709 michael 4032 const struct MaskItem *conf = NULL;
710 michael 4815 const dlink_node *node = NULL;
711 michael 1372
712 michael 3246 for (unsigned int i = 0; i < ATABLE_SIZE; ++i)
713 michael 1372 {
714 michael 4815 DLINK_FOREACH(node, atable[i].head)
715 michael 1372 {
716 michael 4815 const struct AddressRec *arec = node->data;
717 michael 1372
718 michael 1632 if (arec->type != CONF_CLIENT)
719     continue;
720 michael 1372
721 michael 1632 conf = arec->conf;
722 michael 1372
723 michael 3156 if (!MyOper(source_p) && IsConfDoSpoofIp(conf))
724 michael 1632 continue;
725 michael 1372
726 michael 4967 sendto_one_numeric(source_p, &me, RPL_STATSILINE, 'I',
727     conf->name == NULL ? "*" : conf->name,
728     show_iline_prefix(source_p, conf),
729     conf->host, conf->port,
730     conf->class->name);
731 michael 1372 }
732     }
733     }
734    
735     static void
736 michael 1457 stats_auth(struct Client *source_p, int parc, char *parv[])
737 adx 30 {
738     /* Oper only, if unopered, return ERR_NOPRIVILEGES */
739 michael 4340 if (ConfigGeneral.stats_i_oper_only == 2 && !HasUMode(source_p, UMODE_OPER))
740 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
741 adx 30
742 michael 4034 /* If unopered, only return matching auth blocks */
743 michael 4340 else if (ConfigGeneral.stats_i_oper_only == 1 && !HasUMode(source_p, UMODE_OPER))
744 adx 30 {
745 michael 4034 const struct MaskItem *conf = NULL;
746 adx 30
747     if (MyConnect(source_p))
748 michael 1632 conf = find_conf_by_address(source_p->host,
749 michael 4588 &source_p->connection->ip, CONF_CLIENT,
750     source_p->connection->aftype,
751 michael 2820 source_p->username,
752 michael 4588 source_p->connection->password, 1);
753 adx 30 else
754 michael 4034 conf = find_conf_by_address(source_p->host, NULL, CONF_CLIENT, 0,
755     source_p->username, NULL, 1);
756 adx 30
757 michael 1632 if (conf == NULL)
758 adx 30 return;
759    
760 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSILINE,
761     'I', "*", show_iline_prefix(source_p, conf),
762     conf->host, conf->port,
763 michael 4037 conf->class->name);
764 adx 30 }
765 michael 4034 else /* They are opered, or allowed to see all auth blocks */
766 michael 1457 report_auth(source_p, 0, NULL);
767 adx 30 }
768    
769 michael 1372 /* report_Klines()
770     * Inputs: Client to report to,
771     * type(==0 for perm, !=0 for temporary)
772 michael 2820 * mask
773 michael 1372 * Output: None
774 michael 3156 * Side effects: Reports configured K(or k)-lines to source_p.
775 michael 1372 */
776 adx 30 static void
777 michael 3156 report_Klines(struct Client *source_p, int tkline)
778 michael 1372 {
779 michael 4032 const struct MaskItem *conf = NULL;
780 michael 4815 const dlink_node *node = NULL;
781 michael 1921 char c = '\0';
782 michael 1372
783     if (tkline)
784 michael 1921 c = 'k';
785 michael 1372 else
786 michael 1921 c = 'K';
787 michael 1372
788 michael 3246 for (unsigned int i = 0; i < ATABLE_SIZE; ++i)
789 michael 1372 {
790 michael 4815 DLINK_FOREACH(node, atable[i].head)
791 michael 1372 {
792 michael 4815 const struct AddressRec *arec = node->data;
793 michael 1372
794 michael 1632 if (arec->type != CONF_KLINE)
795     continue;
796 michael 1628
797 michael 1632 conf = arec->conf;
798 michael 1372
799 michael 1650 if ((!tkline && conf->until) ||
800     (tkline && !conf->until))
801 michael 1632 continue;
802    
803 michael 4570 sendto_one_numeric(source_p, &me, RPL_STATSKLINE, c, conf->host, conf->user,
804     conf->reason);
805 michael 1372 }
806     }
807     }
808    
809     static void
810 michael 1457 stats_tklines(struct Client *source_p, int parc, char *parv[])
811 adx 30 {
812     /* Oper only, if unopered, return ERR_NOPRIVILEGES */
813 michael 4340 if (ConfigGeneral.stats_k_oper_only == 2 && !HasUMode(source_p, UMODE_OPER))
814 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
815 adx 30
816 michael 4034 /* If unopered, only return matching klines */
817 michael 4340 else if (ConfigGeneral.stats_k_oper_only == 1 && !HasUMode(source_p, UMODE_OPER))
818 adx 30 {
819 michael 4032 const struct MaskItem *conf = NULL;
820 adx 30
821     if (MyConnect(source_p))
822 michael 1632 conf = find_conf_by_address(source_p->host,
823 michael 4588 &source_p->connection->ip, CONF_KLINE,
824     source_p->connection->aftype,
825 michael 2820 source_p->username, NULL, 1);
826 adx 30 else
827 michael 4034 conf = find_conf_by_address(source_p->host, NULL, CONF_KLINE, 0,
828     source_p->username, NULL, 1);
829 adx 30
830 michael 1632 if (!conf)
831 adx 30 return;
832    
833 michael 5542 /* Don't report a permanent kline as temporary kline */
834 michael 1649 if (!conf->until)
835 adx 30 return;
836    
837 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSKLINE, 'k',
838     conf->host, conf->user, conf->reason);
839 adx 30 }
840 michael 4034 else /* They are opered, or allowed to see all klines */
841 adx 30 report_Klines(source_p, 1);
842     }
843    
844     static void
845 michael 1457 stats_klines(struct Client *source_p, int parc, char *parv[])
846 adx 30 {
847     /* Oper only, if unopered, return ERR_NOPRIVILEGES */
848 michael 4340 if (ConfigGeneral.stats_k_oper_only == 2 && !HasUMode(source_p, UMODE_OPER))
849 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
850 adx 30
851 michael 4034 /* If unopered, only return matching klines */
852 michael 4340 else if (ConfigGeneral.stats_k_oper_only == 1 && !HasUMode(source_p, UMODE_OPER))
853 adx 30 {
854 michael 4032 const struct MaskItem *conf = NULL;
855 adx 30
856 michael 4034 /* Search for a kline */
857 michael 560 if (MyConnect(source_p))
858 michael 1632 conf = find_conf_by_address(source_p->host,
859 michael 4588 &source_p->connection->ip, CONF_KLINE,
860     source_p->connection->aftype,
861 michael 2820 source_p->username, NULL, 0);
862 adx 30 else
863 michael 4034 conf = find_conf_by_address(source_p->host, NULL, CONF_KLINE, 0,
864     source_p->username, NULL, 0);
865 adx 30
866 michael 1632 if (!conf)
867 adx 30 return;
868    
869 michael 5542 /* Don't report a temporary kline as permanent kline */
870 michael 1649 if (conf->until)
871 adx 30 return;
872 michael 2820
873 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSKLINE, 'K',
874     conf->host, conf->user, conf->reason);
875 adx 30 }
876 michael 4034 else /* They are opered, or allowed to see all klines */
877 adx 30 report_Klines(source_p, 0);
878     }
879    
880     static void
881 michael 1457 stats_messages(struct Client *source_p, int parc, char *parv[])
882 adx 30 {
883 michael 5026 if (!HasUMode(source_p, UMODE_OPER) && ConfigGeneral.stats_m_oper_only)
884     sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
885     else
886     report_messages(source_p);
887 adx 30 }
888    
889     static void
890 michael 1457 stats_oper(struct Client *source_p, int parc, char *parv[])
891 adx 30 {
892 michael 4340 if (!HasUMode(source_p, UMODE_OPER) && ConfigGeneral.stats_o_oper_only)
893 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
894 adx 30 else
895 michael 1632 report_confitem_types(source_p, CONF_OPER);
896 adx 30 }
897    
898     /* stats_operedup()
899     *
900     * input - client pointer
901     * output - none
902     * side effects - client is shown a list of active opers
903     */
904     static void
905 michael 1457 stats_operedup(struct Client *source_p, int parc, char *parv[])
906 adx 30 {
907 michael 4815 const dlink_node *node = NULL;
908 michael 3511 unsigned int opercount = 0;
909 michael 3516 char buf[IRCD_BUFSIZE] = "";
910 adx 30
911 michael 4815 DLINK_FOREACH(node, oper_list.head)
912 adx 30 {
913 michael 4815 const struct Client *target_p = node->data;
914 adx 30
915 michael 1294 if (HasUMode(target_p, UMODE_HIDDEN) && !HasUMode(source_p, UMODE_OPER))
916 adx 30 continue;
917    
918 michael 3516 if (HasUMode(source_p, UMODE_OPER) || !HasUMode(target_p, UMODE_HIDEIDLE))
919 michael 5544 snprintf(buf, sizeof(buf), "%u", client_get_idle_time(source_p, target_p));
920 michael 3516 else
921     strlcpy(buf, "n/a", sizeof(buf));
922    
923 michael 1219 if (MyClient(source_p) && HasUMode(source_p, UMODE_OPER))
924 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
925 michael 3573 "p :[%c][%s] %s (%s@%s) Idle: %s",
926     HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O',
927 michael 4588 oper_privs_as_string(target_p->connection->operflags),
928 michael 3573 target_p->name, target_p->username, target_p->host, buf);
929 adx 30 else
930 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
931 michael 3573 "p :[%c] %s (%s@%s) Idle: %s",
932     HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O',
933     target_p->name, target_p->username, target_p->host, buf);
934 michael 3511 ++opercount;
935 adx 30 }
936    
937 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
938 michael 3573 "p :%u OPER(s)", opercount);
939 adx 30 }
940    
941     static void
942 michael 1457 stats_ports(struct Client *source_p, int parc, char *parv[])
943 adx 30 {
944 michael 4340 if (!HasUMode(source_p, UMODE_OPER) && ConfigGeneral.stats_P_oper_only)
945 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
946 adx 30 else
947     show_ports(source_p);
948     }
949    
950     static void
951 michael 1457 stats_resv(struct Client *source_p, int parc, char *parv[])
952 adx 30 {
953     report_resv(source_p);
954     }
955    
956     static void
957 michael 1457 stats_service(struct Client *source_p, int parc, char *parv[])
958 adx 30 {
959 michael 1632 report_confitem_types(source_p, CONF_SERVICE);
960 michael 1175 }
961    
962     static void
963 michael 1457 stats_tstats(struct Client *source_p, int parc, char *parv[])
964 adx 30 {
965 michael 4815 const dlink_node *node = NULL;
966 michael 896 struct ServerStatistics tmp;
967 michael 1842 struct ServerStatistics *sp = &tmp;
968 michael 896
969     memcpy(sp, &ServerStats, sizeof(struct ServerStatistics));
970    
971     /*
972     * must use the += operator. is_sv is not the number of currently
973     * active server connections. Note the incrementation in
974     * s_bsd.c:close_connection.
975     */
976 michael 4213 sp->is_sv += dlink_list_length(&local_server_list);
977 michael 896
978 michael 4815 DLINK_FOREACH(node, local_server_list.head)
979 michael 896 {
980 michael 4815 const struct Client *target_p = node->data;
981 michael 896
982 michael 4588 sp->is_sbs += target_p->connection->send.bytes;
983     sp->is_sbr += target_p->connection->recv.bytes;
984     sp->is_sti += CurrentTime - target_p->connection->firsttime;
985 michael 896 }
986    
987     sp->is_cl += dlink_list_length(&local_client_list);
988    
989 michael 4815 DLINK_FOREACH(node, local_client_list.head)
990 michael 896 {
991 michael 4815 const struct Client *target_p = node->data;
992 michael 896
993 michael 4588 sp->is_cbs += target_p->connection->send.bytes;
994     sp->is_cbr += target_p->connection->recv.bytes;
995     sp->is_cti += CurrentTime - target_p->connection->firsttime;
996 michael 896 }
997    
998     sp->is_ni += dlink_list_length(&unknown_list);
999    
1000 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1001 michael 4040 "t :accepts %u refused %u",
1002 michael 3573 sp->is_ac, sp->is_ref);
1003 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1004 michael 4040 "t :unknown commands %u prefixes %u",
1005 michael 3573 sp->is_unco, sp->is_unpf);
1006 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1007 michael 4040 "t :nick collisions %u unknown closes %u",
1008 michael 3573 sp->is_kill, sp->is_ni);
1009 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1010 michael 4040 "t :wrong direction %u empty %u",
1011 michael 3573 sp->is_wrdi, sp->is_empt);
1012 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1013 michael 4040 "t :numerics seen %u",
1014 michael 3573 sp->is_num);
1015 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1016 michael 4040 "t :auth successes %u fails %u",
1017 michael 3573 sp->is_asuc, sp->is_abad);
1018 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1019 michael 4040 "t :Client Server");
1020 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1021 michael 4040 "t :connected %u %u",
1022 michael 3573 (unsigned int)sp->is_cl,
1023     (unsigned int)sp->is_sv);
1024 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1025 michael 4040 "t :bytes sent %llu %llu",
1026 michael 3573 sp->is_cbs, sp->is_sbs);
1027 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1028 michael 4040 "t :bytes recv %llu %llu",
1029 michael 3573 sp->is_cbr, sp->is_sbr);
1030 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1031 michael 4040 "t :time connected %u %u",
1032 michael 3573 (unsigned int)sp->is_cti,
1033     (unsigned int)sp->is_sti);
1034 adx 30 }
1035    
1036     static void
1037 michael 1457 stats_uptime(struct Client *source_p, int parc, char *parv[])
1038 adx 30 {
1039 michael 4340 if (!HasUMode(source_p, UMODE_OPER) && ConfigGeneral.stats_u_oper_only)
1040 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
1041 michael 2269 else
1042     {
1043 michael 4588 time_t now = CurrentTime - me.connection->since;
1044 michael 1148
1045 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSUPTIME, now / 86400,
1046     (now / 3600) % 24, (now / 60) % 60, now % 60);
1047 michael 1148
1048 michael 2269 if (!ConfigServerHide.disable_remote_commands || HasUMode(source_p, UMODE_OPER))
1049 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSCONN, Count.max_loc_con,
1050     Count.max_loc_cli, Count.totalrestartcount);
1051 michael 2269 }
1052 adx 30 }
1053    
1054     static void
1055 michael 1457 stats_shared(struct Client *source_p, int parc, char *parv[])
1056 adx 30 {
1057 michael 1632 report_confitem_types(source_p, CONF_ULINE);
1058 adx 30 }
1059    
1060     /* stats_servers()
1061     *
1062     * input - client pointer
1063     * output - none
1064     * side effects - client is shown lists of who connected servers
1065     */
1066     static void
1067 michael 1457 stats_servers(struct Client *source_p, int parc, char *parv[])
1068 adx 30 {
1069 michael 4815 const dlink_node *node = NULL;
1070 adx 30
1071 michael 4815 DLINK_FOREACH(node, local_server_list.head)
1072 adx 30 {
1073 michael 4815 const struct Client *target_p = node->data;
1074 adx 30
1075 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1076 michael 3573 "v :%s (%s!%s@%s) Idle: %d",
1077     target_p->name,
1078     (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
1079 michael 4588 "*", "*", (int)(CurrentTime - target_p->connection->lasttime));
1080 adx 30 }
1081    
1082 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1083 michael 4213 "v :%u Server(s)",
1084     dlink_list_length(&local_server_list));
1085 adx 30 }
1086    
1087     static void
1088 michael 1457 stats_gecos(struct Client *source_p, int parc, char *parv[])
1089 adx 30 {
1090 michael 1632 report_confitem_types(source_p, CONF_XLINE);
1091 adx 30 }
1092    
1093     static void
1094 michael 1457 stats_class(struct Client *source_p, int parc, char *parv[])
1095 adx 30 {
1096 michael 4815 const dlink_node *node = NULL;
1097 michael 2116
1098 michael 4815 DLINK_FOREACH(node, class_get_list()->head)
1099 michael 2116 {
1100 michael 4815 const struct ClassItem *class = node->data;
1101 michael 2116
1102 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSYLINE, 'Y',
1103     class->name, class->ping_freq,
1104     class->con_freq,
1105     class->max_total, class->max_sendq,
1106     class->max_recvq,
1107     class->ref_count,
1108     class->number_per_cidr, class->cidr_bitlen_ipv4,
1109     class->number_per_cidr, class->cidr_bitlen_ipv6,
1110     class->active ? "active" : "disabled");
1111 michael 2116 }
1112 adx 30 }
1113    
1114     static void
1115 michael 1457 stats_servlinks(struct Client *source_p, int parc, char *parv[])
1116 adx 30 {
1117     uint64_t sendB = 0, recvB = 0;
1118     time_t uptime = 0;
1119 michael 4815 dlink_node *node = NULL;
1120 adx 30
1121 michael 1219 if (ConfigServerHide.flatten_links && !HasUMode(source_p, UMODE_OPER))
1122 adx 30 {
1123 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
1124 adx 30 return;
1125     }
1126    
1127 michael 4815 DLINK_FOREACH(node, local_server_list.head)
1128 adx 30 {
1129 michael 4815 struct Client *target_p = node->data;
1130 adx 30
1131 michael 1851 if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
1132     if (!HasUMode(source_p, UMODE_OPER))
1133     continue;
1134    
1135 michael 4588 sendB += target_p->connection->send.bytes;
1136     recvB += target_p->connection->recv.bytes;
1137 adx 30
1138     /* ":%s 211 %s %s %u %u %llu %u %llu :%u %u %s" */
1139 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSLINKINFO,
1140 michael 1219 get_client_name(target_p, HasUMode(source_p, UMODE_ADMIN) ? SHOW_IP : MASK_IP),
1141 michael 4588 dbuf_length(&target_p->connection->buf_sendq),
1142     target_p->connection->send.messages,
1143     target_p->connection->send.bytes >> 10,
1144     target_p->connection->recv.messages,
1145     target_p->connection->recv.bytes >> 10,
1146 michael 5531 (unsigned int)(CurrentTime - target_p->connection->firsttime),
1147     (CurrentTime > target_p->connection->since) ? (unsigned int)(CurrentTime - target_p->connection->since) : 0,
1148 michael 1219 HasUMode(source_p, UMODE_OPER) ? show_capabilities(target_p) : "TS");
1149 adx 30 }
1150    
1151     sendB >>= 10;
1152     recvB >>= 10;
1153    
1154 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, "? :%u total server(s)",
1155 michael 4213 dlink_list_length(&local_server_list));
1156 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, "? :Sent total: %7.2f %s",
1157 michael 3573 _GMKv(sendB), _GMKs(sendB));
1158 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, "? :Recv total: %7.2f %s",
1159 michael 3573 _GMKv(recvB), _GMKs(recvB));
1160 adx 30
1161 michael 4588 uptime = (CurrentTime - me.connection->since);
1162 adx 30
1163 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1164 michael 3573 "? :Server send: %7.2f %s (%4.1f K/s)",
1165 michael 4588 _GMKv((me.connection->send.bytes>>10)),
1166     _GMKs((me.connection->send.bytes>>10)),
1167     (float)((float)((me.connection->send.bytes) >> 10) /
1168 michael 3573 (float)uptime));
1169 michael 5583 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1170 michael 3573 "? :Server recv: %7.2f %s (%4.1f K/s)",
1171 michael 4588 _GMKv((me.connection->recv.bytes>>10)),
1172     _GMKs((me.connection->recv.bytes>>10)),
1173     (float)((float)((me.connection->recv.bytes) >> 10) /
1174 michael 3573 (float)uptime));
1175 adx 30 }
1176    
1177 michael 1457 /* parse_stats_args()
1178     *
1179     * inputs - arg count
1180     * - args
1181     * - doall flag
1182     * - wild card or not
1183     * output - pointer to name to use
1184     * side effects -
1185     * common parse routine for m_stats args
1186 michael 2820 *
1187 michael 1457 */
1188 michael 4755 static const char *
1189 michael 3114 parse_stats_args(struct Client *source_p, int parc, char *parv[], int *doall, int *wilds)
1190 adx 30 {
1191 michael 1457 if (parc > 2)
1192 adx 30 {
1193 michael 4755 const char *name = parv[2];
1194 adx 30
1195 michael 3114 if (!irccmp(name, ID_or_name(&me, source_p)))
1196 michael 1457 *doall = 2;
1197 michael 3114 else if (!match(name, ID_or_name(&me, source_p)))
1198 michael 1457 *doall = 1;
1199    
1200     *wilds = has_wildcards(name);
1201    
1202     return name;
1203 adx 30 }
1204    
1205 michael 1457 return NULL;
1206 adx 30 }
1207    
1208     static void
1209 michael 4755 stats_L_list(struct Client *source_p, const char *name, int doall, int wilds,
1210     dlink_list *list, const char statchar)
1211 adx 30 {
1212 michael 4815 dlink_node *node = NULL;
1213 adx 30
1214     /*
1215 michael 4034 * Send info about connections which match, or all if the
1216     * mask matches from. Only restrictions are on those who
1217 adx 30 * are invisible not being visible to 'foreigners' who use
1218     * a wild card based search to list it.
1219     */
1220 michael 4815 DLINK_FOREACH(node, list->head)
1221 adx 30 {
1222 michael 4815 struct Client *target_p = node->data;
1223 adx 30
1224 michael 1219 if (HasUMode(target_p, UMODE_INVISIBLE) && (doall || wilds) &&
1225 michael 1457 !(MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) &&
1226     !HasUMode(target_p, UMODE_OPER) && (target_p != source_p))
1227 adx 30 continue;
1228 michael 4034
1229 michael 1652 if (!doall && wilds && match(name, target_p->name))
1230 adx 30 continue;
1231 michael 4034
1232 adx 30 if (!(doall || wilds) && irccmp(name, target_p->name))
1233     continue;
1234    
1235 michael 4034 /*
1236     * This basically shows ips for our opers if it's not a server/admin, or
1237 michael 4298 * it's one of our admins.
1238 michael 4034 */
1239 michael 3655 if (MyClient(source_p) && HasUMode(source_p, UMODE_OPER) &&
1240     (HasUMode(source_p, UMODE_ADMIN) ||
1241     (!IsServer(target_p) && !HasUMode(target_p, UMODE_ADMIN) &&
1242     !IsHandshake(target_p) && !IsConnecting(target_p))))
1243 adx 30 {
1244 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSLINKINFO,
1245 adx 30 (IsUpper(statchar)) ?
1246     get_client_name(target_p, SHOW_IP) :
1247     get_client_name(target_p, HIDE_IP),
1248 michael 4588 dbuf_length(&target_p->connection->buf_sendq),
1249     target_p->connection->send.messages,
1250     target_p->connection->send.bytes>>10,
1251     target_p->connection->recv.messages,
1252     target_p->connection->recv.bytes>>10,
1253 michael 5531 (unsigned int)(CurrentTime - target_p->connection->firsttime),
1254     (CurrentTime > target_p->connection->since) ? (unsigned int)(CurrentTime - target_p->connection->since) : 0,
1255 adx 30 IsServer(target_p) ? show_capabilities(target_p) : "-");
1256     }
1257     else
1258     {
1259 michael 4967 /* If it's a server, mask the real IP */
1260     if (IsServer(target_p) || IsHandshake(target_p) || IsConnecting(target_p))
1261 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSLINKINFO,
1262 michael 1457 get_client_name(target_p, MASK_IP),
1263 michael 4588 dbuf_length(&target_p->connection->buf_sendq),
1264     target_p->connection->send.messages,
1265     target_p->connection->send.bytes>>10,
1266     target_p->connection->recv.messages,
1267     target_p->connection->recv.bytes>>10,
1268 michael 5531 (unsigned int)(CurrentTime - target_p->connection->firsttime),
1269     (CurrentTime > target_p->connection->since) ? (unsigned int)(CurrentTime - target_p->connection->since):0,
1270 michael 1457 IsServer(target_p) ? show_capabilities(target_p) : "-");
1271 adx 30 else /* show the real IP */
1272 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSLINKINFO,
1273 michael 1457 (IsUpper(statchar)) ?
1274     get_client_name(target_p, SHOW_IP) :
1275     get_client_name(target_p, HIDE_IP),
1276 michael 4588 dbuf_length(&target_p->connection->buf_sendq),
1277     target_p->connection->send.messages,
1278     target_p->connection->send.bytes>>10,
1279     target_p->connection->recv.messages,
1280     target_p->connection->recv.bytes>>10,
1281 michael 5531 (unsigned int)(CurrentTime - target_p->connection->firsttime),
1282     (CurrentTime > target_p->connection->since) ? (unsigned int)(CurrentTime - target_p->connection->since):0,
1283 michael 1457 IsServer(target_p) ? show_capabilities(target_p) : "-");
1284 adx 30 }
1285     }
1286     }
1287    
1288 michael 1457 /*
1289     * stats_L
1290 adx 30 *
1291 michael 1457 * inputs - pointer to client to report to
1292     * - doall flag
1293     * - wild card or not
1294     * output - NONE
1295     * side effects -
1296     */
1297     static void
1298 michael 4755 stats_L(struct Client *source_p, const char *name, int doall,
1299     int wilds, const char statchar)
1300 michael 1457 {
1301     stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar);
1302     stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar);
1303 michael 4213 stats_L_list(source_p, name, doall, wilds, &local_server_list, statchar);
1304 michael 1457 }
1305    
1306     static void
1307     stats_ltrace(struct Client *source_p, int parc, char *parv[])
1308     {
1309     int doall = 0;
1310     int wilds = 0;
1311 michael 4755 const char *name = NULL;
1312 michael 1457
1313 michael 3246 if ((name = parse_stats_args(source_p, parc, parv, &doall, &wilds)))
1314 michael 1457 {
1315 michael 4755 const char statchar = *parv[1];
1316 michael 1457 stats_L(source_p, name, doall, wilds, statchar);
1317     }
1318     else
1319 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "STATS");
1320 michael 1457 }
1321    
1322     static const struct StatsStruct
1323     {
1324     const unsigned char letter;
1325 michael 4479 void (*handler)(struct Client *, int, char *[]);
1326 michael 1457 const unsigned int need_oper;
1327     const unsigned int need_admin;
1328     } stats_cmd_table[] = {
1329 michael 4034 /* letter function need_oper need_admin */
1330     { 'a', stats_dns_servers, 1, 1 },
1331     { 'A', stats_dns_servers, 1, 1 },
1332     { 'c', stats_connect, 1, 0 },
1333     { 'C', stats_connect, 1, 0 },
1334     { 'd', stats_tdeny, 1, 0 },
1335     { 'D', stats_deny, 1, 0 },
1336     { 'e', stats_exempt, 1, 0 },
1337     { 'E', stats_events, 1, 1 },
1338     { 'f', fd_dump, 1, 1 },
1339     { 'F', fd_dump, 1, 1 },
1340 michael 4142 { 'h', stats_hubleaf, 1, 1 },
1341 michael 4034 { 'H', stats_hubleaf, 1, 0 },
1342     { 'i', stats_auth, 0, 0 },
1343     { 'I', stats_auth, 0, 0 },
1344     { 'k', stats_tklines, 0, 0 },
1345     { 'K', stats_klines, 0, 0 },
1346     { 'l', stats_ltrace, 1, 0 },
1347     { 'L', stats_ltrace, 1, 0 },
1348     { 'm', stats_messages, 0, 0 },
1349     { 'M', stats_messages, 0, 0 },
1350     { 'o', stats_oper, 0, 0 },
1351     { 'O', stats_oper, 0, 0 },
1352     { 'p', stats_operedup, 0, 0 },
1353     { 'P', stats_ports, 0, 0 },
1354     { 'q', stats_resv, 1, 0 },
1355     { 'Q', stats_resv, 1, 0 },
1356     { 'r', stats_usage, 1, 0 },
1357     { 'R', stats_usage, 1, 0 },
1358     { 's', stats_service, 1, 0 },
1359     { 'S', stats_service, 1, 0 },
1360     { 't', stats_tstats, 1, 0 },
1361     { 'T', motd_report, 1, 0 },
1362     { 'u', stats_uptime, 0, 0 },
1363     { 'U', stats_shared, 1, 0 },
1364     { 'v', stats_servers, 1, 0 },
1365     { 'x', stats_gecos, 1, 0 },
1366     { 'X', stats_gecos, 1, 0 },
1367     { 'y', stats_class, 1, 0 },
1368     { 'Y', stats_class, 1, 0 },
1369     { 'z', stats_memory, 1, 0 },
1370     { '?', stats_servlinks, 0, 0 },
1371     { '\0', NULL, 0, 0 }
1372 michael 1457 };
1373    
1374     static void
1375     do_stats(struct Client *source_p, int parc, char *parv[])
1376     {
1377     const char statchar = *parv[1];
1378    
1379     if (statchar == '\0')
1380     {
1381 michael 3109 sendto_one_numeric(source_p, &me, RPL_ENDOFSTATS, '*');
1382 michael 1457 return;
1383     }
1384    
1385 michael 3283 for (const struct StatsStruct *tab = stats_cmd_table; tab->handler; ++tab)
1386 michael 1457 {
1387     if (tab->letter == statchar)
1388     {
1389     /* The stats table says what privs are needed, so check --fl_ */
1390     if ((tab->need_admin && !HasUMode(source_p, UMODE_ADMIN)) ||
1391     (tab->need_oper && !HasUMode(source_p, UMODE_OPER)))
1392     {
1393 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
1394 michael 1457 break;
1395     }
1396    
1397 michael 1618 sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE,
1398 michael 1532 "STATS %c requested by %s (%s@%s) [%s]",
1399 michael 1457 statchar, source_p->name, source_p->username,
1400     source_p->host, source_p->servptr->name);
1401     tab->handler(source_p, parc, parv);
1402     break;
1403     }
1404     }
1405    
1406 michael 3109 sendto_one_numeric(source_p, &me, RPL_ENDOFSTATS, statchar);
1407 michael 1457 }
1408    
1409     /*
1410     * m_stats()
1411 michael 3096 * parv[0] = command
1412 michael 1457 * parv[1] = stat letter/command
1413     * parv[2] = (if present) server/mask in stats L
1414 adx 30 */
1415 michael 2820 static int
1416 michael 3156 m_stats(struct Client *source_p, int parc, char *parv[])
1417 adx 30 {
1418 michael 1457 static time_t last_used = 0;
1419 adx 30
1420 michael 4298 /* Check the user is actually allowed to do /stats, and isn't flooding */
1421 michael 4340 if ((last_used + ConfigGeneral.pace_wait) > CurrentTime)
1422 michael 1457 {
1423 michael 4759 sendto_one_numeric(source_p, &me, RPL_LOAD2HI, "STATS");
1424 michael 2820 return 0;
1425 michael 1457 }
1426 adx 30
1427 michael 1457 last_used = CurrentTime;
1428 adx 30
1429 michael 2341 /* Is the stats meant for us? */
1430     if (!ConfigServerHide.disable_remote_commands)
1431 michael 4034 if (hunt_server(source_p, ":%s STATS %s :%s", 2, parc, parv) != HUNTED_ISME)
1432 michael 2820 return 0;
1433 michael 2341
1434 michael 1457 do_stats(source_p, parc, parv);
1435 michael 2820 return 0;
1436 michael 1457 }
1437    
1438     /*
1439 michael 3219 * ms_stats()
1440 michael 3096 * parv[0] = command
1441 michael 1457 * parv[1] = stat letter/command
1442     * parv[2] = (if present) server/mask in stats L, or target
1443     */
1444 michael 2820 static int
1445 michael 3219 ms_stats(struct Client *source_p, int parc, char *parv[])
1446 michael 1457 {
1447 michael 4034 if (hunt_server(source_p, ":%s STATS %s :%s", 2, parc, parv) != HUNTED_ISME)
1448 michael 2820 return 0;
1449 michael 1457
1450     do_stats(source_p, parc, parv);
1451 michael 2820 return 0;
1452 adx 30 }
1453 michael 1230
1454 michael 2820 static struct Message stats_msgtab =
1455     {
1456 michael 4545 "STATS", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
1457 michael 3219 { m_unregistered, m_stats, ms_stats, m_ignore, ms_stats, m_ignore }
1458 michael 1230 };
1459    
1460     static void
1461     module_init(void)
1462     {
1463     mod_add_cmd(&stats_msgtab);
1464     }
1465    
1466     static void
1467     module_exit(void)
1468     {
1469     mod_del_cmd(&stats_msgtab);
1470     }
1471    
1472 michael 2820 struct module module_entry =
1473     {
1474 michael 1230 .version = "$Revision$",
1475     .modinit = module_init,
1476     .modexit = module_exit,
1477     };

Properties

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