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.
29 #include "ircd_chattr.h"
31 #include "ircd_reply.h"
32 #include "ircd_string.h"
51 * Report configuration lines and other statistics from this
54 * Note: The info is reported in the order the server uses
55 * it--not reversed as in ircd.conf!
59 * Help info displayed when user provides no stats parameter. --Gte
61 const char *statsinfo[] = {
62 "The following statistics are available:",
63 "U - Service server & nick jupes information.",
64 "u - Current uptime & highest connection count.",
65 "p - Listening ports.",
66 "i - Connection authorisation lines.",
67 "y - Connection classes.",
68 "c - Remote server connection lines.",
69 "h - Hubs information.",
70 "d - Dynamic routing configuration.",
71 "l - Current connections information.",
72 "g - Global bans (G-lines).",
73 "k - Local bans (K-Lines).",
74 "o - Operator information.",
75 "f - Feature settings.",
76 "m - Message usage information.",
77 "t - Local connection statistics (Total SND/RCV, etc).",
78 "w - Userload statistics.",
79 "v - Connection class information.",
80 "M - Memory allocation & leak monitoring.",
81 "z - Memory/Structure allocation information.",
82 "r - System resource usage (Debug only).",
83 "x - List usage information (Debug only).",
87 static unsigned int report_array[17][3] = {
88 {CONF_SERVER, RPL_STATSCLINE, 'C'},
89 {CONF_CLIENT, RPL_STATSILINE, 'I'},
90 {CONF_LEAF, RPL_STATSLLINE, 'L'},
91 {CONF_OPERATOR, RPL_STATSOLINE, 'O'},
92 {CONF_HUB, RPL_STATSHLINE, 'H'},
93 {CONF_LOCOP, RPL_STATSOLINE, 'o'},
94 {CONF_UWORLD, RPL_STATSULINE, 'U'},
98 void report_configured_links(struct Client *sptr, int mask)
100 static char null[] = "<NULL>";
101 struct ConfItem *tmp;
103 unsigned short int port;
104 char c, *host, *pass, *name;
107 for (tmp = GlobalConfList; tmp; tmp = tmp->next)
109 if ((tmp->status & mask))
111 for (p = &report_array[0][0]; *p; p += 3)
112 if (*p == tmp->status)
117 host = BadPtr(tmp->host) ? null : tmp->host;
118 pass = BadPtr(tmp->passwd) ? null : tmp->passwd;
119 name = BadPtr(tmp->name) ? null : tmp->name;
122 * On K line the passwd contents can be
123 * displayed on STATS reply. -Vesa
125 /* Special-case 'k' or 'K' lines as appropriate... -Kev */
126 if ((tmp->status & CONF_UWORLD))
127 send_reply(sptr, p[1], c, host, pass, name, port, get_conf_class(tmp));
128 else if ((tmp->status & (CONF_SERVER | CONF_HUB)))
129 send_reply(sptr, p[1], c, "*", name, port, get_conf_class(tmp));
131 send_reply(sptr, p[1], c, host, name, port, get_conf_class(tmp));
137 * {CONF_TLINES, RPL_STATSTLINE, 'T'},
139 * see now motd_report() in motd.c
141 /* void report_motd_list(struct Client* to) */
143 /* const struct MotdConf* conf = conf_get_motd_list(); */
144 /* for ( ; conf; conf = conf->next) */
145 /* send_reply(to, RPL_STATSTLINE, 'T', conf->hostmask, conf->path); */
149 * {CONF_CRULEALL, RPL_STATSDLINE, 'D'},
150 * {CONF_CRULEAUTO, RPL_STATSDLINE, 'd'},
152 void report_crule_list(struct Client* to, int mask)
154 const struct CRuleConf* p = conf_get_crule_list();
155 for ( ; p; p = p->next) {
156 if (0 != (p->type & mask))
157 send_reply(to, RPL_STATSDLINE, (CRULE_ALL == p->type) ? 'D' : 'd', p->hostmask, p->rule);
162 * {CONF_KILL, RPL_STATSKLINE, 'K'},
163 * {CONF_IPKILL, RPL_STATSKLINE, 'k'},
165 void report_deny_list(struct Client* to)
167 const struct DenyConf* p = conf_get_deny_list();
168 for ( ; p; p = p->next)
169 send_reply(to, RPL_STATSKLINE, (p->ip_kill) ? 'k' : 'K',
170 p->hostmask, p->message, p->usermask);
173 /* m_stats is so obnoxiously full of special cases that the different
174 * hunt_server() possiblites were becoming very messy. It now uses a
175 * switch() so as to be easier to read and update as params change.
178 * 2.10.11: Don't check for the oper limitation if it's not our local server.
179 * thusly once all the hubs have upgraded local opers will be able
180 * to remote stats anywhere on the network.
182 int hunt_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[], char stat)
186 /* open to all, standard # of params */
191 return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s :%C", 2, parc,
194 /* open to all, varying # of params */
203 return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s %C :%s", 2, parc, parv);
205 return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s :%C", 2, parc, parv);
208 /* oper only, varying # of params */
214 return hunt_server_cmd(sptr, CMD_STATS, cptr, MyUser(sptr) ? 1 : 0, "%s %C :%s", 2, parc, parv);
216 return hunt_server_cmd(sptr, CMD_STATS, cptr, MyUser(sptr) ? 1 : 0, "%s %C %s :%s", 2, parc, parv);
218 return hunt_server_cmd(sptr, CMD_STATS, cptr, MyUser(sptr) ? 1 : 0, "%s :%C", 2, parc, parv);
221 /* oper only, standard # of params */
223 return hunt_server_cmd(sptr, CMD_STATS, cptr, MyUser(sptr) ? 1 : 0, "%s :%C", 2, parc, parv);