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