* note: it is guaranteed that parv[0]..parv[parc-1] are all
* non-NULL pointers.
*/
-#if 0
-/*
- * No need to include handlers.h here the signatures must match
- * and we don't need to force a rebuild of all the handlers everytime
- * we add a new one to the list. --Bleep
- */
+#include "config.h"
+
#include "handlers.h"
-#endif /* 0 */
/*
* XXX - ack!!!
*/
#include "ircd.h"
#include "ircd_alloc.h"
#include "ircd_chattr.h"
+#include "ircd_events.h"
+#include "ircd_features.h"
+#include "ircd_policy.h"
#include "ircd_reply.h"
#include "ircd_string.h"
#include "list.h"
#include "listener.h"
#include "match.h"
+#include "motd.h"
#include "msg.h"
#include "numeric.h"
#include "numnicks.h"
#include <string.h>
+int report_klines(struct Client* sptr, char* mask, int limit_query)
+{
+ int wilds = 0;
+ int count = 3;
+ char* user = 0;
+ char* host;
+ const struct DenyConf* conf;
+
+ if (EmptyString(mask)) {
+ if (limit_query)
+ return need_more_params(sptr, "STATS K");
+ else
+ report_deny_list(sptr);
+ return 1;
+ }
+
+ if (!limit_query) {
+ wilds = string_has_wildcards(mask);
+ count = 1000;
+ }
+
+ if ((host = strchr(mask, '@'))) {
+ user = mask;
+ *host++ = '\0';
+ }
+ else {
+ host = mask;
+ }
+
+ for (conf = conf_get_deny_list(); conf; conf = conf->next) {
+ if ((!wilds && ((user || conf->hostmask) &&
+ !match(conf->hostmask, host) &&
+ (!user || !match(conf->usermask, user)))) ||
+ (wilds && !mmatch(host, conf->hostmask) &&
+ (!user || !mmatch(user, conf->usermask))))
+ {
+ send_reply(sptr, RPL_STATSKLINE,
+ (conf->flags & DENY_FLAGS_IP) ? 'k' : 'K',
+ conf->hostmask, conf->message, conf->usermask);
+ if (--count == 0)
+ return 1;
+ }
+ }
+ /* send_reply(sptr, RPL_ENDOFSTATS, stat); */
+ return 1;
+}
+
+
/*
* m_stats - generic message handler
*
*/
int m_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
- struct Message *mptr;
- struct Client *acptr;
- struct ConfItem *aconf;
char stat = parc > 1 ? parv[1][0] : '\0';
const char **infotext = statsinfo;
- int i;
- if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
+ if (hunt_stats(cptr, sptr, parc, parv, stat, HEAD_IN_SAND_REMOTE)
+ != HUNTED_ISME)
return 0;
switch (stat)
{
case 'L':
case 'l':
+#ifdef HEAD_IN_SAND_STATS_L
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
{
- int doall = 0, wilds = 0;
+ struct Client *acptr;
+ int i;
+ int doall = 0;
+ int wilds = 0;
char *name = "*";
- if (parc > 3 && *parv[3])
- {
- char *p;
+
+ if (parc > 3 && !EmptyString(parv[3])) {
name = parv[3];
- wilds = (*name == '*' || *name == '?');
- for (p = name + 1; *p; ++p)
- if ((*p == '*' || *p == '?') && p[-1] != '\\')
- {
- wilds = 1;
- break;
- }
+ wilds = string_has_wildcards(name);
}
else
doall = 1;
* a wild card based search to list it.
*/
send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
- "SendM SendKBytes RcveM RcveKBytes :Open since");
+ "SendM SendKBytes RcveM RcveKBytes :Open since");
for (i = 0; i <= HighestFd; i++)
{
if (!(acptr = LocalClientArray[i]))
if (IsInvisible(acptr) && (doall || wilds) && !IsAnOper(acptr) && (acptr != sptr))
continue;
/* Only show the ones that match the given mask - if any */
- if (!doall && wilds && match(name, acptr->name))
+ if (!doall && wilds && match(name, cli_name(acptr)))
continue;
/* Skip all that do not match the specific query */
- if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
+ if (!(doall || wilds) && 0 != ircd_strcmp(name, cli_name(acptr)))
continue;
- send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
- "%s %u %u %u %u %u :%Tu", (*acptr->name) ? acptr->name : "<unregistered>",
- (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
- (int)acptr->sendK, (int)acptr->receiveM,
- (int)acptr->receiveK, CurrentTime - acptr->firsttime);
+ send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
+ "%s %u %u %u %u %u :%Tu", (*(cli_name(acptr))) ? cli_name(acptr) : "<unregistered>",
+ (int)MsgQLength(&(cli_sendQ(acptr))), (int)cli_sendM(acptr),
+ (int)cli_sendK(acptr), (int)cli_receiveM(acptr),
+ (int)cli_receiveK(acptr), CurrentTime - cli_firsttime(acptr));
}
- break;
}
+#endif
+ break;
+
case 'C':
case 'c':
+#ifdef HEAD_IN_SAND_STATS_C
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
report_configured_links(sptr, CONF_SERVER);
+#endif
+ break;
+
+ case 'E':
+ case 'e': /* report engine name */
+#ifdef HEAD_IN_SAND_STATS_E
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
+ send_reply(sptr, RPL_STATSENGINE, engine_name());
+#endif
break;
+
case 'G':
case 'g': /* send glines */
+#ifdef HEAD_IN_SAND_STATS_G
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
gline_stats(sptr);
+#endif
break;
+
case 'H':
case 'h':
+#ifdef HEAD_IN_SAND_STATS_H
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
report_configured_links(sptr, CONF_HUB | CONF_LEAF);
+#endif
+ break;
+
+ case 'K':
+ case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
+#ifdef HEAD_IN_SAND_STATS_K
+ /* Simple version - if you want to fix it - send in a patch */
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
+ if (0 == report_klines(sptr, (parc == 4) ? parv[3] : 0, 0))
+ return 0;
+#endif
+ break;
+ case 'F':
+ case 'f':
+#ifdef HEAD_IN_SAND_STATS_F
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
+ feature_report(sptr);
+#endif
break;
+
case 'I':
case 'i':
- case 'K':
- case 'k': /* display CONF_IPKILL as well
- as CONF_KILL -Kev */
+#ifdef HEAD_IN_SAND_STATS_I
+ /* Simple version - if you want to fix it - send in a patch */
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
{
- int wilds, count;
- char *user, *host, *p;
- int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
- if (parc < 4)
- {
- report_configured_links(sptr, conf_status);
- break;
- }
-
- wilds = 0;
- for (p = parv[3]; *p; p++)
- {
- if (*p == '\\')
- {
- if (!*++p)
- break;
- continue;
- }
- if (*p == '?' || *p == '*')
- {
- wilds = 1;
- break;
- }
- }
-
- count = 1000;
+ struct ConfItem *aconf;
+ int wilds = 0;
+ int count = 1000;
+ char* host;
- if (conf_status == CONF_CLIENT)
- {
- user = 0; /* Not used, but to avoid compiler warning. */
-
- host = parv[3];
- }
- else
- {
- if ((host = strchr(parv[3], '@')))
- {
- user = parv[3];
- *host++ = 0;;
- }
- else
- {
- user = 0;
- host = parv[3];
- }
+ if (parc < 4) {
+ report_configured_links(sptr, CONF_CLIENT);
+ break;
}
- for (aconf = GlobalConfList; aconf; aconf = aconf->next)
- {
- if ((aconf->status & conf_status))
- {
- if (conf_status == CONF_KLINE)
- {
- if ((!wilds && ((user || aconf->host[1]) &&
- !match(aconf->host, host) &&
- (!user || !match(aconf->name, user)))) ||
- (wilds && !mmatch(host, aconf->host) &&
- (!user || !mmatch(user, aconf->name))))
- {
- send_reply(sptr, RPL_STATSKLINE,
- (aconf->status & CONF_KILL) ? 'K' : 'k', aconf->host,
- aconf->passwd, aconf->name, aconf->port,
- get_conf_class(aconf));
- if (--count == 0)
- break;
- }
- }
- else if (conf_status == CONF_CLIENT)
- {
- if ((!wilds && (!match(aconf->host, host) ||
- !match(aconf->name, host))) ||
- (wilds && (!mmatch(host, aconf->host) ||
- !mmatch(host, aconf->name))))
- {
- send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
- aconf->port, get_conf_class(aconf));
- if (--count == 0)
- break;
- }
- }
- }
+ if (EmptyString(parv[3]))
+ return need_more_params(sptr, "STATS I");
+
+ host = parv[3];
+ wilds = string_has_wildcards(host);
+
+ for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
+ if (CONF_CLIENT == aconf->status) {
+ if ((!wilds && (!match(aconf->host, host) ||
+ !match(aconf->name, host))) ||
+ (wilds && (!mmatch(host, aconf->host) ||
+ !mmatch(host, aconf->name))))
+ {
+ send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
+ aconf->port, get_conf_class(aconf));
+ if (--count == 0)
+ break;
+ }
+ }
}
- break;
}
+#endif
+ break;
+
case 'M':
+#ifdef HEAD_IN_SAND_STATS_M
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
#if !defined(NDEBUG)
send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
- fda_get_block_count());
-#endif
-
-#if 0
-#ifdef MEMSIZESTATS
- sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
- me.name, parv[0], get_mem_size(), get_alloc_cnt());
+ fda_get_block_count());
#endif
-#ifdef MEMLEAKSTATS
- report_memleak_stats(sptr, parc, parv);
#endif
-#if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
- sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
- "is not enabled on this server", me.name, parv[0]);
-#endif
-#endif /* 0 */
break;
+
case 'm':
+#ifdef HEAD_IN_SAND_STATS_m
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
+ {
+ struct Message *mptr;
+
for (mptr = msgtab; mptr->cmd; mptr++)
if (mptr->count)
- send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
- mptr->bytes);
+ send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
+ mptr->bytes);
+ }
+#endif
break;
+
case 'o':
case 'O':
+#ifdef HEAD_IN_SAND_STATS_O
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
report_configured_links(sptr, CONF_OPS);
+#endif
break;
+
case 'p':
case 'P':
/*
* show hidden ports to opers, if there are more than 3 parameters,
* interpret the fourth parameter as the port number.
*/
+#ifdef HEAD_IN_SAND_STATS_P
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
show_ports(sptr, 0, (parc > 3) ? atoi(parv[3]) : 0, 100);
+#endif
break;
+
case 'R':
case 'r':
+#ifdef HEAD_IN_SAND_STATS_R
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
#ifdef DEBUGMODE
send_usage(sptr, parv[0]);
+#endif
#endif
break;
+
case 'D':
- report_configured_links(sptr, CONF_CRULEALL);
+#ifdef HEAD_IN_SAND_STATS_D
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
+ report_crule_list(sptr, CRULE_ALL);
+#endif
break;
+
case 'd':
- report_configured_links(sptr, CONF_CRULE);
+#ifdef HEAD_IN_SAND_STATS_d
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
+ report_crule_list(sptr, CRULE_MASK);
+#endif
break;
+
case 't':
+#ifdef HEAD_IN_SAND_STATS_t
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
tstats(sptr, parv[0]);
+#endif
break;
+
case 'T':
- report_configured_links(sptr, CONF_TLINES);
+#ifdef HEAD_IN_SAND_STATS_T
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
+ motd_report(sptr);
+#endif
break;
+
case 'U':
+#ifdef HEAD_IN_SAND_STATS_U
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
report_configured_links(sptr, CONF_UWORLD);
+#endif
break;
+
case 'u':
+#ifdef HEAD_IN_SAND_STATS_u
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
{
time_t nowr;
- nowr = CurrentTime - me.since;
+ nowr = CurrentTime - cli_since(&me);
send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
- (nowr / 60) % 60, nowr % 60);
+ (nowr / 60) % 60, nowr % 60);
send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
- break;
- }
- case 'v':
- {
- struct ConfClass *cltmp;
-
- for (cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp)) {
- if (Links(cltmp) > 0)
- send_reply(sptr,RPL_TRACECLASS, ConClass(cltmp), Links(cltmp));
- }
- break;
}
+#endif
+ break;
+
case 'W':
case 'w':
+#ifdef HEAD_IN_SAND_STATS_W
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
calc_load(sptr);
+#endif
break;
+
case 'X':
case 'x':
+#ifdef HEAD_IN_SAND_STATS_X
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
#ifdef DEBUGMODE
+ class_send_meminfo(sptr);
send_listinfo(sptr, parv[0]);
+#endif
#endif
break;
+
case 'Y':
case 'y':
+#ifdef HEAD_IN_SAND_STATS_Y
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
report_classes(sptr);
+#endif
break;
+
case 'Z':
case 'z':
+#ifdef HEAD_IN_SAND_STATS_Z
+ return m_not_oper(sptr,cptr,parc,parv);
+#else
count_memory(sptr, parv[0]);
+#endif
break;
+
default:
stat = '*';
while (*infotext)
- sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
break;
}
send_reply(sptr, RPL_ENDOFSTATS, stat);
char stat = parc > 1 ? parv[1][0] : '\0';
int i;
- if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
+ if (hunt_stats(cptr, sptr, parc, parv, stat, 0) != HUNTED_ISME)
return 0;
switch (stat)
case 'L':
case 'l':
{
- int doall = 0, wilds = 0;
+ int doall = 0;
+ int wilds = 0;
char *name = "*";
- if (parc > 3 && *parv[3])
- {
- char *p;
+
+ if (parc > 3 && !EmptyString(parv[3])) {
name = parv[3];
- wilds = (*name == '*' || *name == '?');
- for (p = name + 1; *p; ++p)
- if ((*p == '*' || *p == '?') && p[-1] != '\\')
- {
- wilds = 1;
- break;
- }
+ wilds = string_has_wildcards(name);
}
else
doall = 1;
* a wild card based search to list it.
*/
send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
- "SendM SendKBytes RcveM RcveKBytes :Open since");
+ "SendM SendKBytes RcveM RcveKBytes :Open since");
for (i = 0; i <= HighestFd; i++)
{
if (!(acptr = LocalClientArray[i]))
continue;
/* Don't show invisible people to unauthorized people when using
* wildcards -- Is this still needed now /stats is oper only ?
- * Not here, because ms_stats is specifically a remote command,
- * thus the check was removed. -Ghostwolf */
+ * Not here, because ms_stats is specifically a remote command,
+ * thus the check was removed. -Ghostwolf */
/* Only show the ones that match the given mask - if any */
- if (!doall && wilds && match(name, acptr->name))
+ if (!doall && wilds && match(name, cli_name(acptr)))
continue;
/* Skip all that do not match the specific query */
- if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
+ if (!(doall || wilds) && 0 != ircd_strcmp(name, cli_name(acptr)))
continue;
- send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
- "%s %u %u %u %u %u :%Tu", acptr->name,
- (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
- (int)acptr->sendK, (int)acptr->receiveM,
- (int)acptr->receiveK, CurrentTime - acptr->firsttime);
+ send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
+ "%s %u %u %u %u %u :%Tu", cli_name(acptr),
+ (int)MsgQLength(&(cli_sendQ(acptr))), (int)cli_sendM(acptr),
+ (int)cli_sendK(acptr), (int)cli_receiveM(acptr),
+ (int)cli_receiveK(acptr), CurrentTime - cli_firsttime(acptr));
}
break;
}
case 'c':
report_configured_links(sptr, CONF_SERVER);
break;
+ case 'E':
+ case 'e': /* report engine name */
+ send_reply(sptr, RPL_STATSENGINE, engine_name());
+ break;
case 'G':
case 'g': /* send glines */
gline_stats(sptr);
case 'h':
report_configured_links(sptr, CONF_HUB | CONF_LEAF);
break;
+ case 'K':
+ case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
+ if (0 == report_klines(sptr, (parc > 3) ? parv[3] : 0, !IsOper(sptr)))
+ return 0;
+ break;
+ case 'F':
+ case 'f':
+ feature_report(sptr);
+ break;
case 'I':
case 'i':
- case 'K':
- case 'k': /* display CONF_IPKILL as well
- as CONF_KILL -Kev */
{
- int wilds, count;
- char *user, *host, *p;
- int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
- if (IsOper(sptr) && parc < 4)
- {
- report_configured_links(sptr, conf_status);
+ int wilds = 0;
+ int count = 3;
+ char* host;
+
+ if (parc < 4 && IsOper(sptr)) {
+ report_configured_links(sptr, CONF_CLIENT);
break;
}
- if (parc < 4 || *parv[3] == '\0')
- return need_more_params(sptr,
- (conf_status & CONF_KLINE) ? "STATS K" : "STATS I");
+ if (parc < 4 || EmptyString(parv[3]))
+ return need_more_params(sptr, "STATS I");
- wilds = 0;
- for (p = parv[3]; *p; p++)
- {
- if (*p == '\\')
- {
- if (!*++p)
- break;
- continue;
- }
- if (*p == '?' || *p == '*')
- {
- wilds = 1;
- break;
- }
- }
- if (!IsOper(sptr))
- {
- wilds = 0;
- count = 3;
- }
- else
+ if (IsOper(sptr)) {
+ wilds = string_has_wildcards(parv[3]);
count = 1000;
+ }
- if (conf_status == CONF_CLIENT)
- {
- user = 0; /* Not used, but to avoid compiler warning. */
+ host = parv[3];
- host = parv[3];
- }
- else
- {
- if ((host = strchr(parv[3], '@')))
- {
- user = parv[3];
- *host++ = 0;;
- }
- else
- {
- user = 0;
- host = parv[3];
- }
- }
- for (aconf = GlobalConfList; aconf; aconf = aconf->next)
- {
- if ((aconf->status & conf_status))
- {
- if (conf_status == CONF_KLINE)
- {
- if ((!wilds && ((user || aconf->host[1]) &&
- !match(aconf->host, host) &&
- (!user || !match(aconf->name, user)))) ||
- (wilds && !mmatch(host, aconf->host) &&
- (!user || !mmatch(user, aconf->name))))
- {
- send_reply(sptr, RPL_STATSKLINE,
- (aconf->status & CONF_KILL) ? 'K' : 'k', aconf->host,
- aconf->passwd, aconf->name, aconf->port,
- get_conf_class(aconf));
- if (--count == 0)
- break;
- }
- }
- else if (conf_status == CONF_CLIENT)
- {
- if ((!wilds && (!match(aconf->host, host) ||
- !match(aconf->name, host))) ||
- (wilds && (!mmatch(host, aconf->host) ||
- !mmatch(host, aconf->name))))
- {
- send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
- aconf->port, get_conf_class(aconf));
- if (--count == 0)
- break;
- }
- }
- }
+ for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
+ if (CONF_CLIENT == aconf->status) {
+ if ((!wilds && (!match(aconf->host, host) ||
+ !match(aconf->name, host))) ||
+ (wilds && (!mmatch(host, aconf->host) ||
+ !mmatch(host, aconf->name))))
+ {
+ send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
+ aconf->port, get_conf_class(aconf));
+ if (--count == 0)
+ break;
+ }
+ }
}
break;
}
case 'M':
#if !defined(NDEBUG)
send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
- fda_get_block_count());
-#endif
-
-#if 0
-#ifdef MEMSIZESTATS
- sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
- me.name, parv[0], get_mem_size(), get_alloc_cnt());
-#endif
-#ifdef MEMLEAKSTATS
- report_memleak_stats(sptr, parc, parv);
-#endif
-#if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
- sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
- "is not enabled on this server", me.name, parv[0]);
+ fda_get_block_count());
#endif
-#endif /* 0 */
break;
case 'm':
for (mptr = msgtab; mptr->cmd; mptr++)
if (mptr->count)
- send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
- mptr->bytes);
+ send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
+ mptr->bytes);
break;
case 'o':
case 'O':
#endif
break;
case 'D':
- report_configured_links(sptr, CONF_CRULEALL);
+ report_crule_list(sptr, CRULE_ALL);
break;
case 'd':
- report_configured_links(sptr, CONF_CRULE);
+ report_crule_list(sptr, CRULE_MASK);
break;
case 't':
tstats(sptr, parv[0]);
break;
case 'T':
- report_configured_links(sptr, CONF_TLINES);
+ motd_report(sptr);
break;
case 'U':
report_configured_links(sptr, CONF_UWORLD);
{
time_t nowr;
- nowr = CurrentTime - me.since;
+ nowr = CurrentTime - cli_since(&me);
send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
- (nowr / 60) % 60, nowr % 60);
+ (nowr / 60) % 60, nowr % 60);
send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
break;
}
- case 'v':
- {
- struct ConfClass *cltmp;
-
- for (cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp)) {
- if (Links(cltmp) > 0)
- send_reply(sptr,RPL_TRACECLASS, ConClass(cltmp), Links(cltmp));
- }
- break;
- }
-
case 'W':
case 'w':
calc_load(sptr);
case 'X':
case 'x':
#ifdef DEBUGMODE
+ class_send_meminfo(sptr);
send_listinfo(sptr, parv[0]);
#endif
break;
*/
int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
- struct Message *mptr;
- struct Client *acptr;
- struct ConfItem *aconf;
- char stat = parc > 1 ? parv[1][0] : '\0';
- const char **infotext = statsinfo;
- int i;
-
- if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
+ struct Message* mptr;
+ struct Client* acptr;
+ struct ConfItem* aconf;
+ char stat = parc > 1 ? parv[1][0] : '\0';
+ const char** infotext = statsinfo;
+ int i;
+
+ if (hunt_stats(cptr, sptr, parc, parv, stat, HEAD_IN_SAND_REMOTE)
+ != HUNTED_ISME)
return 0;
switch (stat)
case 'l':
{
int doall = 0, wilds = 0;
- char *name = "*";
- if (parc > 3 && *parv[3])
- {
- char *p;
+ char* name = "*";
+ if (parc > 3 && !EmptyString(parv[3])) {
name = parv[3];
- wilds = (*name == '*' || *name == '?');
- for (p = name + 1; *p; ++p)
- if ((*p == '*' || *p == '?') && p[-1] != '\\')
- {
- wilds = 1;
- break;
- }
+ wilds = string_has_wildcards(name);
}
else
doall = 1;
* a wild card based search to list it.
*/
send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
- "SendM SendKBytes RcveM RcveKBytes :Open since");
+ "SendM SendKBytes RcveM RcveKBytes :Open since");
for (i = 0; i <= HighestFd; i++)
{
if (!(acptr = LocalClientArray[i]))
if (doall && IsUser(acptr))
continue;
/* Only show the ones that match the given mask - if any */
- if (!doall && wilds && match(name, acptr->name))
+ if (!doall && wilds && match(name, cli_name(acptr)))
continue;
/* Skip all that do not match the specific query */
- if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
+ if (!(doall || wilds) && 0 != ircd_strcmp(name, cli_name(acptr)))
continue;
- send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
- "%s %u %u %u %u %u :%Tu", acptr->name,
- (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
- (int)acptr->sendK, (int)acptr->receiveM,
- (int)acptr->receiveK, CurrentTime - acptr->firsttime);
+ send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
+ "%s %u %u %u %u %u :%Tu", cli_name(acptr),
+ (int)MsgQLength(&(cli_sendQ(acptr))), (int)cli_sendM(acptr),
+ (int)cli_sendK(acptr), (int)cli_receiveM(acptr),
+ (int)cli_receiveK(acptr), CurrentTime - cli_firsttime(acptr));
}
break;
}
case 'c':
report_configured_links(sptr, CONF_SERVER);
break;
+ case 'E':
+ case 'e': /* report engine name */
+ send_reply(sptr, RPL_STATSENGINE, engine_name());
+ break;
case 'G':
case 'g': /* send glines */
gline_stats(sptr);
case 'h':
report_configured_links(sptr, CONF_HUB | CONF_LEAF);
break;
+ case 'K':
+ case 'k': /* display CONF_IPKILL as well as CONF_KILL -Kev */
+ if (0 == report_klines(sptr, (parc > 3) ? parv[3] : 0, 0))
+ return 0;
+ break;
+ case 'F':
+ case 'f':
+ feature_report(sptr);
+ break;
case 'I':
case 'i':
- case 'K':
- case 'k': /* display CONF_IPKILL as well
- as CONF_KILL -Kev */
- {
- int wilds, count;
- char *user, *host, *p;
- int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
- if (parc < 4)
{
- report_configured_links(sptr, conf_status);
- break;
- }
-
- wilds = 0;
- for (p = parv[3]; *p; p++)
- {
- if (*p == '\\')
- {
- if (!*++p)
- break;
- continue;
- }
- if (*p == '?' || *p == '*')
- {
- wilds = 1;
- break;
- }
- }
-
- count = 1000;
-
- if (conf_status == CONF_CLIENT)
- {
- user = 0; /* Not used, but to avoid compiler warning. */
-
- host = parv[3];
- }
- else
- {
- if ((host = strchr(parv[3], '@')))
- {
- user = parv[3];
- *host++ = 0;;
- }
- else
- {
- user = 0;
- host = parv[3];
- }
- }
- for (aconf = GlobalConfList; aconf; aconf = aconf->next)
- {
- if ((aconf->status & conf_status))
- {
- if (conf_status == CONF_KLINE)
- {
- if ((!wilds && ((user || aconf->host[1]) &&
- !match(aconf->host, host) &&
- (!user || !match(aconf->name, user)))) ||
- (wilds && !mmatch(host, aconf->host) &&
- (!user || !mmatch(user, aconf->name))))
- {
- send_reply(sptr, RPL_STATSKLINE,
- (aconf->status & CONF_KILL) ? 'K' : 'k', aconf->host,
- aconf->passwd, aconf->name, aconf->port,
- get_conf_class(aconf));
- if (--count == 0)
- break;
- }
- }
- else if (conf_status == CONF_CLIENT)
- {
- if ((!wilds && (!match(aconf->host, host) ||
- !match(aconf->name, host))) ||
- (wilds && (!mmatch(host, aconf->host) ||
- !mmatch(host, aconf->name))))
- {
+ int wilds = 0;
+ int count = 1000;
+ char* host;
+
+ if (parc < 4) {
+ report_configured_links(sptr, CONF_CLIENT);
+ break;
+ }
+ if (EmptyString(parv[3]))
+ return need_more_params(sptr, "STATS I");
+
+ host = parv[3];
+ wilds = string_has_wildcards(host);
+
+ for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
+ if (CONF_CLIENT == aconf->status) {
+ if ((!wilds && (!match(aconf->host, host) ||
+ !match(aconf->name, host))) ||
+ (wilds && (!mmatch(host, aconf->host) ||
+ !mmatch(host, aconf->name))))
+ {
send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
aconf->port, get_conf_class(aconf));
- if (--count == 0)
- break;
- }
- }
- }
+ if (--count == 0)
+ break;
+ }
+ }
+ }
}
break;
- }
case 'M':
#if !defined(NDEBUG)
send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
- fda_get_block_count());
-#endif
-
-#if 0
-#ifdef MEMSIZESTATS
- sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
- me.name, parv[0], get_mem_size(), get_alloc_cnt());
-#endif
-#ifdef MEMLEAKSTATS
- report_memleak_stats(sptr, parc, parv);
+ fda_get_block_count());
#endif
-#if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
- sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
- "is not enabled on this server", me.name, parv[0]);
-#endif
-#endif /* 0 */
break;
case 'm':
for (mptr = msgtab; mptr->cmd; mptr++)
if (mptr->count)
- send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
- mptr->bytes);
+ send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
+ mptr->bytes);
break;
case 'o':
case 'O':
#endif
break;
case 'D':
- report_configured_links(sptr, CONF_CRULEALL);
+ report_crule_list(sptr, CRULE_ALL);
break;
case 'd':
- report_configured_links(sptr, CONF_CRULE);
+ report_crule_list(sptr, CRULE_MASK);
break;
case 't':
tstats(sptr, parv[0]);
break;
case 'T':
- report_configured_links(sptr, CONF_TLINES);
+ motd_report(sptr);
break;
case 'U':
report_configured_links(sptr, CONF_UWORLD);
{
time_t nowr;
- nowr = CurrentTime - me.since;
+ nowr = CurrentTime - cli_since(&me);
send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
- (nowr / 60) % 60, nowr % 60);
+ (nowr / 60) % 60, nowr % 60);
send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
break;
}
case 'X':
case 'x':
#ifdef DEBUGMODE
+ class_send_meminfo(sptr);
send_listinfo(sptr, parv[0]);
#endif
break;
default:
stat = '*';
while (*infotext)
- sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
break;
}
send_reply(sptr, RPL_ENDOFSTATS, stat);
return 0;
}
-#if 0
-/*
- * m_stats
- *
- * parv[0] = sender prefix
- * parv[1] = statistics selector (defaults to Message frequency)
- * parv[2] = target server (current server defaulted, if omitted)
- * And 'stats l' and 'stats' L:
- * parv[3] = server mask ("*" defaulted, if omitted)
- * Or for stats p,P:
- * parv[3] = port mask (returns p-lines when its port is matched by this)
- * Or for stats k,K,i and I:
- * parv[3] = [user@]host.name (returns which K/I-lines match this)
- * or [user@]host.mask (returns which K/I-lines are mmatched by this)
- * (defaults to old reply if ommitted, when local or Oper)
- * A remote mask (something containing wildcards) is only
- * allowed for IRC Operators.
- * Or for stats M:
- * parv[3] = time param
- * parv[4] = time param
- * (see report_memleak_stats() in runmalloc.c for details)
- *
- * This function is getting really ugly. -Ghostwolf
- */
-int m_stats(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
-{
- static char Sformat[] = ":%s %d %s Connection SendQ SendM SendKBytes "
- "RcveM RcveKBytes :Open since";
- static char Lformat[] = ":%s %d %s %s %u %u %u %u %u :" TIME_T_FMT;
- struct Message *mptr;
- struct Client *acptr;
- struct Gline* gline;
- struct ConfItem *aconf;
- char stat = parc > 1 ? parv[1][0] : '\0';
- int i;
-
-/* m_stats is so obnoxiously full of special cases that the different
- * hunt_server() possiblites were becoming very messy. It now uses a
- * switch() so as to be easier to read and update as params change.
- * -Ghostwolf
- */
- switch (stat)
- {
- /* open to all, standard # of params */
- case 'U':
- case 'u':
- {
- if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) /* XXX DEAD */
- != HUNTED_ISME)
- return 0;
- break;
- }
-
- /* open to all, varying # of params */
- case 'k':
- case 'K':
- case 'i':
- case 'I':
- case 'p':
- case 'P':
- {
- if (parc > 3)
- {
- if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv) /* XXX DEAD */
- != HUNTED_ISME)
- return 0;
- }
- else
- {
- if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) /* XXX DEAD */
- != HUNTED_ISME)
- return 0;
- }
- break;
- }
-
- /* oper only, varying # of params */
- case 'l':
- case 'L':
- case 'M':
- {
- if (parc == 4)
- {
- if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv) /* XXX DEAD */
- != HUNTED_ISME)
- return 0;
- }
- else if (parc > 4)
- {
- if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s %s :%s", 2, parc, /* XXX DEAD */
- parv) != HUNTED_ISME)
- return 0;
- }
- else if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) /* XXX DEAD */
- != HUNTED_ISME)
- return 0;
- break;
- }
-
- /* oper only, standard # of params */
- default:
- {
- if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) /* XXX DEAD */
- != HUNTED_ISME)
- return 0;
- break;
- }
- }
-
- switch (stat)
- {
- case 'L':
- case 'l':
- {
- int doall = 0, wilds = 0;
- char *name = "*";
- if (parc > 3 && *parv[3])
- {
- char *p;
- name = parv[3];
- wilds = (*name == '*' || *name == '?');
- for (p = name + 1; *p; ++p)
- if ((*p == '*' || *p == '?') && p[-1] != '\\')
- {
- wilds = 1;
- break;
- }
- }
- else
- doall = 1;
- /*
- * Send info about connections which match, or all if the
- * mask matches me.name. Only restrictions are on those who
- * are invisible not being visible to 'foreigners' who use
- * a wild card based search to list it.
- */
- sendto_one(sptr, Sformat, me.name, RPL_STATSLINKINFO, parv[0]); /* XXX DEAD */
- for (i = 0; i <= HighestFd; i++)
- {
- if (!(acptr = LocalClientArray[i]))
- continue;
- /* Don't return clients when this is a request for `all' */
- if (doall && IsUser(acptr))
- continue;
- /* Don't show invisible people to unauthorized people when using
- * wildcards -- Is this still needed now /stats is oper only ? */
- if (IsInvisible(acptr) && (doall || wilds) &&
- !(MyConnect(sptr) && IsOper(sptr)) &&
- !IsAnOper(acptr) && (acptr != sptr))
- continue;
- /* Only show the ones that match the given mask - if any */
- if (!doall && wilds && match(name, acptr->name))
- continue;
- /* Skip all that do not match the specific query */
- if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
- continue;
- sendto_one(sptr, Lformat, me.name, RPL_STATSLINKINFO, parv[0], /* XXX DEAD */
- acptr->name,
- (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
- (int)acptr->sendK, (int)acptr->receiveM, (int)acptr->receiveK,
- CurrentTime - acptr->firsttime);
- }
- break;
- }
- case 'C':
- case 'c':
- report_configured_links(sptr, CONF_SERVER);
- break;
- case 'G':
- case 'g': /* send glines */
- gline_remove_expired(TStime());
- for (gline = GlobalGlineList; gline; gline = gline->next) {
- sendto_one(sptr, rpl_str(RPL_STATSGLINE), me.name, /* XXX DEAD */
- sptr->name, 'G', gline->name, gline->host,
- gline->expire, gline->reason);
- }
- break;
- case 'H':
- case 'h':
- report_configured_links(sptr, CONF_HUB | CONF_LEAF);
- break;
- case 'I':
- case 'i':
- case 'K':
- case 'k': /* display CONF_IPKILL as well
- as CONF_KILL -Kev */
- {
- int wilds, count;
- char *user, *host, *p;
- int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
- if ((MyUser(sptr) || IsOper(sptr)) && parc < 4)
- {
- report_configured_links(sptr, conf_status);
- break;
- }
- if (parc < 4 || *parv[3] == '\0')
- return need_more_params(sptr,
- (conf_status & CONF_KLINE) ? "STATS K" : "STATS I");
-
- wilds = 0;
- for (p = parv[3]; *p; p++)
- {
- if (*p == '\\')
- {
- if (!*++p)
- break;
- continue;
- }
- if (*p == '?' || *p == '*')
- {
- wilds = 1;
- break;
- }
- }
- if (!(MyConnect(sptr) || IsOper(sptr)))
- {
- wilds = 0;
- count = 3;
- }
- else
- count = 1000;
-
- if (conf_status == CONF_CLIENT)
- {
- user = 0; /* Not used, but to avoid compiler warning. */
-
- host = parv[3];
- }
- else
- {
- if ((host = strchr(parv[3], '@')))
- {
- user = parv[3];
- *host++ = 0;;
- }
- else
- {
- user = 0;
- host = parv[3];
- }
- }
- for (aconf = GlobalConfList; aconf; aconf = aconf->next)
- {
- if ((aconf->status & conf_status))
- {
- if (conf_status == CONF_KLINE)
- {
- if ((!wilds && ((user || aconf->host[1]) &&
- !match(aconf->host, host) &&
- (!user || !match(aconf->name, user)))) ||
- (wilds && !mmatch(host, aconf->host) &&
- (!user || !mmatch(user, aconf->name))))
- {
- sendto_one(sptr, rpl_str(RPL_STATSKLINE), me.name, /* XXX DEAD */
- sptr->name, 'K', aconf->host, aconf->passwd, aconf->name,
- aconf->port, get_conf_class(aconf));
- if (--count == 0)
- break;
- }
- }
- else if (conf_status == CONF_CLIENT)
- {
- if ((!wilds && (!match(aconf->host, host) ||
- !match(aconf->name, host))) ||
- (wilds && (!mmatch(host, aconf->host) ||
- !mmatch(host, aconf->name))))
- {
- sendto_one(sptr, rpl_str(RPL_STATSILINE), me.name, /* XXX DEAD */
- sptr->name, 'I', aconf->host, aconf->name,
- aconf->port, get_conf_class(aconf));
- if (--count == 0)
- break;
- }
- }
- }
- }
- break;
- }
- case 'M':
-#if !defined(NDEBUG)
- sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
- me.name, parv[0], fda_get_byte_count(), fda_get_block_count());
-#endif
-
-#if 0
-#ifdef MEMSIZESTATS
- sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
- me.name, parv[0], get_mem_size(), get_alloc_cnt());
-#endif
-#ifdef MEMLEAKSTATS
- report_memleak_stats(sptr, parc, parv);
-#endif
-#if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
- sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
- "is not enabled on this server", me.name, parv[0]);
-#endif
-#endif /* 0 */
- break;
- case 'm':
- for (mptr = msgtab; mptr->cmd; mptr++)
- if (mptr->count)
- sendto_one(sptr, rpl_str(RPL_STATSCOMMANDS), /* XXX DEAD */
- me.name, parv[0], mptr->cmd, mptr->count, mptr->bytes);
- break;
- case 'o':
- case 'O':
- report_configured_links(sptr, CONF_OPS);
- break;
- case 'p':
- case 'P':
- /*
- * show listener ports
- * show hidden ports to opers, if there are more than 3 parameters,
- * interpret the fourth parameter as the port number, limit non-local
- * or non-oper results to 8 ports.
- */
- show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0,
- (MyUser(sptr) || IsOper(sptr)) ? 100 : 8);
- break;
- case 'R':
- case 'r':
-#ifdef DEBUGMODE
- send_usage(sptr, parv[0]);
-#endif
- break;
- case 'D':
- report_configured_links(sptr, CONF_CRULEALL);
- break;
- case 'd':
- report_configured_links(sptr, CONF_CRULE);
- break;
- case 't':
- tstats(sptr, parv[0]);
- break;
- case 'T':
- report_configured_links(sptr, CONF_TLINES);
- break;
- case 'U':
- report_configured_links(sptr, CONF_UWORLD);
- break;
- case 'u':
- {
- time_t nowr;
-
- nowr = CurrentTime - me.since;
- sendto_one(sptr, rpl_str(RPL_STATSUPTIME), me.name, parv[0], /* XXX DEAD */
- nowr / 86400, (nowr / 3600) % 24, (nowr / 60) % 60, nowr % 60);
- sendto_one(sptr, rpl_str(RPL_STATSCONN), me.name, parv[0], /* XXX DEAD */
- max_connection_count, max_client_count);
- break;
- }
- case 'W':
- case 'w':
- calc_load(sptr);
- break;
- case 'X':
- case 'x':
-#ifdef DEBUGMODE
- send_listinfo(sptr, parv[0]);
-#endif
- break;
- case 'Y':
- case 'y':
- report_classes(sptr);
- break;
- case 'Z':
- case 'z':
- count_memory(sptr, parv[0]);
- break;
- default:
- stat = '*';
- break;
- }
- sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, parv[0], stat); /* XXX DEAD */
- return 0;
-}
-#endif /* 0 */
-
-