wok diff busybox/stuff/busybox-1.18-httpd.u @ rev 9535

busybox/httpd: add directory list support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Apr 08 18:12:43 2011 +0200 (2011-04-08)
parents
children 156116e8b1c3
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/busybox/stuff/busybox-1.18-httpd.u	Fri Apr 08 18:12:43 2011 +0200
     1.3 @@ -0,0 +1,106 @@
     1.4 +This patch allows to run a script to list the directory with httpd
     1.5 +
     1.6 +Install /etc/httpd.conf, /var/www/cgi-bin/list.sh and try !
     1.7 +
     1.8 +===>8=== /etc/httpd.conf ===>8===
     1.9 +H:/var/www
    1.10 +*.sh:/bin/sh
    1.11 +L:/cgi-bin/list.sh
    1.12 +===>8=== /var/www/cgi-bin/list.sh ===>8===
    1.13 +#!/bin/sh
    1.14 +
    1.15 +eval ${QUERY_STRING/&/;}
    1.16 +path=$(dirname /$url)
    1.17 +
    1.18 +unix2dos <<EOT
    1.19 +Content-type: text/html
    1.20 +
    1.21 +<!DOCTYPE html>
    1.22 +<html xmlns="http://www.w3.org/1999/xhtml">
    1.23 +<head>
    1.24 +	<title>Index of $path</title>
    1.25 +</head>
    1.26 +<body>
    1.27 +	<h1>Index of $path</h1>
    1.28 +	<ul>
    1.29 +$(cd $home$path && { [ "$path" != "/" ] && echo "../" ; ls -p; } | \
    1.30 +  sed 's|.*|		<li><a href="&">&</a></li>|')
    1.31 +	</ul>
    1.32 +</body>
    1.33 +</html>
    1.34 +EOT
    1.35 +===>8======>8======>8======>8======>8===
    1.36 +
    1.37 +--- busybox-1.18.4/networking/Config.src
    1.38 ++++ busybox-1.18.4/networking/Config.src
    1.39 +@@ -216,6 +216,14 @@
    1.40 + 	  This option allows scripts and executables to be invoked
    1.41 + 	  when specific URLs are requested.
    1.42 + 
    1.43 ++config FEATURE_HTTPD_LISTING
    1.44 ++	bool "Support for directory listing through a CGI script"
    1.45 ++	default y
    1.46 ++	depends on FEATURE_HTTPD_CGI
    1.47 ++	help
    1.48 ++	  This option allows to run a script to list the directory
    1.49 ++	  content.
    1.50 ++
    1.51 + config FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
    1.52 + 	bool "Support for running scripts through an interpreter"
    1.53 + 	default y
    1.54 +
    1.55 +--- busybox-1.18.4/networking/httpd.c
    1.56 ++++ busybox-1.18.4/networking/httpd.c
    1.57 +@@ -42,6 +42,7 @@
    1.58 +  * D:*               # Deny from other IP connections
    1.59 +  * E404:/path/e404.html # /path/e404.html is the 404 (not found) error page
    1.60 +  * I:index.html      # Show index.html when a directory is requested
    1.61 ++ * L:/path/list      # List directory file from $url and $home arguments
    1.62 +  *
    1.63 +  * P:/url:[http://]hostname[:port]/new/path
    1.64 +  *                   # When /urlXXXXXX is requested, reverse proxy
    1.65 +@@ -240,6 +241,7 @@
    1.66 + 	const char *opt_c_configFile;
    1.67 + 	const char *home_httpd;
    1.68 + 	const char *index_page;
    1.69 ++	const char *listing;
    1.70 + 
    1.71 + 	const char *found_mime_type;
    1.72 + 	const char *found_moved_temporarily;
    1.73 +@@ -291,6 +293,7 @@
    1.74 + #define opt_c_configFile  (G.opt_c_configFile )
    1.75 + #define home_httpd        (G.home_httpd       )
    1.76 + #define index_page        (G.index_page       )
    1.77 ++#define listing           (G.listing          )
    1.78 + #define found_mime_type   (G.found_mime_type  )
    1.79 + #define found_moved_temporarily (G.found_moved_temporarily)
    1.80 + #define last_mod          (G.last_mod         )
    1.81 +@@ -579,6 +582,13 @@
    1.82 + 			continue;
    1.83 + 		}
    1.84 + 
    1.85 ++#if ENABLE_FEATURE_HTTPD_LISTING
    1.86 ++		if (flag == FIRST_PARSE && ch == 'L') {
    1.87 ++			listing = xstrdup(after_colon);
    1.88 ++			continue;
    1.89 ++		}
    1.90 ++#endif
    1.91 ++
    1.92 + 		/* do not allow jumping around using H in subdir's configs */
    1.93 + 		if (flag == FIRST_PARSE && ch == 'H') {
    1.94 + 			home_httpd = xstrdup(after_colon);
    1.95 +@@ -1531,6 +1541,13 @@
    1.96 + 		fd = open(url, O_RDONLY);
    1.97 + 	}
    1.98 + 	if (fd < 0) {
    1.99 ++#if ENABLE_FEATURE_HTTPD_LISTING
   1.100 ++		if (listing) {
   1.101 ++			char args[BUF_SIZE];
   1.102 ++			snprintf(g_query = args, sizeof(args), "url=%s&home=%s", url, home_httpd);
   1.103 ++			send_cgi_and_exit(listing, "GET", 0, NULL, NULL);
   1.104 ++		}
   1.105 ++#endif
   1.106 + 		if (DEBUG)
   1.107 + 			bb_perror_msg("can't open '%s'", url);
   1.108 + 		/* Error pages are sent by using send_file_and_exit(SEND_BODY).
   1.109 +