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