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