ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_stats.c
Revision: 9313
Committed: Sun Mar 8 11:33:45 2020 UTC (5 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 45780 byte(s)
Log Message:
- m_stats.c:stats_operedup(): reduce size of 'buf' to 32

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 9102 * Copyright (c) 1997-2020 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 4564 * 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 8457 #include "parse.h"
34 michael 1632 #include "conf.h"
35 michael 1644 #include "conf_class.h"
36 michael 7208 #include "conf_cluster.h"
37 michael 7303 #include "conf_gecos.h"
38 michael 8452 #include "conf_pseudo.h"
39 michael 7235 #include "conf_resv.h"
40 michael 7247 #include "conf_service.h"
41 michael 7208 #include "conf_shared.h"
42 adx 30 #include "hostmask.h"
43 michael 2820 #include "numeric.h"
44     #include "send.h"
45     #include "fdlist.h"
46 michael 3347 #include "misc.h"
47     #include "server.h"
48 michael 8165 #include "server_capab.h"
49 michael 2820 #include "event.h"
50 adx 30 #include "modules.h"
51     #include "whowas.h"
52 michael 884 #include "watch.h"
53 michael 6834 #include "reslib.h"
54 michael 2150 #include "motd.h"
55 michael 4326 #include "ipcache.h"
56 michael 9233 #include "channel.h"
57 michael 9266 #include "channel_invite.h"
58 adx 30
59    
60 michael 8970 static const char *
61     oper_privs_as_string(const unsigned int flags)
62     {
63     static const struct oper_flags
64     {
65     unsigned int flag;
66     unsigned char letter;
67     } flag_table[] = {
68     { OPER_FLAG_ADMIN, 'A' },
69     { OPER_FLAG_CLOSE, 'B' },
70     { OPER_FLAG_CONNECT, 'C' },
71     { OPER_FLAG_CONNECT_REMOTE, 'D' },
72     { OPER_FLAG_DIE, 'E' },
73     { OPER_FLAG_DLINE, 'F' },
74     { OPER_FLAG_GLOBOPS, 'G' },
75     { OPER_FLAG_JOIN_RESV, 'H' },
76     { OPER_FLAG_KILL, 'I' },
77     { OPER_FLAG_KILL_REMOTE, 'J' },
78     { OPER_FLAG_KLINE, 'K' },
79     { OPER_FLAG_LOCOPS, 'L' },
80     { OPER_FLAG_MODULE, 'M' },
81     { OPER_FLAG_NICK_RESV, 'N' },
82     { OPER_FLAG_OPME, 'O' },
83     { OPER_FLAG_REHASH, 'P' },
84     { OPER_FLAG_REMOTEBAN, 'Q' },
85     { OPER_FLAG_RESTART, 'R' },
86     { OPER_FLAG_RESV, 'S' },
87     { OPER_FLAG_SET, 'T' },
88     { OPER_FLAG_SQUIT, 'U' },
89     { OPER_FLAG_SQUIT_REMOTE, 'V' },
90     { OPER_FLAG_UNDLINE, 'W' },
91     { OPER_FLAG_UNKLINE, 'X' },
92     { OPER_FLAG_UNRESV, 'Y' },
93     { OPER_FLAG_UNXLINE, 'Z' },
94     { OPER_FLAG_WALLOPS, 'a' },
95     { OPER_FLAG_XLINE, 'b' },
96     { 0, '\0' }
97     };
98    
99     static char buf[sizeof(flag_table) / sizeof(flag_table[0])];
100     char *p = buf;
101    
102     for (const struct oper_flags *tab = flag_table; tab->flag; ++tab)
103     if (flags & tab->flag)
104     *p++ = tab->letter;
105    
106     if (p == buf)
107     *p++ = '0';
108    
109     *p = '\0';
110    
111     return buf;
112     }
113    
114 michael 7208 static void
115     report_shared(struct Client *source_p)
116 michael 1922 {
117 michael 7219 static const struct shared_types
118 michael 7208 {
119     unsigned int type;
120     unsigned char letter;
121     } flag_table[] = {
122     { SHARED_KLINE, 'K' },
123     { SHARED_UNKLINE, 'U' },
124     { SHARED_XLINE, 'X' },
125     { SHARED_UNXLINE, 'Y' },
126     { SHARED_RESV, 'Q' },
127     { SHARED_UNRESV, 'R' },
128     { SHARED_LOCOPS, 'L' },
129     { SHARED_DLINE, 'D' },
130     { SHARED_UNDLINE, 'E' },
131     { 0, '\0' }
132     };
133 michael 1922
134 michael 7208 dlink_node *node;
135 michael 8309 char buf[sizeof(flag_table) / sizeof(flag_table[0]) + 1]; /* +1 for 'c' */
136 michael 7208
137     DLINK_FOREACH(node, shared_get_list()->head)
138     {
139 michael 7219 const struct SharedItem *shared = node->data;
140 michael 7208 char *p = buf;
141    
142     *p++ = 'c';
143    
144 michael 7219 for (const struct shared_types *tab = flag_table; tab->type; ++tab)
145     if (tab->type & shared->type)
146     *p++ = tab->letter;
147 michael 7208 else
148 michael 7219 *p++ = ToLower(tab->letter);
149 michael 7208
150     *p = '\0';
151    
152 michael 7219 sendto_one_numeric(source_p, &me, RPL_STATSULINE, shared->server,
153     shared->user, shared->host, buf);
154 michael 7208 }
155     }
156    
157     static void
158     report_cluster(struct Client *source_p)
159     {
160 michael 7219 static const struct cluster_types
161 michael 7208 {
162     unsigned int type;
163     unsigned char letter;
164     } flag_table[] = {
165     { CLUSTER_KLINE, 'K' },
166     { CLUSTER_UNKLINE, 'U' },
167     { CLUSTER_XLINE, 'X' },
168     { CLUSTER_UNXLINE, 'Y' },
169     { CLUSTER_RESV, 'Q' },
170     { CLUSTER_UNRESV, 'R' },
171     { CLUSTER_LOCOPS, 'L' },
172     { CLUSTER_DLINE, 'D' },
173     { CLUSTER_UNDLINE, 'E' },
174     { 0, '\0' }
175     };
176    
177     dlink_node *node;
178 michael 8309 char buf[sizeof(flag_table) / sizeof(flag_table[0]) + 1]; /* +1 for 'C' */
179 michael 7208
180     DLINK_FOREACH(node, cluster_get_list()->head)
181     {
182 michael 7219 const struct ClusterItem *cluster = node->data;
183 michael 7208 char *p = buf;
184    
185     *p++ = 'C';
186    
187 michael 7219 for (const struct cluster_types *tab = flag_table; tab->type; ++tab)
188     if (tab->type & cluster->type)
189     *p++ = tab->letter;
190 michael 7208 else
191 michael 7219 *p++ = ToLower(tab->letter);
192 michael 7208
193     *p = '\0';
194    
195 michael 7219 sendto_one_numeric(source_p, &me, RPL_STATSULINE, cluster->server,
196 michael 7208 "*", "*", buf);
197     }
198     }
199    
200 michael 7247 static void
201 michael 7396 stats_service(struct Client *source_p, int parc, char *parv[])
202 michael 7247 {
203     dlink_node *node;
204    
205     DLINK_FOREACH(node, service_get_list()->head)
206     {
207     const struct ServiceItem *service = node->data;
208 michael 8490 sendto_one_numeric(source_p, &me, RPL_STATSSERVICE, "*", service->name, 0, 0);
209 michael 7247 }
210     }
211    
212 michael 7303 static void
213 michael 7396 stats_gecos(struct Client *source_p, int parc, char *parv[])
214 michael 7303 {
215     dlink_node *node;
216    
217     DLINK_FOREACH(node, gecos_get_list()->head)
218     {
219     const struct GecosItem *gecos = node->data;
220     sendto_one_numeric(source_p, &me, RPL_STATSXLINE,
221 michael 7314 gecos->expire ? 'x' : 'X',
222 michael 7303 gecos->mask, gecos->reason);
223     }
224     }
225    
226 adx 30 /*
227 michael 1922 * inputs - pointer to client requesting confitem report
228     * - ConfType to report
229     * output - none
230     * side effects -
231     */
232     static void
233 michael 7404 stats_operator(struct Client *source_p, int parc, char *parv[])
234 michael 1922 {
235 michael 7404 dlink_node *node;
236 michael 1922
237 michael 7404 if (!HasUMode(source_p, UMODE_OPER) && ConfigGeneral.stats_o_oper_only)
238 michael 1922 {
239 michael 7404 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
240     return;
241     }
242 michael 1922
243 michael 7404 DLINK_FOREACH(node, operator_items.head)
244     {
245     const struct MaskItem *conf = node->data;
246 michael 1922
247 michael 7404 /* Don't allow non opers to see oper privs */
248     if (HasUMode(source_p, UMODE_OPER))
249     sendto_one_numeric(source_p, &me, RPL_STATSOLINE, 'O', conf->user, conf->host,
250     conf->name, oper_privs_as_string(conf->port),
251     conf->class->name);
252     else
253     sendto_one_numeric(source_p, &me, RPL_STATSOLINE, 'O', conf->user, conf->host,
254     conf->name, "0", conf->class->name);
255     }
256     }
257 michael 1922
258 michael 7404 static void
259     stats_connect(struct Client *source_p, int parc, char *parv[])
260     {
261     dlink_node *node;
262 michael 1922
263 michael 7404 DLINK_FOREACH(node, connect_items.head)
264     {
265     char buf[8];
266     char *p = buf;
267     const struct MaskItem *conf = node->data;
268 michael 1922
269 michael 7404 if (IsConfAllowAutoConn(conf))
270     *p++ = 'A';
271 michael 9156 if (IsConfTLS(conf))
272 michael 7404 *p++ = 'S';
273     if (p == buf)
274     *p++ = '*';
275 michael 4035
276 michael 7404 *p = '\0';
277 michael 4035
278 michael 7404 /*
279 michael 8058 * Allow admins to see actual ips unless 'hide_server_ips' is enabled
280 michael 7404 */
281 michael 8604 if (ConfigServerHide.hide_server_ips == 0 && HasUMode(source_p, UMODE_ADMIN))
282 michael 7404 sendto_one_numeric(source_p, &me, RPL_STATSCLINE, 'C', conf->host,
283 michael 8058 buf, conf->name, conf->port, conf->class->name);
284 michael 7404 else
285 michael 8058 sendto_one_numeric(source_p, &me, RPL_STATSCLINE, 'C', "*@127.0.0.1",
286     buf, conf->name, conf->port, conf->class->name);
287 michael 1922 }
288     }
289    
290 michael 1927 /* report_resv()
291     *
292     * inputs - pointer to client pointer to report to.
293     * output - NONE
294     * side effects - report all resvs to client.
295     */
296     static void
297 michael 7396 stats_resv(struct Client *source_p, int parc, char *parv[])
298 michael 1927 {
299 michael 7686 dlink_node *node;
300 michael 1927
301 michael 7281 DLINK_FOREACH(node, resv_chan_get_list()->head)
302 michael 1927 {
303 michael 7281 const struct ResvItem *resv = node->data;
304 michael 3109
305     sendto_one_numeric(source_p, &me, RPL_STATSQLINE,
306 michael 7281 resv->expire ? 'q' : 'Q',
307     resv->mask, resv->reason);
308 michael 1927 }
309    
310 michael 7281 DLINK_FOREACH(node, resv_nick_get_list()->head)
311 michael 1927 {
312 michael 7281 const struct ResvItem *resv = node->data;
313 michael 3109
314     sendto_one_numeric(source_p, &me, RPL_STATSQLINE,
315 michael 7281 resv->expire ? 'q' : 'Q',
316     resv->mask, resv->reason);
317 michael 1927 }
318     }
319    
320 adx 30 static void
321 michael 1457 stats_memory(struct Client *source_p, int parc, char *parv[])
322 adx 30 {
323 michael 7686 dlink_node *node, *node2;
324 adx 30
325 michael 948 unsigned int local_client_conf_count = 0; /* local client conf links */
326 adx 30
327 michael 1017 unsigned int channel_members = 0;
328 michael 948 unsigned int channel_invites = 0;
329     unsigned int channel_bans = 0;
330     unsigned int channel_except = 0;
331     unsigned int channel_invex = 0;
332 adx 30
333 michael 948 unsigned int wwu = 0; /* whowas users */
334 michael 4330 unsigned int number_ips_stored = 0; /* number of ip addresses hashed */
335 adx 30
336 michael 6718 size_t channel_ban_memory = 0;
337     size_t channel_except_memory = 0;
338     size_t channel_invex_memory = 0;
339 adx 30
340     unsigned int safelist_count = 0;
341 michael 6718 size_t safelist_memory = 0;
342 adx 30
343 michael 6718 size_t wwm = 0; /* whowas array memory used */
344     size_t mem_ips_stored = 0; /* memory used by ip address hash */
345 adx 30
346     unsigned int local_client_count = 0;
347     unsigned int remote_client_count = 0;
348    
349 michael 6718 size_t local_client_memory_used = 0;
350     size_t remote_client_memory_used = 0;
351 adx 30
352 michael 1017 unsigned int watch_list_headers = 0; /* watchlist headers */
353     unsigned int watch_list_entries = 0; /* watchlist entries */
354 michael 6718 size_t watch_list_memory = 0; /* watchlist memory used */
355 michael 884
356 michael 7350 unsigned int listener_count = 0;
357     size_t listener_memory = 0;
358 adx 30
359 michael 7350
360 michael 7982 DLINK_FOREACH(node, local_server_list.head)
361 michael 7962 {
362     const struct Client *target_p = node->data;
363    
364 michael 7982 local_client_conf_count += dlink_list_length(&target_p->connection->confs);
365 michael 7962 }
366    
367 michael 7982 DLINK_FOREACH(node, local_client_list.head)
368 adx 30 {
369 michael 7432 const struct Client *target_p = node->data;
370 adx 30
371 michael 7982 local_client_conf_count += dlink_list_length(&target_p->connection->confs);
372     watch_list_entries += dlink_list_length(&target_p->connection->watches);
373 adx 30 }
374    
375 michael 7982 local_client_count = dlink_list_length(&local_server_list) + dlink_list_length(&local_client_list);
376     remote_client_count = dlink_list_length(&global_server_list) + dlink_list_length(&global_client_list) - local_client_count;
377    
378 michael 7604 /* Count up all members, invites, ban lists, except lists, Invex lists */
379 michael 8438 DLINK_FOREACH(node, channel_get_list()->head)
380 adx 30 {
381 michael 9082 const struct Channel *channel = node->data;
382 adx 30
383 michael 9082 channel_members += dlink_list_length(&channel->members);
384     channel_invites += dlink_list_length(&channel->invites);
385 adx 30
386 michael 9082 channel_bans += dlink_list_length(&channel->banlist);
387     channel_ban_memory += dlink_list_length(&channel->banlist) * sizeof(struct Ban);
388 michael 1017
389 michael 9082 channel_except += dlink_list_length(&channel->exceptlist);
390     channel_except_memory += dlink_list_length(&channel->exceptlist) * sizeof(struct Ban);
391 michael 1017
392 michael 9082 channel_invex += dlink_list_length(&channel->invexlist);
393     channel_invex_memory += dlink_list_length(&channel->invexlist) * sizeof(struct Ban);
394 adx 30 }
395    
396 michael 7470 safelist_count = dlink_list_length(&listing_client_list);
397     if (safelist_count)
398 adx 30 {
399     safelist_memory = safelist_count * sizeof(struct ListTask);
400 michael 7432
401     DLINK_FOREACH(node, listing_client_list.head)
402 adx 30 {
403 michael 7432 const struct Client *acptr = node->data;
404 adx 30
405 michael 7432 DLINK_FOREACH(node2, acptr->connection->list_task->show_mask.head)
406     safelist_memory += strlen(node2->data);
407 adx 30
408 michael 7432 DLINK_FOREACH(node2, acptr->connection->list_task->hide_mask.head)
409     safelist_memory += strlen(node2->data);
410 adx 30 }
411     }
412    
413 michael 1017 watch_count_memory(&watch_list_headers, &watch_list_memory);
414 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
415 michael 7615 "z :WATCH headers %u(%zu) entries %u(%zu)",
416 michael 3574 watch_list_headers,
417 michael 7615 watch_list_memory,
418     watch_list_entries,
419 michael 3574 watch_list_entries * sizeof(dlink_node) * 2);
420 michael 884
421 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
422 michael 7615 "z :Clients %u(%zu)",
423 michael 7962 dlink_list_length(&global_client_list),
424     dlink_list_length(&global_client_list) * sizeof(struct Client));
425 adx 30
426 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
427 michael 7980 "z :Servers %u(%zu, %zu)",
428     dlink_list_length(&global_server_list),
429     dlink_list_length(&global_server_list) * sizeof(struct Client),
430     dlink_list_length(&global_server_list) * sizeof(struct Server));
431    
432     sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
433 michael 6718 "z :Attached confs %u(%zu)",
434 michael 3574 local_client_conf_count,
435 michael 6718 local_client_conf_count * sizeof(dlink_node));
436 adx 30
437 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
438 michael 6718 "z :Resv channels %u(%zu) nicks %u(%zu)",
439 michael 7281 dlink_list_length(resv_chan_get_list()),
440     dlink_list_length(resv_chan_get_list()) * sizeof(struct ResvItem),
441     dlink_list_length(resv_nick_get_list()),
442     dlink_list_length(resv_nick_get_list()) * sizeof(struct ResvItem));
443 adx 30
444 michael 7350 listener_count_memory(&listener_count, &listener_memory);
445 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
446 michael 7466 "z :Listeners %u(%zu)",
447 michael 7350 listener_count, listener_memory);
448    
449     sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
450 michael 6718 "z :Classes %u(%zu)",
451 michael 7470 dlink_list_length(class_get_list()),
452     dlink_list_length(class_get_list()) * sizeof(struct ClassItem));
453 adx 30
454 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
455 michael 7602 "z :Channels %u(%zu)",
456 michael 8438 dlink_list_length(channel_get_list()),
457     dlink_list_length(channel_get_list()) * sizeof(struct Channel));
458 adx 30
459 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
460 michael 6718 "z :Bans %u(%zu)",
461 michael 3574 channel_bans, channel_ban_memory);
462 adx 30
463 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
464 michael 6718 "z :Exceptions %u(%zu)",
465 michael 3574 channel_except, channel_except_memory);
466 adx 30
467 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
468 michael 6718 "z :Invex %u(%zu)",
469 michael 3574 channel_invex, channel_invex_memory);
470 adx 30
471 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
472 michael 6718 "z :Channel members %u(%zu) invites %u(%zu)",
473 michael 3574 channel_members,
474 michael 9082 channel_members * sizeof(struct ChannelMember),
475 michael 6718 channel_invites,
476 michael 7606 channel_invites * sizeof(struct Invite));
477 adx 30
478 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
479 michael 6718 "z :Safelist %u(%zu)",
480 michael 3574 safelist_count, safelist_memory);
481 adx 30
482 michael 7436 whowas_count_memory(&wwu, &wwm);
483 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
484 michael 7436 "z :Whowas users %u(%zu)", wwu, wwm);
485 adx 30
486 michael 2150 motd_memory_count(source_p);
487 michael 7470
488 michael 4326 ipcache_get_stats(&number_ips_stored, &mem_ips_stored);
489 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
490 michael 6718 "z :iphash %u(%zu)",
491 michael 3574 number_ips_stored, mem_ips_stored);
492 adx 30
493 michael 8436 local_client_memory_used = local_client_count * (sizeof(struct Client) + sizeof(struct Connection));
494 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
495 michael 6718 "z :Local client Memory in use: %u(%zu)",
496 michael 3574 local_client_count, local_client_memory_used);
497 adx 30
498     remote_client_memory_used = remote_client_count * sizeof(struct Client);
499 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
500 michael 6718 "z :Remote client Memory in use: %u(%zu)",
501 michael 3574 remote_client_count, remote_client_memory_used);
502 adx 30 }
503    
504     static void
505 michael 4478 stats_dns_servers(struct Client *source_p, int parc, char *parv[])
506 adx 30 {
507 michael 9072 char ipaddr[HOSTIPLEN + 1];
508 michael 6834
509     for (unsigned int i = 0; i < irc_nscount; ++i)
510     {
511     getnameinfo((const struct sockaddr *)&(irc_nsaddr_list[i]),
512     irc_nsaddr_list[i].ss_len, ipaddr,
513     sizeof(ipaddr), NULL, 0, NI_NUMERICHOST);
514     sendto_one_numeric(source_p, &me, RPL_STATSALINE, ipaddr);
515 michael 6989 }
516 adx 30 }
517    
518     /* stats_deny()
519     *
520     * input - client to report to
521     * output - none
522     * side effects - client is given dline list.
523     */
524     static void
525 michael 1457 stats_deny(struct Client *source_p, int parc, char *parv[])
526 adx 30 {
527 michael 7686 dlink_node *node;
528 adx 30
529 michael 3246 for (unsigned int i = 0; i < ATABLE_SIZE; ++i)
530 adx 30 {
531 michael 4816 DLINK_FOREACH(node, atable[i].head)
532 adx 30 {
533 michael 4816 const struct AddressRec *arec = node->data;
534 michael 1367
535 michael 1632 if (arec->type != CONF_DLINE)
536     continue;
537 adx 30
538 michael 7470 const struct MaskItem *conf = arec->conf;
539 michael 5541 /* Don't report a temporary dline as permanent dline */
540 michael 1649 if (conf->until)
541 michael 1632 continue;
542 adx 30
543 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSDLINE, 'D', conf->host, conf->reason);
544 adx 30 }
545     }
546     }
547    
548     /* stats_tdeny()
549     *
550     * input - client to report to
551     * output - none
552     * side effects - client is given dline list.
553     */
554     static void
555 michael 1457 stats_tdeny(struct Client *source_p, int parc, char *parv[])
556 adx 30 {
557 michael 7686 dlink_node *node;
558 adx 30
559 michael 3246 for (unsigned int i = 0; i < ATABLE_SIZE; ++i)
560 adx 30 {
561 michael 4816 DLINK_FOREACH(node, atable[i].head)
562 adx 30 {
563 michael 4816 const struct AddressRec *arec = node->data;
564 michael 1367
565 michael 1632 if (arec->type != CONF_DLINE)
566     continue;
567 adx 30
568 michael 7470 const struct MaskItem *conf = arec->conf;
569 michael 5541 /* Don't report a permanent dline as temporary dline */
570 michael 8604 if (conf->until == 0)
571 michael 1632 continue;
572 adx 30
573 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSDLINE, 'd', conf->host, conf->reason);
574 adx 30 }
575     }
576     }
577    
578     /* stats_exempt()
579     *
580     * input - client to report to
581     * output - none
582     * side effects - client is given list of exempt blocks
583     */
584     static void
585 michael 1457 stats_exempt(struct Client *source_p, int parc, char *parv[])
586 adx 30 {
587 michael 7686 dlink_node *node;
588 adx 30
589 michael 4341 if (ConfigGeneral.stats_e_disabled)
590 michael 584 {
591 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
592 michael 584 return;
593     }
594    
595 michael 3246 for (unsigned int i = 0; i < ATABLE_SIZE; ++i)
596 adx 30 {
597 michael 4816 DLINK_FOREACH(node, atable[i].head)
598 adx 30 {
599 michael 4816 const struct AddressRec *arec = node->data;
600 michael 1367
601 michael 1632 if (arec->type != CONF_EXEMPT)
602     continue;
603 adx 30
604 michael 7470 const struct MaskItem *conf = arec->conf;
605 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSDLINE, 'e', conf->host, "");
606 adx 30 }
607     }
608     }
609    
610     static void
611 michael 1457 stats_events(struct Client *source_p, int parc, char *parv[])
612 adx 30 {
613 michael 7686 dlink_node *node;
614 michael 6305
615     sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
616     "E :Operation Next Execution");
617     sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
618     "E :---------------------------------------------");
619    
620     DLINK_FOREACH(node, event_get_list()->head)
621     {
622     const struct event *ev = node->data;
623    
624     sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
625 michael 8936 "E :%-30s %-4ju seconds",
626 michael 8901 ev->name, ev->next - event_base->time.sec_monotonic);
627 michael 6305 }
628 adx 30 }
629    
630     static void
631 michael 8378 stats_fdlist(struct Client *source_p, int parc, char *parv[])
632     {
633     for (int fd = 0; fd <= highest_fd; ++fd)
634     {
635     const fde_t *F = &fd_table[fd];
636    
637 michael 8657 if (F->flags.open == true)
638 michael 8378 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
639     "F :fd %-5d desc '%s'", F->fd, F->desc);
640     }
641     }
642    
643     static void
644 michael 1457 stats_hubleaf(struct Client *source_p, int parc, char *parv[])
645 adx 30 {
646 michael 7686 dlink_node *node, *node2;
647 michael 2118
648 michael 7400 DLINK_FOREACH(node, connect_items.head)
649 michael 2118 {
650 michael 4816 const struct MaskItem *conf = node->data;
651 michael 2118
652 michael 7459 DLINK_FOREACH(node2, conf->hub_list.head)
653     sendto_one_numeric(source_p, &me, RPL_STATSHLINE, 'H', node2->data, conf->name, 0, "*");
654 michael 2118 }
655    
656 michael 7400 DLINK_FOREACH(node, connect_items.head)
657 michael 2118 {
658 michael 4816 const struct MaskItem *conf = node->data;
659 michael 2118
660 michael 7459 DLINK_FOREACH(node2, conf->leaf_list.head)
661     sendto_one_numeric(source_p, &me, RPL_STATSLLINE, 'L', node2->data, conf->name, 0, "*");
662 michael 2118 }
663 adx 30 }
664    
665 michael 1372 /*
666     * show_iline_prefix()
667     *
668     * inputs - pointer to struct Client requesting output
669 michael 2820 * - pointer to struct MaskItem
670 michael 1372 * - name to which iline prefix will be prefixed to
671     * output - pointer to static string with prefixes listed in ascii form
672     * side effects - NONE
673     */
674     static const char *
675 michael 6507 show_iline_prefix(const struct Client *source_p, const struct MaskItem *conf)
676 michael 1372 {
677 michael 7459 static char buf[USERLEN + 16];
678     char *p = buf;
679 michael 1372
680 michael 1715 if (IsConfWebIRC(conf))
681 michael 7459 *p++ = '<';
682 michael 1632 if (IsNoTilde(conf))
683 michael 7459 *p++ = '-';
684 michael 1632 if (IsNeedIdentd(conf))
685 michael 7459 *p++ = '+';
686 michael 1632 if (!IsNeedPassword(conf))
687 michael 7459 *p++ = '&';
688 michael 1632 if (IsConfExemptResv(conf))
689 michael 7459 *p++ = '$';
690 michael 1632 if (IsConfDoSpoofIp(conf))
691 michael 7459 *p++ = '=';
692     if (IsConfCanFlood(conf))
693     *p++ = '|';
694 michael 6507 if (HasUMode(source_p, UMODE_OPER))
695     {
696     if (IsConfExemptKline(conf))
697 michael 7459 *p++ = '^';
698 michael 6507 if (IsConfExemptXline(conf))
699 michael 7459 *p++ = '!';
700 michael 6507 if (IsConfExemptLimits(conf))
701 michael 7459 *p++ = '>';
702 michael 6507 }
703    
704 michael 7510 strlcpy(p, conf->user, USERLEN + 1);
705 michael 7459 return buf;
706 michael 1372 }
707    
708 adx 30 static void
709 michael 3156 report_auth(struct Client *source_p, int parc, char *parv[])
710 michael 1372 {
711 michael 7686 dlink_node *node;
712 michael 1372
713 michael 3246 for (unsigned int i = 0; i < ATABLE_SIZE; ++i)
714 michael 1372 {
715 michael 4816 DLINK_FOREACH(node, atable[i].head)
716 michael 1372 {
717 michael 4816 const struct AddressRec *arec = node->data;
718 michael 1372
719 michael 1632 if (arec->type != CONF_CLIENT)
720     continue;
721 michael 1372
722 michael 7470 const struct MaskItem *conf = arec->conf;
723 michael 6507 if (!HasUMode(source_p, UMODE_OPER) && IsConfDoSpoofIp(conf))
724 michael 1632 continue;
725 michael 1372
726 michael 4968 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 4341 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 4035 /* If unopered, only return matching auth blocks */
743 michael 4341 else if (ConfigGeneral.stats_i_oper_only == 1 && !HasUMode(source_p, UMODE_OPER))
744 adx 30 {
745 michael 9072 const struct MaskItem *conf;
746 adx 30
747     if (MyConnect(source_p))
748 michael 1632 conf = find_conf_by_address(source_p->host,
749 michael 8495 &source_p->ip, CONF_CLIENT,
750 michael 2820 source_p->username,
751 michael 4589 source_p->connection->password, 1);
752 adx 30 else
753 michael 8828 conf = find_conf_by_address(source_p->host, NULL, CONF_CLIENT,
754 michael 4035 source_p->username, NULL, 1);
755 adx 30
756 michael 8604 if (conf == NULL)
757 adx 30 return;
758    
759 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSILINE,
760     'I', "*", show_iline_prefix(source_p, conf),
761     conf->host, conf->port,
762 michael 4036 conf->class->name);
763 adx 30 }
764 michael 4035 else /* They are opered, or allowed to see all auth blocks */
765 michael 1457 report_auth(source_p, 0, NULL);
766 adx 30 }
767    
768 michael 1372 /* report_Klines()
769     * Inputs: Client to report to,
770     * type(==0 for perm, !=0 for temporary)
771 michael 2820 * mask
772 michael 1372 * Output: None
773 michael 3156 * Side effects: Reports configured K(or k)-lines to source_p.
774 michael 1372 */
775 adx 30 static void
776 michael 3156 report_Klines(struct Client *source_p, int tkline)
777 michael 1372 {
778 michael 7686 dlink_node *node;
779 michael 9072 char c;
780 michael 1372
781     if (tkline)
782 michael 1921 c = 'k';
783 michael 1372 else
784 michael 1921 c = 'K';
785 michael 1372
786 michael 3246 for (unsigned int i = 0; i < ATABLE_SIZE; ++i)
787 michael 1372 {
788 michael 4816 DLINK_FOREACH(node, atable[i].head)
789 michael 1372 {
790 michael 4816 const struct AddressRec *arec = node->data;
791 michael 1372
792 michael 1632 if (arec->type != CONF_KLINE)
793     continue;
794 michael 1628
795 michael 7470 const struct MaskItem *conf = arec->conf;
796 michael 1650 if ((!tkline && conf->until) ||
797     (tkline && !conf->until))
798 michael 1632 continue;
799    
800 michael 4569 sendto_one_numeric(source_p, &me, RPL_STATSKLINE, c, conf->host, conf->user,
801     conf->reason);
802 michael 1372 }
803     }
804     }
805    
806     static void
807 michael 1457 stats_tklines(struct Client *source_p, int parc, char *parv[])
808 adx 30 {
809     /* Oper only, if unopered, return ERR_NOPRIVILEGES */
810 michael 4341 if (ConfigGeneral.stats_k_oper_only == 2 && !HasUMode(source_p, UMODE_OPER))
811 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
812 adx 30
813 michael 4035 /* If unopered, only return matching klines */
814 michael 4341 else if (ConfigGeneral.stats_k_oper_only == 1 && !HasUMode(source_p, UMODE_OPER))
815 adx 30 {
816 michael 9072 const struct MaskItem *conf;
817 adx 30
818     if (MyConnect(source_p))
819 michael 1632 conf = find_conf_by_address(source_p->host,
820 michael 8495 &source_p->ip, CONF_KLINE,
821 michael 2820 source_p->username, NULL, 1);
822 adx 30 else
823 michael 8828 conf = find_conf_by_address(source_p->host, NULL, CONF_KLINE,
824 michael 4035 source_p->username, NULL, 1);
825 adx 30
826 michael 8604 if (conf == NULL)
827 adx 30 return;
828    
829 michael 5541 /* Don't report a permanent kline as temporary kline */
830 michael 8604 if (conf->until == 0)
831 adx 30 return;
832    
833 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSKLINE, 'k',
834     conf->host, conf->user, conf->reason);
835 adx 30 }
836 michael 4035 else /* They are opered, or allowed to see all klines */
837 adx 30 report_Klines(source_p, 1);
838     }
839    
840     static void
841 michael 1457 stats_klines(struct Client *source_p, int parc, char *parv[])
842 adx 30 {
843     /* Oper only, if unopered, return ERR_NOPRIVILEGES */
844 michael 4341 if (ConfigGeneral.stats_k_oper_only == 2 && !HasUMode(source_p, UMODE_OPER))
845 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
846 adx 30
847 michael 4035 /* If unopered, only return matching klines */
848 michael 4341 else if (ConfigGeneral.stats_k_oper_only == 1 && !HasUMode(source_p, UMODE_OPER))
849 adx 30 {
850 michael 9072 const struct MaskItem *conf;
851 adx 30
852 michael 4035 /* Search for a kline */
853 michael 560 if (MyConnect(source_p))
854 michael 1632 conf = find_conf_by_address(source_p->host,
855 michael 8495 &source_p->ip, CONF_KLINE,
856 michael 2820 source_p->username, NULL, 0);
857 adx 30 else
858 michael 8828 conf = find_conf_by_address(source_p->host, NULL, CONF_KLINE,
859 michael 4035 source_p->username, NULL, 0);
860 adx 30
861 michael 8604 if (conf == NULL)
862 adx 30 return;
863    
864 michael 5541 /* Don't report a temporary kline as permanent kline */
865 michael 1649 if (conf->until)
866 adx 30 return;
867 michael 2820
868 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSKLINE, 'K',
869     conf->host, conf->user, conf->reason);
870 adx 30 }
871 michael 4035 else /* They are opered, or allowed to see all klines */
872 adx 30 report_Klines(source_p, 0);
873     }
874    
875     static void
876 michael 1457 stats_messages(struct Client *source_p, int parc, char *parv[])
877 adx 30 {
878 michael 5027 if (!HasUMode(source_p, UMODE_OPER) && ConfigGeneral.stats_m_oper_only)
879     sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
880     else
881     report_messages(source_p);
882 adx 30 }
883    
884 michael 8452 static void
885     stats_pseudo(struct Client *source_p, int parc, char *parv[])
886     {
887 michael 8457 dlink_node *node;
888    
889     DLINK_FOREACH(node, pseudo_get_list()->head)
890     {
891     const struct PseudoItem *pseudo = node->data;
892     sendto_one_numeric(source_p, &me, RPL_STATSPSEUDO, pseudo->command,
893     pseudo->name, pseudo->nick, pseudo->serv,
894     pseudo->prepend ? pseudo->prepend : "*");
895     }
896 michael 8452 }
897    
898 adx 30 /* 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 7686 dlink_node *node;
908 michael 9313 char buf[32];
909 michael 3512 unsigned int opercount = 0;
910 adx 30
911 michael 4816 DLINK_FOREACH(node, oper_list.head)
912 adx 30 {
913 michael 4816 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 3517 if (HasUMode(source_p, UMODE_OPER) || !HasUMode(target_p, UMODE_HIDEIDLE))
919 michael 6848 snprintf(buf, sizeof(buf), "%s", time_dissect(client_get_idle_time(source_p, target_p)));
920 michael 3517 else
921     strlcpy(buf, "n/a", sizeof(buf));
922    
923 michael 7052 if (MyConnect(source_p) && HasUMode(source_p, UMODE_OPER))
924 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
925 michael 3574 "p :[%c][%s] %s (%s@%s) Idle: %s",
926     HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O',
927 michael 4589 oper_privs_as_string(target_p->connection->operflags),
928 michael 3574 target_p->name, target_p->username, target_p->host, buf);
929 adx 30 else
930 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
931 michael 3574 "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 3512 ++opercount;
935 adx 30 }
936    
937 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
938 michael 3574 "p :%u OPER(s)", opercount);
939 adx 30 }
940    
941 michael 6365 /* show_ports()
942     *
943     * inputs - pointer to client to show ports to
944     * output - none
945     * side effects - send port listing to a client
946     */
947 adx 30 static void
948 michael 6365 show_ports(struct Client *source_p)
949     {
950 michael 7686 dlink_node *node;
951 michael 6365
952     DLINK_FOREACH(node, listener_get_list()->head)
953     {
954 michael 7686 char buf[8];
955     char *p = buf;
956 michael 6365 const struct Listener *listener = node->data;
957    
958     if (listener->flags & LISTENER_HIDDEN)
959     {
960     if (!HasUMode(source_p, UMODE_ADMIN))
961     continue;
962     *p++ = 'H';
963     }
964    
965     if (listener->flags & LISTENER_SERVER)
966     *p++ = 'S';
967 michael 9156 if (listener->flags & LISTENER_TLS)
968     *p++ = 'T';
969 michael 6365 *p = '\0';
970    
971 michael 9037 if (HasUMode(source_p, UMODE_ADMIN) && ConfigServerHide.hide_server_ips == 0)
972 michael 6365 sendto_one_numeric(source_p, &me, RPL_STATSPLINE, 'P', listener->port,
973     listener->name,
974     listener->ref_count, buf,
975     listener->active ? "active" : "disabled");
976     else
977     sendto_one_numeric(source_p, &me, RPL_STATSPLINE, 'P', listener->port,
978     me.name, listener->ref_count, buf,
979     listener->active ? "active" : "disabled");
980     }
981     }
982    
983     static void
984 michael 1457 stats_ports(struct Client *source_p, int parc, char *parv[])
985 adx 30 {
986 michael 4341 if (!HasUMode(source_p, UMODE_OPER) && ConfigGeneral.stats_P_oper_only)
987 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
988 adx 30 else
989     show_ports(source_p);
990     }
991    
992     static void
993 michael 1457 stats_tstats(struct Client *source_p, int parc, char *parv[])
994 adx 30 {
995 michael 7686 dlink_node *node;
996 michael 9004 struct ServerStatistics sp = ServerStats;
997 michael 896
998 michael 4816 DLINK_FOREACH(node, local_server_list.head)
999 michael 896 {
1000 michael 4816 const struct Client *target_p = node->data;
1001 michael 896
1002 michael 8408 sp.is_sbs += target_p->connection->send.bytes;
1003     sp.is_sbr += target_p->connection->recv.bytes;
1004 michael 8918 sp.is_sti += event_base->time.sec_monotonic - target_p->connection->created_monotonic;
1005 michael 8408 sp.is_sv++;
1006 michael 896 }
1007    
1008 michael 4816 DLINK_FOREACH(node, local_client_list.head)
1009 michael 896 {
1010 michael 4816 const struct Client *target_p = node->data;
1011 michael 896
1012 michael 8408 sp.is_cbs += target_p->connection->send.bytes;
1013     sp.is_cbr += target_p->connection->recv.bytes;
1014 michael 8918 sp.is_cti += event_base->time.sec_monotonic - target_p->connection->created_monotonic;
1015 michael 8408 sp.is_cl++;
1016 michael 896 }
1017    
1018 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1019 michael 4039 "t :accepts %u refused %u",
1020 michael 8408 sp.is_ac, sp.is_ref);
1021 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1022 michael 4039 "t :unknown commands %u prefixes %u",
1023 michael 8408 sp.is_unco, sp.is_unpf);
1024 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1025 michael 4039 "t :nick collisions %u unknown closes %u",
1026 michael 8408 sp.is_kill, sp.is_ni);
1027 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1028 michael 4039 "t :wrong direction %u empty %u",
1029 michael 8408 sp.is_wrdi, sp.is_empt);
1030 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1031 michael 4039 "t :numerics seen %u",
1032 michael 8408 sp.is_num);
1033 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1034 michael 4039 "t :auth successes %u fails %u",
1035 michael 8408 sp.is_asuc, sp.is_abad);
1036 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1037 michael 4039 "t :Client Server");
1038 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1039 michael 4039 "t :connected %u %u",
1040 michael 8408 sp.is_cl, sp.is_sv);
1041 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1042 michael 6781 "t :bytes sent %ju %ju",
1043 michael 8408 sp.is_cbs, sp.is_sbs);
1044 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1045 michael 7470 "t :bytes received %ju %ju",
1046 michael 8408 sp.is_cbr, sp.is_sbr);
1047 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1048 michael 7329 "t :time connected %ju %ju",
1049 michael 8408 sp.is_cti, sp.is_sti);
1050 adx 30 }
1051    
1052     static void
1053 michael 1457 stats_uptime(struct Client *source_p, int parc, char *parv[])
1054 adx 30 {
1055 michael 4341 if (!HasUMode(source_p, UMODE_OPER) && ConfigGeneral.stats_u_oper_only)
1056 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
1057 michael 2269 else
1058     {
1059 michael 6570 sendto_one_numeric(source_p, &me, RPL_STATSUPTIME,
1060 michael 8918 time_dissect(event_base->time.sec_monotonic - me.connection->created_monotonic));
1061 michael 8604 if (ConfigServerHide.disable_remote_commands == 0 || HasUMode(source_p, UMODE_OPER))
1062 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSCONN, Count.max_loc_con,
1063 michael 7998 Count.max_loc, Count.totalrestartcount);
1064 michael 2269 }
1065 adx 30 }
1066    
1067     static void
1068 michael 1457 stats_shared(struct Client *source_p, int parc, char *parv[])
1069 adx 30 {
1070 michael 7208 report_shared(source_p);
1071     report_cluster(source_p);
1072 adx 30 }
1073    
1074     /* stats_servers()
1075     *
1076     * input - client pointer
1077     * output - none
1078     * side effects - client is shown lists of who connected servers
1079     */
1080     static void
1081 michael 1457 stats_servers(struct Client *source_p, int parc, char *parv[])
1082 adx 30 {
1083 michael 7686 dlink_node *node;
1084 adx 30
1085 michael 4816 DLINK_FOREACH(node, local_server_list.head)
1086 adx 30 {
1087 michael 4816 const struct Client *target_p = node->data;
1088 adx 30
1089 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1090 michael 6848 "v :%s (%s!%s@%s) Idle: %s",
1091 michael 3574 target_p->name,
1092     (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
1093 michael 8918 "*", "*", time_dissect(event_base->time.sec_monotonic - target_p->connection->last_data));
1094 adx 30 }
1095    
1096 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1097 michael 4212 "v :%u Server(s)",
1098     dlink_list_length(&local_server_list));
1099 adx 30 }
1100    
1101     static void
1102 michael 1457 stats_class(struct Client *source_p, int parc, char *parv[])
1103 adx 30 {
1104 michael 7913 dlink_node *node;
1105 michael 2116
1106 michael 4816 DLINK_FOREACH(node, class_get_list()->head)
1107 michael 2116 {
1108 michael 4816 const struct ClassItem *class = node->data;
1109 michael 2116
1110 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSYLINE, 'Y',
1111     class->name, class->ping_freq,
1112     class->con_freq,
1113     class->max_total, class->max_sendq,
1114     class->max_recvq,
1115     class->ref_count,
1116     class->number_per_cidr, class->cidr_bitlen_ipv4,
1117     class->number_per_cidr, class->cidr_bitlen_ipv6,
1118     class->active ? "active" : "disabled");
1119 michael 2116 }
1120 adx 30 }
1121    
1122     static void
1123 michael 1457 stats_servlinks(struct Client *source_p, int parc, char *parv[])
1124 adx 30 {
1125 michael 7470 dlink_node *node;
1126 michael 6781 uintmax_t sendB = 0, recvB = 0;
1127 adx 30
1128 michael 1219 if (ConfigServerHide.flatten_links && !HasUMode(source_p, UMODE_OPER))
1129 adx 30 {
1130 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
1131 adx 30 return;
1132     }
1133    
1134 michael 4816 DLINK_FOREACH(node, local_server_list.head)
1135 adx 30 {
1136 michael 7470 const struct Client *target_p = node->data;
1137 adx 30
1138 michael 1851 if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
1139     if (!HasUMode(source_p, UMODE_OPER))
1140     continue;
1141    
1142 michael 4589 sendB += target_p->connection->send.bytes;
1143     recvB += target_p->connection->recv.bytes;
1144 adx 30
1145 michael 8922 /* ":%s 211 %s %s %u %u %ju %u %ju :%ju %ju %s" */
1146 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSLINKINFO,
1147 michael 7996 client_get_name(target_p, HasUMode(source_p, UMODE_ADMIN) ? SHOW_IP : MASK_IP),
1148 michael 4589 dbuf_length(&target_p->connection->buf_sendq),
1149     target_p->connection->send.messages,
1150     target_p->connection->send.bytes >> 10,
1151     target_p->connection->recv.messages,
1152     target_p->connection->recv.bytes >> 10,
1153 michael 8922 (event_base->time.sec_monotonic - target_p->connection->created_monotonic),
1154     (event_base->time.sec_monotonic - target_p->connection->last_data),
1155 michael 8165 HasUMode(source_p, UMODE_OPER) ? capab_get(target_p) : "TS");
1156 adx 30 }
1157    
1158     sendB >>= 10;
1159     recvB >>= 10;
1160    
1161 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, "? :%u total server(s)",
1162 michael 4212 dlink_list_length(&local_server_list));
1163 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, "? :Sent total: %7.2f %s",
1164 michael 3574 _GMKv(sendB), _GMKs(sendB));
1165 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, "? :Recv total: %7.2f %s",
1166 michael 3574 _GMKv(recvB), _GMKs(recvB));
1167 adx 30
1168 michael 9072 uintmax_t uptime = (event_base->time.sec_monotonic - me.connection->created_monotonic);
1169 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1170 michael 9022 "? :Server send: %7.2f %s (%4.1f KiB/s)",
1171 michael 7383 _GMKv((me.connection->send.bytes >> 10)),
1172     _GMKs((me.connection->send.bytes >> 10)),
1173 michael 4589 (float)((float)((me.connection->send.bytes) >> 10) /
1174 michael 3574 (float)uptime));
1175 michael 5582 sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT,
1176 michael 9022 "? :Server recv: %7.2f %s (%4.1f KiB/s)",
1177 michael 7383 _GMKv((me.connection->recv.bytes >> 10)),
1178     _GMKs((me.connection->recv.bytes >> 10)),
1179 michael 4589 (float)((float)((me.connection->recv.bytes) >> 10) /
1180 michael 3574 (float)uptime));
1181 adx 30 }
1182    
1183 michael 1457 /* parse_stats_args()
1184     *
1185     * inputs - arg count
1186     * - args
1187     * - doall flag
1188     * - wild card or not
1189     * output - pointer to name to use
1190     * side effects -
1191     * common parse routine for m_stats args
1192 michael 2820 *
1193 michael 1457 */
1194 michael 4754 static const char *
1195 michael 8657 parse_stats_args(struct Client *source_p, int parc, char *parv[], bool *doall, bool *wilds)
1196 adx 30 {
1197 michael 1457 if (parc > 2)
1198 adx 30 {
1199 michael 4754 const char *name = parv[2];
1200 adx 30
1201 michael 8604 if (irccmp(name, ID_or_name(&me, source_p)) == 0)
1202 michael 8657 *doall = true;
1203 michael 8604 else if (match(name, ID_or_name(&me, source_p)) == 0)
1204 michael 8657 *doall = true;
1205 michael 1457
1206     *wilds = has_wildcards(name);
1207    
1208     return name;
1209 adx 30 }
1210    
1211 michael 1457 return NULL;
1212 adx 30 }
1213    
1214     static void
1215 michael 8657 stats_L_list(struct Client *source_p, const char *name, bool doall, bool wilds,
1216 michael 4754 dlink_list *list, const char statchar)
1217 adx 30 {
1218 michael 7470 dlink_node *node;
1219 adx 30
1220     /*
1221 michael 4035 * Send info about connections which match, or all if the
1222 michael 7651 * mask matches from.
1223 adx 30 */
1224 michael 4816 DLINK_FOREACH(node, list->head)
1225 adx 30 {
1226 michael 7470 const struct Client *target_p = node->data;
1227 michael 9072 enum addr_mask_type type;
1228 adx 30
1229 michael 1652 if (!doall && wilds && match(name, target_p->name))
1230 adx 30 continue;
1231 michael 4035
1232 adx 30 if (!(doall || wilds) && irccmp(name, target_p->name))
1233     continue;
1234    
1235 michael 7651 if (IsUpper(statchar))
1236     type = SHOW_IP;
1237 adx 30 else
1238 michael 7651 type = HIDE_IP;
1239    
1240     if (IsServer(target_p) || IsConnecting(target_p) || IsHandshake(target_p))
1241 michael 7653 if (!HasUMode(source_p, UMODE_ADMIN))
1242 michael 7651 type = MASK_IP;
1243    
1244     sendto_one_numeric(source_p, &me, RPL_STATSLINKINFO,
1245 michael 7996 client_get_name(target_p, type),
1246 michael 7651 dbuf_length(&target_p->connection->buf_sendq),
1247     target_p->connection->send.messages,
1248     target_p->connection->send.bytes >> 10,
1249     target_p->connection->recv.messages,
1250     target_p->connection->recv.bytes >> 10,
1251 michael 8922 (event_base->time.sec_monotonic - target_p->connection->created_monotonic),
1252     (event_base->time.sec_monotonic - target_p->connection->last_data),
1253 michael 8165 IsServer(target_p) ? capab_get(target_p) : "-");
1254 adx 30 }
1255     }
1256    
1257 michael 1457 /*
1258     * stats_L
1259 adx 30 *
1260 michael 1457 * inputs - pointer to client to report to
1261     * - doall flag
1262     * - wild card or not
1263     * output - NONE
1264     * side effects -
1265     */
1266     static void
1267 michael 8657 stats_L(struct Client *source_p, const char *name, bool doall,
1268     bool wilds, const char statchar)
1269 michael 1457 {
1270     stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar);
1271     stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar);
1272 michael 4212 stats_L_list(source_p, name, doall, wilds, &local_server_list, statchar);
1273 michael 1457 }
1274    
1275     static void
1276     stats_ltrace(struct Client *source_p, int parc, char *parv[])
1277     {
1278 michael 8657 bool doall = false;
1279     bool wilds = false;
1280 michael 9072 const char *name;
1281 michael 1457
1282 michael 3246 if ((name = parse_stats_args(source_p, parc, parv, &doall, &wilds)))
1283 michael 1457 {
1284 michael 4754 const char statchar = *parv[1];
1285 michael 1457 stats_L(source_p, name, doall, wilds, statchar);
1286     }
1287     else
1288 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "STATS");
1289 michael 1457 }
1290    
1291 michael 6551 struct StatsStruct
1292 michael 1457 {
1293 michael 9075 unsigned char letter;
1294 michael 4478 void (*handler)(struct Client *, int, char *[]);
1295 michael 9075 unsigned int required_modes;
1296 michael 1457 };
1297    
1298 michael 6551 static const struct StatsStruct *stats_map[256];
1299     static const struct StatsStruct stats_tab[] =
1300     {
1301 michael 9069 { .letter = 'a', .handler = stats_dns_servers, .required_modes = UMODE_ADMIN },
1302     { .letter = 'A', .handler = stats_dns_servers, .required_modes = UMODE_ADMIN },
1303     { .letter = 'c', .handler = stats_connect, .required_modes = UMODE_OPER },
1304     { .letter = 'C', .handler = stats_connect, .required_modes = UMODE_OPER },
1305     { .letter = 'd', .handler = stats_tdeny, .required_modes = UMODE_OPER },
1306     { .letter = 'D', .handler = stats_deny, .required_modes = UMODE_OPER },
1307     { .letter = 'e', .handler = stats_exempt, .required_modes = UMODE_OPER },
1308     { .letter = 'E', .handler = stats_events, .required_modes = UMODE_ADMIN },
1309     { .letter = 'f', .handler = stats_fdlist, .required_modes = UMODE_ADMIN },
1310     { .letter = 'F', .handler = stats_fdlist, .required_modes = UMODE_ADMIN },
1311     { .letter = 'h', .handler = stats_hubleaf, .required_modes = UMODE_OPER },
1312     { .letter = 'H', .handler = stats_hubleaf, .required_modes = UMODE_OPER },
1313     { .letter = 'i', .handler = stats_auth },
1314     { .letter = 'I', .handler = stats_auth },
1315     { .letter = 'k', .handler = stats_tklines },
1316     { .letter = 'K', .handler = stats_klines },
1317     { .letter = 'l', .handler = stats_ltrace, .required_modes = UMODE_OPER },
1318     { .letter = 'L', .handler = stats_ltrace, .required_modes = UMODE_OPER },
1319     { .letter = 'm', .handler = stats_messages },
1320     { .letter = 'M', .handler = stats_messages },
1321     { .letter = 'o', .handler = stats_operator },
1322     { .letter = 'O', .handler = stats_operator },
1323     { .letter = 'p', .handler = stats_operedup },
1324     { .letter = 'P', .handler = stats_ports },
1325     { .letter = 'q', .handler = stats_resv, .required_modes = UMODE_OPER },
1326     { .letter = 'Q', .handler = stats_resv, .required_modes = UMODE_OPER },
1327     { .letter = 's', .handler = stats_pseudo, .required_modes = UMODE_OPER },
1328     { .letter = 'S', .handler = stats_service, .required_modes = UMODE_OPER },
1329     { .letter = 't', .handler = stats_tstats, .required_modes = UMODE_OPER },
1330     { .letter = 'T', .handler = motd_report, .required_modes = UMODE_OPER },
1331     { .letter = 'u', .handler = stats_uptime },
1332     { .letter = 'U', .handler = stats_shared, .required_modes = UMODE_OPER },
1333     { .letter = 'v', .handler = stats_servers, .required_modes = UMODE_OPER },
1334     { .letter = 'x', .handler = stats_gecos, .required_modes = UMODE_OPER },
1335     { .letter = 'X', .handler = stats_gecos, .required_modes = UMODE_OPER },
1336     { .letter = 'y', .handler = stats_class, .required_modes = UMODE_OPER },
1337     { .letter = 'Y', .handler = stats_class, .required_modes = UMODE_OPER },
1338     { .letter = 'z', .handler = stats_memory, .required_modes = UMODE_OPER },
1339     { .letter = '?', .handler = stats_servlinks },
1340     { .letter = '\0' }
1341 michael 6551 };
1342    
1343 michael 1457 static void
1344     do_stats(struct Client *source_p, int parc, char *parv[])
1345     {
1346 michael 6551 const unsigned char statchar = *parv[1];
1347     const struct StatsStruct *tab;
1348 michael 1457
1349     if (statchar == '\0')
1350     {
1351 michael 3109 sendto_one_numeric(source_p, &me, RPL_ENDOFSTATS, '*');
1352 michael 1457 return;
1353     }
1354    
1355 michael 6551 if ((tab = stats_map[statchar]))
1356 michael 1457 {
1357 michael 8436 if (tab->required_modes == 0 || HasUMode(source_p, tab->required_modes))
1358 michael 6551 tab->handler(source_p, parc, parv);
1359     else
1360     sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
1361 michael 1457
1362 michael 6551 sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE,
1363     "STATS %c requested by %s (%s@%s) [%s]",
1364     statchar, source_p->name, source_p->username,
1365     source_p->host, source_p->servptr->name);
1366 michael 1457 }
1367    
1368 michael 3109 sendto_one_numeric(source_p, &me, RPL_ENDOFSTATS, statchar);
1369 michael 1457 }
1370    
1371     /*
1372     * m_stats()
1373 michael 3096 * parv[0] = command
1374 michael 1457 * parv[1] = stat letter/command
1375     * parv[2] = (if present) server/mask in stats L
1376 adx 30 */
1377 michael 9078 static void
1378 michael 3156 m_stats(struct Client *source_p, int parc, char *parv[])
1379 adx 30 {
1380 michael 7329 static uintmax_t last_used = 0;
1381 adx 30
1382 michael 4299 /* Check the user is actually allowed to do /stats, and isn't flooding */
1383 michael 8902 if ((last_used + ConfigGeneral.pace_wait) > event_base->time.sec_monotonic)
1384 michael 1457 {
1385 michael 4758 sendto_one_numeric(source_p, &me, RPL_LOAD2HI, "STATS");
1386 michael 9078 return;
1387 michael 1457 }
1388 adx 30
1389 michael 8902 last_used = event_base->time.sec_monotonic;
1390 adx 30
1391 michael 2341 /* Is the stats meant for us? */
1392 michael 8604 if (ConfigServerHide.disable_remote_commands == 0)
1393 michael 7970 if (server_hunt(source_p, ":%s STATS %s :%s", 2, parc, parv)->ret != HUNTED_ISME)
1394 michael 9078 return;
1395 michael 2341
1396 michael 1457 do_stats(source_p, parc, parv);
1397     }
1398    
1399     /*
1400 michael 3219 * ms_stats()
1401 michael 3096 * parv[0] = command
1402 michael 1457 * parv[1] = stat letter/command
1403     * parv[2] = (if present) server/mask in stats L, or target
1404     */
1405 michael 9078 static void
1406 michael 3219 ms_stats(struct Client *source_p, int parc, char *parv[])
1407 michael 1457 {
1408 michael 7970 if (server_hunt(source_p, ":%s STATS %s :%s", 2, parc, parv)->ret != HUNTED_ISME)
1409 michael 9078 return;
1410 michael 1457
1411     do_stats(source_p, parc, parv);
1412 adx 30 }
1413 michael 1230
1414 michael 6551 static void
1415     stats_init(void)
1416     {
1417     for (const struct StatsStruct *tab = stats_tab; tab->letter; ++tab)
1418     stats_map[tab->letter] = tab;
1419     }
1420    
1421 michael 2820 static struct Message stats_msgtab =
1422     {
1423 michael 5880 .cmd = "STATS",
1424     .args_min = 2,
1425     .args_max = MAXPARA,
1426     .handlers[UNREGISTERED_HANDLER] = m_unregistered,
1427     .handlers[CLIENT_HANDLER] = m_stats,
1428     .handlers[SERVER_HANDLER] = ms_stats,
1429     .handlers[ENCAP_HANDLER] = m_ignore,
1430     .handlers[OPER_HANDLER] = ms_stats
1431 michael 1230 };
1432    
1433     static void
1434     module_init(void)
1435     {
1436 michael 6551 stats_init();
1437 michael 1230 mod_add_cmd(&stats_msgtab);
1438     }
1439    
1440     static void
1441     module_exit(void)
1442     {
1443     mod_del_cmd(&stats_msgtab);
1444     }
1445    
1446 michael 2820 struct module module_entry =
1447     {
1448 michael 1230 .version = "$Revision$",
1449     .modinit = module_init,
1450     .modexit = module_exit,
1451     };

Properties

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