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