home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 8 / CDACTUAL8.iso / share / os2 / varios / apache / mod_info.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-27  |  13.5 KB  |  427 lines

  1. /* ====================================================================
  2.  * Copyright (c) 1995, 1996 The Apache Group.  All rights reserved.
  3.  *
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  *
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer. 
  10.  *
  11.  * 2. Redistributions in binary form must reproduce the above copyright
  12.  *    notice, this list of conditions and the following disclaimer in
  13.  *    the documentation and/or other materials provided with the
  14.  *    distribution.
  15.  *
  16.  * 3. All advertising materials mentioning features or use of this
  17.  *    software must display the following acknowledgment:
  18.  *    "This product includes software developed by the Apache Group
  19.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  20.  *
  21.  * 4. The names "Apache Server" and "Apache Group" must not be used to
  22.  *    endorse or promote products derived from this software without
  23.  *    prior written permission.
  24.  *
  25.  * 5. Redistributions of any form whatsoever must retain the following
  26.  *    acknowledgment:
  27.  *    "This product includes software developed by the Apache Group
  28.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  29.  *
  30.  * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  31.  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  32.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  33.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  34.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  41.  * OF THE POSSIBILITY OF SUCH DAMAGE.
  42.  * ====================================================================
  43.  *
  44.  * This software consists of voluntary contributions made by many
  45.  * individuals on behalf of the Apache Group and was originally based
  46.  * on public domain software written at the National Center for
  47.  * Supercomputing Applications, University of Illinois, Urbana-Champaign.
  48.  * For more information on the Apache Group and the Apache HTTP server
  49.  * project, please see <http://www.apache.org/>.
  50.  *
  51.  */
  52.  
  53. /* 
  54.  * Info Module.  Display configuration information for the server and
  55.  * all included modules.
  56.  *
  57.  * <Location /info>
  58.  * SetHandler server-info
  59.  * </Location>
  60.  *
  61.  * GET /info - Returns full configuration page for server and all modules
  62.  * GET /info?server - Returns server configuration only
  63.  * GET /info?module_name - Returns configuration for a single module
  64.  * GET /info?list - Returns quick list of included modules
  65.  *
  66.  * Rasmus Lerdorf <rasmus@vex.net>, May 1996
  67.  *
  68.  * 05.01.96 Initial Version
  69.  * 
  70.  */
  71.  
  72. #include "httpd.h"
  73. #include "http_config.h"
  74. #include "http_core.h"
  75. #include "http_log.h"
  76. #include "http_main.h"
  77. #include "http_protocol.h"
  78. #include "util_script.h"
  79.  
  80. typedef struct mod_info_config_lines {
  81.     char *cmd;
  82.     char *line;
  83.     struct mod_info_config_lines *next;
  84. } mod_info_config_lines;
  85.  
  86. module info_module;
  87. extern module *top_module;
  88.  
  89. char *mod_info_html_cmd_string(char *string) {
  90.     char *s,*t;
  91.     static char ret[64];  /* What is the max size of a command? */
  92.  
  93.     ret[0]='\0';
  94.     s = string;
  95.     t=ret;    
  96.     while(*s) {
  97.         if(*s=='<') { strcat(t,"<"); t+=4*sizeof(char); }
  98.         else if(*s=='>') { strcat(t,">"); t+=4*sizeof(char); }
  99.         else *t++=*s;
  100.         s++;
  101.         *t='\0';
  102.     }
  103.     return(ret);
  104. }
  105.  
  106. mod_info_config_lines *mod_info_load_config(pool *p, char *filename) {
  107.     char s[MAX_STRING_LEN];
  108.     FILE *fp;
  109.     mod_info_config_lines *new, *ret=NULL, *prev=NULL;
  110.     char *t,*tt,o;
  111.     
  112.     fp = pfopen(p,filename,"r");
  113.     if(!fp) return NULL;
  114.     while(!cfg_getline(s,MAX_STRING_LEN,fp)) {
  115.         if(*s=='#') continue; /* skip comments */
  116.         new = palloc(p,sizeof(struct mod_info_config_lines));
  117.         new->next = NULL;
  118.         if(!ret) ret=new;
  119.         if(prev) prev->next=new;
  120.         t=strchr(s,' ');    
  121.         tt=strchr(s,'\t');
  122.         if(t && tt) t = (t<tt)?t:tt;
  123.         else if(tt) t=tt;
  124.         if(t) {
  125.             o=*t;
  126.             *t='\0';
  127.             new->cmd = pstrdup(p,s);
  128.             new->line = pstrdup(p,t+1);
  129.             *t=o;
  130.         } else {
  131.             new->cmd = pstrdup(p,s);
  132.             new->line = NULL;
  133.         }
  134.         prev=new;    
  135.     }
  136.     pfclose(p,fp);
  137.     return(ret);
  138. }
  139.  
  140. void mod_info_module_cmds(request_rec *r, mod_info_config_lines *cfg, command_rec *cmds,char *label) {
  141.     command_rec *cmd=cmds;
  142.     mod_info_config_lines *li=cfg,*li_st=NULL,*li_se=NULL,*block_start=NULL;
  143.     int lab=0, nest=0;
  144.  
  145.     while(li) {
  146.         if(!strncasecmp(li->cmd,"<directory",10) || !strncasecmp(li->cmd,"<location",9) ||
  147.           !strncasecmp(li->cmd,"<limit",6)) { 
  148.             if(nest) li_se=li;
  149.             else li_st=li; 
  150.             li=li->next; 
  151.             nest++;
  152.             continue; 
  153.         } else if(nest && (!strncasecmp(li->cmd,"</limit",7) ||
  154.           !strncasecmp(li->cmd,"</location",10) || !strncasecmp(li->cmd,"</directory",11))) { 
  155.             if(block_start) {
  156.                 if((nest==1 && block_start==li_st) || (nest==2 && block_start==li_se)) {
  157.                     rputs("<dd><tt>",r);
  158.                     if(nest==2) rputs("  ",r);
  159.                     rputs(mod_info_html_cmd_string(li->cmd),r);
  160.                     rputs(" ",r);
  161.                     if(li->line) rputs(mod_info_html_cmd_string(li->line),r);
  162.                     rputs("</tt>\n",r);
  163.                     nest--;
  164.                     if(!nest) {
  165.                         block_start=NULL;
  166.                         li_st=NULL;
  167.                     } else {
  168.                         block_start=li_st;
  169.                     }
  170.                     li_se=NULL; 
  171.                 } else {
  172.                     nest--;    
  173.                     if(!nest) {
  174.                         li_st=NULL;
  175.                     }
  176.                     li_se=NULL; 
  177.                 }
  178.             } else {
  179.                 nest--;    
  180.                 if(!nest) {
  181.                     li_st=NULL;
  182.                 }
  183.                 li_se=NULL; 
  184.             }
  185.             li=li->next;
  186.             continue;
  187.         }
  188.         cmd = cmds;
  189.         while(cmd) {
  190.             if(cmd->name) {
  191.                 if(!strcasecmp(cmd->name,li->cmd)) {
  192.                     if(!lab) {
  193.                         rputs("<dt><strong>",r);
  194.                         rputs(label,r);
  195.                         rputs("</strong>\n",r);
  196.                         lab=1;
  197.                     }
  198.                     if(((nest && block_start==NULL) || (nest==2 && block_start==li_st))
  199.                       && (strncasecmp(li->cmd,"<directory",10) &&
  200.                       strncasecmp(li->cmd,"<location",9) && strncasecmp(li->cmd,"<limit",6) &&
  201.                       strncasecmp(li->cmd,"</limit",7) && strncasecmp(li->cmd,"</location",10) &&
  202.                       strncasecmp(li->cmd,"</directory",11))) {
  203.                         rputs("<dd><tt>",r);
  204.                         rputs(mod_info_html_cmd_string(li_st->cmd),r);
  205.                         rputs(" ",r);
  206.                         if(li_st->line) rputs(mod_info_html_cmd_string(li_st->line),r);
  207.                         rputs("</tt>\n",r);
  208.                         block_start=li_st;
  209.                         if(li_se) {
  210.                             rputs("<dd><tt>  ",r);
  211.                             rputs(mod_info_html_cmd_string(li_se->cmd),r);
  212.                             rputs(" ",r);
  213.                             if(li_se->line) rputs(mod_info_html_cmd_string(li_se->line),r);
  214.                             rputs("</tt>\n",r);
  215.                             block_start=li_se;
  216.                         }
  217.                     }    
  218.                     rputs("<dd><tt>",r);
  219.                     if(nest) rputs("  ",r);
  220.                     if(nest==2) rputs("  ",r);
  221.                     rputs(mod_info_html_cmd_string(li->cmd),r);
  222.                     if(li->line) {
  223.                         rputs(" <i>",r);
  224.                         rputs(mod_info_html_cmd_string(li->line),r);
  225.                         rputs("</i></tt>",r);
  226.                     }
  227.                 }
  228.             } else break;
  229.             cmd++;
  230.         }
  231.         li = li->next;
  232.     }
  233. }
  234.  
  235. int display_info(request_rec *r) {
  236.     module *modp = NULL;
  237.     char buf[256];
  238.     extern char *module_names[];
  239.     char **names = module_names;
  240.     command_rec *cmd=NULL;
  241.     handler_rec *hand=NULL;
  242.     server_rec *serv = r->server;
  243.     int comma=0;
  244.     mod_info_config_lines *mod_info_cfg_httpd=NULL;
  245.     mod_info_config_lines *mod_info_cfg_srm=NULL;
  246.     mod_info_config_lines *mod_info_cfg_access=NULL;
  247.     extern int standalone;
  248.     extern uid_t user_id;
  249.     extern char *user_name;
  250.     extern gid_t group_id;
  251.     extern int max_requests_per_child;
  252.     extern char *pid_fname;
  253.     extern char *scoreboard_fname;
  254.     extern int daemons_to_start;
  255.     extern int daemons_min_free;
  256.     extern int daemons_max_free;
  257.     extern int daemons_limit;
  258.     extern char server_root[MAX_STRING_LEN];
  259.     extern char server_confname[MAX_STRING_LEN];
  260.  
  261.     /* Init timeout */
  262.     soft_timeout ("send server info", r);
  263.     r->content_type = "text/html";        
  264.     send_http_header(r);
  265.     if(r->header_only) {
  266.         return 0;
  267.     }
  268.     
  269.     rputs("<html><head><title>Server Information</title></head>\n",r);
  270.     rputs("<body><h1 align=center>Apache Server Information</h1>\n",r);
  271.     if(!r->args || strcasecmp(r->args,"list")) {
  272.         sprintf(buf,"%s/%s",server_root,server_confname);
  273.         mod_info_cfg_httpd = mod_info_load_config(r->pool,buf);
  274.         sprintf(buf,"%s/%s",server_root,serv->srm_confname);
  275.         mod_info_cfg_srm = mod_info_load_config(r->pool,buf);
  276.         sprintf(buf,"%s/%s",server_root,serv->access_confname);
  277.         mod_info_cfg_access = mod_info_load_config(r->pool,buf);
  278.         if(!r->args) {
  279.             rputs("<tt><a href=\"#server\">Server Settings</a>, ",r);
  280.             for(modp = top_module, names=module_names; modp; modp = modp->next, names++) {
  281.                 sprintf(buf,"<a href=\"#%s\">%s</a>",*names,*names);
  282.                 rputs(buf, r);
  283.                 if(modp->next) rputs(", ",r);
  284.             }
  285.             rputs("</tt><hr>",r);
  286.  
  287.         }
  288.         if(!r->args || !strcasecmp(r->args,"server")) {    
  289.             sprintf(buf,"<a name=\"server\"><strong>Server Version:</strong> <font size=+1><tt>%s</tt></a></font><br>\n",SERVER_VERSION);
  290.             rputs(buf,r);
  291.             sprintf(buf,"<strong>API Version:</strong> <tt>%d</tt><br>\n",MODULE_MAGIC_NUMBER);
  292.             rputs(buf,r);
  293.             sprintf(buf,"<strong>Run Mode:</strong> <tt>%s</tt><br>\n",standalone?"standalone":"inetd");
  294.             rputs(buf,r);
  295.             sprintf(buf,"<strong>User/Group:</strong> <tt>%s(%d)/%d</tt><br>\n",user_name,(int)user_id,(int)group_id);
  296.             rputs(buf,r);
  297.             sprintf(buf,"<strong>Hostname/port:</strong> <tt>%s:%d</tt><br>\n",serv->server_hostname,serv->port);
  298.             rputs(buf,r);
  299.             sprintf(buf,"<strong>Daemons:</strong> <tt>start: %d    min idle: %d    max idle: %d    max: %d</tt><br>\n",daemons_to_start,daemons_min_free,daemons_max_free,daemons_limit);
  300.             rputs(buf,r);
  301.             sprintf(buf,"<strong>Max Requests:</strong> <tt>per child: %d    per connection: %d</tt><br>\n",max_requests_per_child,serv->keep_alive);
  302.             rputs(buf,r);
  303.             sprintf(buf,"<strong>Timeouts:</strong> <tt>connection: %d    keep-alive: %d</tt><br>",serv->timeout,serv->keep_alive_timeout);
  304.             rputs(buf,r);
  305.             sprintf(buf,"<strong>Server Root:</strong> <tt>%s</tt><br>\n",server_root);
  306.             rputs(buf,r);
  307.             sprintf(buf,"<strong>Config File:</strong> <tt>%s</tt><br>\n",server_confname);
  308.             rputs(buf,r);
  309.             sprintf(buf,"<strong>PID File:</strong> <tt>%s</tt><br>\n",pid_fname);
  310.             rputs(buf,r);
  311.             sprintf(buf,"<strong>Scoreboard File:</strong> <tt>%s</tt><br>\n",scoreboard_fname);
  312.             rputs(buf,r);
  313.         }
  314.         rputs("<hr><dl>",r);
  315.         for(modp = top_module, names=module_names; modp; modp = modp->next, names++) {
  316.             if(!r->args || !strcasecmp(*names,r->args)) {    
  317.                 sprintf(buf,"<dt><a name=\"%s\"><strong>Module Name:</strong> <font size=+1><tt>%s</tt></a></font>\n",*names,*names);
  318.                 rputs(buf,r);
  319.                 rputs("<dt><strong>Content-types affected:</strong>",r);    
  320.                 hand = modp->handlers;
  321.                 if(hand) {
  322.                     while(hand) {
  323.                         if(hand->content_type) {
  324.                             sprintf(buf," <tt>%s</tt>\n",hand->content_type);    
  325.                             rputs(buf,r);
  326.                         } else break;
  327.                         hand++;
  328.                         if(hand && hand->content_type) rputs(",",r);
  329.                     }
  330.                 } else {
  331.                     rputs("<tt> none</tt>",r);
  332.                 }
  333.                 rputs("<dt><strong>Module Groups:</strong> \n",r);
  334.                 if(modp->translate_handler) {
  335.                     rputs("<tt>Translate Handler</tt>\n",r);
  336.                     comma=1;
  337.                 }
  338.                 if(modp->check_user_id) {
  339.                     if(comma) rputs(", ",r);
  340.                     rputs("<tt>User ID Checking</tt>\n",r);
  341.                     comma=1;
  342.                 }
  343.                 if(modp->auth_checker) {
  344.                     if(comma) rputs(", ",r);
  345.                     rputs("<tt>Authentication Checking</tt>\n",r);
  346.                     comma=1;
  347.                 }
  348.                 if(modp->access_checker) {
  349.                     if(comma) rputs(", ",r);
  350.                     rputs("<tt>Access Checking</tt>\n",r);
  351.                     comma=1;
  352.                 }
  353.                 if(modp->type_checker) {
  354.                     if(comma) rputs(", ",r);
  355.                     rputs("<tt>Type Checking</tt>\n",r);
  356.                     comma=1;
  357.                 }
  358.                 if(modp->fixer_upper) {
  359.                     if(comma) rputs(", ",r);
  360.                     rputs("<tt>Header Fixer</tt>\n",r);
  361.                     comma=1;
  362.                 }
  363.                 if(modp->logger) {
  364.                     if(comma) rputs(", ",r);
  365.                     rputs("<tt>Logging</tt>\n",r);
  366.                     comma=1;
  367.                 }
  368.                 if(!comma) rputs("<tt> none</tt>",r);
  369.                 comma=0;
  370.                 rputs("<dt><strong>Module Configuration Commands:</strong> ",r);
  371.                 cmd = modp->cmds;
  372.                 if(cmd) {
  373.                     while(cmd) {
  374.                         if(cmd->name) {
  375.                             sprintf(buf,"<dd><tt>%s - <i>",mod_info_html_cmd_string(cmd->name));    
  376.                             rputs(buf,r);
  377.                             if(cmd->errmsg) rputs(cmd->errmsg,r);
  378.                             rputs("</i></tt>\n",r);
  379.                         } else break;
  380.                         cmd++;
  381.                     }
  382.                     rputs("<dt><strong>Current Configuration:</strong>\n",r);
  383.                     mod_info_module_cmds(r,mod_info_cfg_httpd,modp->cmds,"httpd.conf");    
  384.                     mod_info_module_cmds(r,mod_info_cfg_srm,modp->cmds,"srm.conf");
  385.                     mod_info_module_cmds(r,mod_info_cfg_access,modp->cmds,"access.conf");
  386.                 } else {
  387.                     rputs("<tt> none</tt>\n",r);
  388.                 }
  389.                 rputs("<dt><hr>\n",r);
  390.                 if(r->args) break;
  391.             }
  392.         }
  393.         if(!modp && r->args && strcasecmp(r->args,"server")) rputs("<b>No such module</b>\n",r);
  394.     } else {
  395.         for(modp = top_module; modp; modp = modp->next, names++) {
  396.             rputs(*names,r);
  397.             if(modp->next) rputs("<br>",r);
  398.         }    
  399.     }    
  400.     rputs("</dl></body></html>\n",r);
  401.     /* Done, turn off timeout, close file and return */
  402.     return 0;
  403. }
  404.  
  405. handler_rec info_handlers[] = {
  406.     { "server-info", display_info },
  407.     { NULL }
  408. };
  409.  
  410. module info_module = {
  411.     STANDARD_MODULE_STUFF,
  412.     NULL,                /* initializer */
  413.     NULL,                /* dir config creater */
  414.     NULL,                /* dir merger --- default is to override */
  415.     NULL,                /* server config */
  416.     NULL,                /* merge server config */
  417.     NULL,                /* command table */
  418.     info_handlers,        /* handlers */
  419.     NULL,                /* filename translation */
  420.     NULL,                /* check_user_id */
  421.     NULL,                /* check auth */
  422.     NULL,                /* check access */
  423.     NULL,                /* type_checker */
  424.     NULL,                /* fixups */
  425.     NULL                /* logger */
  426. };
  427.