Author: Ghostwolf <foxxe@trms.com>
[ircu2.10.12-pk.git] / ircd / s_stats.c
1 /*
2  * IRC - Internet Relay Chat, ircd/s_stats.c
3  * Copyright (C) 2000 Joseph Bongaarts
4  *
5  * See file AUTHORS in IRC package for additional names of
6  * the programmers.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 1, or (at your option)
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  * $Id$
23  */
24
25 #include "s_stats.h"
26 #include "class.h"
27 #include "client.h"
28 #include "crule.h"
29 #include "ircd.h"
30 #include "ircd_chattr.h"
31 #include "ircd_reply.h"
32 #include "ircd_string.h"
33 #include "listener.h"
34 #include "match.h"
35 #include "msg.h"
36 #include "numeric.h"
37 #include "numnicks.h"
38 #include "s_conf.h"
39 #include "s_user.h"
40 #include "send.h"
41 #include "struct.h"
42
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <sys/time.h>
46
47
48 /*
49  * m_stats/s_stats
50  *
51  * Report configuration lines and other statistics from this
52  * server. 
53  *
54  * Note: The info is reported in the order the server uses
55  *       it--not reversed as in ircd.conf!
56  */
57
58 /*
59  *  Help info displayed when user provides no stats parameter. --Gte
60  */
61 const char *statsinfo[] = {
62     "The following statistics are available:",
63     "U - Service server & nick jupes information.",
64     "u - Current uptime & highest connection count.",
65     "p - Listening ports.",
66     "i - Connection authorisation lines.",
67     "y - Connection classes.",
68     "c - Remote server connection lines.",
69     "h - Hubs information.",
70     "d - Dynamic routing configuration.", 
71     "l - Current connections information.",
72     "g - Global bans (G-lines).",
73     "k - Local bans (K-Lines).",
74     "o - Operator information.", 
75     "m - Message usage information.",
76     "t - Local connection statistics (Total SND/RCV, etc).", 
77     "w - Userload statistics.",
78     "M - Memory allocation & leak monitoring.", 
79     "z - Memory/Structure allocation information.",
80     "r - System resource usage (Debug only).", 
81     "x - List usage information (Debug only).",
82     0,
83 };
84
85 static unsigned int report_array[17][3] = {
86   {CONF_SERVER, RPL_STATSCLINE, 'C'},
87   {CONF_CLIENT, RPL_STATSILINE, 'I'},
88   {CONF_KILL, RPL_STATSKLINE, 'K'},
89   {CONF_IPKILL, RPL_STATSKLINE, 'k'},
90   {CONF_LEAF, RPL_STATSLLINE, 'L'},
91   {CONF_OPERATOR, RPL_STATSOLINE, 'O'},
92   {CONF_HUB, RPL_STATSHLINE, 'H'},
93   {CONF_LOCOP, RPL_STATSOLINE, 'o'},
94   {CONF_CRULEALL, RPL_STATSDLINE, 'D'},
95   {CONF_CRULEAUTO, RPL_STATSDLINE, 'd'},
96   {CONF_UWORLD, RPL_STATSULINE, 'U'},
97   {CONF_TLINES, RPL_STATSTLINE, 'T'},
98   {0, 0}
99 };
100
101 void report_configured_links(struct Client *sptr, int mask)
102 {
103   static char null[] = "<NULL>";
104   struct ConfItem *tmp;
105   unsigned int *p;
106   unsigned short int port;
107   char c, *host, *pass, *name;
108   
109
110   for (tmp = GlobalConfList; tmp; tmp = tmp->next) 
111   {
112     if ((tmp->status & mask))
113     {
114       for (p = &report_array[0][0]; *p; p += 3)
115         if (*p == tmp->status)
116           break;
117       if (!*p)
118         continue;
119       c = (char)*(p + 2);
120       host = BadPtr(tmp->host) ? null : tmp->host;
121       pass = BadPtr(tmp->passwd) ? null : tmp->passwd;
122       name = BadPtr(tmp->name) ? null : tmp->name;
123       port = tmp->port;
124       /*
125        * On K line the passwd contents can be
126        * displayed on STATS reply.    -Vesa
127        */
128       /* Special-case 'k' or 'K' lines as appropriate... -Kev */
129       if ((tmp->status & CONF_KLINE))
130         sendto_one(sptr, rpl_str(p[1]), me.name,
131             sptr->name, c, host, pass, name, port, get_conf_class(tmp));
132       /*
133        * connect rules are classless
134        */
135       else if ((tmp->status & CONF_CRULE))
136         sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, host, name);
137       else if ((tmp->status & CONF_TLINES))
138         sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, host, pass);
139       else if ((tmp->status & CONF_UWORLD))
140         sendto_one(sptr, rpl_str(p[1]),
141             me.name, sptr->name, c, host, pass, name, port,
142             get_conf_class(tmp));
143       else if ((tmp->status & (CONF_SERVER | CONF_HUB)))
144         sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, "*", name,
145             port, get_conf_class(tmp));
146       else
147         sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, host, name,
148             port, get_conf_class(tmp));
149     }
150   }
151 }
152
153 /* m_stats is so obnoxiously full of special cases that the different
154  * hunt_server() possiblites were becoming very messy. It now uses a
155  * switch() so as to be easier to read and update as params change. 
156  * -Ghostwolf 
157  */
158 int hunt_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[], char stat)
159 {
160   switch (stat)
161   {
162       /* open to all, standard # of params */
163     case 'U':
164     case 'u':
165       return hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv);
166
167     /* open to all, varying # of params */
168     case 'k':
169     case 'K':
170     case 'i':
171     case 'I':
172     case 'p':
173     case 'P':
174     {
175       if (parc > 3)
176         return hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv);
177       else
178         return hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv);
179     }
180
181       /* oper only, varying # of params */
182     case 'l':
183     case 'L':
184     case 'M':
185     {
186       if (parc == 4)
187         return hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv);
188       else if (parc > 4)
189         return hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s %s :%s", 2, parc, parv);
190       else 
191         return hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv);
192     }
193
194       /* oper only, standard # of params */
195     default:
196       return hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv);
197   }
198 }
199