User Tools

Site Tools


docs:guide-user:services:webserver:http.httpd

BusyBox HTTP Daemon (httpd) webserver

There is no package called httpd! httpd is part of busybox functionality. You could either compile busybox with this functionality included, or you could install a second busybox binary with this functionality included.

From http://www.busybox.net/downloads/BusyBox.html:

httpd

    httpd [-ifv[v]] [-c CONFFILE] [-p [IP:]PORT] [-u USER[:GRP]] [-r REALM] [-h HOME] or httpd -d/-e/-m STRING

    Listen for incoming HTTP requests

    Options:

            -i              Inetd mode
            -f              Do not daemonize
            -v[v]           Verbose
            -c FILE         Configuration file (default httpd.conf)
            -p [IP:]PORT    Bind to ip:port (default *:80)
            -u USER[:GRP]   Set uid/gid after binding to port
            -r REALM        Authentication Realm for Basic Authentication
            -h HOME         Home directory (default .)
            -m STRING       MD5 crypt STRING
            -e STRING       HTML encode STRING
            -d STRING       URL decode STRING

Note that multiple instances of httpd can be run, which would have different .conf files:

root@OpenWrt:~# /usr/sbin/httpd -p 80 -h /www
root@OpenWrt:~# /usr/sbin/httpd -p 8080 -h /www2 -c /etc/httpd2.conf

Configuration

httpd works without a configuration file. Default is /etc/httpd.conf (there is also some brief uci support for this: httpd):

#
# httpd.conf - BusyBox v1.00 (2005.04.23-22:18+0000) multi-call binary
# Contribute by Dubravko Penezic, dpenezic@gmail.com , 2005-05-15
#

#
# Allow/Deny part
#
# [aA]:from    ip address allow, * for wildcard, network subnet allow
# [dD]:from    ip address deny, * for wildcard, network subnet allow
#
# network subnet definition
#  172.20.                    address from 172.20.0.0/16
#  10.0.0.0/25                address from 10.0.0.0-10.0.0.127
#  10.0.0.0/255.255.255.128   address that previous set
#
#  The Deny/Allow IP logic:
#
#  - Default is to allow all.  No addresses are denied unless
#         denied with a D: rule.
#  - Order of Deny/Allow rules is significant
#  - Deny rules take precedence over allow rules.
#  - If a deny all rule (D:*) is used it acts as a catch-all for unmatched
#       addresses.
#  - Specification of Allow all (A:*) is a no-op
#
# 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
#
#   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)
#
# Note:
# A:*
# D:*
# Mean deny ALL !!!!
#

A:*

#
# Authentication part
#
# /path:user:pass     username/password
#
# password may be clear text or MD5 cript
#
# Example :
# /cgi-bin:admin:FOO
#
# MD5 crypt password :
# httpd -m "_password_"
# Example :
# httpd -m "astro"  =>  $1$$e6xMPuPW0w8dESCuffefU.
# /work:toor:$1$$e6xMPuPW0w8dESCuffefU.
#

#
# MIME type part
#
# .ext:mime/type   new mime type not compiled into httpd
#
# Example :
# .ipk:application/octet-stream
#
# MIME type compiled into httpd
#
# .htm:text/html
# .html:text/html
# .jpg:image/jpeg
# .jpeg:image/jpeg
# .gif:image/gif
# .png:image/png
# .txt:text/plain
# .h:text/plain
# .c:text/plain
# .cc:text/plain
# .cpp:text/plain
# .css:text/css
# .wav:audio/wav
# .avi:video/x-msvideo
# .qt:video/quicktime
# .mov:video/quicktime
# .mpe:video/mpeg
# .mpeg:video/mpeg
# .mid:audio/midi
# .midi:audio/midi
# .mp3:audio/mpeg
#
# Default MIME type is application/octet-stream if extension isnt set
#

CGI scripts

See Common Gateway Interface. httpd expects it's CGI script files to be in the subdirectory cgi-bin under main web directory set by options -h (default is /www, so /www/cgi-bin). The CGI script files must also have permission to be executed (min mode 700).

CGI

Standard set of Comon Gateway Interface environment variable are :

CONTENT_TYPE=application/x-www-form-urlencoded
GATEWAY_INTERFACE=CGI/1.1
REMOTE_ADDR=192.168.1.180
QUERY_STRING=Zbr=1234567&SrceMB=&ime=jhkjhlkh+klhlkjhlk+%A9%D0%C6%AE%C6%AE&prezime=&sektor=OP
REMOTE_PORT=2292
CONTENT_LENGTH=128
REQUEST_URI=/cgi-bin/test
SERVER_SOFTWARE=busybox httpd/1.35 6-Oct-2004
PATH=/bin:/sbin:/usr/bin:/usr/sbin
HTTP_REFERER=http://192.168.1.1/index1.html
SERVER_PROTOCOL=HTTP/1.0
PATH_INFO=
REQUEST_METHOD=POST
PWD=/www/cgi-bin
SERVER_PORT=80
SCRIPT_NAME=/cgi-bin/test
REMOTE_USER=[http basic auth username]

/cgi-bin/test

#!/bin/sh
echo "Content-type: text/html"
echo ""
echo "Sample CGI Output"
echo ""
echo ""
env
echo ""
echo ""

Environment variables are set up and the script is invoked with pipes for stdin/stdout.

HTML Forms

If a post is being done the script is fed the POST data in addition to setting the QUERY_STRING variable (for GETs or POSTs).

The preferred way to do forms in CGI is POST.

POST

Example how to use POST in form:

/www/form-post.html

CGI Test
  Text field
 
  Radio button  
  
     1
  
  
     2
  
  
     3
  
  Some text 
 
   
   
   

/www/cgi-bin/test-post:

#!/bin/sh
echo "Content-type: text/html"
echo ""
echo "Sample CGI Output"
echo ""
echo ""
echo "Environment variables"
echo ""
env
echo ""
echo "========================================================="
echo ""
echo "Form variables :"
echo ""
read QUERY_STRING
eval $(echo "$QUERY_STRING"|awk -F'&' '{for(i=1;i<=NF;i++){print $i}}')
tmp=`httpd -d $Text_Field`
echo "Text_Field=$tmp"
tmp=`httpd -d $Radio_Button`
echo "Radio_Button=$tmp"
tmp=`httpd -d $Text_Area`
echo "Text_Area=$tmp"
echo ""
echo ""

GET

Text area fields (and any other field that may contain \n are very hard to menage). Example how to use GET in form:

/www/form-get.html:


CGI Test




  Text field
    
  
  Radio button  
  
     1
  
  
     2
  
  
     3
  
  &nbsp;
  
    
    
  
  &nbsp;
  &nbsp;


/www/cgi-bin/test-get:

#!/bin/sh
echo "Content-type: text/html"
echo ""
echo "Sample CGI Output"
echo ""
echo ""
echo "Environment variables"
echo ""
env
echo ""
echo "========================================================="
echo ""
echo "Form variables :"
echo ""
eval $(echo "$QUERY_STRING"|awk -F'&' '{for(i=1;i<=NF;i++){print $i}}')
tmp=`httpd -d $Text_Field`
echo "Text_Field=$tmp"
tmp=`httpd -d $Radio_Button`
echo "Radio_Button=$tmp"
echo ""
echo ""
docs/guide-user/services/webserver/http.httpd.txt · Last modified: 2018/03/03 20:30 by bobafetthotmail