ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 8969
Committed: Sat May 18 11:58:06 2019 UTC (4 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 44961 byte(s)
Log Message:
- Move oper_privs_as_string() from conf.c to m_stats.c

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

Properties

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