Author: Bleep <helveytw@home.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 "ircd.h"
29 #include "ircd_chattr.h"
30 #include "ircd_reply.h"
31 #include "ircd_string.h"
32 #include "listener.h"
33 #include "match.h"
34 #include "msg.h"
35 #include "numeric.h"
36 #include "numnicks.h"
37 #include "s_conf.h"
38 #include "s_user.h"
39 #include "send.h"
40 #include "struct.h"
41
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <sys/time.h>
45
46
47 /*
48  * m_stats/s_stats
49  *
50  * Report configuration lines and other statistics from this
51  * server. 
52  *
53  * Note: The info is reported in the order the server uses
54  *       it--not reversed as in ircd.conf!
55  */
56
57 /*
58  *  Help info displayed when user provides no stats parameter. --Gte
59  */
60 const char *statsinfo[] = {
61     "The following statistics are available:",
62     "U - Service server & nick jupes information.",
63     "u - Current uptime & highest connection count.",
64     "p - Listening ports.",
65     "i - Connection authorisation lines.",
66     "y - Connection classes.",
67     "c - Remote server connection lines.",
68     "h - Hubs information.",
69     "d - Dynamic routing configuration.", 
70     "l - Current connections information.",
71     "g - Global bans (G-lines).",
72     "k - Local bans (K-Lines).",
73     "o - Operator information.", 
74     "m - Message usage information.",
75     "t - Local connection statistics (Total SND/RCV, etc).", 
76     "w - Userload statistics.",
77     "v - Connection class information.",
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_UWORLD, RPL_STATSULINE, 'U'},
95   {0, 0}
96 };
97
98 void report_configured_links(struct Client *sptr, int mask)
99 {
100   static char null[] = "<NULL>";
101   struct ConfItem *tmp;
102   unsigned int *p;
103   unsigned short int port;
104   char c, *host, *pass, *name;
105   
106
107   for (tmp = GlobalConfList; tmp; tmp = tmp->next) 
108   {
109     if ((tmp->status & mask))
110     {
111       for (p = &report_array[0][0]; *p; p += 3)
112         if (*p == tmp->status)
113           break;
114       if (!*p)
115         continue;
116       c = (char)*(p + 2);
117       host = BadPtr(tmp->host) ? null : tmp->host;
118       pass = BadPtr(tmp->passwd) ? null : tmp->passwd;
119       name = BadPtr(tmp->name) ? null : tmp->name;
120       port = tmp->port;
121       /*
122        * On K line the passwd contents can be
123        * displayed on STATS reply.    -Vesa
124        */
125       /* Special-case 'k' or 'K' lines as appropriate... -Kev */
126       if ((tmp->status & CONF_KLINE))
127         send_reply(sptr, p[1], c, host, pass, name, port, get_conf_class(tmp));
128       else if ((tmp->status & CONF_UWORLD))
129         send_reply(sptr, p[1], c, host, pass, name, port, get_conf_class(tmp));
130       else if ((tmp->status & (CONF_SERVER | CONF_HUB)))
131         send_reply(sptr, p[1], c, "*", name, port, get_conf_class(tmp));
132       else
133         send_reply(sptr, p[1], c, host, name, port, get_conf_class(tmp));
134     }
135   }
136 }
137
138 /*
139  *  {CONF_TLINES, RPL_STATSTLINE, 'T'},
140  */
141 void report_motd_list(struct Client* to)
142 {
143   const struct MotdConf* conf = conf_get_motd_list();
144   for ( ; conf; conf = conf->next)
145     send_reply(to, RPL_STATSTLINE, 'T', conf->hostmask, conf->path);
146 }
147
148 /*
149  * {CONF_CRULEALL, RPL_STATSDLINE, 'D'},
150  * {CONF_CRULEAUTO, RPL_STATSDLINE, 'd'},
151  */
152 void report_crule_list(struct Client* to, int mask)
153 {
154   const struct CRuleConf* p = conf_get_crule_list();
155   for ( ; p; p = p->next) {
156     if (0 != (p->type & mask))
157       send_reply(to, RPL_STATSDLINE, (CRULE_ALL == p->type) ? 'D' : 'd', p->hostmask, p->rule);
158   }
159 }
160
161 /* m_stats is so obnoxiously full of special cases that the different
162  * hunt_server() possiblites were becoming very messy. It now uses a
163  * switch() so as to be easier to read and update as params change. 
164  * -Ghostwolf 
165  */
166 int hunt_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[], char stat)
167 {
168   switch (stat)
169   {
170       /* open to all, standard # of params */
171     case 'U':
172     case 'u':
173       return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s :%C", 2, parc,
174                              parv);
175
176     /* open to all, varying # of params */
177     case 'k':
178     case 'K':
179     case 'i':
180     case 'I':
181     case 'p':
182     case 'P':
183     {
184       if (parc > 3)
185         return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s %C :%s", 2, parc, parv);
186       else
187         return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s :%C", 2, parc, parv);
188     }
189
190       /* oper only, varying # of params */
191     case 'l':
192     case 'L':
193     case 'M':
194     {
195       if (parc == 4)
196         return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s %C :%s", 2, parc, parv);
197       else if (parc > 4)
198         return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s %C %s :%s", 2, parc, parv);
199       else 
200         return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s :%C", 2, parc, parv);
201     }
202
203       /* oper only, standard # of params */
204     default:
205       return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s :%C", 2, parc, parv);
206   }
207 }
208