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

# User Rev Content
1 adx 30 /*
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 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26 michael 1011 #include "list.h" /* dlink_node/dlink_list */
27     #include "balloc.h"
28 adx 30 #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 michael 1632 #include "conf.h"
34 michael 1644 #include "conf_class.h"
35 adx 30 #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 michael 1144 #include "hook.h"
46 adx 30 #include "parse.h"
47     #include "modules.h"
48     #include "resv.h" /* report_resv */
49     #include "whowas.h"
50 michael 884 #include "watch.h"
51 michael 1312 #include "irc_res.h"
52 adx 30
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 michael 1457 stats_usage(struct Client *source_p, int parc, char *parv[])
65 adx 30 {
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 michael 1241 rup = (CurrentTime - me.localClient->since) * hzz;
92 adx 30
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 michael 1457 stats_memory(struct Client *source_p, int parc, char *parv[])
121 adx 30 {
122     const dlink_node *gptr = NULL;
123     const dlink_node *dlink = NULL;
124    
125 michael 948 unsigned int local_client_conf_count = 0; /* local client conf links */
126     unsigned int users_counted = 0; /* user structs */
127 adx 30
128 michael 1017 unsigned int channel_members = 0;
129 michael 948 unsigned int channel_invites = 0;
130     unsigned int channel_bans = 0;
131     unsigned int channel_except = 0;
132     unsigned int channel_invex = 0;
133 adx 30
134 michael 948 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 adx 30
139 michael 948 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 adx 30
144     unsigned int safelist_count = 0;
145 michael 948 uint64_t safelist_memory = 0;
146 adx 30
147 michael 948 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 adx 30
151 michael 948 uint64_t total_channel_memory = 0;
152     uint64_t totww = 0;
153 adx 30
154     unsigned int local_client_count = 0;
155     unsigned int remote_client_count = 0;
156    
157 michael 948 uint64_t local_client_memory_used = 0;
158     uint64_t remote_client_memory_used = 0;
159 adx 30
160 michael 948 uint64_t total_memory = 0;
161 adx 30 unsigned int topic_count = 0;
162    
163 michael 1017 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 michael 884
167 adx 30
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 michael 1017 watch_list_entries += dlink_list_length(&target_p->localClient->watches);
177 adx 30 }
178     else
179     ++remote_client_count;
180    
181     if (IsClient(target_p))
182     {
183     ++users_counted;
184    
185 michael 1483 if (target_p->away[0])
186 adx 30 ++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 michael 948 const struct Ban *actualBan;
196     const struct Channel *chptr = gptr->data;
197 adx 30
198 michael 1017 channel_members += dlink_list_length(&chptr->members);
199 adx 30 channel_invites += dlink_list_length(&chptr->invites);
200    
201 michael 1203 if (chptr->topic[0])
202 adx 30 ++topic_count;
203    
204 michael 1017 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 adx 30 {
209 michael 1017 actualBan = dlink->data;
210     assert(actualBan->who);
211 adx 30
212 michael 1017 channel_ban_memory += actualBan->len + 1;
213     channel_ban_memory += strlen(actualBan->who) + 1;
214 adx 30 }
215    
216 michael 1017 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 adx 30 {
221 michael 1017 actualBan = dlink->data;
222     assert(actualBan->who);
223 adx 30
224 michael 1017 channel_except_memory += actualBan->len + 1;
225     channel_except_memory += strlen(actualBan->who) + 1;
226 adx 30 }
227    
228 michael 1017 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 adx 30 {
233 michael 1017 actualBan = dlink->data;
234     assert(actualBan->who);
235 adx 30
236 michael 1017 channel_invex_memory += actualBan->len + 1;
237     channel_invex_memory += strlen(actualBan->who) + 1;
238 adx 30 }
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 michael 948 const struct Client *acptr = gptr->data;
247 adx 30
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 michael 1644 class_count = dlink_list_length(class_get_list());
270 adx 30
271 michael 1017 count_whowas_memory(&wwu, &wwm);
272     watch_count_memory(&watch_list_headers, &watch_list_memory);
273 michael 884
274 michael 1127 sendto_one(source_p, ":%s %d %s z :WATCH headers %u(%u) entries %d(%u)",
275 michael 1017 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 michael 884
279     sendto_one(source_p, ":%s %d %s z :Clients %u(%u)",
280 adx 30 me.name, RPL_STATSDEBUG, source_p->name, users_counted,
281 michael 884 (users_counted * sizeof(struct Client)));
282 adx 30
283 michael 1483 sendto_one(source_p, ":%s %d %s z :User aways %u",
284 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
285 michael 1483 aways_counted);
286 adx 30
287 michael 948 sendto_one(source_p, ":%s %d %s z :Attached confs %u(%llu)",
288 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
289     local_client_conf_count,
290 michael 948 (unsigned long long)(local_client_conf_count * sizeof(dlink_node)));
291 adx 30
292 michael 1127 sendto_one(source_p, ":%s %d %s z :Resv channels %u(%lu) nicks %u(%lu)",
293 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
294     dlink_list_length(&resv_channel_list),
295 michael 1632 dlink_list_length(&resv_channel_list) * sizeof(struct MaskItem),
296 adx 30 dlink_list_length(&nresv_items),
297 michael 1632 dlink_list_length(&nresv_items) * sizeof(struct MaskItem));
298 adx 30
299 michael 948 sendto_one(source_p, ":%s %d %s z :Classes %u(%llu)",
300 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
301 michael 948 class_count, (unsigned long long)(class_count * sizeof(struct ClassItem)));
302 adx 30
303 michael 1127 sendto_one(source_p, ":%s %d %s z :Channels %uu(%llu) Topics %u(%u)",
304 adx 30 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 michael 948 sendto_one(source_p, ":%s %d %s z :Bans %u(%llu)",
310 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
311     channel_bans, channel_ban_memory);
312    
313 michael 948 sendto_one(source_p, ":%s %d %s z :Exceptions %u(%llu)",
314 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
315     channel_except, channel_except_memory);
316    
317 michael 948 sendto_one(source_p, ":%s %d %s z :Invex %u(%llu)",
318 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
319     channel_invex, channel_invex_memory);
320    
321 michael 948 sendto_one(source_p, ":%s %d %s z :Channel members %u(%llu) invites %u(%llu)",
322 michael 1017 me.name, RPL_STATSDEBUG, source_p->name, channel_members,
323     (unsigned long long)(channel_members * sizeof(struct Membership)),
324 michael 948 channel_invites, (unsigned long long)channel_invites *
325 michael 884 sizeof(dlink_node) * 2);
326 adx 30
327     total_channel_memory = channel_memory + channel_ban_memory +
328 michael 1017 channel_members * sizeof(struct Membership) +
329 michael 884 (channel_invites * sizeof(dlink_node)*2);
330 adx 30
331 michael 948 sendto_one(source_p, ":%s %d %s z :Safelist %u(%llu)",
332 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
333     safelist_count, safelist_memory);
334    
335 michael 948 sendto_one(source_p, ":%s %d %s z :Whowas users %u(%llu)",
336 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
337 michael 948 wwu, (unsigned long long)(wwu * sizeof(struct Client)));
338 adx 30
339 michael 948 sendto_one(source_p, ":%s %d %s z :Whowas array %u(%llu)",
340 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
341 michael 948 NICKNAMEHISTORYLENGTH, wwm);
342 adx 30
343     totww = wwu * sizeof(struct Client) + wwm;
344    
345     count_ip_hash(&number_ips_stored,&mem_ips_stored);
346 michael 948 sendto_one(source_p, ":%s %d %s z :iphash %u(%llu)",
347 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
348 michael 948 number_ips_stored, mem_ips_stored);
349 adx 30
350     total_memory = totww + total_channel_memory + conf_memory + class_count *
351     sizeof(struct ClassItem);
352 michael 948 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 adx 30
356     local_client_memory_used = local_client_count*(sizeof(struct Client) + sizeof(struct LocalUser));
357     total_memory += local_client_memory_used;
358 michael 1127 sendto_one(source_p, ":%s %d %s z :Local client Memory in use: %u(%llu)",
359 adx 30 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 michael 1127 sendto_one(source_p, ":%s %d %s z :Remote client Memory in use: %u(%llu)",
365 adx 30 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 michael 948 ":%s %d %s z :TOTAL: %llu",
372 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
373 michael 948 total_memory);
374 adx 30 }
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 michael 1457 stats_connect(struct Client *source_p, int parc, char *parv[])
384 adx 30 {
385 michael 1632 report_confitem_types(source_p, CONF_SERVER);
386 adx 30 }
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 michael 1457 stats_deny(struct Client *source_p, int parc, char *parv[])
396 adx 30 {
397 michael 1632 struct MaskItem *conf;
398 michael 1367 dlink_node *ptr = NULL;
399     unsigned int i = 0;
400 adx 30
401 michael 1367
402     for (i = 0; i < ATABLE_SIZE; ++i)
403 adx 30 {
404 michael 1367 DLINK_FOREACH(ptr, atable[i].head)
405 adx 30 {
406 michael 1367 struct AddressRec *arec = ptr->data;
407    
408 michael 1632 if (arec->type != CONF_DLINE)
409     continue;
410 adx 30
411 michael 1632 conf = arec->conf;
412 adx 30
413 michael 1632 /* dont report a tdline as a dline */
414     if (conf->hold)
415     continue;
416 adx 30
417 michael 1632 sendto_one(source_p, form_str(RPL_STATSDLINE),
418     from, to, 'D', conf->host, conf->reason);
419 adx 30 }
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 michael 1457 stats_tdeny(struct Client *source_p, int parc, char *parv[])
431 adx 30 {
432 michael 1632 struct MaskItem *conf = NULL;
433 michael 1367 dlink_node *ptr = NULL;
434     unsigned int i = 0;
435 adx 30
436 michael 1367
437     for (i = 0; i < ATABLE_SIZE; ++i)
438 adx 30 {
439 michael 1367 DLINK_FOREACH(ptr, atable[i].head)
440 adx 30 {
441 michael 1367 struct AddressRec *arec = ptr->data;
442    
443 michael 1632 if (arec->type != CONF_DLINE)
444     continue;
445 adx 30
446 michael 1632 conf = arec->conf;
447 adx 30
448 michael 1632 /* dont report a permanent dline as a tdline */
449     if (!conf->hold)
450     continue;
451 adx 30
452 michael 1632 sendto_one(source_p, form_str(RPL_STATSDLINE),
453     from, to, 'd', conf->host, conf->reason);
454 adx 30 }
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 michael 1457 stats_exempt(struct Client *source_p, int parc, char *parv[])
466 adx 30 {
467 michael 1632 struct MaskItem *conf;
468 michael 1367 dlink_node *ptr = NULL;
469     unsigned int i = 0;
470 adx 30
471 michael 584 if (ConfigFileEntry.stats_e_disabled)
472     {
473     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
474     from, to);
475     return;
476     }
477    
478 michael 1367
479     for (i = 0; i < ATABLE_SIZE; ++i)
480 adx 30 {
481 michael 1367 DLINK_FOREACH(ptr, atable[i].head)
482 adx 30 {
483 michael 1367 struct AddressRec *arec = ptr->data;
484    
485 michael 1632 if (arec->type != CONF_EXEMPT)
486     continue;
487 adx 30
488 michael 1632 conf = arec->conf;
489 adx 30
490 michael 1632 sendto_one(source_p, form_str(RPL_STATSDLINE),
491     from, to, 'e', conf->host, conf->reason /* XXX */);
492 adx 30 }
493     }
494     }
495    
496     static void
497 michael 1457 stats_events(struct Client *source_p, int parc, char *parv[])
498 adx 30 {
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 michael 1457 stats_pending_glines(struct Client *source_p, int parc, char *parv[])
510 adx 30 {
511 michael 958 const dlink_node *dn_ptr = NULL;
512 michael 988 const struct gline_pending *glp_ptr = NULL;
513 michael 958 char timebuffer[MAX_DATE_STRING] = { '\0' };
514     struct tm *tmptr = NULL;
515 adx 30
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 michael 958 if (dlink_list_length(&pending_glines[GLINE_PENDING_ADD_TYPE]) > 0)
524 adx 30 sendto_one(source_p, ":%s NOTICE %s :Pending G-lines",
525     from, to);
526    
527 michael 958 DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_ADD_TYPE].head)
528 adx 30 {
529 michael 958 glp_ptr = dn_ptr->data;
530     tmptr = localtime(&glp_ptr->vote_1.time_request);
531 adx 30 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 michael 958 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 adx 30
540 michael 988 if (glp_ptr->vote_2.oper_nick[0] != '\0')
541 adx 30 {
542 michael 958 tmptr = localtime(&glp_ptr->vote_2.time_request);
543 adx 30 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 michael 958 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 adx 30 }
551     }
552    
553     sendto_one(source_p, ":%s NOTICE %s :End of Pending G-lines",
554     from, to);
555 michael 958
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 michael 988 if (glp_ptr->vote_2.oper_nick[0] != '\0')
574 michael 958 {
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 adx 30 }
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 michael 1457 stats_glines(struct Client *source_p, int parc, char *parv[])
599 adx 30 {
600 michael 1367 dlink_node *ptr = NULL;
601     unsigned int i = 0;
602 adx 30
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 michael 1367 for (i = 0; i < ATABLE_SIZE; ++i)
611 adx 30 {
612 michael 1367 DLINK_FOREACH(ptr, atable[i].head)
613 adx 30 {
614 michael 1376 const struct AddressRec *arec = ptr->data;
615 michael 1367
616 adx 30 if (arec->type == CONF_GLINE)
617     {
618 michael 1632 const struct MaskItem *conf = arec->conf;
619 adx 30
620     sendto_one(source_p, form_str(RPL_STATSKLINE),
621     from, to, "G",
622 michael 1632 conf->host ? conf->host : "*",
623     conf->user ? conf->user : "*",
624     conf->reason ? conf->reason : "No reason");
625 adx 30 }
626     }
627     }
628     }
629    
630     static void
631 michael 1457 stats_hubleaf(struct Client *source_p, int parc, char *parv[])
632 adx 30 {
633 michael 1632 report_confitem_types(source_p, CONF_HUB);
634 adx 30 }
635    
636 michael 1372 /*
637     * show_iline_prefix()
638     *
639     * inputs - pointer to struct Client requesting output
640 michael 1632 * - pointer to struct MaskItem
641 michael 1372 * - 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 michael 1632 show_iline_prefix(const struct Client *sptr, const struct MaskItem *conf)
647 michael 1372 {
648     static char prefix_of_host[USERLEN + 14];
649     char *prefix_ptr = prefix_of_host;
650    
651 michael 1632 if (IsNoTilde(conf))
652 michael 1372 *prefix_ptr++ = '-';
653 michael 1632 if (IsLimitIp(conf))
654 michael 1372 *prefix_ptr++ = '!';
655 michael 1632 if (IsNeedIdentd(conf))
656 michael 1372 *prefix_ptr++ = '+';
657 michael 1632 if (!IsNeedPassword(conf))
658 michael 1372 *prefix_ptr++ = '&';
659 michael 1632 if (IsConfExemptResv(conf))
660 michael 1372 *prefix_ptr++ = '$';
661 michael 1632 if (IsNoMatchIp(conf))
662 michael 1372 *prefix_ptr++ = '%';
663 michael 1632 if (IsConfDoSpoofIp(conf))
664 michael 1372 *prefix_ptr++ = '=';
665 michael 1632 if (MyOper(sptr) && IsConfExemptKline(conf))
666 michael 1372 *prefix_ptr++ = '^';
667 michael 1632 if (MyOper(sptr) && IsConfExemptGline(conf))
668 michael 1372 *prefix_ptr++ = '_';
669 michael 1632 if (MyOper(sptr) && IsConfExemptLimits(conf))
670 michael 1372 *prefix_ptr++ = '>';
671 michael 1632 if (IsConfCanFlood(conf))
672 michael 1372 *prefix_ptr++ = '|';
673    
674 michael 1632 strlcpy(prefix_ptr, conf->user, USERLEN+1);
675 michael 1372
676     return prefix_of_host;
677     }
678    
679 adx 30 static void
680 michael 1457 report_auth(struct Client *client_p, int parc, char *parv[])
681 michael 1372 {
682 michael 1632 struct MaskItem *conf = NULL;
683 michael 1372 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 michael 1632 if (arec->type != CONF_CLIENT)
694     continue;
695 michael 1372
696 michael 1632 conf = arec->conf;
697 michael 1372
698 michael 1632 if (!MyOper(client_p) && IsConfDoSpoofIp(conf))
699     continue;
700 michael 1372
701 michael 1632 /* 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 michael 1372
713 michael 1632 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 michael 1372 }
721     }
722     }
723    
724     static void
725 michael 1457 stats_auth(struct Client *source_p, int parc, char *parv[])
726 adx 30 {
727     /* Oper only, if unopered, return ERR_NOPRIVILEGES */
728 michael 1219 if ((ConfigFileEntry.stats_i_oper_only == 2) && !HasUMode(source_p, UMODE_OPER))
729 adx 30 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
730     from, to);
731    
732     /* If unopered, Only return matching auth blocks */
733 michael 1219 else if ((ConfigFileEntry.stats_i_oper_only == 1) && !HasUMode(source_p, UMODE_OPER))
734 adx 30 {
735 michael 1632 struct MaskItem *conf;
736 adx 30
737     if (MyConnect(source_p))
738 michael 1632 conf = find_conf_by_address(source_p->host,
739 adx 30 &source_p->localClient->ip,
740     CONF_CLIENT,
741     source_p->localClient->aftype,
742     source_p->username,
743 michael 1371 source_p->localClient->passwd, 1);
744 adx 30 else
745 michael 1632 conf = find_conf_by_address(source_p->host, NULL, CONF_CLIENT,
746 michael 1371 0, source_p->username, NULL, 1);
747 adx 30
748 michael 1632 if (conf == NULL)
749 adx 30 return;
750    
751     sendto_one(source_p, form_str(RPL_STATSILINE), from,
752     to, 'I',
753 michael 1632 "*", show_iline_prefix(source_p, conf),
754     conf->host, conf->port,
755     conf->class ? conf->class->name : "<default>");
756 adx 30 }
757     /* They are opered, or allowed to see all auth blocks */
758     else
759 michael 1457 report_auth(source_p, 0, NULL);
760 adx 30 }
761    
762 michael 1372 /* 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 adx 30 static void
770 michael 1372 report_Klines(struct Client *client_p, int tkline)
771     {
772 michael 1632 struct MaskItem *conf = NULL;
773 michael 1372 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 michael 1632 if (arec->type != CONF_KLINE)
789     continue;
790 michael 1628
791 michael 1632 conf = arec->conf;
792 michael 1372
793 michael 1632 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 michael 1372 }
805     }
806     }
807    
808     static void
809 michael 1457 stats_tklines(struct Client *source_p, int parc, char *parv[])
810 adx 30 {
811     /* Oper only, if unopered, return ERR_NOPRIVILEGES */
812 michael 1219 if ((ConfigFileEntry.stats_k_oper_only == 2) && !HasUMode(source_p, UMODE_OPER))
813 adx 30 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
814     from, to);
815    
816     /* If unopered, Only return matching klines */
817 michael 1219 else if ((ConfigFileEntry.stats_k_oper_only == 1) && !HasUMode(source_p, UMODE_OPER))
818 adx 30 {
819 michael 1632 struct MaskItem *conf = NULL;
820 adx 30
821     if (MyConnect(source_p))
822 michael 1632 conf = find_conf_by_address(source_p->host,
823     &source_p->localClient->ip,
824 michael 1369 CONF_KLINE,
825 adx 30 source_p->localClient->aftype,
826 michael 1371 source_p->username, NULL, 1);
827 adx 30 else
828 michael 1632 conf = find_conf_by_address(source_p->host, NULL, CONF_KLINE,
829 michael 1371 0, source_p->username, NULL, 1);
830 adx 30
831 michael 1632 if (!conf)
832 adx 30 return;
833    
834     /* dont report a permanent kline as a tkline */
835 michael 1632 if (!conf->hold)
836 adx 30 return;
837    
838     sendto_one(source_p, form_str(RPL_STATSKLINE), from,
839 michael 1632 to, "k", conf->host, conf->user, conf->reason);
840 adx 30 }
841     /* Theyre opered, or allowed to see all klines */
842     else {
843     report_Klines(source_p, 1);
844     }
845     }
846    
847     static void
848 michael 1457 stats_klines(struct Client *source_p, int parc, char *parv[])
849 adx 30 {
850     /* Oper only, if unopered, return ERR_NOPRIVILEGES */
851 michael 1219 if ((ConfigFileEntry.stats_k_oper_only == 2) && !HasUMode(source_p, UMODE_OPER))
852 adx 30 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
853     from, to);
854    
855     /* If unopered, Only return matching klines */
856 michael 1219 else if ((ConfigFileEntry.stats_k_oper_only == 1) && !HasUMode(source_p, UMODE_OPER))
857 adx 30 {
858 michael 1632 struct MaskItem *conf = NULL;
859 adx 30
860     /* search for a kline */
861 michael 560 if (MyConnect(source_p))
862 michael 1632 conf = find_conf_by_address(source_p->host,
863 adx 30 &source_p->localClient->ip,
864 michael 1369 CONF_KLINE,
865 adx 30 source_p->localClient->aftype,
866 michael 1371 source_p->username, NULL, 0);
867 adx 30 else
868 michael 1632 conf = find_conf_by_address(source_p->host, NULL, CONF_KLINE,
869 michael 1371 0, source_p->username, NULL, 0);
870 adx 30
871 michael 1632 if (!conf)
872 adx 30 return;
873    
874     /* dont report a tkline as a kline */
875 michael 1632 if (conf->hold)
876 adx 30 return;
877    
878     sendto_one(source_p, form_str(RPL_STATSKLINE), from,
879 michael 1632 to, "K", conf->host, conf->user, conf->reason);
880 adx 30 }
881     /* Theyre opered, or allowed to see all klines */
882     else {
883     report_Klines(source_p, 0);
884 michael 1632 report_confitem_types(source_p, CONF_RKLINE);
885 adx 30 }
886     }
887    
888     static void
889 michael 1457 stats_messages(struct Client *source_p, int parc, char *parv[])
890 adx 30 {
891     report_messages(source_p);
892     }
893    
894     static void
895 michael 1457 stats_oper(struct Client *source_p, int parc, char *parv[])
896 adx 30 {
897 michael 1219 if (!HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.stats_o_oper_only)
898 adx 30 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
899     from, to);
900     else
901 michael 1632 report_confitem_types(source_p, CONF_OPER);
902 adx 30 }
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 michael 1457 stats_operedup(struct Client *source_p, int parc, char *parv[])
912 adx 30 {
913     dlink_node *ptr;
914    
915     DLINK_FOREACH(ptr, oper_list.head)
916     {
917     const struct Client *target_p = ptr->data;
918    
919 michael 1294 if (HasUMode(target_p, UMODE_HIDDEN) && !HasUMode(source_p, UMODE_OPER))
920 adx 30 continue;
921    
922 michael 1219 if (MyClient(source_p) && HasUMode(source_p, UMODE_OPER))
923 adx 30 sendto_one(source_p, ":%s %d %s p :[%c][%s] %s (%s@%s) Idle: %d",
924     from, RPL_STATSDEBUG, to,
925 michael 1294 HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O',
926 adx 30 oper_privs_as_string(target_p->localClient->operflags),
927     target_p->name, target_p->username, target_p->host,
928 michael 1176 (int)(CurrentTime - target_p->localClient->last_privmsg));
929 adx 30 else
930     sendto_one(source_p, ":%s %d %s p :[%c] %s (%s@%s) Idle: %d",
931     from, RPL_STATSDEBUG, to,
932 michael 1294 HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O',
933 adx 30 target_p->name, target_p->username, target_p->host,
934 michael 1176 (int)(CurrentTime - target_p->localClient->last_privmsg));
935 adx 30 }
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 michael 1457 stats_ports(struct Client *source_p, int parc, char *parv[])
943 adx 30 {
944 michael 1219 if (!HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.stats_P_oper_only)
945 adx 30 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
946     from, to);
947     else
948     show_ports(source_p);
949     }
950    
951     static void
952 michael 1457 stats_resv(struct Client *source_p, int parc, char *parv[])
953 adx 30 {
954     report_resv(source_p);
955     }
956    
957     static void
958 michael 1457 stats_service(struct Client *source_p, int parc, char *parv[])
959 adx 30 {
960 michael 1632 report_confitem_types(source_p, CONF_SERVICE);
961 michael 1175 }
962    
963     static void
964 michael 1457 stats_tstats(struct Client *source_p, int parc, char *parv[])
965 adx 30 {
966 michael 896 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 michael 1241 sp->is_sti += CurrentTime - target_p->localClient->firsttime;
988 michael 896 }
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 michael 1241 sp->is_cti += CurrentTime - target_p->localClient->firsttime;
999 michael 896 }
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 adx 30 }
1033    
1034     static void
1035 michael 1457 stats_uptime(struct Client *source_p, int parc, char *parv[])
1036 adx 30 {
1037 michael 1241 time_t now = CurrentTime - me.localClient->since;
1038 michael 1148
1039 adx 30 sendto_one(source_p, form_str(RPL_STATSUPTIME), from, to,
1040 michael 1148 now / 86400, (now / 3600) % 24, (now / 60) % 60, now % 60);
1041    
1042 michael 1219 if (!ConfigFileEntry.disable_remote || HasUMode(source_p, UMODE_OPER))
1043 adx 30 sendto_one(source_p, form_str(RPL_STATSCONN), from, to,
1044 michael 1148 Count.max_loc_con, Count.max_loc_cli, Count.totalrestartcount);
1045 adx 30 }
1046    
1047     static void
1048 michael 1457 stats_shared(struct Client *source_p, int parc, char *parv[])
1049 adx 30 {
1050 michael 1632 report_confitem_types(source_p, CONF_ULINE);
1051 adx 30 }
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 michael 1457 stats_servers(struct Client *source_p, int parc, char *parv[])
1061 adx 30 {
1062 michael 1127 dlink_node *ptr = NULL;
1063 adx 30
1064     DLINK_FOREACH(ptr, serv_list.head)
1065     {
1066 michael 1127 const struct Client *target_p = ptr->data;
1067 adx 30
1068     sendto_one(source_p, ":%s %d %s v :%s (%s!%s@%s) Idle: %d",
1069 michael 1127 from, RPL_STATSDEBUG, to, target_p->name,
1070     (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
1071 michael 1241 "*", "*", (int)(CurrentTime - target_p->localClient->lasttime));
1072 adx 30 }
1073    
1074 michael 1127 sendto_one(source_p, ":%s %d %s v :%u Server(s)",
1075     from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list));
1076 adx 30 }
1077    
1078     static void
1079 michael 1457 stats_gecos(struct Client *source_p, int parc, char *parv[])
1080 adx 30 {
1081 michael 1632 report_confitem_types(source_p, CONF_XLINE);
1082     report_confitem_types(source_p, CONF_RXLINE);
1083 adx 30 }
1084    
1085     static void
1086 michael 1457 stats_class(struct Client *source_p, int parc, char *parv[])
1087 adx 30 {
1088 michael 1632 report_confitem_types(source_p, CONF_CLASS);
1089 adx 30 }
1090    
1091     static void
1092 michael 1457 stats_servlinks(struct Client *source_p, int parc, char *parv[])
1093 adx 30 {
1094     uint64_t sendB = 0, recvB = 0;
1095     time_t uptime = 0;
1096 michael 560 dlink_node *ptr = NULL;
1097 adx 30
1098 michael 1219 if (ConfigServerHide.flatten_links && !HasUMode(source_p, UMODE_OPER))
1099 adx 30 {
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 michael 560 struct Client *target_p = ptr->data;
1108 adx 30
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 michael 1219 get_client_name(target_p, HasUMode(source_p, UMODE_ADMIN) ? SHOW_IP : MASK_IP),
1116 adx 30 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 michael 1241 (unsigned)(CurrentTime - target_p->localClient->firsttime),
1122     (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since): 0,
1123 michael 1219 HasUMode(source_p, UMODE_OPER) ? show_capabilities(target_p) : "TS");
1124 adx 30 }
1125    
1126     sendB >>= 10;
1127     recvB >>= 10;
1128    
1129     sendto_one(source_p, ":%s %d %s ? :%u total server(s)",
1130 michael 560 from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list));
1131 adx 30 sendto_one(source_p, ":%s %d %s ? :Sent total : %7.2f %s",
1132     from, RPL_STATSDEBUG, to,
1133 michael 560 _GMKv(sendB), _GMKs(sendB));
1134 adx 30 sendto_one(source_p, ":%s %d %s ? :Recv total : %7.2f %s",
1135     from, RPL_STATSDEBUG, to,
1136 michael 560 _GMKv(recvB), _GMKs(recvB));
1137 adx 30
1138 michael 1241 uptime = (CurrentTime - me.localClient->since);
1139 adx 30
1140     sendto_one(source_p, ":%s %d %s ? :Server send: %7.2f %s (%4.1f K/s)",
1141     from, RPL_STATSDEBUG, to,
1142 michael 560 _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 adx 30 sendto_one(source_p, ":%s %d %s ? :Server recv: %7.2f %s (%4.1f K/s)",
1147     from, RPL_STATSDEBUG, to,
1148 michael 560 _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 adx 30 }
1153    
1154 michael 1457 /* 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 adx 30 {
1168 michael 1457 char *name;
1169 adx 30
1170 michael 1457 if (parc > 2)
1171 adx 30 {
1172 michael 1457 name = parv[2];
1173 adx 30
1174 michael 1457 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 adx 30 }
1183    
1184 michael 1457 return NULL;
1185 adx 30 }
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 michael 1219 if (HasUMode(target_p, UMODE_INVISIBLE) && (doall || wilds) &&
1205 michael 1457 !(MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) &&
1206     !HasUMode(target_p, UMODE_OPER) && (target_p != source_p))
1207 adx 30 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 michael 1457 if(MyClient(source_p) && HasUMode(source_p, UMODE_OPER) &&
1216 michael 1219 (HasUMode(source_p, UMODE_ADMIN) ||
1217 michael 1457 (!IsServer(target_p) && !HasUMode(target_p, UMODE_ADMIN) &&
1218 adx 30 !IsHandshake(target_p) && !IsConnecting(target_p))))
1219     {
1220     sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1221 michael 1457 from, to,
1222 adx 30 (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 michael 1241 (unsigned)(CurrentTime - target_p->localClient->firsttime),
1231     (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0,
1232 adx 30 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 michael 1219 if(IsIPSpoof(target_p) || IsServer(target_p) || HasUMode(target_p, UMODE_ADMIN)
1238 adx 30 || IsHandshake(target_p) || IsConnecting(target_p))
1239     sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1240     from, to,
1241 michael 1457 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 adx 30 else /* show the real IP */
1251     sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1252     from, to,
1253 michael 1457 (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 adx 30 }
1265     }
1266     }
1267    
1268 michael 1457 /*
1269     * stats_L
1270 adx 30 *
1271 michael 1457 * 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 michael 1618 sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE,
1385 michael 1532 "STATS %c requested by %s (%s@%s) [%s]",
1386 michael 1457 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 adx 30 *
1403 michael 1457 * This will search the tables for the appropriate stats letter/command,
1404     * if found execute it.
1405 adx 30 */
1406 michael 1457 static void
1407     m_stats(struct Client *client_p, struct Client *source_p,
1408     int parc, char *parv[])
1409 adx 30 {
1410 michael 1457 static time_t last_used = 0;
1411 adx 30
1412 michael 1457 /* 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 adx 30 {
1420 michael 1457 from = me.id;
1421     to = source_p->id;
1422     }
1423     else
1424     {
1425     from = me.name;
1426     to = source_p->name;
1427     }
1428 adx 30
1429 michael 1457 /* 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 adx 30
1437 michael 1457 last_used = CurrentTime;
1438 adx 30
1439 michael 1457 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 adx 30 }
1464 michael 1457 else
1465     {
1466     from = me.name;
1467     to = source_p->name;
1468     }
1469 michael 1400
1470 michael 1457 do_stats(source_p, parc, parv);
1471 adx 30 }
1472 michael 1230
1473 michael 1457 /*
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 michael 1230 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