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