wok-next view 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 source
1 This patch allows to run a script to list the directory with httpd
3 Install /etc/httpd.conf, /var/www/cgi-bin/list.sh and try !
5 ===>8=== /etc/httpd.conf ===>8===
6 H:/var/www
7 *.sh:/bin/sh
8 L:/cgi-bin/list.sh
9 ===>8=== /var/www/cgi-bin/list.sh ===>8===
10 #!/bin/sh
12 eval ${QUERY_STRING/&/;}
13 path=$(dirname /$url)
15 unix2dos <<EOT
16 Content-type: text/html
18 <!DOCTYPE html>
19 <html xmlns="http://www.w3.org/1999/xhtml">
20 <head>
21 <title>Index of $path</title>
22 </head>
23 <body>
24 <h1>Index of $path</h1>
25 <ul>
26 $(cd $home$path && { [ "$path" != "/" ] && echo "../" ; ls -p; } | \
27 sed 's|.*| <li><a href="&">&</a></li>|')
28 </ul>
29 </body>
30 </html>
31 EOT
32 ===>8======>8======>8======>8======>8===
34 --- busybox-1.18.4/networking/Config.src
35 +++ busybox-1.18.4/networking/Config.src
36 @@ -216,6 +216,14 @@
37 This option allows scripts and executables to be invoked
38 when specific URLs are requested.
40 +config FEATURE_HTTPD_LISTING
41 + bool "Support for directory listing through a CGI script"
42 + default y
43 + depends on FEATURE_HTTPD_CGI
44 + help
45 + This option allows to run a script to list the directory
46 + content.
47 +
48 config FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
49 bool "Support for running scripts through an interpreter"
50 default y
52 --- busybox-1.18.4/networking/httpd.c
53 +++ busybox-1.18.4/networking/httpd.c
54 @@ -42,6 +42,7 @@
55 * D:* # Deny from other IP connections
56 * E404:/path/e404.html # /path/e404.html is the 404 (not found) error page
57 * I:index.html # Show index.html when a directory is requested
58 + * L:/path/list # List directory file from $url and $home arguments
59 *
60 * P:/url:[http://]hostname[:port]/new/path
61 * # When /urlXXXXXX is requested, reverse proxy
62 @@ -240,6 +241,7 @@
63 const char *opt_c_configFile;
64 const char *home_httpd;
65 const char *index_page;
66 + const char *listing;
68 const char *found_mime_type;
69 const char *found_moved_temporarily;
70 @@ -291,6 +293,7 @@
71 #define opt_c_configFile (G.opt_c_configFile )
72 #define home_httpd (G.home_httpd )
73 #define index_page (G.index_page )
74 +#define listing (G.listing )
75 #define found_mime_type (G.found_mime_type )
76 #define found_moved_temporarily (G.found_moved_temporarily)
77 #define last_mod (G.last_mod )
78 @@ -579,6 +582,13 @@
79 continue;
80 }
82 +#if ENABLE_FEATURE_HTTPD_LISTING
83 + if (flag == FIRST_PARSE && ch == 'L') {
84 + listing = xstrdup(after_colon);
85 + continue;
86 + }
87 +#endif
88 +
89 /* do not allow jumping around using H in subdir's configs */
90 if (flag == FIRST_PARSE && ch == 'H') {
91 home_httpd = xstrdup(after_colon);
92 @@ -1531,6 +1541,13 @@
93 fd = open(url, O_RDONLY);
94 }
95 if (fd < 0) {
96 +#if ENABLE_FEATURE_HTTPD_LISTING
97 + if (listing) {
98 + char args[BUF_SIZE];
99 + snprintf(g_query = args, sizeof(args), "url=%s&home=%s", url, home_httpd);
100 + send_cgi_and_exit(listing, "GET", 0, NULL, NULL);
101 + }
102 +#endif
103 if (DEBUG)
104 bb_perror_msg("can't open '%s'", url);
105 /* Error pages are sent by using send_file_and_exit(SEND_BODY).