]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd). | |
3 | * m_stats.c: Sends the user statistics or config information. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
23 | */ | |
24 | ||
25 | #include "stdinc.h" | |
26 | #include "class.h" /* report_classes */ | |
27 | #include "client.h" /* Client */ | |
28 | #include "match.h" | |
29 | #include "ircd.h" /* me */ | |
30 | #include "listener.h" /* show_ports */ | |
31 | #include "msg.h" /* Message */ | |
32 | #include "hostmask.h" /* report_mtrie_conf_links */ | |
33 | #include "numeric.h" /* ERR_xxx */ | |
34 | #include "scache.h" /* list_scache */ | |
35 | #include "send.h" /* sendto_one */ | |
36 | #include "s_conf.h" /* ConfItem */ | |
37 | #include "s_serv.h" /* hunt_server */ | |
38 | #include "s_stats.h" | |
39 | #include "s_user.h" /* show_opers */ | |
40 | #include "parse.h" | |
41 | #include "modules.h" | |
42 | #include "hook.h" | |
43 | #include "s_newconf.h" | |
44 | #include "hash.h" | |
45 | #include "reject.h" | |
46 | #include "whowas.h" | |
47 | #include "rb_radixtree.h" | |
48 | #include "sslproc.h" | |
49 | #include "s_assert.h" | |
50 | ||
51 | static const char stats_desc[] = | |
52 | "Provides the STATS command to inspect various server/network information"; | |
53 | ||
54 | static void m_stats (struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
55 | ||
56 | struct Message stats_msgtab = { | |
57 | "STATS", false, false, false, false, | |
58 | {mg_unreg, {m_stats, 2}, {m_stats, 3}, mg_ignore, mg_ignore, {m_stats, 2}} | |
59 | }; | |
60 | ||
61 | int doing_stats_hook; | |
62 | int doing_stats_p_hook; | |
63 | ||
64 | mapi_clist_av1 stats_clist[] = { &stats_msgtab, NULL }; | |
65 | mapi_hlist_av1 stats_hlist[] = { | |
66 | { "doing_stats", &doing_stats_hook }, | |
67 | { "doing_stats_p", &doing_stats_p_hook }, | |
68 | { NULL, NULL } | |
69 | }; | |
70 | ||
71 | DECLARE_MODULE_AV2(stats, NULL, NULL, stats_clist, stats_hlist, NULL, NULL, NULL, stats_desc); | |
72 | ||
73 | const char *Lformat = "%s %u %u %u %u %u :%u %u %s"; | |
74 | ||
75 | static void stats_l_list(struct Client *s, const char *, bool, bool, rb_dlink_list *, char, | |
76 | bool (*check_fn)(struct Client *target_p)); | |
77 | static void stats_l_client(struct Client *source_p, struct Client *target_p, | |
78 | char statchar); | |
79 | ||
80 | static int stats_spy(struct Client *, char, const char *); | |
81 | static void stats_p_spy(struct Client *); | |
82 | ||
83 | typedef void (*handler_t)(struct Client *source_p); | |
84 | typedef void (*handler_parv_t)(struct Client *source_p, int parc, const char *parv[]); | |
85 | ||
86 | struct stats_cmd | |
87 | { | |
88 | union | |
89 | { | |
90 | handler_t handler; | |
91 | handler_parv_t handler_parv; | |
92 | }; | |
93 | bool need_parv; | |
94 | bool need_oper; | |
95 | bool need_admin; | |
96 | }; | |
97 | ||
98 | static void stats_dns_servers(struct Client *); | |
99 | static void stats_delay(struct Client *); | |
100 | static void stats_hash(struct Client *); | |
101 | static void stats_connect(struct Client *); | |
102 | static void stats_tdeny(struct Client *); | |
103 | static void stats_deny(struct Client *); | |
104 | static void stats_exempt(struct Client *); | |
105 | static void stats_events(struct Client *); | |
106 | static void stats_prop_klines(struct Client *); | |
107 | static void stats_hubleaf(struct Client *); | |
108 | static void stats_auth(struct Client *); | |
109 | static void stats_tklines(struct Client *); | |
110 | static void stats_klines(struct Client *); | |
111 | static void stats_messages(struct Client *); | |
112 | static void stats_dnsbl(struct Client *); | |
113 | static void stats_oper(struct Client *); | |
114 | static void stats_privset(struct Client *); | |
115 | static void stats_operedup(struct Client *); | |
116 | static void stats_ports(struct Client *); | |
117 | static void stats_tresv(struct Client *); | |
118 | static void stats_resv(struct Client *); | |
119 | static void stats_ssld(struct Client *); | |
120 | static void stats_usage(struct Client *); | |
121 | static void stats_tstats(struct Client *); | |
122 | static void stats_uptime(struct Client *); | |
123 | static void stats_shared(struct Client *); | |
124 | static void stats_servers(struct Client *); | |
125 | static void stats_tgecos(struct Client *); | |
126 | static void stats_gecos(struct Client *); | |
127 | static void stats_class(struct Client *); | |
128 | static void stats_memory(struct Client *); | |
129 | static void stats_servlinks(struct Client *); | |
130 | static void stats_ltrace(struct Client *, int, const char **); | |
131 | static void stats_ziplinks(struct Client *); | |
132 | static void stats_comm(struct Client *); | |
133 | static void stats_capability(struct Client *); | |
134 | ||
135 | #define HANDLER_NORM(fn, oper, admin) { { .handler = fn }, false, oper, admin } | |
136 | #define HANDLER_PARV(fn, oper, admin) { { .handler_parv = fn }, true, oper, admin } | |
137 | ||
138 | /* This table contains the possible stats items, in order: | |
139 | * stats letter, function to call, operonly? adminonly? --fl_ | |
140 | * | |
141 | * Previously in this table letters were a column. I fixed it to use modern | |
142 | * C initalisers so we don't have to iterate anymore | |
143 | * --Elizafox | |
144 | */ | |
145 | static struct stats_cmd stats_cmd_table[256] = { | |
146 | /* letter handler oper admin */ | |
147 | ['a'] = HANDLER_NORM(stats_dns_servers, true, true), | |
148 | ['A'] = HANDLER_NORM(stats_dns_servers, true, true), | |
149 | ['b'] = HANDLER_NORM(stats_delay, true, true), | |
150 | ['B'] = HANDLER_NORM(stats_hash, true, true), | |
151 | ['c'] = HANDLER_NORM(stats_connect, false, false), | |
152 | ['C'] = HANDLER_NORM(stats_capability, true, false), | |
153 | ['d'] = HANDLER_NORM(stats_tdeny, true, false), | |
154 | ['D'] = HANDLER_NORM(stats_deny, true, false), | |
155 | ['e'] = HANDLER_NORM(stats_exempt, true, false), | |
156 | ['E'] = HANDLER_NORM(stats_events, true, true), | |
157 | ['f'] = HANDLER_NORM(stats_comm, true, true), | |
158 | ['F'] = HANDLER_NORM(stats_comm, true, true), | |
159 | ['g'] = HANDLER_NORM(stats_prop_klines, true, false), | |
160 | ['h'] = HANDLER_NORM(stats_hubleaf, false, false), | |
161 | ['H'] = HANDLER_NORM(stats_hubleaf, false, false), | |
162 | ['i'] = HANDLER_NORM(stats_auth, false, false), | |
163 | ['I'] = HANDLER_NORM(stats_auth, false, false), | |
164 | ['k'] = HANDLER_NORM(stats_tklines, false, false), | |
165 | ['K'] = HANDLER_NORM(stats_klines, false, false), | |
166 | ['l'] = HANDLER_PARV(stats_ltrace, false, false), | |
167 | ['L'] = HANDLER_PARV(stats_ltrace, false, false), | |
168 | ['m'] = HANDLER_NORM(stats_messages, false, false), | |
169 | ['M'] = HANDLER_NORM(stats_messages, false, false), | |
170 | ['n'] = HANDLER_NORM(stats_dnsbl, false, false), | |
171 | ['o'] = HANDLER_NORM(stats_oper, false, false), | |
172 | ['O'] = HANDLER_NORM(stats_privset, true, false), | |
173 | ['p'] = HANDLER_NORM(stats_operedup, false, false), | |
174 | ['P'] = HANDLER_NORM(stats_ports, false, false), | |
175 | ['q'] = HANDLER_NORM(stats_tresv, true, false), | |
176 | ['Q'] = HANDLER_NORM(stats_resv, true, false), | |
177 | ['r'] = HANDLER_NORM(stats_usage, true, false), | |
178 | ['R'] = HANDLER_NORM(stats_usage, true, false), | |
179 | ['s'] = HANDLER_NORM(stats_ssld, true, true), | |
180 | ['S'] = HANDLER_NORM(stats_ssld, true, true), | |
181 | ['t'] = HANDLER_NORM(stats_tstats, true, false), | |
182 | ['T'] = HANDLER_NORM(stats_tstats, true, false), | |
183 | ['u'] = HANDLER_NORM(stats_uptime, false, false), | |
184 | ['U'] = HANDLER_NORM(stats_shared, true, false), | |
185 | ['v'] = HANDLER_NORM(stats_servers, false, false), | |
186 | ['V'] = HANDLER_NORM(stats_servers, false, false), | |
187 | ['x'] = HANDLER_NORM(stats_tgecos, true, false), | |
188 | ['X'] = HANDLER_NORM(stats_gecos, true, false), | |
189 | ['y'] = HANDLER_NORM(stats_class, false, false), | |
190 | ['Y'] = HANDLER_NORM(stats_class, false, false), | |
191 | ['z'] = HANDLER_NORM(stats_memory, true, false), | |
192 | ['Z'] = HANDLER_NORM(stats_ziplinks, true, false), | |
193 | ['?'] = HANDLER_NORM(stats_servlinks, false, false), | |
194 | }; | |
195 | ||
196 | /* | |
197 | * m_stats by fl_ | |
198 | * Modified heavily by Elizafox | |
199 | * parv[1] = stat letter/command | |
200 | * parv[2] = (if present) server/mask in stats L, or target | |
201 | * | |
202 | * This will search the tables for the appropriate stats letter, | |
203 | * if found execute it. | |
204 | */ | |
205 | static void | |
206 | m_stats(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
207 | { | |
208 | static time_t last_used = 0; | |
209 | struct stats_cmd *cmd; | |
210 | unsigned char statchar; | |
211 | int did_stats = 0; | |
212 | ||
213 | statchar = parv[1][0]; | |
214 | ||
215 | if(MyClient(source_p) && !IsOper(source_p)) | |
216 | { | |
217 | /* Check the user is actually allowed to do /stats, and isnt flooding */ | |
218 | if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) | |
219 | { | |
220 | /* safe enough to give this on a local connect only */ | |
221 | sendto_one(source_p, form_str(RPL_LOAD2HI), | |
222 | me.name, source_p->name, "STATS"); | |
223 | sendto_one_numeric(source_p, RPL_ENDOFSTATS, | |
224 | form_str(RPL_ENDOFSTATS), statchar); | |
225 | return; | |
226 | } | |
227 | else | |
228 | last_used = rb_current_time(); | |
229 | } | |
230 | ||
231 | if(hunt_server (client_p, source_p, ":%s STATS %s :%s", 2, parc, parv) != HUNTED_ISME) | |
232 | return; | |
233 | ||
234 | if(tolower(statchar) != 'l') | |
235 | /* FIXME */ | |
236 | did_stats = stats_spy(source_p, statchar, NULL); | |
237 | ||
238 | /* if did_stats is true, a module grabbed this STATS request */ | |
239 | if(did_stats) | |
240 | goto stats_out; | |
241 | ||
242 | /* Look up */ | |
243 | cmd = &stats_cmd_table[statchar]; | |
244 | if(cmd->handler != NULL) | |
245 | { | |
246 | /* The stats table says what privs are needed, so check --fl_ */ | |
247 | /* Called for remote clients and for local opers, so check need_admin | |
248 | * and need_oper | |
249 | */ | |
250 | if(cmd->need_admin && !IsOperAdmin(source_p)) | |
251 | { | |
252 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
253 | me.name, source_p->name, "admin"); | |
254 | goto stats_out; | |
255 | } | |
256 | if(cmd->need_oper && !IsOper(source_p)) | |
257 | { | |
258 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
259 | form_str (ERR_NOPRIVILEGES)); | |
260 | goto stats_out; | |
261 | } | |
262 | ||
263 | if(cmd->need_parv) | |
264 | cmd->handler_parv(source_p, parc, parv); | |
265 | else | |
266 | cmd->handler(source_p); | |
267 | } | |
268 | ||
269 | stats_out: | |
270 | /* Send the end of stats notice, and the stats_spy */ | |
271 | sendto_one_numeric(source_p, RPL_ENDOFSTATS, | |
272 | form_str(RPL_ENDOFSTATS), statchar); | |
273 | } | |
274 | ||
275 | static void | |
276 | stats_dns_servers (struct Client *source_p) | |
277 | { | |
278 | rb_dlink_node *n; | |
279 | ||
280 | RB_DLINK_FOREACH(n, nameservers.head) | |
281 | { | |
282 | sendto_one_numeric(source_p, RPL_STATSDEBUG, "A %s", (char *)n->data); | |
283 | } | |
284 | } | |
285 | ||
286 | static void | |
287 | stats_delay(struct Client *source_p) | |
288 | { | |
289 | struct nd_entry *nd; | |
290 | rb_dictionary_iter iter; | |
291 | ||
292 | RB_DICTIONARY_FOREACH(nd, &iter, nd_dict) | |
293 | { | |
294 | sendto_one_notice(source_p, ":Delaying: %s for %ld", | |
295 | nd->name, (long) nd->expire); | |
296 | } | |
297 | } | |
298 | ||
299 | static void | |
300 | stats_hash_cb(const char *buf, void *client_p) | |
301 | { | |
302 | sendto_one_numeric(client_p, RPL_STATSDEBUG, "B :%s", buf); | |
303 | } | |
304 | ||
305 | static void | |
306 | stats_hash(struct Client *source_p) | |
307 | { | |
308 | sendto_one_numeric(source_p, RPL_STATSDEBUG, "B :%-30s %-15s %-10s %-10s %-10s %-10s", | |
309 | "NAME", "TYPE", "OBJECTS", "DEPTH SUM", "AVG DEPTH", "MAX DEPTH"); | |
310 | ||
311 | rb_dictionary_stats_walk(stats_hash_cb, source_p); | |
312 | rb_radixtree_stats_walk(stats_hash_cb, source_p); | |
313 | } | |
314 | ||
315 | static void | |
316 | stats_connect(struct Client *source_p) | |
317 | { | |
318 | static char buf[BUFSIZE]; | |
319 | struct server_conf *server_p; | |
320 | char *s; | |
321 | rb_dlink_node *ptr; | |
322 | ||
323 | if((ConfigFileEntry.stats_c_oper_only || | |
324 | (ConfigServerHide.flatten_links && !IsExemptShide(source_p))) && | |
325 | !IsOper(source_p)) | |
326 | { | |
327 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
328 | form_str(ERR_NOPRIVILEGES)); | |
329 | return; | |
330 | } | |
331 | ||
332 | RB_DLINK_FOREACH(ptr, server_conf_list.head) | |
333 | { | |
334 | server_p = ptr->data; | |
335 | ||
336 | if(ServerConfIllegal(server_p)) | |
337 | continue; | |
338 | ||
339 | s = buf; | |
340 | ||
341 | if(IsOper(source_p)) | |
342 | { | |
343 | if(ServerConfAutoconn(server_p)) | |
344 | *s++ = 'A'; | |
345 | if(ServerConfSCTP(server_p)) | |
346 | *s++ = 'M'; | |
347 | if(ServerConfSSL(server_p)) | |
348 | *s++ = 'S'; | |
349 | if(ServerConfTb(server_p)) | |
350 | *s++ = 'T'; | |
351 | if(ServerConfCompressed(server_p)) | |
352 | *s++ = 'Z'; | |
353 | } | |
354 | ||
355 | if(s == buf) | |
356 | *s++ = '*'; | |
357 | ||
358 | *s = '\0'; | |
359 | ||
360 | sendto_one_numeric(source_p, RPL_STATSCLINE, | |
361 | form_str(RPL_STATSCLINE), | |
362 | "*@127.0.0.1", | |
363 | buf, server_p->name, | |
364 | server_p->port, server_p->class_name, | |
365 | server_p->certfp ? server_p->certfp : "*"); | |
366 | } | |
367 | } | |
368 | ||
369 | /* stats_tdeny() | |
370 | * | |
371 | * input - client to report to | |
372 | * output - none | |
373 | * side effects - client is given temp dline list. | |
374 | */ | |
375 | static void | |
376 | stats_tdeny (struct Client *source_p) | |
377 | { | |
378 | char *host, *pass, *user, *oper_reason; | |
379 | struct AddressRec *arec; | |
380 | struct ConfItem *aconf; | |
381 | int i; | |
382 | ||
383 | for (i = 0; i < ATABLE_SIZE; i++) | |
384 | { | |
385 | for (arec = atable[i]; arec; arec = arec->next) | |
386 | { | |
387 | if(arec->type == CONF_DLINE) | |
388 | { | |
389 | aconf = arec->aconf; | |
390 | ||
391 | if(!(aconf->flags & CONF_FLAGS_TEMPORARY)) | |
392 | continue; | |
393 | ||
394 | get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); | |
395 | ||
396 | sendto_one_numeric(source_p, RPL_STATSDLINE, | |
397 | form_str (RPL_STATSDLINE), | |
398 | 'd', host, pass, | |
399 | oper_reason ? "|" : "", | |
400 | oper_reason ? oper_reason : ""); | |
401 | } | |
402 | } | |
403 | } | |
404 | } | |
405 | ||
406 | /* stats_deny() | |
407 | * | |
408 | * input - client to report to | |
409 | * output - none | |
410 | * side effects - client is given dline list. | |
411 | */ | |
412 | static void | |
413 | stats_deny (struct Client *source_p) | |
414 | { | |
415 | char *host, *pass, *user, *oper_reason; | |
416 | struct AddressRec *arec; | |
417 | struct ConfItem *aconf; | |
418 | int i; | |
419 | ||
420 | for (i = 0; i < ATABLE_SIZE; i++) | |
421 | { | |
422 | for (arec = atable[i]; arec; arec = arec->next) | |
423 | { | |
424 | if(arec->type == CONF_DLINE) | |
425 | { | |
426 | aconf = arec->aconf; | |
427 | ||
428 | if(aconf->flags & CONF_FLAGS_TEMPORARY) | |
429 | continue; | |
430 | ||
431 | get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); | |
432 | ||
433 | sendto_one_numeric(source_p, RPL_STATSDLINE, | |
434 | form_str (RPL_STATSDLINE), | |
435 | 'D', host, pass, | |
436 | oper_reason ? "|" : "", | |
437 | oper_reason ? oper_reason : ""); | |
438 | } | |
439 | } | |
440 | } | |
441 | } | |
442 | ||
443 | ||
444 | /* stats_exempt() | |
445 | * | |
446 | * input - client to report to | |
447 | * output - none | |
448 | * side effects - client is given list of exempt blocks | |
449 | */ | |
450 | static void | |
451 | stats_exempt(struct Client *source_p) | |
452 | { | |
453 | char *name, *host, *user, *classname; | |
454 | const char *pass; | |
455 | struct AddressRec *arec; | |
456 | struct ConfItem *aconf; | |
457 | int i, port; | |
458 | ||
459 | if(ConfigFileEntry.stats_e_disabled) | |
460 | { | |
461 | sendto_one_numeric(source_p, ERR_DISABLED, | |
462 | form_str(ERR_DISABLED), "STATS e"); | |
463 | return; | |
464 | } | |
465 | ||
466 | for (i = 0; i < ATABLE_SIZE; i++) | |
467 | { | |
468 | for (arec = atable[i]; arec; arec = arec->next) | |
469 | { | |
470 | if(arec->type == CONF_EXEMPTDLINE) | |
471 | { | |
472 | aconf = arec->aconf; | |
473 | get_printable_conf (aconf, &name, &host, &pass, | |
474 | &user, &port, &classname); | |
475 | ||
476 | sendto_one_numeric(source_p, RPL_STATSDLINE, | |
477 | form_str(RPL_STATSDLINE), | |
478 | 'e', host, pass, "", ""); | |
479 | } | |
480 | } | |
481 | }} | |
482 | ||
483 | ||
484 | static void | |
485 | stats_events_cb(char *str, void *ptr) | |
486 | { | |
487 | sendto_one_numeric(ptr, RPL_STATSDEBUG, "E :%s", str); | |
488 | } | |
489 | ||
490 | static void | |
491 | stats_events (struct Client *source_p) | |
492 | { | |
493 | rb_dump_events(stats_events_cb, source_p); | |
494 | } | |
495 | ||
496 | static void | |
497 | stats_prop_klines(struct Client *source_p) | |
498 | { | |
499 | struct ConfItem *aconf; | |
500 | rb_dlink_node *ptr; | |
501 | char *user, *host, *pass, *oper_reason; | |
502 | ||
503 | RB_DLINK_FOREACH(ptr, prop_bans.head) | |
504 | { | |
505 | aconf = ptr->data; | |
506 | ||
507 | /* Skip non-klines and deactivated klines. */ | |
508 | if(aconf->status != CONF_KILL) | |
509 | continue; | |
510 | ||
511 | get_printable_kline(source_p, aconf, &host, &pass, | |
512 | &user, &oper_reason); | |
513 | ||
514 | sendto_one_numeric(source_p, RPL_STATSKLINE, | |
515 | form_str(RPL_STATSKLINE), | |
516 | 'g', host, user, pass, | |
517 | oper_reason ? "|" : "", | |
518 | oper_reason ? oper_reason : ""); | |
519 | } | |
520 | } | |
521 | ||
522 | static void | |
523 | stats_hubleaf(struct Client *source_p) | |
524 | { | |
525 | struct remote_conf *hub_p; | |
526 | rb_dlink_node *ptr; | |
527 | ||
528 | if((ConfigFileEntry.stats_h_oper_only || | |
529 | (ConfigServerHide.flatten_links && !IsExemptShide(source_p))) && | |
530 | !IsOper(source_p)) | |
531 | { | |
532 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
533 | form_str (ERR_NOPRIVILEGES)); | |
534 | return; | |
535 | } | |
536 | ||
537 | RB_DLINK_FOREACH(ptr, hubleaf_conf_list.head) | |
538 | { | |
539 | hub_p = ptr->data; | |
540 | ||
541 | if(hub_p->flags & CONF_HUB) | |
542 | sendto_one_numeric(source_p, RPL_STATSHLINE, | |
543 | form_str(RPL_STATSHLINE), | |
544 | hub_p->host, hub_p->server); | |
545 | else | |
546 | sendto_one_numeric(source_p, RPL_STATSLLINE, | |
547 | form_str(RPL_STATSLLINE), | |
548 | hub_p->host, hub_p->server); | |
549 | } | |
550 | } | |
551 | ||
552 | ||
553 | static void | |
554 | stats_auth (struct Client *source_p) | |
555 | { | |
556 | /* Oper only, if unopered, return ERR_NOPRIVS */ | |
557 | if((ConfigFileEntry.stats_i_oper_only == 2) && !IsOper (source_p)) | |
558 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
559 | form_str (ERR_NOPRIVILEGES)); | |
560 | ||
561 | /* If unopered, Only return matching auth blocks */ | |
562 | else if((ConfigFileEntry.stats_i_oper_only == 1) && !IsOper (source_p)) | |
563 | { | |
564 | struct ConfItem *aconf; | |
565 | char *name, *host, *user, *classname; | |
566 | const char *pass = "*"; | |
567 | int port; | |
568 | ||
569 | if(MyConnect (source_p)) | |
570 | aconf = find_conf_by_address (source_p->host, source_p->sockhost, NULL, | |
571 | (struct sockaddr *)&source_p->localClient->ip, | |
572 | CONF_CLIENT, | |
573 | GET_SS_FAMILY(&source_p->localClient->ip), | |
574 | source_p->username, NULL); | |
575 | else | |
576 | aconf = find_conf_by_address (source_p->host, NULL, NULL, NULL, CONF_CLIENT, | |
577 | 0, source_p->username, NULL); | |
578 | ||
579 | if(aconf == NULL) | |
580 | return; | |
581 | ||
582 | get_printable_conf (aconf, &name, &host, &pass, &user, &port, &classname); | |
583 | if(!EmptyString(aconf->spasswd)) | |
584 | pass = aconf->spasswd; | |
585 | ||
586 | sendto_one_numeric(source_p, RPL_STATSILINE, form_str(RPL_STATSILINE), | |
587 | name, pass, show_iline_prefix(source_p, aconf, user), | |
588 | host, port, classname); | |
589 | } | |
590 | ||
591 | /* Theyre opered, or allowed to see all auth blocks */ | |
592 | else | |
593 | report_auth (source_p); | |
594 | } | |
595 | ||
596 | ||
597 | static void | |
598 | stats_tklines(struct Client *source_p) | |
599 | { | |
600 | /* Oper only, if unopered, return ERR_NOPRIVS */ | |
601 | if((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper (source_p)) | |
602 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
603 | form_str (ERR_NOPRIVILEGES)); | |
604 | ||
605 | /* If unopered, Only return matching klines */ | |
606 | else if((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper (source_p)) | |
607 | { | |
608 | struct ConfItem *aconf; | |
609 | char *host, *pass, *user, *oper_reason; | |
610 | ||
611 | if(MyConnect (source_p)) | |
612 | aconf = find_conf_by_address (source_p->host, source_p->sockhost, NULL, | |
613 | (struct sockaddr *)&source_p->localClient->ip, | |
614 | CONF_KILL, | |
615 | GET_SS_FAMILY(&source_p->localClient->ip), | |
616 | source_p->username, NULL); | |
617 | else | |
618 | aconf = find_conf_by_address (source_p->host, NULL, NULL, NULL, CONF_KILL, | |
619 | 0, source_p->username, NULL); | |
620 | ||
621 | if(aconf == NULL) | |
622 | return; | |
623 | ||
624 | /* dont report a permanent kline as a tkline */ | |
625 | if((aconf->flags & CONF_FLAGS_TEMPORARY) == 0) | |
626 | return; | |
627 | ||
628 | get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); | |
629 | ||
630 | sendto_one_numeric(source_p, RPL_STATSKLINE, | |
631 | form_str(RPL_STATSKLINE), (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'k' : 'K', | |
632 | host, user, pass, oper_reason ? "|" : "", | |
633 | oper_reason ? oper_reason : ""); | |
634 | } | |
635 | /* Theyre opered, or allowed to see all klines */ | |
636 | else | |
637 | { | |
638 | struct ConfItem *aconf; | |
639 | rb_dlink_node *ptr; | |
640 | int i; | |
641 | char *user, *host, *pass, *oper_reason; | |
642 | ||
643 | for(i = 0; i < LAST_TEMP_TYPE; i++) | |
644 | { | |
645 | RB_DLINK_FOREACH(ptr, temp_klines[i].head) | |
646 | { | |
647 | aconf = ptr->data; | |
648 | ||
649 | get_printable_kline(source_p, aconf, &host, &pass, | |
650 | &user, &oper_reason); | |
651 | ||
652 | sendto_one_numeric(source_p, RPL_STATSKLINE, | |
653 | form_str(RPL_STATSKLINE), | |
654 | 'k', host, user, pass, | |
655 | oper_reason ? "|" : "", | |
656 | oper_reason ? oper_reason : ""); | |
657 | } | |
658 | } | |
659 | } | |
660 | } | |
661 | ||
662 | /* report_Klines() | |
663 | * | |
664 | * inputs - Client to report to, mask | |
665 | * outputs - | |
666 | * side effects - Reports configured K-lines to client_p. | |
667 | */ | |
668 | static void | |
669 | report_Klines(struct Client *source_p) | |
670 | { | |
671 | char *host, *pass, *user, *oper_reason; | |
672 | struct AddressRec *arec; | |
673 | struct ConfItem *aconf = NULL; | |
674 | int i; | |
675 | ||
676 | for (i = 0; i < ATABLE_SIZE; i++) | |
677 | { | |
678 | for (arec = atable[i]; arec; arec = arec->next) | |
679 | { | |
680 | if(arec->type == CONF_KILL) | |
681 | { | |
682 | aconf = arec->aconf; | |
683 | ||
684 | /* its a tempkline, theyre reported elsewhere */ | |
685 | if(aconf->flags & CONF_FLAGS_TEMPORARY) | |
686 | continue; | |
687 | ||
688 | get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); | |
689 | sendto_one_numeric(source_p, RPL_STATSKLINE, | |
690 | form_str(RPL_STATSKLINE), | |
691 | 'K', host, user, pass, | |
692 | oper_reason ? "|" : "", | |
693 | oper_reason ? oper_reason : ""); | |
694 | } | |
695 | } | |
696 | } | |
697 | } | |
698 | ||
699 | static void | |
700 | stats_klines(struct Client *source_p) | |
701 | { | |
702 | /* Oper only, if unopered, return ERR_NOPRIVS */ | |
703 | if((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper (source_p)) | |
704 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
705 | form_str (ERR_NOPRIVILEGES)); | |
706 | ||
707 | /* If unopered, Only return matching klines */ | |
708 | else if((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper (source_p)) | |
709 | { | |
710 | struct ConfItem *aconf; | |
711 | char *host, *pass, *user, *oper_reason; | |
712 | ||
713 | /* search for a kline */ | |
714 | if(MyConnect (source_p)) | |
715 | aconf = find_conf_by_address (source_p->host, source_p->sockhost, NULL, | |
716 | (struct sockaddr *)&source_p->localClient->ip, | |
717 | CONF_KILL, | |
718 | GET_SS_FAMILY(&source_p->localClient->ip), | |
719 | source_p->username, NULL); | |
720 | else | |
721 | aconf = find_conf_by_address (source_p->host, NULL, NULL, NULL, CONF_KILL, | |
722 | 0, source_p->username, NULL); | |
723 | ||
724 | if(aconf == NULL) | |
725 | return; | |
726 | ||
727 | get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); | |
728 | ||
729 | sendto_one_numeric(source_p, RPL_STATSKLINE, form_str(RPL_STATSKLINE), | |
730 | (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'k' : 'K', | |
731 | host, user, pass, oper_reason ? "|" : "", | |
732 | oper_reason ? oper_reason : ""); | |
733 | } | |
734 | /* Theyre opered, or allowed to see all klines */ | |
735 | else | |
736 | report_Klines (source_p); | |
737 | } | |
738 | ||
739 | static void | |
740 | stats_messages(struct Client *source_p) | |
741 | { | |
742 | rb_dictionary_iter iter; | |
743 | struct Message *msg; | |
744 | ||
745 | RB_DICTIONARY_FOREACH(msg, &iter, cmd_dict) | |
746 | { | |
747 | s_assert(msg->cmd != NULL); | |
748 | sendto_one_numeric(source_p, RPL_STATSCOMMANDS, | |
749 | form_str(RPL_STATSCOMMANDS), | |
750 | msg->cmd, msg->count, | |
751 | msg->bytes, msg->rcount); | |
752 | } | |
753 | } | |
754 | ||
755 | static void | |
756 | stats_dnsbl(struct Client *source_p) | |
757 | { | |
758 | rb_dictionary_iter iter; | |
759 | struct BlacklistStats *stats; | |
760 | ||
761 | if(bl_stats == NULL) | |
762 | return; | |
763 | ||
764 | RB_DICTIONARY_FOREACH(stats, &iter, bl_stats) | |
765 | { | |
766 | /* use RPL_STATSDEBUG for now -- jilles */ | |
767 | sendto_one_numeric(source_p, RPL_STATSDEBUG, "n :%d %s", | |
768 | stats->hits, (const char *)iter.cur->key); | |
769 | } | |
770 | } | |
771 | ||
772 | static void | |
773 | stats_oper(struct Client *source_p) | |
774 | { | |
775 | struct oper_conf *oper_p; | |
776 | rb_dlink_node *ptr; | |
777 | ||
778 | if(!IsOper(source_p) && ConfigFileEntry.stats_o_oper_only) | |
779 | { | |
780 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
781 | form_str (ERR_NOPRIVILEGES)); | |
782 | return; | |
783 | } | |
784 | ||
785 | RB_DLINK_FOREACH(ptr, oper_conf_list.head) | |
786 | { | |
787 | oper_p = ptr->data; | |
788 | ||
789 | sendto_one_numeric(source_p, RPL_STATSOLINE, | |
790 | form_str(RPL_STATSOLINE), | |
791 | oper_p->username, oper_p->host, oper_p->name, | |
792 | IsOper(source_p) ? oper_p->privset->name : "0", "-1"); | |
793 | } | |
794 | } | |
795 | ||
796 | static void | |
797 | stats_capability_walk(const char *line, void *data) | |
798 | { | |
799 | struct Client *client_p = data; | |
800 | ||
801 | sendto_one_numeric(client_p, RPL_STATSDEBUG, "C :%s", line); | |
802 | } | |
803 | ||
804 | static void | |
805 | stats_capability(struct Client *client_p) | |
806 | { | |
807 | capability_index_stats(stats_capability_walk, client_p); | |
808 | } | |
809 | ||
810 | static void | |
811 | stats_privset(struct Client *source_p) | |
812 | { | |
813 | privilegeset_report(source_p); | |
814 | } | |
815 | ||
816 | /* stats_operedup() | |
817 | * | |
818 | * input - client pointer | |
819 | * output - none | |
820 | * side effects - client is shown a list of active opers | |
821 | */ | |
822 | static void | |
823 | stats_operedup (struct Client *source_p) | |
824 | { | |
825 | struct Client *target_p; | |
826 | rb_dlink_node *oper_ptr; | |
827 | unsigned int count = 0; | |
828 | ||
829 | RB_DLINK_FOREACH (oper_ptr, oper_list.head) | |
830 | { | |
831 | target_p = oper_ptr->data; | |
832 | ||
833 | if(!SeesOper(target_p, source_p)) | |
834 | continue; | |
835 | ||
836 | if(target_p->user->away) | |
837 | continue; | |
838 | ||
839 | count++; | |
840 | ||
841 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
842 | "p :%s (%s@%s)", | |
843 | target_p->name, target_p->username, | |
844 | target_p->host); | |
845 | } | |
846 | ||
847 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
848 | "p :%u staff members", count); | |
849 | ||
850 | stats_p_spy (source_p); | |
851 | } | |
852 | ||
853 | static void | |
854 | stats_ports (struct Client *source_p) | |
855 | { | |
856 | if(!IsOper (source_p) && ConfigFileEntry.stats_P_oper_only) | |
857 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
858 | form_str (ERR_NOPRIVILEGES)); | |
859 | else | |
860 | show_ports (source_p); | |
861 | } | |
862 | ||
863 | static void | |
864 | stats_tresv(struct Client *source_p) | |
865 | { | |
866 | struct ConfItem *aconf; | |
867 | rb_radixtree_iteration_state state; | |
868 | rb_dlink_node *ptr; | |
869 | ||
870 | RB_DLINK_FOREACH(ptr, resv_conf_list.head) | |
871 | { | |
872 | aconf = ptr->data; | |
873 | if(aconf->hold) | |
874 | sendto_one_numeric(source_p, RPL_STATSQLINE, | |
875 | form_str(RPL_STATSQLINE), | |
876 | 'q', aconf->port, aconf->host, aconf->passwd); | |
877 | } | |
878 | ||
879 | RB_RADIXTREE_FOREACH(aconf, &state, resv_tree) | |
880 | { | |
881 | if(aconf->hold) | |
882 | sendto_one_numeric(source_p, RPL_STATSQLINE, | |
883 | form_str(RPL_STATSQLINE), | |
884 | 'q', aconf->port, aconf->host, aconf->passwd); | |
885 | } | |
886 | } | |
887 | ||
888 | ||
889 | static void | |
890 | stats_resv(struct Client *source_p) | |
891 | { | |
892 | struct ConfItem *aconf; | |
893 | rb_radixtree_iteration_state state; | |
894 | rb_dlink_node *ptr; | |
895 | ||
896 | RB_DLINK_FOREACH(ptr, resv_conf_list.head) | |
897 | { | |
898 | aconf = ptr->data; | |
899 | if(!aconf->hold) | |
900 | sendto_one_numeric(source_p, RPL_STATSQLINE, | |
901 | form_str(RPL_STATSQLINE), | |
902 | 'Q', aconf->port, aconf->host, aconf->passwd); | |
903 | } | |
904 | ||
905 | RB_RADIXTREE_FOREACH(aconf, &state, resv_tree) | |
906 | { | |
907 | if(!aconf->hold) | |
908 | sendto_one_numeric(source_p, RPL_STATSQLINE, | |
909 | form_str(RPL_STATSQLINE), | |
910 | 'Q', aconf->port, aconf->host, aconf->passwd); | |
911 | } | |
912 | } | |
913 | ||
914 | static void | |
915 | stats_ssld_foreach(void *data, pid_t pid, int cli_count, enum ssld_status status, const char *version) | |
916 | { | |
917 | struct Client *source_p = data; | |
918 | ||
919 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
920 | "S :%u %c %u :%s", | |
921 | pid, | |
922 | status == SSLD_DEAD ? 'D' : (status == SSLD_SHUTDOWN ? 'S' : 'A'), | |
923 | cli_count, | |
924 | version); | |
925 | } | |
926 | ||
927 | static void | |
928 | stats_ssld(struct Client *source_p) | |
929 | { | |
930 | ssld_foreach_info(stats_ssld_foreach, source_p); | |
931 | } | |
932 | ||
933 | static void | |
934 | stats_usage (struct Client *source_p) | |
935 | { | |
936 | #ifndef _WIN32 | |
937 | struct rusage rus; | |
938 | time_t secs; | |
939 | time_t rup; | |
940 | #ifdef hz | |
941 | # define hzz hz | |
942 | #else | |
943 | # ifdef HZ | |
944 | # define hzz HZ | |
945 | # else | |
946 | int hzz = 1; | |
947 | # endif | |
948 | #endif | |
949 | ||
950 | if(getrusage(RUSAGE_SELF, &rus) == -1) | |
951 | { | |
952 | sendto_one_notice(source_p, ":Getruseage error: %s.", | |
953 | strerror(errno)); | |
954 | return; | |
955 | } | |
956 | secs = rus.ru_utime.tv_sec + rus.ru_stime.tv_sec; | |
957 | if(0 == secs) | |
958 | secs = 1; | |
959 | ||
960 | rup = (rb_current_time() - startup_time) * hzz; | |
961 | if(0 == rup) | |
962 | rup = 1; | |
963 | ||
964 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
965 | "R :CPU Secs %d:%02d User %d:%02d System %d:%02d", | |
966 | (int) (secs / 60), (int) (secs % 60), | |
967 | (int) (rus.ru_utime.tv_sec / 60), | |
968 | (int) (rus.ru_utime.tv_sec % 60), | |
969 | (int) (rus.ru_stime.tv_sec / 60), | |
970 | (int) (rus.ru_stime.tv_sec % 60)); | |
971 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
972 | "R :RSS %ld ShMem %ld Data %ld Stack %ld", | |
973 | rus.ru_maxrss, (rus.ru_ixrss / rup), | |
974 | (rus.ru_idrss / rup), (rus.ru_isrss / rup)); | |
975 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
976 | "R :Swaps %d Reclaims %d Faults %d", | |
977 | (int) rus.ru_nswap, (int) rus.ru_minflt, (int) rus.ru_majflt); | |
978 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
979 | "R :Block in %d out %d", | |
980 | (int) rus.ru_inblock, (int) rus.ru_oublock); | |
981 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
982 | "R :Msg Rcv %d Send %d", | |
983 | (int) rus.ru_msgrcv, (int) rus.ru_msgsnd); | |
984 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
985 | "R :Signals %d Context Vol. %d Invol %d", | |
986 | (int) rus.ru_nsignals, (int) rus.ru_nvcsw, | |
987 | (int) rus.ru_nivcsw); | |
988 | #endif | |
989 | } | |
990 | ||
991 | static void | |
992 | stats_tstats (struct Client *source_p) | |
993 | { | |
994 | struct Client *target_p; | |
995 | struct ServerStatistics sp; | |
996 | rb_dlink_node *ptr; | |
997 | ||
998 | memcpy(&sp, &ServerStats, sizeof(struct ServerStatistics)); | |
999 | ||
1000 | RB_DLINK_FOREACH(ptr, serv_list.head) | |
1001 | { | |
1002 | target_p = ptr->data; | |
1003 | ||
1004 | sp.is_sbs += target_p->localClient->sendB; | |
1005 | sp.is_sbr += target_p->localClient->receiveB; | |
1006 | sp.is_sti += (unsigned long long)(rb_current_time() - target_p->localClient->firsttime); | |
1007 | sp.is_sv++; | |
1008 | } | |
1009 | ||
1010 | RB_DLINK_FOREACH(ptr, lclient_list.head) | |
1011 | { | |
1012 | target_p = ptr->data; | |
1013 | ||
1014 | sp.is_cbs += target_p->localClient->sendB; | |
1015 | sp.is_cbr += target_p->localClient->receiveB; | |
1016 | sp.is_cti += (unsigned long long)(rb_current_time() - target_p->localClient->firsttime); | |
1017 | sp.is_cl++; | |
1018 | } | |
1019 | ||
1020 | RB_DLINK_FOREACH(ptr, unknown_list.head) | |
1021 | { | |
1022 | sp.is_ni++; | |
1023 | } | |
1024 | ||
1025 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1026 | "T :accepts %u refused %u", sp.is_ac, sp.is_ref); | |
1027 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1028 | "T :rejected %u delaying %lu", | |
1029 | sp.is_rej, delay_exit_length()); | |
1030 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1031 | "T :throttled refused %u throttle list size %lu", sp.is_thr, throttle_size()); | |
1032 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1033 | "T :nicks being delayed %lu", | |
1034 | get_nd_count()); | |
1035 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1036 | "T :unknown commands %u prefixes %u", | |
1037 | sp.is_unco, sp.is_unpf); | |
1038 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1039 | "T :nick collisions %u saves %u unknown closes %u", | |
1040 | sp.is_kill, sp.is_save, sp.is_ni); | |
1041 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1042 | "T :wrong direction %u empty %u", | |
1043 | sp.is_wrdi, sp.is_empt); | |
1044 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1045 | "T :numerics seen %u", sp.is_num); | |
1046 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1047 | "T :tgchange blocked msgs %u restricted addrs %lu", | |
1048 | sp.is_tgch, rb_dlink_list_length(&tgchange_list)); | |
1049 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1050 | "T :ratelimit blocked commands %u", sp.is_rl); | |
1051 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1052 | "T :auth successes %u fails %u", | |
1053 | sp.is_asuc, sp.is_abad); | |
1054 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1055 | "T :sasl successes %u fails %u", | |
1056 | sp.is_ssuc, sp.is_sbad); | |
1057 | sendto_one_numeric(source_p, RPL_STATSDEBUG, "T :Client Server"); | |
1058 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1059 | "T :connected %u %u", sp.is_cl, sp.is_sv); | |
1060 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1061 | "T :bytes sent %lluK %lluK", | |
1062 | sp.is_cbs / 1024, | |
1063 | sp.is_sbs / 1024); | |
1064 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1065 | "T :bytes recv %lluK %lluK", | |
1066 | sp.is_cbr / 1024, | |
1067 | sp.is_sbr / 1024); | |
1068 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1069 | "T :time connected %llu %llu", | |
1070 | sp.is_cti, sp.is_sti); | |
1071 | } | |
1072 | ||
1073 | static void | |
1074 | stats_uptime (struct Client *source_p) | |
1075 | { | |
1076 | time_t now; | |
1077 | ||
1078 | now = rb_current_time() - startup_time; | |
1079 | sendto_one_numeric(source_p, RPL_STATSUPTIME, | |
1080 | form_str (RPL_STATSUPTIME), | |
1081 | (int)(now / 86400), (int)((now / 3600) % 24), | |
1082 | (int)((now / 60) % 60), (int)(now % 60)); | |
1083 | sendto_one_numeric(source_p, RPL_STATSCONN, | |
1084 | form_str (RPL_STATSCONN), | |
1085 | MaxConnectionCount, MaxClientCount, | |
1086 | Count.totalrestartcount); | |
1087 | } | |
1088 | ||
1089 | struct shared_flags | |
1090 | { | |
1091 | int flag; | |
1092 | char letter; | |
1093 | }; | |
1094 | static struct shared_flags shared_flagtable[] = | |
1095 | { | |
1096 | { SHARED_PKLINE, 'K' }, | |
1097 | { SHARED_TKLINE, 'k' }, | |
1098 | { SHARED_UNKLINE, 'U' }, | |
1099 | { SHARED_PXLINE, 'X' }, | |
1100 | { SHARED_TXLINE, 'x' }, | |
1101 | { SHARED_UNXLINE, 'Y' }, | |
1102 | { SHARED_PRESV, 'Q' }, | |
1103 | { SHARED_TRESV, 'q' }, | |
1104 | { SHARED_UNRESV, 'R' }, | |
1105 | { SHARED_LOCOPS, 'L' }, | |
1106 | { SHARED_REHASH, 'H' }, | |
1107 | { SHARED_TDLINE, 'd' }, | |
1108 | { SHARED_PDLINE, 'D' }, | |
1109 | { SHARED_UNDLINE, 'E' }, | |
1110 | { SHARED_GRANT, 'G' }, | |
1111 | { SHARED_DIE, 'I' }, | |
1112 | { 0, '\0'} | |
1113 | }; | |
1114 | ||
1115 | ||
1116 | static void | |
1117 | stats_shared (struct Client *source_p) | |
1118 | { | |
1119 | struct remote_conf *shared_p; | |
1120 | rb_dlink_node *ptr; | |
1121 | char buf[sizeof(shared_flagtable)/sizeof(shared_flagtable[0])]; | |
1122 | char *p; | |
1123 | int i; | |
1124 | ||
1125 | RB_DLINK_FOREACH(ptr, shared_conf_list.head) | |
1126 | { | |
1127 | shared_p = ptr->data; | |
1128 | ||
1129 | p = buf; | |
1130 | ||
1131 | *p++ = 'c'; | |
1132 | ||
1133 | for(i = 0; shared_flagtable[i].flag != 0; i++) | |
1134 | { | |
1135 | if(shared_p->flags & shared_flagtable[i].flag) | |
1136 | *p++ = shared_flagtable[i].letter; | |
1137 | } | |
1138 | ||
1139 | *p = '\0'; | |
1140 | ||
1141 | sendto_one_numeric(source_p, RPL_STATSULINE, | |
1142 | form_str(RPL_STATSULINE), | |
1143 | shared_p->server, shared_p->username, | |
1144 | shared_p->host, buf); | |
1145 | } | |
1146 | ||
1147 | RB_DLINK_FOREACH(ptr, cluster_conf_list.head) | |
1148 | { | |
1149 | shared_p = ptr->data; | |
1150 | ||
1151 | p = buf; | |
1152 | ||
1153 | *p++ = 'C'; | |
1154 | ||
1155 | for(i = 0; shared_flagtable[i].flag != 0; i++) | |
1156 | { | |
1157 | if(shared_p->flags & shared_flagtable[i].flag) | |
1158 | *p++ = shared_flagtable[i].letter; | |
1159 | } | |
1160 | ||
1161 | *p = '\0'; | |
1162 | ||
1163 | sendto_one_numeric(source_p, RPL_STATSULINE, | |
1164 | form_str(RPL_STATSULINE), | |
1165 | shared_p->server, "*", "*", buf); | |
1166 | } | |
1167 | } | |
1168 | ||
1169 | /* stats_servers() | |
1170 | * | |
1171 | * input - client pointer | |
1172 | * output - none | |
1173 | * side effects - client is shown lists of who connected servers | |
1174 | */ | |
1175 | static void | |
1176 | stats_servers (struct Client *source_p) | |
1177 | { | |
1178 | struct Client *target_p; | |
1179 | rb_dlink_node *ptr; | |
1180 | time_t seconds; | |
1181 | int days, hours, minutes; | |
1182 | int j = 0; | |
1183 | ||
1184 | if(ConfigServerHide.flatten_links && !IsOper(source_p) && | |
1185 | !IsExemptShide(source_p)) | |
1186 | { | |
1187 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
1188 | form_str (ERR_NOPRIVILEGES)); | |
1189 | return; | |
1190 | } | |
1191 | ||
1192 | RB_DLINK_FOREACH (ptr, serv_list.head) | |
1193 | { | |
1194 | target_p = ptr->data; | |
1195 | ||
1196 | j++; | |
1197 | seconds = rb_current_time() - target_p->localClient->firsttime; | |
1198 | ||
1199 | days = (int) (seconds / 86400); | |
1200 | seconds %= 86400; | |
1201 | hours = (int) (seconds / 3600); | |
1202 | seconds %= 3600; | |
1203 | minutes = (int) (seconds / 60); | |
1204 | seconds %= 60; | |
1205 | ||
1206 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1207 | "V :%s (%s!*@*) Idle: %d SendQ: %d " | |
1208 | "Connected: %d day%s, %d:%02d:%02d", | |
1209 | target_p->name, | |
1210 | (target_p->serv->by[0] ? target_p->serv->by : "Remote."), | |
1211 | (int) (rb_current_time() - target_p->localClient->lasttime), | |
1212 | (int) rb_linebuf_len (&target_p->localClient->buf_sendq), | |
1213 | days, (days == 1) ? "" : "s", hours, minutes, | |
1214 | (int) seconds); | |
1215 | } | |
1216 | ||
1217 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1218 | "V :%d Server(s)", j); | |
1219 | } | |
1220 | ||
1221 | static void | |
1222 | stats_tgecos(struct Client *source_p) | |
1223 | { | |
1224 | struct ConfItem *aconf; | |
1225 | rb_dlink_node *ptr; | |
1226 | ||
1227 | RB_DLINK_FOREACH(ptr, xline_conf_list.head) | |
1228 | { | |
1229 | aconf = ptr->data; | |
1230 | ||
1231 | if(aconf->hold) | |
1232 | sendto_one_numeric(source_p, RPL_STATSXLINE, | |
1233 | form_str(RPL_STATSXLINE), | |
1234 | 'x', aconf->port, aconf->host, | |
1235 | aconf->passwd); | |
1236 | } | |
1237 | } | |
1238 | ||
1239 | static void | |
1240 | stats_gecos(struct Client *source_p) | |
1241 | { | |
1242 | struct ConfItem *aconf; | |
1243 | rb_dlink_node *ptr; | |
1244 | ||
1245 | RB_DLINK_FOREACH(ptr, xline_conf_list.head) | |
1246 | { | |
1247 | aconf = ptr->data; | |
1248 | ||
1249 | if(!aconf->hold) | |
1250 | sendto_one_numeric(source_p, RPL_STATSXLINE, | |
1251 | form_str(RPL_STATSXLINE), | |
1252 | 'X', aconf->port, aconf->host, | |
1253 | aconf->passwd); | |
1254 | } | |
1255 | } | |
1256 | ||
1257 | static void | |
1258 | stats_class(struct Client *source_p) | |
1259 | { | |
1260 | if(ConfigFileEntry.stats_y_oper_only && !IsOper(source_p)) | |
1261 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
1262 | form_str (ERR_NOPRIVILEGES)); | |
1263 | else | |
1264 | report_classes(source_p); | |
1265 | } | |
1266 | ||
1267 | static void | |
1268 | stats_memory (struct Client *source_p) | |
1269 | { | |
1270 | struct Client *target_p; | |
1271 | struct Channel *chptr; | |
1272 | rb_dlink_node *rb_dlink; | |
1273 | rb_dlink_node *ptr; | |
1274 | int channel_count = 0; | |
1275 | int local_client_conf_count = 0; /* local client conf links */ | |
1276 | int users_counted = 0; /* user structs */ | |
1277 | ||
1278 | int channel_users = 0; | |
1279 | int channel_invites = 0; | |
1280 | int channel_bans = 0; | |
1281 | int channel_except = 0; | |
1282 | int channel_invex = 0; | |
1283 | int channel_quiets = 0; | |
1284 | ||
1285 | int class_count = 0; /* classes */ | |
1286 | int conf_count = 0; /* conf lines */ | |
1287 | int users_invited_count = 0; /* users invited */ | |
1288 | int user_channels = 0; /* users in channels */ | |
1289 | int aways_counted = 0; | |
1290 | size_t number_servers_cached; /* number of servers cached by scache */ | |
1291 | ||
1292 | size_t channel_memory = 0; | |
1293 | size_t channel_ban_memory = 0; | |
1294 | size_t channel_except_memory = 0; | |
1295 | size_t channel_invex_memory = 0; | |
1296 | size_t channel_quiet_memory = 0; | |
1297 | ||
1298 | size_t away_memory = 0; /* memory used by aways */ | |
1299 | size_t ww = 0; /* whowas array count */ | |
1300 | size_t wwm = 0; /* whowas array memory used */ | |
1301 | size_t conf_memory = 0; /* memory used by conf lines */ | |
1302 | size_t mem_servers_cached; /* memory used by scache */ | |
1303 | ||
1304 | size_t linebuf_count = 0; | |
1305 | size_t linebuf_memory_used = 0; | |
1306 | ||
1307 | size_t total_channel_memory = 0; | |
1308 | size_t totww = 0; | |
1309 | ||
1310 | size_t local_client_count = 0; | |
1311 | size_t local_client_memory_used = 0; | |
1312 | ||
1313 | size_t remote_client_count = 0; | |
1314 | size_t remote_client_memory_used = 0; | |
1315 | ||
1316 | size_t total_memory = 0; | |
1317 | ||
1318 | whowas_memory_usage(&ww, &wwm); | |
1319 | ||
1320 | RB_DLINK_FOREACH(ptr, global_client_list.head) | |
1321 | { | |
1322 | target_p = ptr->data; | |
1323 | if(MyConnect(target_p)) | |
1324 | { | |
1325 | local_client_conf_count++; | |
1326 | } | |
1327 | ||
1328 | if(target_p->user) | |
1329 | { | |
1330 | users_counted++; | |
1331 | users_invited_count += rb_dlink_list_length(&target_p->user->invited); | |
1332 | user_channels += rb_dlink_list_length(&target_p->user->channel); | |
1333 | if(target_p->user->away) | |
1334 | { | |
1335 | aways_counted++; | |
1336 | away_memory += (strlen(target_p->user->away) + 1); | |
1337 | } | |
1338 | } | |
1339 | } | |
1340 | ||
1341 | /* Count up all channels, ban lists, except lists, Invex lists */ | |
1342 | RB_DLINK_FOREACH(ptr, global_channel_list.head) | |
1343 | { | |
1344 | chptr = ptr->data; | |
1345 | channel_count++; | |
1346 | channel_memory += (strlen(chptr->chname) + sizeof(struct Channel)); | |
1347 | ||
1348 | channel_users += rb_dlink_list_length(&chptr->members); | |
1349 | channel_invites += rb_dlink_list_length(&chptr->invites); | |
1350 | ||
1351 | RB_DLINK_FOREACH(rb_dlink, chptr->banlist.head) | |
1352 | { | |
1353 | channel_bans++; | |
1354 | ||
1355 | channel_ban_memory += sizeof(rb_dlink_node) + sizeof(struct Ban); | |
1356 | } | |
1357 | ||
1358 | RB_DLINK_FOREACH(rb_dlink, chptr->exceptlist.head) | |
1359 | { | |
1360 | channel_except++; | |
1361 | ||
1362 | channel_except_memory += (sizeof(rb_dlink_node) + sizeof(struct Ban)); | |
1363 | } | |
1364 | ||
1365 | RB_DLINK_FOREACH(rb_dlink, chptr->invexlist.head) | |
1366 | { | |
1367 | channel_invex++; | |
1368 | ||
1369 | channel_invex_memory += (sizeof(rb_dlink_node) + sizeof(struct Ban)); | |
1370 | } | |
1371 | ||
1372 | RB_DLINK_FOREACH(rb_dlink, chptr->quietlist.head) | |
1373 | { | |
1374 | channel_quiets++; | |
1375 | ||
1376 | channel_quiet_memory += (sizeof(rb_dlink_node) + sizeof(struct Ban)); | |
1377 | } | |
1378 | } | |
1379 | ||
1380 | /* count up all classes */ | |
1381 | ||
1382 | class_count = rb_dlink_list_length(&class_list) + 1; | |
1383 | ||
1384 | rb_count_rb_linebuf_memory(&linebuf_count, &linebuf_memory_used); | |
1385 | ||
1386 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1387 | "z :Users %u(%lu) Invites %u(%lu)", | |
1388 | users_counted, | |
1389 | (unsigned long) users_counted * sizeof(struct User), | |
1390 | users_invited_count, | |
1391 | (unsigned long) users_invited_count * sizeof(rb_dlink_node)); | |
1392 | ||
1393 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1394 | "z :User channels %u(%lu) Aways %u(%d)", | |
1395 | user_channels, | |
1396 | (unsigned long) user_channels * sizeof(rb_dlink_node), | |
1397 | aways_counted, (int) away_memory); | |
1398 | ||
1399 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1400 | "z :Attached confs %u(%lu)", | |
1401 | local_client_conf_count, | |
1402 | (unsigned long) local_client_conf_count * sizeof(rb_dlink_node)); | |
1403 | ||
1404 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1405 | "z :Conflines %u(%d)", conf_count, (int) conf_memory); | |
1406 | ||
1407 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1408 | "z :Classes %u(%lu)", | |
1409 | class_count, | |
1410 | (unsigned long) class_count * sizeof(struct Class)); | |
1411 | ||
1412 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1413 | "z :Channels %u(%d)", | |
1414 | channel_count, (int) channel_memory); | |
1415 | ||
1416 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1417 | "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)", | |
1418 | channel_bans, (int) channel_ban_memory, | |
1419 | channel_except, (int) channel_except_memory, | |
1420 | channel_invex, (int) channel_invex_memory, | |
1421 | channel_quiets, (int) channel_quiet_memory); | |
1422 | ||
1423 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1424 | "z :Channel members %u(%lu) invite %u(%lu)", | |
1425 | channel_users, | |
1426 | (unsigned long) channel_users * sizeof(rb_dlink_node), | |
1427 | channel_invites, | |
1428 | (unsigned long) channel_invites * sizeof(rb_dlink_node)); | |
1429 | ||
1430 | total_channel_memory = channel_memory + | |
1431 | channel_ban_memory + | |
1432 | channel_users * sizeof(rb_dlink_node) + channel_invites * sizeof(rb_dlink_node); | |
1433 | ||
1434 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1435 | "z :Whowas array %ld(%ld)", | |
1436 | (long)ww, (long)wwm); | |
1437 | ||
1438 | totww = wwm; | |
1439 | ||
1440 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1441 | "z :Hash: client %u(%ld) chan %u(%ld)", | |
1442 | U_MAX, (long)(U_MAX * sizeof(rb_dlink_list)), | |
1443 | CH_MAX, (long)(CH_MAX * sizeof(rb_dlink_list))); | |
1444 | ||
1445 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1446 | "z :linebuf %ld(%ld)", | |
1447 | (long)linebuf_count, (long)linebuf_memory_used); | |
1448 | ||
1449 | count_scache(&number_servers_cached, &mem_servers_cached); | |
1450 | ||
1451 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1452 | "z :scache %ld(%ld)", | |
1453 | (long)number_servers_cached, (long)mem_servers_cached); | |
1454 | ||
1455 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1456 | "z :hostname hash %d(%ld)", | |
1457 | HOST_MAX, (long)HOST_MAX * sizeof(rb_dlink_list)); | |
1458 | ||
1459 | total_memory = totww + total_channel_memory + conf_memory + | |
1460 | class_count * sizeof(struct Class); | |
1461 | ||
1462 | total_memory += mem_servers_cached; | |
1463 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1464 | "z :Total: whowas %d channel %d conf %d", | |
1465 | (int) totww, (int) total_channel_memory, | |
1466 | (int) conf_memory); | |
1467 | ||
1468 | count_local_client_memory(&local_client_count, &local_client_memory_used); | |
1469 | total_memory += local_client_memory_used; | |
1470 | ||
1471 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1472 | "z :Local client Memory in use: %ld(%ld)", | |
1473 | (long)local_client_count, (long)local_client_memory_used); | |
1474 | ||
1475 | ||
1476 | count_remote_client_memory(&remote_client_count, &remote_client_memory_used); | |
1477 | total_memory += remote_client_memory_used; | |
1478 | ||
1479 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1480 | "z :Remote client Memory in use: %ld(%ld)", | |
1481 | (long)remote_client_count, | |
1482 | (long)remote_client_memory_used); | |
1483 | } | |
1484 | ||
1485 | static void | |
1486 | stats_ziplinks (struct Client *source_p) | |
1487 | { | |
1488 | rb_dlink_node *ptr; | |
1489 | struct Client *target_p; | |
1490 | struct ZipStats *zipstats; | |
1491 | int sent_data = 0; | |
1492 | char buf[128], buf1[128]; | |
1493 | RB_DLINK_FOREACH (ptr, serv_list.head) | |
1494 | { | |
1495 | target_p = ptr->data; | |
1496 | if(IsCapable (target_p, CAP_ZIP)) | |
1497 | { | |
1498 | zipstats = target_p->localClient->zipstats; | |
1499 | sprintf(buf, "%.2f%%", zipstats->out_ratio); | |
1500 | sprintf(buf1, "%.2f%%", zipstats->in_ratio); | |
1501 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1502 | "Z :ZipLinks stats for %s send[%s compression " | |
1503 | "(%llu kB data/%llu kB wire)] recv[%s compression " | |
1504 | "(%llu kB data/%llu kB wire)]", | |
1505 | target_p->name, | |
1506 | buf, zipstats->out >> 10, | |
1507 | zipstats->out_wire >> 10, buf1, | |
1508 | zipstats->in >> 10, zipstats->in_wire >> 10); | |
1509 | sent_data++; | |
1510 | } | |
1511 | } | |
1512 | ||
1513 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1514 | "Z :%u ziplink(s)", sent_data); | |
1515 | } | |
1516 | ||
1517 | static void | |
1518 | stats_servlinks (struct Client *source_p) | |
1519 | { | |
1520 | static char Sformat[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s"; | |
1521 | long uptime, sendK, receiveK; | |
1522 | struct Client *target_p; | |
1523 | rb_dlink_node *ptr; | |
1524 | int j = 0; | |
1525 | char buf[128]; | |
1526 | ||
1527 | if(ConfigServerHide.flatten_links && !IsOper (source_p) && | |
1528 | !IsExemptShide(source_p)) | |
1529 | { | |
1530 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
1531 | form_str (ERR_NOPRIVILEGES)); | |
1532 | return; | |
1533 | } | |
1534 | ||
1535 | sendK = receiveK = 0; | |
1536 | ||
1537 | RB_DLINK_FOREACH (ptr, serv_list.head) | |
1538 | { | |
1539 | target_p = ptr->data; | |
1540 | ||
1541 | j++; | |
1542 | sendK += target_p->localClient->sendK; | |
1543 | receiveK += target_p->localClient->receiveK; | |
1544 | ||
1545 | sendto_one(source_p, Sformat, | |
1546 | get_id(&me, source_p), RPL_STATSLINKINFO, get_id(source_p, source_p), | |
1547 | target_p->name, | |
1548 | (int) rb_linebuf_len (&target_p->localClient->buf_sendq), | |
1549 | (int) target_p->localClient->sendM, | |
1550 | (int) target_p->localClient->sendK, | |
1551 | (int) target_p->localClient->receiveM, | |
1552 | (int) target_p->localClient->receiveK, | |
1553 | rb_current_time() - target_p->localClient->firsttime, | |
1554 | (rb_current_time() > target_p->localClient->lasttime) ? | |
1555 | (rb_current_time() - target_p->localClient->lasttime) : 0, | |
1556 | IsOper (source_p) ? show_capabilities (target_p) : "TS"); | |
1557 | } | |
1558 | ||
1559 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1560 | "? :%u total server(s)", j); | |
1561 | ||
1562 | snprintf(buf, sizeof buf, "%7.2f", _GMKv ((sendK))); | |
1563 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1564 | "? :Sent total : %s %s", | |
1565 | buf, _GMKs (sendK)); | |
1566 | snprintf(buf, sizeof buf, "%7.2f", _GMKv ((receiveK))); | |
1567 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1568 | "? :Recv total : %s %s", | |
1569 | buf, _GMKs (receiveK)); | |
1570 | ||
1571 | uptime = (rb_current_time() - startup_time); | |
1572 | snprintf(buf, sizeof buf, "%7.2f %s (%4.1f K/s)", | |
1573 | _GMKv (me.localClient->sendK), | |
1574 | _GMKs (me.localClient->sendK), | |
1575 | (float) ((float) me.localClient->sendK / (float) uptime)); | |
1576 | sendto_one_numeric(source_p, RPL_STATSDEBUG, "? :Server send: %s", buf); | |
1577 | snprintf(buf, sizeof buf, "%7.2f %s (%4.1f K/s)", | |
1578 | _GMKv (me.localClient->receiveK), | |
1579 | _GMKs (me.localClient->receiveK), | |
1580 | (float) ((float) me.localClient->receiveK / (float) uptime)); | |
1581 | sendto_one_numeric(source_p, RPL_STATSDEBUG, "? :Server recv: %s", buf); | |
1582 | } | |
1583 | ||
1584 | static inline bool | |
1585 | stats_l_should_show_oper(struct Client *target_p) | |
1586 | { | |
1587 | return (!IsOperInvis(target_p)); | |
1588 | } | |
1589 | ||
1590 | static void | |
1591 | stats_ltrace(struct Client *source_p, int parc, const char *parv[]) | |
1592 | { | |
1593 | bool doall = false; | |
1594 | bool wilds = false; | |
1595 | const char *name; | |
1596 | char statchar = parv[1][0]; | |
1597 | ||
1598 | /* this is def targeted at us somehow.. */ | |
1599 | if(parc > 2 && !EmptyString(parv[2])) | |
1600 | { | |
1601 | /* directed at us generically? */ | |
1602 | if(match(parv[2], me.name) || | |
1603 | (!MyClient(source_p) && !irccmp(parv[2], me.id))) | |
1604 | { | |
1605 | name = me.name; | |
1606 | doall = true; | |
1607 | } | |
1608 | else | |
1609 | { | |
1610 | name = parv[2]; | |
1611 | wilds = strchr(name, '*') || strchr(name, '?'); | |
1612 | } | |
1613 | ||
1614 | /* must be directed at a specific person thats not us */ | |
1615 | if(!doall && !wilds) | |
1616 | { | |
1617 | struct Client *target_p; | |
1618 | ||
1619 | if(MyClient(source_p)) | |
1620 | target_p = find_named_person(name); | |
1621 | else | |
1622 | target_p = find_person(name); | |
1623 | ||
1624 | if(target_p != NULL) | |
1625 | { | |
1626 | stats_spy(source_p, statchar, target_p->name); | |
1627 | stats_l_client(source_p, target_p, statchar); | |
1628 | } | |
1629 | else | |
1630 | sendto_one_numeric(source_p, ERR_NOSUCHSERVER, | |
1631 | form_str(ERR_NOSUCHSERVER), | |
1632 | name); | |
1633 | ||
1634 | return; | |
1635 | } | |
1636 | } | |
1637 | else | |
1638 | { | |
1639 | name = me.name; | |
1640 | doall = true; | |
1641 | } | |
1642 | ||
1643 | stats_spy(source_p, statchar, name); | |
1644 | ||
1645 | if(doall) | |
1646 | { | |
1647 | /* local opers get everyone */ | |
1648 | if(MyOper(source_p)) | |
1649 | { | |
1650 | stats_l_list(source_p, name, doall, wilds, &unknown_list, statchar, NULL); | |
1651 | stats_l_list(source_p, name, doall, wilds, &lclient_list, statchar, NULL); | |
1652 | } | |
1653 | else | |
1654 | { | |
1655 | /* they still need themselves if theyre local.. */ | |
1656 | if(MyClient(source_p)) | |
1657 | stats_l_client(source_p, source_p, statchar); | |
1658 | ||
1659 | stats_l_list(source_p, name, doall, wilds, &local_oper_list, statchar, stats_l_should_show_oper); | |
1660 | } | |
1661 | ||
1662 | if (!ConfigServerHide.flatten_links || IsOper(source_p) || | |
1663 | IsExemptShide(source_p)) | |
1664 | stats_l_list(source_p, name, doall, wilds, &serv_list, statchar, NULL); | |
1665 | ||
1666 | return; | |
1667 | } | |
1668 | ||
1669 | /* ok, at this point theyre looking for a specific client whos on | |
1670 | * our server.. but it contains a wildcard. --fl | |
1671 | */ | |
1672 | stats_l_list(source_p, name, doall, wilds, &lclient_list, statchar, NULL); | |
1673 | ||
1674 | return; | |
1675 | } | |
1676 | ||
1677 | static void | |
1678 | stats_l_list(struct Client *source_p, const char *name, bool doall, bool wilds, | |
1679 | rb_dlink_list * list, char statchar, bool (*check_fn)(struct Client *target_p)) | |
1680 | { | |
1681 | rb_dlink_node *ptr; | |
1682 | struct Client *target_p; | |
1683 | ||
1684 | /* send information about connections which match. note, we | |
1685 | * dont need tests for IsInvisible(), because non-opers will | |
1686 | * never get here for normal clients --fl | |
1687 | */ | |
1688 | RB_DLINK_FOREACH(ptr, list->head) | |
1689 | { | |
1690 | target_p = ptr->data; | |
1691 | ||
1692 | if(!doall && wilds && !match(name, target_p->name)) | |
1693 | continue; | |
1694 | ||
1695 | if (check_fn == NULL || check_fn(target_p)) | |
1696 | stats_l_client(source_p, target_p, statchar); | |
1697 | } | |
1698 | } | |
1699 | ||
1700 | void | |
1701 | stats_l_client(struct Client *source_p, struct Client *target_p, | |
1702 | char statchar) | |
1703 | { | |
1704 | if(IsAnyServer(target_p)) | |
1705 | { | |
1706 | sendto_one_numeric(source_p, RPL_STATSLINKINFO, Lformat, | |
1707 | target_p->name, | |
1708 | (int) rb_linebuf_len(&target_p->localClient->buf_sendq), | |
1709 | (int) target_p->localClient->sendM, | |
1710 | (int) target_p->localClient->sendK, | |
1711 | (int) target_p->localClient->receiveM, | |
1712 | (int) target_p->localClient->receiveK, | |
1713 | rb_current_time() - target_p->localClient->firsttime, | |
1714 | (rb_current_time() > target_p->localClient->lasttime) ? | |
1715 | (rb_current_time() - target_p->localClient->lasttime) : 0, | |
1716 | IsOper(source_p) ? show_capabilities(target_p) : "-"); | |
1717 | } | |
1718 | ||
1719 | else | |
1720 | { | |
1721 | sendto_one_numeric(source_p, RPL_STATSLINKINFO, Lformat, | |
1722 | show_ip(source_p, target_p) ? | |
1723 | (IsUpper(statchar) ? | |
1724 | get_client_name(target_p, SHOW_IP) : | |
1725 | get_client_name(target_p, HIDE_IP)) : | |
1726 | get_client_name(target_p, MASK_IP), | |
1727 | (int) rb_linebuf_len(&target_p->localClient->buf_sendq), | |
1728 | (int) target_p->localClient->sendM, | |
1729 | (int) target_p->localClient->sendK, | |
1730 | (int) target_p->localClient->receiveM, | |
1731 | (int) target_p->localClient->receiveK, | |
1732 | rb_current_time() - target_p->localClient->firsttime, | |
1733 | (rb_current_time() > target_p->localClient->lasttime) ? | |
1734 | (rb_current_time() - target_p->localClient->lasttime) : 0, | |
1735 | "-"); | |
1736 | } | |
1737 | } | |
1738 | ||
1739 | static void | |
1740 | rb_dump_fd_callback(int fd, const char *desc, void *data) | |
1741 | { | |
1742 | struct Client *source_p = data; | |
1743 | sendto_one_numeric(source_p, RPL_STATSDEBUG, "F :fd %-3d desc '%s'", fd, desc); | |
1744 | } | |
1745 | ||
1746 | static void | |
1747 | stats_comm(struct Client *source_p) | |
1748 | { | |
1749 | rb_dump_fd(rb_dump_fd_callback, source_p); | |
1750 | } | |
1751 | ||
1752 | /* | |
1753 | * stats_spy | |
1754 | * | |
1755 | * inputs - pointer to client doing the /stats | |
1756 | * - char letter they are doing /stats on | |
1757 | * output - none | |
1758 | * side effects - | |
1759 | * This little helper function reports to opers if configured. | |
1760 | */ | |
1761 | static int | |
1762 | stats_spy(struct Client *source_p, char statchar, const char *name) | |
1763 | { | |
1764 | hook_data_int data; | |
1765 | ||
1766 | data.client = source_p; | |
1767 | data.arg1 = name; | |
1768 | data.arg2 = (int) statchar; | |
1769 | data.result = 0; | |
1770 | ||
1771 | call_hook(doing_stats_hook, &data); | |
1772 | ||
1773 | return data.result; | |
1774 | } | |
1775 | ||
1776 | /* stats_p_spy() | |
1777 | * | |
1778 | * input - pointer to client doing stats | |
1779 | * ouput - | |
1780 | * side effects - call hook doing_stats_p | |
1781 | */ | |
1782 | static void | |
1783 | stats_p_spy (struct Client *source_p) | |
1784 | { | |
1785 | hook_data data; | |
1786 | ||
1787 | data.client = source_p; | |
1788 | data.arg1 = data.arg2 = NULL; | |
1789 | ||
1790 | call_hook(doing_stats_p_hook, &data); | |
1791 | } |