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