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