📄 mod_info.c
字号:
/* ==================================================================== * Copyright (c) 1995-1998 The Apache Group. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the Apache Group * for use in the Apache HTTP server project (http://www.apache.org/)." * * 4. The names "Apache Server" and "Apache Group" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please contact * apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the Apache Group * for use in the Apache HTTP server project (http://www.apache.org/)." * * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Group and was originally based * on public domain software written at the National Center for * Supercomputing Applications, University of Illinois, Urbana-Champaign. * For more information on the Apache Group and the Apache HTTP server * project, please see <http://www.apache.org/>. * *//* * Info Module. Display configuration information for the server and * all included modules. * * <Location /server-info> * SetHandler server-info * </Location> * * GET /server-info - Returns full configuration page for server and all modules * GET /server-info?server - Returns server configuration only * GET /server-info?module_name - Returns configuration for a single module * GET /server-info?list - Returns quick list of included modules * * Rasmus Lerdorf <rasmus@vex.net>, May 1996 * * 05.01.96 Initial Version * * Lou Langholtz <ldl@usi.utah.edu>, July 1997 * * 07.11.97 Addition of the AddModuleInfo directive * */#include "httpd.h"#include "http_config.h"#include "http_core.h"#include "http_log.h"#include "http_main.h"#include "http_protocol.h"#include "util_script.h"#include "http_conf_globals.h"typedef struct { char *name; /* matching module name */ char *info; /* additional info */} info_entry;typedef struct { array_header *more_info;} info_svr_conf;typedef struct info_cfg_lines { char *cmd; char *line; struct info_cfg_lines *next;} info_cfg_lines;module MODULE_VAR_EXPORT info_module;extern module *top_module;static void *create_info_config(pool *p, server_rec *s){ info_svr_conf *conf = (info_svr_conf *) ap_pcalloc(p, sizeof(info_svr_conf)); conf->more_info = ap_make_array(p, 20, sizeof(info_entry)); return conf;}static void *merge_info_config(pool *p, void *basev, void *overridesv){ info_svr_conf *new = (info_svr_conf *) ap_pcalloc(p, sizeof(info_svr_conf)); info_svr_conf *base = (info_svr_conf *) basev; info_svr_conf *overrides = (info_svr_conf *) overridesv; new->more_info = ap_append_arrays(p, overrides->more_info, base->more_info); return new;}static char *mod_info_html_cmd_string(const char *string, char *buf, size_t buf_len){ const char *s; char *t; char *end_buf; s = string; t = buf; /* keep space for \0 byte */ end_buf = buf + buf_len - 1; while ((*s) && (t < end_buf)) { if (*s == '<') { strncpy(t, "<", end_buf - t); t += 4; } else if (*s == '>') { strncpy(t, ">", end_buf - t); t += 4; } else if (*s == '&') { strncpy(t, "&", end_buf - t); t += 5; } else { *t++ = *s; } s++; } /* oops, overflowed... don't overwrite */ if (t > end_buf) { *end_buf = '\0'; } else { *t = '\0'; } return (buf);}static info_cfg_lines *mod_info_load_config(pool *p, const char *filename, request_rec *r){ char s[MAX_STRING_LEN]; configfile_t *fp; info_cfg_lines *new, *ret, *prev; const char *t; fp = ap_pcfg_openfile(p, filename); if (!fp) { ap_log_rerror(APLOG_MARK, APLOG_WARNING, r, "mod_info: couldn't open config file %s", filename); return NULL; } ret = NULL; prev = NULL; while (!ap_cfg_getline(s, MAX_STRING_LEN, fp)) { if (*s == '#') { continue; /* skip comments */ } new = ap_palloc(p, sizeof(struct info_cfg_lines)); new->next = NULL; if (!ret) { ret = new; } if (prev) { prev->next = new; } t = s; new->cmd = ap_getword_conf(p, &t); if (*t) { new->line = ap_pstrdup(p, t); } else { new->line = NULL; } prev = new; } ap_cfg_closefile(fp); return (ret);}static void mod_info_module_cmds(request_rec *r, info_cfg_lines *cfg, const command_rec *cmds, char *label){ const command_rec *cmd = cmds; info_cfg_lines *li = cfg, *li_st = NULL, *li_se = NULL; info_cfg_lines *block_start = NULL; int lab = 0, nest = 0; char buf[MAX_STRING_LEN]; while (li) { if (!strncasecmp(li->cmd, "<directory", 10) || !strncasecmp(li->cmd, "<location", 9) || !strncasecmp(li->cmd, "<limit", 6) || !strncasecmp(li->cmd, "<files", 6)) { if (nest) { li_se = li; } else { li_st = li; } li = li->next; nest++; continue; } else if (nest && (!strncasecmp(li->cmd, "</limit", 7) || !strncasecmp(li->cmd, "</location", 10) || !strncasecmp(li->cmd, "</directory", 11) || !strncasecmp(li->cmd, "</files", 7))) { if (block_start) { if ((nest == 1 && block_start == li_st) || (nest == 2 && block_start == li_se)) { ap_rputs("<dd><tt>", r); if (nest == 2) { ap_rputs(" ", r); } ap_rputs(mod_info_html_cmd_string(li->cmd, buf, sizeof(buf)), r); ap_rputs(" ", r); if (li->line) { ap_rputs(mod_info_html_cmd_string(li->line, buf, sizeof(buf)), r); } ap_rputs("</tt>\n", r); nest--; if (!nest) { block_start = NULL; li_st = NULL; } else { block_start = li_st; } li_se = NULL; } else { nest--; if (!nest) { li_st = NULL; } li_se = NULL; } } else { nest--; if (!nest) { li_st = NULL; } li_se = NULL; } li = li->next; continue; } cmd = cmds; while (cmd) { if (cmd->name) { if (!strcasecmp(cmd->name, li->cmd)) { if (!lab) { ap_rputs("<dt><strong>", r); ap_rputs(label, r); ap_rputs("</strong>\n", r); lab = 1; } if (((nest && block_start == NULL) || (nest == 2 && block_start == li_st)) && (strncasecmp(li->cmd, "<directory", 10) && strncasecmp(li->cmd, "<location", 9) && strncasecmp(li->cmd, "<limit", 6) && strncasecmp(li->cmd, "</limit", 7) && strncasecmp(li->cmd, "</location", 10) && strncasecmp(li->cmd, "</directory", 11) && strncasecmp(li->cmd, "</files", 7))) { ap_rputs("<dd><tt>", r); ap_rputs(mod_info_html_cmd_string(li_st->cmd, buf, sizeof(buf)), r); ap_rputs(" ", r); if (li_st->line) { ap_rputs(mod_info_html_cmd_string(li_st->line, buf, sizeof(buf)), r); } ap_rputs("</tt>\n", r); block_start = li_st; if (li_se) { ap_rputs("<dd><tt> ", r); ap_rputs(mod_info_html_cmd_string(li_se->cmd, buf, sizeof(buf)), r); ap_rputs(" ", r); if (li_se->line) { ap_rputs(mod_info_html_cmd_string(li_se->line, buf, sizeof(buf)), r); } ap_rputs("</tt>\n", r); block_start = li_se; } } ap_rputs("<dd><tt>", r); if (nest) { ap_rputs(" ", r); } if (nest == 2) { ap_rputs(" ", r); } ap_rputs(mod_info_html_cmd_string(li->cmd, buf, sizeof(buf)), r); if (li->line) { ap_rputs(" <i>", r); ap_rputs(mod_info_html_cmd_string(li->line, buf, sizeof(buf)), r); ap_rputs("</i>", r); } ap_rputs("</tt>", r); } } else break; cmd++; } li = li->next; }}static char *find_more_info(server_rec *s, const char *module_name){ int i; info_svr_conf *conf = (info_svr_conf *) ap_get_module_config(s->module_config, &info_module); info_entry *entry = (info_entry *) conf->more_info->elts; if (!module_name) { return 0; } for (i = 0; i < conf->more_info->nelts; i++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -