2 * IRC - Internet Relay Chat, ircd/s_stats.c
3 * Copyright (C) 2000 Joseph Bongaarts
5 * See file AUTHORS in IRC package for additional names of
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 1, or (at your option)
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include "ircd_chattr.h"
32 #include "ircd_reply.h"
33 #include "ircd_string.h"
52 * Report configuration lines and other statistics from this
55 * Note: The info is reported in the order the server uses
56 * it--not reversed as in ircd.conf!
60 * Help info displayed when user provides no stats parameter. --Gte
62 const char *statsinfo[] = {
63 "The following statistics are available:",
64 "U - Service server & nick jupes information.",
65 "u - Current uptime & highest connection count.",
66 "p - Listening ports.",
67 "i - Connection authorisation lines.",
68 "y - Connection classes.",
69 "c - Remote server connection lines.",
70 "h - Hubs information.",
71 "d - Dynamic routing configuration.",
72 "l - Current connections information.",
73 "g - Global bans (G-lines).",
74 "k - Local bans (K-Lines).",
75 "o - Operator information.",
76 "e - Report server event loop engine.",
77 "f - Feature settings.",
78 "m - Message usage information.",
79 "t - Local connection statistics (Total SND/RCV, etc).",
80 "w - Userload statistics.",
81 "v - Connection class information.",
82 "M - Memory allocation & leak monitoring.",
83 "z - Memory/Structure allocation information.",
84 "r - System resource usage (Debug only).",
85 "x - List usage information (Debug only).",
89 static unsigned int report_array[17][3] = {
90 {CONF_SERVER, RPL_STATSCLINE, 'C'},
91 {CONF_CLIENT, RPL_STATSILINE, 'I'},
92 {CONF_LEAF, RPL_STATSLLINE, 'L'},
93 {CONF_OPERATOR, RPL_STATSOLINE, 'O'},
94 {CONF_HUB, RPL_STATSHLINE, 'H'},
95 {CONF_LOCOP, RPL_STATSOLINE, 'o'},
96 {CONF_UWORLD, RPL_STATSULINE, 'U'},
100 void report_configured_links(struct Client *sptr, int mask)
102 static char null[] = "<NULL>";
103 struct ConfItem *tmp;
105 unsigned short int port;
106 char c, *host, *pass, *name;
109 for (tmp = GlobalConfList; tmp; tmp = tmp->next)
111 if ((tmp->status & mask))
113 for (p = &report_array[0][0]; *p; p += 3)
114 if (*p == tmp->status)
119 host = BadPtr(tmp->host) ? null : tmp->host;
120 pass = BadPtr(tmp->passwd) ? null : tmp->passwd;
121 name = BadPtr(tmp->name) ? null : tmp->name;
124 * On K line the passwd contents can be
125 * displayed on STATS reply. -Vesa
127 /* Special-case 'k' or 'K' lines as appropriate... -Kev */
128 if ((tmp->status & CONF_UWORLD))
129 send_reply(sptr, p[1], c, host, pass, name, port, get_conf_class(tmp));
130 else if ((tmp->status & (CONF_SERVER | CONF_HUB)))
131 send_reply(sptr, p[1], c, "*", name, port, get_conf_class(tmp));
133 send_reply(sptr, p[1], c, host, name, port, get_conf_class(tmp));
139 * {CONF_TLINES, RPL_STATSTLINE, 'T'},
141 * see now motd_report() in motd.c
143 /* void report_motd_list(struct Client* to) */
145 /* const struct MotdConf* conf = conf_get_motd_list(); */
146 /* for ( ; conf; conf = conf->next) */
147 /* send_reply(to, RPL_STATSTLINE, 'T', conf->hostmask, conf->path); */
151 * {CONF_CRULEALL, RPL_STATSDLINE, 'D'},
152 * {CONF_CRULEAUTO, RPL_STATSDLINE, 'd'},
154 void report_crule_list(struct Client* to, int mask)
156 const struct CRuleConf* p = conf_get_crule_list();
157 for ( ; p; p = p->next) {
158 if (0 != (p->type & mask))
159 send_reply(to, RPL_STATSDLINE, (CRULE_ALL == p->type) ? 'D' : 'd', p->hostmask, p->rule);
164 * {CONF_KILL, RPL_STATSKLINE, 'K'},
165 * {CONF_IPKILL, RPL_STATSKLINE, 'k'},
167 void report_deny_list(struct Client* to)
169 const struct DenyConf* p = conf_get_deny_list();
170 for ( ; p; p = p->next)
171 send_reply(to, RPL_STATSKLINE, (p->flags & DENY_FLAGS_IP) ? 'k' : 'K',
172 p->hostmask, p->message, p->usermask);
175 /* m_stats is so obnoxiously full of special cases that the different
176 * hunt_server() possiblites were becoming very messy. It now uses a
177 * switch() so as to be easier to read and update as params change.
180 * 2.10.11: Don't check for the oper limitation if it's not our local server.
181 * thusly once all the hubs have upgraded local opers will be able
182 * to remote stats anywhere on the network.
184 int hunt_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[], char stat)
188 /* open to all, standard # of params */
193 return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s :%C", 2, parc,
196 /* open to all, varying # of params */
205 return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s %C :%s", 2, parc, parv);
207 return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s :%C", 2, parc, parv);
210 /* oper only, varying # of params */
216 return hunt_server_cmd(sptr, CMD_STATS, cptr, MyUser(sptr) ? 1 : 0, "%s %C :%s", 2, parc, parv);
218 return hunt_server_cmd(sptr, CMD_STATS, cptr, MyUser(sptr) ? 1 : 0, "%s %C %s :%s", 2, parc, parv);
220 return hunt_server_cmd(sptr, CMD_STATS, cptr, MyUser(sptr) ? 1 : 0, "%s :%C", 2, parc, parv);
223 /* oper only, standard # of params */
225 return hunt_server_cmd(sptr, CMD_STATS, cptr, MyUser(sptr) ? 1 : 0, "%s :%C", 2, parc, parv);