/*
###############################################################################
mod_server_tokens.c - A module for Apache 1.3.29
Version 0.1.3 beta - 14/DEC/2003
(c) 2003 Juan R. Pozo
http://html.conclase.net/cp/scripts/
mailto:jrpozo@conclase.net
Mailing-list: http://www.conclase.net/mailman/listinfo/cpanel_conclase.net
###############################################################################
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
###############################################################################
INSTALLATION
1. Download the mod_server_tokens.tgz file to your server
2. Uncompress it:
tar xvzf mod_server_tokens.tgz
3. cd mod_server_tokens-0.1.3
4. make all
5. make install
6. Edit httpd.conf and add the configuration directive:
FakeVersionString "Apache"
ShowRealVersionStringTo "cpanel.net"
7. Stop apache
8. Start apache (don't just restart, you must stop and start)
Please remember this is beta software.
###############################################################################
CONFIGURATION DIRECTIVES
FakeVersionString string
If specified, changes Apache's version string to the given string (except
for connections coming from the specified IP address).
Example:
FakeVersionString "Apache"
ShowRealVersionStringTo "127.0.0.1"
###############################################################################
Changelog:
14/DEC/2003 - v. 0.1.3
Allows to specify the IP or domain you want to allow to read the real version
string. Defaults to "127.0.0.1"
14/NOV/2003 - v. 0.1.2
Provides more detailed installation instructions
22/OCT/2003 - v. 0.1.1
Registers cleanup handler so that each new request starts with the fake version
string
20/OCT2003 - v. 0.1
First public release
###############################################################################
Please consider making a donation today. Visit my amazon.com wishlist at:
http://html.conclase.net/link/wishlist
Thank you :)
###############################################################################
*/
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_main.h"
#include "http_protocol.h"
#include "http_request.h"
module MODULE_VAR_EXPORT server_tokens_module;
void server_tokens_cleanup_handler(void *);
/* The per-server configuration data structure */
typedef struct {
char *fakeversion;
char *realversion;
char ip[16];
} server_tokens_server_config;
/* Allocate storage for the per-server configuration information and set up
appropriate defaults */
static void *server_tokens_create_server_config(pool *p, server_rec *s)
{
server_tokens_server_config *scfg = (server_tokens_server_config *)
ap_pcalloc(p, sizeof(server_tokens_server_config));
scfg->fakeversion = NULL;
scfg->realversion = NULL;
ap_cpystrn(scfg->ip, "127.0.0.1", sizeof(scfg->ip));
return (void *)scfg;
}
/* Directive handlers */
/* The server_tokens_cmd array declares 2 directives: FakeVersionString
which is processed by a handler routine named set_fake_version_cmd(), and
ShowRealVersionStringTo which is processed by a handler routine named
set_allowed_domain_cmd() */
static const char *server_tokens_set_fake_version_cmd(
cmd_parms *parms,
void *mconfig,
char *fakeversion
)
{
server_tokens_server_config *scfg = (server_tokens_server_config *)
ap_get_module_config(parms->server->module_config, &server_tokens_module);
scfg->fakeversion = ap_pstrdup(parms->pool, fakeversion);
return NULL;
}
static const char *server_tokens_set_allowed_ip_cmd(
cmd_parms *parms,
void *mconfig,
char *domain
)
{
server_tokens_server_config *scfg = (server_tokens_server_config *)
ap_get_module_config(parms->server->module_config, &server_tokens_module);
struct hostent *h;
if (h = gethostbyname(domain)) {
inet_ntop(AF_INET, h->h_addr_list[0], scfg->ip, sizeof(scfg->ip));
}
return NULL;
}
/* Our command_rec definition: */
static const command_rec server_tokens_cmds[] =
{
{"FakeVersionString",
server_tokens_set_fake_version_cmd,
NULL, RSRC_CONF, TAKE1,
"The fake version string"},
{"ShowRealVersionStringTo",
server_tokens_set_allowed_ip_cmd,
NULL, RSRC_CONF, TAKE1,
"The IP or domain from where you can see the real version string"},
{NULL}
};
/* INIT */
/* The module init */
void server_tokens_init(server_rec *s, pool *p)
{
server_tokens_server_config *scfg = (server_tokens_server_config *)
ap_get_module_config(s->module_config, &server_tokens_module);
if (scfg->fakeversion) {
char *vc = (char *)ap_pcalloc(p, strlen(scfg->fakeversion) + 1);
memset(vc, '*', strlen(scfg->fakeversion));
ap_add_version_component(vc);
}
}
/* The process init - by default show the fake version string */
void server_tokens_child_init(server_rec *s, pool *p)
{
server_tokens_server_config *scfg = (server_tokens_server_config *)
ap_get_module_config(s->module_config, &server_tokens_module);
char *server_version = (char *)ap_get_server_version();
scfg->realversion = ap_pstrdup(p, server_version);
if (server_version && scfg->fakeversion) {
strcpy(server_version, scfg->fakeversion);
}
}
/* PROCESSING THE REQUEST */
/* The Post Read Request Phase - This is where we will change the version
string for requests from localhost*/
int server_tokens_post_read_request(request_rec *r)
{
server_tokens_server_config *scfg = (server_tokens_server_config *)
ap_get_module_config(r->server->module_config, &server_tokens_module);
char *server_version = (char *)ap_get_server_version();
if (server_version && scfg->realversion &&
!strcmp(r->connection->remote_ip, scfg->ip)) {
strcpy(server_version, scfg->realversion);
}
ap_register_cleanup(r->pool, (void *)scfg->fakeversion,
server_tokens_cleanup_handler, ap_null_cleanup);
return OK;
}
/* The cleanup handler: restore fake server version string */
void server_tokens_cleanup_handler(void *data)
{
char *fakeversion = (char *)data;
char *server_version = (char *)ap_get_server_version();
if (server_version && fakeversion) {
strcpy(server_version, fakeversion);
}
}
/* Finally the module structure */
module MODULE_VAR_EXPORT server_tokens_module =
{
STANDARD_MODULE_STUFF,
server_tokens_init, /* module initializer */
NULL, /* per-directory config creator */
NULL, /* dir config merger */
server_tokens_create_server_config, /* server config creator */
NULL, /* server config merger */
server_tokens_cmds, /* config directive table */
NULL, /* [9] content handlers */
NULL, /* [2] URI-to-filename translation */
NULL, /* [5] check/validate user_id */
NULL, /* [6] check user_id is valid *here* */
NULL, /* [4] check access by host address */
NULL, /* [7] MIME type checker/setter */
NULL, /* [8] fixups */
NULL, /* [10] logger */
NULL, /* [3] header parser */
server_tokens_child_init, /* process initialization */
NULL, /* process exit/cleanup */
server_tokens_post_read_request /* [1] post read_request handling */
};