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 "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         send_reply(sptr, p[1], c, host, pass, name, port, get_conf_class(tmp));
131       /*
132        * connect rules are classless
133        */
134       else if ((tmp->status & CONF_CRULE))
135         send_reply(sptr, p[1], c, host, name);
136       else if ((tmp->status & CONF_TLINES))
137         send_reply(sptr, p[1], c, host, pass);
138       else if ((tmp->status & CONF_UWORLD))
139         send_reply(sptr, p[1], c, host, pass, name, port, get_conf_class(tmp));
140       else if ((tmp->status & (CONF_SERVER | CONF_HUB)))
141         send_reply(sptr, p[1], c, "*", name, port, get_conf_class(tmp));
142       else
143         send_reply(sptr, p[1], c, host, name, port, get_conf_class(tmp));
144     }
145   }
146 }
147
148 /* m_stats is so obnoxiously full of special cases that the different
149  * hunt_server() possiblites were becoming very messy. It now uses a
150  * switch() so as to be easier to read and update as params change. 
151  * -Ghostwolf 
152  */
153 int hunt_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[], char stat)
154 {
155   switch (stat)
156   {
157       /* open to all, standard # of params */
158     case 'U':
159     case 'u':
160       return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s :%C", 2, parc,
161                              parv);
162
163     /* open to all, varying # of params */
164     case 'k':
165     case 'K':
166     case 'i':
167     case 'I':
168     case 'p':
169     case 'P':
170     {
171       if (parc > 3)
172         return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s %C :%s", 2, parc,
173                                parv);
174       else
175         return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s :%C", 2, parc,
176                                parv);
177     }
178
179       /* oper only, varying # of params */
180     case 'l':
181     case 'L':
182     case 'M':
183     {
184       if (parc == 4)
185         return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s %C :%s", 2, parc,
186                                parv);
187       else if (parc > 4)
188         return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s %C %s :%s", 2,
189                                parc, parv);
190       else 
191         return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s :%C", 2, parc,
192                                parv);
193     }
194
195       /* oper only, standard # of params */
196     default:
197       return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s :%C", 2, parc,
198                              parv);
199   }
200 }
201