Sign inSign up

hectorvido/sh-cgi

By hectorvido

•Updated over 2 years ago

Little Lighttpd image with CGI calling a shell script

Image
0

10K+

hectorvido/sh-cgi repository overview

⁠Dockerfile

FROM docker.io/alpine

ENV VERSION 0.1

COPY . /tmp

RUN apk add --no-cache lighttpd; \
  mv /tmp/lighttpd.conf /etc/lighttpd/; \
  mv /tmp/index.sh /var/www/localhost/htdocs/

CMD lighttpd -D -f /etc/lighttpd/lighttpd.conf

⁠lighttpd.conf

# lighttpd.conf

server.modules = (
    "mod_access",
    "mod_accesslog",
    "mod_setenv"
)

include "mime-types.conf"

server.port          = 8080
server.username      = "lighttpd"
server.groupname     = "lighttpd"

server.document-root = "/var/www/localhost/htdocs"
server.pid-file      = "/run/lighttpd.pid"

server.errorlog      = "/var/log/lighttpd/error.log"
accesslog.filename   = "/var/log/lighttpd/access.log"

server.indexfiles    = ("index.html", "index.sh")
static-file.exclude-extensions = (".cgi", ".sh")

setenv.set-environment = ("VERSION" => env.VERSION)

# mod_cgi.conf

server.modules += ("mod_cgi")
cgi.assign = (
    ".sh"    =>    "/bin/sh",
)

# vim: set ft=conf foldmethod=marker et :

⁠index.sh

#!/bin/sh

if [ "$(echo $HTTP_USER_AGENT | grep -Ei 'curl|wget')" == '' ]; then
	echo -e "Content-Type: text/html\n"
	cat <<-EOF
		<!DOCTYPE html>
		<html>
			<head>
				<title>Lighttpd - SH CGI</title>
				<meta charset="UTF-8">
			</head>
			<body>
				<table>
					<tr>
						<td><b>Webserver:</b></td><td>$SERVER_SOFTWARE</td>
					</tr>
					<tr>
						<td><b>Hostname:</b></td><td>$HOSTNAME</td>
					</tr>
					<tr>
						<td><b>Address:</b></td><td>$SERVER_ADDR</td>
					</tr>
					<tr>
						<td><b>Method:</b></td><td>$REQUEST_METHOD</td>
					</tr>
				</table>
			</body>
		</html>
	EOF
else
	cat <<-EOF
		Content-Type: text

		Version:   $VERSION
		Webserver: $SERVER_SOFTWARE
		Hostname:  $HOSTNAME
		Address:   $SERVER_ADDR
		Method:    $REQUEST_METHOD
	EOF
fi

exit 0

Tag summary

Content type

Image

Digest

sha256:cbb3883a4…

Size

5.1 MB

Last updated

over 2 years ago

docker pull hectorvido/sh-cgi