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