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