1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
/* +------------------------------------+
* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
* InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
* E-mail:
* <brain@chatspike.net>
* <Craig@chatspike.net>
*
* Written by Craig Edwards, Craig McLure, and others.
* This program is free but copyrighted software; see
* the file COPYING for details.
*
* ---------------------------------------------------
*/
using namespace std;
#include "inspircd_config.h"
#include "inspircd.h"
#include "inspircd_io.h"
#include <time.h>
#include <string>
#ifdef GCC3
#include <ext/hash_map>
#else
#include <hash_map>
#endif
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#ifdef THREADED_DNS
#include <pthread.h>
#endif
#ifndef RUSAGE_SELF
#define RUSAGE_SELF 0
#define RUSAGE_CHILDREN -1
#endif
#include <map>
#include <sstream>
#include <vector>
#include <deque>
#include "users.h"
#include "ctables.h"
#include "globals.h"
#include "modules.h"
#include "dynamic.h"
#include "wildcard.h"
#include "message.h"
#include "commands.h"
#include "mode.h"
#include "xline.h"
#include "inspstring.h"
#include "dnsqueue.h"
#include "helperfuncs.h"
#include "hashcomp.h"
#include "socketengine.h"
#include "typedefs.h"
#include "command_parse.h"
#include "cmd_stats.h"
extern ServerConfig* Config;
extern InspIRCd* ServerInstance;
extern int MODCOUNT;
extern std::vector<Module*> modules;
extern std::vector<ircd_module*> factory;
extern time_t TIME;
extern user_hash clientlist;
extern chan_hash chanlist;
extern whowas_hash whowas;
extern std::vector<userrec*> all_opers;
extern std::vector<userrec*> local_users;
extern userrec* fd_ref_table[MAX_DESCRIPTORS];
void cmd_stats::Handle (char **parameters, int pcnt, userrec *user)
{
if (pcnt != 1)
{
return;
}
if (parameters[0][1])
{
/* make the stats query 1 character long */
parameters[0][1] = 0;
}
if ((*Config->OperOnlyStats) && (strchr(Config->OperOnlyStats,*parameters[0])) && (!*user->oper))
{
WriteServ(user->fd,"481 %s :Permission denied - STATS %c is oper-only",user->nick,*parameters[0]);
return;
}
int MOD_RESULT = 0;
FOREACH_RESULT(I_OnStats,OnStats(*parameters[0],user));
if (MOD_RESULT)
return;
if (*parameters[0] == 'c')
{
/* This stats symbol must be handled by a linking module */
}
if (*parameters[0] == 'i')
{
int idx = 0;
for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
{
WriteServ(user->fd,"215 %s I * * * %d %d %s *",user->nick,MAXCLIENTS,idx,Config->ServerName);
idx++;
}
}
if (*parameters[0] == 'y')
{
int idx = 0;
for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
{
WriteServ(user->fd,"218 %s Y %d %d 0 %d %d",user->nick,idx,120,i->flood,i->registration_timeout);
idx++;
}
}
if (*parameters[0] == 'U')
{
char ulined[MAXBUF];
for (int i = 0; i < Config->ConfValueEnum("uline",&Config->config_f); i++)
{
Config->ConfValue("uline","server",i,ulined,&Config->config_f);
WriteServ(user->fd,"248 %s U %s",user->nick,ulined);
}
}
if (*parameters[0] == 'P')
{
int idx = 0;
for (user_hash::iterator i = clientlist.begin(); i != clientlist.end(); i++)
{
if (*i->second->oper)
{
WriteServ(user->fd,"249 %s :%s (%s@%s) Idle: %d",user->nick,i->second->nick,i->second->ident,i->second->dhost,(TIME - i->second->idle_lastmsg));
idx++;
}
}
WriteServ(user->fd,"249 %s :%d OPER(s)",user->nick,idx);
}
if (*parameters[0] == 'k')
{
stats_k(user);
}
if (*parameters[0] == 'g')
{
stats_g(user);
}
if (*parameters[0] == 'q')
{
stats_q(user);
}
if (*parameters[0] == 'Z')
{
stats_z(user);
}
if (*parameters[0] == 'e')
{
stats_e(user);
}
/* stats m (list number of times each command has been used, plus bytecount) */
if (*parameters[0] == 'm')
{
for (nspace::hash_map<std::string,command_t*>::iterator i = ServerInstance->Parser->cmdlist.begin(); i != ServerInstance->Parser->cmdlist.end(); i++)
{
if (i->second->use_count)
{
/* RPL_STATSCOMMANDS */
WriteServ(user->fd,"212 %s %s %d %d",user->nick,i->second->command.c_str(),i->second->use_count,i->second->total_bytes);
}
}
}
/* stats z (debug and memory info) */
if (*parameters[0] == 'z')
{
rusage R;
WriteServ(user->fd,"249 %s :Users(HASH_MAP) %d (%d bytes, %d buckets)",user->nick,clientlist.size(),clientlist.size()*sizeof(userrec),clientlist.bucket_count());
WriteServ(user->fd,"249 %s :Channels(HASH_MAP) %d (%d bytes, %d buckets)",user->nick,chanlist.size(),chanlist.size()*sizeof(chanrec),chanlist.bucket_count());
WriteServ(user->fd,"249 %s :Commands(VECTOR) %d (%d bytes)",user->nick,ServerInstance->Parser->cmdlist.size(),ServerInstance->Parser->cmdlist.size()*sizeof(command_t));
WriteServ(user->fd,"249 %s :MOTD(VECTOR) %d, RULES(VECTOR) %d",user->nick,Config->MOTD.size(),Config->RULES.size());
WriteServ(user->fd,"249 %s :Modules(VECTOR) %d (%d)",user->nick,modules.size(),modules.size()*sizeof(Module));
WriteServ(user->fd,"249 %s :ClassFactories(VECTOR) %d (%d)",user->nick,factory.size(),factory.size()*sizeof(ircd_module));
if (!getrusage(RUSAGE_SELF,&R))
{
WriteServ(user->fd,"249 %s :Total allocation: %luK (0x%lx)",user->nick,R.ru_maxrss,R.ru_maxrss);
WriteServ(user->fd,"249 %s :Signals: %lu (0x%lx)",user->nick,R.ru_nsignals,R.ru_nsignals);
WriteServ(user->fd,"249 %s :Page faults: %lu (0x%lx)",user->nick,R.ru_majflt,R.ru_majflt);
WriteServ(user->fd,"249 %s :Swaps: %lu (0x%lx)",user->nick,R.ru_nswap,R.ru_nswap);
WriteServ(user->fd,"249 %s :Context Switches: %lu (0x%lx)",user->nick,R.ru_nvcsw+R.ru_nivcsw,R.ru_nvcsw+R.ru_nivcsw);
}
}
if (*parameters[0] == 'T')
{
WriteServ(user->fd,"249 Brain :accepts %d refused %d",ServerInstance->stats->statsAccept,ServerInstance->stats->statsRefused);
WriteServ(user->fd,"249 Brain :unknown commands %d",ServerInstance->stats->statsUnknown);
WriteServ(user->fd,"249 Brain :nick collisions %d",ServerInstance->stats->statsCollisions);
WriteServ(user->fd,"249 Brain :dns requests %d succeeded %d failed %d",ServerInstance->stats->statsDns,ServerInstance->stats->statsDnsGood,ServerInstance->stats->statsDnsBad);
WriteServ(user->fd,"249 Brain :connections %d",ServerInstance->stats->statsConnects);
WriteServ(user->fd,"249 Brain :bytes sent %dK recv %dK",(ServerInstance->stats->statsSent / 1024),(ServerInstance->stats->statsRecv / 1024));
}
/* stats o */
if (*parameters[0] == 'o')
{
for (int i = 0; i < Config->ConfValueEnum("oper",&Config->config_f); i++)
{
char LoginName[MAXBUF];
char HostName[MAXBUF];
char OperType[MAXBUF];
Config->ConfValue("oper","name",i,LoginName,&Config->config_f);
Config->ConfValue("oper","host",i,HostName,&Config->config_f);
Config->ConfValue("oper","type",i,OperType,&Config->config_f);
WriteServ(user->fd,"243 %s O %s * %s %s 0",user->nick,HostName,LoginName,OperType);
}
}
/* stats l (show user I/O stats) */
if (*parameters[0] == 'l')
{
WriteServ(user->fd,"211 %s :server:port nick bytes_in cmds_in bytes_out cmds_out",user->nick);
for (user_hash::iterator i = clientlist.begin(); i != clientlist.end(); i++)
{
if (isnick(i->second->nick))
{
WriteServ(user->fd,"211 %s :%s:%d %s %d %d %d %d",user->nick,i->second->server,i->second->port,i->second->nick,i->second->bytes_in,i->second->cmds_in,i->second->bytes_out,i->second->cmds_out);
}
else
{
WriteServ(user->fd,"211 %s :%s:%d (unknown@%d) %d %d %d %d",user->nick,i->second->server,i->second->port,i->second->fd,i->second->bytes_in,i->second->cmds_in,i->second->bytes_out,i->second->cmds_out);
}
}
}
/* stats u (show server uptime) */
if (*parameters[0] == 'u')
{
time_t current_time = 0;
current_time = TIME;
time_t server_uptime = current_time - ServerInstance->startup_time;
struct tm* stime;
stime = gmtime(&server_uptime);
/* i dont know who the hell would have an ircd running for over a year nonstop, but
* Craig suggested this, and it seemed a good idea so in it went */
if (stime->tm_year > 70)
{
WriteServ(user->fd,"242 %s :Server up %d years, %d days, %.2d:%.2d:%.2d",user->nick,(stime->tm_year-70),stime->tm_yday,stime->tm_hour,stime->tm_min,stime->tm_sec);
}
else
{
WriteServ(user->fd,"242 %s :Server up %d days, %.2d:%.2d:%.2d",user->nick,stime->tm_yday,stime->tm_hour,stime->tm_min,stime->tm_sec);
}
}
WriteServ(user->fd,"219 %s %s :End of /STATS report",user->nick,parameters[0]);
WriteOpers("*** Notice: Stats '%s' requested by %s (%s@%s)",parameters[0],user->nick,user->ident,user->host);
}
|