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