ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 7218
Committed: Wed Feb 3 15:29:38 2016 UTC (8 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 50015 byte(s)
Log Message:
- m_stats.c: renamings & constifications

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

Properties

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