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