Using the busybox HTTP server

From Chumby Wiki
Revision as of 13:55, 24 January 2010 by Unwiredben (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The chumby classic and chumby one devices run a simple HTTP server using the implementation in busybox. If you don't need to do complicated web server processes, you can use that without needing to install additional software or disable the system's server.

Running CGI Scripts

The simplest way to extend the server is to add scripts and content files to /psp/cgi-bin. These will be available via http://<chumby-ip-address>/cgi-bin/custom/<script-name> Scripts need to be marked executable using

 chmod +x /psp/cgi-bin/<script-name>

Scripts can be written in C and compiled to a binary using the scratchbox toolchain or can be interpreted using a language installed on the device. To use the built-in shell, start the first line with "#!/bin/sh"; to use the mini-perl interpreter, start with "#!/usr/bin/perl".

Supporting Additional MIME Types

The busybox HTTPD looks in each directory for a httpd.conf file that provides configuration information. To add a mapping from an extension to a MIME type, just create this file and add a line like

 .xml:text/xml * httpd.conf has the following format:

This will cause any files ending in .xml to be served as text/xml.

https.conf format

This is borrowed from the httpd.c file in the BusyBox source code:

H:/serverroot     # define the server root. It will override -h
A:172.20.         # Allow address from 172.20.0.0/16
A:10.0.0.0/25     # Allow any address from 10.0.0.0-10.0.0.127
A:10.0.0.0/255.255.255.128  # Allow any address that previous set
A:127.0.0.1       # Allow local loopback connections
D:*               # Deny from other IP connections
E404:/path/e404.html # /path/e404.html is the 404 (not found) error page
I:index.html      # Show index.html when a directory is requested

P:/url:[http://]hostname[:port]/new/path
                  # When /urlXXXXXX is requested, reverse proxy
                  # it to http://hostname[:port]/new/pathXXXXXX

/cgi-bin:foo:bar  # Require user foo, pwd bar on urls starting with /cgi-bin/
/adm:admin:setup  # Require user admin, pwd setup on urls starting with /adm/
/adm:toor:PaSsWd  # or user toor, pwd PaSsWd on urls starting with /adm/
.au:audio/basic   # additional mime type for audio.au files
*.php:/path/php   # run xxx.php through an interpreter

A/D may be as a/d or allow/deny - only first char matters.

Deny/Allow IP logic:

* Default is to allow all (Allow all (A:*) is a no-op).
* Deny rules take precedence over allow rules.
* "Deny all" rule (D:*) is applied last.

Example 1: Allow only specified addresses

 A:172.20          # Allow any address that begins with 172.20.
 A:10.10.          # Allow any address that begins with 10.10.
 A:127.0.0.1       # Allow local loopback connections
 D:*               # Deny from other IP connections

Example 2: Only deny specified addresses

 D:1.2.3.        # deny from 1.2.3.0 - 1.2.3.255
 D:2.3.4.        # deny from 2.3.4.0 - 2.3.4.255
 A:*             # (optional line added for clarity)

If a sub directory contains a config file it is parsed and merged with any existing settings as if it was appended to the original configuration.

subdir paths are relative to the containing subdir and thus cannot affect the parent rules.

Note that since the sub dir is parsed in the forked thread servicing the subdir http request, any merge is discarded when the process exits. As a result, the subdir settings only have a lifetime of a single request.

Custom error pages can contain an absolute path or be relative to 'home_httpd'. Error pages are to be static files (no CGI or script). Error page can only be defined in the root configuration file and are not taken into account in local (directories) config files.