#!/bin/sh

# CGI Framework für einfache POST und GET-Funktionen
# sudo git clone https://git.plutz.net/git/cgilite /opt/cgilite
. /opt/cgilite/cgilite.sh

echo "Content-Type: text/html; charset=utf-8"
echo

vorname="$(POST nf)"
nachname="$(POST nl)"
grussformel=""

if [ "${vorname}" != "" -o "${nachname}" != "" ]; then
  grussformel="Sei gegrüßt ${vorname} ${nachname}!</br>"
fi

cat <<-HTML_ENDE
	<!DOCTYPE HTML>
	<html lang="de"><head>
	  <title>Hallo Welt!</title>
	</head><body>
	  <form action="/hallo.sh" method="POST">
		${grussformel}
		<h1>Hallo Programm</h1>
		<input type="text" placeholder="Vorname"  name="nf">
		<input type="text" placeholder="Nachname" name="nl">
		<input type="submit">
		<h2>Letztes Aufrufdatum:</h2>
		$(date)
		<h2>Webserver Umgebungsvariablen</h2>
		<pre>$(env)</pre>
	  </form>
	</body></html>
	HTML_ENDE