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