1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_stats.c: Sends the user statistics or config information. |
4 |
* |
5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "list.h" /* dlink_node/dlink_list */ |
27 |
#include "balloc.h" |
28 |
#include "client.h" /* Client */ |
29 |
#include "irc_string.h" |
30 |
#include "ircd.h" /* me */ |
31 |
#include "listener.h" /* show_ports */ |
32 |
#include "s_gline.h" |
33 |
#include "hostmask.h" |
34 |
#include "numeric.h" /* ERR_xxx */ |
35 |
#include "send.h" /* sendto_one */ |
36 |
#include "fdlist.h" /* PF and friends */ |
37 |
#include "s_bsd.h" /* highest_fd */ |
38 |
#include "s_conf.h" /* AccessItem, report_configured_links */ |
39 |
#include "s_misc.h" /* serv_info */ |
40 |
#include "s_serv.h" /* hunt_server */ |
41 |
#include "s_user.h" /* show_opers */ |
42 |
#include "event.h" /* events */ |
43 |
#include "dbuf.h" |
44 |
#include "hook.h" |
45 |
#include "parse.h" |
46 |
#include "modules.h" |
47 |
#include "resv.h" /* report_resv */ |
48 |
#include "whowas.h" |
49 |
#include "watch.h" |
50 |
|
51 |
|
52 |
static char *parse_stats_args(int, char **, int *, int *); |
53 |
static void stats_L(struct Client *, char *, int, int, char); |
54 |
static void stats_L_list(struct Client *, char *, int, int, dlink_list *, char); |
55 |
static void stats_dns_servers(struct Client *); |
56 |
static void stats_connect(struct Client *); |
57 |
static void stats_deny(struct Client *); |
58 |
static void stats_tdeny(struct Client *); |
59 |
static void stats_exempt(struct Client *); |
60 |
static void stats_events(struct Client *); |
61 |
static void stats_pending_glines(struct Client *); |
62 |
static void stats_glines(struct Client *); |
63 |
static void stats_gdeny(struct Client *); |
64 |
static void stats_hubleaf(struct Client *); |
65 |
static void stats_auth(struct Client *); |
66 |
static void stats_tklines(struct Client *); |
67 |
static void stats_klines(struct Client *); |
68 |
static void stats_messages(struct Client *); |
69 |
static void stats_oper(struct Client *); |
70 |
static void stats_operedup(struct Client *); |
71 |
static void stats_ports(struct Client *); |
72 |
static void stats_resv(struct Client *); |
73 |
static void stats_usage(struct Client *); |
74 |
static void stats_service(struct Client *); |
75 |
static void stats_tstats(struct Client *); |
76 |
static void stats_uptime(struct Client *); |
77 |
static void stats_shared(struct Client *); |
78 |
static void stats_servers(struct Client *); |
79 |
static void stats_gecos(struct Client *); |
80 |
static void stats_class(struct Client *); |
81 |
static void stats_memory(struct Client *); |
82 |
static void stats_servlinks(struct Client *); |
83 |
static void stats_ltrace(struct Client *, int, char **); |
84 |
static void stats_ziplinks(struct Client *); |
85 |
|
86 |
/* This table contains the possible stats items, in order: |
87 |
* /stats name, function to call, operonly? adminonly? /stats letter |
88 |
* case only matters in the stats letter column.. -- fl_ */ |
89 |
static const struct StatsStruct |
90 |
{ |
91 |
const unsigned char letter; |
92 |
void (*handler)(); |
93 |
const unsigned int need_oper; |
94 |
const unsigned int need_admin; |
95 |
} stats_cmd_table[] = { |
96 |
/* letter function need_oper need_admin */ |
97 |
{ 'a', stats_dns_servers, 1, 1 }, |
98 |
{ 'A', stats_dns_servers, 1, 1 }, |
99 |
{ 'c', stats_connect, 1, 0 }, |
100 |
{ 'C', stats_connect, 1, 0 }, |
101 |
{ 'd', stats_tdeny, 1, 0 }, |
102 |
{ 'D', stats_deny, 1, 0 }, |
103 |
{ 'e', stats_exempt, 1, 0 }, |
104 |
{ 'E', stats_events, 1, 1 }, |
105 |
{ 'f', fd_dump, 1, 1 }, |
106 |
{ 'F', fd_dump, 1, 1 }, |
107 |
{ 'g', stats_pending_glines, 1, 0 }, |
108 |
{ 'G', stats_glines, 1, 0 }, |
109 |
{ 'h', stats_hooks, 1, 1 }, |
110 |
{ 'H', stats_hubleaf, 1, 0 }, |
111 |
{ 'i', stats_auth, 0, 0 }, |
112 |
{ 'I', stats_auth, 0, 0 }, |
113 |
{ 'k', stats_tklines, 0, 0 }, |
114 |
{ 'K', stats_klines, 0, 0 }, |
115 |
{ 'l', stats_ltrace, 1, 0 }, |
116 |
{ 'L', stats_ltrace, 1, 0 }, |
117 |
{ 'm', stats_messages, 0, 0 }, |
118 |
{ 'M', stats_messages, 0, 0 }, |
119 |
{ 'o', stats_oper, 0, 0 }, |
120 |
{ 'O', stats_oper, 0, 0 }, |
121 |
{ 'p', stats_operedup, 0, 0 }, |
122 |
{ 'P', stats_ports, 0, 0 }, |
123 |
{ 'q', stats_resv, 1, 0 }, |
124 |
{ 'Q', stats_resv, 1, 0 }, |
125 |
{ 'r', stats_usage, 1, 0 }, |
126 |
{ 'R', stats_usage, 1, 0 }, |
127 |
{ 'S', stats_service, 1, 0 }, |
128 |
{ 't', stats_tstats, 1, 0 }, |
129 |
{ 'T', stats_tstats, 1, 0 }, |
130 |
{ 'u', stats_uptime, 0, 0 }, |
131 |
{ 'U', stats_shared, 1, 0 }, |
132 |
{ 'v', stats_servers, 1, 0 }, |
133 |
{ 'V', stats_gdeny, 1, 0 }, |
134 |
{ 'x', stats_gecos, 1, 0 }, |
135 |
{ 'X', stats_gecos, 1, 0 }, |
136 |
{ 'y', stats_class, 1, 0 }, |
137 |
{ 'Y', stats_class, 1, 0 }, |
138 |
{ 'z', stats_memory, 1, 0 }, |
139 |
{ 'Z', stats_ziplinks, 1, 0 }, |
140 |
{ '?', stats_servlinks, 0, 0 }, |
141 |
{ '\0', NULL, 0, 0 } |
142 |
}; |
143 |
|
144 |
const char *from, *to; |
145 |
|
146 |
static void |
147 |
do_stats(struct Client *source_p, int parc, char *parv[]) |
148 |
{ |
149 |
const struct StatsStruct *tab = stats_cmd_table; |
150 |
char statchar = *parv[1]; |
151 |
|
152 |
if (statchar == '\0') |
153 |
{ |
154 |
sendto_one(source_p, form_str(RPL_ENDOFSTATS), |
155 |
from, to, '*'); |
156 |
return; |
157 |
} |
158 |
|
159 |
for (; tab->handler; ++tab) |
160 |
{ |
161 |
if (tab->letter == statchar) |
162 |
{ |
163 |
/* The stats table says what privs are needed, so check --fl_ */ |
164 |
if ((tab->need_admin && !HasUMode(source_p, UMODE_ADMIN)) || |
165 |
(tab->need_oper && !HasUMode(source_p, UMODE_OPER))) |
166 |
{ |
167 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
168 |
from, to); |
169 |
break; |
170 |
} |
171 |
|
172 |
/* Blah, stats L needs the parameters, none of the others do.. */ |
173 |
if (statchar == 'L' || statchar == 'l') |
174 |
{ |
175 |
sendto_realops_flags(UMODE_SPY, L_ALL, |
176 |
"STATS %c requested by %s (%s@%s) [%s] on %s", |
177 |
statchar, source_p->name, source_p->username, |
178 |
source_p->host, source_p->servptr->name, |
179 |
parc > 2 ? parv[2] : "<no recipient>"); |
180 |
tab->handler(source_p, parc, parv); |
181 |
} |
182 |
else |
183 |
{ |
184 |
sendto_realops_flags(UMODE_SPY, L_ALL, |
185 |
"STATS %c requested by %s (%s@%s) [%s]", |
186 |
statchar, source_p->name, source_p->username, |
187 |
source_p->host, source_p->servptr->name); |
188 |
tab->handler(source_p); |
189 |
} |
190 |
|
191 |
break; |
192 |
} |
193 |
} |
194 |
|
195 |
sendto_one(source_p, form_str(RPL_ENDOFSTATS), |
196 |
from, to, statchar); |
197 |
} |
198 |
|
199 |
/* |
200 |
* m_stats() |
201 |
* parv[0] = sender prefix |
202 |
* parv[1] = stat letter/command |
203 |
* parv[2] = (if present) server/mask in stats L |
204 |
* |
205 |
* This will search the tables for the appropriate stats letter/command, |
206 |
* if found execute it. |
207 |
*/ |
208 |
static void |
209 |
m_stats(struct Client *client_p, struct Client *source_p, |
210 |
int parc, char *parv[]) |
211 |
{ |
212 |
static time_t last_used = 0; |
213 |
|
214 |
/* Is the stats meant for us? */ |
215 |
if (!ConfigFileEntry.disable_remote) |
216 |
if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2, |
217 |
parc, parv) != HUNTED_ISME) |
218 |
return; |
219 |
|
220 |
if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p)) |
221 |
{ |
222 |
from = me.id; |
223 |
to = source_p->id; |
224 |
} |
225 |
else |
226 |
{ |
227 |
from = me.name; |
228 |
to = source_p->name; |
229 |
} |
230 |
|
231 |
/* Check the user is actually allowed to do /stats, and isnt flooding */ |
232 |
if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime) |
233 |
{ |
234 |
sendto_one(source_p,form_str(RPL_LOAD2HI), |
235 |
from, to); |
236 |
return; |
237 |
} |
238 |
|
239 |
last_used = CurrentTime; |
240 |
|
241 |
do_stats(source_p, parc, parv); |
242 |
} |
243 |
|
244 |
/* |
245 |
* mo_stats() |
246 |
* parv[0] = sender prefix |
247 |
* parv[1] = stat letter/command |
248 |
* parv[2] = (if present) server/mask in stats L, or target |
249 |
* |
250 |
* This will search the tables for the appropriate stats letter, |
251 |
* if found execute it. |
252 |
*/ |
253 |
static void |
254 |
mo_stats(struct Client *client_p, struct Client *source_p, |
255 |
int parc, char *parv[]) |
256 |
{ |
257 |
if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2, |
258 |
parc, parv) != HUNTED_ISME) |
259 |
return; |
260 |
|
261 |
if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p)) |
262 |
{ |
263 |
from = me.id; |
264 |
to = source_p->id; |
265 |
} |
266 |
else |
267 |
{ |
268 |
from = me.name; |
269 |
to = source_p->name; |
270 |
} |
271 |
|
272 |
do_stats(source_p, parc, parv); |
273 |
} |
274 |
|
275 |
/* |
276 |
* ms_stats - STATS message handler |
277 |
* parv[0] = sender prefix |
278 |
* parv[1] = statistics selector (defaults to Message frequency) |
279 |
* parv[2] = server name (current server defaulted, if omitted) |
280 |
*/ |
281 |
static void |
282 |
ms_stats(struct Client *client_p, struct Client *source_p, |
283 |
int parc, char *parv[]) |
284 |
{ |
285 |
if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2, |
286 |
parc, parv) != HUNTED_ISME) |
287 |
return; |
288 |
|
289 |
if (IsClient(source_p)) |
290 |
mo_stats(client_p, source_p, parc, parv); |
291 |
} |
292 |
|
293 |
/* |
294 |
* This is part of the STATS replies. There is no offical numeric for this |
295 |
* since this isnt an official command, in much the same way as HASH isnt. |
296 |
* It is also possible that some systems wont support this call or have |
297 |
* different field names for "struct rusage". |
298 |
* -avalon |
299 |
*/ |
300 |
static void |
301 |
send_usage(struct Client *source_p) |
302 |
{ |
303 |
struct rusage rus; |
304 |
time_t secs; |
305 |
time_t rup; |
306 |
#ifdef hz |
307 |
# define hzz hz |
308 |
#else |
309 |
# ifdef HZ |
310 |
# define hzz HZ |
311 |
# else |
312 |
int hzz = 1; |
313 |
# endif |
314 |
#endif |
315 |
|
316 |
if (getrusage(RUSAGE_SELF, &rus) == -1) |
317 |
{ |
318 |
sendto_one(source_p, ":%s NOTICE %s :Getruseage error: %s", |
319 |
me.name, source_p->name, strerror(errno)); |
320 |
return; |
321 |
} |
322 |
|
323 |
secs = rus.ru_utime.tv_sec + rus.ru_stime.tv_sec; |
324 |
|
325 |
if (secs == 0) |
326 |
secs = 1; |
327 |
|
328 |
rup = (CurrentTime - me.localClient->since) * hzz; |
329 |
|
330 |
if (rup == 0) |
331 |
rup = 1; |
332 |
|
333 |
sendto_one(source_p, |
334 |
":%s %d %s R :CPU Secs %d:%d User %d:%d System %d:%d", |
335 |
me.name, RPL_STATSDEBUG, source_p->name, (int)(secs/60), (int)(secs%60), |
336 |
(int)(rus.ru_utime.tv_sec/60), (int)(rus.ru_utime.tv_sec%60), |
337 |
(int)(rus.ru_stime.tv_sec/60), (int)(rus.ru_stime.tv_sec%60)); |
338 |
sendto_one(source_p, ":%s %d %s R :RSS %ld ShMem %ld Data %ld Stack %ld", |
339 |
me.name, RPL_STATSDEBUG, source_p->name, rus.ru_maxrss, |
340 |
(rus.ru_ixrss / rup), (rus.ru_idrss / rup), |
341 |
(rus.ru_isrss / rup)); |
342 |
sendto_one(source_p, ":%s %d %s R :Swaps %d Reclaims %d Faults %d", |
343 |
me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_nswap, |
344 |
(int)rus.ru_minflt, (int)rus.ru_majflt); |
345 |
sendto_one(source_p, ":%s %d %s R :Block in %d out %d", |
346 |
me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_inblock, |
347 |
(int)rus.ru_oublock); |
348 |
sendto_one(source_p, ":%s %d %s R :Msg Rcv %d Send %d", |
349 |
me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_msgrcv, |
350 |
(int)rus.ru_msgsnd); |
351 |
sendto_one(source_p, ":%s %d %s R :Signals %d Context Vol. %d Invol %d", |
352 |
me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_nsignals, |
353 |
(int)rus.ru_nvcsw, (int)rus.ru_nivcsw); |
354 |
} |
355 |
|
356 |
static void |
357 |
count_memory(struct Client *source_p) |
358 |
{ |
359 |
const dlink_node *gptr = NULL; |
360 |
const dlink_node *dlink = NULL; |
361 |
|
362 |
unsigned int local_client_conf_count = 0; /* local client conf links */ |
363 |
unsigned int users_counted = 0; /* user structs */ |
364 |
|
365 |
unsigned int channel_members = 0; |
366 |
unsigned int channel_invites = 0; |
367 |
unsigned int channel_bans = 0; |
368 |
unsigned int channel_except = 0; |
369 |
unsigned int channel_invex = 0; |
370 |
|
371 |
unsigned int wwu = 0; /* whowas users */ |
372 |
unsigned int class_count = 0; /* classes */ |
373 |
unsigned int aways_counted = 0; |
374 |
unsigned int number_ips_stored; /* number of ip addresses hashed */ |
375 |
|
376 |
uint64_t channel_memory = 0; |
377 |
uint64_t channel_ban_memory = 0; |
378 |
uint64_t channel_except_memory = 0; |
379 |
uint64_t channel_invex_memory = 0; |
380 |
|
381 |
unsigned int safelist_count = 0; |
382 |
uint64_t safelist_memory = 0; |
383 |
|
384 |
uint64_t away_memory = 0; /* memory used by aways */ |
385 |
uint64_t wwm = 0; /* whowas array memory used */ |
386 |
uint64_t conf_memory = 0; /* memory used by conf lines */ |
387 |
uint64_t mem_ips_stored; /* memory used by ip address hash */ |
388 |
|
389 |
uint64_t total_channel_memory = 0; |
390 |
uint64_t totww = 0; |
391 |
|
392 |
unsigned int local_client_count = 0; |
393 |
unsigned int remote_client_count = 0; |
394 |
|
395 |
uint64_t local_client_memory_used = 0; |
396 |
uint64_t remote_client_memory_used = 0; |
397 |
|
398 |
uint64_t total_memory = 0; |
399 |
unsigned int topic_count = 0; |
400 |
|
401 |
unsigned int watch_list_headers = 0; /* watchlist headers */ |
402 |
unsigned int watch_list_entries = 0; /* watchlist entries */ |
403 |
uint64_t watch_list_memory = 0; /* watchlist memory used */ |
404 |
|
405 |
|
406 |
DLINK_FOREACH(gptr, global_client_list.head) |
407 |
{ |
408 |
struct Client *target_p = gptr->data; |
409 |
|
410 |
if (MyConnect(target_p)) |
411 |
{ |
412 |
++local_client_count; |
413 |
local_client_conf_count += dlink_list_length(&target_p->localClient->confs); |
414 |
watch_list_entries += dlink_list_length(&target_p->localClient->watches); |
415 |
} |
416 |
else |
417 |
++remote_client_count; |
418 |
|
419 |
if (IsClient(target_p)) |
420 |
{ |
421 |
++users_counted; |
422 |
|
423 |
if (target_p->away != NULL) |
424 |
{ |
425 |
++aways_counted; |
426 |
away_memory += strlen(target_p->away) + 1; |
427 |
} |
428 |
} |
429 |
} |
430 |
|
431 |
/* Count up all channels, ban lists, except lists, Invex lists */ |
432 |
channel_memory = dlink_list_length(&global_channel_list) * |
433 |
sizeof(struct Channel); |
434 |
DLINK_FOREACH(gptr, global_channel_list.head) |
435 |
{ |
436 |
const struct Ban *actualBan; |
437 |
const struct Channel *chptr = gptr->data; |
438 |
|
439 |
channel_members += dlink_list_length(&chptr->members); |
440 |
channel_invites += dlink_list_length(&chptr->invites); |
441 |
|
442 |
if (chptr->topic[0]) |
443 |
++topic_count; |
444 |
|
445 |
channel_bans += dlink_list_length(&chptr->banlist); |
446 |
channel_ban_memory += dlink_list_length(&chptr->banlist) * sizeof(struct Ban); |
447 |
|
448 |
DLINK_FOREACH(dlink, chptr->banlist.head) |
449 |
{ |
450 |
actualBan = dlink->data; |
451 |
assert(actualBan->who); |
452 |
|
453 |
channel_ban_memory += actualBan->len + 1; |
454 |
channel_ban_memory += strlen(actualBan->who) + 1; |
455 |
} |
456 |
|
457 |
channel_except += dlink_list_length(&chptr->exceptlist); |
458 |
channel_except_memory += dlink_list_length(&chptr->exceptlist) * sizeof(struct Ban); |
459 |
|
460 |
DLINK_FOREACH(dlink, chptr->exceptlist.head) |
461 |
{ |
462 |
actualBan = dlink->data; |
463 |
assert(actualBan->who); |
464 |
|
465 |
channel_except_memory += actualBan->len + 1; |
466 |
channel_except_memory += strlen(actualBan->who) + 1; |
467 |
} |
468 |
|
469 |
channel_invex += dlink_list_length(&chptr->invexlist); |
470 |
channel_invex_memory += dlink_list_length(&chptr->invexlist) * sizeof(struct Ban); |
471 |
|
472 |
DLINK_FOREACH(dlink, chptr->invexlist.head) |
473 |
{ |
474 |
actualBan = dlink->data; |
475 |
assert(actualBan->who); |
476 |
|
477 |
channel_invex_memory += actualBan->len + 1; |
478 |
channel_invex_memory += strlen(actualBan->who) + 1; |
479 |
} |
480 |
} |
481 |
|
482 |
if ((safelist_count = dlink_list_length(&listing_client_list))) |
483 |
{ |
484 |
safelist_memory = safelist_count * sizeof(struct ListTask); |
485 |
DLINK_FOREACH(gptr, listing_client_list.head) |
486 |
{ |
487 |
const struct Client *acptr = gptr->data; |
488 |
|
489 |
DLINK_FOREACH(dlink, acptr->localClient->list_task->show_mask.head) |
490 |
safelist_memory += strlen(dlink->data); |
491 |
|
492 |
DLINK_FOREACH(dlink, acptr->localClient->list_task->hide_mask.head) |
493 |
safelist_memory += strlen(dlink->data); |
494 |
} |
495 |
} |
496 |
|
497 |
#if 0 |
498 |
/* XXX THIS has to be fixed !!!! -db */ |
499 |
/* count up all config items */ |
500 |
DLINK_FOREACH(dlink, ConfigItemList.head) |
501 |
{ |
502 |
aconf = dlink->data; |
503 |
conf_memory += aconf->host ? strlen(aconf->host)+1 : 0; |
504 |
conf_memory += aconf->passwd ? strlen(aconf->passwd)+1 : 0; |
505 |
conf_memory += aconf->name ? strlen(aconf->name)+1 : 0; |
506 |
conf_memory += sizeof(struct AccessItem); |
507 |
} |
508 |
#endif |
509 |
/* count up all classes */ |
510 |
class_count = dlink_list_length(&class_items); |
511 |
|
512 |
count_whowas_memory(&wwu, &wwm); |
513 |
watch_count_memory(&watch_list_headers, &watch_list_memory); |
514 |
|
515 |
sendto_one(source_p, ":%s %d %s z :WATCH headers %u(%u) entries %d(%u)", |
516 |
me.name, RPL_STATSDEBUG, source_p->name, watch_list_headers, |
517 |
watch_list_memory, watch_list_entries, |
518 |
watch_list_entries * sizeof(dlink_node) * 2); |
519 |
|
520 |
sendto_one(source_p, ":%s %d %s z :Clients %u(%u)", |
521 |
me.name, RPL_STATSDEBUG, source_p->name, users_counted, |
522 |
(users_counted * sizeof(struct Client))); |
523 |
|
524 |
sendto_one(source_p, ":%s %d %s z :User aways %u(%llu)", |
525 |
me.name, RPL_STATSDEBUG, source_p->name, |
526 |
aways_counted, away_memory); |
527 |
|
528 |
sendto_one(source_p, ":%s %d %s z :Attached confs %u(%llu)", |
529 |
me.name, RPL_STATSDEBUG, source_p->name, |
530 |
local_client_conf_count, |
531 |
(unsigned long long)(local_client_conf_count * sizeof(dlink_node))); |
532 |
|
533 |
sendto_one(source_p, ":%s %d %s z :Resv channels %u(%lu) nicks %u(%lu)", |
534 |
me.name, RPL_STATSDEBUG, source_p->name, |
535 |
dlink_list_length(&resv_channel_list), |
536 |
dlink_list_length(&resv_channel_list) * sizeof(struct ResvChannel), |
537 |
dlink_list_length(&nresv_items), |
538 |
dlink_list_length(&nresv_items) * sizeof(struct MatchItem)); |
539 |
|
540 |
sendto_one(source_p, ":%s %d %s z :Classes %u(%llu)", |
541 |
me.name, RPL_STATSDEBUG, source_p->name, |
542 |
class_count, (unsigned long long)(class_count * sizeof(struct ClassItem))); |
543 |
|
544 |
sendto_one(source_p, ":%s %d %s z :Channels %uu(%llu) Topics %u(%u)", |
545 |
me.name, RPL_STATSDEBUG, source_p->name, |
546 |
dlink_list_length(&global_channel_list), |
547 |
channel_memory, topic_count, topic_count * |
548 |
(TOPICLEN + 1 + USERHOST_REPLYLEN)); |
549 |
|
550 |
sendto_one(source_p, ":%s %d %s z :Bans %u(%llu)", |
551 |
me.name, RPL_STATSDEBUG, source_p->name, |
552 |
channel_bans, channel_ban_memory); |
553 |
|
554 |
sendto_one(source_p, ":%s %d %s z :Exceptions %u(%llu)", |
555 |
me.name, RPL_STATSDEBUG, source_p->name, |
556 |
channel_except, channel_except_memory); |
557 |
|
558 |
sendto_one(source_p, ":%s %d %s z :Invex %u(%llu)", |
559 |
me.name, RPL_STATSDEBUG, source_p->name, |
560 |
channel_invex, channel_invex_memory); |
561 |
|
562 |
sendto_one(source_p, ":%s %d %s z :Channel members %u(%llu) invites %u(%llu)", |
563 |
me.name, RPL_STATSDEBUG, source_p->name, channel_members, |
564 |
(unsigned long long)(channel_members * sizeof(struct Membership)), |
565 |
channel_invites, (unsigned long long)channel_invites * |
566 |
sizeof(dlink_node) * 2); |
567 |
|
568 |
total_channel_memory = channel_memory + channel_ban_memory + |
569 |
channel_members * sizeof(struct Membership) + |
570 |
(channel_invites * sizeof(dlink_node)*2); |
571 |
|
572 |
sendto_one(source_p, ":%s %d %s z :Safelist %u(%llu)", |
573 |
me.name, RPL_STATSDEBUG, source_p->name, |
574 |
safelist_count, safelist_memory); |
575 |
|
576 |
sendto_one(source_p, ":%s %d %s z :Whowas users %u(%llu)", |
577 |
me.name, RPL_STATSDEBUG, source_p->name, |
578 |
wwu, (unsigned long long)(wwu * sizeof(struct Client))); |
579 |
|
580 |
sendto_one(source_p, ":%s %d %s z :Whowas array %u(%llu)", |
581 |
me.name, RPL_STATSDEBUG, source_p->name, |
582 |
NICKNAMEHISTORYLENGTH, wwm); |
583 |
|
584 |
totww = wwu * sizeof(struct Client) + wwm; |
585 |
|
586 |
count_ip_hash(&number_ips_stored,&mem_ips_stored); |
587 |
sendto_one(source_p, ":%s %d %s z :iphash %u(%llu)", |
588 |
me.name, RPL_STATSDEBUG, source_p->name, |
589 |
number_ips_stored, mem_ips_stored); |
590 |
|
591 |
total_memory = totww + total_channel_memory + conf_memory + class_count * |
592 |
sizeof(struct ClassItem); |
593 |
sendto_one(source_p, ":%s %d %s z :Total: whowas %llu channel %llu conf %llu", |
594 |
me.name, RPL_STATSDEBUG, source_p->name, totww, |
595 |
total_channel_memory, conf_memory); |
596 |
|
597 |
local_client_memory_used = local_client_count*(sizeof(struct Client) + sizeof(struct LocalUser)); |
598 |
total_memory += local_client_memory_used; |
599 |
sendto_one(source_p, ":%s %d %s z :Local client Memory in use: %u(%llu)", |
600 |
me.name, RPL_STATSDEBUG, source_p->name, local_client_count, |
601 |
local_client_memory_used); |
602 |
|
603 |
remote_client_memory_used = remote_client_count * sizeof(struct Client); |
604 |
total_memory += remote_client_memory_used; |
605 |
sendto_one(source_p, ":%s %d %s z :Remote client Memory in use: %u(%llu)", |
606 |
me.name, RPL_STATSDEBUG, source_p->name, remote_client_count, |
607 |
remote_client_memory_used); |
608 |
|
609 |
block_heap_report_stats(source_p); |
610 |
|
611 |
sendto_one(source_p, |
612 |
":%s %d %s z :TOTAL: %llu", |
613 |
me.name, RPL_STATSDEBUG, source_p->name, |
614 |
total_memory); |
615 |
} |
616 |
|
617 |
static void |
618 |
stats_dns_servers(struct Client *source_p) |
619 |
{ |
620 |
report_dns_servers(source_p); |
621 |
} |
622 |
|
623 |
static void |
624 |
stats_connect(struct Client *source_p) |
625 |
{ |
626 |
report_confitem_types(source_p, SERVER_TYPE, 0); |
627 |
} |
628 |
|
629 |
/* stats_deny() |
630 |
* |
631 |
* input - client to report to |
632 |
* output - none |
633 |
* side effects - client is given dline list. |
634 |
*/ |
635 |
static void |
636 |
stats_deny(struct Client *source_p) |
637 |
{ |
638 |
struct AddressRec *arec; |
639 |
struct ConfItem *conf; |
640 |
struct AccessItem *aconf; |
641 |
int i; |
642 |
|
643 |
for (i = 0; i < ATABLE_SIZE; i++) |
644 |
{ |
645 |
for (arec = atable[i]; arec; arec=arec->next) |
646 |
{ |
647 |
if (arec->type == CONF_DLINE) |
648 |
{ |
649 |
aconf = arec->aconf; |
650 |
|
651 |
/* dont report a tdline as a dline */ |
652 |
if (aconf->flags & CONF_FLAGS_TEMPORARY) |
653 |
continue; |
654 |
|
655 |
conf = unmap_conf_item(aconf); |
656 |
|
657 |
sendto_one(source_p, form_str(RPL_STATSDLINE), |
658 |
from, to, 'D', aconf->host, aconf->reason, |
659 |
aconf->oper_reason); |
660 |
} |
661 |
} |
662 |
} |
663 |
} |
664 |
|
665 |
/* stats_tdeny() |
666 |
* |
667 |
* input - client to report to |
668 |
* output - none |
669 |
* side effects - client is given dline list. |
670 |
*/ |
671 |
static void |
672 |
stats_tdeny(struct Client *source_p) |
673 |
{ |
674 |
struct AddressRec *arec; |
675 |
struct ConfItem *conf; |
676 |
struct AccessItem *aconf; |
677 |
int i; |
678 |
|
679 |
for (i = 0; i < ATABLE_SIZE; i++) |
680 |
{ |
681 |
for (arec = atable[i]; arec; arec=arec->next) |
682 |
{ |
683 |
if (arec->type == CONF_DLINE) |
684 |
{ |
685 |
aconf = arec->aconf; |
686 |
|
687 |
/* dont report a permanent dline as a tdline */ |
688 |
if (!(aconf->flags & CONF_FLAGS_TEMPORARY)) |
689 |
continue; |
690 |
|
691 |
conf = unmap_conf_item(aconf); |
692 |
|
693 |
sendto_one(source_p, form_str(RPL_STATSDLINE), |
694 |
from, to, 'd', aconf->host, aconf->reason, |
695 |
aconf->oper_reason); |
696 |
} |
697 |
} |
698 |
} |
699 |
} |
700 |
|
701 |
/* stats_exempt() |
702 |
* |
703 |
* input - client to report to |
704 |
* output - none |
705 |
* side effects - client is given list of exempt blocks |
706 |
*/ |
707 |
static void |
708 |
stats_exempt(struct Client *source_p) |
709 |
{ |
710 |
struct AddressRec *arec; |
711 |
struct ConfItem *conf; |
712 |
struct AccessItem *aconf; |
713 |
int i; |
714 |
|
715 |
if (ConfigFileEntry.stats_e_disabled) |
716 |
{ |
717 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
718 |
from, to); |
719 |
return; |
720 |
} |
721 |
|
722 |
for (i = 0; i < ATABLE_SIZE; i++) |
723 |
{ |
724 |
for (arec = atable[i]; arec; arec=arec->next) |
725 |
{ |
726 |
if (arec->type == CONF_EXEMPTDLINE) |
727 |
{ |
728 |
aconf = arec->aconf; |
729 |
|
730 |
conf = unmap_conf_item(aconf); |
731 |
|
732 |
sendto_one(source_p, form_str(RPL_STATSDLINE), |
733 |
from, to, 'e', aconf->host, |
734 |
aconf->reason, aconf->oper_reason); |
735 |
} |
736 |
} |
737 |
} |
738 |
} |
739 |
|
740 |
static void |
741 |
stats_events(struct Client *source_p) |
742 |
{ |
743 |
show_events(source_p); |
744 |
} |
745 |
|
746 |
/* stats_pending_glines() |
747 |
* |
748 |
* input - client pointer |
749 |
* output - none |
750 |
* side effects - client is shown list of pending glines |
751 |
*/ |
752 |
static void |
753 |
stats_pending_glines(struct Client *source_p) |
754 |
{ |
755 |
const dlink_node *dn_ptr = NULL; |
756 |
const struct gline_pending *glp_ptr = NULL; |
757 |
char timebuffer[MAX_DATE_STRING] = { '\0' }; |
758 |
struct tm *tmptr = NULL; |
759 |
|
760 |
if (!ConfigFileEntry.glines) |
761 |
{ |
762 |
sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines", |
763 |
from, to); |
764 |
return; |
765 |
} |
766 |
|
767 |
if (dlink_list_length(&pending_glines[GLINE_PENDING_ADD_TYPE]) > 0) |
768 |
sendto_one(source_p, ":%s NOTICE %s :Pending G-lines", |
769 |
from, to); |
770 |
|
771 |
DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_ADD_TYPE].head) |
772 |
{ |
773 |
glp_ptr = dn_ptr->data; |
774 |
tmptr = localtime(&glp_ptr->vote_1.time_request); |
775 |
strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr); |
776 |
|
777 |
sendto_one(source_p, |
778 |
":%s NOTICE %s :1) %s!%s@%s on %s requested gline at %s for %s@%s [%s]", |
779 |
from, to, glp_ptr->vote_1.oper_nick, |
780 |
glp_ptr->vote_1.oper_user, glp_ptr->vote_1.oper_host, |
781 |
glp_ptr->vote_1.oper_server, timebuffer, |
782 |
glp_ptr->user, glp_ptr->host, glp_ptr->vote_1.reason); |
783 |
|
784 |
if (glp_ptr->vote_2.oper_nick[0] != '\0') |
785 |
{ |
786 |
tmptr = localtime(&glp_ptr->vote_2.time_request); |
787 |
strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr); |
788 |
sendto_one(source_p, |
789 |
":%s NOTICE %s :2) %s!%s@%s on %s requested gline at %s for %s@%s [%s]", |
790 |
from, to, glp_ptr->vote_2.oper_nick, |
791 |
glp_ptr->vote_2.oper_user, glp_ptr->vote_2.oper_host, |
792 |
glp_ptr->vote_2.oper_server, timebuffer, |
793 |
glp_ptr->user, glp_ptr->host, glp_ptr->vote_2.reason); |
794 |
} |
795 |
} |
796 |
|
797 |
sendto_one(source_p, ":%s NOTICE %s :End of Pending G-lines", |
798 |
from, to); |
799 |
|
800 |
if (dlink_list_length(&pending_glines[GLINE_PENDING_DEL_TYPE]) > 0) |
801 |
sendto_one(source_p, ":%s NOTICE %s :Pending UNG-lines", |
802 |
from, to); |
803 |
|
804 |
DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_DEL_TYPE].head) |
805 |
{ |
806 |
glp_ptr = dn_ptr->data; |
807 |
tmptr = localtime(&glp_ptr->vote_1.time_request); |
808 |
strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr); |
809 |
|
810 |
sendto_one(source_p, |
811 |
":%s NOTICE %s :1) %s!%s@%s on %s requested ungline at %s for %s@%s [%s]", |
812 |
from, to, glp_ptr->vote_1.oper_nick, |
813 |
glp_ptr->vote_1.oper_user, glp_ptr->vote_1.oper_host, |
814 |
glp_ptr->vote_1.oper_server, timebuffer, |
815 |
glp_ptr->user, glp_ptr->host, glp_ptr->vote_1.reason); |
816 |
|
817 |
if (glp_ptr->vote_2.oper_nick[0] != '\0') |
818 |
{ |
819 |
tmptr = localtime(&glp_ptr->vote_2.time_request); |
820 |
strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr); |
821 |
sendto_one(source_p, |
822 |
":%s NOTICE %s :2) %s!%s@%s on %s requested ungline at %s for %s@%s [%s]", |
823 |
from, to, glp_ptr->vote_2.oper_nick, |
824 |
glp_ptr->vote_2.oper_user, glp_ptr->vote_2.oper_host, |
825 |
glp_ptr->vote_2.oper_server, timebuffer, |
826 |
glp_ptr->user, glp_ptr->host, glp_ptr->vote_2.reason); |
827 |
|
828 |
} |
829 |
} |
830 |
|
831 |
sendto_one(source_p, ":%s NOTICE %s :End of Pending UNG-lines", |
832 |
from, to); |
833 |
} |
834 |
|
835 |
/* stats_glines() |
836 |
* |
837 |
* input - client pointer |
838 |
* output - none |
839 |
* side effects - client is shown list of glines |
840 |
*/ |
841 |
static void |
842 |
stats_glines(struct Client *source_p) |
843 |
{ |
844 |
struct AddressRec *arec = NULL; |
845 |
int i = 0; |
846 |
|
847 |
if (!ConfigFileEntry.glines) |
848 |
{ |
849 |
sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines", |
850 |
from, to); |
851 |
return; |
852 |
} |
853 |
|
854 |
for (; i < ATABLE_SIZE; ++i) |
855 |
{ |
856 |
for (arec = atable[i]; arec; arec = arec->next) |
857 |
{ |
858 |
if (arec->type == CONF_GLINE) |
859 |
{ |
860 |
const struct AccessItem *aconf = arec->aconf; |
861 |
|
862 |
sendto_one(source_p, form_str(RPL_STATSKLINE), |
863 |
from, to, "G", |
864 |
aconf->host ? aconf->host : "*", |
865 |
aconf->user ? aconf->user : "*", |
866 |
aconf->reason ? aconf->reason : "No reason", "" ); |
867 |
} |
868 |
} |
869 |
} |
870 |
} |
871 |
|
872 |
/* stats_gdeny() |
873 |
* |
874 |
* input - client pointer |
875 |
* outputs - none |
876 |
* side effects - client is shown gline ACL |
877 |
*/ |
878 |
static void |
879 |
stats_gdeny(struct Client *source_p) |
880 |
{ |
881 |
if (!ConfigFileEntry.glines) |
882 |
{ |
883 |
sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines", |
884 |
from, to); |
885 |
return; |
886 |
} |
887 |
|
888 |
report_confitem_types(source_p, GDENY_TYPE, 0); |
889 |
} |
890 |
|
891 |
static void |
892 |
stats_hubleaf(struct Client *source_p) |
893 |
{ |
894 |
report_confitem_types(source_p, HUB_TYPE, 0); |
895 |
report_confitem_types(source_p, LEAF_TYPE, 0); |
896 |
} |
897 |
|
898 |
static void |
899 |
stats_auth(struct Client *source_p) |
900 |
{ |
901 |
/* Oper only, if unopered, return ERR_NOPRIVILEGES */ |
902 |
if ((ConfigFileEntry.stats_i_oper_only == 2) && !HasUMode(source_p, UMODE_OPER)) |
903 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
904 |
from, to); |
905 |
|
906 |
/* If unopered, Only return matching auth blocks */ |
907 |
else if ((ConfigFileEntry.stats_i_oper_only == 1) && !HasUMode(source_p, UMODE_OPER)) |
908 |
{ |
909 |
struct ConfItem *conf; |
910 |
struct AccessItem *aconf; |
911 |
|
912 |
if (MyConnect(source_p)) |
913 |
aconf = find_conf_by_address(source_p->host, |
914 |
&source_p->localClient->ip, |
915 |
CONF_CLIENT, |
916 |
source_p->localClient->aftype, |
917 |
source_p->username, |
918 |
source_p->localClient->passwd); |
919 |
else |
920 |
aconf = find_conf_by_address(source_p->host, NULL, CONF_CLIENT, |
921 |
0, source_p->username, NULL); |
922 |
|
923 |
if (aconf == NULL) |
924 |
return; |
925 |
|
926 |
conf = unmap_conf_item(aconf); |
927 |
|
928 |
sendto_one(source_p, form_str(RPL_STATSILINE), from, |
929 |
to, 'I', |
930 |
"*", show_iline_prefix(source_p, aconf, aconf->user), |
931 |
aconf->host, aconf->port, |
932 |
aconf->class_ptr ? aconf->class_ptr->name : "<default>"); |
933 |
} |
934 |
/* They are opered, or allowed to see all auth blocks */ |
935 |
else |
936 |
report_auth(source_p); |
937 |
} |
938 |
|
939 |
static void |
940 |
stats_tklines(struct Client *source_p) |
941 |
{ |
942 |
struct ConfItem *conf; |
943 |
/* Oper only, if unopered, return ERR_NOPRIVILEGES */ |
944 |
if ((ConfigFileEntry.stats_k_oper_only == 2) && !HasUMode(source_p, UMODE_OPER)) |
945 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
946 |
from, to); |
947 |
|
948 |
/* If unopered, Only return matching klines */ |
949 |
else if ((ConfigFileEntry.stats_k_oper_only == 1) && !HasUMode(source_p, UMODE_OPER)) |
950 |
{ |
951 |
struct AccessItem *aconf; |
952 |
|
953 |
if (MyConnect(source_p)) |
954 |
aconf = find_conf_by_address(source_p->host, |
955 |
&source_p->localClient->ip, |
956 |
CONF_KILL, |
957 |
source_p->localClient->aftype, |
958 |
source_p->username, NULL); |
959 |
else |
960 |
aconf = find_conf_by_address(source_p->host, NULL, CONF_KILL, |
961 |
0, source_p->username, NULL); |
962 |
|
963 |
if (aconf == NULL) |
964 |
return; |
965 |
|
966 |
/* dont report a permanent kline as a tkline */ |
967 |
if (!(aconf->flags & CONF_FLAGS_TEMPORARY)) |
968 |
return; |
969 |
|
970 |
conf = unmap_conf_item(aconf); |
971 |
|
972 |
sendto_one(source_p, form_str(RPL_STATSKLINE), from, |
973 |
to, "k", aconf->host, aconf->user, aconf->reason, ""); |
974 |
} |
975 |
/* Theyre opered, or allowed to see all klines */ |
976 |
else { |
977 |
report_Klines(source_p, 1); |
978 |
report_confitem_types(source_p, RKLINE_TYPE, 1); |
979 |
} |
980 |
} |
981 |
|
982 |
static void |
983 |
stats_klines(struct Client *source_p) |
984 |
{ |
985 |
/* Oper only, if unopered, return ERR_NOPRIVILEGES */ |
986 |
if ((ConfigFileEntry.stats_k_oper_only == 2) && !HasUMode(source_p, UMODE_OPER)) |
987 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
988 |
from, to); |
989 |
|
990 |
/* If unopered, Only return matching klines */ |
991 |
else if ((ConfigFileEntry.stats_k_oper_only == 1) && !HasUMode(source_p, UMODE_OPER)) |
992 |
{ |
993 |
struct AccessItem *aconf; |
994 |
|
995 |
/* search for a kline */ |
996 |
if (MyConnect(source_p)) |
997 |
aconf = find_conf_by_address(source_p->host, |
998 |
&source_p->localClient->ip, |
999 |
CONF_KILL, |
1000 |
source_p->localClient->aftype, |
1001 |
source_p->username, NULL); |
1002 |
else |
1003 |
aconf = find_conf_by_address(source_p->host, NULL, CONF_KILL, |
1004 |
0, source_p->username, NULL); |
1005 |
|
1006 |
if (aconf == NULL) |
1007 |
return; |
1008 |
|
1009 |
/* dont report a tkline as a kline */ |
1010 |
if (aconf->flags & CONF_FLAGS_TEMPORARY) |
1011 |
return; |
1012 |
|
1013 |
sendto_one(source_p, form_str(RPL_STATSKLINE), from, |
1014 |
to, "K", aconf->host, aconf->user, aconf->reason, |
1015 |
aconf->oper_reason); |
1016 |
} |
1017 |
/* Theyre opered, or allowed to see all klines */ |
1018 |
else { |
1019 |
report_Klines(source_p, 0); |
1020 |
report_confitem_types(source_p, RKLINE_TYPE, 0); |
1021 |
} |
1022 |
} |
1023 |
|
1024 |
static void |
1025 |
stats_messages(struct Client *source_p) |
1026 |
{ |
1027 |
report_messages(source_p); |
1028 |
} |
1029 |
|
1030 |
static void |
1031 |
stats_oper(struct Client *source_p) |
1032 |
{ |
1033 |
if (!HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.stats_o_oper_only) |
1034 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
1035 |
from, to); |
1036 |
else |
1037 |
report_confitem_types(source_p, OPER_TYPE, 0); |
1038 |
} |
1039 |
|
1040 |
/* stats_operedup() |
1041 |
* |
1042 |
* input - client pointer |
1043 |
* output - none |
1044 |
* side effects - client is shown a list of active opers |
1045 |
*/ |
1046 |
static void |
1047 |
stats_operedup(struct Client *source_p) |
1048 |
{ |
1049 |
dlink_node *ptr; |
1050 |
|
1051 |
DLINK_FOREACH(ptr, oper_list.head) |
1052 |
{ |
1053 |
const struct Client *target_p = ptr->data; |
1054 |
|
1055 |
if (HasOFlag(target_p, OPER_FLAG_HIDDEN_OPER) && !HasUMode(source_p, UMODE_OPER)) |
1056 |
continue; |
1057 |
|
1058 |
if (MyClient(source_p) && HasUMode(source_p, UMODE_OPER)) |
1059 |
sendto_one(source_p, ":%s %d %s p :[%c][%s] %s (%s@%s) Idle: %d", |
1060 |
from, RPL_STATSDEBUG, to, |
1061 |
HasUMode(target_p, UMODE_ADMIN) ? |
1062 |
(HasOFlag(target_p, OPER_FLAG_HIDDEN_ADMIN) ? 'O' : 'A') : 'O', |
1063 |
oper_privs_as_string(target_p->localClient->operflags), |
1064 |
target_p->name, target_p->username, target_p->host, |
1065 |
(int)(CurrentTime - target_p->localClient->last_privmsg)); |
1066 |
else |
1067 |
sendto_one(source_p, ":%s %d %s p :[%c] %s (%s@%s) Idle: %d", |
1068 |
from, RPL_STATSDEBUG, to, |
1069 |
HasUMode(target_p, UMODE_ADMIN) ? |
1070 |
(HasOFlag(target_p, OPER_FLAG_HIDDEN_ADMIN) ? 'O' : 'A') : 'O', |
1071 |
target_p->name, target_p->username, target_p->host, |
1072 |
(int)(CurrentTime - target_p->localClient->last_privmsg)); |
1073 |
} |
1074 |
|
1075 |
sendto_one(source_p, ":%s %d %s p :%lu OPER(s)", |
1076 |
from, RPL_STATSDEBUG, to, dlink_list_length(&oper_list)); |
1077 |
} |
1078 |
|
1079 |
static void |
1080 |
stats_ports(struct Client *source_p) |
1081 |
{ |
1082 |
if (!HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.stats_P_oper_only) |
1083 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
1084 |
from, to); |
1085 |
else |
1086 |
show_ports(source_p); |
1087 |
} |
1088 |
|
1089 |
static void |
1090 |
stats_resv(struct Client *source_p) |
1091 |
{ |
1092 |
report_resv(source_p); |
1093 |
} |
1094 |
|
1095 |
static void |
1096 |
stats_usage(struct Client *source_p) |
1097 |
{ |
1098 |
send_usage(source_p); |
1099 |
} |
1100 |
|
1101 |
static void |
1102 |
stats_service(struct Client *source_p) |
1103 |
{ |
1104 |
report_confitem_types(source_p, SERVICE_TYPE, 0); |
1105 |
} |
1106 |
|
1107 |
static void |
1108 |
stats_tstats(struct Client *source_p) |
1109 |
{ |
1110 |
const struct Client *target_p = NULL; |
1111 |
const dlink_node *ptr = NULL; |
1112 |
struct ServerStatistics *sp; |
1113 |
struct ServerStatistics tmp; |
1114 |
|
1115 |
sp = &tmp; |
1116 |
memcpy(sp, &ServerStats, sizeof(struct ServerStatistics)); |
1117 |
|
1118 |
/* |
1119 |
* must use the += operator. is_sv is not the number of currently |
1120 |
* active server connections. Note the incrementation in |
1121 |
* s_bsd.c:close_connection. |
1122 |
*/ |
1123 |
sp->is_sv += dlink_list_length(&serv_list); |
1124 |
|
1125 |
DLINK_FOREACH(ptr, serv_list.head) |
1126 |
{ |
1127 |
target_p = ptr->data; |
1128 |
|
1129 |
sp->is_sbs += target_p->localClient->send.bytes; |
1130 |
sp->is_sbr += target_p->localClient->recv.bytes; |
1131 |
sp->is_sti += CurrentTime - target_p->localClient->firsttime; |
1132 |
} |
1133 |
|
1134 |
sp->is_cl += dlink_list_length(&local_client_list); |
1135 |
|
1136 |
DLINK_FOREACH(ptr, local_client_list.head) |
1137 |
{ |
1138 |
target_p = ptr->data; |
1139 |
|
1140 |
sp->is_cbs += target_p->localClient->send.bytes; |
1141 |
sp->is_cbr += target_p->localClient->recv.bytes; |
1142 |
sp->is_cti += CurrentTime - target_p->localClient->firsttime; |
1143 |
} |
1144 |
|
1145 |
sp->is_ni += dlink_list_length(&unknown_list); |
1146 |
|
1147 |
sendto_one(source_p, ":%s %d %s T :accepts %u refused %u", |
1148 |
me.name, RPL_STATSDEBUG, source_p->name, sp->is_ac, sp->is_ref); |
1149 |
sendto_one(source_p, ":%s %d %s T :unknown commands %u prefixes %u", |
1150 |
me.name, RPL_STATSDEBUG, source_p->name, sp->is_unco, sp->is_unpf); |
1151 |
sendto_one(source_p, ":%s %d %s T :nick collisions %u unknown closes %u", |
1152 |
me.name, RPL_STATSDEBUG, source_p->name, sp->is_kill, sp->is_ni); |
1153 |
sendto_one(source_p, ":%s %d %s T :wrong direction %u empty %u", |
1154 |
me.name, RPL_STATSDEBUG, source_p->name, sp->is_wrdi, sp->is_empt); |
1155 |
sendto_one(source_p, ":%s %d %s T :numerics seen %u", |
1156 |
me.name, RPL_STATSDEBUG, source_p->name, sp->is_num); |
1157 |
sendto_one(source_p, ":%s %d %s T :auth successes %u fails %u", |
1158 |
me.name, RPL_STATSDEBUG, source_p->name, sp->is_asuc, sp->is_abad); |
1159 |
sendto_one(source_p, ":%s %d %s T :Client Server", |
1160 |
me.name, RPL_STATSDEBUG, source_p->name); |
1161 |
|
1162 |
sendto_one(source_p, ":%s %d %s T :connected %u %u", |
1163 |
me.name, RPL_STATSDEBUG, source_p->name, |
1164 |
(unsigned int)sp->is_cl, |
1165 |
(unsigned int)sp->is_sv); |
1166 |
sendto_one(source_p, ":%s %d %s T :bytes sent %llu %llu", |
1167 |
me.name, RPL_STATSDEBUG, source_p->name, |
1168 |
sp->is_cbs, sp->is_sbs); |
1169 |
sendto_one(source_p, ":%s %d %s T :bytes recv %llu %llu", |
1170 |
me.name, RPL_STATSDEBUG, source_p->name, |
1171 |
sp->is_cbr, sp->is_sbr); |
1172 |
sendto_one(source_p, ":%s %d %s T :time connected %u %u", |
1173 |
me.name, RPL_STATSDEBUG, source_p->name, |
1174 |
(unsigned int)sp->is_cti, |
1175 |
(unsigned int)sp->is_sti); |
1176 |
} |
1177 |
|
1178 |
static void |
1179 |
stats_uptime(struct Client *source_p) |
1180 |
{ |
1181 |
time_t now = CurrentTime - me.localClient->since; |
1182 |
|
1183 |
sendto_one(source_p, form_str(RPL_STATSUPTIME), from, to, |
1184 |
now / 86400, (now / 3600) % 24, (now / 60) % 60, now % 60); |
1185 |
|
1186 |
if (!ConfigFileEntry.disable_remote || HasUMode(source_p, UMODE_OPER)) |
1187 |
sendto_one(source_p, form_str(RPL_STATSCONN), from, to, |
1188 |
Count.max_loc_con, Count.max_loc_cli, Count.totalrestartcount); |
1189 |
} |
1190 |
|
1191 |
static void |
1192 |
stats_shared(struct Client *source_p) |
1193 |
{ |
1194 |
report_confitem_types(source_p, ULINE_TYPE, 0); |
1195 |
} |
1196 |
|
1197 |
/* stats_servers() |
1198 |
* |
1199 |
* input - client pointer |
1200 |
* output - none |
1201 |
* side effects - client is shown lists of who connected servers |
1202 |
*/ |
1203 |
static void |
1204 |
stats_servers(struct Client *source_p) |
1205 |
{ |
1206 |
dlink_node *ptr = NULL; |
1207 |
|
1208 |
DLINK_FOREACH(ptr, serv_list.head) |
1209 |
{ |
1210 |
const struct Client *target_p = ptr->data; |
1211 |
|
1212 |
sendto_one(source_p, ":%s %d %s v :%s (%s!%s@%s) Idle: %d", |
1213 |
from, RPL_STATSDEBUG, to, target_p->name, |
1214 |
(target_p->serv->by[0] ? target_p->serv->by : "Remote."), |
1215 |
"*", "*", (int)(CurrentTime - target_p->localClient->lasttime)); |
1216 |
} |
1217 |
|
1218 |
sendto_one(source_p, ":%s %d %s v :%u Server(s)", |
1219 |
from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list)); |
1220 |
} |
1221 |
|
1222 |
static void |
1223 |
stats_gecos(struct Client *source_p) |
1224 |
{ |
1225 |
report_confitem_types(source_p, XLINE_TYPE, 0); |
1226 |
report_confitem_types(source_p, RXLINE_TYPE, 0); |
1227 |
} |
1228 |
|
1229 |
static void |
1230 |
stats_class(struct Client *source_p) |
1231 |
{ |
1232 |
report_confitem_types(source_p, CLASS_TYPE, 0); |
1233 |
} |
1234 |
|
1235 |
static void |
1236 |
stats_memory(struct Client *source_p) |
1237 |
{ |
1238 |
count_memory(source_p); |
1239 |
} |
1240 |
|
1241 |
static void |
1242 |
stats_ziplinks(struct Client *source_p) |
1243 |
{ |
1244 |
dlink_node *ptr = NULL; |
1245 |
unsigned int sent_data = 0; |
1246 |
|
1247 |
DLINK_FOREACH(ptr, serv_list.head) |
1248 |
{ |
1249 |
const struct Client *target_p = ptr->data; |
1250 |
|
1251 |
if (IsCapable(target_p, CAP_ZIP)) |
1252 |
{ |
1253 |
/* we use memcpy(3) and a local copy of the structure to |
1254 |
* work around a register use bug on GCC on the SPARC. |
1255 |
* -jmallett, 04/27/2002 |
1256 |
*/ |
1257 |
struct ZipStats zipstats; |
1258 |
|
1259 |
memcpy(&zipstats, &target_p->localClient->zipstats, sizeof(zipstats)); |
1260 |
|
1261 |
sendto_one(source_p, ":%s %d %s Z :ZipLinks stats for %s send[%.2f%% " |
1262 |
"compression (%llu bytes data/%llu bytes wire)] recv[%.2f%% " |
1263 |
"compression (%llu bytes data/%llu bytes wire)]", |
1264 |
from, RPL_STATSDEBUG, to, target_p->name, |
1265 |
zipstats.out_ratio, zipstats.out, zipstats.out_wire, |
1266 |
zipstats.in_ratio, zipstats.in, zipstats.in_wire); |
1267 |
++sent_data; |
1268 |
} |
1269 |
} |
1270 |
|
1271 |
sendto_one(source_p, ":%s %d %s Z :%u ziplink(s)", |
1272 |
from, RPL_STATSDEBUG, to, sent_data); |
1273 |
} |
1274 |
|
1275 |
static void |
1276 |
stats_servlinks(struct Client *source_p) |
1277 |
{ |
1278 |
uint64_t sendB = 0, recvB = 0; |
1279 |
time_t uptime = 0; |
1280 |
dlink_node *ptr = NULL; |
1281 |
|
1282 |
if (ConfigServerHide.flatten_links && !HasUMode(source_p, UMODE_OPER)) |
1283 |
{ |
1284 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
1285 |
from, to); |
1286 |
return; |
1287 |
} |
1288 |
|
1289 |
DLINK_FOREACH(ptr, serv_list.head) |
1290 |
{ |
1291 |
struct Client *target_p = ptr->data; |
1292 |
|
1293 |
sendB += target_p->localClient->send.bytes; |
1294 |
recvB += target_p->localClient->recv.bytes; |
1295 |
|
1296 |
/* ":%s 211 %s %s %u %u %llu %u %llu :%u %u %s" */ |
1297 |
sendto_one(source_p, form_str(RPL_STATSLINKINFO), |
1298 |
from, to, |
1299 |
get_client_name(target_p, HasUMode(source_p, UMODE_ADMIN) ? SHOW_IP : MASK_IP), |
1300 |
dbuf_length(&target_p->localClient->buf_sendq), |
1301 |
target_p->localClient->send.messages, |
1302 |
target_p->localClient->send.bytes >> 10, |
1303 |
target_p->localClient->recv.messages, |
1304 |
target_p->localClient->recv.bytes >> 10, |
1305 |
(unsigned)(CurrentTime - target_p->localClient->firsttime), |
1306 |
(CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since): 0, |
1307 |
HasUMode(source_p, UMODE_OPER) ? show_capabilities(target_p) : "TS"); |
1308 |
} |
1309 |
|
1310 |
sendB >>= 10; |
1311 |
recvB >>= 10; |
1312 |
|
1313 |
sendto_one(source_p, ":%s %d %s ? :%u total server(s)", |
1314 |
from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list)); |
1315 |
sendto_one(source_p, ":%s %d %s ? :Sent total : %7.2f %s", |
1316 |
from, RPL_STATSDEBUG, to, |
1317 |
_GMKv(sendB), _GMKs(sendB)); |
1318 |
sendto_one(source_p, ":%s %d %s ? :Recv total : %7.2f %s", |
1319 |
from, RPL_STATSDEBUG, to, |
1320 |
_GMKv(recvB), _GMKs(recvB)); |
1321 |
|
1322 |
uptime = (CurrentTime - me.localClient->since); |
1323 |
|
1324 |
sendto_one(source_p, ":%s %d %s ? :Server send: %7.2f %s (%4.1f K/s)", |
1325 |
from, RPL_STATSDEBUG, to, |
1326 |
_GMKv((me.localClient->send.bytes>>10)), |
1327 |
_GMKs((me.localClient->send.bytes>>10)), |
1328 |
(float)((float)((me.localClient->send.bytes) >> 10) / |
1329 |
(float)uptime)); |
1330 |
sendto_one(source_p, ":%s %d %s ? :Server recv: %7.2f %s (%4.1f K/s)", |
1331 |
from, RPL_STATSDEBUG, to, |
1332 |
_GMKv((me.localClient->recv.bytes>>10)), |
1333 |
_GMKs((me.localClient->recv.bytes>>10)), |
1334 |
(float)((float)((me.localClient->recv.bytes) >> 10) / |
1335 |
(float)uptime)); |
1336 |
} |
1337 |
|
1338 |
static void |
1339 |
stats_ltrace(struct Client *source_p, int parc, char *parv[]) |
1340 |
{ |
1341 |
int doall = 0; |
1342 |
int wilds = 0; |
1343 |
char *name = NULL; |
1344 |
char statchar; |
1345 |
|
1346 |
if ((name = parse_stats_args(parc, parv, &doall, &wilds)) != NULL) |
1347 |
{ |
1348 |
statchar = parv[1][0]; |
1349 |
|
1350 |
stats_L(source_p, name, doall, wilds, statchar); |
1351 |
} |
1352 |
else |
1353 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
1354 |
from, to, "STATS"); |
1355 |
} |
1356 |
|
1357 |
/* |
1358 |
* stats_L |
1359 |
* |
1360 |
* inputs - pointer to client to report to |
1361 |
* - doall flag |
1362 |
* - wild card or not |
1363 |
* output - NONE |
1364 |
* side effects - |
1365 |
*/ |
1366 |
static void |
1367 |
stats_L(struct Client *source_p,char *name,int doall, |
1368 |
int wilds,char statchar) |
1369 |
{ |
1370 |
stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar); |
1371 |
stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar); |
1372 |
stats_L_list(source_p, name, doall, wilds, &serv_list, statchar); |
1373 |
} |
1374 |
|
1375 |
static void |
1376 |
stats_L_list(struct Client *source_p,char *name, int doall, int wilds, |
1377 |
dlink_list *list,char statchar) |
1378 |
{ |
1379 |
dlink_node *ptr; |
1380 |
struct Client *target_p; |
1381 |
|
1382 |
/* |
1383 |
* send info about connections which match, or all if the |
1384 |
* mask matches from. Only restrictions are on those who |
1385 |
* are invisible not being visible to 'foreigners' who use |
1386 |
* a wild card based search to list it. |
1387 |
*/ |
1388 |
DLINK_FOREACH(ptr, list->head) |
1389 |
{ |
1390 |
target_p = ptr->data; |
1391 |
|
1392 |
if (HasUMode(target_p, UMODE_INVISIBLE) && (doall || wilds) && |
1393 |
!(MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) && |
1394 |
!HasUMode(target_p, UMODE_OPER) && (target_p != source_p)) |
1395 |
continue; |
1396 |
if (!doall && wilds && !match(name, target_p->name)) |
1397 |
continue; |
1398 |
if (!(doall || wilds) && irccmp(name, target_p->name)) |
1399 |
continue; |
1400 |
|
1401 |
/* This basically shows ips for our opers if its not a server/admin, or |
1402 |
* its one of our admins. */ |
1403 |
if(MyClient(source_p) && HasUMode(source_p, UMODE_OPER) && |
1404 |
(HasUMode(source_p, UMODE_ADMIN) || |
1405 |
(!IsServer(target_p) && !HasUMode(target_p, UMODE_ADMIN) && |
1406 |
!IsHandshake(target_p) && !IsConnecting(target_p)))) |
1407 |
{ |
1408 |
sendto_one(source_p, form_str(RPL_STATSLINKINFO), |
1409 |
from, to, |
1410 |
(IsUpper(statchar)) ? |
1411 |
get_client_name(target_p, SHOW_IP) : |
1412 |
get_client_name(target_p, HIDE_IP), |
1413 |
dbuf_length(&target_p->localClient->buf_sendq), |
1414 |
target_p->localClient->send.messages, |
1415 |
target_p->localClient->send.bytes>>10, |
1416 |
target_p->localClient->recv.messages, |
1417 |
target_p->localClient->recv.bytes>>10, |
1418 |
(unsigned)(CurrentTime - target_p->localClient->firsttime), |
1419 |
(CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0, |
1420 |
IsServer(target_p) ? show_capabilities(target_p) : "-"); |
1421 |
} |
1422 |
else |
1423 |
{ |
1424 |
/* If its a hidden ip, an admin, or a server, mask the real IP */ |
1425 |
if(IsIPSpoof(target_p) || IsServer(target_p) || HasUMode(target_p, UMODE_ADMIN) |
1426 |
|| IsHandshake(target_p) || IsConnecting(target_p)) |
1427 |
sendto_one(source_p, form_str(RPL_STATSLINKINFO), |
1428 |
from, to, |
1429 |
get_client_name(target_p, MASK_IP), |
1430 |
dbuf_length(&target_p->localClient->buf_sendq), |
1431 |
target_p->localClient->send.messages, |
1432 |
target_p->localClient->send.bytes>>10, |
1433 |
target_p->localClient->recv.messages, |
1434 |
target_p->localClient->recv.bytes>>10, |
1435 |
(unsigned)(CurrentTime - target_p->localClient->firsttime), |
1436 |
(CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0, |
1437 |
IsServer(target_p) ? show_capabilities(target_p) : "-"); |
1438 |
else /* show the real IP */ |
1439 |
sendto_one(source_p, form_str(RPL_STATSLINKINFO), |
1440 |
from, to, |
1441 |
(IsUpper(statchar)) ? |
1442 |
get_client_name(target_p, SHOW_IP) : |
1443 |
get_client_name(target_p, HIDE_IP), |
1444 |
dbuf_length(&target_p->localClient->buf_sendq), |
1445 |
target_p->localClient->send.messages, |
1446 |
target_p->localClient->send.bytes>>10, |
1447 |
target_p->localClient->recv.messages, |
1448 |
target_p->localClient->recv.bytes>>10, |
1449 |
(unsigned)(CurrentTime - target_p->localClient->firsttime), |
1450 |
(CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0, |
1451 |
IsServer(target_p) ? show_capabilities(target_p) : "-"); |
1452 |
} |
1453 |
} |
1454 |
} |
1455 |
|
1456 |
/* parse_stats_args() |
1457 |
* |
1458 |
* inputs - arg count |
1459 |
* - args |
1460 |
* - doall flag |
1461 |
* - wild card or not |
1462 |
* output - pointer to name to use |
1463 |
* side effects - |
1464 |
* common parse routine for m_stats args |
1465 |
* |
1466 |
*/ |
1467 |
static char * |
1468 |
parse_stats_args(int parc, char *parv[], int *doall, int *wilds) |
1469 |
{ |
1470 |
char *name; |
1471 |
|
1472 |
if (parc > 2) |
1473 |
{ |
1474 |
name = parv[2]; |
1475 |
|
1476 |
if (!irccmp(name, from)) |
1477 |
*doall = 2; |
1478 |
else if (match(name, from)) |
1479 |
*doall = 1; |
1480 |
|
1481 |
if (strchr(name, '*') || |
1482 |
strchr(name, '?')) |
1483 |
*wilds = 1; |
1484 |
|
1485 |
return(name); |
1486 |
} |
1487 |
else |
1488 |
return(NULL); |
1489 |
} |
1490 |
|
1491 |
static struct Message stats_msgtab = { |
1492 |
"STATS", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
1493 |
{ m_unregistered, m_stats, ms_stats, m_ignore, mo_stats, m_ignore } |
1494 |
}; |
1495 |
|
1496 |
static void |
1497 |
module_init(void) |
1498 |
{ |
1499 |
mod_add_cmd(&stats_msgtab); |
1500 |
} |
1501 |
|
1502 |
static void |
1503 |
module_exit(void) |
1504 |
{ |
1505 |
mod_del_cmd(&stats_msgtab); |
1506 |
} |
1507 |
|
1508 |
struct module module_entry = { |
1509 |
.node = { NULL, NULL, NULL }, |
1510 |
.name = NULL, |
1511 |
.version = "$Revision$", |
1512 |
.handle = NULL, |
1513 |
.modinit = module_init, |
1514 |
.modexit = module_exit, |
1515 |
.flags = 0 |
1516 |
}; |