1 |
adx |
30 |
/* |
2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
|
|
* m_stats.c: Sends the user statistics or config information. |
4 |
|
|
* |
5 |
|
|
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
|
|
* |
7 |
|
|
* This program is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* This program is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with this program; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
|
|
* USA |
21 |
|
|
* |
22 |
knight |
31 |
* $Id$ |
23 |
adx |
30 |
*/ |
24 |
|
|
|
25 |
|
|
#include "stdinc.h" |
26 |
michael |
1011 |
#include "list.h" /* dlink_node/dlink_list */ |
27 |
|
|
#include "balloc.h" |
28 |
adx |
30 |
#include "client.h" /* Client */ |
29 |
|
|
#include "irc_string.h" |
30 |
|
|
#include "ircd.h" /* me */ |
31 |
|
|
#include "listener.h" /* show_ports */ |
32 |
|
|
#include "s_gline.h" |
33 |
|
|
#include "hostmask.h" |
34 |
|
|
#include "numeric.h" /* ERR_xxx */ |
35 |
|
|
#include "send.h" /* sendto_one */ |
36 |
|
|
#include "fdlist.h" /* PF and friends */ |
37 |
|
|
#include "s_bsd.h" /* highest_fd */ |
38 |
michael |
1309 |
#include "conf.h" /* AccessItem, report_configured_links */ |
39 |
adx |
30 |
#include "s_misc.h" /* serv_info */ |
40 |
|
|
#include "s_serv.h" /* hunt_server */ |
41 |
|
|
#include "s_user.h" /* show_opers */ |
42 |
|
|
#include "event.h" /* events */ |
43 |
|
|
#include "dbuf.h" |
44 |
michael |
1144 |
#include "hook.h" |
45 |
adx |
30 |
#include "parse.h" |
46 |
|
|
#include "modules.h" |
47 |
|
|
#include "resv.h" /* report_resv */ |
48 |
|
|
#include "whowas.h" |
49 |
michael |
884 |
#include "watch.h" |
50 |
michael |
1312 |
#include "irc_res.h" |
51 |
adx |
30 |
|
52 |
|
|
|
53 |
|
|
const char *from, *to; |
54 |
|
|
|
55 |
|
|
/* |
56 |
|
|
* This is part of the STATS replies. There is no offical numeric for this |
57 |
|
|
* since this isnt an official command, in much the same way as HASH isnt. |
58 |
|
|
* It is also possible that some systems wont support this call or have |
59 |
|
|
* different field names for "struct rusage". |
60 |
|
|
* -avalon |
61 |
|
|
*/ |
62 |
|
|
static void |
63 |
michael |
1457 |
stats_usage(struct Client *source_p, int parc, char *parv[]) |
64 |
adx |
30 |
{ |
65 |
|
|
struct rusage rus; |
66 |
|
|
time_t secs; |
67 |
|
|
time_t rup; |
68 |
|
|
#ifdef hz |
69 |
|
|
# define hzz hz |
70 |
|
|
#else |
71 |
|
|
# ifdef HZ |
72 |
|
|
# define hzz HZ |
73 |
|
|
# else |
74 |
|
|
int hzz = 1; |
75 |
|
|
# endif |
76 |
|
|
#endif |
77 |
|
|
|
78 |
|
|
if (getrusage(RUSAGE_SELF, &rus) == -1) |
79 |
|
|
{ |
80 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Getruseage error: %s", |
81 |
|
|
me.name, source_p->name, strerror(errno)); |
82 |
|
|
return; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
secs = rus.ru_utime.tv_sec + rus.ru_stime.tv_sec; |
86 |
|
|
|
87 |
|
|
if (secs == 0) |
88 |
|
|
secs = 1; |
89 |
|
|
|
90 |
michael |
1241 |
rup = (CurrentTime - me.localClient->since) * hzz; |
91 |
adx |
30 |
|
92 |
|
|
if (rup == 0) |
93 |
|
|
rup = 1; |
94 |
|
|
|
95 |
|
|
sendto_one(source_p, |
96 |
|
|
":%s %d %s R :CPU Secs %d:%d User %d:%d System %d:%d", |
97 |
|
|
me.name, RPL_STATSDEBUG, source_p->name, (int)(secs/60), (int)(secs%60), |
98 |
|
|
(int)(rus.ru_utime.tv_sec/60), (int)(rus.ru_utime.tv_sec%60), |
99 |
|
|
(int)(rus.ru_stime.tv_sec/60), (int)(rus.ru_stime.tv_sec%60)); |
100 |
|
|
sendto_one(source_p, ":%s %d %s R :RSS %ld ShMem %ld Data %ld Stack %ld", |
101 |
|
|
me.name, RPL_STATSDEBUG, source_p->name, rus.ru_maxrss, |
102 |
|
|
(rus.ru_ixrss / rup), (rus.ru_idrss / rup), |
103 |
|
|
(rus.ru_isrss / rup)); |
104 |
|
|
sendto_one(source_p, ":%s %d %s R :Swaps %d Reclaims %d Faults %d", |
105 |
|
|
me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_nswap, |
106 |
|
|
(int)rus.ru_minflt, (int)rus.ru_majflt); |
107 |
|
|
sendto_one(source_p, ":%s %d %s R :Block in %d out %d", |
108 |
|
|
me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_inblock, |
109 |
|
|
(int)rus.ru_oublock); |
110 |
|
|
sendto_one(source_p, ":%s %d %s R :Msg Rcv %d Send %d", |
111 |
|
|
me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_msgrcv, |
112 |
|
|
(int)rus.ru_msgsnd); |
113 |
|
|
sendto_one(source_p, ":%s %d %s R :Signals %d Context Vol. %d Invol %d", |
114 |
|
|
me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_nsignals, |
115 |
|
|
(int)rus.ru_nvcsw, (int)rus.ru_nivcsw); |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
static void |
119 |
michael |
1457 |
stats_memory(struct Client *source_p, int parc, char *parv[]) |
120 |
adx |
30 |
{ |
121 |
|
|
const dlink_node *gptr = NULL; |
122 |
|
|
const dlink_node *dlink = NULL; |
123 |
|
|
|
124 |
michael |
948 |
unsigned int local_client_conf_count = 0; /* local client conf links */ |
125 |
|
|
unsigned int users_counted = 0; /* user structs */ |
126 |
adx |
30 |
|
127 |
michael |
1017 |
unsigned int channel_members = 0; |
128 |
michael |
948 |
unsigned int channel_invites = 0; |
129 |
|
|
unsigned int channel_bans = 0; |
130 |
|
|
unsigned int channel_except = 0; |
131 |
|
|
unsigned int channel_invex = 0; |
132 |
adx |
30 |
|
133 |
michael |
948 |
unsigned int wwu = 0; /* whowas users */ |
134 |
|
|
unsigned int class_count = 0; /* classes */ |
135 |
|
|
unsigned int aways_counted = 0; |
136 |
|
|
unsigned int number_ips_stored; /* number of ip addresses hashed */ |
137 |
adx |
30 |
|
138 |
michael |
948 |
uint64_t channel_memory = 0; |
139 |
|
|
uint64_t channel_ban_memory = 0; |
140 |
|
|
uint64_t channel_except_memory = 0; |
141 |
|
|
uint64_t channel_invex_memory = 0; |
142 |
adx |
30 |
|
143 |
|
|
unsigned int safelist_count = 0; |
144 |
michael |
948 |
uint64_t safelist_memory = 0; |
145 |
adx |
30 |
|
146 |
michael |
948 |
uint64_t away_memory = 0; /* memory used by aways */ |
147 |
|
|
uint64_t wwm = 0; /* whowas array memory used */ |
148 |
|
|
uint64_t conf_memory = 0; /* memory used by conf lines */ |
149 |
|
|
uint64_t mem_ips_stored; /* memory used by ip address hash */ |
150 |
adx |
30 |
|
151 |
michael |
948 |
uint64_t total_channel_memory = 0; |
152 |
|
|
uint64_t totww = 0; |
153 |
adx |
30 |
|
154 |
|
|
unsigned int local_client_count = 0; |
155 |
|
|
unsigned int remote_client_count = 0; |
156 |
|
|
|
157 |
michael |
948 |
uint64_t local_client_memory_used = 0; |
158 |
|
|
uint64_t remote_client_memory_used = 0; |
159 |
adx |
30 |
|
160 |
michael |
948 |
uint64_t total_memory = 0; |
161 |
adx |
30 |
unsigned int topic_count = 0; |
162 |
|
|
|
163 |
michael |
1017 |
unsigned int watch_list_headers = 0; /* watchlist headers */ |
164 |
|
|
unsigned int watch_list_entries = 0; /* watchlist entries */ |
165 |
|
|
uint64_t watch_list_memory = 0; /* watchlist memory used */ |
166 |
michael |
884 |
|
167 |
adx |
30 |
|
168 |
|
|
DLINK_FOREACH(gptr, global_client_list.head) |
169 |
|
|
{ |
170 |
|
|
struct Client *target_p = gptr->data; |
171 |
|
|
|
172 |
|
|
if (MyConnect(target_p)) |
173 |
|
|
{ |
174 |
|
|
++local_client_count; |
175 |
|
|
local_client_conf_count += dlink_list_length(&target_p->localClient->confs); |
176 |
michael |
1017 |
watch_list_entries += dlink_list_length(&target_p->localClient->watches); |
177 |
adx |
30 |
} |
178 |
|
|
else |
179 |
|
|
++remote_client_count; |
180 |
|
|
|
181 |
|
|
if (IsClient(target_p)) |
182 |
|
|
{ |
183 |
|
|
++users_counted; |
184 |
|
|
|
185 |
|
|
if (target_p->away != NULL) |
186 |
|
|
{ |
187 |
|
|
++aways_counted; |
188 |
|
|
away_memory += strlen(target_p->away) + 1; |
189 |
|
|
} |
190 |
|
|
} |
191 |
|
|
} |
192 |
|
|
|
193 |
|
|
/* Count up all channels, ban lists, except lists, Invex lists */ |
194 |
|
|
channel_memory = dlink_list_length(&global_channel_list) * |
195 |
|
|
sizeof(struct Channel); |
196 |
|
|
DLINK_FOREACH(gptr, global_channel_list.head) |
197 |
|
|
{ |
198 |
michael |
948 |
const struct Ban *actualBan; |
199 |
|
|
const struct Channel *chptr = gptr->data; |
200 |
adx |
30 |
|
201 |
michael |
1017 |
channel_members += dlink_list_length(&chptr->members); |
202 |
adx |
30 |
channel_invites += dlink_list_length(&chptr->invites); |
203 |
|
|
|
204 |
michael |
1203 |
if (chptr->topic[0]) |
205 |
adx |
30 |
++topic_count; |
206 |
|
|
|
207 |
michael |
1017 |
channel_bans += dlink_list_length(&chptr->banlist); |
208 |
|
|
channel_ban_memory += dlink_list_length(&chptr->banlist) * sizeof(struct Ban); |
209 |
|
|
|
210 |
|
|
DLINK_FOREACH(dlink, chptr->banlist.head) |
211 |
adx |
30 |
{ |
212 |
michael |
1017 |
actualBan = dlink->data; |
213 |
|
|
assert(actualBan->who); |
214 |
adx |
30 |
|
215 |
michael |
1017 |
channel_ban_memory += actualBan->len + 1; |
216 |
|
|
channel_ban_memory += strlen(actualBan->who) + 1; |
217 |
adx |
30 |
} |
218 |
|
|
|
219 |
michael |
1017 |
channel_except += dlink_list_length(&chptr->exceptlist); |
220 |
|
|
channel_except_memory += dlink_list_length(&chptr->exceptlist) * sizeof(struct Ban); |
221 |
|
|
|
222 |
|
|
DLINK_FOREACH(dlink, chptr->exceptlist.head) |
223 |
adx |
30 |
{ |
224 |
michael |
1017 |
actualBan = dlink->data; |
225 |
|
|
assert(actualBan->who); |
226 |
adx |
30 |
|
227 |
michael |
1017 |
channel_except_memory += actualBan->len + 1; |
228 |
|
|
channel_except_memory += strlen(actualBan->who) + 1; |
229 |
adx |
30 |
} |
230 |
|
|
|
231 |
michael |
1017 |
channel_invex += dlink_list_length(&chptr->invexlist); |
232 |
|
|
channel_invex_memory += dlink_list_length(&chptr->invexlist) * sizeof(struct Ban); |
233 |
|
|
|
234 |
|
|
DLINK_FOREACH(dlink, chptr->invexlist.head) |
235 |
adx |
30 |
{ |
236 |
michael |
1017 |
actualBan = dlink->data; |
237 |
|
|
assert(actualBan->who); |
238 |
adx |
30 |
|
239 |
michael |
1017 |
channel_invex_memory += actualBan->len + 1; |
240 |
|
|
channel_invex_memory += strlen(actualBan->who) + 1; |
241 |
adx |
30 |
} |
242 |
|
|
} |
243 |
|
|
|
244 |
|
|
if ((safelist_count = dlink_list_length(&listing_client_list))) |
245 |
|
|
{ |
246 |
|
|
safelist_memory = safelist_count * sizeof(struct ListTask); |
247 |
|
|
DLINK_FOREACH(gptr, listing_client_list.head) |
248 |
|
|
{ |
249 |
michael |
948 |
const struct Client *acptr = gptr->data; |
250 |
adx |
30 |
|
251 |
|
|
DLINK_FOREACH(dlink, acptr->localClient->list_task->show_mask.head) |
252 |
|
|
safelist_memory += strlen(dlink->data); |
253 |
|
|
|
254 |
|
|
DLINK_FOREACH(dlink, acptr->localClient->list_task->hide_mask.head) |
255 |
|
|
safelist_memory += strlen(dlink->data); |
256 |
|
|
} |
257 |
|
|
} |
258 |
|
|
|
259 |
|
|
#if 0 |
260 |
|
|
/* XXX THIS has to be fixed !!!! -db */ |
261 |
|
|
/* count up all config items */ |
262 |
|
|
DLINK_FOREACH(dlink, ConfigItemList.head) |
263 |
|
|
{ |
264 |
|
|
aconf = dlink->data; |
265 |
|
|
conf_memory += aconf->host ? strlen(aconf->host)+1 : 0; |
266 |
|
|
conf_memory += aconf->passwd ? strlen(aconf->passwd)+1 : 0; |
267 |
|
|
conf_memory += aconf->name ? strlen(aconf->name)+1 : 0; |
268 |
|
|
conf_memory += sizeof(struct AccessItem); |
269 |
|
|
} |
270 |
|
|
#endif |
271 |
|
|
/* count up all classes */ |
272 |
|
|
class_count = dlink_list_length(&class_items); |
273 |
|
|
|
274 |
michael |
1017 |
count_whowas_memory(&wwu, &wwm); |
275 |
|
|
watch_count_memory(&watch_list_headers, &watch_list_memory); |
276 |
michael |
884 |
|
277 |
michael |
1127 |
sendto_one(source_p, ":%s %d %s z :WATCH headers %u(%u) entries %d(%u)", |
278 |
michael |
1017 |
me.name, RPL_STATSDEBUG, source_p->name, watch_list_headers, |
279 |
|
|
watch_list_memory, watch_list_entries, |
280 |
|
|
watch_list_entries * sizeof(dlink_node) * 2); |
281 |
michael |
884 |
|
282 |
|
|
sendto_one(source_p, ":%s %d %s z :Clients %u(%u)", |
283 |
adx |
30 |
me.name, RPL_STATSDEBUG, source_p->name, users_counted, |
284 |
michael |
884 |
(users_counted * sizeof(struct Client))); |
285 |
adx |
30 |
|
286 |
michael |
948 |
sendto_one(source_p, ":%s %d %s z :User aways %u(%llu)", |
287 |
adx |
30 |
me.name, RPL_STATSDEBUG, source_p->name, |
288 |
michael |
948 |
aways_counted, away_memory); |
289 |
adx |
30 |
|
290 |
michael |
948 |
sendto_one(source_p, ":%s %d %s z :Attached confs %u(%llu)", |
291 |
adx |
30 |
me.name, RPL_STATSDEBUG, source_p->name, |
292 |
|
|
local_client_conf_count, |
293 |
michael |
948 |
(unsigned long long)(local_client_conf_count * sizeof(dlink_node))); |
294 |
adx |
30 |
|
295 |
michael |
1127 |
sendto_one(source_p, ":%s %d %s z :Resv channels %u(%lu) nicks %u(%lu)", |
296 |
adx |
30 |
me.name, RPL_STATSDEBUG, source_p->name, |
297 |
|
|
dlink_list_length(&resv_channel_list), |
298 |
|
|
dlink_list_length(&resv_channel_list) * sizeof(struct ResvChannel), |
299 |
|
|
dlink_list_length(&nresv_items), |
300 |
|
|
dlink_list_length(&nresv_items) * sizeof(struct MatchItem)); |
301 |
|
|
|
302 |
michael |
948 |
sendto_one(source_p, ":%s %d %s z :Classes %u(%llu)", |
303 |
adx |
30 |
me.name, RPL_STATSDEBUG, source_p->name, |
304 |
michael |
948 |
class_count, (unsigned long long)(class_count * sizeof(struct ClassItem))); |
305 |
adx |
30 |
|
306 |
michael |
1127 |
sendto_one(source_p, ":%s %d %s z :Channels %uu(%llu) Topics %u(%u)", |
307 |
adx |
30 |
me.name, RPL_STATSDEBUG, source_p->name, |
308 |
|
|
dlink_list_length(&global_channel_list), |
309 |
|
|
channel_memory, topic_count, topic_count * |
310 |
|
|
(TOPICLEN + 1 + USERHOST_REPLYLEN)); |
311 |
|
|
|
312 |
michael |
948 |
sendto_one(source_p, ":%s %d %s z :Bans %u(%llu)", |
313 |
adx |
30 |
me.name, RPL_STATSDEBUG, source_p->name, |
314 |
|
|
channel_bans, channel_ban_memory); |
315 |
|
|
|
316 |
michael |
948 |
sendto_one(source_p, ":%s %d %s z :Exceptions %u(%llu)", |
317 |
adx |
30 |
me.name, RPL_STATSDEBUG, source_p->name, |
318 |
|
|
channel_except, channel_except_memory); |
319 |
|
|
|
320 |
michael |
948 |
sendto_one(source_p, ":%s %d %s z :Invex %u(%llu)", |
321 |
adx |
30 |
me.name, RPL_STATSDEBUG, source_p->name, |
322 |
|
|
channel_invex, channel_invex_memory); |
323 |
|
|
|
324 |
michael |
948 |
sendto_one(source_p, ":%s %d %s z :Channel members %u(%llu) invites %u(%llu)", |
325 |
michael |
1017 |
me.name, RPL_STATSDEBUG, source_p->name, channel_members, |
326 |
|
|
(unsigned long long)(channel_members * sizeof(struct Membership)), |
327 |
michael |
948 |
channel_invites, (unsigned long long)channel_invites * |
328 |
michael |
884 |
sizeof(dlink_node) * 2); |
329 |
adx |
30 |
|
330 |
|
|
total_channel_memory = channel_memory + channel_ban_memory + |
331 |
michael |
1017 |
channel_members * sizeof(struct Membership) + |
332 |
michael |
884 |
(channel_invites * sizeof(dlink_node)*2); |
333 |
adx |
30 |
|
334 |
michael |
948 |
sendto_one(source_p, ":%s %d %s z :Safelist %u(%llu)", |
335 |
adx |
30 |
me.name, RPL_STATSDEBUG, source_p->name, |
336 |
|
|
safelist_count, safelist_memory); |
337 |
|
|
|
338 |
michael |
948 |
sendto_one(source_p, ":%s %d %s z :Whowas users %u(%llu)", |
339 |
adx |
30 |
me.name, RPL_STATSDEBUG, source_p->name, |
340 |
michael |
948 |
wwu, (unsigned long long)(wwu * sizeof(struct Client))); |
341 |
adx |
30 |
|
342 |
michael |
948 |
sendto_one(source_p, ":%s %d %s z :Whowas array %u(%llu)", |
343 |
adx |
30 |
me.name, RPL_STATSDEBUG, source_p->name, |
344 |
michael |
948 |
NICKNAMEHISTORYLENGTH, wwm); |
345 |
adx |
30 |
|
346 |
|
|
totww = wwu * sizeof(struct Client) + wwm; |
347 |
|
|
|
348 |
|
|
count_ip_hash(&number_ips_stored,&mem_ips_stored); |
349 |
michael |
948 |
sendto_one(source_p, ":%s %d %s z :iphash %u(%llu)", |
350 |
adx |
30 |
me.name, RPL_STATSDEBUG, source_p->name, |
351 |
michael |
948 |
number_ips_stored, mem_ips_stored); |
352 |
adx |
30 |
|
353 |
|
|
total_memory = totww + total_channel_memory + conf_memory + class_count * |
354 |
|
|
sizeof(struct ClassItem); |
355 |
michael |
948 |
sendto_one(source_p, ":%s %d %s z :Total: whowas %llu channel %llu conf %llu", |
356 |
|
|
me.name, RPL_STATSDEBUG, source_p->name, totww, |
357 |
|
|
total_channel_memory, conf_memory); |
358 |
adx |
30 |
|
359 |
|
|
local_client_memory_used = local_client_count*(sizeof(struct Client) + sizeof(struct LocalUser)); |
360 |
|
|
total_memory += local_client_memory_used; |
361 |
michael |
1127 |
sendto_one(source_p, ":%s %d %s z :Local client Memory in use: %u(%llu)", |
362 |
adx |
30 |
me.name, RPL_STATSDEBUG, source_p->name, local_client_count, |
363 |
|
|
local_client_memory_used); |
364 |
|
|
|
365 |
|
|
remote_client_memory_used = remote_client_count * sizeof(struct Client); |
366 |
|
|
total_memory += remote_client_memory_used; |
367 |
michael |
1127 |
sendto_one(source_p, ":%s %d %s z :Remote client Memory in use: %u(%llu)", |
368 |
adx |
30 |
me.name, RPL_STATSDEBUG, source_p->name, remote_client_count, |
369 |
|
|
remote_client_memory_used); |
370 |
|
|
|
371 |
|
|
block_heap_report_stats(source_p); |
372 |
|
|
|
373 |
|
|
sendto_one(source_p, |
374 |
michael |
948 |
":%s %d %s z :TOTAL: %llu", |
375 |
adx |
30 |
me.name, RPL_STATSDEBUG, source_p->name, |
376 |
michael |
948 |
total_memory); |
377 |
adx |
30 |
} |
378 |
|
|
|
379 |
|
|
static void |
380 |
|
|
stats_dns_servers(struct Client *source_p) |
381 |
|
|
{ |
382 |
|
|
report_dns_servers(source_p); |
383 |
|
|
} |
384 |
|
|
|
385 |
|
|
static void |
386 |
michael |
1457 |
stats_connect(struct Client *source_p, int parc, char *parv[]) |
387 |
adx |
30 |
{ |
388 |
michael |
1368 |
report_confitem_types(source_p, SERVER_TYPE); |
389 |
adx |
30 |
} |
390 |
|
|
|
391 |
|
|
/* stats_deny() |
392 |
|
|
* |
393 |
|
|
* input - client to report to |
394 |
|
|
* output - none |
395 |
|
|
* side effects - client is given dline list. |
396 |
|
|
*/ |
397 |
|
|
static void |
398 |
michael |
1457 |
stats_deny(struct Client *source_p, int parc, char *parv[]) |
399 |
adx |
30 |
{ |
400 |
|
|
struct ConfItem *conf; |
401 |
|
|
struct AccessItem *aconf; |
402 |
michael |
1367 |
dlink_node *ptr = NULL; |
403 |
|
|
unsigned int i = 0; |
404 |
adx |
30 |
|
405 |
michael |
1367 |
|
406 |
|
|
for (i = 0; i < ATABLE_SIZE; ++i) |
407 |
adx |
30 |
{ |
408 |
michael |
1367 |
DLINK_FOREACH(ptr, atable[i].head) |
409 |
adx |
30 |
{ |
410 |
michael |
1367 |
struct AddressRec *arec = ptr->data; |
411 |
|
|
|
412 |
adx |
30 |
if (arec->type == CONF_DLINE) |
413 |
|
|
{ |
414 |
|
|
aconf = arec->aconf; |
415 |
|
|
|
416 |
|
|
/* dont report a tdline as a dline */ |
417 |
|
|
if (aconf->flags & CONF_FLAGS_TEMPORARY) |
418 |
|
|
continue; |
419 |
|
|
|
420 |
|
|
conf = unmap_conf_item(aconf); |
421 |
|
|
|
422 |
|
|
sendto_one(source_p, form_str(RPL_STATSDLINE), |
423 |
|
|
from, to, 'D', aconf->host, aconf->reason, |
424 |
|
|
aconf->oper_reason); |
425 |
|
|
} |
426 |
|
|
} |
427 |
|
|
} |
428 |
|
|
} |
429 |
|
|
|
430 |
|
|
/* stats_tdeny() |
431 |
|
|
* |
432 |
|
|
* input - client to report to |
433 |
|
|
* output - none |
434 |
|
|
* side effects - client is given dline list. |
435 |
|
|
*/ |
436 |
|
|
static void |
437 |
michael |
1457 |
stats_tdeny(struct Client *source_p, int parc, char *parv[]) |
438 |
adx |
30 |
{ |
439 |
|
|
struct ConfItem *conf; |
440 |
|
|
struct AccessItem *aconf; |
441 |
michael |
1367 |
dlink_node *ptr = NULL; |
442 |
|
|
unsigned int i = 0; |
443 |
adx |
30 |
|
444 |
michael |
1367 |
|
445 |
|
|
for (i = 0; i < ATABLE_SIZE; ++i) |
446 |
adx |
30 |
{ |
447 |
michael |
1367 |
DLINK_FOREACH(ptr, atable[i].head) |
448 |
adx |
30 |
{ |
449 |
michael |
1367 |
struct AddressRec *arec = ptr->data; |
450 |
|
|
|
451 |
adx |
30 |
if (arec->type == CONF_DLINE) |
452 |
|
|
{ |
453 |
|
|
aconf = arec->aconf; |
454 |
|
|
|
455 |
|
|
/* dont report a permanent dline as a tdline */ |
456 |
|
|
if (!(aconf->flags & CONF_FLAGS_TEMPORARY)) |
457 |
|
|
continue; |
458 |
|
|
|
459 |
|
|
conf = unmap_conf_item(aconf); |
460 |
|
|
|
461 |
|
|
sendto_one(source_p, form_str(RPL_STATSDLINE), |
462 |
|
|
from, to, 'd', aconf->host, aconf->reason, |
463 |
|
|
aconf->oper_reason); |
464 |
|
|
} |
465 |
|
|
} |
466 |
|
|
} |
467 |
|
|
} |
468 |
|
|
|
469 |
|
|
/* stats_exempt() |
470 |
|
|
* |
471 |
|
|
* input - client to report to |
472 |
|
|
* output - none |
473 |
|
|
* side effects - client is given list of exempt blocks |
474 |
|
|
*/ |
475 |
|
|
static void |
476 |
michael |
1457 |
stats_exempt(struct Client *source_p, int parc, char *parv[]) |
477 |
adx |
30 |
{ |
478 |
|
|
struct ConfItem *conf; |
479 |
|
|
struct AccessItem *aconf; |
480 |
michael |
1367 |
dlink_node *ptr = NULL; |
481 |
|
|
unsigned int i = 0; |
482 |
adx |
30 |
|
483 |
michael |
584 |
if (ConfigFileEntry.stats_e_disabled) |
484 |
|
|
{ |
485 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
486 |
|
|
from, to); |
487 |
|
|
return; |
488 |
|
|
} |
489 |
|
|
|
490 |
michael |
1367 |
|
491 |
|
|
for (i = 0; i < ATABLE_SIZE; ++i) |
492 |
adx |
30 |
{ |
493 |
michael |
1367 |
DLINK_FOREACH(ptr, atable[i].head) |
494 |
adx |
30 |
{ |
495 |
michael |
1367 |
struct AddressRec *arec = ptr->data; |
496 |
|
|
|
497 |
adx |
30 |
if (arec->type == CONF_EXEMPTDLINE) |
498 |
|
|
{ |
499 |
|
|
aconf = arec->aconf; |
500 |
|
|
|
501 |
|
|
conf = unmap_conf_item(aconf); |
502 |
|
|
|
503 |
|
|
sendto_one(source_p, form_str(RPL_STATSDLINE), |
504 |
|
|
from, to, 'e', aconf->host, |
505 |
|
|
aconf->reason, aconf->oper_reason); |
506 |
|
|
} |
507 |
|
|
} |
508 |
|
|
} |
509 |
|
|
} |
510 |
|
|
|
511 |
|
|
static void |
512 |
michael |
1457 |
stats_events(struct Client *source_p, int parc, char *parv[]) |
513 |
adx |
30 |
{ |
514 |
|
|
show_events(source_p); |
515 |
|
|
} |
516 |
|
|
|
517 |
|
|
/* stats_pending_glines() |
518 |
|
|
* |
519 |
|
|
* input - client pointer |
520 |
|
|
* output - none |
521 |
|
|
* side effects - client is shown list of pending glines |
522 |
|
|
*/ |
523 |
|
|
static void |
524 |
michael |
1457 |
stats_pending_glines(struct Client *source_p, int parc, char *parv[]) |
525 |
adx |
30 |
{ |
526 |
michael |
958 |
const dlink_node *dn_ptr = NULL; |
527 |
michael |
988 |
const struct gline_pending *glp_ptr = NULL; |
528 |
michael |
958 |
char timebuffer[MAX_DATE_STRING] = { '\0' }; |
529 |
|
|
struct tm *tmptr = NULL; |
530 |
adx |
30 |
|
531 |
|
|
if (!ConfigFileEntry.glines) |
532 |
|
|
{ |
533 |
|
|
sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines", |
534 |
|
|
from, to); |
535 |
|
|
return; |
536 |
|
|
} |
537 |
|
|
|
538 |
michael |
958 |
if (dlink_list_length(&pending_glines[GLINE_PENDING_ADD_TYPE]) > 0) |
539 |
adx |
30 |
sendto_one(source_p, ":%s NOTICE %s :Pending G-lines", |
540 |
|
|
from, to); |
541 |
|
|
|
542 |
michael |
958 |
DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_ADD_TYPE].head) |
543 |
adx |
30 |
{ |
544 |
michael |
958 |
glp_ptr = dn_ptr->data; |
545 |
|
|
tmptr = localtime(&glp_ptr->vote_1.time_request); |
546 |
adx |
30 |
strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr); |
547 |
|
|
|
548 |
|
|
sendto_one(source_p, |
549 |
|
|
":%s NOTICE %s :1) %s!%s@%s on %s requested gline at %s for %s@%s [%s]", |
550 |
michael |
958 |
from, to, glp_ptr->vote_1.oper_nick, |
551 |
|
|
glp_ptr->vote_1.oper_user, glp_ptr->vote_1.oper_host, |
552 |
|
|
glp_ptr->vote_1.oper_server, timebuffer, |
553 |
|
|
glp_ptr->user, glp_ptr->host, glp_ptr->vote_1.reason); |
554 |
adx |
30 |
|
555 |
michael |
988 |
if (glp_ptr->vote_2.oper_nick[0] != '\0') |
556 |
adx |
30 |
{ |
557 |
michael |
958 |
tmptr = localtime(&glp_ptr->vote_2.time_request); |
558 |
adx |
30 |
strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr); |
559 |
|
|
sendto_one(source_p, |
560 |
|
|
":%s NOTICE %s :2) %s!%s@%s on %s requested gline at %s for %s@%s [%s]", |
561 |
michael |
958 |
from, to, glp_ptr->vote_2.oper_nick, |
562 |
|
|
glp_ptr->vote_2.oper_user, glp_ptr->vote_2.oper_host, |
563 |
|
|
glp_ptr->vote_2.oper_server, timebuffer, |
564 |
|
|
glp_ptr->user, glp_ptr->host, glp_ptr->vote_2.reason); |
565 |
adx |
30 |
} |
566 |
|
|
} |
567 |
|
|
|
568 |
|
|
sendto_one(source_p, ":%s NOTICE %s :End of Pending G-lines", |
569 |
|
|
from, to); |
570 |
michael |
958 |
|
571 |
|
|
if (dlink_list_length(&pending_glines[GLINE_PENDING_DEL_TYPE]) > 0) |
572 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Pending UNG-lines", |
573 |
|
|
from, to); |
574 |
|
|
|
575 |
|
|
DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_DEL_TYPE].head) |
576 |
|
|
{ |
577 |
|
|
glp_ptr = dn_ptr->data; |
578 |
|
|
tmptr = localtime(&glp_ptr->vote_1.time_request); |
579 |
|
|
strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr); |
580 |
|
|
|
581 |
|
|
sendto_one(source_p, |
582 |
|
|
":%s NOTICE %s :1) %s!%s@%s on %s requested ungline at %s for %s@%s [%s]", |
583 |
|
|
from, to, glp_ptr->vote_1.oper_nick, |
584 |
|
|
glp_ptr->vote_1.oper_user, glp_ptr->vote_1.oper_host, |
585 |
|
|
glp_ptr->vote_1.oper_server, timebuffer, |
586 |
|
|
glp_ptr->user, glp_ptr->host, glp_ptr->vote_1.reason); |
587 |
|
|
|
588 |
michael |
988 |
if (glp_ptr->vote_2.oper_nick[0] != '\0') |
589 |
michael |
958 |
{ |
590 |
|
|
tmptr = localtime(&glp_ptr->vote_2.time_request); |
591 |
|
|
strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr); |
592 |
|
|
sendto_one(source_p, |
593 |
|
|
":%s NOTICE %s :2) %s!%s@%s on %s requested ungline at %s for %s@%s [%s]", |
594 |
|
|
from, to, glp_ptr->vote_2.oper_nick, |
595 |
|
|
glp_ptr->vote_2.oper_user, glp_ptr->vote_2.oper_host, |
596 |
|
|
glp_ptr->vote_2.oper_server, timebuffer, |
597 |
|
|
glp_ptr->user, glp_ptr->host, glp_ptr->vote_2.reason); |
598 |
|
|
|
599 |
|
|
} |
600 |
|
|
} |
601 |
|
|
|
602 |
|
|
sendto_one(source_p, ":%s NOTICE %s :End of Pending UNG-lines", |
603 |
|
|
from, to); |
604 |
adx |
30 |
} |
605 |
|
|
|
606 |
|
|
/* stats_glines() |
607 |
|
|
* |
608 |
|
|
* input - client pointer |
609 |
|
|
* output - none |
610 |
|
|
* side effects - client is shown list of glines |
611 |
|
|
*/ |
612 |
|
|
static void |
613 |
michael |
1457 |
stats_glines(struct Client *source_p, int parc, char *parv[]) |
614 |
adx |
30 |
{ |
615 |
michael |
1367 |
dlink_node *ptr = NULL; |
616 |
|
|
unsigned int i = 0; |
617 |
adx |
30 |
|
618 |
|
|
if (!ConfigFileEntry.glines) |
619 |
|
|
{ |
620 |
|
|
sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines", |
621 |
|
|
from, to); |
622 |
|
|
return; |
623 |
|
|
} |
624 |
|
|
|
625 |
michael |
1367 |
for (i = 0; i < ATABLE_SIZE; ++i) |
626 |
adx |
30 |
{ |
627 |
michael |
1367 |
DLINK_FOREACH(ptr, atable[i].head) |
628 |
adx |
30 |
{ |
629 |
michael |
1376 |
const struct AddressRec *arec = ptr->data; |
630 |
michael |
1367 |
|
631 |
adx |
30 |
if (arec->type == CONF_GLINE) |
632 |
|
|
{ |
633 |
|
|
const struct AccessItem *aconf = arec->aconf; |
634 |
|
|
|
635 |
|
|
sendto_one(source_p, form_str(RPL_STATSKLINE), |
636 |
|
|
from, to, "G", |
637 |
|
|
aconf->host ? aconf->host : "*", |
638 |
|
|
aconf->user ? aconf->user : "*", |
639 |
|
|
aconf->reason ? aconf->reason : "No reason", "" ); |
640 |
|
|
} |
641 |
|
|
} |
642 |
|
|
} |
643 |
|
|
} |
644 |
|
|
|
645 |
|
|
static void |
646 |
michael |
1457 |
stats_hubleaf(struct Client *source_p, int parc, char *parv[]) |
647 |
adx |
30 |
{ |
648 |
michael |
1368 |
report_confitem_types(source_p, HUB_TYPE); |
649 |
|
|
report_confitem_types(source_p, LEAF_TYPE); |
650 |
adx |
30 |
} |
651 |
|
|
|
652 |
michael |
1372 |
/* |
653 |
|
|
* show_iline_prefix() |
654 |
|
|
* |
655 |
|
|
* inputs - pointer to struct Client requesting output |
656 |
|
|
* - pointer to struct AccessItem |
657 |
|
|
* - name to which iline prefix will be prefixed to |
658 |
|
|
* output - pointer to static string with prefixes listed in ascii form |
659 |
|
|
* side effects - NONE |
660 |
|
|
*/ |
661 |
|
|
static const char * |
662 |
|
|
show_iline_prefix(struct Client *sptr, struct AccessItem *aconf, const char *name) |
663 |
|
|
{ |
664 |
|
|
static char prefix_of_host[USERLEN + 14]; |
665 |
|
|
char *prefix_ptr = prefix_of_host; |
666 |
|
|
|
667 |
|
|
if (IsNoTilde(aconf)) |
668 |
|
|
*prefix_ptr++ = '-'; |
669 |
|
|
if (IsLimitIp(aconf)) |
670 |
|
|
*prefix_ptr++ = '!'; |
671 |
|
|
if (IsNeedIdentd(aconf)) |
672 |
|
|
*prefix_ptr++ = '+'; |
673 |
|
|
if (!IsNeedPassword(aconf)) |
674 |
|
|
*prefix_ptr++ = '&'; |
675 |
|
|
if (IsConfExemptResv(aconf)) |
676 |
|
|
*prefix_ptr++ = '$'; |
677 |
|
|
if (IsNoMatchIp(aconf)) |
678 |
|
|
*prefix_ptr++ = '%'; |
679 |
|
|
if (IsConfDoSpoofIp(aconf)) |
680 |
|
|
*prefix_ptr++ = '='; |
681 |
|
|
if (MyOper(sptr) && IsConfExemptKline(aconf)) |
682 |
|
|
*prefix_ptr++ = '^'; |
683 |
|
|
if (MyOper(sptr) && IsConfExemptGline(aconf)) |
684 |
|
|
*prefix_ptr++ = '_'; |
685 |
|
|
if (MyOper(sptr) && IsConfExemptLimits(aconf)) |
686 |
|
|
*prefix_ptr++ = '>'; |
687 |
|
|
if (IsConfCanFlood(aconf)) |
688 |
|
|
*prefix_ptr++ = '|'; |
689 |
|
|
|
690 |
|
|
strlcpy(prefix_ptr, name, USERLEN+1); |
691 |
|
|
|
692 |
|
|
return prefix_of_host; |
693 |
|
|
} |
694 |
|
|
|
695 |
adx |
30 |
static void |
696 |
michael |
1457 |
report_auth(struct Client *client_p, int parc, char *parv[]) |
697 |
michael |
1372 |
{ |
698 |
|
|
struct ConfItem *conf; |
699 |
|
|
struct AccessItem *aconf; |
700 |
|
|
dlink_node *ptr = NULL; |
701 |
|
|
unsigned int i; |
702 |
|
|
|
703 |
|
|
|
704 |
|
|
for (i = 0; i < ATABLE_SIZE; ++i) |
705 |
|
|
{ |
706 |
|
|
DLINK_FOREACH(ptr, atable[i].head) |
707 |
|
|
{ |
708 |
|
|
struct AddressRec *arec = ptr->data; |
709 |
|
|
|
710 |
|
|
if (arec->type == CONF_CLIENT) |
711 |
|
|
{ |
712 |
|
|
aconf = arec->aconf; |
713 |
|
|
|
714 |
|
|
if (!MyOper(client_p) && IsConfDoSpoofIp(aconf)) |
715 |
|
|
continue; |
716 |
|
|
|
717 |
|
|
conf = unmap_conf_item(aconf); |
718 |
|
|
|
719 |
|
|
/* We are doing a partial list, based on what matches the u@h of the |
720 |
|
|
* sender, so prepare the strings for comparing --fl_ |
721 |
|
|
*/ |
722 |
|
|
if (ConfigFileEntry.hide_spoof_ips) |
723 |
|
|
sendto_one(client_p, form_str(RPL_STATSILINE), me.name, |
724 |
|
|
client_p->name, 'I', |
725 |
|
|
conf->name == NULL ? "*" : conf->name, |
726 |
|
|
show_iline_prefix(client_p, aconf, aconf->user), |
727 |
|
|
IsConfDoSpoofIp(aconf) ? "255.255.255.255" : |
728 |
|
|
aconf->host, aconf->port, |
729 |
|
|
aconf->class_ptr ? aconf->class_ptr->name : "<default>"); |
730 |
|
|
|
731 |
|
|
else |
732 |
|
|
sendto_one(client_p, form_str(RPL_STATSILINE), me.name, |
733 |
|
|
client_p->name, 'I', |
734 |
|
|
conf->name == NULL ? "*" : conf->name, |
735 |
|
|
show_iline_prefix(client_p, aconf, aconf->user), |
736 |
|
|
aconf->host, aconf->port, |
737 |
|
|
aconf->class_ptr ? aconf->class_ptr->name : "<default>"); |
738 |
|
|
} |
739 |
|
|
} |
740 |
|
|
} |
741 |
|
|
} |
742 |
|
|
|
743 |
|
|
static void |
744 |
michael |
1457 |
stats_auth(struct Client *source_p, int parc, char *parv[]) |
745 |
adx |
30 |
{ |
746 |
|
|
/* Oper only, if unopered, return ERR_NOPRIVILEGES */ |
747 |
michael |
1219 |
if ((ConfigFileEntry.stats_i_oper_only == 2) && !HasUMode(source_p, UMODE_OPER)) |
748 |
adx |
30 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
749 |
|
|
from, to); |
750 |
|
|
|
751 |
|
|
/* If unopered, Only return matching auth blocks */ |
752 |
michael |
1219 |
else if ((ConfigFileEntry.stats_i_oper_only == 1) && !HasUMode(source_p, UMODE_OPER)) |
753 |
adx |
30 |
{ |
754 |
|
|
struct ConfItem *conf; |
755 |
|
|
struct AccessItem *aconf; |
756 |
|
|
|
757 |
|
|
if (MyConnect(source_p)) |
758 |
|
|
aconf = find_conf_by_address(source_p->host, |
759 |
|
|
&source_p->localClient->ip, |
760 |
|
|
CONF_CLIENT, |
761 |
|
|
source_p->localClient->aftype, |
762 |
|
|
source_p->username, |
763 |
michael |
1371 |
source_p->localClient->passwd, 1); |
764 |
adx |
30 |
else |
765 |
|
|
aconf = find_conf_by_address(source_p->host, NULL, CONF_CLIENT, |
766 |
michael |
1371 |
0, source_p->username, NULL, 1); |
767 |
adx |
30 |
|
768 |
|
|
if (aconf == NULL) |
769 |
|
|
return; |
770 |
|
|
|
771 |
|
|
conf = unmap_conf_item(aconf); |
772 |
|
|
|
773 |
|
|
sendto_one(source_p, form_str(RPL_STATSILINE), from, |
774 |
|
|
to, 'I', |
775 |
|
|
"*", show_iline_prefix(source_p, aconf, aconf->user), |
776 |
|
|
aconf->host, aconf->port, |
777 |
|
|
aconf->class_ptr ? aconf->class_ptr->name : "<default>"); |
778 |
|
|
} |
779 |
|
|
/* They are opered, or allowed to see all auth blocks */ |
780 |
|
|
else |
781 |
michael |
1457 |
report_auth(source_p, 0, NULL); |
782 |
adx |
30 |
} |
783 |
|
|
|
784 |
michael |
1372 |
/* report_Klines() |
785 |
|
|
* Inputs: Client to report to, |
786 |
|
|
* type(==0 for perm, !=0 for temporary) |
787 |
|
|
* mask |
788 |
|
|
* Output: None |
789 |
|
|
* Side effects: Reports configured K(or k)-lines to client_p. |
790 |
|
|
*/ |
791 |
adx |
30 |
static void |
792 |
michael |
1372 |
report_Klines(struct Client *client_p, int tkline) |
793 |
|
|
{ |
794 |
|
|
struct AccessItem *aconf = NULL; |
795 |
|
|
unsigned int i = 0; |
796 |
|
|
const char *p = NULL; |
797 |
|
|
dlink_node *ptr = NULL; |
798 |
|
|
|
799 |
|
|
if (tkline) |
800 |
|
|
p = "k"; |
801 |
|
|
else |
802 |
|
|
p = "K"; |
803 |
|
|
|
804 |
|
|
for (i = 0; i < ATABLE_SIZE; ++i) |
805 |
|
|
{ |
806 |
|
|
DLINK_FOREACH(ptr, atable[i].head) |
807 |
|
|
{ |
808 |
|
|
struct AddressRec *arec = ptr->data; |
809 |
|
|
|
810 |
|
|
if (arec->type == CONF_KLINE) |
811 |
|
|
{ |
812 |
|
|
if ((tkline && !((aconf = arec->aconf)->flags & CONF_FLAGS_TEMPORARY)) || |
813 |
|
|
(!tkline && ((aconf = arec->aconf)->flags & CONF_FLAGS_TEMPORARY))) |
814 |
|
|
continue; |
815 |
|
|
|
816 |
|
|
if (HasUMode(client_p, UMODE_OPER)) |
817 |
|
|
sendto_one(client_p, form_str(RPL_STATSKLINE), me.name, |
818 |
|
|
client_p->name, p, aconf->host, aconf->user, |
819 |
|
|
aconf->reason, aconf->oper_reason ? aconf->oper_reason : ""); |
820 |
|
|
else |
821 |
|
|
sendto_one(client_p, form_str(RPL_STATSKLINE), me.name, |
822 |
|
|
client_p->name, p, aconf->host, aconf->user, |
823 |
|
|
aconf->reason, ""); |
824 |
|
|
} |
825 |
|
|
} |
826 |
|
|
} |
827 |
|
|
} |
828 |
|
|
|
829 |
|
|
static void |
830 |
michael |
1457 |
stats_tklines(struct Client *source_p, int parc, char *parv[]) |
831 |
adx |
30 |
{ |
832 |
|
|
struct ConfItem *conf; |
833 |
|
|
/* Oper only, if unopered, return ERR_NOPRIVILEGES */ |
834 |
michael |
1219 |
if ((ConfigFileEntry.stats_k_oper_only == 2) && !HasUMode(source_p, UMODE_OPER)) |
835 |
adx |
30 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
836 |
|
|
from, to); |
837 |
|
|
|
838 |
|
|
/* If unopered, Only return matching klines */ |
839 |
michael |
1219 |
else if ((ConfigFileEntry.stats_k_oper_only == 1) && !HasUMode(source_p, UMODE_OPER)) |
840 |
adx |
30 |
{ |
841 |
|
|
struct AccessItem *aconf; |
842 |
|
|
|
843 |
|
|
if (MyConnect(source_p)) |
844 |
|
|
aconf = find_conf_by_address(source_p->host, |
845 |
|
|
&source_p->localClient->ip, |
846 |
michael |
1369 |
CONF_KLINE, |
847 |
adx |
30 |
source_p->localClient->aftype, |
848 |
michael |
1371 |
source_p->username, NULL, 1); |
849 |
adx |
30 |
else |
850 |
michael |
1369 |
aconf = find_conf_by_address(source_p->host, NULL, CONF_KLINE, |
851 |
michael |
1371 |
0, source_p->username, NULL, 1); |
852 |
adx |
30 |
|
853 |
|
|
if (aconf == NULL) |
854 |
|
|
return; |
855 |
|
|
|
856 |
|
|
/* dont report a permanent kline as a tkline */ |
857 |
|
|
if (!(aconf->flags & CONF_FLAGS_TEMPORARY)) |
858 |
|
|
return; |
859 |
|
|
|
860 |
|
|
conf = unmap_conf_item(aconf); |
861 |
|
|
|
862 |
|
|
sendto_one(source_p, form_str(RPL_STATSKLINE), from, |
863 |
|
|
to, "k", aconf->host, aconf->user, aconf->reason, ""); |
864 |
|
|
} |
865 |
|
|
/* Theyre opered, or allowed to see all klines */ |
866 |
|
|
else { |
867 |
|
|
report_Klines(source_p, 1); |
868 |
|
|
} |
869 |
|
|
} |
870 |
|
|
|
871 |
|
|
static void |
872 |
michael |
1457 |
stats_klines(struct Client *source_p, int parc, char *parv[]) |
873 |
adx |
30 |
{ |
874 |
|
|
/* Oper only, if unopered, return ERR_NOPRIVILEGES */ |
875 |
michael |
1219 |
if ((ConfigFileEntry.stats_k_oper_only == 2) && !HasUMode(source_p, UMODE_OPER)) |
876 |
adx |
30 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
877 |
|
|
from, to); |
878 |
|
|
|
879 |
|
|
/* If unopered, Only return matching klines */ |
880 |
michael |
1219 |
else if ((ConfigFileEntry.stats_k_oper_only == 1) && !HasUMode(source_p, UMODE_OPER)) |
881 |
adx |
30 |
{ |
882 |
|
|
struct AccessItem *aconf; |
883 |
|
|
|
884 |
|
|
/* search for a kline */ |
885 |
michael |
560 |
if (MyConnect(source_p)) |
886 |
adx |
30 |
aconf = find_conf_by_address(source_p->host, |
887 |
|
|
&source_p->localClient->ip, |
888 |
michael |
1369 |
CONF_KLINE, |
889 |
adx |
30 |
source_p->localClient->aftype, |
890 |
michael |
1371 |
source_p->username, NULL, 0); |
891 |
adx |
30 |
else |
892 |
michael |
1369 |
aconf = find_conf_by_address(source_p->host, NULL, CONF_KLINE, |
893 |
michael |
1371 |
0, source_p->username, NULL, 0); |
894 |
adx |
30 |
|
895 |
michael |
560 |
if (aconf == NULL) |
896 |
adx |
30 |
return; |
897 |
|
|
|
898 |
|
|
/* dont report a tkline as a kline */ |
899 |
michael |
560 |
if (aconf->flags & CONF_FLAGS_TEMPORARY) |
900 |
adx |
30 |
return; |
901 |
|
|
|
902 |
|
|
sendto_one(source_p, form_str(RPL_STATSKLINE), from, |
903 |
|
|
to, "K", aconf->host, aconf->user, aconf->reason, |
904 |
|
|
aconf->oper_reason); |
905 |
|
|
} |
906 |
|
|
/* Theyre opered, or allowed to see all klines */ |
907 |
|
|
else { |
908 |
|
|
report_Klines(source_p, 0); |
909 |
michael |
1368 |
report_confitem_types(source_p, RKLINE_TYPE); |
910 |
adx |
30 |
} |
911 |
|
|
} |
912 |
|
|
|
913 |
|
|
static void |
914 |
michael |
1457 |
stats_messages(struct Client *source_p, int parc, char *parv[]) |
915 |
adx |
30 |
{ |
916 |
|
|
report_messages(source_p); |
917 |
|
|
} |
918 |
|
|
|
919 |
|
|
static void |
920 |
michael |
1457 |
stats_oper(struct Client *source_p, int parc, char *parv[]) |
921 |
adx |
30 |
{ |
922 |
michael |
1219 |
if (!HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.stats_o_oper_only) |
923 |
adx |
30 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
924 |
|
|
from, to); |
925 |
|
|
else |
926 |
michael |
1368 |
report_confitem_types(source_p, OPER_TYPE); |
927 |
adx |
30 |
} |
928 |
|
|
|
929 |
|
|
/* stats_operedup() |
930 |
|
|
* |
931 |
|
|
* input - client pointer |
932 |
|
|
* output - none |
933 |
|
|
* side effects - client is shown a list of active opers |
934 |
|
|
*/ |
935 |
|
|
static void |
936 |
michael |
1457 |
stats_operedup(struct Client *source_p, int parc, char *parv[]) |
937 |
adx |
30 |
{ |
938 |
|
|
dlink_node *ptr; |
939 |
|
|
|
940 |
|
|
DLINK_FOREACH(ptr, oper_list.head) |
941 |
|
|
{ |
942 |
|
|
const struct Client *target_p = ptr->data; |
943 |
|
|
|
944 |
michael |
1294 |
if (HasUMode(target_p, UMODE_HIDDEN) && !HasUMode(source_p, UMODE_OPER)) |
945 |
adx |
30 |
continue; |
946 |
|
|
|
947 |
michael |
1219 |
if (MyClient(source_p) && HasUMode(source_p, UMODE_OPER)) |
948 |
adx |
30 |
sendto_one(source_p, ":%s %d %s p :[%c][%s] %s (%s@%s) Idle: %d", |
949 |
|
|
from, RPL_STATSDEBUG, to, |
950 |
michael |
1294 |
HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O', |
951 |
adx |
30 |
oper_privs_as_string(target_p->localClient->operflags), |
952 |
|
|
target_p->name, target_p->username, target_p->host, |
953 |
michael |
1176 |
(int)(CurrentTime - target_p->localClient->last_privmsg)); |
954 |
adx |
30 |
else |
955 |
|
|
sendto_one(source_p, ":%s %d %s p :[%c] %s (%s@%s) Idle: %d", |
956 |
|
|
from, RPL_STATSDEBUG, to, |
957 |
michael |
1294 |
HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O', |
958 |
adx |
30 |
target_p->name, target_p->username, target_p->host, |
959 |
michael |
1176 |
(int)(CurrentTime - target_p->localClient->last_privmsg)); |
960 |
adx |
30 |
} |
961 |
|
|
|
962 |
|
|
sendto_one(source_p, ":%s %d %s p :%lu OPER(s)", |
963 |
|
|
from, RPL_STATSDEBUG, to, dlink_list_length(&oper_list)); |
964 |
|
|
} |
965 |
|
|
|
966 |
|
|
static void |
967 |
michael |
1457 |
stats_ports(struct Client *source_p, int parc, char *parv[]) |
968 |
adx |
30 |
{ |
969 |
michael |
1219 |
if (!HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.stats_P_oper_only) |
970 |
adx |
30 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
971 |
|
|
from, to); |
972 |
|
|
else |
973 |
|
|
show_ports(source_p); |
974 |
|
|
} |
975 |
|
|
|
976 |
|
|
static void |
977 |
michael |
1457 |
stats_resv(struct Client *source_p, int parc, char *parv[]) |
978 |
adx |
30 |
{ |
979 |
|
|
report_resv(source_p); |
980 |
|
|
} |
981 |
|
|
|
982 |
|
|
static void |
983 |
michael |
1457 |
stats_service(struct Client *source_p, int parc, char *parv[]) |
984 |
adx |
30 |
{ |
985 |
michael |
1368 |
report_confitem_types(source_p, SERVICE_TYPE); |
986 |
michael |
1175 |
} |
987 |
|
|
|
988 |
|
|
static void |
989 |
michael |
1457 |
stats_tstats(struct Client *source_p, int parc, char *parv[]) |
990 |
adx |
30 |
{ |
991 |
michael |
896 |
const struct Client *target_p = NULL; |
992 |
|
|
const dlink_node *ptr = NULL; |
993 |
|
|
struct ServerStatistics *sp; |
994 |
|
|
struct ServerStatistics tmp; |
995 |
|
|
|
996 |
|
|
sp = &tmp; |
997 |
|
|
memcpy(sp, &ServerStats, sizeof(struct ServerStatistics)); |
998 |
|
|
|
999 |
|
|
/* |
1000 |
|
|
* must use the += operator. is_sv is not the number of currently |
1001 |
|
|
* active server connections. Note the incrementation in |
1002 |
|
|
* s_bsd.c:close_connection. |
1003 |
|
|
*/ |
1004 |
|
|
sp->is_sv += dlink_list_length(&serv_list); |
1005 |
|
|
|
1006 |
|
|
DLINK_FOREACH(ptr, serv_list.head) |
1007 |
|
|
{ |
1008 |
|
|
target_p = ptr->data; |
1009 |
|
|
|
1010 |
|
|
sp->is_sbs += target_p->localClient->send.bytes; |
1011 |
|
|
sp->is_sbr += target_p->localClient->recv.bytes; |
1012 |
michael |
1241 |
sp->is_sti += CurrentTime - target_p->localClient->firsttime; |
1013 |
michael |
896 |
} |
1014 |
|
|
|
1015 |
|
|
sp->is_cl += dlink_list_length(&local_client_list); |
1016 |
|
|
|
1017 |
|
|
DLINK_FOREACH(ptr, local_client_list.head) |
1018 |
|
|
{ |
1019 |
|
|
target_p = ptr->data; |
1020 |
|
|
|
1021 |
|
|
sp->is_cbs += target_p->localClient->send.bytes; |
1022 |
|
|
sp->is_cbr += target_p->localClient->recv.bytes; |
1023 |
michael |
1241 |
sp->is_cti += CurrentTime - target_p->localClient->firsttime; |
1024 |
michael |
896 |
} |
1025 |
|
|
|
1026 |
|
|
sp->is_ni += dlink_list_length(&unknown_list); |
1027 |
|
|
|
1028 |
|
|
sendto_one(source_p, ":%s %d %s T :accepts %u refused %u", |
1029 |
|
|
me.name, RPL_STATSDEBUG, source_p->name, sp->is_ac, sp->is_ref); |
1030 |
|
|
sendto_one(source_p, ":%s %d %s T :unknown commands %u prefixes %u", |
1031 |
|
|
me.name, RPL_STATSDEBUG, source_p->name, sp->is_unco, sp->is_unpf); |
1032 |
|
|
sendto_one(source_p, ":%s %d %s T :nick collisions %u unknown closes %u", |
1033 |
|
|
me.name, RPL_STATSDEBUG, source_p->name, sp->is_kill, sp->is_ni); |
1034 |
|
|
sendto_one(source_p, ":%s %d %s T :wrong direction %u empty %u", |
1035 |
|
|
me.name, RPL_STATSDEBUG, source_p->name, sp->is_wrdi, sp->is_empt); |
1036 |
|
|
sendto_one(source_p, ":%s %d %s T :numerics seen %u", |
1037 |
|
|
me.name, RPL_STATSDEBUG, source_p->name, sp->is_num); |
1038 |
|
|
sendto_one(source_p, ":%s %d %s T :auth successes %u fails %u", |
1039 |
|
|
me.name, RPL_STATSDEBUG, source_p->name, sp->is_asuc, sp->is_abad); |
1040 |
|
|
sendto_one(source_p, ":%s %d %s T :Client Server", |
1041 |
|
|
me.name, RPL_STATSDEBUG, source_p->name); |
1042 |
|
|
|
1043 |
|
|
sendto_one(source_p, ":%s %d %s T :connected %u %u", |
1044 |
|
|
me.name, RPL_STATSDEBUG, source_p->name, |
1045 |
|
|
(unsigned int)sp->is_cl, |
1046 |
|
|
(unsigned int)sp->is_sv); |
1047 |
|
|
sendto_one(source_p, ":%s %d %s T :bytes sent %llu %llu", |
1048 |
|
|
me.name, RPL_STATSDEBUG, source_p->name, |
1049 |
|
|
sp->is_cbs, sp->is_sbs); |
1050 |
|
|
sendto_one(source_p, ":%s %d %s T :bytes recv %llu %llu", |
1051 |
|
|
me.name, RPL_STATSDEBUG, source_p->name, |
1052 |
|
|
sp->is_cbr, sp->is_sbr); |
1053 |
|
|
sendto_one(source_p, ":%s %d %s T :time connected %u %u", |
1054 |
|
|
me.name, RPL_STATSDEBUG, source_p->name, |
1055 |
|
|
(unsigned int)sp->is_cti, |
1056 |
|
|
(unsigned int)sp->is_sti); |
1057 |
adx |
30 |
} |
1058 |
|
|
|
1059 |
|
|
static void |
1060 |
michael |
1457 |
stats_uptime(struct Client *source_p, int parc, char *parv[]) |
1061 |
adx |
30 |
{ |
1062 |
michael |
1241 |
time_t now = CurrentTime - me.localClient->since; |
1063 |
michael |
1148 |
|
1064 |
adx |
30 |
sendto_one(source_p, form_str(RPL_STATSUPTIME), from, to, |
1065 |
michael |
1148 |
now / 86400, (now / 3600) % 24, (now / 60) % 60, now % 60); |
1066 |
|
|
|
1067 |
michael |
1219 |
if (!ConfigFileEntry.disable_remote || HasUMode(source_p, UMODE_OPER)) |
1068 |
adx |
30 |
sendto_one(source_p, form_str(RPL_STATSCONN), from, to, |
1069 |
michael |
1148 |
Count.max_loc_con, Count.max_loc_cli, Count.totalrestartcount); |
1070 |
adx |
30 |
} |
1071 |
|
|
|
1072 |
|
|
static void |
1073 |
michael |
1457 |
stats_shared(struct Client *source_p, int parc, char *parv[]) |
1074 |
adx |
30 |
{ |
1075 |
michael |
1368 |
report_confitem_types(source_p, ULINE_TYPE); |
1076 |
adx |
30 |
} |
1077 |
|
|
|
1078 |
|
|
/* stats_servers() |
1079 |
|
|
* |
1080 |
|
|
* input - client pointer |
1081 |
|
|
* output - none |
1082 |
|
|
* side effects - client is shown lists of who connected servers |
1083 |
|
|
*/ |
1084 |
|
|
static void |
1085 |
michael |
1457 |
stats_servers(struct Client *source_p, int parc, char *parv[]) |
1086 |
adx |
30 |
{ |
1087 |
michael |
1127 |
dlink_node *ptr = NULL; |
1088 |
adx |
30 |
|
1089 |
|
|
DLINK_FOREACH(ptr, serv_list.head) |
1090 |
|
|
{ |
1091 |
michael |
1127 |
const struct Client *target_p = ptr->data; |
1092 |
adx |
30 |
|
1093 |
|
|
sendto_one(source_p, ":%s %d %s v :%s (%s!%s@%s) Idle: %d", |
1094 |
michael |
1127 |
from, RPL_STATSDEBUG, to, target_p->name, |
1095 |
|
|
(target_p->serv->by[0] ? target_p->serv->by : "Remote."), |
1096 |
michael |
1241 |
"*", "*", (int)(CurrentTime - target_p->localClient->lasttime)); |
1097 |
adx |
30 |
} |
1098 |
|
|
|
1099 |
michael |
1127 |
sendto_one(source_p, ":%s %d %s v :%u Server(s)", |
1100 |
|
|
from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list)); |
1101 |
adx |
30 |
} |
1102 |
|
|
|
1103 |
|
|
static void |
1104 |
michael |
1457 |
stats_gecos(struct Client *source_p, int parc, char *parv[]) |
1105 |
adx |
30 |
{ |
1106 |
michael |
1368 |
report_confitem_types(source_p, XLINE_TYPE); |
1107 |
|
|
report_confitem_types(source_p, RXLINE_TYPE); |
1108 |
adx |
30 |
} |
1109 |
|
|
|
1110 |
|
|
static void |
1111 |
michael |
1457 |
stats_class(struct Client *source_p, int parc, char *parv[]) |
1112 |
adx |
30 |
{ |
1113 |
michael |
1368 |
report_confitem_types(source_p, CLASS_TYPE); |
1114 |
adx |
30 |
} |
1115 |
|
|
|
1116 |
|
|
static void |
1117 |
michael |
1457 |
stats_servlinks(struct Client *source_p, int parc, char *parv[]) |
1118 |
adx |
30 |
{ |
1119 |
|
|
uint64_t sendB = 0, recvB = 0; |
1120 |
|
|
time_t uptime = 0; |
1121 |
michael |
560 |
dlink_node *ptr = NULL; |
1122 |
adx |
30 |
|
1123 |
michael |
1219 |
if (ConfigServerHide.flatten_links && !HasUMode(source_p, UMODE_OPER)) |
1124 |
adx |
30 |
{ |
1125 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
1126 |
|
|
from, to); |
1127 |
|
|
return; |
1128 |
|
|
} |
1129 |
|
|
|
1130 |
|
|
DLINK_FOREACH(ptr, serv_list.head) |
1131 |
|
|
{ |
1132 |
michael |
560 |
struct Client *target_p = ptr->data; |
1133 |
adx |
30 |
|
1134 |
|
|
sendB += target_p->localClient->send.bytes; |
1135 |
|
|
recvB += target_p->localClient->recv.bytes; |
1136 |
|
|
|
1137 |
|
|
/* ":%s 211 %s %s %u %u %llu %u %llu :%u %u %s" */ |
1138 |
|
|
sendto_one(source_p, form_str(RPL_STATSLINKINFO), |
1139 |
|
|
from, to, |
1140 |
michael |
1219 |
get_client_name(target_p, HasUMode(source_p, UMODE_ADMIN) ? SHOW_IP : MASK_IP), |
1141 |
adx |
30 |
dbuf_length(&target_p->localClient->buf_sendq), |
1142 |
|
|
target_p->localClient->send.messages, |
1143 |
|
|
target_p->localClient->send.bytes >> 10, |
1144 |
|
|
target_p->localClient->recv.messages, |
1145 |
|
|
target_p->localClient->recv.bytes >> 10, |
1146 |
michael |
1241 |
(unsigned)(CurrentTime - target_p->localClient->firsttime), |
1147 |
|
|
(CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since): 0, |
1148 |
michael |
1219 |
HasUMode(source_p, UMODE_OPER) ? show_capabilities(target_p) : "TS"); |
1149 |
adx |
30 |
} |
1150 |
|
|
|
1151 |
|
|
sendB >>= 10; |
1152 |
|
|
recvB >>= 10; |
1153 |
|
|
|
1154 |
|
|
sendto_one(source_p, ":%s %d %s ? :%u total server(s)", |
1155 |
michael |
560 |
from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list)); |
1156 |
adx |
30 |
sendto_one(source_p, ":%s %d %s ? :Sent total : %7.2f %s", |
1157 |
|
|
from, RPL_STATSDEBUG, to, |
1158 |
michael |
560 |
_GMKv(sendB), _GMKs(sendB)); |
1159 |
adx |
30 |
sendto_one(source_p, ":%s %d %s ? :Recv total : %7.2f %s", |
1160 |
|
|
from, RPL_STATSDEBUG, to, |
1161 |
michael |
560 |
_GMKv(recvB), _GMKs(recvB)); |
1162 |
adx |
30 |
|
1163 |
michael |
1241 |
uptime = (CurrentTime - me.localClient->since); |
1164 |
adx |
30 |
|
1165 |
|
|
sendto_one(source_p, ":%s %d %s ? :Server send: %7.2f %s (%4.1f K/s)", |
1166 |
|
|
from, RPL_STATSDEBUG, to, |
1167 |
michael |
560 |
_GMKv((me.localClient->send.bytes>>10)), |
1168 |
|
|
_GMKs((me.localClient->send.bytes>>10)), |
1169 |
|
|
(float)((float)((me.localClient->send.bytes) >> 10) / |
1170 |
|
|
(float)uptime)); |
1171 |
adx |
30 |
sendto_one(source_p, ":%s %d %s ? :Server recv: %7.2f %s (%4.1f K/s)", |
1172 |
|
|
from, RPL_STATSDEBUG, to, |
1173 |
michael |
560 |
_GMKv((me.localClient->recv.bytes>>10)), |
1174 |
|
|
_GMKs((me.localClient->recv.bytes>>10)), |
1175 |
|
|
(float)((float)((me.localClient->recv.bytes) >> 10) / |
1176 |
|
|
(float)uptime)); |
1177 |
adx |
30 |
} |
1178 |
|
|
|
1179 |
michael |
1457 |
/* parse_stats_args() |
1180 |
|
|
* |
1181 |
|
|
* inputs - arg count |
1182 |
|
|
* - args |
1183 |
|
|
* - doall flag |
1184 |
|
|
* - wild card or not |
1185 |
|
|
* output - pointer to name to use |
1186 |
|
|
* side effects - |
1187 |
|
|
* common parse routine for m_stats args |
1188 |
|
|
* |
1189 |
|
|
*/ |
1190 |
|
|
static char * |
1191 |
|
|
parse_stats_args(int parc, char *parv[], int *doall, int *wilds) |
1192 |
adx |
30 |
{ |
1193 |
michael |
1457 |
char *name; |
1194 |
adx |
30 |
|
1195 |
michael |
1457 |
if (parc > 2) |
1196 |
adx |
30 |
{ |
1197 |
michael |
1457 |
name = parv[2]; |
1198 |
adx |
30 |
|
1199 |
michael |
1457 |
if (!irccmp(name, from)) |
1200 |
|
|
*doall = 2; |
1201 |
|
|
else if (match(name, from)) |
1202 |
|
|
*doall = 1; |
1203 |
|
|
|
1204 |
|
|
*wilds = has_wildcards(name); |
1205 |
|
|
|
1206 |
|
|
return name; |
1207 |
adx |
30 |
} |
1208 |
|
|
|
1209 |
michael |
1457 |
return NULL; |
1210 |
adx |
30 |
} |
1211 |
|
|
|
1212 |
|
|
static void |
1213 |
|
|
stats_L_list(struct Client *source_p,char *name, int doall, int wilds, |
1214 |
|
|
dlink_list *list,char statchar) |
1215 |
|
|
{ |
1216 |
|
|
dlink_node *ptr; |
1217 |
|
|
struct Client *target_p; |
1218 |
|
|
|
1219 |
|
|
/* |
1220 |
|
|
* send info about connections which match, or all if the |
1221 |
|
|
* mask matches from. Only restrictions are on those who |
1222 |
|
|
* are invisible not being visible to 'foreigners' who use |
1223 |
|
|
* a wild card based search to list it. |
1224 |
|
|
*/ |
1225 |
|
|
DLINK_FOREACH(ptr, list->head) |
1226 |
|
|
{ |
1227 |
|
|
target_p = ptr->data; |
1228 |
|
|
|
1229 |
michael |
1219 |
if (HasUMode(target_p, UMODE_INVISIBLE) && (doall || wilds) && |
1230 |
michael |
1457 |
!(MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) && |
1231 |
|
|
!HasUMode(target_p, UMODE_OPER) && (target_p != source_p)) |
1232 |
adx |
30 |
continue; |
1233 |
|
|
if (!doall && wilds && !match(name, target_p->name)) |
1234 |
|
|
continue; |
1235 |
|
|
if (!(doall || wilds) && irccmp(name, target_p->name)) |
1236 |
|
|
continue; |
1237 |
|
|
|
1238 |
|
|
/* This basically shows ips for our opers if its not a server/admin, or |
1239 |
|
|
* its one of our admins. */ |
1240 |
michael |
1457 |
if(MyClient(source_p) && HasUMode(source_p, UMODE_OPER) && |
1241 |
michael |
1219 |
(HasUMode(source_p, UMODE_ADMIN) || |
1242 |
michael |
1457 |
(!IsServer(target_p) && !HasUMode(target_p, UMODE_ADMIN) && |
1243 |
adx |
30 |
!IsHandshake(target_p) && !IsConnecting(target_p)))) |
1244 |
|
|
{ |
1245 |
|
|
sendto_one(source_p, form_str(RPL_STATSLINKINFO), |
1246 |
michael |
1457 |
from, to, |
1247 |
adx |
30 |
(IsUpper(statchar)) ? |
1248 |
|
|
get_client_name(target_p, SHOW_IP) : |
1249 |
|
|
get_client_name(target_p, HIDE_IP), |
1250 |
|
|
dbuf_length(&target_p->localClient->buf_sendq), |
1251 |
|
|
target_p->localClient->send.messages, |
1252 |
|
|
target_p->localClient->send.bytes>>10, |
1253 |
|
|
target_p->localClient->recv.messages, |
1254 |
|
|
target_p->localClient->recv.bytes>>10, |
1255 |
michael |
1241 |
(unsigned)(CurrentTime - target_p->localClient->firsttime), |
1256 |
|
|
(CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0, |
1257 |
adx |
30 |
IsServer(target_p) ? show_capabilities(target_p) : "-"); |
1258 |
|
|
} |
1259 |
|
|
else |
1260 |
|
|
{ |
1261 |
|
|
/* If its a hidden ip, an admin, or a server, mask the real IP */ |
1262 |
michael |
1219 |
if(IsIPSpoof(target_p) || IsServer(target_p) || HasUMode(target_p, UMODE_ADMIN) |
1263 |
adx |
30 |
|| IsHandshake(target_p) || IsConnecting(target_p)) |
1264 |
|
|
sendto_one(source_p, form_str(RPL_STATSLINKINFO), |
1265 |
|
|
from, to, |
1266 |
michael |
1457 |
get_client_name(target_p, MASK_IP), |
1267 |
|
|
dbuf_length(&target_p->localClient->buf_sendq), |
1268 |
|
|
target_p->localClient->send.messages, |
1269 |
|
|
target_p->localClient->send.bytes>>10, |
1270 |
|
|
target_p->localClient->recv.messages, |
1271 |
|
|
target_p->localClient->recv.bytes>>10, |
1272 |
|
|
(unsigned)(CurrentTime - target_p->localClient->firsttime), |
1273 |
|
|
(CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0, |
1274 |
|
|
IsServer(target_p) ? show_capabilities(target_p) : "-"); |
1275 |
adx |
30 |
else /* show the real IP */ |
1276 |
|
|
sendto_one(source_p, form_str(RPL_STATSLINKINFO), |
1277 |
|
|
from, to, |
1278 |
michael |
1457 |
(IsUpper(statchar)) ? |
1279 |
|
|
get_client_name(target_p, SHOW_IP) : |
1280 |
|
|
get_client_name(target_p, HIDE_IP), |
1281 |
|
|
dbuf_length(&target_p->localClient->buf_sendq), |
1282 |
|
|
target_p->localClient->send.messages, |
1283 |
|
|
target_p->localClient->send.bytes>>10, |
1284 |
|
|
target_p->localClient->recv.messages, |
1285 |
|
|
target_p->localClient->recv.bytes>>10, |
1286 |
|
|
(unsigned)(CurrentTime - target_p->localClient->firsttime), |
1287 |
|
|
(CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0, |
1288 |
|
|
IsServer(target_p) ? show_capabilities(target_p) : "-"); |
1289 |
adx |
30 |
} |
1290 |
|
|
} |
1291 |
|
|
} |
1292 |
|
|
|
1293 |
michael |
1457 |
/* |
1294 |
|
|
* stats_L |
1295 |
adx |
30 |
* |
1296 |
michael |
1457 |
* inputs - pointer to client to report to |
1297 |
|
|
* - doall flag |
1298 |
|
|
* - wild card or not |
1299 |
|
|
* output - NONE |
1300 |
|
|
* side effects - |
1301 |
|
|
*/ |
1302 |
|
|
static void |
1303 |
|
|
stats_L(struct Client *source_p,char *name,int doall, |
1304 |
|
|
int wilds,char statchar) |
1305 |
|
|
{ |
1306 |
|
|
stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar); |
1307 |
|
|
stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar); |
1308 |
|
|
stats_L_list(source_p, name, doall, wilds, &serv_list, statchar); |
1309 |
|
|
} |
1310 |
|
|
|
1311 |
|
|
static void |
1312 |
|
|
stats_ltrace(struct Client *source_p, int parc, char *parv[]) |
1313 |
|
|
{ |
1314 |
|
|
int doall = 0; |
1315 |
|
|
int wilds = 0; |
1316 |
|
|
char *name = NULL; |
1317 |
|
|
char statchar; |
1318 |
|
|
|
1319 |
|
|
if ((name = parse_stats_args(parc, parv, &doall, &wilds)) != NULL) |
1320 |
|
|
{ |
1321 |
|
|
statchar = parv[1][0]; |
1322 |
|
|
|
1323 |
|
|
stats_L(source_p, name, doall, wilds, statchar); |
1324 |
|
|
} |
1325 |
|
|
else |
1326 |
|
|
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
1327 |
|
|
from, to, "STATS"); |
1328 |
|
|
} |
1329 |
|
|
|
1330 |
|
|
static const struct StatsStruct |
1331 |
|
|
{ |
1332 |
|
|
const unsigned char letter; |
1333 |
|
|
void (*handler)(); |
1334 |
|
|
const unsigned int need_oper; |
1335 |
|
|
const unsigned int need_admin; |
1336 |
|
|
} stats_cmd_table[] = { |
1337 |
|
|
/* letter function need_oper need_admin */ |
1338 |
|
|
{ 'a', stats_dns_servers, 1, 1 }, |
1339 |
|
|
{ 'A', stats_dns_servers, 1, 1 }, |
1340 |
|
|
{ 'c', stats_connect, 1, 0 }, |
1341 |
|
|
{ 'C', stats_connect, 1, 0 }, |
1342 |
|
|
{ 'd', stats_tdeny, 1, 0 }, |
1343 |
|
|
{ 'D', stats_deny, 1, 0 }, |
1344 |
|
|
{ 'e', stats_exempt, 1, 0 }, |
1345 |
|
|
{ 'E', stats_events, 1, 1 }, |
1346 |
|
|
{ 'f', fd_dump, 1, 1 }, |
1347 |
|
|
{ 'F', fd_dump, 1, 1 }, |
1348 |
|
|
{ 'g', stats_pending_glines, 1, 0 }, |
1349 |
|
|
{ 'G', stats_glines, 1, 0 }, |
1350 |
|
|
{ 'h', stats_hooks, 1, 1 }, |
1351 |
|
|
{ 'H', stats_hubleaf, 1, 0 }, |
1352 |
|
|
{ 'i', stats_auth, 0, 0 }, |
1353 |
|
|
{ 'I', stats_auth, 0, 0 }, |
1354 |
|
|
{ 'k', stats_tklines, 0, 0 }, |
1355 |
|
|
{ 'K', stats_klines, 0, 0 }, |
1356 |
|
|
{ 'l', stats_ltrace, 1, 0 }, |
1357 |
|
|
{ 'L', stats_ltrace, 1, 0 }, |
1358 |
|
|
{ 'm', stats_messages, 0, 0 }, |
1359 |
|
|
{ 'M', stats_messages, 0, 0 }, |
1360 |
|
|
{ 'o', stats_oper, 0, 0 }, |
1361 |
|
|
{ 'O', stats_oper, 0, 0 }, |
1362 |
|
|
{ 'p', stats_operedup, 0, 0 }, |
1363 |
|
|
{ 'P', stats_ports, 0, 0 }, |
1364 |
|
|
{ 'q', stats_resv, 1, 0 }, |
1365 |
|
|
{ 'Q', stats_resv, 1, 0 }, |
1366 |
|
|
{ 'r', stats_usage, 1, 0 }, |
1367 |
|
|
{ 'R', stats_usage, 1, 0 }, |
1368 |
|
|
{ 'S', stats_service, 1, 0 }, |
1369 |
|
|
{ 't', stats_tstats, 1, 0 }, |
1370 |
|
|
{ 'T', stats_tstats, 1, 0 }, |
1371 |
|
|
{ 'u', stats_uptime, 0, 0 }, |
1372 |
|
|
{ 'U', stats_shared, 1, 0 }, |
1373 |
|
|
{ 'v', stats_servers, 1, 0 }, |
1374 |
|
|
{ 'x', stats_gecos, 1, 0 }, |
1375 |
|
|
{ 'X', stats_gecos, 1, 0 }, |
1376 |
|
|
{ 'y', stats_class, 1, 0 }, |
1377 |
|
|
{ 'Y', stats_class, 1, 0 }, |
1378 |
|
|
{ 'z', stats_memory, 1, 0 }, |
1379 |
|
|
{ '?', stats_servlinks, 0, 0 }, |
1380 |
|
|
{ '\0', NULL, 0, 0 } |
1381 |
|
|
}; |
1382 |
|
|
|
1383 |
|
|
static void |
1384 |
|
|
do_stats(struct Client *source_p, int parc, char *parv[]) |
1385 |
|
|
{ |
1386 |
|
|
const struct StatsStruct *tab = stats_cmd_table; |
1387 |
|
|
const char statchar = *parv[1]; |
1388 |
|
|
|
1389 |
|
|
if (statchar == '\0') |
1390 |
|
|
{ |
1391 |
|
|
sendto_one(source_p, form_str(RPL_ENDOFSTATS), |
1392 |
|
|
from, to, '*'); |
1393 |
|
|
return; |
1394 |
|
|
} |
1395 |
|
|
|
1396 |
|
|
for (; tab->handler; ++tab) |
1397 |
|
|
{ |
1398 |
|
|
if (tab->letter == statchar) |
1399 |
|
|
{ |
1400 |
|
|
/* The stats table says what privs are needed, so check --fl_ */ |
1401 |
|
|
if ((tab->need_admin && !HasUMode(source_p, UMODE_ADMIN)) || |
1402 |
|
|
(tab->need_oper && !HasUMode(source_p, UMODE_OPER))) |
1403 |
|
|
{ |
1404 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
1405 |
|
|
from, to); |
1406 |
|
|
break; |
1407 |
|
|
} |
1408 |
|
|
|
1409 |
|
|
sendto_realops_flags(UMODE_SPY, L_ALL, |
1410 |
|
|
"STATS %c requested by %s (%s@%s) [%s] on %s", |
1411 |
|
|
statchar, source_p->name, source_p->username, |
1412 |
|
|
source_p->host, source_p->servptr->name); |
1413 |
|
|
tab->handler(source_p, parc, parv); |
1414 |
|
|
break; |
1415 |
|
|
} |
1416 |
|
|
} |
1417 |
|
|
|
1418 |
|
|
sendto_one(source_p, form_str(RPL_ENDOFSTATS), |
1419 |
|
|
from, to, statchar); |
1420 |
|
|
} |
1421 |
|
|
|
1422 |
|
|
/* |
1423 |
|
|
* m_stats() |
1424 |
|
|
* parv[0] = sender prefix |
1425 |
|
|
* parv[1] = stat letter/command |
1426 |
|
|
* parv[2] = (if present) server/mask in stats L |
1427 |
adx |
30 |
* |
1428 |
michael |
1457 |
* This will search the tables for the appropriate stats letter/command, |
1429 |
|
|
* if found execute it. |
1430 |
adx |
30 |
*/ |
1431 |
michael |
1457 |
static void |
1432 |
|
|
m_stats(struct Client *client_p, struct Client *source_p, |
1433 |
|
|
int parc, char *parv[]) |
1434 |
adx |
30 |
{ |
1435 |
michael |
1457 |
static time_t last_used = 0; |
1436 |
adx |
30 |
|
1437 |
michael |
1457 |
/* Is the stats meant for us? */ |
1438 |
|
|
if (!ConfigFileEntry.disable_remote) |
1439 |
|
|
if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2, |
1440 |
|
|
parc, parv) != HUNTED_ISME) |
1441 |
|
|
return; |
1442 |
|
|
|
1443 |
|
|
if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p)) |
1444 |
adx |
30 |
{ |
1445 |
michael |
1457 |
from = me.id; |
1446 |
|
|
to = source_p->id; |
1447 |
|
|
} |
1448 |
|
|
else |
1449 |
|
|
{ |
1450 |
|
|
from = me.name; |
1451 |
|
|
to = source_p->name; |
1452 |
|
|
} |
1453 |
adx |
30 |
|
1454 |
michael |
1457 |
/* Check the user is actually allowed to do /stats, and isnt flooding */ |
1455 |
|
|
if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime) |
1456 |
|
|
{ |
1457 |
|
|
sendto_one(source_p,form_str(RPL_LOAD2HI), |
1458 |
|
|
from, to); |
1459 |
|
|
return; |
1460 |
|
|
} |
1461 |
adx |
30 |
|
1462 |
michael |
1457 |
last_used = CurrentTime; |
1463 |
adx |
30 |
|
1464 |
michael |
1457 |
do_stats(source_p, parc, parv); |
1465 |
|
|
} |
1466 |
|
|
|
1467 |
|
|
/* |
1468 |
|
|
* mo_stats() |
1469 |
|
|
* parv[0] = sender prefix |
1470 |
|
|
* parv[1] = stat letter/command |
1471 |
|
|
* parv[2] = (if present) server/mask in stats L, or target |
1472 |
|
|
* |
1473 |
|
|
* This will search the tables for the appropriate stats letter, |
1474 |
|
|
* if found execute it. |
1475 |
|
|
*/ |
1476 |
|
|
static void |
1477 |
|
|
mo_stats(struct Client *client_p, struct Client *source_p, |
1478 |
|
|
int parc, char *parv[]) |
1479 |
|
|
{ |
1480 |
|
|
if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2, |
1481 |
|
|
parc, parv) != HUNTED_ISME) |
1482 |
|
|
return; |
1483 |
|
|
|
1484 |
|
|
if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p)) |
1485 |
|
|
{ |
1486 |
|
|
from = me.id; |
1487 |
|
|
to = source_p->id; |
1488 |
adx |
30 |
} |
1489 |
michael |
1457 |
else |
1490 |
|
|
{ |
1491 |
|
|
from = me.name; |
1492 |
|
|
to = source_p->name; |
1493 |
|
|
} |
1494 |
michael |
1400 |
|
1495 |
michael |
1457 |
do_stats(source_p, parc, parv); |
1496 |
adx |
30 |
} |
1497 |
michael |
1230 |
|
1498 |
michael |
1457 |
/* |
1499 |
|
|
* ms_stats - STATS message handler |
1500 |
|
|
* parv[0] = sender prefix |
1501 |
|
|
* parv[1] = statistics selector (defaults to Message frequency) |
1502 |
|
|
* parv[2] = server name (current server defaulted, if omitted) |
1503 |
|
|
*/ |
1504 |
|
|
static void |
1505 |
|
|
ms_stats(struct Client *client_p, struct Client *source_p, |
1506 |
|
|
int parc, char *parv[]) |
1507 |
|
|
{ |
1508 |
|
|
if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2, |
1509 |
|
|
parc, parv) != HUNTED_ISME) |
1510 |
|
|
return; |
1511 |
|
|
|
1512 |
|
|
if (IsClient(source_p)) |
1513 |
|
|
mo_stats(client_p, source_p, parc, parv); |
1514 |
|
|
} |
1515 |
|
|
|
1516 |
michael |
1230 |
static struct Message stats_msgtab = { |
1517 |
|
|
"STATS", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
1518 |
|
|
{ m_unregistered, m_stats, ms_stats, m_ignore, mo_stats, m_ignore } |
1519 |
|
|
}; |
1520 |
|
|
|
1521 |
|
|
static void |
1522 |
|
|
module_init(void) |
1523 |
|
|
{ |
1524 |
|
|
mod_add_cmd(&stats_msgtab); |
1525 |
|
|
} |
1526 |
|
|
|
1527 |
|
|
static void |
1528 |
|
|
module_exit(void) |
1529 |
|
|
{ |
1530 |
|
|
mod_del_cmd(&stats_msgtab); |
1531 |
|
|
} |
1532 |
|
|
|
1533 |
|
|
struct module module_entry = { |
1534 |
|
|
.node = { NULL, NULL, NULL }, |
1535 |
|
|
.name = NULL, |
1536 |
|
|
.version = "$Revision$", |
1537 |
|
|
.handle = NULL, |
1538 |
|
|
.modinit = module_init, |
1539 |
|
|
.modexit = module_exit, |
1540 |
|
|
.flags = 0 |
1541 |
|
|
}; |