ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
Revision: 1577
Committed: Thu Oct 18 14:52:52 2012 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_stats.c
File size: 49511 byte(s)
Log Message:
- stats_tklines(): remove unused variable

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

Properties

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