Standard set of Common Gateway Interface environment variable are described in RFC3875. For example:
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/printenvs
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/printenvs
REMOTE_USER=[http basic auth username]
Example of CGI script that prints them /cgi-bin/printenvs.cgi
Environment variables are set up and the script is invoked with pipes for stdin/stdout.
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) e.g chmod +x /cgi-bin/index.cgi
.
If directory URL is given, no index.html is found and CGI support is enabled, then cgi-bin/index.cgi
will be executed.
BusyBox sources contains two useful CGI programs:
- httpd_indexcgi.c generates a directory listing i.e. list of files. Other Web Servers has this as built-in feature but for BB http this is delegated to a CGI program.
- httpd_ssi.c processes Server Side Includes SSI Use httpd_helpers.sh to compile them.
Also there is and example of shell script to process File Upload httpd_post_upload.cgi
- https://github.com/yurt-page/cgi-oauth plain shell
- https://github.com/yurt-page/cgi-ubus plain shell
- https://github.com/ruudud/cgi bash samples
- https://git.zx2c4.com/cgit/tree/README cgit
- https://github.com/OpenPrinting/cups/tree/master/cgi-bin CUPS printing
- date.cgi
- echo.cgi
- Directory listing script in Perl
- print envs in Python