1 /* ====================================================================
2 * The Apache Software License, Version 1.1
4 * Copyright (c) 2000 The Apache Software Foundation. All rights
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
19 * 3. The end-user documentation included with the redistribution,
20 * if any, must include the following acknowledgment:
21 * "This product includes software developed by the
22 * Apache Software Foundation (http://www.apache.org/)."
23 * Alternately, this acknowledgment may appear in the software itself,
24 * if and wherever such third-party acknowledgments normally appear.
26 * 4. The names "Apache" and "Apache Software Foundation" must
27 * not be used to endorse or promote products derived from this
28 * software without prior written permission. For written
29 * permission, please contact apache@apache.org.
31 * 5. Products derived from this software may not be called "Apache",
32 * nor may "Apache" appear in their name, without prior written
33 * permission of the Apache Software Foundation.
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * ====================================================================
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation. For more
51 * information on the Apache Software Foundation, please see
52 * <http://www.apache.org/>.
54 * Portions of this software are based upon public domain software
55 * originally written at the National Center for Supercomputing Applications,
56 * University of Illinois, Urbana-Champaign.
60 * Info Module. Display configuration information for the server and
61 * all included modules.
63 * <Location /server-info>
64 * SetHandler server-info
67 * GET /server-info - Returns full configuration page for server and all modules
68 * GET /server-info?server - Returns server configuration only
69 * GET /server-info?module_name - Returns configuration for a single module
70 * GET /server-info?list - Returns quick list of included modules
72 * Rasmus Lerdorf <rasmus@vex.net>, May 1996
74 * 05.01.96 Initial Version
76 * Lou Langholtz <ldl@usi.utah.edu>, July 1997
78 * 07.11.97 Addition of the AddModuleInfo directive
80 * Ryan Morgan <rmorgan@covalent.net>
82 * 8.11.00 Port to Apache 2.0. Read configuation from the configuration
83 * tree rather than reparse the entire configuation file.
88 #include "http_config.h"
89 #include "http_core.h"
91 #include "http_main.h"
92 #include "http_protocol.h"
93 #include "util_script.h"
94 #include "http_conf_globals.h"
97 const char *name; /* matching module name */
98 const char *info; /* additional info */
102 apr_array_header_t *more_info;
105 module AP_MODULE_DECLARE_DATA info_module;
107 extern module *top_module;
108 extern ap_directive_t *ap_conftree;
110 static void *create_info_config(apr_pool_t *p, server_rec *s)
112 info_svr_conf *conf = (info_svr_conf *) apr_pcalloc(p, sizeof(info_svr_conf));
114 conf->more_info = apr_make_array(p, 20, sizeof(info_entry));
118 static void *merge_info_config(apr_pool_t *p, void *basev, void *overridesv)
120 info_svr_conf *new = (info_svr_conf *) apr_pcalloc(p, sizeof(info_svr_conf));
121 info_svr_conf *base = (info_svr_conf *) basev;
122 info_svr_conf *overrides = (info_svr_conf *) overridesv;
124 new->more_info = apr_append_arrays(p, overrides->more_info, base->more_info);
128 static char *mod_info_html_cmd_string(const char *string, char *buf, size_t buf_len, int close)
136 /* keep space for \0 byte */
137 end_buf = buf + buf_len - 1;
138 while ((*s) && (t < end_buf)) {
141 strncpy(t, "</,", end_buf -t);
144 strncpy(t, "<", end_buf - t);
148 else if (*s == '>') {
149 strncpy(t, ">", end_buf - t);
152 else if (*s == '&') {
153 strncpy(t, "&", end_buf - t);
156 else if (*s == ' ') {
158 strncpy(t, ">", end_buf -t);
169 /* oops, overflowed... don't overwrite */
179 static void mod_info_module_cmds(request_rec * r, const command_rec * cmds,
180 ap_directive_t * conftree)
182 const command_rec *cmd;
183 ap_directive_t *tmptree = conftree;
185 char buf[MAX_STRING_LEN];
186 char htmlstring[MAX_STRING_LEN];
190 while (tmptree != NULL) {
193 if (!strcasecmp(cmd->name, tmptree->directive)) {
194 if (nest > block_start) {
196 apr_snprintf(htmlstring, sizeof(htmlstring), "%s %s",
197 tmptree->parent->directive,
198 tmptree->parent->args);
199 ap_rprintf(r, "<dd><tt>%s</tt><br>\n",
200 mod_info_html_cmd_string(htmlstring, buf,
204 ap_rprintf(r, "<dd><tt> %s "
205 "<i>%s</i></tt><br>\n",
206 tmptree->directive, tmptree->args);
207 } else if (nest == 1) {
209 "<dd><tt> %s <i>%s</i></tt><br>\n",
210 tmptree->directive, tmptree->args);
212 ap_rprintf(r, "<dd><tt>%s <i>%s</i></tt><br>\n",
213 mod_info_html_cmd_string(tmptree->directive,
220 if (tmptree->first_child != NULL) {
221 tmptree = tmptree->first_child;
223 } else if (tmptree->next != NULL) {
224 tmptree = tmptree->next;
227 apr_snprintf(htmlstring, sizeof(htmlstring), "%s %s",
228 tmptree->parent->directive,
229 tmptree->parent->args);
230 ap_rprintf(r, "<dd><tt>%s</tt><br>\n",
231 mod_info_html_cmd_string(htmlstring, buf,
235 if (tmptree->parent) {
236 tmptree = tmptree->parent->next;
246 static const char *find_more_info(server_rec *s, const char *module_name)
249 info_svr_conf *conf = (info_svr_conf *) ap_get_module_config(s->module_config,
251 info_entry *entry = (info_entry *) conf->more_info->elts;
256 for (i = 0; i < conf->more_info->nelts; i++) {
257 if (!strcmp(module_name, entry->name)) {
265 static int display_info(request_rec *r)
268 char buf[MAX_STRING_LEN];
270 const char *more_info;
271 const command_rec *cmd = NULL;
273 const handler_rec *hand = NULL;
275 server_rec *serv = r->server;
278 if (strcmp(r->handler, "server-info"))
281 r->allowed |= (1 << M_GET);
282 if (r->method_number != M_GET)
285 r->content_type = "text/html";
286 ap_send_http_header(r);
287 if (r->header_only) {
291 ap_rputs(DOCTYPE_HTML_3_2
292 "<html><head><title>Server Information</title></head>\n", r);
293 ap_rputs("<body><h1 align=center>Apache Server Information</h1>\n", r);
294 if (!r->args || strcasecmp(r->args, "list")) {
295 cfname = ap_server_root_relative(r->pool, SERVER_CONFIG_FILE);
297 ap_rputs("<tt><a href=\"#server\">Server Settings</a>, ", r);
298 for (modp = top_module; modp; modp = modp->next) {
299 ap_rprintf(r, "<a href=\"#%s\">%s</a>", modp->name, modp->name);
304 ap_rputs("</tt><hr>", r);
307 if (!r->args || !strcasecmp(r->args, "server")) {
308 ap_rprintf(r, "<a name=\"server\"><strong>Server Version:</strong> "
309 "<font size=+1><tt>%s</tt></a></font><br>\n",
310 ap_get_server_version());
311 ap_rprintf(r, "<strong>Server Built:</strong> "
312 "<font size=+1><tt>%s</tt></a></font><br>\n",
313 ap_get_server_built());
314 ap_rprintf(r, "<strong>API Version:</strong> "
315 "<tt>%d:%d</tt><br>\n",
316 MODULE_MAGIC_NUMBER_MAJOR, MODULE_MAGIC_NUMBER_MINOR);
317 ap_rprintf(r, "<strong>Hostname/port:</strong> "
318 "<tt>%s:%u</tt><br>\n",
319 serv->server_hostname, serv->port);
320 ap_rprintf(r, "<strong>Timeouts:</strong> "
321 "<tt>connection: %d "
322 "keep-alive: %d</tt><br>",
323 serv->timeout, serv->keep_alive_timeout);
324 ap_rprintf(r, "<strong>Server Root:</strong> "
325 "<tt>%s</tt><br>\n", ap_server_root);
326 ap_rprintf(r, "<strong>Config File:</strong> "
327 "<tt>%s</tt><br>\n", SERVER_CONFIG_FILE);
329 ap_rputs("<hr><dl>", r);
330 for (modp = top_module; modp; modp = modp->next) {
331 if (!r->args || !strcasecmp(modp->name, r->args)) {
332 ap_rprintf(r, "<dt><a name=\"%s\"><strong>Module Name:</strong> "
333 "<font size=+1><tt>%s</tt></a></font>\n",
334 modp->name, modp->name);
335 ap_rputs("<dt><strong>Content handlers:</strong>", r);
337 hand = modp->handlers;
340 if (hand->content_type) {
341 ap_rprintf(r, " <tt>%s</tt>\n", hand->content_type);
347 if (hand && hand->content_type) {
353 ap_rputs("<tt> <EM>none</EM></tt>", r);
356 ap_rputs("<tt> <EM>(code broken)</EM></tt>", r);
358 ap_rputs("<dt><strong>Configuration Phase Participation:</strong> \n",
360 if (modp->create_dir_config) {
364 ap_rputs("<tt>Create Directory Config</tt>", r);
367 if (modp->merge_dir_config) {
371 ap_rputs("<tt>Merge Directory Configs</tt>", r);
374 if (modp->create_server_config) {
378 ap_rputs("<tt>Create Server Config</tt>", r);
381 if (modp->merge_server_config) {
385 ap_rputs("<tt>Merge Server Configs</tt>", r);
389 ap_rputs("<tt> <EM>none</EM></tt>", r);
391 ap_rputs("<dt><strong>Module Directives:</strong> ", r);
396 ap_rprintf(r, "<dd><tt>%s - <i>",
397 mod_info_html_cmd_string(cmd->name,
398 buf, sizeof(buf), 0));
400 ap_rputs(cmd->errmsg, r);
402 ap_rputs("</i></tt>\n", r);
409 ap_rputs("<dt><strong>Current Configuration:</strong>\n", r);
410 mod_info_module_cmds(r, modp->cmds, ap_conftree);
413 ap_rputs("<tt> none</tt>\n", r);
415 more_info = find_more_info(serv, modp->name);
417 ap_rputs("<dt><strong>Additional Information:</strong>\n<dd>",
419 ap_rputs(more_info, r);
421 ap_rputs("<dt><hr>\n", r);
427 if (!modp && r->args && strcasecmp(r->args, "server")) {
428 ap_rputs("<b>No such module</b>\n", r);
432 for (modp = top_module; modp; modp = modp->next) {
433 ap_rputs(modp->name, r);
439 ap_rputs("</dl>\n", r);
440 ap_rputs(ap_psignature("",r), r);
441 ap_rputs("</body></html>\n", r);
442 /* Done, turn off timeout, close file and return */
446 static const char *add_module_info(cmd_parms *cmd, void *dummy,
447 const char *name, const char *info)
449 server_rec *s = cmd->server;
450 info_svr_conf *conf = (info_svr_conf *) ap_get_module_config(s->module_config,
452 info_entry *new = apr_push_array(conf->more_info);
459 static const command_rec info_cmds[] =
461 AP_INIT_TAKE2("AddModuleInfo", add_module_info, NULL, RSRC_CONF,
462 "a module name and additional information on that module"),
466 static void register_hooks(void)
468 ap_hook_handler(display_info, NULL, NULL, AP_HOOK_MIDDLE);
471 module AP_MODULE_DECLARE_DATA info_module =
473 STANDARD20_MODULE_STUFF,
474 NULL, /* dir config creater */
475 NULL, /* dir merger --- default is to override */
476 create_info_config, /* server config */
477 merge_info_config, /* merge server config */
478 info_cmds, /* command apr_table_t */