ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 1644
Committed: Tue Nov 6 22:20:16 2012 UTC (12 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 48478 byte(s)
Log Message:
- More config subsystem cleanups

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_stats.c: Sends the user statistics or config information.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "list.h" /* dlink_node/dlink_list */
27 #include "balloc.h"
28 #include "client.h" /* Client */
29 #include "irc_string.h"
30 #include "ircd.h" /* me */
31 #include "listener.h" /* show_ports */
32 #include "s_gline.h"
33 #include "conf.h"
34 #include "conf_class.h"
35 #include "hostmask.h"
36 #include "numeric.h" /* ERR_xxx */
37 #include "send.h" /* sendto_one */
38 #include "fdlist.h" /* PF and friends */
39 #include "s_bsd.h" /* highest_fd */
40 #include "s_misc.h" /* serv_info */
41 #include "s_serv.h" /* hunt_server */
42 #include "s_user.h" /* show_opers */
43 #include "event.h" /* events */
44 #include "dbuf.h"
45 #include "hook.h"
46 #include "parse.h"
47 #include "modules.h"
48 #include "resv.h" /* report_resv */
49 #include "whowas.h"
50 #include "watch.h"
51 #include "irc_res.h"
52
53
54 const char *from, *to;
55
56 /*
57 * This is part of the STATS replies. There is no offical numeric for this
58 * since this isnt an official command, in much the same way as HASH isnt.
59 * It is also possible that some systems wont support this call or have
60 * different field names for "struct rusage".
61 * -avalon
62 */
63 static void
64 stats_usage(struct Client *source_p, int parc, char *parv[])
65 {
66 struct rusage rus;
67 time_t secs;
68 time_t rup;
69 #ifdef hz
70 # define hzz hz
71 #else
72 # ifdef HZ
73 # define hzz HZ
74 # else
75 int hzz = 1;
76 # endif
77 #endif
78
79 if (getrusage(RUSAGE_SELF, &rus) == -1)
80 {
81 sendto_one(source_p, ":%s NOTICE %s :Getruseage error: %s",
82 me.name, source_p->name, strerror(errno));
83 return;
84 }
85
86 secs = rus.ru_utime.tv_sec + rus.ru_stime.tv_sec;
87
88 if (secs == 0)
89 secs = 1;
90
91 rup = (CurrentTime - me.localClient->since) * hzz;
92
93 if (rup == 0)
94 rup = 1;
95
96 sendto_one(source_p,
97 ":%s %d %s R :CPU Secs %d:%d User %d:%d System %d:%d",
98 me.name, RPL_STATSDEBUG, source_p->name, (int)(secs/60), (int)(secs%60),
99 (int)(rus.ru_utime.tv_sec/60), (int)(rus.ru_utime.tv_sec%60),
100 (int)(rus.ru_stime.tv_sec/60), (int)(rus.ru_stime.tv_sec%60));
101 sendto_one(source_p, ":%s %d %s R :RSS %ld ShMem %ld Data %ld Stack %ld",
102 me.name, RPL_STATSDEBUG, source_p->name, rus.ru_maxrss,
103 (rus.ru_ixrss / rup), (rus.ru_idrss / rup),
104 (rus.ru_isrss / rup));
105 sendto_one(source_p, ":%s %d %s R :Swaps %d Reclaims %d Faults %d",
106 me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_nswap,
107 (int)rus.ru_minflt, (int)rus.ru_majflt);
108 sendto_one(source_p, ":%s %d %s R :Block in %d out %d",
109 me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_inblock,
110 (int)rus.ru_oublock);
111 sendto_one(source_p, ":%s %d %s R :Msg Rcv %d Send %d",
112 me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_msgrcv,
113 (int)rus.ru_msgsnd);
114 sendto_one(source_p, ":%s %d %s R :Signals %d Context Vol. %d Invol %d",
115 me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_nsignals,
116 (int)rus.ru_nvcsw, (int)rus.ru_nivcsw);
117 }
118
119 static void
120 stats_memory(struct Client *source_p, int parc, char *parv[])
121 {
122 const dlink_node *gptr = NULL;
123 const dlink_node *dlink = NULL;
124
125 unsigned int local_client_conf_count = 0; /* local client conf links */
126 unsigned int users_counted = 0; /* user structs */
127
128 unsigned int channel_members = 0;
129 unsigned int channel_invites = 0;
130 unsigned int channel_bans = 0;
131 unsigned int channel_except = 0;
132 unsigned int channel_invex = 0;
133
134 unsigned int wwu = 0; /* whowas users */
135 unsigned int class_count = 0; /* classes */
136 unsigned int aways_counted = 0;
137 unsigned int number_ips_stored; /* number of ip addresses hashed */
138
139 uint64_t channel_memory = 0;
140 uint64_t channel_ban_memory = 0;
141 uint64_t channel_except_memory = 0;
142 uint64_t channel_invex_memory = 0;
143
144 unsigned int safelist_count = 0;
145 uint64_t safelist_memory = 0;
146
147 uint64_t wwm = 0; /* whowas array memory used */
148 uint64_t conf_memory = 0; /* memory used by conf lines */
149 uint64_t mem_ips_stored; /* memory used by ip address hash */
150
151 uint64_t total_channel_memory = 0;
152 uint64_t totww = 0;
153
154 unsigned int local_client_count = 0;
155 unsigned int remote_client_count = 0;
156
157 uint64_t local_client_memory_used = 0;
158 uint64_t remote_client_memory_used = 0;
159
160 uint64_t total_memory = 0;
161 unsigned int topic_count = 0;
162
163 unsigned int watch_list_headers = 0; /* watchlist headers */
164 unsigned int watch_list_entries = 0; /* watchlist entries */
165 uint64_t watch_list_memory = 0; /* watchlist memory used */
166
167
168 DLINK_FOREACH(gptr, global_client_list.head)
169 {
170 struct Client *target_p = gptr->data;
171
172 if (MyConnect(target_p))
173 {
174 ++local_client_count;
175 local_client_conf_count += dlink_list_length(&target_p->localClient->confs);
176 watch_list_entries += dlink_list_length(&target_p->localClient->watches);
177 }
178 else
179 ++remote_client_count;
180
181 if (IsClient(target_p))
182 {
183 ++users_counted;
184
185 if (target_p->away[0])
186 ++aways_counted;
187 }
188 }
189
190 /* Count up all channels, ban lists, except lists, Invex lists */
191 channel_memory = dlink_list_length(&global_channel_list) *
192 sizeof(struct Channel);
193 DLINK_FOREACH(gptr, global_channel_list.head)
194 {
195 const struct Ban *actualBan;
196 const struct Channel *chptr = gptr->data;
197
198 channel_members += dlink_list_length(&chptr->members);
199 channel_invites += dlink_list_length(&chptr->invites);
200
201 if (chptr->topic[0])
202 ++topic_count;
203
204 channel_bans += dlink_list_length(&chptr->banlist);
205 channel_ban_memory += dlink_list_length(&chptr->banlist) * sizeof(struct Ban);
206
207 DLINK_FOREACH(dlink, chptr->banlist.head)
208 {
209 actualBan = dlink->data;
210 assert(actualBan->who);
211
212 channel_ban_memory += actualBan->len + 1;
213 channel_ban_memory += strlen(actualBan->who) + 1;
214 }
215
216 channel_except += dlink_list_length(&chptr->exceptlist);
217 channel_except_memory += dlink_list_length(&chptr->exceptlist) * sizeof(struct Ban);
218
219 DLINK_FOREACH(dlink, chptr->exceptlist.head)
220 {
221 actualBan = dlink->data;
222 assert(actualBan->who);
223
224 channel_except_memory += actualBan->len + 1;
225 channel_except_memory += strlen(actualBan->who) + 1;
226 }
227
228 channel_invex += dlink_list_length(&chptr->invexlist);
229 channel_invex_memory += dlink_list_length(&chptr->invexlist) * sizeof(struct Ban);
230
231 DLINK_FOREACH(dlink, chptr->invexlist.head)
232 {
233 actualBan = dlink->data;
234 assert(actualBan->who);
235
236 channel_invex_memory += actualBan->len + 1;
237 channel_invex_memory += strlen(actualBan->who) + 1;
238 }
239 }
240
241 if ((safelist_count = dlink_list_length(&listing_client_list)))
242 {
243 safelist_memory = safelist_count * sizeof(struct ListTask);
244 DLINK_FOREACH(gptr, listing_client_list.head)
245 {
246 const struct Client *acptr = gptr->data;
247
248 DLINK_FOREACH(dlink, acptr->localClient->list_task->show_mask.head)
249 safelist_memory += strlen(dlink->data);
250
251 DLINK_FOREACH(dlink, acptr->localClient->list_task->hide_mask.head)
252 safelist_memory += strlen(dlink->data);
253 }
254 }
255
256 #if 0
257 /* XXX THIS has to be fixed !!!! -db */
258 /* count up all config items */
259 DLINK_FOREACH(dlink, ConfigItemList.head)
260 {
261 aconf = dlink->data;
262 conf_memory += aconf->host ? strlen(aconf->host)+1 : 0;
263 conf_memory += aconf->passwd ? strlen(aconf->passwd)+1 : 0;
264 conf_memory += aconf->name ? strlen(aconf->name)+1 : 0;
265 conf_memory += sizeof(struct AccessItem);
266 }
267 #endif
268 /* count up all classes */
269 class_count = dlink_list_length(class_get_list());
270
271 count_whowas_memory(&wwu, &wwm);
272 watch_count_memory(&watch_list_headers, &watch_list_memory);
273
274 sendto_one(source_p, ":%s %d %s z :WATCH headers %u(%u) entries %d(%u)",
275 me.name, RPL_STATSDEBUG, source_p->name, watch_list_headers,
276 watch_list_memory, watch_list_entries,
277 watch_list_entries * sizeof(dlink_node) * 2);
278
279 sendto_one(source_p, ":%s %d %s z :Clients %u(%u)",
280 me.name, RPL_STATSDEBUG, source_p->name, users_counted,
281 (users_counted * sizeof(struct Client)));
282
283 sendto_one(source_p, ":%s %d %s z :User aways %u",
284 me.name, RPL_STATSDEBUG, source_p->name,
285 aways_counted);
286
287 sendto_one(source_p, ":%s %d %s z :Attached confs %u(%llu)",
288 me.name, RPL_STATSDEBUG, source_p->name,
289 local_client_conf_count,
290 (unsigned long long)(local_client_conf_count * sizeof(dlink_node)));
291
292 sendto_one(source_p, ":%s %d %s z :Resv channels %u(%lu) nicks %u(%lu)",
293 me.name, RPL_STATSDEBUG, source_p->name,
294 dlink_list_length(&resv_channel_list),
295 dlink_list_length(&resv_channel_list) * sizeof(struct MaskItem),
296 dlink_list_length(&nresv_items),
297 dlink_list_length(&nresv_items) * sizeof(struct MaskItem));
298
299 sendto_one(source_p, ":%s %d %s z :Classes %u(%llu)",
300 me.name, RPL_STATSDEBUG, source_p->name,
301 class_count, (unsigned long long)(class_count * sizeof(struct ClassItem)));
302
303 sendto_one(source_p, ":%s %d %s z :Channels %uu(%llu) Topics %u(%u)",
304 me.name, RPL_STATSDEBUG, source_p->name,
305 dlink_list_length(&global_channel_list),
306 channel_memory, topic_count, topic_count *
307 (TOPICLEN + 1 + USERHOST_REPLYLEN));
308
309 sendto_one(source_p, ":%s %d %s z :Bans %u(%llu)",
310 me.name, RPL_STATSDEBUG, source_p->name,
311 channel_bans, channel_ban_memory);
312
313 sendto_one(source_p, ":%s %d %s z :Exceptions %u(%llu)",
314 me.name, RPL_STATSDEBUG, source_p->name,
315 channel_except, channel_except_memory);
316
317 sendto_one(source_p, ":%s %d %s z :Invex %u(%llu)",
318 me.name, RPL_STATSDEBUG, source_p->name,
319 channel_invex, channel_invex_memory);
320
321 sendto_one(source_p, ":%s %d %s z :Channel members %u(%llu) invites %u(%llu)",
322 me.name, RPL_STATSDEBUG, source_p->name, channel_members,
323 (unsigned long long)(channel_members * sizeof(struct Membership)),
324 channel_invites, (unsigned long long)channel_invites *
325 sizeof(dlink_node) * 2);
326
327 total_channel_memory = channel_memory + channel_ban_memory +
328 channel_members * sizeof(struct Membership) +
329 (channel_invites * sizeof(dlink_node)*2);
330
331 sendto_one(source_p, ":%s %d %s z :Safelist %u(%llu)",
332 me.name, RPL_STATSDEBUG, source_p->name,
333 safelist_count, safelist_memory);
334
335 sendto_one(source_p, ":%s %d %s z :Whowas users %u(%llu)",
336 me.name, RPL_STATSDEBUG, source_p->name,
337 wwu, (unsigned long long)(wwu * sizeof(struct Client)));
338
339 sendto_one(source_p, ":%s %d %s z :Whowas array %u(%llu)",
340 me.name, RPL_STATSDEBUG, source_p->name,
341 NICKNAMEHISTORYLENGTH, wwm);
342
343 totww = wwu * sizeof(struct Client) + wwm;
344
345 count_ip_hash(&number_ips_stored,&mem_ips_stored);
346 sendto_one(source_p, ":%s %d %s z :iphash %u(%llu)",
347 me.name, RPL_STATSDEBUG, source_p->name,
348 number_ips_stored, mem_ips_stored);
349
350 total_memory = totww + total_channel_memory + conf_memory + class_count *
351 sizeof(struct ClassItem);
352 sendto_one(source_p, ":%s %d %s z :Total: whowas %llu channel %llu conf %llu",
353 me.name, RPL_STATSDEBUG, source_p->name, totww,
354 total_channel_memory, conf_memory);
355
356 local_client_memory_used = local_client_count*(sizeof(struct Client) + sizeof(struct LocalUser));
357 total_memory += local_client_memory_used;
358 sendto_one(source_p, ":%s %d %s z :Local client Memory in use: %u(%llu)",
359 me.name, RPL_STATSDEBUG, source_p->name, local_client_count,
360 local_client_memory_used);
361
362 remote_client_memory_used = remote_client_count * sizeof(struct Client);
363 total_memory += remote_client_memory_used;
364 sendto_one(source_p, ":%s %d %s z :Remote client Memory in use: %u(%llu)",
365 me.name, RPL_STATSDEBUG, source_p->name, remote_client_count,
366 remote_client_memory_used);
367
368 block_heap_report_stats(source_p);
369
370 sendto_one(source_p,
371 ":%s %d %s z :TOTAL: %llu",
372 me.name, RPL_STATSDEBUG, source_p->name,
373 total_memory);
374 }
375
376 static void
377 stats_dns_servers(struct Client *source_p)
378 {
379 report_dns_servers(source_p);
380 }
381
382 static void
383 stats_connect(struct Client *source_p, int parc, char *parv[])
384 {
385 report_confitem_types(source_p, CONF_SERVER);
386 }
387
388 /* stats_deny()
389 *
390 * input - client to report to
391 * output - none
392 * side effects - client is given dline list.
393 */
394 static void
395 stats_deny(struct Client *source_p, int parc, char *parv[])
396 {
397 struct MaskItem *conf;
398 dlink_node *ptr = NULL;
399 unsigned int i = 0;
400
401
402 for (i = 0; i < ATABLE_SIZE; ++i)
403 {
404 DLINK_FOREACH(ptr, atable[i].head)
405 {
406 struct AddressRec *arec = ptr->data;
407
408 if (arec->type != CONF_DLINE)
409 continue;
410
411 conf = arec->conf;
412
413 /* dont report a tdline as a dline */
414 if (conf->hold)
415 continue;
416
417 sendto_one(source_p, form_str(RPL_STATSDLINE),
418 from, to, 'D', conf->host, conf->reason);
419 }
420 }
421 }
422
423 /* stats_tdeny()
424 *
425 * input - client to report to
426 * output - none
427 * side effects - client is given dline list.
428 */
429 static void
430 stats_tdeny(struct Client *source_p, int parc, char *parv[])
431 {
432 struct MaskItem *conf = NULL;
433 dlink_node *ptr = NULL;
434 unsigned int i = 0;
435
436
437 for (i = 0; i < ATABLE_SIZE; ++i)
438 {
439 DLINK_FOREACH(ptr, atable[i].head)
440 {
441 struct AddressRec *arec = ptr->data;
442
443 if (arec->type != CONF_DLINE)
444 continue;
445
446 conf = arec->conf;
447
448 /* dont report a permanent dline as a tdline */
449 if (!conf->hold)
450 continue;
451
452 sendto_one(source_p, form_str(RPL_STATSDLINE),
453 from, to, 'd', conf->host, conf->reason);
454 }
455 }
456 }
457
458 /* stats_exempt()
459 *
460 * input - client to report to
461 * output - none
462 * side effects - client is given list of exempt blocks
463 */
464 static void
465 stats_exempt(struct Client *source_p, int parc, char *parv[])
466 {
467 struct MaskItem *conf;
468 dlink_node *ptr = NULL;
469 unsigned int i = 0;
470
471 if (ConfigFileEntry.stats_e_disabled)
472 {
473 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
474 from, to);
475 return;
476 }
477
478
479 for (i = 0; i < ATABLE_SIZE; ++i)
480 {
481 DLINK_FOREACH(ptr, atable[i].head)
482 {
483 struct AddressRec *arec = ptr->data;
484
485 if (arec->type != CONF_EXEMPT)
486 continue;
487
488 conf = arec->conf;
489
490 sendto_one(source_p, form_str(RPL_STATSDLINE),
491 from, to, 'e', conf->host, conf->reason /* XXX */);
492 }
493 }
494 }
495
496 static void
497 stats_events(struct Client *source_p, int parc, char *parv[])
498 {
499 show_events(source_p);
500 }
501
502 /* stats_pending_glines()
503 *
504 * input - client pointer
505 * output - none
506 * side effects - client is shown list of pending glines
507 */
508 static void
509 stats_pending_glines(struct Client *source_p, int parc, char *parv[])
510 {
511 const dlink_node *dn_ptr = NULL;
512 const struct gline_pending *glp_ptr = NULL;
513 char timebuffer[MAX_DATE_STRING] = { '\0' };
514 struct tm *tmptr = NULL;
515
516 if (!ConfigFileEntry.glines)
517 {
518 sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
519 from, to);
520 return;
521 }
522
523 if (dlink_list_length(&pending_glines[GLINE_PENDING_ADD_TYPE]) > 0)
524 sendto_one(source_p, ":%s NOTICE %s :Pending G-lines",
525 from, to);
526
527 DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_ADD_TYPE].head)
528 {
529 glp_ptr = dn_ptr->data;
530 tmptr = localtime(&glp_ptr->vote_1.time_request);
531 strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
532
533 sendto_one(source_p,
534 ":%s NOTICE %s :1) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
535 from, to, glp_ptr->vote_1.oper_nick,
536 glp_ptr->vote_1.oper_user, glp_ptr->vote_1.oper_host,
537 glp_ptr->vote_1.oper_server, timebuffer,
538 glp_ptr->user, glp_ptr->host, glp_ptr->vote_1.reason);
539
540 if (glp_ptr->vote_2.oper_nick[0] != '\0')
541 {
542 tmptr = localtime(&glp_ptr->vote_2.time_request);
543 strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
544 sendto_one(source_p,
545 ":%s NOTICE %s :2) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
546 from, to, glp_ptr->vote_2.oper_nick,
547 glp_ptr->vote_2.oper_user, glp_ptr->vote_2.oper_host,
548 glp_ptr->vote_2.oper_server, timebuffer,
549 glp_ptr->user, glp_ptr->host, glp_ptr->vote_2.reason);
550 }
551 }
552
553 sendto_one(source_p, ":%s NOTICE %s :End of Pending G-lines",
554 from, to);
555
556 if (dlink_list_length(&pending_glines[GLINE_PENDING_DEL_TYPE]) > 0)
557 sendto_one(source_p, ":%s NOTICE %s :Pending UNG-lines",
558 from, to);
559
560 DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_DEL_TYPE].head)
561 {
562 glp_ptr = dn_ptr->data;
563 tmptr = localtime(&glp_ptr->vote_1.time_request);
564 strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
565
566 sendto_one(source_p,
567 ":%s NOTICE %s :1) %s!%s@%s on %s requested ungline at %s for %s@%s [%s]",
568 from, to, glp_ptr->vote_1.oper_nick,
569 glp_ptr->vote_1.oper_user, glp_ptr->vote_1.oper_host,
570 glp_ptr->vote_1.oper_server, timebuffer,
571 glp_ptr->user, glp_ptr->host, glp_ptr->vote_1.reason);
572
573 if (glp_ptr->vote_2.oper_nick[0] != '\0')
574 {
575 tmptr = localtime(&glp_ptr->vote_2.time_request);
576 strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
577 sendto_one(source_p,
578 ":%s NOTICE %s :2) %s!%s@%s on %s requested ungline at %s for %s@%s [%s]",
579 from, to, glp_ptr->vote_2.oper_nick,
580 glp_ptr->vote_2.oper_user, glp_ptr->vote_2.oper_host,
581 glp_ptr->vote_2.oper_server, timebuffer,
582 glp_ptr->user, glp_ptr->host, glp_ptr->vote_2.reason);
583
584 }
585 }
586
587 sendto_one(source_p, ":%s NOTICE %s :End of Pending UNG-lines",
588 from, to);
589 }
590
591 /* stats_glines()
592 *
593 * input - client pointer
594 * output - none
595 * side effects - client is shown list of glines
596 */
597 static void
598 stats_glines(struct Client *source_p, int parc, char *parv[])
599 {
600 dlink_node *ptr = NULL;
601 unsigned int i = 0;
602
603 if (!ConfigFileEntry.glines)
604 {
605 sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
606 from, to);
607 return;
608 }
609
610 for (i = 0; i < ATABLE_SIZE; ++i)
611 {
612 DLINK_FOREACH(ptr, atable[i].head)
613 {
614 const struct AddressRec *arec = ptr->data;
615
616 if (arec->type == CONF_GLINE)
617 {
618 const struct MaskItem *conf = arec->conf;
619
620 sendto_one(source_p, form_str(RPL_STATSKLINE),
621 from, to, "G",
622 conf->host ? conf->host : "*",
623 conf->user ? conf->user : "*",
624 conf->reason ? conf->reason : "No reason");
625 }
626 }
627 }
628 }
629
630 static void
631 stats_hubleaf(struct Client *source_p, int parc, char *parv[])
632 {
633 report_confitem_types(source_p, CONF_HUB);
634 }
635
636 /*
637 * show_iline_prefix()
638 *
639 * inputs - pointer to struct Client requesting output
640 * - pointer to struct MaskItem
641 * - name to which iline prefix will be prefixed to
642 * output - pointer to static string with prefixes listed in ascii form
643 * side effects - NONE
644 */
645 static const char *
646 show_iline_prefix(const struct Client *sptr, const struct MaskItem *conf)
647 {
648 static char prefix_of_host[USERLEN + 14];
649 char *prefix_ptr = prefix_of_host;
650
651 if (IsNoTilde(conf))
652 *prefix_ptr++ = '-';
653 if (IsLimitIp(conf))
654 *prefix_ptr++ = '!';
655 if (IsNeedIdentd(conf))
656 *prefix_ptr++ = '+';
657 if (!IsNeedPassword(conf))
658 *prefix_ptr++ = '&';
659 if (IsConfExemptResv(conf))
660 *prefix_ptr++ = '$';
661 if (IsNoMatchIp(conf))
662 *prefix_ptr++ = '%';
663 if (IsConfDoSpoofIp(conf))
664 *prefix_ptr++ = '=';
665 if (MyOper(sptr) && IsConfExemptKline(conf))
666 *prefix_ptr++ = '^';
667 if (MyOper(sptr) && IsConfExemptGline(conf))
668 *prefix_ptr++ = '_';
669 if (MyOper(sptr) && IsConfExemptLimits(conf))
670 *prefix_ptr++ = '>';
671 if (IsConfCanFlood(conf))
672 *prefix_ptr++ = '|';
673
674 strlcpy(prefix_ptr, conf->user, USERLEN+1);
675
676 return prefix_of_host;
677 }
678
679 static void
680 report_auth(struct Client *client_p, int parc, char *parv[])
681 {
682 struct MaskItem *conf = NULL;
683 dlink_node *ptr = NULL;
684 unsigned int i;
685
686
687 for (i = 0; i < ATABLE_SIZE; ++i)
688 {
689 DLINK_FOREACH(ptr, atable[i].head)
690 {
691 struct AddressRec *arec = ptr->data;
692
693 if (arec->type != CONF_CLIENT)
694 continue;
695
696 conf = arec->conf;
697
698 if (!MyOper(client_p) && IsConfDoSpoofIp(conf))
699 continue;
700
701 /* We are doing a partial list, based on what matches the u@h of the
702 * sender, so prepare the strings for comparing --fl_
703 */
704 if (ConfigFileEntry.hide_spoof_ips)
705 sendto_one(client_p, form_str(RPL_STATSILINE), me.name,
706 client_p->name, 'I',
707 conf->name == NULL ? "*" : conf->name,
708 show_iline_prefix(client_p, conf),
709 IsConfDoSpoofIp(conf) ? "255.255.255.255" :
710 conf->host, conf->port,
711 conf->class ? conf->class->name : "<default>");
712
713 else
714 sendto_one(client_p, form_str(RPL_STATSILINE), me.name,
715 client_p->name, 'I',
716 conf->name == NULL ? "*" : conf->name,
717 show_iline_prefix(client_p, conf),
718 conf->host, conf->port,
719 conf->class ? conf->class->name : "<default>");
720 }
721 }
722 }
723
724 static void
725 stats_auth(struct Client *source_p, int parc, char *parv[])
726 {
727 /* Oper only, if unopered, return ERR_NOPRIVILEGES */
728 if ((ConfigFileEntry.stats_i_oper_only == 2) && !HasUMode(source_p, UMODE_OPER))
729 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
730 from, to);
731
732 /* If unopered, Only return matching auth blocks */
733 else if ((ConfigFileEntry.stats_i_oper_only == 1) && !HasUMode(source_p, UMODE_OPER))
734 {
735 struct MaskItem *conf;
736
737 if (MyConnect(source_p))
738 conf = find_conf_by_address(source_p->host,
739 &source_p->localClient->ip,
740 CONF_CLIENT,
741 source_p->localClient->aftype,
742 source_p->username,
743 source_p->localClient->passwd, 1);
744 else
745 conf = find_conf_by_address(source_p->host, NULL, CONF_CLIENT,
746 0, source_p->username, NULL, 1);
747
748 if (conf == NULL)
749 return;
750
751 sendto_one(source_p, form_str(RPL_STATSILINE), from,
752 to, 'I',
753 "*", show_iline_prefix(source_p, conf),
754 conf->host, conf->port,
755 conf->class ? conf->class->name : "<default>");
756 }
757 /* They are opered, or allowed to see all auth blocks */
758 else
759 report_auth(source_p, 0, NULL);
760 }
761
762 /* report_Klines()
763 * Inputs: Client to report to,
764 * type(==0 for perm, !=0 for temporary)
765 * mask
766 * Output: None
767 * Side effects: Reports configured K(or k)-lines to client_p.
768 */
769 static void
770 report_Klines(struct Client *client_p, int tkline)
771 {
772 struct MaskItem *conf = NULL;
773 unsigned int i = 0;
774 const char *p = NULL;
775 dlink_node *ptr = NULL;
776
777 if (tkline)
778 p = "k";
779 else
780 p = "K";
781
782 for (i = 0; i < ATABLE_SIZE; ++i)
783 {
784 DLINK_FOREACH(ptr, atable[i].head)
785 {
786 struct AddressRec *arec = ptr->data;
787
788 if (arec->type != CONF_KLINE)
789 continue;
790
791 conf = arec->conf;
792
793 if (!tkline && conf->hold)
794 continue;
795
796 if (HasUMode(client_p, UMODE_OPER))
797 sendto_one(client_p, form_str(RPL_STATSKLINE), me.name,
798 client_p->name, p, conf->host, conf->user,
799 conf->reason);
800 else
801 sendto_one(client_p, form_str(RPL_STATSKLINE), me.name,
802 client_p->name, p, conf->host, conf->user,
803 conf->reason);
804 }
805 }
806 }
807
808 static void
809 stats_tklines(struct Client *source_p, int parc, char *parv[])
810 {
811 /* Oper only, if unopered, return ERR_NOPRIVILEGES */
812 if ((ConfigFileEntry.stats_k_oper_only == 2) && !HasUMode(source_p, UMODE_OPER))
813 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
814 from, to);
815
816 /* If unopered, Only return matching klines */
817 else if ((ConfigFileEntry.stats_k_oper_only == 1) && !HasUMode(source_p, UMODE_OPER))
818 {
819 struct MaskItem *conf = NULL;
820
821 if (MyConnect(source_p))
822 conf = find_conf_by_address(source_p->host,
823 &source_p->localClient->ip,
824 CONF_KLINE,
825 source_p->localClient->aftype,
826 source_p->username, NULL, 1);
827 else
828 conf = find_conf_by_address(source_p->host, NULL, CONF_KLINE,
829 0, source_p->username, NULL, 1);
830
831 if (!conf)
832 return;
833
834 /* dont report a permanent kline as a tkline */
835 if (!conf->hold)
836 return;
837
838 sendto_one(source_p, form_str(RPL_STATSKLINE), from,
839 to, "k", conf->host, conf->user, conf->reason);
840 }
841 /* Theyre opered, or allowed to see all klines */
842 else {
843 report_Klines(source_p, 1);
844 }
845 }
846
847 static void
848 stats_klines(struct Client *source_p, int parc, char *parv[])
849 {
850 /* Oper only, if unopered, return ERR_NOPRIVILEGES */
851 if ((ConfigFileEntry.stats_k_oper_only == 2) && !HasUMode(source_p, UMODE_OPER))
852 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
853 from, to);
854
855 /* If unopered, Only return matching klines */
856 else if ((ConfigFileEntry.stats_k_oper_only == 1) && !HasUMode(source_p, UMODE_OPER))
857 {
858 struct MaskItem *conf = NULL;
859
860 /* search for a kline */
861 if (MyConnect(source_p))
862 conf = find_conf_by_address(source_p->host,
863 &source_p->localClient->ip,
864 CONF_KLINE,
865 source_p->localClient->aftype,
866 source_p->username, NULL, 0);
867 else
868 conf = find_conf_by_address(source_p->host, NULL, CONF_KLINE,
869 0, source_p->username, NULL, 0);
870
871 if (!conf)
872 return;
873
874 /* dont report a tkline as a kline */
875 if (conf->hold)
876 return;
877
878 sendto_one(source_p, form_str(RPL_STATSKLINE), from,
879 to, "K", conf->host, conf->user, conf->reason);
880 }
881 /* Theyre opered, or allowed to see all klines */
882 else {
883 report_Klines(source_p, 0);
884 report_confitem_types(source_p, CONF_RKLINE);
885 }
886 }
887
888 static void
889 stats_messages(struct Client *source_p, int parc, char *parv[])
890 {
891 report_messages(source_p);
892 }
893
894 static void
895 stats_oper(struct Client *source_p, int parc, char *parv[])
896 {
897 if (!HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.stats_o_oper_only)
898 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
899 from, to);
900 else
901 report_confitem_types(source_p, CONF_OPER);
902 }
903
904 /* stats_operedup()
905 *
906 * input - client pointer
907 * output - none
908 * side effects - client is shown a list of active opers
909 */
910 static void
911 stats_operedup(struct Client *source_p, int parc, char *parv[])
912 {
913 dlink_node *ptr;
914
915 DLINK_FOREACH(ptr, oper_list.head)
916 {
917 const struct Client *target_p = ptr->data;
918
919 if (HasUMode(target_p, UMODE_HIDDEN) && !HasUMode(source_p, UMODE_OPER))
920 continue;
921
922 if (MyClient(source_p) && HasUMode(source_p, UMODE_OPER))
923 sendto_one(source_p, ":%s %d %s p :[%c][%s] %s (%s@%s) Idle: %d",
924 from, RPL_STATSDEBUG, to,
925 HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O',
926 oper_privs_as_string(target_p->localClient->operflags),
927 target_p->name, target_p->username, target_p->host,
928 (int)(CurrentTime - target_p->localClient->last_privmsg));
929 else
930 sendto_one(source_p, ":%s %d %s p :[%c] %s (%s@%s) Idle: %d",
931 from, RPL_STATSDEBUG, to,
932 HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O',
933 target_p->name, target_p->username, target_p->host,
934 (int)(CurrentTime - target_p->localClient->last_privmsg));
935 }
936
937 sendto_one(source_p, ":%s %d %s p :%lu OPER(s)",
938 from, RPL_STATSDEBUG, to, dlink_list_length(&oper_list));
939 }
940
941 static void
942 stats_ports(struct Client *source_p, int parc, char *parv[])
943 {
944 if (!HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.stats_P_oper_only)
945 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
946 from, to);
947 else
948 show_ports(source_p);
949 }
950
951 static void
952 stats_resv(struct Client *source_p, int parc, char *parv[])
953 {
954 report_resv(source_p);
955 }
956
957 static void
958 stats_service(struct Client *source_p, int parc, char *parv[])
959 {
960 report_confitem_types(source_p, CONF_SERVICE);
961 }
962
963 static void
964 stats_tstats(struct Client *source_p, int parc, char *parv[])
965 {
966 const struct Client *target_p = NULL;
967 const dlink_node *ptr = NULL;
968 struct ServerStatistics *sp;
969 struct ServerStatistics tmp;
970
971 sp = &tmp;
972 memcpy(sp, &ServerStats, sizeof(struct ServerStatistics));
973
974 /*
975 * must use the += operator. is_sv is not the number of currently
976 * active server connections. Note the incrementation in
977 * s_bsd.c:close_connection.
978 */
979 sp->is_sv += dlink_list_length(&serv_list);
980
981 DLINK_FOREACH(ptr, serv_list.head)
982 {
983 target_p = ptr->data;
984
985 sp->is_sbs += target_p->localClient->send.bytes;
986 sp->is_sbr += target_p->localClient->recv.bytes;
987 sp->is_sti += CurrentTime - target_p->localClient->firsttime;
988 }
989
990 sp->is_cl += dlink_list_length(&local_client_list);
991
992 DLINK_FOREACH(ptr, local_client_list.head)
993 {
994 target_p = ptr->data;
995
996 sp->is_cbs += target_p->localClient->send.bytes;
997 sp->is_cbr += target_p->localClient->recv.bytes;
998 sp->is_cti += CurrentTime - target_p->localClient->firsttime;
999 }
1000
1001 sp->is_ni += dlink_list_length(&unknown_list);
1002
1003 sendto_one(source_p, ":%s %d %s T :accepts %u refused %u",
1004 me.name, RPL_STATSDEBUG, source_p->name, sp->is_ac, sp->is_ref);
1005 sendto_one(source_p, ":%s %d %s T :unknown commands %u prefixes %u",
1006 me.name, RPL_STATSDEBUG, source_p->name, sp->is_unco, sp->is_unpf);
1007 sendto_one(source_p, ":%s %d %s T :nick collisions %u unknown closes %u",
1008 me.name, RPL_STATSDEBUG, source_p->name, sp->is_kill, sp->is_ni);
1009 sendto_one(source_p, ":%s %d %s T :wrong direction %u empty %u",
1010 me.name, RPL_STATSDEBUG, source_p->name, sp->is_wrdi, sp->is_empt);
1011 sendto_one(source_p, ":%s %d %s T :numerics seen %u",
1012 me.name, RPL_STATSDEBUG, source_p->name, sp->is_num);
1013 sendto_one(source_p, ":%s %d %s T :auth successes %u fails %u",
1014 me.name, RPL_STATSDEBUG, source_p->name, sp->is_asuc, sp->is_abad);
1015 sendto_one(source_p, ":%s %d %s T :Client Server",
1016 me.name, RPL_STATSDEBUG, source_p->name);
1017
1018 sendto_one(source_p, ":%s %d %s T :connected %u %u",
1019 me.name, RPL_STATSDEBUG, source_p->name,
1020 (unsigned int)sp->is_cl,
1021 (unsigned int)sp->is_sv);
1022 sendto_one(source_p, ":%s %d %s T :bytes sent %llu %llu",
1023 me.name, RPL_STATSDEBUG, source_p->name,
1024 sp->is_cbs, sp->is_sbs);
1025 sendto_one(source_p, ":%s %d %s T :bytes recv %llu %llu",
1026 me.name, RPL_STATSDEBUG, source_p->name,
1027 sp->is_cbr, sp->is_sbr);
1028 sendto_one(source_p, ":%s %d %s T :time connected %u %u",
1029 me.name, RPL_STATSDEBUG, source_p->name,
1030 (unsigned int)sp->is_cti,
1031 (unsigned int)sp->is_sti);
1032 }
1033
1034 static void
1035 stats_uptime(struct Client *source_p, int parc, char *parv[])
1036 {
1037 time_t now = CurrentTime - me.localClient->since;
1038
1039 sendto_one(source_p, form_str(RPL_STATSUPTIME), from, to,
1040 now / 86400, (now / 3600) % 24, (now / 60) % 60, now % 60);
1041
1042 if (!ConfigFileEntry.disable_remote || HasUMode(source_p, UMODE_OPER))
1043 sendto_one(source_p, form_str(RPL_STATSCONN), from, to,
1044 Count.max_loc_con, Count.max_loc_cli, Count.totalrestartcount);
1045 }
1046
1047 static void
1048 stats_shared(struct Client *source_p, int parc, char *parv[])
1049 {
1050 report_confitem_types(source_p, CONF_ULINE);
1051 }
1052
1053 /* stats_servers()
1054 *
1055 * input - client pointer
1056 * output - none
1057 * side effects - client is shown lists of who connected servers
1058 */
1059 static void
1060 stats_servers(struct Client *source_p, int parc, char *parv[])
1061 {
1062 dlink_node *ptr = NULL;
1063
1064 DLINK_FOREACH(ptr, serv_list.head)
1065 {
1066 const struct Client *target_p = ptr->data;
1067
1068 sendto_one(source_p, ":%s %d %s v :%s (%s!%s@%s) Idle: %d",
1069 from, RPL_STATSDEBUG, to, target_p->name,
1070 (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
1071 "*", "*", (int)(CurrentTime - target_p->localClient->lasttime));
1072 }
1073
1074 sendto_one(source_p, ":%s %d %s v :%u Server(s)",
1075 from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list));
1076 }
1077
1078 static void
1079 stats_gecos(struct Client *source_p, int parc, char *parv[])
1080 {
1081 report_confitem_types(source_p, CONF_XLINE);
1082 report_confitem_types(source_p, CONF_RXLINE);
1083 }
1084
1085 static void
1086 stats_class(struct Client *source_p, int parc, char *parv[])
1087 {
1088 report_confitem_types(source_p, CONF_CLASS);
1089 }
1090
1091 static void
1092 stats_servlinks(struct Client *source_p, int parc, char *parv[])
1093 {
1094 uint64_t sendB = 0, recvB = 0;
1095 time_t uptime = 0;
1096 dlink_node *ptr = NULL;
1097
1098 if (ConfigServerHide.flatten_links && !HasUMode(source_p, UMODE_OPER))
1099 {
1100 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1101 from, to);
1102 return;
1103 }
1104
1105 DLINK_FOREACH(ptr, serv_list.head)
1106 {
1107 struct Client *target_p = ptr->data;
1108
1109 sendB += target_p->localClient->send.bytes;
1110 recvB += target_p->localClient->recv.bytes;
1111
1112 /* ":%s 211 %s %s %u %u %llu %u %llu :%u %u %s" */
1113 sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1114 from, to,
1115 get_client_name(target_p, HasUMode(source_p, UMODE_ADMIN) ? SHOW_IP : MASK_IP),
1116 dbuf_length(&target_p->localClient->buf_sendq),
1117 target_p->localClient->send.messages,
1118 target_p->localClient->send.bytes >> 10,
1119 target_p->localClient->recv.messages,
1120 target_p->localClient->recv.bytes >> 10,
1121 (unsigned)(CurrentTime - target_p->localClient->firsttime),
1122 (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since): 0,
1123 HasUMode(source_p, UMODE_OPER) ? show_capabilities(target_p) : "TS");
1124 }
1125
1126 sendB >>= 10;
1127 recvB >>= 10;
1128
1129 sendto_one(source_p, ":%s %d %s ? :%u total server(s)",
1130 from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list));
1131 sendto_one(source_p, ":%s %d %s ? :Sent total : %7.2f %s",
1132 from, RPL_STATSDEBUG, to,
1133 _GMKv(sendB), _GMKs(sendB));
1134 sendto_one(source_p, ":%s %d %s ? :Recv total : %7.2f %s",
1135 from, RPL_STATSDEBUG, to,
1136 _GMKv(recvB), _GMKs(recvB));
1137
1138 uptime = (CurrentTime - me.localClient->since);
1139
1140 sendto_one(source_p, ":%s %d %s ? :Server send: %7.2f %s (%4.1f K/s)",
1141 from, RPL_STATSDEBUG, to,
1142 _GMKv((me.localClient->send.bytes>>10)),
1143 _GMKs((me.localClient->send.bytes>>10)),
1144 (float)((float)((me.localClient->send.bytes) >> 10) /
1145 (float)uptime));
1146 sendto_one(source_p, ":%s %d %s ? :Server recv: %7.2f %s (%4.1f K/s)",
1147 from, RPL_STATSDEBUG, to,
1148 _GMKv((me.localClient->recv.bytes>>10)),
1149 _GMKs((me.localClient->recv.bytes>>10)),
1150 (float)((float)((me.localClient->recv.bytes) >> 10) /
1151 (float)uptime));
1152 }
1153
1154 /* parse_stats_args()
1155 *
1156 * inputs - arg count
1157 * - args
1158 * - doall flag
1159 * - wild card or not
1160 * output - pointer to name to use
1161 * side effects -
1162 * common parse routine for m_stats args
1163 *
1164 */
1165 static char *
1166 parse_stats_args(int parc, char *parv[], int *doall, int *wilds)
1167 {
1168 char *name;
1169
1170 if (parc > 2)
1171 {
1172 name = parv[2];
1173
1174 if (!irccmp(name, from))
1175 *doall = 2;
1176 else if (match(name, from))
1177 *doall = 1;
1178
1179 *wilds = has_wildcards(name);
1180
1181 return name;
1182 }
1183
1184 return NULL;
1185 }
1186
1187 static void
1188 stats_L_list(struct Client *source_p,char *name, int doall, int wilds,
1189 dlink_list *list,char statchar)
1190 {
1191 dlink_node *ptr;
1192 struct Client *target_p;
1193
1194 /*
1195 * send info about connections which match, or all if the
1196 * mask matches from. Only restrictions are on those who
1197 * are invisible not being visible to 'foreigners' who use
1198 * a wild card based search to list it.
1199 */
1200 DLINK_FOREACH(ptr, list->head)
1201 {
1202 target_p = ptr->data;
1203
1204 if (HasUMode(target_p, UMODE_INVISIBLE) && (doall || wilds) &&
1205 !(MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) &&
1206 !HasUMode(target_p, UMODE_OPER) && (target_p != source_p))
1207 continue;
1208 if (!doall && wilds && !match(name, target_p->name))
1209 continue;
1210 if (!(doall || wilds) && irccmp(name, target_p->name))
1211 continue;
1212
1213 /* This basically shows ips for our opers if its not a server/admin, or
1214 * its one of our admins. */
1215 if(MyClient(source_p) && HasUMode(source_p, UMODE_OPER) &&
1216 (HasUMode(source_p, UMODE_ADMIN) ||
1217 (!IsServer(target_p) && !HasUMode(target_p, UMODE_ADMIN) &&
1218 !IsHandshake(target_p) && !IsConnecting(target_p))))
1219 {
1220 sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1221 from, to,
1222 (IsUpper(statchar)) ?
1223 get_client_name(target_p, SHOW_IP) :
1224 get_client_name(target_p, HIDE_IP),
1225 dbuf_length(&target_p->localClient->buf_sendq),
1226 target_p->localClient->send.messages,
1227 target_p->localClient->send.bytes>>10,
1228 target_p->localClient->recv.messages,
1229 target_p->localClient->recv.bytes>>10,
1230 (unsigned)(CurrentTime - target_p->localClient->firsttime),
1231 (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0,
1232 IsServer(target_p) ? show_capabilities(target_p) : "-");
1233 }
1234 else
1235 {
1236 /* If its a hidden ip, an admin, or a server, mask the real IP */
1237 if(IsIPSpoof(target_p) || IsServer(target_p) || HasUMode(target_p, UMODE_ADMIN)
1238 || IsHandshake(target_p) || IsConnecting(target_p))
1239 sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1240 from, to,
1241 get_client_name(target_p, MASK_IP),
1242 dbuf_length(&target_p->localClient->buf_sendq),
1243 target_p->localClient->send.messages,
1244 target_p->localClient->send.bytes>>10,
1245 target_p->localClient->recv.messages,
1246 target_p->localClient->recv.bytes>>10,
1247 (unsigned)(CurrentTime - target_p->localClient->firsttime),
1248 (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0,
1249 IsServer(target_p) ? show_capabilities(target_p) : "-");
1250 else /* show the real IP */
1251 sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1252 from, to,
1253 (IsUpper(statchar)) ?
1254 get_client_name(target_p, SHOW_IP) :
1255 get_client_name(target_p, HIDE_IP),
1256 dbuf_length(&target_p->localClient->buf_sendq),
1257 target_p->localClient->send.messages,
1258 target_p->localClient->send.bytes>>10,
1259 target_p->localClient->recv.messages,
1260 target_p->localClient->recv.bytes>>10,
1261 (unsigned)(CurrentTime - target_p->localClient->firsttime),
1262 (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0,
1263 IsServer(target_p) ? show_capabilities(target_p) : "-");
1264 }
1265 }
1266 }
1267
1268 /*
1269 * stats_L
1270 *
1271 * inputs - pointer to client to report to
1272 * - doall flag
1273 * - wild card or not
1274 * output - NONE
1275 * side effects -
1276 */
1277 static void
1278 stats_L(struct Client *source_p,char *name,int doall,
1279 int wilds,char statchar)
1280 {
1281 stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar);
1282 stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar);
1283 stats_L_list(source_p, name, doall, wilds, &serv_list, statchar);
1284 }
1285
1286 static void
1287 stats_ltrace(struct Client *source_p, int parc, char *parv[])
1288 {
1289 int doall = 0;
1290 int wilds = 0;
1291 char *name = NULL;
1292 char statchar;
1293
1294 if ((name = parse_stats_args(parc, parv, &doall, &wilds)) != NULL)
1295 {
1296 statchar = parv[1][0];
1297
1298 stats_L(source_p, name, doall, wilds, statchar);
1299 }
1300 else
1301 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1302 from, to, "STATS");
1303 }
1304
1305 static const struct StatsStruct
1306 {
1307 const unsigned char letter;
1308 void (*handler)();
1309 const unsigned int need_oper;
1310 const unsigned int need_admin;
1311 } stats_cmd_table[] = {
1312 /* letter function need_oper need_admin */
1313 { 'a', stats_dns_servers, 1, 1 },
1314 { 'A', stats_dns_servers, 1, 1 },
1315 { 'c', stats_connect, 1, 0 },
1316 { 'C', stats_connect, 1, 0 },
1317 { 'd', stats_tdeny, 1, 0 },
1318 { 'D', stats_deny, 1, 0 },
1319 { 'e', stats_exempt, 1, 0 },
1320 { 'E', stats_events, 1, 1 },
1321 { 'f', fd_dump, 1, 1 },
1322 { 'F', fd_dump, 1, 1 },
1323 { 'g', stats_pending_glines, 1, 0 },
1324 { 'G', stats_glines, 1, 0 },
1325 { 'h', stats_hooks, 1, 1 },
1326 { 'H', stats_hubleaf, 1, 0 },
1327 { 'i', stats_auth, 0, 0 },
1328 { 'I', stats_auth, 0, 0 },
1329 { 'k', stats_tklines, 0, 0 },
1330 { 'K', stats_klines, 0, 0 },
1331 { 'l', stats_ltrace, 1, 0 },
1332 { 'L', stats_ltrace, 1, 0 },
1333 { 'm', stats_messages, 0, 0 },
1334 { 'M', stats_messages, 0, 0 },
1335 { 'o', stats_oper, 0, 0 },
1336 { 'O', stats_oper, 0, 0 },
1337 { 'p', stats_operedup, 0, 0 },
1338 { 'P', stats_ports, 0, 0 },
1339 { 'q', stats_resv, 1, 0 },
1340 { 'Q', stats_resv, 1, 0 },
1341 { 'r', stats_usage, 1, 0 },
1342 { 'R', stats_usage, 1, 0 },
1343 { 'S', stats_service, 1, 0 },
1344 { 't', stats_tstats, 1, 0 },
1345 { 'T', stats_tstats, 1, 0 },
1346 { 'u', stats_uptime, 0, 0 },
1347 { 'U', stats_shared, 1, 0 },
1348 { 'v', stats_servers, 1, 0 },
1349 { 'x', stats_gecos, 1, 0 },
1350 { 'X', stats_gecos, 1, 0 },
1351 { 'y', stats_class, 1, 0 },
1352 { 'Y', stats_class, 1, 0 },
1353 { 'z', stats_memory, 1, 0 },
1354 { '?', stats_servlinks, 0, 0 },
1355 { '\0', NULL, 0, 0 }
1356 };
1357
1358 static void
1359 do_stats(struct Client *source_p, int parc, char *parv[])
1360 {
1361 const struct StatsStruct *tab = stats_cmd_table;
1362 const char statchar = *parv[1];
1363
1364 if (statchar == '\0')
1365 {
1366 sendto_one(source_p, form_str(RPL_ENDOFSTATS),
1367 from, to, '*');
1368 return;
1369 }
1370
1371 for (; tab->handler; ++tab)
1372 {
1373 if (tab->letter == statchar)
1374 {
1375 /* The stats table says what privs are needed, so check --fl_ */
1376 if ((tab->need_admin && !HasUMode(source_p, UMODE_ADMIN)) ||
1377 (tab->need_oper && !HasUMode(source_p, UMODE_OPER)))
1378 {
1379 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1380 from, to);
1381 break;
1382 }
1383
1384 sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE,
1385 "STATS %c requested by %s (%s@%s) [%s]",
1386 statchar, source_p->name, source_p->username,
1387 source_p->host, source_p->servptr->name);
1388 tab->handler(source_p, parc, parv);
1389 break;
1390 }
1391 }
1392
1393 sendto_one(source_p, form_str(RPL_ENDOFSTATS),
1394 from, to, statchar);
1395 }
1396
1397 /*
1398 * m_stats()
1399 * parv[0] = sender prefix
1400 * parv[1] = stat letter/command
1401 * parv[2] = (if present) server/mask in stats L
1402 *
1403 * This will search the tables for the appropriate stats letter/command,
1404 * if found execute it.
1405 */
1406 static void
1407 m_stats(struct Client *client_p, struct Client *source_p,
1408 int parc, char *parv[])
1409 {
1410 static time_t last_used = 0;
1411
1412 /* Is the stats meant for us? */
1413 if (!ConfigFileEntry.disable_remote)
1414 if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
1415 parc, parv) != HUNTED_ISME)
1416 return;
1417
1418 if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
1419 {
1420 from = me.id;
1421 to = source_p->id;
1422 }
1423 else
1424 {
1425 from = me.name;
1426 to = source_p->name;
1427 }
1428
1429 /* Check the user is actually allowed to do /stats, and isnt flooding */
1430 if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
1431 {
1432 sendto_one(source_p,form_str(RPL_LOAD2HI),
1433 from, to);
1434 return;
1435 }
1436
1437 last_used = CurrentTime;
1438
1439 do_stats(source_p, parc, parv);
1440 }
1441
1442 /*
1443 * mo_stats()
1444 * parv[0] = sender prefix
1445 * parv[1] = stat letter/command
1446 * parv[2] = (if present) server/mask in stats L, or target
1447 *
1448 * This will search the tables for the appropriate stats letter,
1449 * if found execute it.
1450 */
1451 static void
1452 mo_stats(struct Client *client_p, struct Client *source_p,
1453 int parc, char *parv[])
1454 {
1455 if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
1456 parc, parv) != HUNTED_ISME)
1457 return;
1458
1459 if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
1460 {
1461 from = me.id;
1462 to = source_p->id;
1463 }
1464 else
1465 {
1466 from = me.name;
1467 to = source_p->name;
1468 }
1469
1470 do_stats(source_p, parc, parv);
1471 }
1472
1473 /*
1474 * ms_stats - STATS message handler
1475 * parv[0] = sender prefix
1476 * parv[1] = statistics selector (defaults to Message frequency)
1477 * parv[2] = server name (current server defaulted, if omitted)
1478 */
1479 static void
1480 ms_stats(struct Client *client_p, struct Client *source_p,
1481 int parc, char *parv[])
1482 {
1483 if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
1484 parc, parv) != HUNTED_ISME)
1485 return;
1486
1487 if (IsClient(source_p))
1488 mo_stats(client_p, source_p, parc, parv);
1489 }
1490
1491 static struct Message stats_msgtab = {
1492 "STATS", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
1493 { m_unregistered, m_stats, ms_stats, m_ignore, mo_stats, m_ignore }
1494 };
1495
1496 static void
1497 module_init(void)
1498 {
1499 mod_add_cmd(&stats_msgtab);
1500 }
1501
1502 static void
1503 module_exit(void)
1504 {
1505 mod_del_cmd(&stats_msgtab);
1506 }
1507
1508 struct module module_entry = {
1509 .node = { NULL, NULL, NULL },
1510 .name = NULL,
1511 .version = "$Revision$",
1512 .handle = NULL,
1513 .modinit = module_init,
1514 .modexit = module_exit,
1515 .flags = 0
1516 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision