1 |
adx |
30 |
/* |
2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
9101 |
* 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 |
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 |
michael |
9234 |
#include "channel.h" |
57 |
michael |
9265 |
#include "channel_invite.h" |
58 |
adx |
30 |
|
59 |
|
|
|
60 |
michael |
8969 |
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 |
7209 |
static void |
115 |
|
|
report_shared(struct Client *source_p) |
116 |
michael |
1922 |
{ |
117 |
michael |
7218 |
static const struct shared_types |
118 |
michael |
7209 |
{ |
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 |
7209 |
dlink_node *node; |
135 |
michael |
8310 |
char buf[sizeof(flag_table) / sizeof(flag_table[0]) + 1]; /* +1 for 'c' */ |
136 |
michael |
7209 |
|
137 |
|
|
DLINK_FOREACH(node, shared_get_list()->head) |
138 |
|
|
{ |
139 |
michael |
7218 |
const struct SharedItem *shared = node->data; |
140 |
michael |
7209 |
char *p = buf; |
141 |
|
|
|
142 |
|
|
*p++ = 'c'; |
143 |
|
|
|
144 |
michael |
7218 |
for (const struct shared_types *tab = flag_table; tab->type; ++tab) |
145 |
|
|
if (tab->type & shared->type) |
146 |
|
|
*p++ = tab->letter; |
147 |
michael |
7209 |
else |
148 |
michael |
7218 |
*p++ = ToLower(tab->letter); |
149 |
michael |
7209 |
|
150 |
|
|
*p = '\0'; |
151 |
|
|
|
152 |
michael |
7218 |
sendto_one_numeric(source_p, &me, RPL_STATSULINE, shared->server, |
153 |
|
|
shared->user, shared->host, buf); |
154 |
michael |
7209 |
} |
155 |
|
|
} |
156 |
|
|
|
157 |
|
|
static void |
158 |
|
|
report_cluster(struct Client *source_p) |
159 |
|
|
{ |
160 |
michael |
7218 |
static const struct cluster_types |
161 |
michael |
7209 |
{ |
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 |
8310 |
char buf[sizeof(flag_table) / sizeof(flag_table[0]) + 1]; /* +1 for 'C' */ |
179 |
michael |
7209 |
|
180 |
|
|
DLINK_FOREACH(node, cluster_get_list()->head) |
181 |
|
|
{ |
182 |
michael |
7218 |
const struct ClusterItem *cluster = node->data; |
183 |
michael |
7209 |
char *p = buf; |
184 |
|
|
|
185 |
|
|
*p++ = 'C'; |
186 |
|
|
|
187 |
michael |
7218 |
for (const struct cluster_types *tab = flag_table; tab->type; ++tab) |
188 |
|
|
if (tab->type & cluster->type) |
189 |
|
|
*p++ = tab->letter; |
190 |
michael |
7209 |
else |
191 |
michael |
7218 |
*p++ = ToLower(tab->letter); |
192 |
michael |
7209 |
|
193 |
|
|
*p = '\0'; |
194 |
|
|
|
195 |
michael |
7218 |
sendto_one_numeric(source_p, &me, RPL_STATSULINE, cluster->server, |
196 |
michael |
7209 |
"*", "*", buf); |
197 |
|
|
} |
198 |
|
|
} |
199 |
|
|
|
200 |
michael |
7248 |
static void |
201 |
michael |
7397 |
stats_service(struct Client *source_p, int parc, char *parv[]) |
202 |
michael |
7248 |
{ |
203 |
|
|
dlink_node *node; |
204 |
|
|
|
205 |
|
|
DLINK_FOREACH(node, service_get_list()->head) |
206 |
|
|
{ |
207 |
|
|
const struct ServiceItem *service = node->data; |
208 |
michael |
8491 |
sendto_one_numeric(source_p, &me, RPL_STATSSERVICE, "*", service->name, 0, 0); |
209 |
michael |
7248 |
} |
210 |
|
|
} |
211 |
|
|
|
212 |
michael |
7304 |
static void |
213 |
michael |
7397 |
stats_gecos(struct Client *source_p, int parc, char *parv[]) |
214 |
michael |
7304 |
{ |
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 |
7313 |
gecos->expire ? 'x' : 'X', |
222 |
michael |
7304 |
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 |
7405 |
stats_operator(struct Client *source_p, int parc, char *parv[]) |
234 |
michael |
1922 |
{ |
235 |
michael |
7405 |
dlink_node *node; |
236 |
michael |
1922 |
|
237 |
michael |
7405 |
if (!HasUMode(source_p, UMODE_OPER) && ConfigGeneral.stats_o_oper_only) |
238 |
michael |
1922 |
{ |
239 |
michael |
7405 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
240 |
|
|
return; |
241 |
|
|
} |
242 |
michael |
1922 |
|
243 |
michael |
7405 |
DLINK_FOREACH(node, operator_items.head) |
244 |
|
|
{ |
245 |
|
|
const struct MaskItem *conf = node->data; |
246 |
michael |
1922 |
|
247 |
michael |
7405 |
/* 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 |
7405 |
static void |
259 |
|
|
stats_connect(struct Client *source_p, int parc, char *parv[]) |
260 |
|
|
{ |
261 |
|
|
dlink_node *node; |
262 |
michael |
1922 |
|
263 |
michael |
7405 |
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 |
7405 |
if (IsConfAllowAutoConn(conf)) |
270 |
|
|
*p++ = 'A'; |
271 |
michael |
9157 |
if (IsConfTLS(conf)) |
272 |
michael |
7405 |
*p++ = 'S'; |
273 |
|
|
if (p == buf) |
274 |
|
|
*p++ = '*'; |
275 |
michael |
4034 |
|
276 |
michael |
7405 |
*p = '\0'; |
277 |
michael |
4034 |
|
278 |
michael |
7405 |
/* |
279 |
michael |
8059 |
* Allow admins to see actual ips unless 'hide_server_ips' is enabled |
280 |
michael |
7405 |
*/ |
281 |
michael |
8603 |
if (ConfigServerHide.hide_server_ips == 0 && HasUMode(source_p, UMODE_ADMIN)) |
282 |
michael |
7405 |
sendto_one_numeric(source_p, &me, RPL_STATSCLINE, 'C', conf->host, |
283 |
michael |
8059 |
buf, conf->name, conf->port, conf->class->name); |
284 |
michael |
7405 |
else |
285 |
michael |
8059 |
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 |
7397 |
stats_resv(struct Client *source_p, int parc, char *parv[]) |
298 |
michael |
1927 |
{ |
299 |
michael |
7687 |
dlink_node *node; |
300 |
michael |
1927 |
|
301 |
michael |
7282 |
DLINK_FOREACH(node, resv_chan_get_list()->head) |
302 |
michael |
1927 |
{ |
303 |
michael |
7282 |
const struct ResvItem *resv = node->data; |
304 |
michael |
3109 |
|
305 |
|
|
sendto_one_numeric(source_p, &me, RPL_STATSQLINE, |
306 |
michael |
7282 |
resv->expire ? 'q' : 'Q', |
307 |
|
|
resv->mask, resv->reason); |
308 |
michael |
1927 |
} |
309 |
|
|
|
310 |
michael |
7282 |
DLINK_FOREACH(node, resv_nick_get_list()->head) |
311 |
michael |
1927 |
{ |
312 |
michael |
7282 |
const struct ResvItem *resv = node->data; |
313 |
michael |
3109 |
|
314 |
|
|
sendto_one_numeric(source_p, &me, RPL_STATSQLINE, |
315 |
michael |
7282 |
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 |
7687 |
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 |
4329 |
unsigned int number_ips_stored = 0; /* number of ip addresses hashed */ |
335 |
adx |
30 |
|
336 |
michael |
6719 |
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 |
6719 |
size_t safelist_memory = 0; |
342 |
adx |
30 |
|
343 |
michael |
6719 |
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 |
6719 |
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 |
6719 |
size_t watch_list_memory = 0; /* watchlist memory used */ |
355 |
michael |
884 |
|
356 |
michael |
7349 |
unsigned int listener_count = 0; |
357 |
|
|
size_t listener_memory = 0; |
358 |
adx |
30 |
|
359 |
michael |
7349 |
|
360 |
michael |
7983 |
DLINK_FOREACH(node, local_server_list.head) |
361 |
michael |
7963 |
{ |
362 |
|
|
const struct Client *target_p = node->data; |
363 |
|
|
|
364 |
michael |
7983 |
local_client_conf_count += dlink_list_length(&target_p->connection->confs); |
365 |
michael |
7963 |
} |
366 |
|
|
|
367 |
michael |
7983 |
DLINK_FOREACH(node, local_client_list.head) |
368 |
adx |
30 |
{ |
369 |
michael |
7433 |
const struct Client *target_p = node->data; |
370 |
adx |
30 |
|
371 |
michael |
7983 |
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 |
7983 |
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 |
7605 |
/* Count up all members, invites, ban lists, except lists, Invex lists */ |
379 |
michael |
8439 |
DLINK_FOREACH(node, channel_get_list()->head) |
380 |
adx |
30 |
{ |
381 |
michael |
9081 |
const struct Channel *channel = node->data; |
382 |
adx |
30 |
|
383 |
michael |
9081 |
channel_members += dlink_list_length(&channel->members); |
384 |
|
|
channel_invites += dlink_list_length(&channel->invites); |
385 |
adx |
30 |
|
386 |
michael |
9081 |
channel_bans += dlink_list_length(&channel->banlist); |
387 |
|
|
channel_ban_memory += dlink_list_length(&channel->banlist) * sizeof(struct Ban); |
388 |
michael |
1017 |
|
389 |
michael |
9081 |
channel_except += dlink_list_length(&channel->exceptlist); |
390 |
|
|
channel_except_memory += dlink_list_length(&channel->exceptlist) * sizeof(struct Ban); |
391 |
michael |
1017 |
|
392 |
michael |
9081 |
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 |
7471 |
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 |
7433 |
|
401 |
|
|
DLINK_FOREACH(node, listing_client_list.head) |
402 |
adx |
30 |
{ |
403 |
michael |
7433 |
const struct Client *acptr = node->data; |
404 |
adx |
30 |
|
405 |
michael |
7433 |
DLINK_FOREACH(node2, acptr->connection->list_task->show_mask.head) |
406 |
|
|
safelist_memory += strlen(node2->data); |
407 |
adx |
30 |
|
408 |
michael |
7433 |
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 |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
415 |
michael |
7616 |
"z :WATCH headers %u(%zu) entries %u(%zu)", |
416 |
michael |
3573 |
watch_list_headers, |
417 |
michael |
7616 |
watch_list_memory, |
418 |
|
|
watch_list_entries, |
419 |
michael |
3573 |
watch_list_entries * sizeof(dlink_node) * 2); |
420 |
michael |
884 |
|
421 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
422 |
michael |
7616 |
"z :Clients %u(%zu)", |
423 |
michael |
7963 |
dlink_list_length(&global_client_list), |
424 |
|
|
dlink_list_length(&global_client_list) * sizeof(struct Client)); |
425 |
adx |
30 |
|
426 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
427 |
michael |
7981 |
"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 |
6719 |
"z :Attached confs %u(%zu)", |
434 |
michael |
3573 |
local_client_conf_count, |
435 |
michael |
6719 |
local_client_conf_count * sizeof(dlink_node)); |
436 |
adx |
30 |
|
437 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
438 |
michael |
6719 |
"z :Resv channels %u(%zu) nicks %u(%zu)", |
439 |
michael |
7282 |
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 |
7349 |
listener_count_memory(&listener_count, &listener_memory); |
445 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
446 |
michael |
7467 |
"z :Listeners %u(%zu)", |
447 |
michael |
7349 |
listener_count, listener_memory); |
448 |
|
|
|
449 |
|
|
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
450 |
michael |
6719 |
"z :Classes %u(%zu)", |
451 |
michael |
7471 |
dlink_list_length(class_get_list()), |
452 |
|
|
dlink_list_length(class_get_list()) * sizeof(struct ClassItem)); |
453 |
adx |
30 |
|
454 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
455 |
michael |
7603 |
"z :Channels %u(%zu)", |
456 |
michael |
8439 |
dlink_list_length(channel_get_list()), |
457 |
|
|
dlink_list_length(channel_get_list()) * sizeof(struct Channel)); |
458 |
adx |
30 |
|
459 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
460 |
michael |
6719 |
"z :Bans %u(%zu)", |
461 |
michael |
3573 |
channel_bans, channel_ban_memory); |
462 |
adx |
30 |
|
463 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
464 |
michael |
6719 |
"z :Exceptions %u(%zu)", |
465 |
michael |
3573 |
channel_except, channel_except_memory); |
466 |
adx |
30 |
|
467 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
468 |
michael |
6719 |
"z :Invex %u(%zu)", |
469 |
michael |
3573 |
channel_invex, channel_invex_memory); |
470 |
adx |
30 |
|
471 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
472 |
michael |
6719 |
"z :Channel members %u(%zu) invites %u(%zu)", |
473 |
michael |
3573 |
channel_members, |
474 |
michael |
9081 |
channel_members * sizeof(struct ChannelMember), |
475 |
michael |
6719 |
channel_invites, |
476 |
michael |
7607 |
channel_invites * sizeof(struct Invite)); |
477 |
adx |
30 |
|
478 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
479 |
michael |
6719 |
"z :Safelist %u(%zu)", |
480 |
michael |
3573 |
safelist_count, safelist_memory); |
481 |
adx |
30 |
|
482 |
michael |
7437 |
whowas_count_memory(&wwu, &wwm); |
483 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
484 |
michael |
7437 |
"z :Whowas users %u(%zu)", wwu, wwm); |
485 |
adx |
30 |
|
486 |
michael |
2150 |
motd_memory_count(source_p); |
487 |
michael |
7471 |
|
488 |
michael |
4325 |
ipcache_get_stats(&number_ips_stored, &mem_ips_stored); |
489 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
490 |
michael |
6719 |
"z :iphash %u(%zu)", |
491 |
michael |
3573 |
number_ips_stored, mem_ips_stored); |
492 |
adx |
30 |
|
493 |
michael |
8437 |
local_client_memory_used = local_client_count * (sizeof(struct Client) + sizeof(struct Connection)); |
494 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
495 |
michael |
6719 |
"z :Local client Memory in use: %u(%zu)", |
496 |
michael |
3573 |
local_client_count, local_client_memory_used); |
497 |
adx |
30 |
|
498 |
|
|
remote_client_memory_used = remote_client_count * sizeof(struct Client); |
499 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
500 |
michael |
6719 |
"z :Remote client Memory in use: %u(%zu)", |
501 |
michael |
3573 |
remote_client_count, remote_client_memory_used); |
502 |
adx |
30 |
} |
503 |
|
|
|
504 |
|
|
static void |
505 |
michael |
4479 |
stats_dns_servers(struct Client *source_p, int parc, char *parv[]) |
506 |
adx |
30 |
{ |
507 |
michael |
9071 |
char ipaddr[HOSTIPLEN + 1]; |
508 |
michael |
6836 |
|
509 |
|
|
for (unsigned int i = 0; i < irc_nscount; ++i) |
510 |
|
|
{ |
511 |
michael |
9318 |
getnameinfo((const struct sockaddr *)&irc_nsaddr_list[i], irc_nsaddr_list[i].ss_len, |
512 |
|
|
ipaddr, sizeof(ipaddr), NULL, 0, NI_NUMERICHOST); |
513 |
michael |
6836 |
sendto_one_numeric(source_p, &me, RPL_STATSALINE, ipaddr); |
514 |
michael |
6990 |
} |
515 |
adx |
30 |
} |
516 |
|
|
|
517 |
|
|
/* stats_deny() |
518 |
|
|
* |
519 |
|
|
* input - client to report to |
520 |
|
|
* output - none |
521 |
|
|
* side effects - client is given dline list. |
522 |
|
|
*/ |
523 |
|
|
static void |
524 |
michael |
1457 |
stats_deny(struct Client *source_p, int parc, char *parv[]) |
525 |
adx |
30 |
{ |
526 |
michael |
7687 |
dlink_node *node; |
527 |
adx |
30 |
|
528 |
michael |
3246 |
for (unsigned int i = 0; i < ATABLE_SIZE; ++i) |
529 |
adx |
30 |
{ |
530 |
michael |
4815 |
DLINK_FOREACH(node, atable[i].head) |
531 |
adx |
30 |
{ |
532 |
michael |
4815 |
const struct AddressRec *arec = node->data; |
533 |
michael |
1367 |
|
534 |
michael |
1632 |
if (arec->type != CONF_DLINE) |
535 |
|
|
continue; |
536 |
adx |
30 |
|
537 |
michael |
7471 |
const struct MaskItem *conf = arec->conf; |
538 |
michael |
5542 |
/* Don't report a temporary dline as permanent dline */ |
539 |
michael |
1649 |
if (conf->until) |
540 |
michael |
1632 |
continue; |
541 |
adx |
30 |
|
542 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_STATSDLINE, 'D', conf->host, conf->reason); |
543 |
adx |
30 |
} |
544 |
|
|
} |
545 |
|
|
} |
546 |
|
|
|
547 |
|
|
/* stats_tdeny() |
548 |
|
|
* |
549 |
|
|
* input - client to report to |
550 |
|
|
* output - none |
551 |
|
|
* side effects - client is given dline list. |
552 |
|
|
*/ |
553 |
|
|
static void |
554 |
michael |
1457 |
stats_tdeny(struct Client *source_p, int parc, char *parv[]) |
555 |
adx |
30 |
{ |
556 |
michael |
7687 |
dlink_node *node; |
557 |
adx |
30 |
|
558 |
michael |
3246 |
for (unsigned int i = 0; i < ATABLE_SIZE; ++i) |
559 |
adx |
30 |
{ |
560 |
michael |
4815 |
DLINK_FOREACH(node, atable[i].head) |
561 |
adx |
30 |
{ |
562 |
michael |
4815 |
const struct AddressRec *arec = node->data; |
563 |
michael |
1367 |
|
564 |
michael |
1632 |
if (arec->type != CONF_DLINE) |
565 |
|
|
continue; |
566 |
adx |
30 |
|
567 |
michael |
7471 |
const struct MaskItem *conf = arec->conf; |
568 |
michael |
5542 |
/* Don't report a permanent dline as temporary dline */ |
569 |
michael |
8603 |
if (conf->until == 0) |
570 |
michael |
1632 |
continue; |
571 |
adx |
30 |
|
572 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_STATSDLINE, 'd', conf->host, conf->reason); |
573 |
adx |
30 |
} |
574 |
|
|
} |
575 |
|
|
} |
576 |
|
|
|
577 |
|
|
/* stats_exempt() |
578 |
|
|
* |
579 |
|
|
* input - client to report to |
580 |
|
|
* output - none |
581 |
|
|
* side effects - client is given list of exempt blocks |
582 |
|
|
*/ |
583 |
|
|
static void |
584 |
michael |
1457 |
stats_exempt(struct Client *source_p, int parc, char *parv[]) |
585 |
adx |
30 |
{ |
586 |
michael |
7687 |
dlink_node *node; |
587 |
adx |
30 |
|
588 |
michael |
4340 |
if (ConfigGeneral.stats_e_disabled) |
589 |
michael |
584 |
{ |
590 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
591 |
michael |
584 |
return; |
592 |
|
|
} |
593 |
|
|
|
594 |
michael |
3246 |
for (unsigned int i = 0; i < ATABLE_SIZE; ++i) |
595 |
adx |
30 |
{ |
596 |
michael |
4815 |
DLINK_FOREACH(node, atable[i].head) |
597 |
adx |
30 |
{ |
598 |
michael |
4815 |
const struct AddressRec *arec = node->data; |
599 |
michael |
1367 |
|
600 |
michael |
1632 |
if (arec->type != CONF_EXEMPT) |
601 |
|
|
continue; |
602 |
adx |
30 |
|
603 |
michael |
7471 |
const struct MaskItem *conf = arec->conf; |
604 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_STATSDLINE, 'e', conf->host, ""); |
605 |
adx |
30 |
} |
606 |
|
|
} |
607 |
|
|
} |
608 |
|
|
|
609 |
|
|
static void |
610 |
michael |
1457 |
stats_events(struct Client *source_p, int parc, char *parv[]) |
611 |
adx |
30 |
{ |
612 |
michael |
7687 |
dlink_node *node; |
613 |
michael |
6306 |
|
614 |
|
|
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
615 |
|
|
"E :Operation Next Execution"); |
616 |
|
|
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
617 |
|
|
"E :---------------------------------------------"); |
618 |
|
|
|
619 |
|
|
DLINK_FOREACH(node, event_get_list()->head) |
620 |
|
|
{ |
621 |
|
|
const struct event *ev = node->data; |
622 |
|
|
|
623 |
|
|
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
624 |
michael |
8937 |
"E :%-30s %-4ju seconds", |
625 |
michael |
8900 |
ev->name, ev->next - event_base->time.sec_monotonic); |
626 |
michael |
6306 |
} |
627 |
adx |
30 |
} |
628 |
|
|
|
629 |
|
|
static void |
630 |
michael |
8379 |
stats_fdlist(struct Client *source_p, int parc, char *parv[]) |
631 |
|
|
{ |
632 |
|
|
for (int fd = 0; fd <= highest_fd; ++fd) |
633 |
|
|
{ |
634 |
|
|
const fde_t *F = &fd_table[fd]; |
635 |
|
|
|
636 |
michael |
8658 |
if (F->flags.open == true) |
637 |
michael |
8379 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
638 |
|
|
"F :fd %-5d desc '%s'", F->fd, F->desc); |
639 |
|
|
} |
640 |
|
|
} |
641 |
|
|
|
642 |
|
|
static void |
643 |
michael |
1457 |
stats_hubleaf(struct Client *source_p, int parc, char *parv[]) |
644 |
adx |
30 |
{ |
645 |
michael |
7687 |
dlink_node *node, *node2; |
646 |
michael |
2118 |
|
647 |
michael |
7401 |
DLINK_FOREACH(node, connect_items.head) |
648 |
michael |
2118 |
{ |
649 |
michael |
4815 |
const struct MaskItem *conf = node->data; |
650 |
michael |
2118 |
|
651 |
michael |
7460 |
DLINK_FOREACH(node2, conf->hub_list.head) |
652 |
|
|
sendto_one_numeric(source_p, &me, RPL_STATSHLINE, 'H', node2->data, conf->name, 0, "*"); |
653 |
michael |
2118 |
} |
654 |
|
|
|
655 |
michael |
7401 |
DLINK_FOREACH(node, connect_items.head) |
656 |
michael |
2118 |
{ |
657 |
michael |
4815 |
const struct MaskItem *conf = node->data; |
658 |
michael |
2118 |
|
659 |
michael |
7460 |
DLINK_FOREACH(node2, conf->leaf_list.head) |
660 |
|
|
sendto_one_numeric(source_p, &me, RPL_STATSLLINE, 'L', node2->data, conf->name, 0, "*"); |
661 |
michael |
2118 |
} |
662 |
adx |
30 |
} |
663 |
|
|
|
664 |
michael |
1372 |
/* |
665 |
|
|
* show_iline_prefix() |
666 |
|
|
* |
667 |
|
|
* inputs - pointer to struct Client requesting output |
668 |
michael |
2820 |
* - pointer to struct MaskItem |
669 |
michael |
1372 |
* - name to which iline prefix will be prefixed to |
670 |
|
|
* output - pointer to static string with prefixes listed in ascii form |
671 |
|
|
* side effects - NONE |
672 |
|
|
*/ |
673 |
|
|
static const char * |
674 |
michael |
6506 |
show_iline_prefix(const struct Client *source_p, const struct MaskItem *conf) |
675 |
michael |
1372 |
{ |
676 |
michael |
7460 |
static char buf[USERLEN + 16]; |
677 |
|
|
char *p = buf; |
678 |
michael |
1372 |
|
679 |
michael |
1715 |
if (IsConfWebIRC(conf)) |
680 |
michael |
7460 |
*p++ = '<'; |
681 |
michael |
1632 |
if (IsNoTilde(conf)) |
682 |
michael |
7460 |
*p++ = '-'; |
683 |
michael |
1632 |
if (IsNeedIdentd(conf)) |
684 |
michael |
7460 |
*p++ = '+'; |
685 |
michael |
1632 |
if (!IsNeedPassword(conf)) |
686 |
michael |
7460 |
*p++ = '&'; |
687 |
michael |
1632 |
if (IsConfExemptResv(conf)) |
688 |
michael |
7460 |
*p++ = '$'; |
689 |
michael |
1632 |
if (IsConfDoSpoofIp(conf)) |
690 |
michael |
7460 |
*p++ = '='; |
691 |
|
|
if (IsConfCanFlood(conf)) |
692 |
|
|
*p++ = '|'; |
693 |
michael |
6506 |
if (HasUMode(source_p, UMODE_OPER)) |
694 |
|
|
{ |
695 |
|
|
if (IsConfExemptKline(conf)) |
696 |
michael |
7460 |
*p++ = '^'; |
697 |
michael |
6506 |
if (IsConfExemptXline(conf)) |
698 |
michael |
7460 |
*p++ = '!'; |
699 |
michael |
6506 |
if (IsConfExemptLimits(conf)) |
700 |
michael |
7460 |
*p++ = '>'; |
701 |
michael |
6506 |
} |
702 |
|
|
|
703 |
michael |
7511 |
strlcpy(p, conf->user, USERLEN + 1); |
704 |
michael |
7460 |
return buf; |
705 |
michael |
1372 |
} |
706 |
|
|
|
707 |
adx |
30 |
static void |
708 |
michael |
9319 |
stats_auth(struct Client *source_p, int parc, char *parv[]) |
709 |
michael |
1372 |
{ |
710 |
michael |
7687 |
dlink_node *node; |
711 |
michael |
1372 |
|
712 |
michael |
9319 |
/* Oper only, if unopered, return ERR_NOPRIVILEGES */ |
713 |
|
|
if (ConfigGeneral.stats_i_oper_only && !HasUMode(source_p, UMODE_OPER)) |
714 |
|
|
{ |
715 |
|
|
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
716 |
|
|
return; |
717 |
|
|
} |
718 |
|
|
|
719 |
michael |
3246 |
for (unsigned int i = 0; i < ATABLE_SIZE; ++i) |
720 |
michael |
1372 |
{ |
721 |
michael |
4815 |
DLINK_FOREACH(node, atable[i].head) |
722 |
michael |
1372 |
{ |
723 |
michael |
4815 |
const struct AddressRec *arec = node->data; |
724 |
michael |
1372 |
|
725 |
michael |
1632 |
if (arec->type != CONF_CLIENT) |
726 |
|
|
continue; |
727 |
michael |
1372 |
|
728 |
michael |
7471 |
const struct MaskItem *conf = arec->conf; |
729 |
michael |
9315 |
if (IsConfDoSpoofIp(conf) && !HasUMode(source_p, UMODE_OPER)) |
730 |
michael |
1632 |
continue; |
731 |
michael |
1372 |
|
732 |
michael |
4967 |
sendto_one_numeric(source_p, &me, RPL_STATSILINE, 'I', |
733 |
|
|
conf->name == NULL ? "*" : conf->name, |
734 |
|
|
show_iline_prefix(source_p, conf), |
735 |
|
|
conf->host, conf->port, |
736 |
|
|
conf->class->name); |
737 |
michael |
1372 |
} |
738 |
|
|
} |
739 |
|
|
} |
740 |
|
|
|
741 |
|
|
/* report_Klines() |
742 |
|
|
* Inputs: Client to report to, |
743 |
|
|
* type(==0 for perm, !=0 for temporary) |
744 |
michael |
2820 |
* mask |
745 |
michael |
1372 |
* Output: None |
746 |
michael |
3156 |
* Side effects: Reports configured K(or k)-lines to source_p. |
747 |
michael |
1372 |
*/ |
748 |
adx |
30 |
static void |
749 |
michael |
9319 |
stats_kill(struct Client *source_p, int parc, char *parv[]) |
750 |
michael |
1372 |
{ |
751 |
michael |
7687 |
dlink_node *node; |
752 |
michael |
1372 |
|
753 |
michael |
9319 |
/* Oper only, if unopered, return ERR_NOPRIVILEGES */ |
754 |
|
|
if (ConfigGeneral.stats_k_oper_only && !HasUMode(source_p, UMODE_OPER)) |
755 |
|
|
{ |
756 |
|
|
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
757 |
|
|
return; |
758 |
|
|
} |
759 |
michael |
1372 |
|
760 |
michael |
3246 |
for (unsigned int i = 0; i < ATABLE_SIZE; ++i) |
761 |
michael |
1372 |
{ |
762 |
michael |
4815 |
DLINK_FOREACH(node, atable[i].head) |
763 |
michael |
1372 |
{ |
764 |
michael |
4815 |
const struct AddressRec *arec = node->data; |
765 |
michael |
1372 |
|
766 |
michael |
1632 |
if (arec->type != CONF_KLINE) |
767 |
|
|
continue; |
768 |
michael |
1628 |
|
769 |
michael |
7471 |
const struct MaskItem *conf = arec->conf; |
770 |
michael |
9319 |
/* Don't report a temporary kline as permanent kline */ |
771 |
|
|
if (conf->until) |
772 |
michael |
1632 |
continue; |
773 |
|
|
|
774 |
michael |
9319 |
sendto_one_numeric(source_p, &me, RPL_STATSKLINE, 'K', conf->host, conf->user, |
775 |
michael |
4570 |
conf->reason); |
776 |
michael |
1372 |
} |
777 |
|
|
} |
778 |
|
|
} |
779 |
|
|
|
780 |
|
|
static void |
781 |
michael |
9319 |
stats_tkill(struct Client *source_p, int parc, char *parv[]) |
782 |
adx |
30 |
{ |
783 |
michael |
9319 |
dlink_node *node; |
784 |
|
|
|
785 |
adx |
30 |
/* Oper only, if unopered, return ERR_NOPRIVILEGES */ |
786 |
michael |
9319 |
if (ConfigGeneral.stats_k_oper_only && !HasUMode(source_p, UMODE_OPER)) |
787 |
|
|
{ |
788 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
789 |
michael |
9319 |
return; |
790 |
adx |
30 |
} |
791 |
|
|
|
792 |
michael |
9319 |
for (unsigned int i = 0; i < ATABLE_SIZE; ++i) |
793 |
adx |
30 |
{ |
794 |
michael |
9319 |
DLINK_FOREACH(node, atable[i].head) |
795 |
|
|
{ |
796 |
|
|
const struct AddressRec *arec = node->data; |
797 |
adx |
30 |
|
798 |
michael |
9319 |
if (arec->type != CONF_KLINE) |
799 |
|
|
continue; |
800 |
adx |
30 |
|
801 |
michael |
9319 |
const struct MaskItem *conf = arec->conf; |
802 |
|
|
/* Don't report a permanent kline as temporary kline */ |
803 |
|
|
if (conf->until == 0) |
804 |
|
|
continue; |
805 |
adx |
30 |
|
806 |
michael |
9319 |
sendto_one_numeric(source_p, &me, RPL_STATSKLINE, 'k', conf->host, conf->user, |
807 |
|
|
conf->reason); |
808 |
|
|
} |
809 |
adx |
30 |
} |
810 |
|
|
} |
811 |
|
|
|
812 |
|
|
static void |
813 |
michael |
1457 |
stats_messages(struct Client *source_p, int parc, char *parv[]) |
814 |
adx |
30 |
{ |
815 |
michael |
5026 |
if (!HasUMode(source_p, UMODE_OPER) && ConfigGeneral.stats_m_oper_only) |
816 |
|
|
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
817 |
|
|
else |
818 |
|
|
report_messages(source_p); |
819 |
adx |
30 |
} |
820 |
|
|
|
821 |
michael |
8453 |
static void |
822 |
|
|
stats_pseudo(struct Client *source_p, int parc, char *parv[]) |
823 |
|
|
{ |
824 |
michael |
8458 |
dlink_node *node; |
825 |
|
|
|
826 |
|
|
DLINK_FOREACH(node, pseudo_get_list()->head) |
827 |
|
|
{ |
828 |
|
|
const struct PseudoItem *pseudo = node->data; |
829 |
|
|
sendto_one_numeric(source_p, &me, RPL_STATSPSEUDO, pseudo->command, |
830 |
|
|
pseudo->name, pseudo->nick, pseudo->serv, |
831 |
|
|
pseudo->prepend ? pseudo->prepend : "*"); |
832 |
|
|
} |
833 |
michael |
8453 |
} |
834 |
|
|
|
835 |
adx |
30 |
/* stats_operedup() |
836 |
|
|
* |
837 |
|
|
* input - client pointer |
838 |
|
|
* output - none |
839 |
|
|
* side effects - client is shown a list of active opers |
840 |
|
|
*/ |
841 |
|
|
static void |
842 |
michael |
1457 |
stats_operedup(struct Client *source_p, int parc, char *parv[]) |
843 |
adx |
30 |
{ |
844 |
michael |
7687 |
dlink_node *node; |
845 |
michael |
9314 |
char buf[32]; |
846 |
michael |
3511 |
unsigned int opercount = 0; |
847 |
adx |
30 |
|
848 |
michael |
4815 |
DLINK_FOREACH(node, oper_list.head) |
849 |
adx |
30 |
{ |
850 |
michael |
4815 |
const struct Client *target_p = node->data; |
851 |
adx |
30 |
|
852 |
michael |
1294 |
if (HasUMode(target_p, UMODE_HIDDEN) && !HasUMode(source_p, UMODE_OPER)) |
853 |
adx |
30 |
continue; |
854 |
|
|
|
855 |
michael |
3516 |
if (HasUMode(source_p, UMODE_OPER) || !HasUMode(target_p, UMODE_HIDEIDLE)) |
856 |
michael |
6846 |
snprintf(buf, sizeof(buf), "%s", time_dissect(client_get_idle_time(source_p, target_p))); |
857 |
michael |
3516 |
else |
858 |
|
|
strlcpy(buf, "n/a", sizeof(buf)); |
859 |
|
|
|
860 |
michael |
7051 |
if (MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) |
861 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
862 |
michael |
3573 |
"p :[%c][%s] %s (%s@%s) Idle: %s", |
863 |
|
|
HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O', |
864 |
michael |
4588 |
oper_privs_as_string(target_p->connection->operflags), |
865 |
michael |
3573 |
target_p->name, target_p->username, target_p->host, buf); |
866 |
adx |
30 |
else |
867 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
868 |
michael |
3573 |
"p :[%c] %s (%s@%s) Idle: %s", |
869 |
|
|
HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O', |
870 |
|
|
target_p->name, target_p->username, target_p->host, buf); |
871 |
michael |
3511 |
++opercount; |
872 |
adx |
30 |
} |
873 |
|
|
|
874 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
875 |
michael |
3573 |
"p :%u OPER(s)", opercount); |
876 |
adx |
30 |
} |
877 |
|
|
|
878 |
michael |
6366 |
/* show_ports() |
879 |
|
|
* |
880 |
|
|
* inputs - pointer to client to show ports to |
881 |
|
|
* output - none |
882 |
|
|
* side effects - send port listing to a client |
883 |
|
|
*/ |
884 |
adx |
30 |
static void |
885 |
michael |
9322 |
stats_ports(struct Client *source_p, int parc, char *parv[]) |
886 |
michael |
6366 |
{ |
887 |
michael |
7687 |
dlink_node *node; |
888 |
michael |
6366 |
|
889 |
michael |
9322 |
if (ConfigGeneral.stats_P_oper_only && !HasUMode(source_p, UMODE_OPER)) |
890 |
|
|
{ |
891 |
|
|
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
892 |
|
|
return; |
893 |
|
|
} |
894 |
|
|
|
895 |
michael |
6366 |
DLINK_FOREACH(node, listener_get_list()->head) |
896 |
|
|
{ |
897 |
michael |
7687 |
char buf[8]; |
898 |
|
|
char *p = buf; |
899 |
michael |
6366 |
const struct Listener *listener = node->data; |
900 |
|
|
|
901 |
|
|
if (listener->flags & LISTENER_HIDDEN) |
902 |
|
|
{ |
903 |
|
|
if (!HasUMode(source_p, UMODE_ADMIN)) |
904 |
|
|
continue; |
905 |
|
|
*p++ = 'H'; |
906 |
|
|
} |
907 |
|
|
|
908 |
|
|
if (listener->flags & LISTENER_SERVER) |
909 |
|
|
*p++ = 'S'; |
910 |
michael |
9157 |
if (listener->flags & LISTENER_TLS) |
911 |
|
|
*p++ = 'T'; |
912 |
michael |
6366 |
*p = '\0'; |
913 |
|
|
|
914 |
michael |
9038 |
if (HasUMode(source_p, UMODE_ADMIN) && ConfigServerHide.hide_server_ips == 0) |
915 |
michael |
6366 |
sendto_one_numeric(source_p, &me, RPL_STATSPLINE, 'P', listener->port, |
916 |
|
|
listener->name, |
917 |
|
|
listener->ref_count, buf, |
918 |
|
|
listener->active ? "active" : "disabled"); |
919 |
|
|
else |
920 |
|
|
sendto_one_numeric(source_p, &me, RPL_STATSPLINE, 'P', listener->port, |
921 |
|
|
me.name, listener->ref_count, buf, |
922 |
|
|
listener->active ? "active" : "disabled"); |
923 |
|
|
} |
924 |
|
|
} |
925 |
|
|
|
926 |
|
|
static void |
927 |
michael |
1457 |
stats_tstats(struct Client *source_p, int parc, char *parv[]) |
928 |
adx |
30 |
{ |
929 |
michael |
7687 |
dlink_node *node; |
930 |
michael |
9003 |
struct ServerStatistics sp = ServerStats; |
931 |
michael |
896 |
|
932 |
michael |
4815 |
DLINK_FOREACH(node, local_server_list.head) |
933 |
michael |
896 |
{ |
934 |
michael |
4815 |
const struct Client *target_p = node->data; |
935 |
michael |
896 |
|
936 |
michael |
8409 |
sp.is_sbs += target_p->connection->send.bytes; |
937 |
|
|
sp.is_sbr += target_p->connection->recv.bytes; |
938 |
michael |
8919 |
sp.is_sti += event_base->time.sec_monotonic - target_p->connection->created_monotonic; |
939 |
michael |
8409 |
sp.is_sv++; |
940 |
michael |
896 |
} |
941 |
|
|
|
942 |
michael |
4815 |
DLINK_FOREACH(node, local_client_list.head) |
943 |
michael |
896 |
{ |
944 |
michael |
4815 |
const struct Client *target_p = node->data; |
945 |
michael |
896 |
|
946 |
michael |
8409 |
sp.is_cbs += target_p->connection->send.bytes; |
947 |
|
|
sp.is_cbr += target_p->connection->recv.bytes; |
948 |
michael |
8919 |
sp.is_cti += event_base->time.sec_monotonic - target_p->connection->created_monotonic; |
949 |
michael |
8409 |
sp.is_cl++; |
950 |
michael |
896 |
} |
951 |
|
|
|
952 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
953 |
michael |
4040 |
"t :accepts %u refused %u", |
954 |
michael |
8409 |
sp.is_ac, sp.is_ref); |
955 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
956 |
michael |
4040 |
"t :unknown commands %u prefixes %u", |
957 |
michael |
8409 |
sp.is_unco, sp.is_unpf); |
958 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
959 |
michael |
4040 |
"t :nick collisions %u unknown closes %u", |
960 |
michael |
8409 |
sp.is_kill, sp.is_ni); |
961 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
962 |
michael |
4040 |
"t :wrong direction %u empty %u", |
963 |
michael |
8409 |
sp.is_wrdi, sp.is_empt); |
964 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
965 |
michael |
4040 |
"t :numerics seen %u", |
966 |
michael |
8409 |
sp.is_num); |
967 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
968 |
michael |
4040 |
"t :auth successes %u fails %u", |
969 |
michael |
8409 |
sp.is_asuc, sp.is_abad); |
970 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
971 |
michael |
4040 |
"t :Client Server"); |
972 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
973 |
michael |
4040 |
"t :connected %u %u", |
974 |
michael |
8409 |
sp.is_cl, sp.is_sv); |
975 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
976 |
michael |
6782 |
"t :bytes sent %ju %ju", |
977 |
michael |
8409 |
sp.is_cbs, sp.is_sbs); |
978 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
979 |
michael |
7471 |
"t :bytes received %ju %ju", |
980 |
michael |
8409 |
sp.is_cbr, sp.is_sbr); |
981 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
982 |
michael |
7330 |
"t :time connected %ju %ju", |
983 |
michael |
8409 |
sp.is_cti, sp.is_sti); |
984 |
adx |
30 |
} |
985 |
|
|
|
986 |
|
|
static void |
987 |
michael |
1457 |
stats_uptime(struct Client *source_p, int parc, char *parv[]) |
988 |
adx |
30 |
{ |
989 |
michael |
4340 |
if (!HasUMode(source_p, UMODE_OPER) && ConfigGeneral.stats_u_oper_only) |
990 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
991 |
michael |
2269 |
else |
992 |
|
|
{ |
993 |
michael |
6569 |
sendto_one_numeric(source_p, &me, RPL_STATSUPTIME, |
994 |
michael |
8919 |
time_dissect(event_base->time.sec_monotonic - me.connection->created_monotonic)); |
995 |
michael |
8603 |
if (ConfigServerHide.disable_remote_commands == 0 || HasUMode(source_p, UMODE_OPER)) |
996 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_STATSCONN, Count.max_loc_con, |
997 |
michael |
7999 |
Count.max_loc, Count.totalrestartcount); |
998 |
michael |
2269 |
} |
999 |
adx |
30 |
} |
1000 |
|
|
|
1001 |
|
|
static void |
1002 |
michael |
1457 |
stats_shared(struct Client *source_p, int parc, char *parv[]) |
1003 |
adx |
30 |
{ |
1004 |
michael |
7209 |
report_shared(source_p); |
1005 |
|
|
report_cluster(source_p); |
1006 |
adx |
30 |
} |
1007 |
|
|
|
1008 |
|
|
/* stats_servers() |
1009 |
|
|
* |
1010 |
|
|
* input - client pointer |
1011 |
|
|
* output - none |
1012 |
|
|
* side effects - client is shown lists of who connected servers |
1013 |
|
|
*/ |
1014 |
|
|
static void |
1015 |
michael |
1457 |
stats_servers(struct Client *source_p, int parc, char *parv[]) |
1016 |
adx |
30 |
{ |
1017 |
michael |
7687 |
dlink_node *node; |
1018 |
adx |
30 |
|
1019 |
michael |
4815 |
DLINK_FOREACH(node, local_server_list.head) |
1020 |
adx |
30 |
{ |
1021 |
michael |
4815 |
const struct Client *target_p = node->data; |
1022 |
adx |
30 |
|
1023 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
1024 |
michael |
6846 |
"v :%s (%s!%s@%s) Idle: %s", |
1025 |
michael |
3573 |
target_p->name, |
1026 |
|
|
(target_p->serv->by[0] ? target_p->serv->by : "Remote."), |
1027 |
michael |
8919 |
"*", "*", time_dissect(event_base->time.sec_monotonic - target_p->connection->last_data)); |
1028 |
adx |
30 |
} |
1029 |
|
|
|
1030 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
1031 |
michael |
4213 |
"v :%u Server(s)", |
1032 |
|
|
dlink_list_length(&local_server_list)); |
1033 |
adx |
30 |
} |
1034 |
|
|
|
1035 |
|
|
static void |
1036 |
michael |
1457 |
stats_class(struct Client *source_p, int parc, char *parv[]) |
1037 |
adx |
30 |
{ |
1038 |
michael |
7914 |
dlink_node *node; |
1039 |
michael |
2116 |
|
1040 |
michael |
4815 |
DLINK_FOREACH(node, class_get_list()->head) |
1041 |
michael |
2116 |
{ |
1042 |
michael |
4815 |
const struct ClassItem *class = node->data; |
1043 |
michael |
2116 |
|
1044 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_STATSYLINE, 'Y', |
1045 |
|
|
class->name, class->ping_freq, |
1046 |
|
|
class->con_freq, |
1047 |
|
|
class->max_total, class->max_sendq, |
1048 |
|
|
class->max_recvq, |
1049 |
|
|
class->ref_count, |
1050 |
|
|
class->number_per_cidr, class->cidr_bitlen_ipv4, |
1051 |
|
|
class->number_per_cidr, class->cidr_bitlen_ipv6, |
1052 |
|
|
class->active ? "active" : "disabled"); |
1053 |
michael |
2116 |
} |
1054 |
adx |
30 |
} |
1055 |
|
|
|
1056 |
|
|
static void |
1057 |
michael |
1457 |
stats_servlinks(struct Client *source_p, int parc, char *parv[]) |
1058 |
adx |
30 |
{ |
1059 |
michael |
7471 |
dlink_node *node; |
1060 |
michael |
6782 |
uintmax_t sendB = 0, recvB = 0; |
1061 |
adx |
30 |
|
1062 |
michael |
4815 |
DLINK_FOREACH(node, local_server_list.head) |
1063 |
adx |
30 |
{ |
1064 |
michael |
7471 |
const struct Client *target_p = node->data; |
1065 |
adx |
30 |
|
1066 |
michael |
4588 |
sendB += target_p->connection->send.bytes; |
1067 |
|
|
recvB += target_p->connection->recv.bytes; |
1068 |
adx |
30 |
|
1069 |
michael |
8923 |
/* ":%s 211 %s %s %u %u %ju %u %ju :%ju %ju %s" */ |
1070 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_STATSLINKINFO, |
1071 |
michael |
7997 |
client_get_name(target_p, HasUMode(source_p, UMODE_ADMIN) ? SHOW_IP : MASK_IP), |
1072 |
michael |
4588 |
dbuf_length(&target_p->connection->buf_sendq), |
1073 |
|
|
target_p->connection->send.messages, |
1074 |
|
|
target_p->connection->send.bytes >> 10, |
1075 |
|
|
target_p->connection->recv.messages, |
1076 |
|
|
target_p->connection->recv.bytes >> 10, |
1077 |
michael |
8923 |
(event_base->time.sec_monotonic - target_p->connection->created_monotonic), |
1078 |
|
|
(event_base->time.sec_monotonic - target_p->connection->last_data), |
1079 |
michael |
9558 |
capab_get(target_p)); |
1080 |
adx |
30 |
} |
1081 |
|
|
|
1082 |
|
|
sendB >>= 10; |
1083 |
|
|
recvB >>= 10; |
1084 |
|
|
|
1085 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, "? :%u total server(s)", |
1086 |
michael |
4213 |
dlink_list_length(&local_server_list)); |
1087 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, "? :Sent total: %7.2f %s", |
1088 |
michael |
3573 |
_GMKv(sendB), _GMKs(sendB)); |
1089 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, "? :Recv total: %7.2f %s", |
1090 |
michael |
3573 |
_GMKv(recvB), _GMKs(recvB)); |
1091 |
adx |
30 |
|
1092 |
michael |
9558 |
const uintmax_t uptime = (event_base->time.sec_monotonic - me.connection->created_monotonic); |
1093 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
1094 |
michael |
9023 |
"? :Server send: %7.2f %s (%4.1f KiB/s)", |
1095 |
michael |
7382 |
_GMKv((me.connection->send.bytes >> 10)), |
1096 |
|
|
_GMKs((me.connection->send.bytes >> 10)), |
1097 |
michael |
4588 |
(float)((float)((me.connection->send.bytes) >> 10) / |
1098 |
michael |
3573 |
(float)uptime)); |
1099 |
michael |
5583 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
1100 |
michael |
9023 |
"? :Server recv: %7.2f %s (%4.1f KiB/s)", |
1101 |
michael |
7382 |
_GMKv((me.connection->recv.bytes >> 10)), |
1102 |
|
|
_GMKs((me.connection->recv.bytes >> 10)), |
1103 |
michael |
4588 |
(float)((float)((me.connection->recv.bytes) >> 10) / |
1104 |
michael |
3573 |
(float)uptime)); |
1105 |
adx |
30 |
} |
1106 |
|
|
|
1107 |
michael |
1457 |
/* parse_stats_args() |
1108 |
|
|
* |
1109 |
|
|
* inputs - arg count |
1110 |
|
|
* - args |
1111 |
|
|
* - doall flag |
1112 |
|
|
* - wild card or not |
1113 |
|
|
* output - pointer to name to use |
1114 |
|
|
* side effects - |
1115 |
|
|
* common parse routine for m_stats args |
1116 |
michael |
2820 |
* |
1117 |
michael |
1457 |
*/ |
1118 |
michael |
4755 |
static const char * |
1119 |
michael |
8658 |
parse_stats_args(struct Client *source_p, int parc, char *parv[], bool *doall, bool *wilds) |
1120 |
adx |
30 |
{ |
1121 |
michael |
1457 |
if (parc > 2) |
1122 |
adx |
30 |
{ |
1123 |
michael |
4755 |
const char *name = parv[2]; |
1124 |
adx |
30 |
|
1125 |
michael |
8603 |
if (irccmp(name, ID_or_name(&me, source_p)) == 0) |
1126 |
michael |
8658 |
*doall = true; |
1127 |
michael |
8603 |
else if (match(name, ID_or_name(&me, source_p)) == 0) |
1128 |
michael |
8658 |
*doall = true; |
1129 |
michael |
1457 |
|
1130 |
|
|
*wilds = has_wildcards(name); |
1131 |
|
|
|
1132 |
|
|
return name; |
1133 |
adx |
30 |
} |
1134 |
|
|
|
1135 |
michael |
1457 |
return NULL; |
1136 |
adx |
30 |
} |
1137 |
|
|
|
1138 |
|
|
static void |
1139 |
michael |
8658 |
stats_L_list(struct Client *source_p, const char *name, bool doall, bool wilds, |
1140 |
michael |
4755 |
dlink_list *list, const char statchar) |
1141 |
adx |
30 |
{ |
1142 |
michael |
7471 |
dlink_node *node; |
1143 |
adx |
30 |
|
1144 |
|
|
/* |
1145 |
michael |
4034 |
* Send info about connections which match, or all if the |
1146 |
michael |
7652 |
* mask matches from. |
1147 |
adx |
30 |
*/ |
1148 |
michael |
4815 |
DLINK_FOREACH(node, list->head) |
1149 |
adx |
30 |
{ |
1150 |
michael |
7471 |
const struct Client *target_p = node->data; |
1151 |
michael |
9071 |
enum addr_mask_type type; |
1152 |
adx |
30 |
|
1153 |
michael |
1652 |
if (!doall && wilds && match(name, target_p->name)) |
1154 |
adx |
30 |
continue; |
1155 |
michael |
4034 |
|
1156 |
adx |
30 |
if (!(doall || wilds) && irccmp(name, target_p->name)) |
1157 |
|
|
continue; |
1158 |
|
|
|
1159 |
michael |
7652 |
if (IsUpper(statchar)) |
1160 |
|
|
type = SHOW_IP; |
1161 |
adx |
30 |
else |
1162 |
michael |
7652 |
type = HIDE_IP; |
1163 |
|
|
|
1164 |
|
|
if (IsServer(target_p) || IsConnecting(target_p) || IsHandshake(target_p)) |
1165 |
michael |
7654 |
if (!HasUMode(source_p, UMODE_ADMIN)) |
1166 |
michael |
7652 |
type = MASK_IP; |
1167 |
|
|
|
1168 |
|
|
sendto_one_numeric(source_p, &me, RPL_STATSLINKINFO, |
1169 |
michael |
7997 |
client_get_name(target_p, type), |
1170 |
michael |
7652 |
dbuf_length(&target_p->connection->buf_sendq), |
1171 |
|
|
target_p->connection->send.messages, |
1172 |
|
|
target_p->connection->send.bytes >> 10, |
1173 |
|
|
target_p->connection->recv.messages, |
1174 |
|
|
target_p->connection->recv.bytes >> 10, |
1175 |
michael |
8923 |
(event_base->time.sec_monotonic - target_p->connection->created_monotonic), |
1176 |
|
|
(event_base->time.sec_monotonic - target_p->connection->last_data), |
1177 |
michael |
8166 |
IsServer(target_p) ? capab_get(target_p) : "-"); |
1178 |
adx |
30 |
} |
1179 |
|
|
} |
1180 |
|
|
|
1181 |
michael |
1457 |
/* |
1182 |
|
|
* stats_L |
1183 |
adx |
30 |
* |
1184 |
michael |
1457 |
* inputs - pointer to client to report to |
1185 |
|
|
* - doall flag |
1186 |
|
|
* - wild card or not |
1187 |
|
|
* output - NONE |
1188 |
|
|
* side effects - |
1189 |
|
|
*/ |
1190 |
|
|
static void |
1191 |
michael |
8658 |
stats_L(struct Client *source_p, const char *name, bool doall, |
1192 |
|
|
bool wilds, const char statchar) |
1193 |
michael |
1457 |
{ |
1194 |
|
|
stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar); |
1195 |
|
|
stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar); |
1196 |
michael |
4213 |
stats_L_list(source_p, name, doall, wilds, &local_server_list, statchar); |
1197 |
michael |
1457 |
} |
1198 |
|
|
|
1199 |
|
|
static void |
1200 |
|
|
stats_ltrace(struct Client *source_p, int parc, char *parv[]) |
1201 |
|
|
{ |
1202 |
michael |
8658 |
bool doall = false; |
1203 |
|
|
bool wilds = false; |
1204 |
michael |
9071 |
const char *name; |
1205 |
michael |
1457 |
|
1206 |
michael |
3246 |
if ((name = parse_stats_args(source_p, parc, parv, &doall, &wilds))) |
1207 |
michael |
1457 |
{ |
1208 |
michael |
4755 |
const char statchar = *parv[1]; |
1209 |
michael |
1457 |
stats_L(source_p, name, doall, wilds, statchar); |
1210 |
|
|
} |
1211 |
|
|
else |
1212 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "STATS"); |
1213 |
michael |
1457 |
} |
1214 |
|
|
|
1215 |
michael |
6552 |
struct StatsStruct |
1216 |
michael |
1457 |
{ |
1217 |
michael |
9076 |
unsigned char letter; |
1218 |
michael |
4479 |
void (*handler)(struct Client *, int, char *[]); |
1219 |
michael |
9076 |
unsigned int required_modes; |
1220 |
michael |
1457 |
}; |
1221 |
|
|
|
1222 |
michael |
6552 |
static const struct StatsStruct *stats_map[256]; |
1223 |
|
|
static const struct StatsStruct stats_tab[] = |
1224 |
|
|
{ |
1225 |
michael |
9070 |
{ .letter = 'a', .handler = stats_dns_servers, .required_modes = UMODE_ADMIN }, |
1226 |
|
|
{ .letter = 'A', .handler = stats_dns_servers, .required_modes = UMODE_ADMIN }, |
1227 |
|
|
{ .letter = 'c', .handler = stats_connect, .required_modes = UMODE_OPER }, |
1228 |
|
|
{ .letter = 'C', .handler = stats_connect, .required_modes = UMODE_OPER }, |
1229 |
|
|
{ .letter = 'd', .handler = stats_tdeny, .required_modes = UMODE_OPER }, |
1230 |
|
|
{ .letter = 'D', .handler = stats_deny, .required_modes = UMODE_OPER }, |
1231 |
|
|
{ .letter = 'e', .handler = stats_exempt, .required_modes = UMODE_OPER }, |
1232 |
|
|
{ .letter = 'E', .handler = stats_events, .required_modes = UMODE_ADMIN }, |
1233 |
|
|
{ .letter = 'f', .handler = stats_fdlist, .required_modes = UMODE_ADMIN }, |
1234 |
|
|
{ .letter = 'F', .handler = stats_fdlist, .required_modes = UMODE_ADMIN }, |
1235 |
|
|
{ .letter = 'h', .handler = stats_hubleaf, .required_modes = UMODE_OPER }, |
1236 |
|
|
{ .letter = 'H', .handler = stats_hubleaf, .required_modes = UMODE_OPER }, |
1237 |
|
|
{ .letter = 'i', .handler = stats_auth }, |
1238 |
|
|
{ .letter = 'I', .handler = stats_auth }, |
1239 |
michael |
9319 |
{ .letter = 'k', .handler = stats_tkill }, |
1240 |
|
|
{ .letter = 'K', .handler = stats_kill }, |
1241 |
michael |
9070 |
{ .letter = 'l', .handler = stats_ltrace, .required_modes = UMODE_OPER }, |
1242 |
|
|
{ .letter = 'L', .handler = stats_ltrace, .required_modes = UMODE_OPER }, |
1243 |
|
|
{ .letter = 'm', .handler = stats_messages }, |
1244 |
|
|
{ .letter = 'M', .handler = stats_messages }, |
1245 |
|
|
{ .letter = 'o', .handler = stats_operator }, |
1246 |
|
|
{ .letter = 'O', .handler = stats_operator }, |
1247 |
|
|
{ .letter = 'p', .handler = stats_operedup }, |
1248 |
|
|
{ .letter = 'P', .handler = stats_ports }, |
1249 |
|
|
{ .letter = 'q', .handler = stats_resv, .required_modes = UMODE_OPER }, |
1250 |
|
|
{ .letter = 'Q', .handler = stats_resv, .required_modes = UMODE_OPER }, |
1251 |
|
|
{ .letter = 's', .handler = stats_pseudo, .required_modes = UMODE_OPER }, |
1252 |
|
|
{ .letter = 'S', .handler = stats_service, .required_modes = UMODE_OPER }, |
1253 |
|
|
{ .letter = 't', .handler = stats_tstats, .required_modes = UMODE_OPER }, |
1254 |
|
|
{ .letter = 'T', .handler = motd_report, .required_modes = UMODE_OPER }, |
1255 |
|
|
{ .letter = 'u', .handler = stats_uptime }, |
1256 |
|
|
{ .letter = 'U', .handler = stats_shared, .required_modes = UMODE_OPER }, |
1257 |
|
|
{ .letter = 'v', .handler = stats_servers, .required_modes = UMODE_OPER }, |
1258 |
|
|
{ .letter = 'x', .handler = stats_gecos, .required_modes = UMODE_OPER }, |
1259 |
|
|
{ .letter = 'X', .handler = stats_gecos, .required_modes = UMODE_OPER }, |
1260 |
|
|
{ .letter = 'y', .handler = stats_class, .required_modes = UMODE_OPER }, |
1261 |
|
|
{ .letter = 'Y', .handler = stats_class, .required_modes = UMODE_OPER }, |
1262 |
|
|
{ .letter = 'z', .handler = stats_memory, .required_modes = UMODE_OPER }, |
1263 |
michael |
9558 |
{ .letter = '?', .handler = stats_servlinks, .required_modes = UMODE_OPER }, |
1264 |
michael |
9070 |
{ .letter = '\0' } |
1265 |
michael |
6552 |
}; |
1266 |
|
|
|
1267 |
michael |
1457 |
static void |
1268 |
|
|
do_stats(struct Client *source_p, int parc, char *parv[]) |
1269 |
|
|
{ |
1270 |
michael |
6552 |
const unsigned char statchar = *parv[1]; |
1271 |
|
|
const struct StatsStruct *tab; |
1272 |
michael |
1457 |
|
1273 |
|
|
if (statchar == '\0') |
1274 |
|
|
{ |
1275 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_ENDOFSTATS, '*'); |
1276 |
michael |
1457 |
return; |
1277 |
|
|
} |
1278 |
|
|
|
1279 |
michael |
6552 |
if ((tab = stats_map[statchar])) |
1280 |
michael |
1457 |
{ |
1281 |
michael |
8437 |
if (tab->required_modes == 0 || HasUMode(source_p, tab->required_modes)) |
1282 |
michael |
6552 |
tab->handler(source_p, parc, parv); |
1283 |
|
|
else |
1284 |
|
|
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
1285 |
michael |
1457 |
|
1286 |
michael |
6552 |
sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE, |
1287 |
|
|
"STATS %c requested by %s (%s@%s) [%s]", |
1288 |
|
|
statchar, source_p->name, source_p->username, |
1289 |
|
|
source_p->host, source_p->servptr->name); |
1290 |
michael |
1457 |
} |
1291 |
|
|
|
1292 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_ENDOFSTATS, statchar); |
1293 |
michael |
1457 |
} |
1294 |
|
|
|
1295 |
|
|
/* |
1296 |
|
|
* m_stats() |
1297 |
michael |
3096 |
* parv[0] = command |
1298 |
michael |
1457 |
* parv[1] = stat letter/command |
1299 |
|
|
* parv[2] = (if present) server/mask in stats L |
1300 |
adx |
30 |
*/ |
1301 |
michael |
9077 |
static void |
1302 |
michael |
3156 |
m_stats(struct Client *source_p, int parc, char *parv[]) |
1303 |
adx |
30 |
{ |
1304 |
michael |
7330 |
static uintmax_t last_used = 0; |
1305 |
adx |
30 |
|
1306 |
michael |
4298 |
/* Check the user is actually allowed to do /stats, and isn't flooding */ |
1307 |
michael |
8903 |
if ((last_used + ConfigGeneral.pace_wait) > event_base->time.sec_monotonic) |
1308 |
michael |
1457 |
{ |
1309 |
michael |
4759 |
sendto_one_numeric(source_p, &me, RPL_LOAD2HI, "STATS"); |
1310 |
michael |
9077 |
return; |
1311 |
michael |
1457 |
} |
1312 |
adx |
30 |
|
1313 |
michael |
8903 |
last_used = event_base->time.sec_monotonic; |
1314 |
adx |
30 |
|
1315 |
michael |
2341 |
/* Is the stats meant for us? */ |
1316 |
michael |
8603 |
if (ConfigServerHide.disable_remote_commands == 0) |
1317 |
michael |
9397 |
if (server_hunt(source_p, ":%s STATS %s :%s", 2, parv)->ret != HUNTED_ISME) |
1318 |
michael |
9077 |
return; |
1319 |
michael |
2341 |
|
1320 |
michael |
1457 |
do_stats(source_p, parc, parv); |
1321 |
|
|
} |
1322 |
|
|
|
1323 |
|
|
/* |
1324 |
michael |
3219 |
* ms_stats() |
1325 |
michael |
3096 |
* parv[0] = command |
1326 |
michael |
1457 |
* parv[1] = stat letter/command |
1327 |
|
|
* parv[2] = (if present) server/mask in stats L, or target |
1328 |
|
|
*/ |
1329 |
michael |
9077 |
static void |
1330 |
michael |
3219 |
ms_stats(struct Client *source_p, int parc, char *parv[]) |
1331 |
michael |
1457 |
{ |
1332 |
michael |
9397 |
if (server_hunt(source_p, ":%s STATS %s :%s", 2, parv)->ret != HUNTED_ISME) |
1333 |
michael |
9077 |
return; |
1334 |
michael |
1457 |
|
1335 |
|
|
do_stats(source_p, parc, parv); |
1336 |
adx |
30 |
} |
1337 |
michael |
1230 |
|
1338 |
michael |
6552 |
static void |
1339 |
|
|
stats_init(void) |
1340 |
|
|
{ |
1341 |
|
|
for (const struct StatsStruct *tab = stats_tab; tab->letter; ++tab) |
1342 |
|
|
stats_map[tab->letter] = tab; |
1343 |
|
|
} |
1344 |
|
|
|
1345 |
michael |
2820 |
static struct Message stats_msgtab = |
1346 |
|
|
{ |
1347 |
michael |
5881 |
.cmd = "STATS", |
1348 |
michael |
9374 |
.handlers[UNREGISTERED_HANDLER] = { .handler = m_unregistered }, |
1349 |
|
|
.handlers[CLIENT_HANDLER] = { .handler = m_stats, .args_min = 2 }, |
1350 |
|
|
.handlers[SERVER_HANDLER] = { .handler = ms_stats, .args_min = 3 }, |
1351 |
|
|
.handlers[ENCAP_HANDLER] = { .handler = m_ignore }, |
1352 |
|
|
.handlers[OPER_HANDLER] = { .handler = m_stats, .args_min = 2 } |
1353 |
michael |
1230 |
}; |
1354 |
|
|
|
1355 |
|
|
static void |
1356 |
|
|
module_init(void) |
1357 |
|
|
{ |
1358 |
michael |
6552 |
stats_init(); |
1359 |
michael |
1230 |
mod_add_cmd(&stats_msgtab); |
1360 |
|
|
} |
1361 |
|
|
|
1362 |
|
|
static void |
1363 |
|
|
module_exit(void) |
1364 |
|
|
{ |
1365 |
|
|
mod_del_cmd(&stats_msgtab); |
1366 |
|
|
} |
1367 |
|
|
|
1368 |
michael |
2820 |
struct module module_entry = |
1369 |
|
|
{ |
1370 |
michael |
1230 |
.version = "$Revision$", |
1371 |
|
|
.modinit = module_init, |
1372 |
|
|
.modexit = module_exit, |
1373 |
|
|
}; |