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