1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * Info Module. Display configuration information for the server and
19 * all included modules.
21 * <Location /server-info>
22 * SetHandler server-info
25 * GET /server-info - Returns full configuration page for server and all modules
26 * GET /server-info?server - Returns server configuration only
27 * GET /server-info?module_name - Returns configuration for a single module
28 * GET /server-info?list - Returns quick list of included modules
30 * Rasmus Lerdorf <rasmus@vex.net>, May 1996
32 * 05.01.96 Initial Version
34 * Lou Langholtz <ldl@usi.utah.edu>, July 1997
36 * 07.11.97 Addition of the AddModuleInfo directive
38 * Ryan Morgan <rmorgan@covalent.net>
40 * 8.11.00 Port to Apache 2.0. Read configuation from the configuration
41 * tree rather than reparse the entire configuation file.
48 #include "http_config.h"
49 #include "http_core.h"
51 #include "http_main.h"
52 #include "http_protocol.h"
53 #include "http_request.h"
54 #include "util_script.h"
55 #include "apr_strings.h"
57 #define APR_WANT_STRFUNC
62 const char *name; /* matching module name */
63 const char *info; /* additional info */
67 apr_array_header_t *more_info;
70 module AP_MODULE_DECLARE_DATA info_module;
72 static void *create_info_config(apr_pool_t *p, server_rec *s)
74 info_svr_conf *conf = (info_svr_conf *) apr_pcalloc(p, sizeof(info_svr_conf));
76 conf->more_info = apr_array_make(p, 20, sizeof(info_entry));
80 static void *merge_info_config(apr_pool_t *p, void *basev, void *overridesv)
82 info_svr_conf *new = (info_svr_conf *) apr_pcalloc(p, sizeof(info_svr_conf));
83 info_svr_conf *base = (info_svr_conf *) basev;
84 info_svr_conf *overrides = (info_svr_conf *) overridesv;
86 new->more_info = apr_array_append(p, overrides->more_info, base->more_info);
90 static void mod_info_html_cmd_string(request_rec *r, const char *string,
96 /* keep space for \0 byte */
100 ap_rputs("</", r);
105 else if (*s == '>') {
108 else if (*s == '&') {
109 ap_rputs("&", r);
111 else if (*s == ' ') {
125 static void mod_info_module_cmds(request_rec * r, const command_rec * cmds,
126 ap_directive_t * conftree)
128 const command_rec *cmd;
129 ap_directive_t *tmptree = conftree;
130 char htmlstring[MAX_STRING_LEN];
134 while (tmptree != NULL) {
137 if ((cmd->name[0] != '<') &&
138 (strcasecmp(cmd->name, tmptree->directive) == 0)) {
139 if (nest > block_start) {
141 apr_snprintf(htmlstring, sizeof(htmlstring), "%s %s",
142 tmptree->parent->directive,
143 tmptree->parent->args);
144 ap_rputs("<dd><tt>", r);
145 mod_info_html_cmd_string(r, htmlstring, 0);
146 ap_rputs("</tt></dd>\n", r);
149 ap_rprintf(r, "<dd><tt> %s "
150 "<i>%s</i></tt></dd>\n",
151 ap_escape_html(r->pool,tmptree->directive),
152 ap_escape_html(r->pool,tmptree->args));
153 } else if (nest == 1) {
155 "<dd><tt> %s <i>%s</i></tt></dd>\n",
156 ap_escape_html(r->pool,tmptree->directive),
157 ap_escape_html(r->pool,tmptree->args));
159 ap_rputs("<dd><tt>", r);
160 mod_info_html_cmd_string(r, tmptree->directive, 0);
161 ap_rprintf(r, " <i>%s</i></tt></dd>\n",
162 ap_escape_html(r->pool,tmptree->args));
167 if (tmptree->first_child != NULL) {
168 tmptree = tmptree->first_child;
170 } else if (tmptree->next != NULL) {
171 tmptree = tmptree->next;
174 apr_snprintf(htmlstring, sizeof(htmlstring), "%s %s",
175 tmptree->parent->directive,
176 tmptree->parent->args);
177 ap_rputs("<dd><tt>", r);
178 mod_info_html_cmd_string(r, htmlstring, 1);
179 ap_rputs("</tt></dd>\n", r);
182 if (tmptree->parent) {
183 tmptree = tmptree->parent->next;
194 typedef struct { /*XXX: should get something from apr_hooks.h instead */
195 void (*pFunc)(void); /* just to get the right size */
197 const char * const *aszPredecessors;
198 const char * const *aszSuccessors;
203 * hook_get_t is a pointer to a function that takes void as an argument and
204 * returns a pointer to an apr_array_header_t. The nasty WIN32 ifdef
205 * is required to account for the fact that the ap_hook* calls all use
206 * STDCALL calling convention.
208 typedef apr_array_header_t * (
219 static hook_lookup_t request_hooks[] = {
220 {"Post-Read Request", ap_hook_get_post_read_request},
221 {"Header Parse", ap_hook_get_header_parser},
222 {"Translate Path", ap_hook_get_translate_name},
223 {"Check Access", ap_hook_get_access_checker},
224 {"Verify User ID", ap_hook_get_check_user_id},
225 {"Verify User Access", ap_hook_get_auth_checker},
226 {"Check Type", ap_hook_get_type_checker},
227 {"Fixups", ap_hook_get_fixups},
228 {"Logging", ap_hook_get_log_transaction},
232 static int module_find_hook(module *modp,
236 apr_array_header_t *hooks = hook_get();
243 elts = (hook_struct_t *)hooks->elts;
245 for (i=0; i< hooks->nelts; i++) {
246 if (strcmp(elts[i].szName, modp->name) == 0) {
254 static void module_participate(request_rec *r,
256 hook_lookup_t *lookup,
259 if (module_find_hook(modp, lookup->get)) {
263 ap_rvputs(r, "<tt>", lookup->name, "</tt>", NULL);
268 static void module_request_hook_participate(request_rec *r, module *modp)
272 ap_rputs("<dt><strong>Request Phase Participation:</strong>\n", r);
274 for (i=0; request_hooks[i].name; i++) {
275 module_participate(r, modp, &request_hooks[i], &comma);
279 ap_rputs("<tt> <em>none</em></tt>", r);
281 ap_rputs("</dt>\n", r);
284 static const char *find_more_info(server_rec *s, const char *module_name)
287 info_svr_conf *conf = (info_svr_conf *) ap_get_module_config(s->module_config,
289 info_entry *entry = (info_entry *) conf->more_info->elts;
294 for (i = 0; i < conf->more_info->nelts; i++) {
295 if (!strcmp(module_name, entry->name)) {
303 static int display_info(request_rec *r)
306 const char *more_info;
307 const command_rec *cmd = NULL;
309 const handler_rec *hand = NULL;
311 server_rec *serv = r->server;
314 if (strcmp(r->handler, "server-info"))
317 r->allowed |= (AP_METHOD_BIT << M_GET);
318 if (r->method_number != M_GET)
321 ap_set_content_type(r, "text/html; charset=ISO-8859-1");
323 ap_rputs(DOCTYPE_HTML_3_2
324 "<html><head><title>Server Information</title></head>\n", r);
325 ap_rputs("<body><h1 align=\"center\">Apache Server Information</h1>\n", r);
326 if (!r->args || strcasecmp(r->args, "list")) {
328 ap_rputs("<dl><dt><tt><a href=\"#server\">Server Settings</a>, ", r);
329 for (modp = ap_top_module; modp; modp = modp->next) {
330 ap_rprintf(r, "<a href=\"#%s\">%s</a>", modp->name, modp->name);
335 ap_rputs("</tt></dt></dl><hr />", r);
338 if (!r->args || !strcasecmp(r->args, "server")) {
339 int max_daemons, forked, threaded;
341 ap_rprintf(r, "<dl><dt><a name=\"server\"><strong>Server Version:</strong> "
342 "<font size=\"+1\"><tt>%s</tt></font></a></dt>\n",
343 ap_get_server_version());
344 ap_rprintf(r, "<dt><strong>Server Built:</strong> "
345 "<font size=\"+1\"><tt>%s</tt></font></dt>\n",
346 ap_get_server_built());
347 ap_rprintf(r, "<dt><strong>API Version:</strong> "
348 "<tt>%d:%d</tt></dt>\n",
349 MODULE_MAGIC_NUMBER_MAJOR, MODULE_MAGIC_NUMBER_MINOR);
350 ap_rprintf(r, "<dt><strong>Hostname/port:</strong> "
351 "<tt>%s:%u</tt></dt>\n",
352 ap_get_server_name(r), ap_get_server_port(r));
353 ap_rprintf(r, "<dt><strong>Timeouts:</strong> "
354 "<tt>connection: %d "
355 "keep-alive: %d</tt></dt>",
356 (int)(apr_time_sec(serv->timeout)),
357 (int)(apr_time_sec(serv->timeout)));
358 ap_mpm_query(AP_MPMQ_MAX_DAEMON_USED, &max_daemons);
359 ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded);
360 ap_mpm_query(AP_MPMQ_IS_FORKED, &forked);
361 ap_rprintf(r, "<dt><strong>MPM Name:</strong> <tt>%s</tt></dt>\n", ap_show_mpm());
362 ap_rprintf(r, "<dt><strong>MPM Information:</strong> "
363 "<tt>Max Daemons: %d Threaded: %s Forked: %s</tt></dt>\n",
364 max_daemons, threaded ? "yes" : "no",
365 forked ? "yes" : "no");
366 ap_rprintf(r, "<dt><strong>Server Root:</strong> "
367 "<tt>%s</tt></dt>\n", ap_server_root);
368 ap_rprintf(r, "<dt><strong>Config File:</strong> "
369 "<tt>%s</tt></dt>\n", ap_conftree->filename);
370 ap_rputs("</dl><hr />", r);
372 for (modp = ap_top_module; modp; modp = modp->next) {
373 if (!r->args || !strcasecmp(modp->name, r->args)) {
374 ap_rprintf(r, "<dl><dt><a name=\"%s\"><strong>Module Name:</strong> "
375 "<font size=\"+1\"><tt>%s</tt></font></a></dt>\n",
376 modp->name, modp->name);
377 ap_rputs("<dt><strong>Content handlers:</strong> ", r);
379 hand = modp->handlers;
382 if (hand->content_type) {
383 ap_rprintf(r, " <tt>%s</tt>\n", hand->content_type);
389 if (hand && hand->content_type) {
395 ap_rputs("<tt> <em>none</em></tt>", r);
398 if (module_find_hook(modp, ap_hook_get_handler)) {
399 ap_rputs("<tt> <em>yes</em></tt>", r);
402 ap_rputs("<tt> <em>none</em></tt>", r);
405 ap_rputs("</dt>", r);
406 ap_rputs("<dt><strong>Configuration Phase Participation:</strong>\n",
408 if (modp->create_dir_config) {
412 ap_rputs("<tt>Create Directory Config</tt>", r);
415 if (modp->merge_dir_config) {
419 ap_rputs("<tt>Merge Directory Configs</tt>", r);
422 if (modp->create_server_config) {
426 ap_rputs("<tt>Create Server Config</tt>", r);
429 if (modp->merge_server_config) {
433 ap_rputs("<tt>Merge Server Configs</tt>", r);
437 ap_rputs("<tt> <em>none</em></tt>", r);
439 ap_rputs("</dt>", r);
441 module_request_hook_participate(r, modp);
445 ap_rputs("<dt><strong>Module Directives:</strong></dt>", r);
448 ap_rputs("<dd><tt>", r);
449 mod_info_html_cmd_string(r, cmd->name, 0);
450 ap_rputs(" - <i>", r);
452 ap_rputs(cmd->errmsg, r);
454 ap_rputs("</i></tt></dd>\n", r);
461 ap_rputs("<dt><strong>Current Configuration:</strong></dt>\n", r);
462 mod_info_module_cmds(r, modp->cmds, ap_conftree);
465 ap_rputs("<dt><strong>Module Directives:</strong> <tt>none</tt></dt>", r);
467 more_info = find_more_info(serv, modp->name);
469 ap_rputs("<dt><strong>Additional Information:</strong>\n</dt><dd>",
471 ap_rputs(more_info, r);
472 ap_rputs("</dd>", r);
474 ap_rputs("</dl><hr />\n", r);
480 if (!modp && r->args && strcasecmp(r->args, "server")) {
481 ap_rputs("<p><b>No such module</b></p>\n", r);
485 ap_rputs("<dl><dt>Server Module List</dt>", r);
486 for (modp = ap_top_module; modp; modp = modp->next) {
488 ap_rputs(modp->name, r);
489 ap_rputs("</dd>", r);
491 ap_rputs("</dl><hr />", r);
493 ap_rputs(ap_psignature("",r), r);
494 ap_rputs("</body></html>\n", r);
495 /* Done, turn off timeout, close file and return */
499 static const char *add_module_info(cmd_parms *cmd, void *dummy,
500 const char *name, const char *info)
502 server_rec *s = cmd->server;
503 info_svr_conf *conf = (info_svr_conf *) ap_get_module_config(s->module_config,
505 info_entry *new = apr_array_push(conf->more_info);
512 static const command_rec info_cmds[] =
514 AP_INIT_TAKE2("AddModuleInfo", add_module_info, NULL, RSRC_CONF,
515 "a module name and additional information on that module"),
519 static void register_hooks(apr_pool_t *p)
521 ap_hook_handler(display_info, NULL, NULL, APR_HOOK_MIDDLE);
524 module AP_MODULE_DECLARE_DATA info_module =
526 STANDARD20_MODULE_STUFF,
527 NULL, /* dir config creater */
528 NULL, /* dir merger --- default is to override */
529 create_info_config, /* server config */
530 merge_info_config, /* merge server config */
531 info_cmds, /* command apr_table_t */