add feature: support for running scripts through an interpreter. Thanks Florian Schirmer <jolt@tuxbox.org>

This commit is contained in:
"Vladimir N. Oleynik" 2006-01-31 13:53:30 +00:00
parent 1f17d3287a
commit 4333a09d65
2 changed files with 51 additions and 5 deletions

View File

@ -85,7 +85,6 @@ config CONFIG_FEATURE_HTTPD_AUTH_MD5
Enables basic per url authentication from /etc/httpd.conf
using md5 passwords.
if !CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
config CONFIG_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP
bool " Support reloading the global config file using hup signal"
@ -122,6 +121,17 @@ config CONFIG_FEATURE_HTTPD_CGI
This option allows scripts and executables to be invoked
when specific urls are requested.
config CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
bool " Enable support for running scripts through an interpreter"
default n
depends on CONFIG_FEATURE_HTTPD_CGI
help
This option enables support for running scripts through an
interpreter. Turn this on, if you want PHP scripts to work
properly. You need to supply an addition line in your httpd
config file:
*.php:/path/to/your/php
config CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV
bool " Support the REMOTE_PORT environment variable for CGI"
default n

View File

@ -54,6 +54,7 @@
* /adm:admin:setup # Require user admin, pwd setup on urls starting with /adm/
* /adm:toor:PaSsWd # or user toor, pwd PaSsWd on urls starting with /adm/
* .au:audio/basic # additional mime type for audio.au files
* *.php:/path/php # running cgi.php scripts through an interpreter
*
* A/D may be as a/d or allow/deny - first char case insensitive
* Deny IP rules take precedence over allow rules.
@ -285,6 +286,9 @@ typedef struct
#endif
volatile int alarm_signaled;
#ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
Htaccess *script_i; /* config script interpreters */
#endif
} HttpdConfig;
static HttpdConfig *config;
@ -529,7 +533,7 @@ static void parse_conf(const char *path, int flag)
config->flg_deny_all = 0;
#if defined(CONFIG_FEATURE_HTTPD_BASIC_AUTH) || defined(CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES)
#if defined(CONFIG_FEATURE_HTTPD_BASIC_AUTH) || defined(CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES) || defined(CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR)
/* retain previous auth and mime config only for subdir parse */
if(flag != SUBDIR_PARSE) {
#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
@ -537,6 +541,9 @@ static void parse_conf(const char *path, int flag)
#endif
#ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES
free_config_lines(&config->mime_a);
#endif
#ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
free_config_lines(&config->script_i);
#endif
}
#endif
@ -600,6 +607,9 @@ static void parse_conf(const char *path, int flag)
#endif
#ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES
&& *p0 != '.'
#endif
#ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
&& *p0 != '*'
#endif
)
continue;
@ -672,7 +682,7 @@ static void parse_conf(const char *path, int flag)
}
#endif
#if defined(CONFIG_FEATURE_HTTPD_BASIC_AUTH) || defined(CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES)
#if defined(CONFIG_FEATURE_HTTPD_BASIC_AUTH) || defined(CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES) || defined(CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR)
/* storing current config line */
cur = calloc(1, sizeof(Htaccess) + strlen(p0));
if(cur) {
@ -688,6 +698,14 @@ static void parse_conf(const char *path, int flag)
continue;
}
#endif
#ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
if(*cf == '*' && cf[1] == '.') {
/* config script interpreter line move top for overwrite previous */
cur->next = config->script_i;
config->script_i = cur;
continue;
}
#endif
#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
free(p0);
if(prev == NULL) {
@ -1219,11 +1237,29 @@ static int sendCgi(const char *url,
if(script) {
*script = '\0';
if(chdir(realpath_buff) == 0) {
*script = '/';
// now run the program. If it fails,
// use _exit() so no destructors
// get called and make a mess.
execv(realpath_buff, argp);
#ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
char *interpr = NULL;
char *suffix = strrchr(purl, '.');
if(suffix) {
Htaccess * cur;
for (cur = config->script_i; cur; cur = cur->next)
if(strcmp(cur->before_colon + 1, suffix) == 0) {
interpr = cur->after_colon;
break;
}
}
#endif
*script = '/';
#ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
if (interpr)
execv(interpr, argp);
else
#endif
execv(realpath_buff, argp);
}
}
}