Provide /stats F to report even defaulted feature values.
[ircu2.10.12-pk.git] / ircd / s_stats.c
index 3d536944429f12eb277def6bc48cc3939b8242e2..c3f01cd7c43abc0e64b5c2c5fe01dc748d253a47 100644 (file)
@@ -24,6 +24,7 @@
 #include "class.h"
 #include "client.h"
 #include "gline.h"
+#include "hash.h"
 #include "ircd.h"
 #include "ircd_chattr.h"
 #include "ircd_events.h"
@@ -40,7 +41,9 @@
 #include "msgq.h"
 #include "numeric.h"
 #include "numnicks.h"
+#include "querycmds.h"
 #include "res.h"
+#include "s_auth.h"
 #include "s_bsd.h"
 #include "s_conf.h"
 #include "s_debug.h"
@@ -104,14 +107,20 @@ stats_configured_links(struct Client *sptr, const struct StatDesc* sd,
       if (tmp->status & CONF_UWORLD)
        send_reply(sptr, RPL_STATSULINE, host);
       else if (tmp->status & CONF_SERVER)
-       send_reply(sptr, RPL_STATSCLINE, name, "", "*", port, maximum, hub_limit, get_conf_class(tmp));
+       send_reply(sptr, RPL_STATSCLINE, name, port, maximum, hub_limit, get_conf_class(tmp));
       else if (tmp->status & CONF_CLIENT)
         send_reply(sptr, RPL_STATSILINE,
+                   (tmp->username ? tmp->username : ""), (tmp->username ? "@" : ""),
                    (tmp->host ? tmp->host : "*"), maximum,
                    (name[0] == ':' ? "0" : ""), (tmp->name ? tmp->name : "*"),
                    port, get_conf_class(tmp));
       else if (tmp->status & CONF_OPERATOR)
-       send_reply(sptr, RPL_STATSOLINE, username, host, name, get_conf_class(tmp));
+        send_reply(sptr, RPL_STATSOLINE,
+                   ((FlagHas(&tmp->privs_dirty, PRIV_PROPAGATE)
+                     && FlagHas(&tmp->privs, PRIV_PROPAGATE))
+                    || (FlagHas(&tmp->conn_class->privs_dirty, PRIV_PROPAGATE)
+                        && FlagHas(&tmp->conn_class->privs, PRIV_PROPAGATE)))
+                   ? 'O' : 'o', username, host, name, get_conf_class(tmp));
     }
   }
 }
@@ -131,7 +140,7 @@ stats_crule_list(struct Client* to, const struct StatDesc *sd,
   for ( ; p; p = p->next)
   {
     if (p->type & sd->sd_funcdata)
-      send_reply(to, RPL_STATSDLINE, sd->sd_c, p->hostmask, p->rule);
+      send_reply(to, RPL_STATSDLINE, (p->type & CRULE_ALL ? 'D' : 'd'), p->hostmask, p->rule);
   }
 }
 
@@ -170,12 +179,16 @@ stats_access(struct Client *to, const struct StatDesc *sd, char *param)
   {
     if (aconf->status != CONF_CLIENT)
       continue;
-    if ((!wilds && (!match(aconf->host, param) ||
-                    !match(aconf->name, param))) ||
-        (wilds && (!mmatch(param, aconf->host) ||
-                   !mmatch(param, aconf->name))))
+    if (wilds ? ((aconf->host && !mmatch(aconf->host, param))
+                 || (aconf->name && !mmatch(aconf->name, param)))
+        : ((aconf->host && !match(param, aconf->host))
+           || (aconf->name && !match(param, aconf->name))))
     {
-      send_reply(to, RPL_STATSILINE, 'I', aconf->host, aconf->name,
+      send_reply(to, RPL_STATSILINE,
+                 (aconf->username ? aconf->username : ""), (aconf->username ? "@" : ""), 
+                 (aconf->host ? aconf->host : "*"), aconf->maximum,
+                 (aconf->name && aconf->name[0] == ':' ? "0":""),
+                 aconf->name ? aconf->name : "*",
                  aconf->address.port, get_conf_class(aconf));
       if (--count == 0)
         break;
@@ -192,8 +205,11 @@ report_deny_list(struct Client* to)
 {
   const struct DenyConf* p = conf_get_deny_list();
   for ( ; p; p = p->next)
-    send_reply(to, RPL_STATSKLINE, (p->flags & DENY_FLAGS_IP) ? 'k' : 'K',
-               p->hostmask, p->message, p->usermask);
+    send_reply(to, RPL_STATSKLINE, p->bits > 0 ? 'k' : 'K',
+               p->usermask ? p->usermask : "*",
+               p->hostmask ? p->hostmask : "*",
+               p->message ? p->message : "(none)",
+               p->realmask ? p->realmask : "*");
 }
 
 /** Report K/k-lines to a user.
@@ -238,18 +254,30 @@ stats_klines(struct Client *sptr, const struct StatDesc *sd, char *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;
-    }
+    /* Skip this block if the user is searching for a user-matching
+     * mask but the current Kill doesn't have a usermask, or if user
+     * is searching for a host-matching mask but the Kill has no
+     * hostmask, or if the user mask is specified and doesn't match,
+     * or if the host mask is specified and doesn't match.
+     */
+    if ((user && !conf->usermask)
+        || (host && !conf->hostmask)
+        || (user && conf->usermask
+            && (wilds
+                ? mmatch(user, conf->usermask)
+                : match(conf->usermask, user)))
+        || (host && conf->hostmask
+            && (wilds
+                ? mmatch(host, conf->hostmask)
+                : match(conf->hostmask, host))))
+      continue;
+    send_reply(sptr, RPL_STATSKLINE, conf->bits > 0 ? 'k' : 'K',
+               conf->usermask ? conf->usermask : "*",
+               conf->hostmask ? conf->hostmask : "*",
+               conf->message ? conf->message : "(none)",
+               conf->realmask ? conf->realmask : "*");
+    if (--count == 0)
+      return;
   }
 }
 
@@ -430,9 +458,9 @@ stats_servers_verbose(struct Client* sptr, const struct StatDesc* sd,
                "%-20s %-20s Flags Hops Numeric   Lag  RTT   Up Down "
                "Clients/Max Proto %-10s :Info", "Servername", "Uplink",
                "LinkTS");
-    fmt = "%-20s %-20s %c%c%c%c  %4i %s %-4i %5i %4i %4i %4i %5i %5i P%-2i   %Tu :%s";
+    fmt = "%-20s %-20s %c%c%c%c%c  %4i %s %-4i %5i %4i %4i %4i %5i %5i P%-2i   %Tu :%s";
   } else {
-    fmt = "%s %s %c%c%c%c %i %s %i %i %i %i %i %i %i P%i %Tu :%s";
+    fmt = "%s %s %c%c%c%c%c %i %s %i %i %i %i %i %i %i P%i %Tu :%s";
   }
 
   for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr))
@@ -449,6 +477,7 @@ stats_servers_verbose(struct Client* sptr, const struct StatDesc* sd,
                IsBurstAck(acptr) ? 'A' : '-',
                IsHub(acptr) ? 'H' : '-',
                IsService(acptr) ? 'S' : '-',
+               IsIPv6(acptr) ? '6' : '-',
                cli_hopcount(acptr),
                NumServ(acptr),
                base64toint(cli_yxx(acptr)),
@@ -456,7 +485,7 @@ stats_servers_verbose(struct Client* sptr, const struct StatDesc* sd,
                cli_serv(acptr)->asll_rtt,
                cli_serv(acptr)->asll_to,
                cli_serv(acptr)->asll_from,
-               cli_serv(acptr)->clients,
+               (acptr == &me ? UserStats.local_clients : cli_serv(acptr)->clients),
                cli_serv(acptr)->nn_mask,
                cli_serv(acptr)->prot,
                cli_serv(acptr)->timestamp,
@@ -464,7 +493,6 @@ stats_servers_verbose(struct Client* sptr, const struct StatDesc* sd,
   }
 }
 
-#ifdef DEBUGMODE
 /** Display objects allocated (and total memory used by them) for
  * several types of structures.
  * @param[in] to Client requesting statistics.
@@ -474,10 +502,12 @@ stats_servers_verbose(struct Client* sptr, const struct StatDesc* sd,
 static void
 stats_meminfo(struct Client* to, const struct StatDesc* sd, char* param)
 {
+  extern void bans_send_meminfo(struct Client *cptr);
+
   class_send_meminfo(to);
+  bans_send_meminfo(to);
   send_listinfo(to, 0);
 }
-#endif
 
 /** Send a list of available statistics.
  * @param[in] to Client requesting statistics.
@@ -499,7 +529,7 @@ stats_help(struct Client* to, const struct StatDesc* sd, char* param)
 
 /** Contains information about all statistics. */
 struct StatDesc statsinfo[] = {
-  { 'a', "nameservers", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_a,
+  { 'a', "nameservers", STAT_FLAG_OPERFEAT|STAT_FLAG_LOCONLY, FEAT_HIS_STATS_a,
     report_dns_servers, 0,
     "DNS servers." },
   { 'c', "connect", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_c,
@@ -514,18 +544,24 @@ struct StatDesc statsinfo[] = {
   { 'e', "engine", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_e,
     stats_engine, 0,
     "Report server event loop engine." },
-  { 'f', "features", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_f,
+  { 'f', "features", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_f,
     feature_report, 0,
     "Feature settings." },
+  { 'F', "featuresall", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_f,
+    feature_report, 1,
+    "All feature settings, including defaulted values." },
   { 'g', "glines", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_g,
     gline_stats, 0,
     "Global bans (G-lines)." },
   { 'i', "access", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM), FEAT_HIS_STATS_i,
     stats_access, CONF_CLIENT,
     "Connection authorization lines." },
-  { 'j', "histogram", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_j,
+  { 'j', "histogram", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_j,
     msgq_histogram, 0,
     "Message length histogram." },
+  { 'J', "jupes", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_J,
+    stats_nickjupes, 0,
+    "Nickname jupes." },
   { 'k', "klines", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM), FEAT_HIS_STATS_k,
     stats_klines, 0,
     "Local bans (K-Lines)." },
@@ -533,7 +569,7 @@ struct StatDesc statsinfo[] = {
     FEAT_HIS_STATS_l,
     stats_links, 0,
     "Current connections information." },
-  { 'L', "modules", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS),
+  { 'L', "modules", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS),
     FEAT_HIS_STATS_L,
     stats_modules, 0,
     "Dynamically loaded modules." },
@@ -565,7 +601,7 @@ struct StatDesc statsinfo[] = {
     "Local connection statistics (Total SND/RCV, etc)." },
   { 'U', "uworld", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_U,
     stats_configured_links, CONF_UWORLD,
-    "Service server & nick jupes information." },
+    "Service server information." },
   { 'u', "uptime", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_u,
     stats_uptime, 0,
     "Current uptime & highest connection count." },
@@ -578,18 +614,22 @@ struct StatDesc statsinfo[] = {
   { 'w', "userload", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_w,
     calc_load, 0,
     "Userload statistics." },
-#ifdef DEBUGMODE
   { 'x', "memusage", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_x,
     stats_meminfo, 0,
-    "List usage information (Debug only)." },
-#endif
+    "List usage information." },
   { 'y', "classes", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_y,
     report_classes, 0,
     "Connection classes." },
   { 'z', "memory", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_z,
     count_memory, 0,
     "Memory/Structure allocation information." },
-  { '*', "help", (STAT_FLAG_CASESENS | STAT_FLAG_VARPARAM), FEAT_LAST_F,
+  { ' ', "iauth", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_IAUTH,
+    report_iauth_stats, 0,
+    "IAuth statistics." },
+  { ' ', "iauthconf", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_IAUTH,
+    report_iauth_conf, 0,
+    "IAuth configuration." },
+  { '*', "help", STAT_FLAG_CASESENS, FEAT_LAST_F,
     stats_help, 0,
     "Send help for stats." },
   { '\0', 0, FEAT_LAST_F, 0, 0, 0 }
@@ -640,7 +680,7 @@ const struct StatDesc *
 stats_find(const char *name_or_char)
 {
   if (!name_or_char[1])
-    return statsmap[(int)name_or_char[0]];
+    return statsmap[name_or_char[0] - CHAR_MIN];
   else
     return bsearch(name_or_char, statsinfo, statscount, sizeof(statsinfo[0]), stats_search);
 }
@@ -650,11 +690,6 @@ void
 stats_init(void)
 {
   struct StatDesc *sd;
-  int i;
-
-  /* Make darn sure the statsmap array is initialized to all zeros */
-  for (i = 0; i < 256; i++)
-    statsmap[i] = 0;
 
   /* Count number of stats entries and sort them. */
   for (statscount = 0, sd = statsinfo; sd->sd_name; sd++, statscount++) {}
@@ -667,12 +702,12 @@ stats_init(void)
       continue;
     else if (sd->sd_flags & STAT_FLAG_CASESENS)
       /* case sensitive character... */
-      statsmap[(int)sd->sd_c] = sd;
+      statsmap[sd->sd_c - CHAR_MIN] = sd;
     else
     {
       /* case insensitive--make sure to put in two entries */
-      statsmap[(int)ToLower((int)sd->sd_c)] = sd;
-      statsmap[(int)ToUpper((int)sd->sd_c)] = sd;
+      statsmap[ToLower(sd->sd_c) - CHAR_MIN] = sd;
+      statsmap[ToUpper(sd->sd_c) - CHAR_MIN] = sd;
     }
   }
 }