[PATCH] httpd: Support configurable start page

Alex Landau landau_alex at yahoo.com
Thu Oct 18 11:41:29 UTC 2007


--- Denys Vlasenko <vda.linux at googlemail.com> wrote:

> 
>                         *c++ = '\0';
>                         if (strncmp(c, "http://", 7) == 0)
>                                 c += 7;
>                         host_port = c;
>                         if (host_port == NULL) {
>                                 bb_error_msg("config error '%s' in '%s'", buf, cf);
>                                 continue;
>                         }
> 
> host_port cannot be NULL. What do you really want to test there?

Sure, my oops. It should have been *host_port == '\0'. Fixed.
> 
> 
> index.cgi support broke. I understand that now I need to supply
> a config file for it, but it still doesn't work:
> 
> ./busybox httpd -c httpd.conf -f -vvv -p 8888
> 
> httpd.conf
> ==========
> S:cgi-bin/index.cgi
> 
> cgi-bin/index.cgi is a binary I built from httpd_indexcgi.c
> (you may find it alongside httpd.c in busybox source).
> 
> 
> Obviously you pass different QUERY_STRING now, and this doesn't work
> in httpd_indexcgi.c anymore:
> 
>         if (chdir("..")
>          || (QUERY_STRING[1] && chdir(QUERY_STRING + 1))
>         ) {
>                 return 1;
>         }
> 

Yeah, another oops. I couldn't imagine that the query string is used for the path!
Being here, I changed it so that the path is passed to the CGI via PATH_INFO. This is
useful by itself, say, if the URL is http://host/?name=value. The previous approach would
clobber ?name=value with ?/.
The attached patch changes httpd_indexcgi to use PATH_INFO. The change is in getenv(),
everything else is just noise that renames the QUERY_STRING variable to PATH_INFO.

I added another small enhancement (absolute vs. relative paths for start page in
httpd.conf). Please add this to the START_PAGE item in Config.in.

          If the file is specified via a relative path, it will be searched
          in the requested directory. An absolute path will trigger a search
          from the document root. In any case, if the file is a script,
          the requested directory will be available to it via the
          PATH_INFO environment variable.

If I want each directory to have its own default index.php, I'll write S:index.php.
If I want a single global index.php, I'll write S:/index.php (or S:/dir/index.php,
depending on its location).
If I want a index.cgi to run, I'll write S:/cgi-bin/index.cgi (note the '/' before
cgi-bin, which tells it to look for an absolute path). cgi-bin does not work with
relative paths since in some other code section, busybox verifies that if we're trying to
run a script, it must be in /cgi-bin/.

Regarding your question about whether the current index.cgi approach is enough for me, it
isn't. Due to two reasons. First, it has to be a binary and be located in /cgi-bin/. I
want it to be a PHP script. That's the main reason for me. (I can try putting a
#!/bin/php at the top, but I think PHP will just display it...). Second, it's one page
for the whole site, you can't decide that some directories have their own version of the
default page.

vda, thanks for your comments and tests!

> See attached httpd.c
> --
> vda
> 

Alex

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: httpd.c.bz2
Type: application/x-bzip
Size: 19509 bytes
Desc: 824490146-httpd.c.bz2
Url : http://lists.busybox.net/pipermail/busybox/attachments/20071018/950739ab/attachment-0004.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: httpd_indexcgi.diff
Type: text/x-patch
Size: 1217 bytes
Desc: 2301216940-httpd_indexcgi.diff
Url : http://lists.busybox.net/pipermail/busybox/attachments/20071018/950739ab/attachment-0005.bin 


More information about the busybox mailing list