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
29
* GET /server-info?config - Returns full configuration
30
* GET /server-info?hooks - Returns a listing of the modules active for each hook
33
* Rasmus Lerdorf <rasmus vex.net>, May 1996
36
* Lou Langholtz <ldl usi.utah.edu>, July 1997
39
* Ryan Morgan <rmorgan covalent.net>, August 2000
45
#include "apr_strings.h"
47
#define APR_WANT_STRFUNC
53
#include "http_config.h"
54
#include "http_core.h"
56
#include "http_main.h"
57
#include "http_protocol.h"
58
#include "http_connection.h"
59
#include "http_request.h"
60
#include "util_script.h"
65
const char *name; /* matching module name */
66
const char *info; /* additional info */
71
apr_array_header_t *more_info;
74
module AP_MODULE_DECLARE_DATA info_module;
76
static void *create_info_config(apr_pool_t * p, server_rec * s)
79
(info_svr_conf *) apr_pcalloc(p, sizeof(info_svr_conf));
81
conf->more_info = apr_array_make(p, 20, sizeof(info_entry));
85
static void *merge_info_config(apr_pool_t * p, void *basev, void *overridesv)
88
(info_svr_conf *) apr_pcalloc(p, sizeof(info_svr_conf));
89
info_svr_conf *base = (info_svr_conf *) basev;
90
info_svr_conf *overrides = (info_svr_conf *) overridesv;
93
apr_array_append(p, overrides->more_info, base->more_info);
97
static void put_int_flush_right(request_rec * r, int i, int field)
99
if (field > 1 || i > 9)
100
put_int_flush_right(r, i / 10, field - 1);
102
ap_rputc('0' + i % 10, r);
104
ap_rputs(" ", r);
107
static void mod_info_indent(request_rec * r, int nest,
108
const char *thisfn, int linenum)
112
ap_get_module_config(r->request_config, &info_module);
114
thisfn = "*UNKNOWN*";
115
if (prevfn == NULL || 0 != strcmp(prevfn, thisfn)) {
116
thisfn = ap_escape_html(r->pool, thisfn);
117
ap_rprintf(r, "<dd><tt><strong>In file: %s</strong></tt></dd>\n",
119
ap_set_module_config(r->request_config, &info_module,
123
ap_rputs("<dd><tt>", r);
124
put_int_flush_right(r, linenum > 0 ? linenum : 0, 4);
125
ap_rputs(": ", r);
127
for (i = 1; i <= nest; ++i) {
128
ap_rputs(" ", r);
132
static void mod_info_show_cmd(request_rec * r, const ap_directive_t * dir,
135
mod_info_indent(r, nest, dir->filename, dir->line_num);
136
ap_rprintf(r, "%s <i>%s</i></tt></dd>\n",
137
ap_escape_html(r->pool, dir->directive),
138
ap_escape_html(r->pool, dir->args));
141
static void mod_info_show_open(request_rec * r, const ap_directive_t * dir,
144
mod_info_indent(r, nest, dir->filename, dir->line_num);
145
ap_rprintf(r, "%s %s</tt></dd>\n",
146
ap_escape_html(r->pool, dir->directive),
147
ap_escape_html(r->pool, dir->args));
150
static void mod_info_show_close(request_rec * r, const ap_directive_t * dir,
153
const char *dirname = dir->directive;
154
mod_info_indent(r, nest, dir->filename, 0);
155
if (*dirname == '<') {
156
ap_rprintf(r, "</%s></tt></dd>",
157
ap_escape_html(r->pool, dirname + 1));
160
ap_rprintf(r, "/%s</tt></dd>", ap_escape_html(r->pool, dirname));
164
static int mod_info_has_cmd(const command_rec * cmds, ap_directive_t * dir)
166
const command_rec *cmd;
169
for (cmd = cmds; cmd->name; ++cmd) {
170
if (strcasecmp(cmd->name, dir->directive) == 0)
176
static void mod_info_show_parents(request_rec * r, ap_directive_t * node,
180
mod_info_show_parents(r, node->parent, from, to - 1);
181
mod_info_show_open(r, node, to);
184
static int mod_info_module_cmds(request_rec * r, const command_rec * cmds,
185
ap_directive_t * node, int from, int level)
190
ap_set_module_config(r->request_config, &info_module, NULL);
191
for (dir = node; dir; dir = dir->next) {
192
if (dir->first_child != NULL) {
193
if (level < mod_info_module_cmds(r, cmds, dir->first_child,
196
mod_info_show_close(r, dir, level);
199
else if (mod_info_has_cmd(cmds, dir)) {
201
mod_info_show_parents(r, dir->parent, shown, level - 1);
204
mod_info_show_cmd(r, dir, level);
211
{ /*XXX: should get something from apr_hooks.h instead */
212
void (*pFunc) (void); /* just to get the right size */
214
const char *const *aszPredecessors;
215
const char *const *aszSuccessors;
220
* hook_get_t is a pointer to a function that takes void as an argument and
221
* returns a pointer to an apr_array_header_t. The nasty WIN32 ifdef
222
* is required to account for the fact that the ap_hook* calls all use
223
* STDCALL calling convention.
225
typedef apr_array_header_t *(
229
* hook_get_t) (void);
237
static hook_lookup_t startup_hooks[] = {
238
{"Pre-Config", ap_hook_get_pre_config},
239
{"Test Configuration", ap_hook_get_test_config},
240
{"Post Configuration", ap_hook_get_post_config},
241
{"Open Logs", ap_hook_get_open_logs},
242
{"Child Init", ap_hook_get_child_init},
246
static hook_lookup_t request_hooks[] = {
247
{"Pre-Connection", ap_hook_get_pre_connection},
248
{"Create Connection", ap_hook_get_create_connection},
249
{"Process Connection", ap_hook_get_process_connection},
250
{"Create Request", ap_hook_get_create_request},
251
{"Post-Read Request", ap_hook_get_post_read_request},
252
{"Header Parse", ap_hook_get_header_parser},
253
{"HTTP Scheme", ap_hook_get_http_scheme},
254
{"Default Port", ap_hook_get_default_port},
255
{"Quick Handler", ap_hook_get_quick_handler},
256
{"Translate Name", ap_hook_get_translate_name},
257
{"Map to Storage", ap_hook_get_map_to_storage},
258
{"Check Access", ap_hook_get_access_checker},
259
{"Verify User ID", ap_hook_get_check_user_id},
260
{"Verify User Access", ap_hook_get_auth_checker},
261
{"Check Type", ap_hook_get_type_checker},
262
{"Fixups", ap_hook_get_fixups},
263
{"Insert Filters", ap_hook_get_insert_filter},
264
{"Content Handlers", ap_hook_get_handler},
265
{"Logging", ap_hook_get_log_transaction},
266
{"Insert Errors", ap_hook_get_insert_error_filter},
270
static int module_find_hook(module * modp, hook_get_t hook_get)
273
apr_array_header_t *hooks = hook_get();
280
elts = (hook_struct_t *) hooks->elts;
282
for (i = 0; i < hooks->nelts; i++) {
283
if (strcmp(elts[i].szName, modp->name) == 0) {
291
static void module_participate(request_rec * r,
293
hook_lookup_t * lookup, int *comma)
295
if (module_find_hook(modp, lookup->get)) {
299
ap_rvputs(r, "<tt>", lookup->name, "</tt>", NULL);
304
static void module_request_hook_participate(request_rec * r, module * modp)
308
ap_rputs("<dt><strong>Request Phase Participation:</strong>\n", r);
310
for (i = 0; request_hooks[i].name; i++) {
311
module_participate(r, modp, &request_hooks[i], &comma);
315
ap_rputs("<tt> <em>none</em></tt>", r);
317
ap_rputs("</dt>\n", r);
320
static const char *find_more_info(server_rec * s, const char *module_name)
323
info_svr_conf *conf =
324
(info_svr_conf *) ap_get_module_config(s->module_config,
326
info_entry *entry = (info_entry *) conf->more_info->elts;
331
for (i = 0; i < conf->more_info->nelts; i++) {
332
if (!strcmp(module_name, entry->name)) {
340
static int show_server_settings(request_rec * r)
342
server_rec *serv = r->server;
343
int max_daemons, forked, threaded;
345
ap_rputs("<h2><a name=\"server\">Server Settings</a></h2>", r);
347
"<dl><dt><strong>Server Version:</strong> "
348
"<font size=\"+1\"><tt>%s</tt></font></dt>\n",
349
ap_get_server_version());
351
"<dt><strong>Server Built:</strong> "
352
"<font size=\"+1\"><tt>%s</tt></font></dt>\n",
353
ap_get_server_built());
355
"<dt><strong>Module Magic Number:</strong> "
356
"<tt>%d:%d</tt></dt>\n", MODULE_MAGIC_NUMBER_MAJOR,
357
MODULE_MAGIC_NUMBER_MINOR);
359
"<dt><strong>Hostname/port:</strong> "
360
"<tt>%s:%u</tt></dt>\n", ap_get_server_name(r),
361
ap_get_server_port(r));
363
"<dt><strong>Timeouts:</strong> "
364
"<tt>connection: %d "
365
"keep-alive: %d</tt></dt>",
366
(int) (apr_time_sec(serv->timeout)),
367
(int) (apr_time_sec(serv->timeout)));
368
ap_mpm_query(AP_MPMQ_MAX_DAEMON_USED, &max_daemons);
369
ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded);
370
ap_mpm_query(AP_MPMQ_IS_FORKED, &forked);
371
ap_rprintf(r, "<dt><strong>MPM Name:</strong> <tt>%s</tt></dt>\n",
374
"<dt><strong>MPM Information:</strong> "
375
"<tt>Max Daemons: %d Threaded: %s Forked: %s</tt></dt>\n",
376
max_daemons, threaded ? "yes" : "no", forked ? "yes" : "no");
378
"<dt><strong>Server Architecture:</strong> "
379
"<tt>%ld-bit</tt></dt>\n", 8 * (long) sizeof(void *));
381
"<dt><strong>Server Root:</strong> "
382
"<tt>%s</tt></dt>\n", ap_server_root);
384
"<dt><strong>Config File:</strong> "
385
"<tt>%s</tt></dt>\n", ap_conftree->filename);
387
ap_rputs("<dt><strong>Server Built With:</strong>\n"
388
"<tt style=\"white-space: pre;\">\n", r);
390
/* TODO: Not all of these defines are getting set like they do in main.c.
391
* Missing some headers?
394
#ifdef BIG_SECURITY_HOLE
395
ap_rputs(" -D BIG_SECURITY_HOLE\n", r);
398
#ifdef SECURITY_HOLE_PASS_AUTHORIZATION
399
ap_rputs(" -D SECURITY_HOLE_PASS_AUTHORIZATION\n", r);
403
ap_rputs(" -D OS=\"" OS "\"\n", r);
406
#ifdef APACHE_MPM_DIR
407
ap_rputs(" -D APACHE_MPM_DIR=\"" APACHE_MPM_DIR "\"\n", r);
411
ap_rputs(" -D HAVE_SHMGET\n", r);
414
#if APR_FILE_BASED_SHM
415
ap_rputs(" -D APR_FILE_BASED_SHM\n", r);
419
ap_rputs(" -D APR_HAS_SENDFILE\n", r);
423
ap_rputs(" -D APR_HAS_MMAP\n", r);
427
ap_rputs(" -D NO_WRITEV\n", r);
431
ap_rputs(" -D NO_LINGCLOSE\n", r);
435
ap_rputs(" -D APR_HAVE_IPV6 (IPv4-mapped addresses ", r);
436
#ifdef AP_ENABLE_V4_MAPPED
437
ap_rputs("enabled)\n", r);
439
ap_rputs("disabled)\n", r);
443
#if APR_USE_FLOCK_SERIALIZE
444
ap_rputs(" -D APR_USE_FLOCK_SERIALIZE\n", r);
447
#if APR_USE_SYSVSEM_SERIALIZE
448
ap_rputs(" -D APR_USE_SYSVSEM_SERIALIZE\n", r);
451
#if APR_USE_POSIXSEM_SERIALIZE
452
ap_rputs(" -D APR_USE_POSIXSEM_SERIALIZE\n", r);
455
#if APR_USE_FCNTL_SERIALIZE
456
ap_rputs(" -D APR_USE_FCNTL_SERIALIZE\n", r);
459
#if APR_USE_PROC_PTHREAD_SERIALIZE
460
ap_rputs(" -D APR_USE_PROC_PTHREAD_SERIALIZE\n", r);
462
#if APR_PROCESS_LOCK_IS_GLOBAL
463
ap_rputs(" -D APR_PROCESS_LOCK_IS_GLOBAL\n", r);
466
#ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
467
ap_rputs(" -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT\n", r);
470
#if APR_HAS_OTHER_CHILD
471
ap_rputs(" -D APR_HAS_OTHER_CHILD\n", r);
474
#ifdef AP_HAVE_RELIABLE_PIPED_LOGS
475
ap_rputs(" -D AP_HAVE_RELIABLE_PIPED_LOGS\n", r);
479
ap_rputs(" -D BUFFERED_LOGS\n", r);
481
ap_rputs(" -D PIPE_BUF=%ld\n", (long) PIPE_BUF, r);
485
#if APR_CHARSET_EBCDIC
486
ap_rputs(" -D APR_CHARSET_EBCDIC\n", r);
489
#ifdef NEED_HASHBANG_EMUL
490
ap_rputs(" -D NEED_HASHBANG_EMUL\n", r);
494
ap_rputs(" -D SHARED_CORE\n", r);
497
/* This list displays the compiled in default paths: */
499
ap_rputs(" -D HTTPD_ROOT=\"" HTTPD_ROOT "\"\n", r);
503
ap_rputs(" -D SUEXEC_BIN=\"" SUEXEC_BIN "\"\n", r);
506
#if defined(SHARED_CORE) && defined(SHARED_CORE_DIR)
507
ap_rputs(" -D SHARED_CORE_DIR=\"" SHARED_CORE_DIR "\"\n", r);
510
#ifdef DEFAULT_PIDLOG
511
ap_rputs(" -D DEFAULT_PIDLOG=\"" DEFAULT_PIDLOG "\"\n", r);
514
#ifdef DEFAULT_SCOREBOARD
515
ap_rputs(" -D DEFAULT_SCOREBOARD=\"" DEFAULT_SCOREBOARD "\"\n", r);
518
#ifdef DEFAULT_LOCKFILE
519
ap_rputs(" -D DEFAULT_LOCKFILE=\"" DEFAULT_LOCKFILE "\"\n", r);
522
#ifdef DEFAULT_ERRORLOG
523
ap_rputs(" -D DEFAULT_ERRORLOG=\"" DEFAULT_ERRORLOG "\"\n", r);
527
#ifdef AP_TYPES_CONFIG_FILE
528
ap_rputs(" -D AP_TYPES_CONFIG_FILE=\"" AP_TYPES_CONFIG_FILE "\"\n", r);
531
#ifdef SERVER_CONFIG_FILE
532
ap_rputs(" -D SERVER_CONFIG_FILE=\"" SERVER_CONFIG_FILE "\"\n", r);
534
ap_rputs("</tt></dt>\n", r);
535
ap_rputs("</dl><hr />", r);
539
static int dump_a_hook(request_rec * r, hook_get_t hook_get)
544
apr_array_header_t *hooks = hook_get();
550
if (r->args && strcasecmp(r->args, "hooks") == 0) {
557
elts = (hook_struct_t *) hooks->elts;
559
for (i = 0; i < hooks->nelts; i++) {
561
" %02d <a href=\"%c%s\">%s</a> <br/>",
562
elts[i].nOrder, qs, elts[i].szName, elts[i].szName);
567
static int show_active_hooks(request_rec * r)
570
ap_rputs("<h2><a name=\"startup_hooks\">Startup Hooks</a></h2>\n<dl>", r);
572
for (i = 0; startup_hooks[i].name; i++) {
573
ap_rprintf(r, "<dt><strong>%s:</strong>\n <br /><tt>\n",
574
startup_hooks[i].name);
575
dump_a_hook(r, startup_hooks[i].get);
576
ap_rputs("\n </tt>\n</dt>\n", r);
580
("</dl>\n<hr />\n<h2><a name=\"request_hooks\">Request Hooks</a></h2>\n<dl>",
583
for (i = 0; request_hooks[i].name; i++) {
584
ap_rprintf(r, "<dt><strong>%s:</strong>\n <br /><tt>\n",
585
request_hooks[i].name);
586
dump_a_hook(r, request_hooks[i].get);
587
ap_rputs("\n </tt>\n</dt>\n", r);
590
ap_rputs("</dl>\n<hr />\n", r);
595
static int display_info(request_rec * r)
598
server_rec *serv = r->server;
599
const char *more_info;
600
const command_rec *cmd = NULL;
603
if (strcmp(r->handler, "server-info"))
606
r->allowed |= (AP_METHOD_BIT << M_GET);
607
if (r->method_number != M_GET)
610
ap_set_content_type(r, "text/html");
612
ap_rputs(DOCTYPE_XHTML_1_0T
613
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
615
" <title>Server Information</title>\n" "</head>\n", r);
616
ap_rputs("<body><h1 style=\"text-align: center\">"
617
"Apache Server Information</h1>\n", r);
618
if (!r->args || strcasecmp(r->args, "list")) {
620
ap_rputs("<dl><dt><tt>Subpages:<br />", r);
621
ap_rputs("<a href=\"?config\">Configuration Files</a>, "
622
"<a href=\"?server\">Server Settings</a>, "
623
"<a href=\"?list\">Module List</a>, "
624
"<a href=\"?hooks\">Active Hooks</a>", r);
625
ap_rputs("</tt></dt></dl><hr />", r);
627
ap_rputs("<dl><dt><tt>Sections:<br />", r);
628
ap_rputs("<a href=\"#server\">Server Settings</a>, "
629
"<a href=\"#startup_hooks\">Startup Hooks</a>, "
630
"<a href=\"#request_hooks\">Request Hooks</a>", r);
631
ap_rputs("</tt></dt></dl><hr />", r);
633
ap_rputs("<dl><dt><tt>Loaded Modules: <br />", r);
634
/* TODO: Sort by Alpha */
635
for (modp = ap_top_module; modp; modp = modp->next) {
636
ap_rprintf(r, "<a href=\"#%s\">%s</a>", modp->name,
642
ap_rputs("</tt></dt></dl><hr />", r);
645
if (!r->args || !strcasecmp(r->args, "server")) {
646
show_server_settings(r);
649
if (!r->args || !strcasecmp(r->args, "hooks")) {
650
show_active_hooks(r);
653
if (r->args && 0 == strcasecmp(r->args, "config")) {
654
ap_rputs("<dl><dt><strong>Configuration:</strong>\n", r);
655
mod_info_module_cmds(r, NULL, ap_conftree, 0, 0);
656
ap_rputs("</dl><hr />", r);
659
for (modp = ap_top_module; modp; modp = modp->next) {
660
if (!r->args || !strcasecmp(modp->name, r->args)) {
662
"<dl><dt><a name=\"%s\"><strong>Module Name:</strong></a> "
663
"<font size=\"+1\"><tt><a href=\"?%s\">%s</a></tt></font></dt>\n",
664
modp->name, modp->name, modp->name);
665
ap_rputs("<dt><strong>Content handlers:</strong> ", r);
667
if (module_find_hook(modp, ap_hook_get_handler)) {
668
ap_rputs("<tt> <em>yes</em></tt>", r);
671
ap_rputs("<tt> <em>none</em></tt>", r);
674
ap_rputs("</dt>", r);
676
("<dt><strong>Configuration Phase Participation:</strong>\n",
678
if (modp->create_dir_config) {
682
ap_rputs("<tt>Create Directory Config</tt>", r);
685
if (modp->merge_dir_config) {
689
ap_rputs("<tt>Merge Directory Configs</tt>", r);
692
if (modp->create_server_config) {
696
ap_rputs("<tt>Create Server Config</tt>", r);
699
if (modp->merge_server_config) {
703
ap_rputs("<tt>Merge Server Configs</tt>", r);
707
ap_rputs("<tt> <em>none</em></tt>", r);
709
ap_rputs("</dt>", r);
711
module_request_hook_participate(r, modp);
716
("<dt><strong>Module Directives:</strong></dt>",
720
ap_rprintf(r, "<dd><tt>%s%s - <i>",
721
ap_escape_html(r->pool, cmd->name),
722
cmd->name[0] == '<' ? ">" : "");
724
ap_rputs(cmd->errmsg, r);
726
ap_rputs("</i></tt></dd>\n", r);
734
("<dt><strong>Current Configuration:</strong></dt>\n",
736
mod_info_module_cmds(r, modp->cmds, ap_conftree, 0,
741
("<dt><strong>Module Directives:</strong> <tt>none</tt></dt>",
744
more_info = find_more_info(serv, modp->name);
747
("<dt><strong>Additional Information:</strong>\n</dt><dd>",
749
ap_rputs(more_info, r);
750
ap_rputs("</dd>", r);
752
ap_rputs("</dl><hr />\n", r);
758
if (!modp && r->args && strcasecmp(r->args, "server")) {
759
ap_rputs("<p><b>No such module</b></p>\n", r);
764
ap_rputs("<dl><dt>Server Module List</dt>", r);
765
for (modp = ap_top_module; modp; modp = modp->next) {
767
ap_rputs(modp->name, r);
768
ap_rputs("</dd>", r);
770
ap_rputs("</dl><hr />", r);
772
ap_rputs(ap_psignature("", r), r);
773
ap_rputs("</body></html>\n", r);
774
/* Done, turn off timeout, close file and return */
778
static const char *add_module_info(cmd_parms * cmd, void *dummy,
779
const char *name, const char *info)
781
server_rec *s = cmd->server;
782
info_svr_conf *conf =
783
(info_svr_conf *) ap_get_module_config(s->module_config,
785
info_entry *new = apr_array_push(conf->more_info);
792
static const command_rec info_cmds[] = {
793
AP_INIT_TAKE2("AddModuleInfo", add_module_info, NULL, RSRC_CONF,
794
"a module name and additional information on that module"),
798
static void register_hooks(apr_pool_t * p)
800
ap_hook_handler(display_info, NULL, NULL, APR_HOOK_MIDDLE);
803
module AP_MODULE_DECLARE_DATA info_module = {
804
STANDARD20_MODULE_STUFF,
805
NULL, /* dir config creater */
806
NULL, /* dir merger --- default is to override */
807
create_info_config, /* server config */
808
merge_info_config, /* merge server config */
809
info_cmds, /* command apr_table_t */