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