Author: Kev <klmitch@mit.edu>
[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_log.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     "f - Feature settings.",
76     "m - Message usage information.",
77     "t - Local connection statistics (Total SND/RCV, etc).", 
78     "w - Userload statistics.",
79     "v - Connection class information.",
80     "M - Memory allocation & leak monitoring.", 
81     "z - Memory/Structure allocation information.",
82     "r - System resource usage (Debug only).", 
83     "x - List usage information (Debug only).",
84     0,
85 };
86
87 static unsigned int report_array[17][3] = {
88   {CONF_SERVER, RPL_STATSCLINE, 'C'},
89   {CONF_CLIENT, RPL_STATSILINE, 'I'},
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_UWORLD))
127         send_reply(sptr, p[1], c, host, pass, name, port, get_conf_class(tmp));
128       else if ((tmp->status & (CONF_SERVER | CONF_HUB)))
129         send_reply(sptr, p[1], c, "*", name, port, get_conf_class(tmp));
130       else
131         send_reply(sptr, p[1], c, host, name, port, get_conf_class(tmp));
132     }
133   }
134 }
135
136 /*
137  *  {CONF_TLINES, RPL_STATSTLINE, 'T'},
138  *
139  * see now motd_report() in motd.c
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 /*
162  * {CONF_KILL, RPL_STATSKLINE, 'K'},
163  * {CONF_IPKILL, RPL_STATSKLINE, 'k'},
164  */
165 void report_deny_list(struct Client* to)
166 {
167   const struct DenyConf* p = conf_get_deny_list();
168   for ( ; p; p = p->next)
169     send_reply(to, RPL_STATSKLINE, (p->ip_kill) ? 'k' : 'K',
170                p->hostmask, p->message, p->usermask);
171 }
172
173 /* m_stats is so obnoxiously full of special cases that the different
174  * hunt_server() possiblites were becoming very messy. It now uses a
175  * switch() so as to be easier to read and update as params change. 
176  * -Ghostwolf 
177  *
178  * 2.10.11: Don't check for the oper limitation if it's not our local server.
179  *          thusly once all the hubs have upgraded local opers will be able
180  *          to remote stats anywhere on the network.
181  */
182 int hunt_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[], char stat)
183 {
184   switch (stat)
185   {
186       /* open to all, standard # of params */
187     case 'U':
188     case 'u':
189     case 'F':
190     case 'f':
191       return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s :%C", 2, parc,
192                              parv);
193
194     /* open to all, varying # of params */
195     case 'k':
196     case 'K':
197     case 'i':
198     case 'I':
199     case 'p':
200     case 'P':
201     {
202       if (parc > 3)
203         return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s %C :%s", 2, parc, parv);
204       else
205         return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s :%C", 2, parc, parv);
206     }
207
208       /* oper only, varying # of params */
209     case 'l':
210     case 'L':
211     case 'M':
212     {
213       if (parc == 4)
214         return hunt_server_cmd(sptr, CMD_STATS, cptr, MyUser(sptr) ? 1 : 0, "%s %C :%s", 2, parc, parv);
215       else if (parc > 4)
216         return hunt_server_cmd(sptr, CMD_STATS, cptr, MyUser(sptr) ? 1 : 0, "%s %C %s :%s", 2, parc, parv);
217       else 
218         return hunt_server_cmd(sptr, CMD_STATS, cptr, MyUser(sptr) ? 1 : 0, "%s :%C", 2, parc, parv);
219     }
220
221       /* oper only, standard # of params */
222     default:
223       return hunt_server_cmd(sptr, CMD_STATS, cptr, MyUser(sptr) ? 1 : 0, "%s :%C", 2, parc, parv);
224   }
225 }
226