mod_status.c revision 3d96ee83babeec32482c9082c9426340cee8c44d
842ae4bd224140319ae7feec1872b93dfd491143fielding/* ====================================================================
842ae4bd224140319ae7feec1872b93dfd491143fielding * The Apache Software License, Version 1.1
842ae4bd224140319ae7feec1872b93dfd491143fielding *
842ae4bd224140319ae7feec1872b93dfd491143fielding * Copyright (c) 2000 The Apache Software Foundation. All rights
842ae4bd224140319ae7feec1872b93dfd491143fielding * reserved.
842ae4bd224140319ae7feec1872b93dfd491143fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Redistribution and use in source and binary forms, with or without
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * modification, are permitted provided that the following conditions
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * are met:
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * 1. Redistributions of source code must retain the above copyright
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * notice, this list of conditions and the following disclaimer.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * 2. Redistributions in binary form must reproduce the above copyright
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * notice, this list of conditions and the following disclaimer in
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the documentation and/or other materials provided with the
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * distribution.
e8f95a682820a599fe41b22977010636be5c2717jim *
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * 3. The end-user documentation included with the redistribution,
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * if any, must include the following acknowledgment:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * "This product includes software developed by the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Apache Software Foundation (http://www.apache.org/)."
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * Alternately, this acknowledgment may appear in the software itself,
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * if and wherever such third-party acknowledgments normally appear.
1b21d7b3d97def358b2e923655edeb16613a1c31gstein *
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * 4. The names "Apache" and "Apache Software Foundation" must
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * not be used to endorse or promote products derived from this
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * software without prior written permission. For written
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * permission, please contact apache@apache.org.
2d71630471d1c23f0137309e3c3957c633ecbfd6rbb *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * 5. Products derived from this software may not be called "Apache",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * nor may "Apache" appear in their name, without prior written
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * permission of the Apache Software Foundation.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
51af95bb51b5084e883bad250b2afa2838e9ceebfielding * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
d4f1d9c1ff112a8ab9bee31f196973761329b236rbb * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
7fae9cc4639013f3c04c085547256c68814aee8ftrawick * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
7fae9cc4639013f3c04c085547256c68814aee8ftrawick * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
7fae9cc4639013f3c04c085547256c68814aee8ftrawick * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
7fae9cc4639013f3c04c085547256c68814aee8ftrawick * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * SUCH DAMAGE.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * ====================================================================
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * This software consists of voluntary contributions made by many
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * individuals on behalf of the Apache Software Foundation. For more
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * information on the Apache Software Foundation, please see
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * <http://www.apache.org/>.
785be1b6298010956622771c870ab3cd8ca57a2faaron *
785be1b6298010956622771c870ab3cd8ca57a2faaron * Portions of this software are based upon public domain software
785be1b6298010956622771c870ab3cd8ca57a2faaron * originally written at the National Center for Supercomputing Applications,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * University of Illinois, Urbana-Champaign.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "httpd.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_config.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_core.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_protocol.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "mpm_status.h"
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaron#ifndef DEFAULT_TIME_FORMAT
785be1b6298010956622771c870ab3cd8ca57a2faaron#define DEFAULT_TIME_FORMAT "%A, %d-%b-%Y %H:%M:%S %Z"
785be1b6298010956622771c870ab3cd8ca57a2faaron#endif
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaron#define STATUS_MAGIC_TYPE "application/x-httpd-status"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingmodule AP_MODULE_DECLARE_DATA status_module;
f4b96a996afbc46872f57ad1450e6ee1c8f13707jorton
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic int print_status_value(void *data, const char *key, const char *val)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding request_rec *r = (request_rec *) data;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rprintf(r, "<dt>%s\n<dd>%s\n", key, val);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic int status_handler(request_rec *r)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int i;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_array_header_t *server_status;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_status_table_row_t *status_rows;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding r->allowed = (1 << M_GET);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (r->method_number != M_GET)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return DECLINED;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding r->content_type = "text/html";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_send_http_header(r);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (r->header_only)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_status = ap_get_status_table(r->pool);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rputs(DOCTYPE_HTML_3_2
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "<html><head>\n<title>Apache Status</title>\n</head><body>\n",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding r);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rputs("<H1>Apache Server Status for ", r);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rvputs(r, ap_get_server_name(r), "</H1>\n\n", NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rvputs(r, "Server Version: ",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_get_server_version(), "<br>\n", NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rvputs(r, "Server Built: ",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_get_server_built(), "<br>\n<hr>\n", NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rvputs(r, "Current Time: ",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_ht_time(r->pool, apr_now(), DEFAULT_TIME_FORMAT, 0), "<br>\n", NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rprintf(r, "\n%d connections currently being processed\n",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_status->nelts);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding status_rows = (ap_status_table_row_t *) server_status->elts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; i < server_status->nelts; i++) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rprintf(r, "<h2>Connection %ld</h2>\n", status_rows[i].conn_id);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_table_do(print_status_value, (void *) r, status_rows[i].data, NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rputs("</body></html>\n", r);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
45acd673a68181802b112e97e84fa3813ddd3ec1stoddard
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const handler_rec status_handlers[] =
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {STATUS_MAGIC_TYPE, status_handler},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"server-status", status_handler},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {NULL}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingmodule AP_MODULE_DECLARE_DATA status_module =
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding STANDARD20_MODULE_STUFF,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding NULL, /* create per-dir config */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding NULL, /* merge per-dir config */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding NULL, /* server config */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding NULL, /* merge server config */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding NULL, /* command table */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm status_handlers, /* handlers */
e8f95a682820a599fe41b22977010636be5c2717jim NULL /* register hooks */
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick};
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding