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"
95 #if APR_HAVE_STRINGS_H
100 const char *name; /* matching module name */
101 const char *info; /* additional info */
105 apr_array_header_t *more_info;
108 module AP_MODULE_DECLARE_DATA info_module;
110 extern module *top_module;
111 extern ap_directive_t *ap_conftree;
113 static void *create_info_config(apr_pool_t *p, server_rec *s)
115 info_svr_conf *conf = (info_svr_conf *) apr_pcalloc(p, sizeof(info_svr_conf));
117 conf->more_info = apr_array_make(p, 20, sizeof(info_entry));
121 static void *merge_info_config(apr_pool_t *p, void *basev, void *overridesv)
123 info_svr_conf *new = (info_svr_conf *) apr_pcalloc(p, sizeof(info_svr_conf));
124 info_svr_conf *base = (info_svr_conf *) basev;
125 info_svr_conf *overrides = (info_svr_conf *) overridesv;
127 new->more_info = apr_array_append(p, overrides->more_info, base->more_info);
131 static char *mod_info_html_cmd_string(const char *string, char *buf, size_t buf_len, int close)
139 /* keep space for \0 byte */
140 end_buf = buf + buf_len - 1;
141 while ((*s) && (t < end_buf)) {
144 strncpy(t, "</,", end_buf -t);
147 strncpy(t, "<", end_buf - t);
151 else if (*s == '>') {
152 strncpy(t, ">", end_buf - t);
155 else if (*s == '&') {
156 strncpy(t, "&", end_buf - t);
159 else if (*s == ' ') {
161 strncpy(t, ">", end_buf -t);
172 /* oops, overflowed... don't overwrite */
182 static void mod_info_module_cmds(request_rec * r, const command_rec * cmds,
183 ap_directive_t * conftree)
185 const command_rec *cmd;
186 ap_directive_t *tmptree = conftree;
188 char buf[MAX_STRING_LEN];
189 char htmlstring[MAX_STRING_LEN];
193 while (tmptree != NULL) {
196 if (!strcasecmp(cmd->name, tmptree->directive)) {
197 if (nest > block_start) {
199 apr_snprintf(htmlstring, sizeof(htmlstring), "%s %s",
200 tmptree->parent->directive,
201 tmptree->parent->args);
202 ap_rprintf(r, "<dd><tt>%s</tt><br>\n",
203 mod_info_html_cmd_string(htmlstring, buf,
207 ap_rprintf(r, "<dd><tt> %s "
208 "<i>%s</i></tt><br>\n",
209 tmptree->directive, tmptree->args);
210 } else if (nest == 1) {
212 "<dd><tt> %s <i>%s</i></tt><br>\n",
213 tmptree->directive, tmptree->args);
215 ap_rprintf(r, "<dd><tt>%s <i>%s</i></tt><br>\n",
216 mod_info_html_cmd_string(tmptree->directive,
223 if (tmptree->first_child != NULL) {
224 tmptree = tmptree->first_child;
226 } else if (tmptree->next != NULL) {
227 tmptree = tmptree->next;
230 apr_snprintf(htmlstring, sizeof(htmlstring), "%s %s",
231 tmptree->parent->directive,
232 tmptree->parent->args);
233 ap_rprintf(r, "<dd><tt>%s</tt><br>\n",
234 mod_info_html_cmd_string(htmlstring, buf,
238 if (tmptree->parent) {
239 tmptree = tmptree->parent->next;
249 static const char *find_more_info(server_rec *s, const char *module_name)
252 info_svr_conf *conf = (info_svr_conf *) ap_get_module_config(s->module_config,
254 info_entry *entry = (info_entry *) conf->more_info->elts;
259 for (i = 0; i < conf->more_info->nelts; i++) {
260 if (!strcmp(module_name, entry->name)) {
268 static int display_info(request_rec *r)
271 char buf[MAX_STRING_LEN];
273 const char *more_info;
274 const command_rec *cmd = NULL;
276 const handler_rec *hand = NULL;
278 server_rec *serv = r->server;
281 if (strcmp(r->handler, "server-info"))
284 r->allowed |= (1 << M_GET);
285 if (r->method_number != M_GET)
288 r->content_type = "text/html";
289 ap_send_http_header(r);
290 if (r->header_only) {
294 ap_rputs(DOCTYPE_HTML_3_2
295 "<html><head><title>Server Information</title></head>\n", r);
296 ap_rputs("<body><h1 align=center>Apache Server Information</h1>\n", r);
297 if (!r->args || strcasecmp(r->args, "list")) {
298 cfname = ap_server_root_relative(r->pool, SERVER_CONFIG_FILE);
300 ap_rputs("<tt><a href=\"#server\">Server Settings</a>, ", r);
301 for (modp = top_module; modp; modp = modp->next) {
302 ap_rprintf(r, "<a href=\"#%s\">%s</a>", modp->name, modp->name);
307 ap_rputs("</tt><hr>", r);
310 if (!r->args || !strcasecmp(r->args, "server")) {
311 ap_rprintf(r, "<a name=\"server\"><strong>Server Version:</strong> "
312 "<font size=+1><tt>%s</tt></a></font><br>\n",
313 ap_get_server_version());
314 ap_rprintf(r, "<strong>Server Built:</strong> "
315 "<font size=+1><tt>%s</tt></a></font><br>\n",
316 ap_get_server_built());
317 ap_rprintf(r, "<strong>API Version:</strong> "
318 "<tt>%d:%d</tt><br>\n",
319 MODULE_MAGIC_NUMBER_MAJOR, MODULE_MAGIC_NUMBER_MINOR);
320 ap_rprintf(r, "<strong>Hostname/port:</strong> "
321 "<tt>%s:%u</tt><br>\n",
322 serv->server_hostname, serv->port);
323 ap_rprintf(r, "<strong>Timeouts:</strong> "
324 "<tt>connection: %d "
325 "keep-alive: %d</tt><br>",
326 serv->timeout, serv->keep_alive_timeout);
327 ap_rprintf(r, "<strong>Server Root:</strong> "
328 "<tt>%s</tt><br>\n", ap_server_root);
329 ap_rprintf(r, "<strong>Config File:</strong> "
330 "<tt>%s</tt><br>\n", SERVER_CONFIG_FILE);
332 ap_rputs("<hr><dl>", r);
333 for (modp = top_module; modp; modp = modp->next) {
334 if (!r->args || !strcasecmp(modp->name, r->args)) {
335 ap_rprintf(r, "<dt><a name=\"%s\"><strong>Module Name:</strong> "
336 "<font size=+1><tt>%s</tt></a></font>\n",
337 modp->name, modp->name);
338 ap_rputs("<dt><strong>Content handlers:</strong>", r);
340 hand = modp->handlers;
343 if (hand->content_type) {
344 ap_rprintf(r, " <tt>%s</tt>\n", hand->content_type);
350 if (hand && hand->content_type) {
356 ap_rputs("<tt> <EM>none</EM></tt>", r);
359 ap_rputs("<tt> <EM>(code broken)</EM></tt>", r);
361 ap_rputs("<dt><strong>Configuration Phase Participation:</strong> \n",
363 if (modp->create_dir_config) {
367 ap_rputs("<tt>Create Directory Config</tt>", r);
370 if (modp->merge_dir_config) {
374 ap_rputs("<tt>Merge Directory Configs</tt>", r);
377 if (modp->create_server_config) {
381 ap_rputs("<tt>Create Server Config</tt>", r);
384 if (modp->merge_server_config) {
388 ap_rputs("<tt>Merge Server Configs</tt>", r);
392 ap_rputs("<tt> <EM>none</EM></tt>", r);
394 ap_rputs("<dt><strong>Module Directives:</strong> ", r);
399 ap_rprintf(r, "<dd><tt>%s - <i>",
400 mod_info_html_cmd_string(cmd->name,
401 buf, sizeof(buf), 0));
403 ap_rputs(cmd->errmsg, r);
405 ap_rputs("</i></tt>\n", r);
412 ap_rputs("<dt><strong>Current Configuration:</strong>\n", r);
413 mod_info_module_cmds(r, modp->cmds, ap_conftree);
416 ap_rputs("<tt> none</tt>\n", r);
418 more_info = find_more_info(serv, modp->name);
420 ap_rputs("<dt><strong>Additional Information:</strong>\n<dd>",
422 ap_rputs(more_info, r);
424 ap_rputs("<dt><hr>\n", r);
430 if (!modp && r->args && strcasecmp(r->args, "server")) {
431 ap_rputs("<b>No such module</b>\n", r);
435 for (modp = top_module; modp; modp = modp->next) {
436 ap_rputs(modp->name, r);
442 ap_rputs("</dl>\n", r);
443 ap_rputs(ap_psignature("",r), r);
444 ap_rputs("</body></html>\n", r);
445 /* Done, turn off timeout, close file and return */
449 static const char *add_module_info(cmd_parms *cmd, void *dummy,
450 const char *name, const char *info)
452 server_rec *s = cmd->server;
453 info_svr_conf *conf = (info_svr_conf *) ap_get_module_config(s->module_config,
455 info_entry *new = apr_array_push(conf->more_info);
462 static const command_rec info_cmds[] =
464 AP_INIT_TAKE2("AddModuleInfo", add_module_info, NULL, RSRC_CONF,
465 "a module name and additional information on that module"),
469 static void register_hooks(apr_pool_t *p)
471 ap_hook_handler(display_info, NULL, NULL, APR_HOOK_MIDDLE);
474 module AP_MODULE_DECLARE_DATA info_module =
476 STANDARD20_MODULE_STUFF,
477 NULL, /* dir config creater */
478 NULL, /* dir merger --- default is to override */
479 create_info_config, /* server config */
480 merge_info_config, /* merge server config */
481 info_cmds, /* command apr_table_t */