Author: Isomer <isomer@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 "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     "v - Connection class information.",
79     "M - Memory allocation & leak monitoring.", 
80     "z - Memory/Structure allocation information.",
81     "r - System resource usage (Debug only).", 
82     "x - List usage information (Debug only).",
83     0,
84 };
85
86 static unsigned int report_array[17][3] = {
87   {CONF_SERVER, RPL_STATSCLINE, 'C'},
88   {CONF_CLIENT, RPL_STATSILINE, 'I'},
89   {CONF_KILL, RPL_STATSKLINE, 'K'},
90   {CONF_IPKILL, RPL_STATSKLINE, 'k'},
91   {CONF_LEAF, RPL_STATSLLINE, 'L'},
92   {CONF_OPERATOR, RPL_STATSOLINE, 'O'},
93   {CONF_HUB, RPL_STATSHLINE, 'H'},
94   {CONF_LOCOP, RPL_STATSOLINE, 'o'},
95   {CONF_CRULEALL, RPL_STATSDLINE, 'D'},
96   {CONF_CRULEAUTO, RPL_STATSDLINE, 'd'},
97   {CONF_UWORLD, RPL_STATSULINE, 'U'},
98   {CONF_TLINES, RPL_STATSTLINE, 'T'},
99   {0, 0}
100 };
101
102 void report_configured_links(struct Client *sptr, int mask)
103 {
104   static char null[] = "<NULL>";
105   struct ConfItem *tmp;
106   unsigned int *p;
107   unsigned short int port;
108   char c, *host, *pass, *name;
109   
110
111   for (tmp = GlobalConfList; tmp; tmp = tmp->next) 
112   {
113     if ((tmp->status & mask))
114     {
115       for (p = &report_array[0][0]; *p; p += 3)
116         if (*p == tmp->status)
117           break;
118       if (!*p)
119         continue;
120       c = (char)*(p + 2);
121       host = BadPtr(tmp->host) ? null : tmp->host;
122       pass = BadPtr(tmp->passwd) ? null : tmp->passwd;
123       name = BadPtr(tmp->name) ? null : tmp->name;
124       port = tmp->port;
125       /*
126        * On K line the passwd contents can be
127        * displayed on STATS reply.    -Vesa
128        */
129       /* Special-case 'k' or 'K' lines as appropriate... -Kev */
130       if ((tmp->status & CONF_KLINE))
131         send_reply(sptr, p[1], c, host, pass, name, port, get_conf_class(tmp));
132       /*
133        * connect rules are classless
134        */
135       else if ((tmp->status & CONF_CRULE))
136         send_reply(sptr, p[1], c, host, name);
137       else if ((tmp->status & CONF_TLINES))
138         send_reply(sptr, p[1], c, host, pass);
139       else if ((tmp->status & CONF_UWORLD))
140         send_reply(sptr, p[1], c, host, pass, name, port, get_conf_class(tmp));
141       else if ((tmp->status & (CONF_SERVER | CONF_HUB)))
142         send_reply(sptr, p[1], c, "*", name, port, get_conf_class(tmp));
143       else
144         send_reply(sptr, p[1], c, host, name, port, get_conf_class(tmp));
145     }
146   }
147 }
148
149 /* m_stats is so obnoxiously full of special cases that the different
150  * hunt_server() possiblites were becoming very messy. It now uses a
151  * switch() so as to be easier to read and update as params change. 
152  * -Ghostwolf 
153  */
154 int hunt_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[], char stat)
155 {
156   switch (stat)
157   {
158       /* open to all, standard # of params */
159     case 'U':
160     case 'u':
161       return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s :%C", 2, parc,
162                              parv);
163
164     /* open to all, varying # of params */
165     case 'k':
166     case 'K':
167     case 'i':
168     case 'I':
169     case 'p':
170     case 'P':
171     {
172       if (parc > 3)
173         return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s %C :%s", 2, parc,
174                                parv);
175       else
176         return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s :%C", 2, parc,
177                                parv);
178     }
179
180       /* oper only, varying # of params */
181     case 'l':
182     case 'L':
183     case 'M':
184     {
185       if (parc == 4)
186         return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s %C :%s", 2, parc,
187                                parv);
188       else if (parc > 4)
189         return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s %C %s :%s", 2,
190                                parc, parv);
191       else 
192         return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s :%C", 2, parc,
193                                parv);
194     }
195
196       /* oper only, standard # of params */
197     default:
198       return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s :%C", 2, parc,
199                              parv);
200   }
201 }
202