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