diff options
author | "Vladimir N. Oleynik" <dzo@simtreas.ru> | 2006-01-31 13:53:30 +0000 |
---|---|---|
committer | "Vladimir N. Oleynik" <dzo@simtreas.ru> | 2006-01-31 13:53:30 +0000 |
commit | 4333a09d657348672db61f3063f2d272708c2548 (patch) | |
tree | 6888ebd5177a29cdd49320e4cfb5bce9af3b827f | |
parent | 1f17d3287adaa01c8605699e80aaaba3a5a01d65 (diff) | |
download | busybox-w32-4333a09d657348672db61f3063f2d272708c2548.tar.gz busybox-w32-4333a09d657348672db61f3063f2d272708c2548.tar.bz2 busybox-w32-4333a09d657348672db61f3063f2d272708c2548.zip |
add feature: support for running scripts through an interpreter. Thanks Florian Schirmer <jolt@tuxbox.org>
-rw-r--r-- | networking/Config.in | 12 | ||||
-rw-r--r-- | networking/httpd.c | 44 |
2 files changed, 51 insertions, 5 deletions
diff --git a/networking/Config.in b/networking/Config.in index 0f4381b5c..c0278778e 100644 --- a/networking/Config.in +++ b/networking/Config.in | |||
@@ -85,7 +85,6 @@ config CONFIG_FEATURE_HTTPD_AUTH_MD5 | |||
85 | Enables basic per url authentication from /etc/httpd.conf | 85 | Enables basic per url authentication from /etc/httpd.conf |
86 | using md5 passwords. | 86 | using md5 passwords. |
87 | 87 | ||
88 | |||
89 | if !CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY | 88 | if !CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY |
90 | config CONFIG_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP | 89 | config CONFIG_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP |
91 | bool " Support reloading the global config file using hup signal" | 90 | bool " Support reloading the global config file using hup signal" |
@@ -122,6 +121,17 @@ config CONFIG_FEATURE_HTTPD_CGI | |||
122 | This option allows scripts and executables to be invoked | 121 | This option allows scripts and executables to be invoked |
123 | when specific urls are requested. | 122 | when specific urls are requested. |
124 | 123 | ||
124 | config CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR | ||
125 | bool " Enable support for running scripts through an interpreter" | ||
126 | default n | ||
127 | depends on CONFIG_FEATURE_HTTPD_CGI | ||
128 | help | ||
129 | This option enables support for running scripts through an | ||
130 | interpreter. Turn this on, if you want PHP scripts to work | ||
131 | properly. You need to supply an addition line in your httpd | ||
132 | config file: | ||
133 | *.php:/path/to/your/php | ||
134 | |||
125 | config CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV | 135 | config CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV |
126 | bool " Support the REMOTE_PORT environment variable for CGI" | 136 | bool " Support the REMOTE_PORT environment variable for CGI" |
127 | default n | 137 | default n |
diff --git a/networking/httpd.c b/networking/httpd.c index b44adf730..99a87d186 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -54,6 +54,7 @@ | |||
54 | * /adm:admin:setup # Require user admin, pwd setup on urls starting with /adm/ | 54 | * /adm:admin:setup # Require user admin, pwd setup on urls starting with /adm/ |
55 | * /adm:toor:PaSsWd # or user toor, pwd PaSsWd on urls starting with /adm/ | 55 | * /adm:toor:PaSsWd # or user toor, pwd PaSsWd on urls starting with /adm/ |
56 | * .au:audio/basic # additional mime type for audio.au files | 56 | * .au:audio/basic # additional mime type for audio.au files |
57 | * *.php:/path/php # running cgi.php scripts through an interpreter | ||
57 | * | 58 | * |
58 | * A/D may be as a/d or allow/deny - first char case insensitive | 59 | * A/D may be as a/d or allow/deny - first char case insensitive |
59 | * Deny IP rules take precedence over allow rules. | 60 | * Deny IP rules take precedence over allow rules. |
@@ -285,6 +286,9 @@ typedef struct | |||
285 | #endif | 286 | #endif |
286 | volatile int alarm_signaled; | 287 | volatile int alarm_signaled; |
287 | 288 | ||
289 | #ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR | ||
290 | Htaccess *script_i; /* config script interpreters */ | ||
291 | #endif | ||
288 | } HttpdConfig; | 292 | } HttpdConfig; |
289 | 293 | ||
290 | static HttpdConfig *config; | 294 | static HttpdConfig *config; |
@@ -529,7 +533,7 @@ static void parse_conf(const char *path, int flag) | |||
529 | 533 | ||
530 | config->flg_deny_all = 0; | 534 | config->flg_deny_all = 0; |
531 | 535 | ||
532 | #if defined(CONFIG_FEATURE_HTTPD_BASIC_AUTH) || defined(CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES) | 536 | #if defined(CONFIG_FEATURE_HTTPD_BASIC_AUTH) || defined(CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES) || defined(CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR) |
533 | /* retain previous auth and mime config only for subdir parse */ | 537 | /* retain previous auth and mime config only for subdir parse */ |
534 | if(flag != SUBDIR_PARSE) { | 538 | if(flag != SUBDIR_PARSE) { |
535 | #ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH | 539 | #ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH |
@@ -538,6 +542,9 @@ static void parse_conf(const char *path, int flag) | |||
538 | #ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES | 542 | #ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES |
539 | free_config_lines(&config->mime_a); | 543 | free_config_lines(&config->mime_a); |
540 | #endif | 544 | #endif |
545 | #ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR | ||
546 | free_config_lines(&config->script_i); | ||
547 | #endif | ||
541 | } | 548 | } |
542 | #endif | 549 | #endif |
543 | 550 | ||
@@ -601,6 +608,9 @@ static void parse_conf(const char *path, int flag) | |||
601 | #ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES | 608 | #ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES |
602 | && *p0 != '.' | 609 | && *p0 != '.' |
603 | #endif | 610 | #endif |
611 | #ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR | ||
612 | && *p0 != '*' | ||
613 | #endif | ||
604 | ) | 614 | ) |
605 | continue; | 615 | continue; |
606 | if(*p0 == 'A' || *p0 == 'D') { | 616 | if(*p0 == 'A' || *p0 == 'D') { |
@@ -672,7 +682,7 @@ static void parse_conf(const char *path, int flag) | |||
672 | } | 682 | } |
673 | #endif | 683 | #endif |
674 | 684 | ||
675 | #if defined(CONFIG_FEATURE_HTTPD_BASIC_AUTH) || defined(CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES) | 685 | #if defined(CONFIG_FEATURE_HTTPD_BASIC_AUTH) || defined(CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES) || defined(CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR) |
676 | /* storing current config line */ | 686 | /* storing current config line */ |
677 | cur = calloc(1, sizeof(Htaccess) + strlen(p0)); | 687 | cur = calloc(1, sizeof(Htaccess) + strlen(p0)); |
678 | if(cur) { | 688 | if(cur) { |
@@ -688,6 +698,14 @@ static void parse_conf(const char *path, int flag) | |||
688 | continue; | 698 | continue; |
689 | } | 699 | } |
690 | #endif | 700 | #endif |
701 | #ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR | ||
702 | if(*cf == '*' && cf[1] == '.') { | ||
703 | /* config script interpreter line move top for overwrite previous */ | ||
704 | cur->next = config->script_i; | ||
705 | config->script_i = cur; | ||
706 | continue; | ||
707 | } | ||
708 | #endif | ||
691 | #ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH | 709 | #ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH |
692 | free(p0); | 710 | free(p0); |
693 | if(prev == NULL) { | 711 | if(prev == NULL) { |
@@ -1219,11 +1237,29 @@ static int sendCgi(const char *url, | |||
1219 | if(script) { | 1237 | if(script) { |
1220 | *script = '\0'; | 1238 | *script = '\0'; |
1221 | if(chdir(realpath_buff) == 0) { | 1239 | if(chdir(realpath_buff) == 0) { |
1222 | *script = '/'; | ||
1223 | // now run the program. If it fails, | 1240 | // now run the program. If it fails, |
1224 | // use _exit() so no destructors | 1241 | // use _exit() so no destructors |
1225 | // get called and make a mess. | 1242 | // get called and make a mess. |
1226 | execv(realpath_buff, argp); | 1243 | #ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR |
1244 | char *interpr = NULL; | ||
1245 | char *suffix = strrchr(purl, '.'); | ||
1246 | |||
1247 | if(suffix) { | ||
1248 | Htaccess * cur; | ||
1249 | for (cur = config->script_i; cur; cur = cur->next) | ||
1250 | if(strcmp(cur->before_colon + 1, suffix) == 0) { | ||
1251 | interpr = cur->after_colon; | ||
1252 | break; | ||
1253 | } | ||
1254 | } | ||
1255 | #endif | ||
1256 | *script = '/'; | ||
1257 | #ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR | ||
1258 | if (interpr) | ||
1259 | execv(interpr, argp); | ||
1260 | else | ||
1261 | #endif | ||
1262 | execv(realpath_buff, argp); | ||
1227 | } | 1263 | } |
1228 | } | 1264 | } |
1229 | } | 1265 | } |