| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
* |
| 4 |
* Copyright (c) 1997-2020 ircd-hybrid development team |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
* USA |
| 20 |
*/ |
| 21 |
|
| 22 |
/*! \file m_stats.c |
| 23 |
* \brief Includes required functions for processing the STATS command. |
| 24 |
* \version $Id$ |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "stdinc.h" |
| 28 |
#include "list.h" |
| 29 |
#include "client.h" |
| 30 |
#include "irc_string.h" |
| 31 |
#include "ircd.h" |
| 32 |
#include "listener.h" |
| 33 |
#include "parse.h" |
| 34 |
#include "conf.h" |
| 35 |
#include "conf_class.h" |
| 36 |
#include "conf_cluster.h" |
| 37 |
#include "conf_gecos.h" |
| 38 |
#include "conf_pseudo.h" |
| 39 |
#include "conf_resv.h" |
| 40 |
#include "conf_service.h" |
| 41 |
#include "conf_shared.h" |
| 42 |
#include "hostmask.h" |
| 43 |
#include "numeric.h" |
| 44 |
#include "send.h" |
| 45 |
#include "fdlist.h" |
| 46 |
#include "misc.h" |
| 47 |
#include "server.h" |
| 48 |
#include "server_capab.h" |
| 49 |
#include "event.h" |
| 50 |
#include "modules.h" |
| 51 |
#include "whowas.h" |
| 52 |
#include "watch.h" |
| 53 |
#include "reslib.h" |
| 54 |
#include "motd.h" |
| 55 |
#include "ipcache.h" |
| 56 |
#include "channel.h" |
| 57 |
#include "channel_invite.h" |
| 58 |
|
| 59 |
|
| 60 |
static const char * |
| 61 |
oper_privs_as_string(const unsigned int flags) |
| 62 |
{ |
| 63 |
static const struct oper_flags |
| 64 |
{ |
| 65 |
unsigned int flag; |
| 66 |
unsigned char letter; |
| 67 |
} flag_table[] = { |
| 68 |
{ OPER_FLAG_ADMIN, 'A' }, |
| 69 |
{ OPER_FLAG_CLOSE, 'B' }, |
| 70 |
{ OPER_FLAG_CONNECT, 'C' }, |
| 71 |
{ OPER_FLAG_CONNECT_REMOTE, 'D' }, |
| 72 |
{ OPER_FLAG_DIE, 'E' }, |
| 73 |
{ OPER_FLAG_DLINE, 'F' }, |
| 74 |
{ OPER_FLAG_GLOBOPS, 'G' }, |
| 75 |
{ OPER_FLAG_JOIN_RESV, 'H' }, |
| 76 |
{ OPER_FLAG_KILL, 'I' }, |
| 77 |
{ OPER_FLAG_KILL_REMOTE, 'J' }, |
| 78 |
{ OPER_FLAG_KLINE, 'K' }, |
| 79 |
{ OPER_FLAG_LOCOPS, 'L' }, |
| 80 |
{ OPER_FLAG_MODULE, 'M' }, |
| 81 |
{ OPER_FLAG_NICK_RESV, 'N' }, |
| 82 |
{ OPER_FLAG_OPME, 'O' }, |
| 83 |
{ OPER_FLAG_REHASH, 'P' }, |
| 84 |
{ OPER_FLAG_REMOTEBAN, 'Q' }, |
| 85 |
{ OPER_FLAG_RESTART, 'R' }, |
| 86 |
{ OPER_FLAG_RESV, 'S' }, |
| 87 |
{ OPER_FLAG_SET, 'T' }, |
| 88 |
{ OPER_FLAG_SQUIT, 'U' }, |
| 89 |
{ OPER_FLAG_SQUIT_REMOTE, 'V' }, |
| 90 |
{ OPER_FLAG_UNDLINE, 'W' }, |
| 91 |
{ OPER_FLAG_UNKLINE, 'X' }, |
| 92 |
{ OPER_FLAG_UNRESV, 'Y' }, |
| 93 |
{ OPER_FLAG_UNXLINE, 'Z' }, |
| 94 |
{ OPER_FLAG_WALLOPS, 'a' }, |
| 95 |
{ OPER_FLAG_XLINE, 'b' }, |
| 96 |
{ 0, '\0' } |
| 97 |
}; |
| 98 |
|
| 99 |
static char buf[sizeof(flag_table) / sizeof(flag_table[0])]; |
| 100 |
char *p = buf; |
| 101 |
|
| 102 |
for (const struct oper_flags *tab = flag_table; tab->flag; ++tab) |
| 103 |
if (flags & tab->flag) |
| 104 |
*p++ = tab->letter; |
| 105 |
|
| 106 |
if (p == buf) |
| 107 |
*p++ = '0'; |
| 108 |
|
| 109 |
*p = '\0'; |
| 110 |
|
| 111 |
return buf; |
| 112 |
} |
| 113 |
|
| 114 |
static void |
| 115 |
report_shared(struct Client *source_p) |
| 116 |
{ |
| 117 |
static const struct shared_types |
| 118 |
{ |
| 119 |
unsigned int type; |
| 120 |
unsigned char letter; |
| 121 |
} flag_table[] = { |
| 122 |
{ SHARED_KLINE, 'K' }, |
| 123 |
{ SHARED_UNKLINE, 'U' }, |
| 124 |
{ SHARED_XLINE, 'X' }, |
| 125 |
{ SHARED_UNXLINE, 'Y' }, |
| 126 |
{ SHARED_RESV, 'Q' }, |
| 127 |
{ SHARED_UNRESV, 'R' }, |
| 128 |
{ SHARED_LOCOPS, 'L' }, |
| 129 |
{ SHARED_DLINE, 'D' }, |
| 130 |
{ SHARED_UNDLINE, 'E' }, |
| 131 |
{ 0, '\0' } |
| 132 |
}; |
| 133 |
|
| 134 |
dlink_node *node; |
| 135 |
char buf[sizeof(flag_table) / sizeof(flag_table[0]) + 1]; /* +1 for 'c' */ |
| 136 |
|
| 137 |
DLINK_FOREACH(node, shared_get_list()->head) |
| 138 |
{ |
| 139 |
const struct SharedItem *shared = node->data; |
| 140 |
char *p = buf; |
| 141 |
|
| 142 |
*p++ = 'c'; |
| 143 |
|
| 144 |
for (const struct shared_types *tab = flag_table; tab->type; ++tab) |
| 145 |
if (tab->type & shared->type) |
| 146 |
*p++ = tab->letter; |
| 147 |
else |
| 148 |
*p++ = ToLower(tab->letter); |
| 149 |
|
| 150 |
*p = '\0'; |
| 151 |
|
| 152 |
sendto_one_numeric(source_p, &me, RPL_STATSULINE, shared->server, |
| 153 |
shared->user, shared->host, buf); |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
static void |
| 158 |
report_cluster(struct Client *source_p) |
| 159 |
{ |
| 160 |
static const struct cluster_types |
| 161 |
{ |
| 162 |
unsigned int type; |
| 163 |
unsigned char letter; |
| 164 |
} flag_table[] = { |
| 165 |
{ CLUSTER_KLINE, 'K' }, |
| 166 |
{ CLUSTER_UNKLINE, 'U' }, |
| 167 |
{ CLUSTER_XLINE, 'X' }, |
| 168 |
{ CLUSTER_UNXLINE, 'Y' }, |
| 169 |
{ CLUSTER_RESV, 'Q' }, |
| 170 |
{ CLUSTER_UNRESV, 'R' }, |
| 171 |
{ CLUSTER_LOCOPS, 'L' }, |
| 172 |
{ CLUSTER_DLINE, 'D' }, |
| 173 |
{ CLUSTER_UNDLINE, 'E' }, |
| 174 |
{ 0, '\0' } |
| 175 |
}; |
| 176 |
|
| 177 |
dlink_node *node; |
| 178 |
char buf[sizeof(flag_table) / sizeof(flag_table[0]) + 1]; /* +1 for 'C' */ |
| 179 |
|
| 180 |
DLINK_FOREACH(node, cluster_get_list()->head) |
| 181 |
{ |
| 182 |
const struct ClusterItem *cluster = node->data; |
| 183 |
char *p = buf; |
| 184 |
|
| 185 |
*p++ = 'C'; |
| 186 |
|
| 187 |
for (const struct cluster_types *tab = flag_table; tab->type; ++tab) |
| 188 |
if (tab->type & cluster->type) |
| 189 |
*p++ = tab->letter; |
| 190 |
else |
| 191 |
*p++ = ToLower(tab->letter); |
| 192 |
|
| 193 |
*p = '\0'; |
| 194 |
|
| 195 |
sendto_one_numeric(source_p, &me, RPL_STATSULINE, cluster->server, |
| 196 |
"*", "*", buf); |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
static void |
| 201 |
stats_service(struct Client *source_p, int parc, char *parv[]) |
| 202 |
{ |
| 203 |
dlink_node *node; |
| 204 |
|
| 205 |
DLINK_FOREACH(node, service_get_list()->head) |
| 206 |
{ |
| 207 |
const struct ServiceItem *service = node->data; |
| 208 |
sendto_one_numeric(source_p, &me, RPL_STATSSERVICE, "*", service->name, 0, 0); |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
static void |
| 213 |
stats_gecos(struct Client *source_p, int parc, char *parv[]) |
| 214 |
{ |
| 215 |
dlink_node *node; |
| 216 |
|
| 217 |
DLINK_FOREACH(node, gecos_get_list()->head) |
| 218 |
{ |
| 219 |
const struct GecosItem *gecos = node->data; |
| 220 |
sendto_one_numeric(source_p, &me, RPL_STATSXLINE, |
| 221 |
gecos->expire ? 'x' : 'X', |
| 222 |
gecos->mask, gecos->reason); |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
/* |
| 227 |
* inputs - pointer to client requesting confitem report |
| 228 |
* - ConfType to report |
| 229 |
* output - none |
| 230 |
* side effects - |
| 231 |
*/ |
| 232 |
static void |
| 233 |
stats_operator(struct Client *source_p, int parc, char *parv[]) |
| 234 |
{ |
| 235 |
dlink_node *node; |
| 236 |
|
| 237 |
if (!HasUMode(source_p, UMODE_OPER) && ConfigGeneral.stats_o_oper_only) |
| 238 |
{ |
| 239 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
| 240 |
return; |
| 241 |
} |
| 242 |
|
| 243 |
DLINK_FOREACH(node, operator_items.head) |
| 244 |
{ |
| 245 |
const struct MaskItem *conf = node->data; |
| 246 |
|
| 247 |
/* Don't allow non opers to see oper privs */ |
| 248 |
if (HasUMode(source_p, UMODE_OPER)) |
| 249 |
sendto_one_numeric(source_p, &me, RPL_STATSOLINE, 'O', conf->user, conf->host, |
| 250 |
conf->name, oper_privs_as_string(conf->port), |
| 251 |
conf->class->name); |
| 252 |
else |
| 253 |
sendto_one_numeric(source_p, &me, RPL_STATSOLINE, 'O', conf->user, conf->host, |
| 254 |
conf->name, "0", conf->class->name); |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
static void |
| 259 |
stats_connect(struct Client *source_p, int parc, char *parv[]) |
| 260 |
{ |
| 261 |
dlink_node *node; |
| 262 |
|
| 263 |
DLINK_FOREACH(node, connect_items.head) |
| 264 |
{ |
| 265 |
char buf[8]; |
| 266 |
char *p = buf; |
| 267 |
const struct MaskItem *conf = node->data; |
| 268 |
|
| 269 |
if (IsConfAllowAutoConn(conf)) |
| 270 |
*p++ = 'A'; |
| 271 |
if (IsConfTLS(conf)) |
| 272 |
*p++ = 'S'; |
| 273 |
if (p == buf) |
| 274 |
*p++ = '*'; |
| 275 |
|
| 276 |
*p = '\0'; |
| 277 |
|
| 278 |
/* |
| 279 |
* Allow admins to see actual ips unless 'hide_server_ips' is enabled |
| 280 |
*/ |
| 281 |
if (ConfigServerHide.hide_server_ips == 0 && HasUMode(source_p, UMODE_ADMIN)) |
| 282 |
sendto_one_numeric(source_p, &me, RPL_STATSCLINE, 'C', conf->host, |
| 283 |
buf, conf->name, conf->port, conf->class->name); |
| 284 |
else |
| 285 |
sendto_one_numeric(source_p, &me, RPL_STATSCLINE, 'C', "*@127.0.0.1", |
| 286 |
buf, conf->name, conf->port, conf->class->name); |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
/* report_resv() |
| 291 |
* |
| 292 |
* inputs - pointer to client pointer to report to. |
| 293 |
* output - NONE |
| 294 |
* side effects - report all resvs to client. |
| 295 |
*/ |
| 296 |
static void |
| 297 |
stats_resv(struct Client *source_p, int parc, char *parv[]) |
| 298 |
{ |
| 299 |
dlink_node *node; |
| 300 |
|
| 301 |
DLINK_FOREACH(node, resv_chan_get_list()->head) |
| 302 |
{ |
| 303 |
const struct ResvItem *resv = node->data; |
| 304 |
|
| 305 |
sendto_one_numeric(source_p, &me, RPL_STATSQLINE, |
| 306 |
resv->expire ? 'q' : 'Q', |
| 307 |
resv->mask, resv->reason); |
| 308 |
} |
| 309 |
|
| 310 |
DLINK_FOREACH(node, resv_nick_get_list()->head) |
| 311 |
{ |
| 312 |
const struct ResvItem *resv = node->data; |
| 313 |
|
| 314 |
sendto_one_numeric(source_p, &me, RPL_STATSQLINE, |
| 315 |
resv->expire ? 'q' : 'Q', |
| 316 |
resv->mask, resv->reason); |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
static void |
| 321 |
stats_memory(struct Client *source_p, int parc, char *parv[]) |
| 322 |
{ |
| 323 |
dlink_node *node, *node2; |
| 324 |
|
| 325 |
unsigned int local_client_conf_count = 0; /* local client conf links */ |
| 326 |
|
| 327 |
unsigned int channel_members = 0; |
| 328 |
unsigned int channel_invites = 0; |
| 329 |
unsigned int channel_bans = 0; |
| 330 |
unsigned int channel_except = 0; |
| 331 |
unsigned int channel_invex = 0; |
| 332 |
|
| 333 |
unsigned int wwu = 0; /* whowas users */ |
| 334 |
unsigned int number_ips_stored = 0; /* number of ip addresses hashed */ |
| 335 |
|
| 336 |
size_t channel_ban_memory = 0; |
| 337 |
size_t channel_except_memory = 0; |
| 338 |
size_t channel_invex_memory = 0; |
| 339 |
|
| 340 |
unsigned int safelist_count = 0; |
| 341 |
size_t safelist_memory = 0; |
| 342 |
|
| 343 |
size_t wwm = 0; /* whowas array memory used */ |
| 344 |
size_t mem_ips_stored = 0; /* memory used by ip address hash */ |
| 345 |
|
| 346 |
unsigned int local_client_count = 0; |
| 347 |
unsigned int remote_client_count = 0; |
| 348 |
|
| 349 |
size_t local_client_memory_used = 0; |
| 350 |
size_t remote_client_memory_used = 0; |
| 351 |
|
| 352 |
unsigned int watch_list_headers = 0; /* watchlist headers */ |
| 353 |
unsigned int watch_list_entries = 0; /* watchlist entries */ |
| 354 |
size_t watch_list_memory = 0; /* watchlist memory used */ |
| 355 |
|
| 356 |
unsigned int listener_count = 0; |
| 357 |
size_t listener_memory = 0; |
| 358 |
|
| 359 |
|
| 360 |
DLINK_FOREACH(node, local_server_list.head) |
| 361 |
{ |
| 362 |
const struct Client *target_p = node->data; |
| 363 |
|
| 364 |
local_client_conf_count += dlink_list_length(&target_p->connection->confs); |
| 365 |
} |
| 366 |
|
| 367 |
DLINK_FOREACH(node, local_client_list.head) |
| 368 |
{ |
| 369 |
const struct Client *target_p = node->data; |
| 370 |
|
| 371 |
local_client_conf_count += dlink_list_length(&target_p->connection->confs); |
| 372 |
watch_list_entries += dlink_list_length(&target_p->connection->watches); |
| 373 |
} |
| 374 |
|
| 375 |
local_client_count = dlink_list_length(&local_server_list) + dlink_list_length(&local_client_list); |
| 376 |
remote_client_count = dlink_list_length(&global_server_list) + dlink_list_length(&global_client_list) - local_client_count; |
| 377 |
|
| 378 |
/* Count up all members, invites, ban lists, except lists, Invex lists */ |
| 379 |
DLINK_FOREACH(node, channel_get_list()->head) |
| 380 |
{ |
| 381 |
const struct Channel *channel = node->data; |
| 382 |
|
| 383 |
channel_members += dlink_list_length(&channel->members); |
| 384 |
channel_invites += dlink_list_length(&channel->invites); |
| 385 |
|
| 386 |
channel_bans += dlink_list_length(&channel->banlist); |
| 387 |
channel_ban_memory += dlink_list_length(&channel->banlist) * sizeof(struct Ban); |
| 388 |
|
| 389 |
channel_except += dlink_list_length(&channel->exceptlist); |
| 390 |
channel_except_memory += dlink_list_length(&channel->exceptlist) * sizeof(struct Ban); |
| 391 |
|
| 392 |
channel_invex += dlink_list_length(&channel->invexlist); |
| 393 |
channel_invex_memory += dlink_list_length(&channel->invexlist) * sizeof(struct Ban); |
| 394 |
} |
| 395 |
|
| 396 |
safelist_count = dlink_list_length(&listing_client_list); |
| 397 |
if (safelist_count) |
| 398 |
{ |
| 399 |
safelist_memory = safelist_count * sizeof(struct ListTask); |
| 400 |
|
| 401 |
DLINK_FOREACH(node, listing_client_list.head) |
| 402 |
{ |
| 403 |
const struct Client *acptr = node->data; |
| 404 |
|
| 405 |
DLINK_FOREACH(node2, acptr->connection->list_task->show_mask.head) |
| 406 |
safelist_memory += strlen(node2->data); |
| 407 |
|
| 408 |
DLINK_FOREACH(node2, acptr->connection->list_task->hide_mask.head) |
| 409 |
safelist_memory += strlen(node2->data); |
| 410 |
} |
| 411 |
} |
| 412 |
|
| 413 |
watch_count_memory(&watch_list_headers, &watch_list_memory); |
| 414 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 415 |
"z :WATCH headers %u(%zu) entries %u(%zu)", |
| 416 |
watch_list_headers, |
| 417 |
watch_list_memory, |
| 418 |
watch_list_entries, |
| 419 |
watch_list_entries * sizeof(dlink_node) * 2); |
| 420 |
|
| 421 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 422 |
"z :Clients %u(%zu)", |
| 423 |
dlink_list_length(&global_client_list), |
| 424 |
dlink_list_length(&global_client_list) * sizeof(struct Client)); |
| 425 |
|
| 426 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 427 |
"z :Servers %u(%zu, %zu)", |
| 428 |
dlink_list_length(&global_server_list), |
| 429 |
dlink_list_length(&global_server_list) * sizeof(struct Client), |
| 430 |
dlink_list_length(&global_server_list) * sizeof(struct Server)); |
| 431 |
|
| 432 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 433 |
"z :Attached confs %u(%zu)", |
| 434 |
local_client_conf_count, |
| 435 |
local_client_conf_count * sizeof(dlink_node)); |
| 436 |
|
| 437 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 438 |
"z :Resv channels %u(%zu) nicks %u(%zu)", |
| 439 |
dlink_list_length(resv_chan_get_list()), |
| 440 |
dlink_list_length(resv_chan_get_list()) * sizeof(struct ResvItem), |
| 441 |
dlink_list_length(resv_nick_get_list()), |
| 442 |
dlink_list_length(resv_nick_get_list()) * sizeof(struct ResvItem)); |
| 443 |
|
| 444 |
listener_count_memory(&listener_count, &listener_memory); |
| 445 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 446 |
"z :Listeners %u(%zu)", |
| 447 |
listener_count, listener_memory); |
| 448 |
|
| 449 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 450 |
"z :Classes %u(%zu)", |
| 451 |
dlink_list_length(class_get_list()), |
| 452 |
dlink_list_length(class_get_list()) * sizeof(struct ClassItem)); |
| 453 |
|
| 454 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 455 |
"z :Channels %u(%zu)", |
| 456 |
dlink_list_length(channel_get_list()), |
| 457 |
dlink_list_length(channel_get_list()) * sizeof(struct Channel)); |
| 458 |
|
| 459 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 460 |
"z :Bans %u(%zu)", |
| 461 |
channel_bans, channel_ban_memory); |
| 462 |
|
| 463 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 464 |
"z :Exceptions %u(%zu)", |
| 465 |
channel_except, channel_except_memory); |
| 466 |
|
| 467 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 468 |
"z :Invex %u(%zu)", |
| 469 |
channel_invex, channel_invex_memory); |
| 470 |
|
| 471 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 472 |
"z :Channel members %u(%zu) invites %u(%zu)", |
| 473 |
channel_members, |
| 474 |
channel_members * sizeof(struct ChannelMember), |
| 475 |
channel_invites, |
| 476 |
channel_invites * sizeof(struct Invite)); |
| 477 |
|
| 478 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 479 |
"z :Safelist %u(%zu)", |
| 480 |
safelist_count, safelist_memory); |
| 481 |
|
| 482 |
whowas_count_memory(&wwu, &wwm); |
| 483 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 484 |
"z :Whowas users %u(%zu)", wwu, wwm); |
| 485 |
|
| 486 |
motd_memory_count(source_p); |
| 487 |
|
| 488 |
ipcache_get_stats(&number_ips_stored, &mem_ips_stored); |
| 489 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 490 |
"z :iphash %u(%zu)", |
| 491 |
number_ips_stored, mem_ips_stored); |
| 492 |
|
| 493 |
local_client_memory_used = local_client_count * (sizeof(struct Client) + sizeof(struct Connection)); |
| 494 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 495 |
"z :Local client Memory in use: %u(%zu)", |
| 496 |
local_client_count, local_client_memory_used); |
| 497 |
|
| 498 |
remote_client_memory_used = remote_client_count * sizeof(struct Client); |
| 499 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 500 |
"z :Remote client Memory in use: %u(%zu)", |
| 501 |
remote_client_count, remote_client_memory_used); |
| 502 |
} |
| 503 |
|
| 504 |
static void |
| 505 |
stats_dns_servers(struct Client *source_p, int parc, char *parv[]) |
| 506 |
{ |
| 507 |
char ipaddr[HOSTIPLEN + 1]; |
| 508 |
|
| 509 |
for (unsigned int i = 0; i < irc_nscount; ++i) |
| 510 |
{ |
| 511 |
getnameinfo((const struct sockaddr *)&irc_nsaddr_list[i], irc_nsaddr_list[i].ss_len, |
| 512 |
ipaddr, sizeof(ipaddr), NULL, 0, NI_NUMERICHOST); |
| 513 |
sendto_one_numeric(source_p, &me, RPL_STATSALINE, ipaddr); |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
/* stats_deny() |
| 518 |
* |
| 519 |
* input - client to report to |
| 520 |
* output - none |
| 521 |
* side effects - client is given dline list. |
| 522 |
*/ |
| 523 |
static void |
| 524 |
stats_deny(struct Client *source_p, int parc, char *parv[]) |
| 525 |
{ |
| 526 |
dlink_node *node; |
| 527 |
|
| 528 |
for (unsigned int i = 0; i < ATABLE_SIZE; ++i) |
| 529 |
{ |
| 530 |
DLINK_FOREACH(node, atable[i].head) |
| 531 |
{ |
| 532 |
const struct AddressRec *arec = node->data; |
| 533 |
|
| 534 |
if (arec->type != CONF_DLINE) |
| 535 |
continue; |
| 536 |
|
| 537 |
const struct MaskItem *conf = arec->conf; |
| 538 |
/* Don't report a temporary dline as permanent dline */ |
| 539 |
if (conf->until) |
| 540 |
continue; |
| 541 |
|
| 542 |
sendto_one_numeric(source_p, &me, RPL_STATSDLINE, 'D', conf->host, conf->reason); |
| 543 |
} |
| 544 |
} |
| 545 |
} |
| 546 |
|
| 547 |
/* stats_tdeny() |
| 548 |
* |
| 549 |
* input - client to report to |
| 550 |
* output - none |
| 551 |
* side effects - client is given dline list. |
| 552 |
*/ |
| 553 |
static void |
| 554 |
stats_tdeny(struct Client *source_p, int parc, char *parv[]) |
| 555 |
{ |
| 556 |
dlink_node *node; |
| 557 |
|
| 558 |
for (unsigned int i = 0; i < ATABLE_SIZE; ++i) |
| 559 |
{ |
| 560 |
DLINK_FOREACH(node, atable[i].head) |
| 561 |
{ |
| 562 |
const struct AddressRec *arec = node->data; |
| 563 |
|
| 564 |
if (arec->type != CONF_DLINE) |
| 565 |
continue; |
| 566 |
|
| 567 |
const struct MaskItem *conf = arec->conf; |
| 568 |
/* Don't report a permanent dline as temporary dline */ |
| 569 |
if (conf->until == 0) |
| 570 |
continue; |
| 571 |
|
| 572 |
sendto_one_numeric(source_p, &me, RPL_STATSDLINE, 'd', conf->host, conf->reason); |
| 573 |
} |
| 574 |
} |
| 575 |
} |
| 576 |
|
| 577 |
/* stats_exempt() |
| 578 |
* |
| 579 |
* input - client to report to |
| 580 |
* output - none |
| 581 |
* side effects - client is given list of exempt blocks |
| 582 |
*/ |
| 583 |
static void |
| 584 |
stats_exempt(struct Client *source_p, int parc, char *parv[]) |
| 585 |
{ |
| 586 |
dlink_node *node; |
| 587 |
|
| 588 |
if (ConfigGeneral.stats_e_disabled) |
| 589 |
{ |
| 590 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
| 591 |
return; |
| 592 |
} |
| 593 |
|
| 594 |
for (unsigned int i = 0; i < ATABLE_SIZE; ++i) |
| 595 |
{ |
| 596 |
DLINK_FOREACH(node, atable[i].head) |
| 597 |
{ |
| 598 |
const struct AddressRec *arec = node->data; |
| 599 |
|
| 600 |
if (arec->type != CONF_EXEMPT) |
| 601 |
continue; |
| 602 |
|
| 603 |
const struct MaskItem *conf = arec->conf; |
| 604 |
sendto_one_numeric(source_p, &me, RPL_STATSDLINE, 'e', conf->host, ""); |
| 605 |
} |
| 606 |
} |
| 607 |
} |
| 608 |
|
| 609 |
static void |
| 610 |
stats_events(struct Client *source_p, int parc, char *parv[]) |
| 611 |
{ |
| 612 |
dlink_node *node; |
| 613 |
|
| 614 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 615 |
"E :Operation Next Execution"); |
| 616 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 617 |
"E :---------------------------------------------"); |
| 618 |
|
| 619 |
DLINK_FOREACH(node, event_get_list()->head) |
| 620 |
{ |
| 621 |
const struct event *ev = node->data; |
| 622 |
|
| 623 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 624 |
"E :%-30s %-4ju seconds", |
| 625 |
ev->name, ev->next - event_base->time.sec_monotonic); |
| 626 |
} |
| 627 |
} |
| 628 |
|
| 629 |
static void |
| 630 |
stats_fdlist(struct Client *source_p, int parc, char *parv[]) |
| 631 |
{ |
| 632 |
for (int fd = 0; fd <= highest_fd; ++fd) |
| 633 |
{ |
| 634 |
const fde_t *F = &fd_table[fd]; |
| 635 |
|
| 636 |
if (F->flags.open == true) |
| 637 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 638 |
"F :fd %-5d desc '%s'", F->fd, F->desc); |
| 639 |
} |
| 640 |
} |
| 641 |
|
| 642 |
static void |
| 643 |
stats_hubleaf(struct Client *source_p, int parc, char *parv[]) |
| 644 |
{ |
| 645 |
dlink_node *node, *node2; |
| 646 |
|
| 647 |
DLINK_FOREACH(node, connect_items.head) |
| 648 |
{ |
| 649 |
const struct MaskItem *conf = node->data; |
| 650 |
|
| 651 |
DLINK_FOREACH(node2, conf->hub_list.head) |
| 652 |
sendto_one_numeric(source_p, &me, RPL_STATSHLINE, 'H', node2->data, conf->name, 0, "*"); |
| 653 |
} |
| 654 |
|
| 655 |
DLINK_FOREACH(node, connect_items.head) |
| 656 |
{ |
| 657 |
const struct MaskItem *conf = node->data; |
| 658 |
|
| 659 |
DLINK_FOREACH(node2, conf->leaf_list.head) |
| 660 |
sendto_one_numeric(source_p, &me, RPL_STATSLLINE, 'L', node2->data, conf->name, 0, "*"); |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
/* |
| 665 |
* show_iline_prefix() |
| 666 |
* |
| 667 |
* inputs - pointer to struct Client requesting output |
| 668 |
* - pointer to struct MaskItem |
| 669 |
* - name to which iline prefix will be prefixed to |
| 670 |
* output - pointer to static string with prefixes listed in ascii form |
| 671 |
* side effects - NONE |
| 672 |
*/ |
| 673 |
static const char * |
| 674 |
show_iline_prefix(const struct Client *source_p, const struct MaskItem *conf) |
| 675 |
{ |
| 676 |
static char buf[USERLEN + 16]; |
| 677 |
char *p = buf; |
| 678 |
|
| 679 |
if (IsConfWebIRC(conf)) |
| 680 |
*p++ = '<'; |
| 681 |
if (IsNoTilde(conf)) |
| 682 |
*p++ = '-'; |
| 683 |
if (IsNeedIdentd(conf)) |
| 684 |
*p++ = '+'; |
| 685 |
if (!IsNeedPassword(conf)) |
| 686 |
*p++ = '&'; |
| 687 |
if (IsConfExemptResv(conf)) |
| 688 |
*p++ = '$'; |
| 689 |
if (IsConfDoSpoofIp(conf)) |
| 690 |
*p++ = '='; |
| 691 |
if (IsConfCanFlood(conf)) |
| 692 |
*p++ = '|'; |
| 693 |
if (HasUMode(source_p, UMODE_OPER)) |
| 694 |
{ |
| 695 |
if (IsConfExemptKline(conf)) |
| 696 |
*p++ = '^'; |
| 697 |
if (IsConfExemptXline(conf)) |
| 698 |
*p++ = '!'; |
| 699 |
if (IsConfExemptLimits(conf)) |
| 700 |
*p++ = '>'; |
| 701 |
} |
| 702 |
|
| 703 |
strlcpy(p, conf->user, USERLEN + 1); |
| 704 |
return buf; |
| 705 |
} |
| 706 |
|
| 707 |
static void |
| 708 |
stats_auth(struct Client *source_p, int parc, char *parv[]) |
| 709 |
{ |
| 710 |
dlink_node *node; |
| 711 |
|
| 712 |
/* Oper only, if unopered, return ERR_NOPRIVILEGES */ |
| 713 |
if (ConfigGeneral.stats_i_oper_only && !HasUMode(source_p, UMODE_OPER)) |
| 714 |
{ |
| 715 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
| 716 |
return; |
| 717 |
} |
| 718 |
|
| 719 |
for (unsigned int i = 0; i < ATABLE_SIZE; ++i) |
| 720 |
{ |
| 721 |
DLINK_FOREACH(node, atable[i].head) |
| 722 |
{ |
| 723 |
const struct AddressRec *arec = node->data; |
| 724 |
|
| 725 |
if (arec->type != CONF_CLIENT) |
| 726 |
continue; |
| 727 |
|
| 728 |
const struct MaskItem *conf = arec->conf; |
| 729 |
if (IsConfDoSpoofIp(conf) && !HasUMode(source_p, UMODE_OPER)) |
| 730 |
continue; |
| 731 |
|
| 732 |
sendto_one_numeric(source_p, &me, RPL_STATSILINE, 'I', |
| 733 |
conf->name == NULL ? "*" : conf->name, |
| 734 |
show_iline_prefix(source_p, conf), |
| 735 |
conf->host, conf->port, |
| 736 |
conf->class->name); |
| 737 |
} |
| 738 |
} |
| 739 |
} |
| 740 |
|
| 741 |
/* report_Klines() |
| 742 |
* Inputs: Client to report to, |
| 743 |
* type(==0 for perm, !=0 for temporary) |
| 744 |
* mask |
| 745 |
* Output: None |
| 746 |
* Side effects: Reports configured K(or k)-lines to source_p. |
| 747 |
*/ |
| 748 |
static void |
| 749 |
stats_kill(struct Client *source_p, int parc, char *parv[]) |
| 750 |
{ |
| 751 |
dlink_node *node; |
| 752 |
|
| 753 |
/* Oper only, if unopered, return ERR_NOPRIVILEGES */ |
| 754 |
if (ConfigGeneral.stats_k_oper_only && !HasUMode(source_p, UMODE_OPER)) |
| 755 |
{ |
| 756 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
| 757 |
return; |
| 758 |
} |
| 759 |
|
| 760 |
for (unsigned int i = 0; i < ATABLE_SIZE; ++i) |
| 761 |
{ |
| 762 |
DLINK_FOREACH(node, atable[i].head) |
| 763 |
{ |
| 764 |
const struct AddressRec *arec = node->data; |
| 765 |
|
| 766 |
if (arec->type != CONF_KLINE) |
| 767 |
continue; |
| 768 |
|
| 769 |
const struct MaskItem *conf = arec->conf; |
| 770 |
/* Don't report a temporary kline as permanent kline */ |
| 771 |
if (conf->until) |
| 772 |
continue; |
| 773 |
|
| 774 |
sendto_one_numeric(source_p, &me, RPL_STATSKLINE, 'K', conf->host, conf->user, |
| 775 |
conf->reason); |
| 776 |
} |
| 777 |
} |
| 778 |
} |
| 779 |
|
| 780 |
static void |
| 781 |
stats_tkill(struct Client *source_p, int parc, char *parv[]) |
| 782 |
{ |
| 783 |
dlink_node *node; |
| 784 |
|
| 785 |
/* Oper only, if unopered, return ERR_NOPRIVILEGES */ |
| 786 |
if (ConfigGeneral.stats_k_oper_only && !HasUMode(source_p, UMODE_OPER)) |
| 787 |
{ |
| 788 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
| 789 |
return; |
| 790 |
} |
| 791 |
|
| 792 |
for (unsigned int i = 0; i < ATABLE_SIZE; ++i) |
| 793 |
{ |
| 794 |
DLINK_FOREACH(node, atable[i].head) |
| 795 |
{ |
| 796 |
const struct AddressRec *arec = node->data; |
| 797 |
|
| 798 |
if (arec->type != CONF_KLINE) |
| 799 |
continue; |
| 800 |
|
| 801 |
const struct MaskItem *conf = arec->conf; |
| 802 |
/* Don't report a permanent kline as temporary kline */ |
| 803 |
if (conf->until == 0) |
| 804 |
continue; |
| 805 |
|
| 806 |
sendto_one_numeric(source_p, &me, RPL_STATSKLINE, 'k', conf->host, conf->user, |
| 807 |
conf->reason); |
| 808 |
} |
| 809 |
} |
| 810 |
} |
| 811 |
|
| 812 |
static void |
| 813 |
stats_messages(struct Client *source_p, int parc, char *parv[]) |
| 814 |
{ |
| 815 |
if (!HasUMode(source_p, UMODE_OPER) && ConfigGeneral.stats_m_oper_only) |
| 816 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
| 817 |
else |
| 818 |
report_messages(source_p); |
| 819 |
} |
| 820 |
|
| 821 |
static void |
| 822 |
stats_pseudo(struct Client *source_p, int parc, char *parv[]) |
| 823 |
{ |
| 824 |
dlink_node *node; |
| 825 |
|
| 826 |
DLINK_FOREACH(node, pseudo_get_list()->head) |
| 827 |
{ |
| 828 |
const struct PseudoItem *pseudo = node->data; |
| 829 |
sendto_one_numeric(source_p, &me, RPL_STATSPSEUDO, pseudo->command, |
| 830 |
pseudo->name, pseudo->nick, pseudo->serv, |
| 831 |
pseudo->prepend ? pseudo->prepend : "*"); |
| 832 |
} |
| 833 |
} |
| 834 |
|
| 835 |
/* stats_operedup() |
| 836 |
* |
| 837 |
* input - client pointer |
| 838 |
* output - none |
| 839 |
* side effects - client is shown a list of active opers |
| 840 |
*/ |
| 841 |
static void |
| 842 |
stats_operedup(struct Client *source_p, int parc, char *parv[]) |
| 843 |
{ |
| 844 |
dlink_node *node; |
| 845 |
char buf[32]; |
| 846 |
unsigned int opercount = 0; |
| 847 |
|
| 848 |
DLINK_FOREACH(node, oper_list.head) |
| 849 |
{ |
| 850 |
const struct Client *target_p = node->data; |
| 851 |
|
| 852 |
if (HasUMode(target_p, UMODE_HIDDEN) && !HasUMode(source_p, UMODE_OPER)) |
| 853 |
continue; |
| 854 |
|
| 855 |
if (HasUMode(source_p, UMODE_OPER) || !HasUMode(target_p, UMODE_HIDEIDLE)) |
| 856 |
snprintf(buf, sizeof(buf), "%s", time_dissect(client_get_idle_time(source_p, target_p))); |
| 857 |
else |
| 858 |
strlcpy(buf, "n/a", sizeof(buf)); |
| 859 |
|
| 860 |
if (MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) |
| 861 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 862 |
"p :[%c][%s] %s (%s@%s) Idle: %s", |
| 863 |
HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O', |
| 864 |
oper_privs_as_string(target_p->connection->operflags), |
| 865 |
target_p->name, target_p->username, target_p->host, buf); |
| 866 |
else |
| 867 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 868 |
"p :[%c] %s (%s@%s) Idle: %s", |
| 869 |
HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O', |
| 870 |
target_p->name, target_p->username, target_p->host, buf); |
| 871 |
++opercount; |
| 872 |
} |
| 873 |
|
| 874 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 875 |
"p :%u OPER(s)", opercount); |
| 876 |
} |
| 877 |
|
| 878 |
/* show_ports() |
| 879 |
* |
| 880 |
* inputs - pointer to client to show ports to |
| 881 |
* output - none |
| 882 |
* side effects - send port listing to a client |
| 883 |
*/ |
| 884 |
static void |
| 885 |
stats_ports(struct Client *source_p, int parc, char *parv[]) |
| 886 |
{ |
| 887 |
dlink_node *node; |
| 888 |
|
| 889 |
if (ConfigGeneral.stats_P_oper_only && !HasUMode(source_p, UMODE_OPER)) |
| 890 |
{ |
| 891 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
| 892 |
return; |
| 893 |
} |
| 894 |
|
| 895 |
DLINK_FOREACH(node, listener_get_list()->head) |
| 896 |
{ |
| 897 |
char buf[8]; |
| 898 |
char *p = buf; |
| 899 |
const struct Listener *listener = node->data; |
| 900 |
|
| 901 |
if (listener_has_flag(listener, LISTENER_HIDDEN)) |
| 902 |
{ |
| 903 |
if (!HasUMode(source_p, UMODE_ADMIN)) |
| 904 |
continue; |
| 905 |
*p++ = 'H'; |
| 906 |
} |
| 907 |
|
| 908 |
if (listener_has_flag(listener, LISTENER_SERVER)) |
| 909 |
*p++ = 'S'; |
| 910 |
if (listener_has_flag(listener, LISTENER_CLIENT)) |
| 911 |
*p++ = 'C'; |
| 912 |
if (listener_has_flag(listener, LISTENER_TLS)) |
| 913 |
*p++ = 'T'; |
| 914 |
if (listener_has_flag(listener, LISTENER_DEFER)) |
| 915 |
*p++ = 'D'; |
| 916 |
*p = '\0'; |
| 917 |
|
| 918 |
if (HasUMode(source_p, UMODE_ADMIN) && ConfigServerHide.hide_server_ips == 0) |
| 919 |
sendto_one_numeric(source_p, &me, RPL_STATSPLINE, 'P', listener->port, |
| 920 |
listener->name, |
| 921 |
listener->ref_count, buf, |
| 922 |
listener->active == true ? "active" : "disabled"); |
| 923 |
else |
| 924 |
sendto_one_numeric(source_p, &me, RPL_STATSPLINE, 'P', listener->port, |
| 925 |
me.name, listener->ref_count, buf, |
| 926 |
listener->active == true ? "active" : "disabled"); |
| 927 |
} |
| 928 |
} |
| 929 |
|
| 930 |
static void |
| 931 |
stats_tstats(struct Client *source_p, int parc, char *parv[]) |
| 932 |
{ |
| 933 |
dlink_node *node; |
| 934 |
struct ServerStatistics sp = ServerStats; |
| 935 |
|
| 936 |
DLINK_FOREACH(node, local_server_list.head) |
| 937 |
{ |
| 938 |
const struct Client *target_p = node->data; |
| 939 |
|
| 940 |
sp.is_sbs += target_p->connection->send.bytes; |
| 941 |
sp.is_sbr += target_p->connection->recv.bytes; |
| 942 |
sp.is_sti += event_base->time.sec_monotonic - target_p->connection->created_monotonic; |
| 943 |
sp.is_sv++; |
| 944 |
} |
| 945 |
|
| 946 |
DLINK_FOREACH(node, local_client_list.head) |
| 947 |
{ |
| 948 |
const struct Client *target_p = node->data; |
| 949 |
|
| 950 |
sp.is_cbs += target_p->connection->send.bytes; |
| 951 |
sp.is_cbr += target_p->connection->recv.bytes; |
| 952 |
sp.is_cti += event_base->time.sec_monotonic - target_p->connection->created_monotonic; |
| 953 |
sp.is_cl++; |
| 954 |
} |
| 955 |
|
| 956 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 957 |
"t :accepts %u refused %u", |
| 958 |
sp.is_ac, sp.is_ref); |
| 959 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 960 |
"t :unknown commands %u prefixes %u", |
| 961 |
sp.is_unco, sp.is_unpf); |
| 962 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 963 |
"t :nick collisions %u unknown closes %u", |
| 964 |
sp.is_kill, sp.is_ni); |
| 965 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 966 |
"t :wrong direction %u empty %u", |
| 967 |
sp.is_wrdi, sp.is_empt); |
| 968 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 969 |
"t :numerics seen %u", |
| 970 |
sp.is_num); |
| 971 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 972 |
"t :auth successes %u fails %u", |
| 973 |
sp.is_asuc, sp.is_abad); |
| 974 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 975 |
"t :Client Server"); |
| 976 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 977 |
"t :connected %u %u", |
| 978 |
sp.is_cl, sp.is_sv); |
| 979 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 980 |
"t :bytes sent %ju %ju", |
| 981 |
sp.is_cbs, sp.is_sbs); |
| 982 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 983 |
"t :bytes received %ju %ju", |
| 984 |
sp.is_cbr, sp.is_sbr); |
| 985 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 986 |
"t :time connected %ju %ju", |
| 987 |
sp.is_cti, sp.is_sti); |
| 988 |
} |
| 989 |
|
| 990 |
static void |
| 991 |
stats_uptime(struct Client *source_p, int parc, char *parv[]) |
| 992 |
{ |
| 993 |
if (!HasUMode(source_p, UMODE_OPER) && ConfigGeneral.stats_u_oper_only) |
| 994 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
| 995 |
else |
| 996 |
{ |
| 997 |
sendto_one_numeric(source_p, &me, RPL_STATSUPTIME, |
| 998 |
time_dissect(event_base->time.sec_monotonic - me.connection->created_monotonic)); |
| 999 |
if (ConfigServerHide.disable_remote_commands == 0 || HasUMode(source_p, UMODE_OPER)) |
| 1000 |
sendto_one_numeric(source_p, &me, RPL_STATSCONN, Count.max_loc_con, |
| 1001 |
Count.max_loc, Count.totalrestartcount); |
| 1002 |
} |
| 1003 |
} |
| 1004 |
|
| 1005 |
static void |
| 1006 |
stats_shared(struct Client *source_p, int parc, char *parv[]) |
| 1007 |
{ |
| 1008 |
report_shared(source_p); |
| 1009 |
report_cluster(source_p); |
| 1010 |
} |
| 1011 |
|
| 1012 |
/* stats_servers() |
| 1013 |
* |
| 1014 |
* input - client pointer |
| 1015 |
* output - none |
| 1016 |
* side effects - client is shown lists of who connected servers |
| 1017 |
*/ |
| 1018 |
static void |
| 1019 |
stats_servers(struct Client *source_p, int parc, char *parv[]) |
| 1020 |
{ |
| 1021 |
dlink_node *node; |
| 1022 |
|
| 1023 |
DLINK_FOREACH(node, local_server_list.head) |
| 1024 |
{ |
| 1025 |
const struct Client *target_p = node->data; |
| 1026 |
|
| 1027 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 1028 |
"v :%s (%s!%s@%s) Idle: %s", |
| 1029 |
target_p->name, |
| 1030 |
(target_p->serv->by[0] ? target_p->serv->by : "Remote."), |
| 1031 |
"*", "*", time_dissect(event_base->time.sec_monotonic - target_p->connection->last_data)); |
| 1032 |
} |
| 1033 |
|
| 1034 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 1035 |
"v :%u Server(s)", |
| 1036 |
dlink_list_length(&local_server_list)); |
| 1037 |
} |
| 1038 |
|
| 1039 |
static void |
| 1040 |
stats_class(struct Client *source_p, int parc, char *parv[]) |
| 1041 |
{ |
| 1042 |
dlink_node *node; |
| 1043 |
|
| 1044 |
DLINK_FOREACH(node, class_get_list()->head) |
| 1045 |
{ |
| 1046 |
const struct ClassItem *class = node->data; |
| 1047 |
|
| 1048 |
sendto_one_numeric(source_p, &me, RPL_STATSYLINE, 'Y', |
| 1049 |
class->name, class->ping_freq, |
| 1050 |
class->con_freq, |
| 1051 |
class->max_total, class->max_sendq, |
| 1052 |
class->max_recvq, |
| 1053 |
class->ref_count, |
| 1054 |
class->number_per_cidr, class->cidr_bitlen_ipv4, |
| 1055 |
class->number_per_cidr, class->cidr_bitlen_ipv6, |
| 1056 |
class->active ? "active" : "disabled"); |
| 1057 |
} |
| 1058 |
} |
| 1059 |
|
| 1060 |
static void |
| 1061 |
stats_servlinks(struct Client *source_p, int parc, char *parv[]) |
| 1062 |
{ |
| 1063 |
dlink_node *node; |
| 1064 |
uintmax_t sendB = 0, recvB = 0; |
| 1065 |
|
| 1066 |
DLINK_FOREACH(node, local_server_list.head) |
| 1067 |
{ |
| 1068 |
const struct Client *target_p = node->data; |
| 1069 |
|
| 1070 |
sendB += target_p->connection->send.bytes; |
| 1071 |
recvB += target_p->connection->recv.bytes; |
| 1072 |
|
| 1073 |
/* ":%s 211 %s %s %u %u %ju %u %ju :%ju %ju %s" */ |
| 1074 |
sendto_one_numeric(source_p, &me, RPL_STATSLINKINFO, |
| 1075 |
client_get_name(target_p, HasUMode(source_p, UMODE_ADMIN) ? SHOW_IP : MASK_IP), |
| 1076 |
dbuf_length(&target_p->connection->buf_sendq), |
| 1077 |
target_p->connection->send.messages, |
| 1078 |
target_p->connection->send.bytes >> 10, |
| 1079 |
target_p->connection->recv.messages, |
| 1080 |
target_p->connection->recv.bytes >> 10, |
| 1081 |
(event_base->time.sec_monotonic - target_p->connection->created_monotonic), |
| 1082 |
(event_base->time.sec_monotonic - target_p->connection->last_data), |
| 1083 |
capab_get(target_p)); |
| 1084 |
} |
| 1085 |
|
| 1086 |
sendB >>= 10; |
| 1087 |
recvB >>= 10; |
| 1088 |
|
| 1089 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, "? :%u total server(s)", |
| 1090 |
dlink_list_length(&local_server_list)); |
| 1091 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, "? :Sent total: %7.2f %s", |
| 1092 |
_GMKv(sendB), _GMKs(sendB)); |
| 1093 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, "? :Recv total: %7.2f %s", |
| 1094 |
_GMKv(recvB), _GMKs(recvB)); |
| 1095 |
|
| 1096 |
const uintmax_t uptime = (event_base->time.sec_monotonic - me.connection->created_monotonic); |
| 1097 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 1098 |
"? :Server send: %7.2f %s (%4.1f KiB/s)", |
| 1099 |
_GMKv((me.connection->send.bytes >> 10)), |
| 1100 |
_GMKs((me.connection->send.bytes >> 10)), |
| 1101 |
(float)((float)((me.connection->send.bytes) >> 10) / |
| 1102 |
(float)uptime)); |
| 1103 |
sendto_one_numeric(source_p, &me, RPL_STATSDEBUG | SND_EXPLICIT, |
| 1104 |
"? :Server recv: %7.2f %s (%4.1f KiB/s)", |
| 1105 |
_GMKv((me.connection->recv.bytes >> 10)), |
| 1106 |
_GMKs((me.connection->recv.bytes >> 10)), |
| 1107 |
(float)((float)((me.connection->recv.bytes) >> 10) / |
| 1108 |
(float)uptime)); |
| 1109 |
} |
| 1110 |
|
| 1111 |
/* parse_stats_args() |
| 1112 |
* |
| 1113 |
* inputs - arg count |
| 1114 |
* - args |
| 1115 |
* - doall flag |
| 1116 |
* - wild card or not |
| 1117 |
* output - pointer to name to use |
| 1118 |
* side effects - |
| 1119 |
* common parse routine for m_stats args |
| 1120 |
* |
| 1121 |
*/ |
| 1122 |
static const char * |
| 1123 |
parse_stats_args(struct Client *source_p, int parc, char *parv[], bool *doall, bool *wilds) |
| 1124 |
{ |
| 1125 |
if (parc > 2) |
| 1126 |
{ |
| 1127 |
const char *name = parv[2]; |
| 1128 |
|
| 1129 |
if (irccmp(name, ID_or_name(&me, source_p)) == 0) |
| 1130 |
*doall = true; |
| 1131 |
else if (match(name, ID_or_name(&me, source_p)) == 0) |
| 1132 |
*doall = true; |
| 1133 |
|
| 1134 |
*wilds = has_wildcards(name); |
| 1135 |
|
| 1136 |
return name; |
| 1137 |
} |
| 1138 |
|
| 1139 |
return NULL; |
| 1140 |
} |
| 1141 |
|
| 1142 |
static void |
| 1143 |
stats_L_list(struct Client *source_p, const char *name, bool doall, bool wilds, |
| 1144 |
dlink_list *list, const char statchar) |
| 1145 |
{ |
| 1146 |
dlink_node *node; |
| 1147 |
|
| 1148 |
/* |
| 1149 |
* Send info about connections which match, or all if the |
| 1150 |
* mask matches from. |
| 1151 |
*/ |
| 1152 |
DLINK_FOREACH(node, list->head) |
| 1153 |
{ |
| 1154 |
const struct Client *target_p = node->data; |
| 1155 |
enum addr_mask_type type; |
| 1156 |
|
| 1157 |
if (!doall && wilds && match(name, target_p->name)) |
| 1158 |
continue; |
| 1159 |
|
| 1160 |
if (!(doall || wilds) && irccmp(name, target_p->name)) |
| 1161 |
continue; |
| 1162 |
|
| 1163 |
if (IsUpper(statchar)) |
| 1164 |
type = SHOW_IP; |
| 1165 |
else |
| 1166 |
type = HIDE_IP; |
| 1167 |
|
| 1168 |
if (IsServer(target_p) || IsConnecting(target_p) || IsHandshake(target_p)) |
| 1169 |
if (!HasUMode(source_p, UMODE_ADMIN)) |
| 1170 |
type = MASK_IP; |
| 1171 |
|
| 1172 |
sendto_one_numeric(source_p, &me, RPL_STATSLINKINFO, |
| 1173 |
client_get_name(target_p, type), |
| 1174 |
dbuf_length(&target_p->connection->buf_sendq), |
| 1175 |
target_p->connection->send.messages, |
| 1176 |
target_p->connection->send.bytes >> 10, |
| 1177 |
target_p->connection->recv.messages, |
| 1178 |
target_p->connection->recv.bytes >> 10, |
| 1179 |
(event_base->time.sec_monotonic - target_p->connection->created_monotonic), |
| 1180 |
(event_base->time.sec_monotonic - target_p->connection->last_data), |
| 1181 |
IsServer(target_p) ? capab_get(target_p) : "-"); |
| 1182 |
} |
| 1183 |
} |
| 1184 |
|
| 1185 |
/* |
| 1186 |
* stats_L |
| 1187 |
* |
| 1188 |
* inputs - pointer to client to report to |
| 1189 |
* - doall flag |
| 1190 |
* - wild card or not |
| 1191 |
* output - NONE |
| 1192 |
* side effects - |
| 1193 |
*/ |
| 1194 |
static void |
| 1195 |
stats_L(struct Client *source_p, const char *name, bool doall, |
| 1196 |
bool wilds, const char statchar) |
| 1197 |
{ |
| 1198 |
stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar); |
| 1199 |
stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar); |
| 1200 |
stats_L_list(source_p, name, doall, wilds, &local_server_list, statchar); |
| 1201 |
} |
| 1202 |
|
| 1203 |
static void |
| 1204 |
stats_ltrace(struct Client *source_p, int parc, char *parv[]) |
| 1205 |
{ |
| 1206 |
bool doall = false; |
| 1207 |
bool wilds = false; |
| 1208 |
const char *name; |
| 1209 |
|
| 1210 |
if ((name = parse_stats_args(source_p, parc, parv, &doall, &wilds))) |
| 1211 |
{ |
| 1212 |
const char statchar = *parv[1]; |
| 1213 |
stats_L(source_p, name, doall, wilds, statchar); |
| 1214 |
} |
| 1215 |
else |
| 1216 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "STATS"); |
| 1217 |
} |
| 1218 |
|
| 1219 |
struct StatsStruct |
| 1220 |
{ |
| 1221 |
unsigned char letter; |
| 1222 |
void (*handler)(struct Client *, int, char *[]); |
| 1223 |
unsigned int required_modes; |
| 1224 |
}; |
| 1225 |
|
| 1226 |
static const struct StatsStruct *stats_map[256]; |
| 1227 |
static const struct StatsStruct stats_tab[] = |
| 1228 |
{ |
| 1229 |
{ .letter = 'a', .handler = stats_dns_servers, .required_modes = UMODE_ADMIN }, |
| 1230 |
{ .letter = 'A', .handler = stats_dns_servers, .required_modes = UMODE_ADMIN }, |
| 1231 |
{ .letter = 'c', .handler = stats_connect, .required_modes = UMODE_OPER }, |
| 1232 |
{ .letter = 'C', .handler = stats_connect, .required_modes = UMODE_OPER }, |
| 1233 |
{ .letter = 'd', .handler = stats_tdeny, .required_modes = UMODE_OPER }, |
| 1234 |
{ .letter = 'D', .handler = stats_deny, .required_modes = UMODE_OPER }, |
| 1235 |
{ .letter = 'e', .handler = stats_exempt, .required_modes = UMODE_OPER }, |
| 1236 |
{ .letter = 'E', .handler = stats_events, .required_modes = UMODE_ADMIN }, |
| 1237 |
{ .letter = 'f', .handler = stats_fdlist, .required_modes = UMODE_ADMIN }, |
| 1238 |
{ .letter = 'F', .handler = stats_fdlist, .required_modes = UMODE_ADMIN }, |
| 1239 |
{ .letter = 'h', .handler = stats_hubleaf, .required_modes = UMODE_OPER }, |
| 1240 |
{ .letter = 'H', .handler = stats_hubleaf, .required_modes = UMODE_OPER }, |
| 1241 |
{ .letter = 'i', .handler = stats_auth }, |
| 1242 |
{ .letter = 'I', .handler = stats_auth }, |
| 1243 |
{ .letter = 'k', .handler = stats_tkill }, |
| 1244 |
{ .letter = 'K', .handler = stats_kill }, |
| 1245 |
{ .letter = 'l', .handler = stats_ltrace, .required_modes = UMODE_OPER }, |
| 1246 |
{ .letter = 'L', .handler = stats_ltrace, .required_modes = UMODE_OPER }, |
| 1247 |
{ .letter = 'm', .handler = stats_messages }, |
| 1248 |
{ .letter = 'M', .handler = stats_messages }, |
| 1249 |
{ .letter = 'o', .handler = stats_operator }, |
| 1250 |
{ .letter = 'O', .handler = stats_operator }, |
| 1251 |
{ .letter = 'p', .handler = stats_operedup }, |
| 1252 |
{ .letter = 'P', .handler = stats_ports }, |
| 1253 |
{ .letter = 'q', .handler = stats_resv, .required_modes = UMODE_OPER }, |
| 1254 |
{ .letter = 'Q', .handler = stats_resv, .required_modes = UMODE_OPER }, |
| 1255 |
{ .letter = 's', .handler = stats_pseudo, .required_modes = UMODE_OPER }, |
| 1256 |
{ .letter = 'S', .handler = stats_service, .required_modes = UMODE_OPER }, |
| 1257 |
{ .letter = 't', .handler = stats_tstats, .required_modes = UMODE_OPER }, |
| 1258 |
{ .letter = 'T', .handler = motd_report, .required_modes = UMODE_OPER }, |
| 1259 |
{ .letter = 'u', .handler = stats_uptime }, |
| 1260 |
{ .letter = 'U', .handler = stats_shared, .required_modes = UMODE_OPER }, |
| 1261 |
{ .letter = 'v', .handler = stats_servers, .required_modes = UMODE_OPER }, |
| 1262 |
{ .letter = 'x', .handler = stats_gecos, .required_modes = UMODE_OPER }, |
| 1263 |
{ .letter = 'X', .handler = stats_gecos, .required_modes = UMODE_OPER }, |
| 1264 |
{ .letter = 'y', .handler = stats_class, .required_modes = UMODE_OPER }, |
| 1265 |
{ .letter = 'Y', .handler = stats_class, .required_modes = UMODE_OPER }, |
| 1266 |
{ .letter = 'z', .handler = stats_memory, .required_modes = UMODE_OPER }, |
| 1267 |
{ .letter = '?', .handler = stats_servlinks, .required_modes = UMODE_OPER }, |
| 1268 |
{ .letter = '\0' } |
| 1269 |
}; |
| 1270 |
|
| 1271 |
static void |
| 1272 |
do_stats(struct Client *source_p, int parc, char *parv[]) |
| 1273 |
{ |
| 1274 |
const unsigned char statchar = *parv[1]; |
| 1275 |
const struct StatsStruct *tab; |
| 1276 |
|
| 1277 |
if (statchar == '\0') |
| 1278 |
{ |
| 1279 |
sendto_one_numeric(source_p, &me, RPL_ENDOFSTATS, '*'); |
| 1280 |
return; |
| 1281 |
} |
| 1282 |
|
| 1283 |
if ((tab = stats_map[statchar])) |
| 1284 |
{ |
| 1285 |
if (tab->required_modes == 0 || HasUMode(source_p, tab->required_modes)) |
| 1286 |
tab->handler(source_p, parc, parv); |
| 1287 |
else |
| 1288 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
| 1289 |
|
| 1290 |
sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE, |
| 1291 |
"STATS %c requested by %s (%s@%s) [%s]", |
| 1292 |
statchar, source_p->name, source_p->username, |
| 1293 |
source_p->host, source_p->servptr->name); |
| 1294 |
} |
| 1295 |
|
| 1296 |
sendto_one_numeric(source_p, &me, RPL_ENDOFSTATS, statchar); |
| 1297 |
} |
| 1298 |
|
| 1299 |
/* |
| 1300 |
* m_stats() |
| 1301 |
* parv[0] = command |
| 1302 |
* parv[1] = stat letter/command |
| 1303 |
* parv[2] = (if present) server/mask in stats L |
| 1304 |
*/ |
| 1305 |
static void |
| 1306 |
m_stats(struct Client *source_p, int parc, char *parv[]) |
| 1307 |
{ |
| 1308 |
static uintmax_t last_used = 0; |
| 1309 |
|
| 1310 |
/* Check the user is actually allowed to do /stats, and isn't flooding */ |
| 1311 |
if ((last_used + ConfigGeneral.pace_wait) > event_base->time.sec_monotonic) |
| 1312 |
{ |
| 1313 |
sendto_one_numeric(source_p, &me, RPL_LOAD2HI, "STATS"); |
| 1314 |
return; |
| 1315 |
} |
| 1316 |
|
| 1317 |
last_used = event_base->time.sec_monotonic; |
| 1318 |
|
| 1319 |
/* Is the stats meant for us? */ |
| 1320 |
if (ConfigServerHide.disable_remote_commands == 0) |
| 1321 |
if (server_hunt(source_p, ":%s STATS %s :%s", 2, parv)->ret != HUNTED_ISME) |
| 1322 |
return; |
| 1323 |
|
| 1324 |
do_stats(source_p, parc, parv); |
| 1325 |
} |
| 1326 |
|
| 1327 |
/* |
| 1328 |
* ms_stats() |
| 1329 |
* parv[0] = command |
| 1330 |
* parv[1] = stat letter/command |
| 1331 |
* parv[2] = (if present) server/mask in stats L, or target |
| 1332 |
*/ |
| 1333 |
static void |
| 1334 |
ms_stats(struct Client *source_p, int parc, char *parv[]) |
| 1335 |
{ |
| 1336 |
if (server_hunt(source_p, ":%s STATS %s :%s", 2, parv)->ret != HUNTED_ISME) |
| 1337 |
return; |
| 1338 |
|
| 1339 |
do_stats(source_p, parc, parv); |
| 1340 |
} |
| 1341 |
|
| 1342 |
static void |
| 1343 |
stats_init(void) |
| 1344 |
{ |
| 1345 |
for (const struct StatsStruct *tab = stats_tab; tab->letter; ++tab) |
| 1346 |
stats_map[tab->letter] = tab; |
| 1347 |
} |
| 1348 |
|
| 1349 |
static struct Message stats_msgtab = |
| 1350 |
{ |
| 1351 |
.cmd = "STATS", |
| 1352 |
.handlers[UNREGISTERED_HANDLER] = { .handler = m_unregistered }, |
| 1353 |
.handlers[CLIENT_HANDLER] = { .handler = m_stats, .args_min = 2 }, |
| 1354 |
.handlers[SERVER_HANDLER] = { .handler = ms_stats, .args_min = 3 }, |
| 1355 |
.handlers[ENCAP_HANDLER] = { .handler = m_ignore }, |
| 1356 |
.handlers[OPER_HANDLER] = { .handler = m_stats, .args_min = 2 } |
| 1357 |
}; |
| 1358 |
|
| 1359 |
static void |
| 1360 |
module_init(void) |
| 1361 |
{ |
| 1362 |
stats_init(); |
| 1363 |
mod_add_cmd(&stats_msgtab); |
| 1364 |
} |
| 1365 |
|
| 1366 |
static void |
| 1367 |
module_exit(void) |
| 1368 |
{ |
| 1369 |
mod_del_cmd(&stats_msgtab); |
| 1370 |
} |
| 1371 |
|
| 1372 |
struct module module_entry = |
| 1373 |
{ |
| 1374 |
.version = "$Revision$", |
| 1375 |
.modinit = module_init, |
| 1376 |
.modexit = module_exit, |
| 1377 |
}; |