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