]>
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 */ | |
42 | #include "s_stats.h" /* tstats */ | |
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" | |
50 | ||
51 | static int m_stats (struct Client *, struct Client *, int, const char **); | |
52 | ||
53 | struct Message stats_msgtab = { | |
54 | "STATS", 0, 0, 0, MFLG_SLOW, | |
55 | {mg_unreg, {m_stats, 2}, {m_stats, 3}, mg_ignore, mg_ignore, {m_stats, 2}} | |
56 | }; | |
57 | ||
58 | int doing_stats_hook; | |
59 | int doing_stats_p_hook; | |
60 | ||
61 | mapi_clist_av1 stats_clist[] = { &stats_msgtab, NULL }; | |
62 | mapi_hlist_av1 stats_hlist[] = { | |
63 | { "doing_stats", &doing_stats_hook }, | |
64 | { "doing_stats_p", &doing_stats_p_hook }, | |
65 | { NULL, NULL } | |
66 | }; | |
67 | ||
68 | DECLARE_MODULE_AV1(stats, NULL, NULL, stats_clist, stats_hlist, NULL, "$Revision: 1608 $"); | |
69 | ||
70 | const char *Lformat = "%s %u %u %u %u %u :%u %u %s"; | |
71 | ||
5b96d9a6 | 72 | static void stats_l_list(struct Client *s, const char *, int, int, rb_dlink_list *, char); |
212380e3 AC |
73 | static void stats_l_client(struct Client *source_p, struct Client *target_p, |
74 | char statchar); | |
75 | ||
76 | static void stats_spy(struct Client *, char, const char *); | |
77 | static void stats_p_spy(struct Client *); | |
78 | ||
79 | /* Heres our struct for the stats table */ | |
80 | struct StatsStruct | |
81 | { | |
82 | char letter; | |
83 | void (*handler) (); | |
84 | int need_oper; | |
85 | int need_admin; | |
86 | }; | |
87 | ||
88 | static void stats_dns_servers (struct Client *); | |
89 | static void stats_delay(struct Client *); | |
90 | static void stats_hash(struct Client *); | |
91 | static void stats_connect(struct Client *); | |
92 | static void stats_tdeny(struct Client *); | |
93 | static void stats_deny(struct Client *); | |
94 | static void stats_exempt(struct Client *); | |
95 | static void stats_events(struct Client *); | |
96 | static void stats_glines(struct Client *); | |
97 | static void stats_pending_glines(struct Client *); | |
98 | static void stats_hubleaf(struct Client *); | |
99 | static void stats_auth(struct Client *); | |
100 | static void stats_tklines(struct Client *); | |
101 | static void stats_klines(struct Client *); | |
102 | static void stats_messages(struct Client *); | |
103 | static void stats_dnsbl(struct Client *); | |
104 | static void stats_oper(struct Client *); | |
105 | static void stats_operedup(struct Client *); | |
106 | static void stats_ports(struct Client *); | |
107 | static void stats_tresv(struct Client *); | |
108 | static void stats_resv(struct Client *); | |
109 | static void stats_usage(struct Client *); | |
110 | static void stats_tstats(struct Client *); | |
111 | static void stats_uptime(struct Client *); | |
112 | static void stats_shared(struct Client *); | |
113 | static void stats_servers(struct Client *); | |
114 | static void stats_tgecos(struct Client *); | |
115 | static void stats_gecos(struct Client *); | |
116 | static void stats_class(struct Client *); | |
117 | static void stats_memory(struct Client *); | |
118 | static void stats_servlinks(struct Client *); | |
119 | static void stats_ltrace(struct Client *, int, const char **); | |
120 | static void stats_ziplinks(struct Client *); | |
a235e410 | 121 | static void stats_comm(struct Client *); |
212380e3 AC |
122 | /* This table contains the possible stats items, in order: |
123 | * stats letter, function to call, operonly? adminonly? | |
124 | * case only matters in the stats letter column.. -- fl_ | |
125 | */ | |
126 | static struct StatsStruct stats_cmd_table[] = { | |
127 | /* letter function need_oper need_admin */ | |
128 | {'a', stats_dns_servers, 1, 1, }, | |
129 | {'A', stats_dns_servers, 1, 1, }, | |
130 | {'b', stats_delay, 1, 1, }, | |
131 | {'B', stats_hash, 1, 1, }, | |
132 | {'c', stats_connect, 0, 0, }, | |
133 | {'C', stats_connect, 0, 0, }, | |
134 | {'d', stats_tdeny, 1, 0, }, | |
135 | {'D', stats_deny, 1, 0, }, | |
136 | {'e', stats_exempt, 1, 0, }, | |
137 | {'E', stats_events, 1, 1, }, | |
a235e410 VY |
138 | {'f', stats_comm, 1, 1, }, |
139 | {'F', stats_comm, 1, 1, }, | |
212380e3 AC |
140 | {'g', stats_pending_glines, 1, 0, }, |
141 | {'G', stats_glines, 1, 0, }, | |
142 | {'h', stats_hubleaf, 0, 0, }, | |
143 | {'H', stats_hubleaf, 0, 0, }, | |
144 | {'i', stats_auth, 0, 0, }, | |
145 | {'I', stats_auth, 0, 0, }, | |
146 | {'k', stats_tklines, 0, 0, }, | |
147 | {'K', stats_klines, 0, 0, }, | |
148 | {'l', stats_ltrace, 0, 0, }, | |
149 | {'L', stats_ltrace, 0, 0, }, | |
150 | {'m', stats_messages, 0, 0, }, | |
151 | {'M', stats_messages, 0, 0, }, | |
152 | {'n', stats_dnsbl, 0, 0, }, | |
153 | {'o', stats_oper, 0, 0, }, | |
154 | {'O', stats_oper, 0, 0, }, | |
155 | {'p', stats_operedup, 0, 0, }, | |
156 | {'P', stats_ports, 0, 0, }, | |
157 | {'q', stats_tresv, 1, 0, }, | |
158 | {'Q', stats_resv, 1, 0, }, | |
159 | {'r', stats_usage, 1, 0, }, | |
160 | {'R', stats_usage, 1, 0, }, | |
161 | {'t', stats_tstats, 1, 0, }, | |
162 | {'T', stats_tstats, 1, 0, }, | |
163 | {'u', stats_uptime, 0, 0, }, | |
164 | {'U', stats_shared, 1, 0, }, | |
165 | {'v', stats_servers, 0, 0, }, | |
166 | {'V', stats_servers, 0, 0, }, | |
167 | {'x', stats_tgecos, 1, 0, }, | |
168 | {'X', stats_gecos, 1, 0, }, | |
169 | {'y', stats_class, 0, 0, }, | |
170 | {'Y', stats_class, 0, 0, }, | |
171 | {'z', stats_memory, 1, 0, }, | |
172 | {'Z', stats_ziplinks, 1, 0, }, | |
173 | {'?', stats_servlinks, 0, 0, }, | |
174 | {(char) 0, (void (*)()) 0, 0, 0, } | |
175 | }; | |
176 | ||
177 | /* | |
178 | * m_stats by fl_ | |
179 | * parv[0] = sender prefix | |
180 | * parv[1] = stat letter/command | |
181 | * parv[2] = (if present) server/mask in stats L, or target | |
182 | * | |
183 | * This will search the tables for the appropriate stats letter, | |
184 | * if found execute it. | |
185 | */ | |
186 | static int | |
187 | m_stats(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
188 | { | |
189 | static time_t last_used = 0; | |
190 | int i; | |
191 | char statchar; | |
192 | ||
193 | statchar = parv[1][0]; | |
194 | ||
195 | if(MyClient(source_p) && !IsOper(source_p)) | |
196 | { | |
197 | /* Check the user is actually allowed to do /stats, and isnt flooding */ | |
198 | if((last_used + ConfigFileEntry.pace_wait) > CurrentTime) | |
199 | { | |
200 | /* safe enough to give this on a local connect only */ | |
201 | sendto_one(source_p, form_str(RPL_LOAD2HI), | |
202 | me.name, source_p->name, "STATS"); | |
203 | sendto_one_numeric(source_p, RPL_ENDOFSTATS, | |
204 | form_str(RPL_ENDOFSTATS), statchar); | |
205 | return 0; | |
206 | } | |
207 | else | |
208 | last_used = CurrentTime; | |
209 | } | |
210 | ||
211 | if(hunt_server (client_p, source_p, ":%s STATS %s :%s", 2, parc, parv) != HUNTED_ISME) | |
212 | return 0; | |
213 | ||
214 | if((statchar != 'L') && (statchar != 'l')) | |
215 | stats_spy(source_p, statchar, NULL); | |
216 | ||
217 | for (i = 0; stats_cmd_table[i].handler; i++) | |
218 | { | |
219 | if(stats_cmd_table[i].letter == statchar) | |
220 | { | |
221 | /* The stats table says what privs are needed, so check --fl_ */ | |
222 | /* Called for remote clients and for local opers, so check need_admin | |
223 | * and need_oper | |
224 | */ | |
9fc04df8 | 225 | if(stats_cmd_table[i].need_oper && !IsOper(source_p)) |
212380e3 AC |
226 | { |
227 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
228 | form_str (ERR_NOPRIVILEGES)); | |
229 | break; | |
230 | } | |
9fc04df8 JT |
231 | if(stats_cmd_table[i].need_admin && !IsOperAdmin(source_p)) |
232 | { | |
233 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
234 | me.name, source_p->name, "admin"); | |
235 | break; | |
236 | } | |
212380e3 AC |
237 | |
238 | /* Blah, stats L needs the parameters, none of the others do.. */ | |
239 | if(statchar == 'L' || statchar == 'l') | |
240 | stats_cmd_table[i].handler (source_p, parc, parv); | |
241 | else | |
242 | stats_cmd_table[i].handler (source_p); | |
243 | } | |
244 | } | |
245 | ||
246 | /* Send the end of stats notice, and the stats_spy */ | |
247 | sendto_one_numeric(source_p, RPL_ENDOFSTATS, | |
248 | form_str(RPL_ENDOFSTATS), statchar); | |
249 | ||
250 | return 0; | |
251 | } | |
252 | ||
253 | static void | |
254 | stats_dns_servers (struct Client *source_p) | |
255 | { | |
256 | report_dns_servers (source_p); | |
257 | } | |
258 | ||
259 | static void | |
260 | stats_delay(struct Client *source_p) | |
261 | { | |
262 | struct nd_entry *nd; | |
b37021a4 | 263 | struct DictionaryIter iter; |
212380e3 | 264 | |
b37021a4 | 265 | DICTIONARY_FOREACH(nd, &iter, nd_dict) |
212380e3 | 266 | { |
e4b9c8e1 | 267 | sendto_one_notice(source_p, ":Delaying: %s for %ld", |
212380e3 AC |
268 | nd->name, (long) nd->expire); |
269 | } | |
212380e3 AC |
270 | } |
271 | ||
272 | static void | |
273 | stats_hash(struct Client *source_p) | |
274 | { | |
275 | hash_stats(source_p); | |
276 | } | |
277 | ||
278 | static void | |
279 | stats_connect(struct Client *source_p) | |
280 | { | |
281 | static char buf[5]; | |
282 | struct server_conf *server_p; | |
283 | char *s; | |
5b96d9a6 | 284 | rb_dlink_node *ptr; |
212380e3 AC |
285 | |
286 | if((ConfigFileEntry.stats_c_oper_only || | |
287 | (ConfigServerHide.flatten_links && !IsExemptShide(source_p))) && | |
288 | !IsOper(source_p)) | |
289 | { | |
290 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
291 | form_str(ERR_NOPRIVILEGES)); | |
292 | return; | |
293 | } | |
294 | ||
5b96d9a6 | 295 | RB_DLINK_FOREACH(ptr, server_conf_list.head) |
212380e3 AC |
296 | { |
297 | server_p = ptr->data; | |
298 | ||
299 | if(ServerConfIllegal(server_p)) | |
300 | continue; | |
301 | ||
302 | buf[0] = '\0'; | |
303 | s = buf; | |
304 | ||
305 | if(IsOper(source_p)) | |
306 | { | |
307 | if(ServerConfAutoconn(server_p)) | |
308 | *s++ = 'A'; | |
309 | if(ServerConfTb(server_p)) | |
310 | *s++ = 'T'; | |
311 | if(ServerConfCompressed(server_p)) | |
312 | *s++ = 'Z'; | |
313 | } | |
314 | ||
315 | if(!buf[0]) | |
316 | *s++ = '*'; | |
317 | ||
318 | *s = '\0'; | |
319 | ||
320 | sendto_one_numeric(source_p, RPL_STATSCLINE, | |
321 | form_str(RPL_STATSCLINE), | |
322 | #ifndef HIDE_SERVERS_IPS | |
323 | server_p->host, | |
324 | #else | |
325 | "*@127.0.0.1", | |
326 | #endif | |
327 | buf, server_p->name, | |
328 | server_p->port, server_p->class_name); | |
329 | } | |
330 | } | |
331 | ||
332 | /* stats_tdeny() | |
333 | * | |
334 | * input - client to report to | |
335 | * output - none | |
336 | * side effects - client is given temp dline list. | |
337 | */ | |
338 | static void | |
339 | stats_tdeny (struct Client *source_p) | |
340 | { | |
341 | char *host, *pass, *user, *oper_reason; | |
342 | struct AddressRec *arec; | |
343 | struct ConfItem *aconf; | |
344 | int i; | |
345 | ||
346 | for (i = 0; i < ATABLE_SIZE; i++) | |
347 | { | |
348 | for (arec = atable[i]; arec; arec = arec->next) | |
349 | { | |
350 | if(arec->type == CONF_DLINE) | |
351 | { | |
352 | aconf = arec->aconf; | |
353 | ||
354 | if(!(aconf->flags & CONF_FLAGS_TEMPORARY)) | |
355 | continue; | |
356 | ||
357 | get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); | |
358 | ||
359 | sendto_one_numeric(source_p, RPL_STATSDLINE, | |
360 | form_str (RPL_STATSDLINE), | |
361 | 'd', host, pass, | |
362 | oper_reason ? "|" : "", | |
363 | oper_reason ? oper_reason : ""); | |
364 | } | |
365 | } | |
366 | } | |
367 | } | |
368 | ||
369 | /* stats_deny() | |
370 | * | |
371 | * input - client to report to | |
372 | * output - none | |
373 | * side effects - client is given dline list. | |
374 | */ | |
375 | static void | |
376 | stats_deny (struct Client *source_p) | |
377 | { | |
378 | char *host, *pass, *user, *oper_reason; | |
379 | struct AddressRec *arec; | |
380 | struct ConfItem *aconf; | |
381 | int i; | |
382 | ||
383 | for (i = 0; i < ATABLE_SIZE; i++) | |
384 | { | |
385 | for (arec = atable[i]; arec; arec = arec->next) | |
386 | { | |
387 | if(arec->type == CONF_DLINE) | |
388 | { | |
389 | aconf = arec->aconf; | |
390 | ||
391 | if(aconf->flags & CONF_FLAGS_TEMPORARY) | |
392 | continue; | |
393 | ||
394 | get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); | |
395 | ||
396 | sendto_one_numeric(source_p, RPL_STATSDLINE, | |
397 | form_str (RPL_STATSDLINE), | |
398 | 'D', host, pass, | |
399 | oper_reason ? "|" : "", | |
400 | oper_reason ? oper_reason : ""); | |
401 | } | |
402 | } | |
403 | } | |
404 | } | |
405 | ||
406 | ||
407 | /* stats_exempt() | |
408 | * | |
409 | * input - client to report to | |
410 | * output - none | |
411 | * side effects - client is given list of exempt blocks | |
412 | */ | |
413 | static void | |
414 | stats_exempt(struct Client *source_p) | |
415 | { | |
416 | char *name, *host, *pass, *user, *classname; | |
417 | struct AddressRec *arec; | |
418 | struct ConfItem *aconf; | |
419 | int i, port; | |
420 | ||
421 | if(ConfigFileEntry.stats_e_disabled) | |
422 | { | |
22f2f68a JT |
423 | sendto_one_numeric(source_p, ERR_DISABLED, |
424 | form_str(ERR_DISABLED), "STATS e"); | |
212380e3 AC |
425 | return; |
426 | } | |
427 | ||
428 | for (i = 0; i < ATABLE_SIZE; i++) | |
429 | { | |
430 | for (arec = atable[i]; arec; arec = arec->next) | |
431 | { | |
432 | if(arec->type == CONF_EXEMPTDLINE) | |
433 | { | |
434 | aconf = arec->aconf; | |
435 | get_printable_conf (aconf, &name, &host, &pass, | |
436 | &user, &port, &classname); | |
437 | ||
438 | sendto_one_numeric(source_p, RPL_STATSDLINE, | |
439 | form_str(RPL_STATSDLINE), | |
440 | 'e', host, pass, "", ""); | |
441 | } | |
442 | } | |
443 | }} | |
444 | ||
445 | ||
e8e79621 VY |
446 | static void\r |
447 | stats_events_cb(char *str, void *ptr)\r | |
448 | {\r | |
449 | sendto_one_numeric(ptr, RPL_STATSDEBUG, "E :%s", str);\r | |
450 | }\r | |
451 | \r | |
452 | static void\r | |
453 | stats_events (struct Client *source_p)\r | |
454 | {\r | |
455 | rb_dump_events(stats_events_cb, source_p);\r | |
456 | send_pop_queue(source_p);\r | |
212380e3 AC |
457 | } |
458 | ||
459 | /* stats_pending_glines() | |
460 | * | |
461 | * input - client pointer | |
462 | * output - none | |
463 | * side effects - client is shown list of pending glines | |
464 | */ | |
465 | static void | |
466 | stats_pending_glines (struct Client *source_p) | |
467 | { | |
468 | if(ConfigFileEntry.glines) | |
469 | { | |
5b96d9a6 | 470 | rb_dlink_node *pending_node; |
212380e3 AC |
471 | struct gline_pending *glp_ptr; |
472 | char timebuffer[MAX_DATE_STRING]; | |
473 | struct tm *tmptr; | |
474 | ||
5b96d9a6 | 475 | RB_DLINK_FOREACH (pending_node, pending_glines.head) |
212380e3 AC |
476 | { |
477 | glp_ptr = pending_node->data; | |
478 | ||
479 | tmptr = localtime (&glp_ptr->time_request1); | |
480 | strftime (timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr); | |
481 | ||
482 | sendto_one_notice(source_p, | |
483 | ":1) %s!%s@%s on %s requested gline at %s for %s@%s [%s]", | |
484 | glp_ptr->oper_nick1, | |
485 | glp_ptr->oper_user1, glp_ptr->oper_host1, | |
486 | glp_ptr->oper_server1, timebuffer, | |
487 | glp_ptr->user, glp_ptr->host, glp_ptr->reason1); | |
488 | ||
489 | if(glp_ptr->oper_nick2[0]) | |
490 | { | |
491 | tmptr = localtime (&glp_ptr->time_request2); | |
492 | strftime (timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr); | |
493 | sendto_one_notice(source_p, | |
494 | ":2) %s!%s@%s on %s requested gline at %s for %s@%s [%s]", | |
495 | glp_ptr->oper_nick2, | |
496 | glp_ptr->oper_user2, glp_ptr->oper_host2, | |
497 | glp_ptr->oper_server2, timebuffer, | |
498 | glp_ptr->user, glp_ptr->host, glp_ptr->reason2); | |
499 | } | |
500 | } | |
501 | ||
5b96d9a6 | 502 | if(rb_dlink_list_length (&pending_glines) > 0) |
212380e3 AC |
503 | sendto_one_notice(source_p, ":End of Pending G-lines"); |
504 | } | |
505 | else | |
506 | sendto_one_notice(source_p, ":This server does not support G-Lines"); | |
507 | ||
508 | } | |
509 | ||
510 | /* stats_glines() | |
511 | * | |
512 | * input - client pointer | |
513 | * output - none | |
514 | * side effects - client is shown list of glines | |
515 | */ | |
516 | static void | |
517 | stats_glines (struct Client *source_p) | |
518 | { | |
519 | if(ConfigFileEntry.glines) | |
520 | { | |
5b96d9a6 | 521 | rb_dlink_node *gline_node; |
212380e3 AC |
522 | struct ConfItem *kill_ptr; |
523 | ||
5b96d9a6 | 524 | RB_DLINK_FOREACH_PREV (gline_node, glines.tail) |
212380e3 AC |
525 | { |
526 | kill_ptr = gline_node->data; | |
527 | ||
528 | sendto_one_numeric(source_p, RPL_STATSKLINE, | |
529 | form_str(RPL_STATSKLINE), 'G', | |
530 | kill_ptr->host ? kill_ptr->host : "*", | |
531 | kill_ptr->user ? kill_ptr->user : "*", | |
532 | kill_ptr->passwd ? kill_ptr->passwd : "No Reason", | |
533 | kill_ptr->spasswd ? "|" : "", | |
534 | kill_ptr->spasswd ? kill_ptr->spasswd : ""); | |
535 | } | |
536 | } | |
537 | else | |
538 | sendto_one_notice(source_p, ":This server does not support G-Lines"); | |
539 | } | |
540 | ||
541 | ||
542 | static void | |
543 | stats_hubleaf(struct Client *source_p) | |
544 | { | |
545 | struct remote_conf *hub_p; | |
5b96d9a6 | 546 | rb_dlink_node *ptr; |
212380e3 AC |
547 | |
548 | if((ConfigFileEntry.stats_h_oper_only || | |
549 | (ConfigServerHide.flatten_links && !IsExemptShide(source_p))) && | |
550 | !IsOper(source_p)) | |
551 | { | |
552 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
553 | form_str (ERR_NOPRIVILEGES)); | |
554 | return; | |
555 | } | |
556 | ||
5b96d9a6 | 557 | RB_DLINK_FOREACH(ptr, hubleaf_conf_list.head) |
212380e3 AC |
558 | { |
559 | hub_p = ptr->data; | |
560 | ||
561 | if(hub_p->flags & CONF_HUB) | |
562 | sendto_one_numeric(source_p, RPL_STATSHLINE, | |
563 | form_str(RPL_STATSHLINE), | |
564 | hub_p->host, hub_p->server); | |
565 | else | |
566 | sendto_one_numeric(source_p, RPL_STATSLLINE, | |
567 | form_str(RPL_STATSLLINE), | |
568 | hub_p->host, hub_p->server); | |
569 | } | |
570 | } | |
571 | ||
572 | ||
573 | static void | |
574 | stats_auth (struct Client *source_p) | |
575 | { | |
576 | /* Oper only, if unopered, return ERR_NOPRIVS */ | |
577 | if((ConfigFileEntry.stats_i_oper_only == 2) && !IsOper (source_p)) | |
578 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
579 | form_str (ERR_NOPRIVILEGES)); | |
580 | ||
581 | /* If unopered, Only return matching auth blocks */ | |
582 | else if((ConfigFileEntry.stats_i_oper_only == 1) && !IsOper (source_p)) | |
583 | { | |
584 | struct ConfItem *aconf; | |
585 | char *name, *host, *pass, *user, *classname; | |
586 | int port; | |
587 | ||
588 | if(MyConnect (source_p)) | |
589 | aconf = find_conf_by_address (source_p->host, source_p->sockhost, NULL, | |
590 | (struct sockaddr *)&source_p->localClient->ip, | |
591 | CONF_CLIENT, | |
592 | source_p->localClient->ip.ss_family, | |
593 | source_p->username); | |
594 | else | |
595 | aconf = find_conf_by_address (source_p->host, NULL, NULL, NULL, CONF_CLIENT, | |
596 | 0, source_p->username); | |
597 | ||
598 | if(aconf == NULL) | |
599 | return; | |
600 | ||
601 | get_printable_conf (aconf, &name, &host, &pass, &user, &port, &classname); | |
602 | ||
603 | sendto_one_numeric(source_p, RPL_STATSILINE, form_str(RPL_STATSILINE), | |
604 | name, show_iline_prefix(source_p, aconf, user), | |
605 | host, port, classname); | |
606 | } | |
607 | ||
608 | /* Theyre opered, or allowed to see all auth blocks */ | |
609 | else | |
610 | report_auth (source_p); | |
611 | } | |
612 | ||
613 | ||
614 | static void | |
615 | stats_tklines(struct Client *source_p) | |
616 | { | |
617 | /* Oper only, if unopered, return ERR_NOPRIVS */ | |
618 | if((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper (source_p)) | |
619 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
620 | form_str (ERR_NOPRIVILEGES)); | |
621 | ||
622 | /* If unopered, Only return matching klines */ | |
623 | else if((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper (source_p)) | |
624 | { | |
625 | struct ConfItem *aconf; | |
626 | char *host, *pass, *user, *oper_reason; | |
627 | ||
628 | if(MyConnect (source_p)) | |
629 | aconf = find_conf_by_address (source_p->host, source_p->sockhost, NULL, | |
630 | (struct sockaddr *)&source_p->localClient->ip, | |
631 | CONF_KILL, | |
632 | source_p->localClient->ip.ss_family, | |
633 | source_p->username); | |
634 | else | |
635 | aconf = find_conf_by_address (source_p->host, NULL, NULL, NULL, CONF_KILL, | |
636 | 0, source_p->username); | |
637 | ||
638 | if(aconf == NULL) | |
639 | return; | |
640 | ||
641 | /* dont report a permanent kline as a tkline */ | |
642 | if((aconf->flags & CONF_FLAGS_TEMPORARY) == 0) | |
643 | return; | |
644 | ||
645 | get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); | |
646 | ||
647 | sendto_one_numeric(source_p, RPL_STATSKLINE, | |
0a621c4b JT |
648 | form_str(RPL_STATSKLINE), aconf->flags & CONF_FLAGS_TEMPORARY ? 'k' : 'K', |
649 | host, user, pass, oper_reason ? "|" : "", | |
212380e3 AC |
650 | oper_reason ? oper_reason : ""); |
651 | } | |
652 | /* Theyre opered, or allowed to see all klines */ | |
653 | else | |
654 | { | |
655 | struct ConfItem *aconf; | |
5b96d9a6 | 656 | rb_dlink_node *ptr; |
212380e3 AC |
657 | int i; |
658 | char *user, *host, *pass, *oper_reason; | |
659 | ||
660 | for(i = 0; i < LAST_TEMP_TYPE; i++) | |
661 | { | |
5b96d9a6 | 662 | RB_DLINK_FOREACH(ptr, temp_klines[i].head) |
212380e3 AC |
663 | { |
664 | aconf = ptr->data; | |
665 | ||
666 | get_printable_kline(source_p, aconf, &host, &pass, | |
667 | &user, &oper_reason); | |
668 | ||
669 | sendto_one_numeric(source_p, RPL_STATSKLINE, | |
670 | form_str(RPL_STATSKLINE), | |
671 | 'k', host, user, pass, | |
672 | oper_reason ? "|" : "", | |
673 | oper_reason ? oper_reason : ""); | |
674 | } | |
675 | } | |
676 | } | |
677 | } | |
678 | ||
679 | static void | |
680 | stats_klines(struct Client *source_p) | |
681 | { | |
682 | /* Oper only, if unopered, return ERR_NOPRIVS */ | |
683 | if((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper (source_p)) | |
684 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
685 | form_str (ERR_NOPRIVILEGES)); | |
686 | ||
687 | /* If unopered, Only return matching klines */ | |
688 | else if((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper (source_p)) | |
689 | { | |
690 | struct ConfItem *aconf; | |
691 | char *host, *pass, *user, *oper_reason; | |
692 | ||
693 | /* search for a kline */ | |
694 | if(MyConnect (source_p)) | |
695 | aconf = find_conf_by_address (source_p->host, source_p->sockhost, NULL, | |
696 | (struct sockaddr *)&source_p->localClient->ip, | |
697 | CONF_KILL, | |
698 | source_p->localClient->ip.ss_family, | |
699 | source_p->username); | |
700 | else | |
701 | aconf = find_conf_by_address (source_p->host, NULL, NULL, NULL, CONF_KILL, | |
702 | 0, source_p->username); | |
703 | ||
704 | if(aconf == NULL) | |
705 | return; | |
706 | ||
212380e3 AC |
707 | get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); |
708 | ||
709 | sendto_one_numeric(source_p, RPL_STATSKLINE, form_str(RPL_STATSKLINE), | |
0a621c4b JT |
710 | aconf->flags & CONF_FLAGS_TEMPORARY ? 'k' : 'K', |
711 | host, user, pass, oper_reason ? "|" : "", | |
212380e3 AC |
712 | oper_reason ? oper_reason : ""); |
713 | } | |
714 | /* Theyre opered, or allowed to see all klines */ | |
715 | else | |
716 | report_Klines (source_p); | |
717 | } | |
718 | ||
719 | static void | |
720 | stats_messages(struct Client *source_p) | |
721 | { | |
722 | report_messages(source_p); | |
723 | } | |
724 | ||
725 | static void | |
726 | stats_dnsbl(struct Client *source_p) | |
727 | { | |
5b96d9a6 | 728 | rb_dlink_node *ptr; |
212380e3 AC |
729 | struct Blacklist *blptr; |
730 | ||
5b96d9a6 | 731 | RB_DLINK_FOREACH(ptr, blacklist_list.head) |
212380e3 AC |
732 | { |
733 | blptr = ptr->data; | |
734 | ||
735 | /* use RPL_STATSDEBUG for now -- jilles */ | |
736 | sendto_one_numeric(source_p, RPL_STATSDEBUG, "n :%d %s %s (%d)", | |
737 | blptr->hits, | |
738 | blptr->host, | |
739 | blptr->status & CONF_ILLEGAL ? "disabled" : "active", | |
740 | blptr->refcount); | |
741 | } | |
742 | } | |
743 | ||
744 | static void | |
745 | stats_oper(struct Client *source_p) | |
746 | { | |
747 | struct oper_conf *oper_p; | |
5b96d9a6 | 748 | rb_dlink_node *ptr; |
212380e3 AC |
749 | |
750 | if(!IsOper(source_p) && ConfigFileEntry.stats_o_oper_only) | |
751 | { | |
752 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
753 | form_str (ERR_NOPRIVILEGES)); | |
754 | return; | |
755 | } | |
756 | ||
5b96d9a6 | 757 | RB_DLINK_FOREACH(ptr, oper_conf_list.head) |
212380e3 AC |
758 | { |
759 | oper_p = ptr->data; | |
760 | ||
761 | sendto_one_numeric(source_p, RPL_STATSOLINE, | |
762 | form_str(RPL_STATSOLINE), | |
763 | oper_p->username, oper_p->host, oper_p->name, | |
764 | IsOper(source_p) ? get_oper_privs(oper_p->flags) : "0", "-1"); | |
765 | } | |
766 | } | |
767 | ||
768 | ||
769 | /* stats_operedup() | |
770 | * | |
771 | * input - client pointer | |
772 | * output - none | |
773 | * side effects - client is shown a list of active opers | |
774 | */ | |
775 | static void | |
776 | stats_operedup (struct Client *source_p) | |
777 | { | |
778 | struct Client *target_p; | |
5b96d9a6 | 779 | rb_dlink_node *oper_ptr; |
212380e3 AC |
780 | unsigned int count = 0; |
781 | ||
5b96d9a6 | 782 | RB_DLINK_FOREACH (oper_ptr, oper_list.head) |
212380e3 AC |
783 | { |
784 | target_p = oper_ptr->data; | |
785 | ||
786 | if(IsOperInvis(target_p) && !IsOper(source_p)) | |
787 | continue; | |
788 | ||
789 | if(target_p->user->away) | |
790 | continue; | |
791 | ||
792 | count++; | |
793 | ||
794 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
795 | "p :%s (%s@%s)", | |
796 | target_p->name, target_p->username, | |
797 | target_p->host); | |
798 | } | |
799 | ||
800 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
801 | "p :%u staff members", count); | |
802 | ||
803 | stats_p_spy (source_p); | |
804 | } | |
805 | ||
806 | static void | |
807 | stats_ports (struct Client *source_p) | |
808 | { | |
809 | if(!IsOper (source_p) && ConfigFileEntry.stats_P_oper_only) | |
810 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
811 | form_str (ERR_NOPRIVILEGES)); | |
812 | else | |
813 | show_ports (source_p); | |
814 | } | |
815 | ||
816 | static void | |
817 | stats_tresv(struct Client *source_p) | |
818 | { | |
819 | struct ConfItem *aconf; | |
5b96d9a6 | 820 | rb_dlink_node *ptr; |
212380e3 AC |
821 | int i; |
822 | ||
5b96d9a6 | 823 | RB_DLINK_FOREACH(ptr, resv_conf_list.head) |
212380e3 AC |
824 | { |
825 | aconf = ptr->data; | |
826 | if(aconf->hold) | |
827 | sendto_one_numeric(source_p, RPL_STATSQLINE, | |
828 | form_str(RPL_STATSQLINE), | |
829 | 'q', aconf->port, aconf->name, aconf->passwd); | |
830 | } | |
831 | ||
832 | HASH_WALK(i, R_MAX, ptr, resvTable) | |
833 | { | |
834 | aconf = ptr->data; | |
835 | if(aconf->hold) | |
836 | sendto_one_numeric(source_p, RPL_STATSQLINE, | |
837 | form_str(RPL_STATSQLINE), | |
838 | 'q', aconf->port, aconf->name, aconf->passwd); | |
839 | } | |
840 | HASH_WALK_END | |
841 | } | |
842 | ||
843 | ||
844 | static void | |
845 | stats_resv(struct Client *source_p) | |
846 | { | |
847 | struct ConfItem *aconf; | |
5b96d9a6 | 848 | rb_dlink_node *ptr; |
212380e3 AC |
849 | int i; |
850 | ||
5b96d9a6 | 851 | RB_DLINK_FOREACH(ptr, resv_conf_list.head) |
212380e3 AC |
852 | { |
853 | aconf = ptr->data; | |
854 | if(!aconf->hold) | |
855 | sendto_one_numeric(source_p, RPL_STATSQLINE, | |
856 | form_str(RPL_STATSQLINE), | |
857 | 'Q', aconf->port, aconf->name, aconf->passwd); | |
858 | } | |
859 | ||
860 | HASH_WALK(i, R_MAX, ptr, resvTable) | |
861 | { | |
862 | aconf = ptr->data; | |
863 | if(!aconf->hold) | |
864 | sendto_one_numeric(source_p, RPL_STATSQLINE, | |
865 | form_str(RPL_STATSQLINE), | |
866 | 'Q', aconf->port, aconf->name, aconf->passwd); | |
867 | } | |
868 | HASH_WALK_END | |
869 | } | |
870 | ||
871 | static void | |
872 | stats_usage (struct Client *source_p) | |
873 | { | |
874 | struct rusage rus; | |
875 | time_t secs; | |
876 | time_t rup; | |
877 | #ifdef hz | |
878 | # define hzz hz | |
879 | #else | |
880 | # ifdef HZ | |
881 | # define hzz HZ | |
882 | # else | |
883 | int hzz = 1; | |
884 | # endif | |
885 | #endif | |
886 | ||
887 | if(getrusage(RUSAGE_SELF, &rus) == -1) | |
888 | { | |
889 | sendto_one_notice(source_p, ":Getruseage error: %s.", | |
890 | strerror(errno)); | |
891 | return; | |
892 | } | |
893 | secs = rus.ru_utime.tv_sec + rus.ru_stime.tv_sec; | |
894 | if(0 == secs) | |
895 | secs = 1; | |
896 | ||
897 | rup = (CurrentTime - startup_time) * hzz; | |
898 | if(0 == rup) | |
899 | rup = 1; | |
900 | ||
901 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
902 | "R :CPU Secs %d:%d User %d:%d System %d:%d", | |
903 | (int) (secs / 60), (int) (secs % 60), | |
904 | (int) (rus.ru_utime.tv_sec / 60), | |
905 | (int) (rus.ru_utime.tv_sec % 60), | |
906 | (int) (rus.ru_stime.tv_sec / 60), | |
907 | (int) (rus.ru_stime.tv_sec % 60)); | |
908 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
909 | "R :RSS %ld ShMem %ld Data %ld Stack %ld", | |
910 | rus.ru_maxrss, (rus.ru_ixrss / rup), | |
911 | (rus.ru_idrss / rup), (rus.ru_isrss / rup)); | |
912 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
913 | "R :Swaps %d Reclaims %d Faults %d", | |
914 | (int) rus.ru_nswap, (int) rus.ru_minflt, (int) rus.ru_majflt); | |
915 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
916 | "R :Block in %d out %d", | |
917 | (int) rus.ru_inblock, (int) rus.ru_oublock); | |
918 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
919 | "R :Msg Rcv %d Send %d", | |
920 | (int) rus.ru_msgrcv, (int) rus.ru_msgsnd); | |
921 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
922 | "R :Signals %d Context Vol. %d Invol %d", | |
923 | (int) rus.ru_nsignals, (int) rus.ru_nvcsw, | |
924 | (int) rus.ru_nivcsw); | |
925 | } | |
926 | ||
927 | static void | |
928 | stats_tstats (struct Client *source_p) | |
929 | { | |
930 | tstats (source_p); | |
931 | } | |
932 | ||
933 | static void | |
934 | stats_uptime (struct Client *source_p) | |
935 | { | |
936 | time_t now; | |
937 | ||
938 | now = CurrentTime - startup_time; | |
939 | sendto_one_numeric(source_p, RPL_STATSUPTIME, | |
940 | form_str (RPL_STATSUPTIME), | |
941 | now / 86400, (now / 3600) % 24, | |
942 | (now / 60) % 60, now % 60); | |
943 | sendto_one_numeric(source_p, RPL_STATSCONN, | |
944 | form_str (RPL_STATSCONN), | |
945 | MaxConnectionCount, MaxClientCount, | |
946 | Count.totalrestartcount); | |
947 | } | |
948 | ||
949 | struct shared_flags | |
950 | { | |
951 | int flag; | |
952 | char letter; | |
953 | }; | |
954 | static struct shared_flags shared_flagtable[] = | |
955 | { | |
956 | { SHARED_PKLINE, 'K' }, | |
957 | { SHARED_TKLINE, 'k' }, | |
958 | { SHARED_UNKLINE, 'U' }, | |
959 | { SHARED_PXLINE, 'X' }, | |
960 | { SHARED_TXLINE, 'x' }, | |
961 | { SHARED_UNXLINE, 'Y' }, | |
962 | { SHARED_PRESV, 'Q' }, | |
963 | { SHARED_TRESV, 'q' }, | |
964 | { SHARED_UNRESV, 'R' }, | |
965 | { SHARED_LOCOPS, 'L' }, | |
966 | { SHARED_REHASH, 'H' }, | |
967 | { 0, '\0'} | |
968 | }; | |
969 | ||
970 | ||
971 | static void | |
972 | stats_shared (struct Client *source_p) | |
973 | { | |
974 | struct remote_conf *shared_p; | |
5b96d9a6 | 975 | rb_dlink_node *ptr; |
212380e3 AC |
976 | char buf[15]; |
977 | char *p; | |
978 | int i; | |
979 | ||
5b96d9a6 | 980 | RB_DLINK_FOREACH(ptr, shared_conf_list.head) |
212380e3 AC |
981 | { |
982 | shared_p = ptr->data; | |
983 | ||
984 | p = buf; | |
985 | ||
986 | *p++ = 'c'; | |
987 | ||
988 | for(i = 0; shared_flagtable[i].flag != 0; i++) | |
989 | { | |
990 | if(shared_p->flags & shared_flagtable[i].flag) | |
991 | *p++ = shared_flagtable[i].letter; | |
992 | } | |
993 | ||
994 | *p = '\0'; | |
995 | ||
996 | sendto_one_numeric(source_p, RPL_STATSULINE, | |
997 | form_str(RPL_STATSULINE), | |
998 | shared_p->server, shared_p->username, | |
999 | shared_p->host, buf); | |
1000 | } | |
1001 | ||
5b96d9a6 | 1002 | RB_DLINK_FOREACH(ptr, cluster_conf_list.head) |
212380e3 AC |
1003 | { |
1004 | shared_p = ptr->data; | |
1005 | ||
1006 | p = buf; | |
1007 | ||
1008 | *p++ = 'C'; | |
1009 | ||
1010 | for(i = 0; shared_flagtable[i].flag != 0; i++) | |
1011 | { | |
1012 | if(shared_p->flags & shared_flagtable[i].flag) | |
1013 | *p++ = shared_flagtable[i].letter; | |
1014 | } | |
1015 | ||
1016 | *p = '\0'; | |
1017 | ||
1018 | sendto_one_numeric(source_p, RPL_STATSULINE, | |
1019 | form_str(RPL_STATSULINE), | |
1020 | shared_p->server, "*", "*", buf); | |
1021 | } | |
1022 | } | |
1023 | ||
1024 | /* stats_servers() | |
1025 | * | |
1026 | * input - client pointer | |
1027 | * output - none | |
1028 | * side effects - client is shown lists of who connected servers | |
1029 | */ | |
1030 | static void | |
1031 | stats_servers (struct Client *source_p) | |
1032 | { | |
1033 | struct Client *target_p; | |
5b96d9a6 | 1034 | rb_dlink_node *ptr; |
212380e3 AC |
1035 | time_t seconds; |
1036 | int days, hours, minutes; | |
1037 | int j = 0; | |
1038 | ||
1039 | if(ConfigServerHide.flatten_links && !IsOper(source_p) && | |
1040 | !IsExemptShide(source_p)) | |
1041 | { | |
1042 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
1043 | form_str (ERR_NOPRIVILEGES)); | |
1044 | return; | |
1045 | } | |
1046 | ||
5b96d9a6 | 1047 | RB_DLINK_FOREACH (ptr, serv_list.head) |
212380e3 AC |
1048 | { |
1049 | target_p = ptr->data; | |
1050 | ||
1051 | j++; | |
1052 | seconds = CurrentTime - target_p->localClient->firsttime; | |
1053 | ||
1054 | days = (int) (seconds / 86400); | |
1055 | seconds %= 86400; | |
1056 | hours = (int) (seconds / 3600); | |
1057 | seconds %= 3600; | |
1058 | minutes = (int) (seconds / 60); | |
1059 | seconds %= 60; | |
1060 | ||
1061 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1062 | "V :%s (%s!*@*) Idle: %d SendQ: %d " | |
1063 | "Connected: %d day%s, %d:%02d:%02d", | |
1064 | target_p->name, | |
1065 | (target_p->serv->by[0] ? target_p->serv->by : "Remote."), | |
1066 | (int) (CurrentTime - target_p->localClient->lasttime), | |
e8e79621 | 1067 | (int) rb_linebuf_len (&target_p->localClient->buf_sendq), |
212380e3 AC |
1068 | days, (days == 1) ? "" : "s", hours, minutes, |
1069 | (int) seconds); | |
1070 | } | |
1071 | ||
1072 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1073 | "V :%d Server(s)", j); | |
1074 | } | |
1075 | ||
1076 | static void | |
1077 | stats_tgecos(struct Client *source_p) | |
1078 | { | |
1079 | struct ConfItem *aconf; | |
5b96d9a6 | 1080 | rb_dlink_node *ptr; |
212380e3 | 1081 | |
5b96d9a6 | 1082 | RB_DLINK_FOREACH(ptr, xline_conf_list.head) |
212380e3 AC |
1083 | { |
1084 | aconf = ptr->data; | |
1085 | ||
1086 | if(aconf->hold) | |
1087 | sendto_one_numeric(source_p, RPL_STATSXLINE, | |
1088 | form_str(RPL_STATSXLINE), | |
1089 | 'x', aconf->port, aconf->name, | |
1090 | aconf->passwd); | |
1091 | } | |
1092 | } | |
1093 | ||
1094 | static void | |
1095 | stats_gecos(struct Client *source_p) | |
1096 | { | |
1097 | struct ConfItem *aconf; | |
5b96d9a6 | 1098 | rb_dlink_node *ptr; |
212380e3 | 1099 | |
5b96d9a6 | 1100 | RB_DLINK_FOREACH(ptr, xline_conf_list.head) |
212380e3 AC |
1101 | { |
1102 | aconf = ptr->data; | |
1103 | ||
1104 | if(!aconf->hold) | |
1105 | sendto_one_numeric(source_p, RPL_STATSXLINE, | |
1106 | form_str(RPL_STATSXLINE), | |
1107 | 'X', aconf->port, aconf->name, | |
1108 | aconf->passwd); | |
1109 | } | |
1110 | } | |
1111 | ||
1112 | static void | |
1113 | stats_class(struct Client *source_p) | |
1114 | { | |
1115 | if(ConfigFileEntry.stats_y_oper_only && !IsOper(source_p)) | |
1116 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
1117 | form_str (ERR_NOPRIVILEGES)); | |
1118 | else | |
1119 | report_classes(source_p); | |
1120 | } | |
1121 | ||
1122 | static void | |
1123 | stats_memory (struct Client *source_p) | |
1124 | { | |
1125 | count_memory (source_p); | |
1126 | } | |
1127 | ||
1128 | static void | |
1129 | stats_ziplinks (struct Client *source_p) | |
1130 | { | |
5b96d9a6 | 1131 | rb_dlink_node *ptr; |
212380e3 AC |
1132 | struct Client *target_p; |
1133 | int sent_data = 0; | |
1134 | ||
5b96d9a6 | 1135 | RB_DLINK_FOREACH (ptr, serv_list.head) |
212380e3 AC |
1136 | { |
1137 | target_p = ptr->data; | |
1138 | if(IsCapable (target_p, CAP_ZIP)) | |
1139 | { | |
1140 | /* we use memcpy(3) and a local copy of the structure to | |
1141 | * work around a register use bug on GCC on the SPARC. | |
1142 | * -jmallett, 04/27/2002 | |
1143 | */ | |
1144 | struct ZipStats zipstats; | |
1145 | memcpy (&zipstats, &target_p->localClient->zipstats, | |
1146 | sizeof (struct ZipStats)); | |
1147 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1148 | "Z :ZipLinks stats for %s send[%.2f%% compression " | |
1149 | "(%lu kB data/%lu kB wire)] recv[%.2f%% compression " | |
1150 | "(%lu kB data/%lu kB wire)]", | |
1151 | target_p->name, | |
1152 | zipstats.out_ratio, zipstats.outK, zipstats.outK_wire, | |
1153 | zipstats.in_ratio, zipstats.inK, zipstats.inK_wire); | |
1154 | sent_data++; | |
1155 | } | |
1156 | } | |
1157 | ||
1158 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1159 | "Z :%u ziplink(s)", sent_data); | |
1160 | } | |
1161 | ||
1162 | static void | |
1163 | stats_servlinks (struct Client *source_p) | |
1164 | { | |
1165 | static char Sformat[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s"; | |
1166 | long uptime, sendK, receiveK; | |
1167 | struct Client *target_p; | |
5b96d9a6 | 1168 | rb_dlink_node *ptr; |
212380e3 AC |
1169 | int j = 0; |
1170 | ||
1171 | if(ConfigServerHide.flatten_links && !IsOper (source_p) && | |
1172 | !IsExemptShide(source_p)) | |
1173 | { | |
1174 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
1175 | form_str (ERR_NOPRIVILEGES)); | |
1176 | return; | |
1177 | } | |
1178 | ||
1179 | sendK = receiveK = 0; | |
1180 | ||
5b96d9a6 | 1181 | RB_DLINK_FOREACH (ptr, serv_list.head) |
212380e3 AC |
1182 | { |
1183 | target_p = ptr->data; | |
1184 | ||
1185 | j++; | |
1186 | sendK += target_p->localClient->sendK; | |
1187 | receiveK += target_p->localClient->receiveK; | |
1188 | ||
1189 | sendto_one(source_p, Sformat, | |
1190 | get_id(&me, source_p), RPL_STATSLINKINFO, get_id(source_p, source_p), | |
1191 | get_server_name(target_p, SHOW_IP), | |
d269d0b6 | 1192 | (int) rb_linebuf_len (&target_p->localClient->buf_sendq), |
212380e3 AC |
1193 | (int) target_p->localClient->sendM, |
1194 | (int) target_p->localClient->sendK, | |
1195 | (int) target_p->localClient->receiveM, | |
1196 | (int) target_p->localClient->receiveK, | |
1197 | CurrentTime - target_p->localClient->firsttime, | |
1198 | (CurrentTime > target_p->localClient->lasttime) ? | |
1199 | (CurrentTime - target_p->localClient->lasttime) : 0, | |
1200 | IsOper (source_p) ? show_capabilities (target_p) : "TS"); | |
1201 | } | |
1202 | ||
1203 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1204 | "? :%u total server(s)", j); | |
1205 | ||
1206 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1207 | "? :Sent total : %7.2f %s", | |
1208 | _GMKv (sendK), _GMKs (sendK)); | |
1209 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1210 | "? :Recv total : %7.2f %s", | |
1211 | _GMKv (receiveK), _GMKs (receiveK)); | |
1212 | ||
1213 | uptime = (CurrentTime - startup_time); | |
1214 | ||
1215 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1216 | "? :Server send: %7.2f %s (%4.1f K/s)", | |
1217 | _GMKv (me.localClient->sendK), | |
1218 | _GMKs (me.localClient->sendK), | |
1219 | (float) ((float) me.localClient->sendK / (float) uptime)); | |
1220 | sendto_one_numeric(source_p, RPL_STATSDEBUG, | |
1221 | "? :Server recv: %7.2f %s (%4.1f K/s)", | |
1222 | _GMKv (me.localClient->receiveK), | |
1223 | _GMKs (me.localClient->receiveK), | |
1224 | (float) ((float) me.localClient->receiveK / (float) uptime)); | |
1225 | } | |
1226 | ||
1227 | static void | |
1228 | stats_ltrace(struct Client *source_p, int parc, const char *parv[]) | |
1229 | { | |
1230 | int doall = 0; | |
1231 | int wilds = 0; | |
1232 | const char *name; | |
1233 | char statchar = parv[1][0]; | |
1234 | ||
1235 | /* this is def targeted at us somehow.. */ | |
1236 | if(parc > 2 && !EmptyString(parv[2])) | |
1237 | { | |
1238 | /* directed at us generically? */ | |
1239 | if(match(parv[2], me.name) || | |
1240 | (!MyClient(source_p) && !irccmp(parv[2], me.id))) | |
1241 | { | |
1242 | name = me.name; | |
1243 | doall = 1; | |
1244 | } | |
1245 | else | |
1246 | { | |
1247 | name = parv[2]; | |
1248 | wilds = strchr(name, '*') || strchr(name, '?'); | |
1249 | } | |
1250 | ||
1251 | /* must be directed at a specific person thats not us */ | |
1252 | if(!doall && !wilds) | |
1253 | { | |
1254 | struct Client *target_p; | |
1255 | ||
1256 | if(MyClient(source_p)) | |
1257 | target_p = find_named_person(name); | |
1258 | else | |
1259 | target_p = find_person(name); | |
1260 | ||
1261 | if(target_p != NULL) | |
1262 | { | |
1263 | stats_spy(source_p, statchar, target_p->name); | |
1264 | stats_l_client(source_p, target_p, statchar); | |
1265 | } | |
1266 | else | |
1267 | sendto_one_numeric(source_p, ERR_NOSUCHSERVER, | |
1268 | form_str(ERR_NOSUCHSERVER), | |
1269 | name); | |
1270 | ||
1271 | return; | |
1272 | } | |
1273 | } | |
1274 | else | |
1275 | { | |
1276 | name = me.name; | |
1277 | doall = 1; | |
1278 | } | |
1279 | ||
1280 | stats_spy(source_p, statchar, name); | |
1281 | ||
1282 | if(doall) | |
1283 | { | |
1284 | /* local opers get everyone */ | |
1285 | if(MyOper(source_p)) | |
1286 | { | |
1287 | stats_l_list(source_p, name, doall, wilds, &unknown_list, statchar); | |
1288 | stats_l_list(source_p, name, doall, wilds, &lclient_list, statchar); | |
1289 | } | |
1290 | else | |
1291 | { | |
1292 | /* they still need themselves if theyre local.. */ | |
1293 | if(MyClient(source_p)) | |
1294 | stats_l_client(source_p, source_p, statchar); | |
1295 | ||
1296 | stats_l_list(source_p, name, doall, wilds, &local_oper_list, statchar); | |
1297 | } | |
1298 | ||
1299 | if (!ConfigServerHide.flatten_links || IsOper(source_p) || | |
1300 | IsExemptShide(source_p)) | |
1301 | stats_l_list(source_p, name, doall, wilds, &serv_list, statchar); | |
1302 | ||
1303 | return; | |
1304 | } | |
1305 | ||
1306 | /* ok, at this point theyre looking for a specific client whos on | |
1307 | * our server.. but it contains a wildcard. --fl | |
1308 | */ | |
1309 | stats_l_list(source_p, name, doall, wilds, &lclient_list, statchar); | |
1310 | ||
1311 | return; | |
1312 | } | |
1313 | ||
1314 | ||
1315 | static void | |
1316 | stats_l_list(struct Client *source_p, const char *name, int doall, int wilds, | |
5b96d9a6 | 1317 | rb_dlink_list * list, char statchar) |
212380e3 | 1318 | { |
5b96d9a6 | 1319 | rb_dlink_node *ptr; |
212380e3 AC |
1320 | struct Client *target_p; |
1321 | ||
1322 | /* send information about connections which match. note, we | |
1323 | * dont need tests for IsInvisible(), because non-opers will | |
1324 | * never get here for normal clients --fl | |
1325 | */ | |
5b96d9a6 | 1326 | RB_DLINK_FOREACH(ptr, list->head) |
212380e3 AC |
1327 | { |
1328 | target_p = ptr->data; | |
1329 | ||
1330 | if(!doall && wilds && !match(name, target_p->name)) | |
1331 | continue; | |
1332 | ||
1333 | stats_l_client(source_p, target_p, statchar); | |
1334 | } | |
1335 | } | |
1336 | ||
1337 | void | |
1338 | stats_l_client(struct Client *source_p, struct Client *target_p, | |
1339 | char statchar) | |
1340 | { | |
1341 | if(IsAnyServer(target_p)) | |
1342 | { | |
1343 | sendto_one_numeric(source_p, RPL_STATSLINKINFO, Lformat, | |
1344 | get_server_name(target_p, SHOW_IP), | |
d269d0b6 | 1345 | (int) rb_linebuf_len(&target_p->localClient->buf_sendq), |
212380e3 AC |
1346 | (int) target_p->localClient->sendM, |
1347 | (int) target_p->localClient->sendK, | |
1348 | (int) target_p->localClient->receiveM, | |
1349 | (int) target_p->localClient->receiveK, | |
1350 | CurrentTime - target_p->localClient->firsttime, | |
1351 | (CurrentTime > target_p->localClient->lasttime) ? | |
1352 | (CurrentTime - target_p->localClient->lasttime) : 0, | |
1353 | IsOper(source_p) ? show_capabilities(target_p) : "-"); | |
1354 | } | |
1355 | ||
1356 | else | |
1357 | { | |
1358 | sendto_one_numeric(source_p, RPL_STATSLINKINFO, Lformat, | |
1359 | show_ip(source_p, target_p) ? | |
1360 | (IsUpper(statchar) ? | |
1361 | get_client_name(target_p, SHOW_IP) : | |
1362 | get_client_name(target_p, HIDE_IP)) : | |
1363 | get_client_name(target_p, MASK_IP), | |
d269d0b6 | 1364 | (int) rb_linebuf_len(&target_p->localClient->buf_sendq), |
212380e3 AC |
1365 | (int) target_p->localClient->sendM, |
1366 | (int) target_p->localClient->sendK, | |
1367 | (int) target_p->localClient->receiveM, | |
1368 | (int) target_p->localClient->receiveK, | |
1369 | CurrentTime - target_p->localClient->firsttime, | |
1370 | (CurrentTime > target_p->localClient->lasttime) ? | |
1371 | (CurrentTime - target_p->localClient->lasttime) : 0, | |
1372 | "-"); | |
1373 | } | |
1374 | } | |
1375 | ||
a235e410 VY |
1376 | static void\r |
1377 | rb_dump_fd_callback(int fd, const char *desc, void *data)\r | |
1378 | {\r | |
1379 | struct Client *source_p = data;\r | |
1380 | sendto_one_numeric(source_p, RPL_STATSDEBUG, "F :fd %-3d desc '%s'", fd, desc);\r | |
1381 | }\r | |
1382 | \r | |
1383 | static void\r | |
1384 | stats_comm(struct Client *source_p)\r | |
1385 | {\r | |
1386 | rb_dump_fd(rb_dump_fd_callback, source_p);\r | |
1387 | send_pop_queue(source_p);\r | |
1388 | } | |
1389 | ||
212380e3 AC |
1390 | /* |
1391 | * stats_spy | |
1392 | * | |
1393 | * inputs - pointer to client doing the /stats | |
1394 | * - char letter they are doing /stats on | |
1395 | * output - none | |
1396 | * side effects - | |
1397 | * This little helper function reports to opers if configured. | |
1398 | * personally, I don't see why opers need to see stats requests | |
1399 | * at all. They are just "noise" to an oper, and users can't do | |
1400 | * any damage with stats requests now anyway. So, why show them? | |
1401 | * -Dianora | |
1402 | */ | |
1403 | static void | |
1404 | stats_spy(struct Client *source_p, char statchar, const char *name) | |
1405 | { | |
1406 | hook_data_int data; | |
1407 | ||
1408 | data.client = source_p; | |
1409 | data.arg1 = name; | |
1410 | data.arg2 = (int) statchar; | |
1411 | ||
1412 | call_hook(doing_stats_hook, &data); | |
1413 | } | |
1414 | ||
1415 | /* stats_p_spy() | |
1416 | * | |
1417 | * input - pointer to client doing stats | |
1418 | * ouput - | |
1419 | * side effects - call hook doing_stats_p | |
1420 | */ | |
1421 | static void | |
1422 | stats_p_spy (struct Client *source_p) | |
1423 | { | |
1424 | hook_data data; | |
1425 | ||
1426 | data.client = source_p; | |
1427 | data.arg1 = data.arg2 = NULL; | |
1428 | ||
1429 | call_hook(doing_stats_p_hook, &data); | |
1430 | } | |
1431 |