Author: Isomer <perry@coders.net>
[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_LEAF, RPL_STATSLLINE, 'L'},
89   {CONF_OPERATOR, RPL_STATSOLINE, 'O'},
90   {CONF_HUB, RPL_STATSHLINE, 'H'},
91   {CONF_LOCOP, RPL_STATSOLINE, 'o'},
92   {CONF_UWORLD, RPL_STATSULINE, 'U'},
93   {0, 0}
94 };
95
96 void report_configured_links(struct Client *sptr, int mask)
97 {
98   static char null[] = "<NULL>";
99   struct ConfItem *tmp;
100   unsigned int *p;
101   unsigned short int port;
102   char c, *host, *pass, *name;
103   
104
105   for (tmp = GlobalConfList; tmp; tmp = tmp->next) 
106   {
107     if ((tmp->status & mask))
108     {
109       for (p = &report_array[0][0]; *p; p += 3)
110         if (*p == tmp->status)
111           break;
112       if (!*p)
113         continue;
114       c = (char)*(p + 2);
115       host = BadPtr(tmp->host) ? null : tmp->host;
116       pass = BadPtr(tmp->passwd) ? null : tmp->passwd;
117       name = BadPtr(tmp->name) ? null : tmp->name;
118       port = tmp->port;
119       /*
120        * On K line the passwd contents can be
121        * displayed on STATS reply.    -Vesa
122        */
123       /* Special-case 'k' or 'K' lines as appropriate... -Kev */
124       if ((tmp->status & CONF_UWORLD))
125         send_reply(sptr, p[1], c, host, pass, name, port, get_conf_class(tmp));
126       else if ((tmp->status & (CONF_SERVER | CONF_HUB)))
127         send_reply(sptr, p[1], c, "*", name, port, get_conf_class(tmp));
128       else
129         send_reply(sptr, p[1], c, host, name, port, get_conf_class(tmp));
130     }
131   }
132 }
133
134 /*
135  *  {CONF_TLINES, RPL_STATSTLINE, 'T'},
136  */
137 void report_motd_list(struct Client* to)
138 {
139   const struct MotdConf* conf = conf_get_motd_list();
140   for ( ; conf; conf = conf->next)
141     send_reply(to, RPL_STATSTLINE, 'T', conf->hostmask, conf->path);
142 }
143
144 /*
145  * {CONF_CRULEALL, RPL_STATSDLINE, 'D'},
146  * {CONF_CRULEAUTO, RPL_STATSDLINE, 'd'},
147  */
148 void report_crule_list(struct Client* to, int mask)
149 {
150   const struct CRuleConf* p = conf_get_crule_list();
151   for ( ; p; p = p->next) {
152     if (0 != (p->type & mask))
153       send_reply(to, RPL_STATSDLINE, (CRULE_ALL == p->type) ? 'D' : 'd', p->hostmask, p->rule);
154   }
155 }
156
157 /*
158  * {CONF_KILL, RPL_STATSKLINE, 'K'},
159  * {CONF_IPKILL, RPL_STATSKLINE, 'k'},
160  */
161 void report_deny_list(struct Client* to)
162 {
163   const struct DenyConf* p = conf_get_deny_list();
164   for ( ; p; p = p->next)
165     send_reply(to, RPL_STATSKLINE, (p->ip_kill) ? 'k' : 'K',
166                p->hostmask, p->message, p->usermask);
167 }
168
169 /* m_stats is so obnoxiously full of special cases that the different
170  * hunt_server() possiblites were becoming very messy. It now uses a
171  * switch() so as to be easier to read and update as params change. 
172  * -Ghostwolf 
173  *
174  * 2.10.11: Don't check for the oper limitation if it's not our local server.
175  *          thusly once all the hubs have upgraded local opers will be able
176  *          to remote stats anywhere on the network.
177  */
178 int hunt_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[], char stat)
179 {
180   switch (stat)
181   {
182       /* open to all, standard # of params */
183     case 'U':
184     case 'u':
185       return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s :%C", 2, parc,
186                              parv);
187
188     /* open to all, varying # of params */
189     case 'k':
190     case 'K':
191     case 'i':
192     case 'I':
193     case 'p':
194     case 'P':
195     {
196       if (parc > 3)
197         return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s %C :%s", 2, parc, parv);
198       else
199         return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s :%C", 2, parc, parv);
200     }
201
202       /* oper only, varying # of params */
203     case 'l':
204     case 'L':
205     case 'M':
206     {
207       if (parc == 4)
208         return hunt_server_cmd(sptr, CMD_STATS, cptr, MyUser(sptr) ? 1 : 0, "%s %C :%s", 2, parc, parv);
209       else if (parc > 4)
210         return hunt_server_cmd(sptr, CMD_STATS, cptr, MyUser(sptr) ? 1 : 0, "%s %C %s :%s", 2, parc, parv);
211       else 
212         return hunt_server_cmd(sptr, CMD_STATS, cptr, MyUser(sptr) ? 1 : 0, "%s :%C", 2, parc, parv);
213     }
214
215       /* oper only, standard # of params */
216     default:
217       return hunt_server_cmd(sptr, CMD_STATS, cptr, MyUser(sptr) ? 1 : 0, "%s :%C", 2, parc, parv);
218   }
219 }
220