1
0
Fork 0
mirror of https://gitlab.com/niansa/simpsh-httpd.git synced 2025-03-06 20:53:36 +01:00

Add files via upload

This commit is contained in:
niansa 2017-08-21 08:55:46 +02:00 committed by GitHub
parent da5f93dc49
commit d3690881ff
10 changed files with 42 additions and 31 deletions

View file

@ -23,3 +23,6 @@ An usable bash-httpserver with easy configuration and PHP.
* `cd ~/simpsh-httpd`
* `./start-socat.sh`
6. Have fun with simpsh-httpd!
Tip: You don't need to restart simpsh-httpd after update-/configchange!

View file

@ -1,19 +1,22 @@
#! /bin/bash
# Wo ist der Webroot (Hauptverzeichniss)?
export FILES="/var/www/html"
FILES="/var/www/html/"
# Wie soll der Titel der Dateiliste sein, die aufgerufene URL ist in $URL enthalten.
export HTMLTITLE="Datei: $URL"
HTMLTITLE="Datei: $URL"
# Wo soll das Fertige HTML-Dokument gespeichert werden? Die Variable $OUTFILEID muss enthalten sein!
export OUTFILE="/tmp/simpsh-html.${OUTFILEID}.html"
OUTFILE="/tmp/simpsh-html.${OUTFILEID}.html"
# Welcher Content-Type soll bei einem Unbekannten Dateityp gesendet werden?
export DEFAULTCONTENTTYPE="text/html"
DEFAULTCONTENTTYPE="text/html"
# Port zum lauschen (Falls start-socat.sh als startscript verwendet wird)
export PORT=8888
PORT=8888
# Wie heisst die Webseite (URL des obersten Verzeichnis)?
export WEBSITE="http://localhost:$PORT"
WEBSITE="http://localhost:$PORT"
# Statuscode-Seiten (Müssen txt-Dateien sein)
ERROR404="${FILES}/404.txt"

View file

@ -2,7 +2,7 @@
status="$URL"
# Statisches HTML
# Dynamisches HTML
echo '<html>
<head>
<title>'"${HTMLTITLE}"'</title>
@ -11,8 +11,6 @@ echo '<html>
<p>'"$status"'</p>
<h2>Directory list:</h2><br />
<a href="../">..</a><br />' >> $OUTFILE
# Erstelle Dateiliste im HTML-Format
for i in $( ls "${FILE}" ); do
echo ' <a href="./'"${i}"'">'"${i}"'</a><br />' >> $OUTFILE
done

View file

@ -1,5 +1,5 @@
#! /bin/bash
echo "$ANSWER" >> $OUTFILE
echo "$STATUS" >> $OUTFILE
echo 'Date: '"$(date)" >> $OUTFILE
echo 'Server: httpd' >> $OUTFILE
echo 'Content-Type: '"$CONTENTTYPE" >> $OUTFILE

View file

@ -1,3 +1,4 @@
#! /bin/bash
export OUTFILEID="$RANDOM"
STATUS="HTTP/1.0 200 OK"
OUTFILEID="$RANDOM"

View file

@ -9,7 +9,7 @@
# Lese HTTP-Anfrage
. ./readrequest.sh
# Eine kurze sicherheutsüberprüfung...
# Und vieles andere...
. ./urlcheck.sh
# Wenn das Dokument schon fertig ist, dann den folgenden Schritt überspringen

View file

@ -6,4 +6,6 @@ read header
# Verarbeite den request
URL="${header#GET }"
URL="${URL% HTTP/*}"
export FILE="$FILES$URL"
FILE="$FILES$URL"
DECODED_FILE=$(printf '%b' "${FILE//%/\\x}")
FILE="$DECODED_FILE"

View file

@ -2,18 +2,15 @@
# Überprüfe: Muss eine Dateiliste ausgegeben werden? Ist es ein PHP-script?
if [[ "$FILE" == *.php ]]; then
export ANSWER="HTTP/1.0 200 OK"
export CONTENTTYPE="text/html"
CONTENTTYPE="text/html"
. ./httpheaders.sh
php "$FILE" >> $OUTFILE
elif [ -f "${FILE}" ]; then
export ANSWER="HTTP/1.0 200 OK"
export CONTENTTYPE="$DEFAULTCONTENTTYPE"
CONTENTTYPE="$DEFAULTCONTENTTYPE"
. ./httpheaders.sh
cat "${FILE}" >> ${OUTFILE}
else
export ANSWER="HTTP/1.0 200 OK"
export CONTENTTYPE="text/html"
CONTENTTYPE="text/html"
. ./httpheaders.sh
. ./filelist.sh
fi

View file

@ -2,29 +2,36 @@
# Blockiere Versuche, das restliche Dateisystem zu lesen
if [[ "$URL" == *..* ]]; then
export URL='/'
export FILE="$FILES"
URL='/'
FILE="$FILES"
fi
# Verhindere "/"-bug
if [ -d "$FILE" ]; then
if [[ "$URL" != */ ]]; then
export ANSWER='HTTP/1.0 302 Moved permanently
STATUS='HTTP/1.0 302 Moved permanently
Location: '"${WEBSITE}${URL}"'/'
export CONTENTTYPE="$DEFAULTCONTENTTYPE"
CONTENTTYPE="$DEFAULTCONTENTTYPE"
. ./httpheaders.sh
export DONE=true
DONE=true
fi
fi
# Erkenne index.html
# Finde index.html
if [ -f "${FILE}index.html" ]; then
export URL="${URL}index.html"
export FILE="${FILE}index.html"
URL="${URL}index.html"
FILE="${FILE}index.html"
fi
# Erkenne index.php
# Finde index.php
if [ -f "${FILE}index.php" ]; then
export URL="${URL}index.php"
export FILE="${FILE}index.php"
URL="${URL}index.php"
FILE="${FILE}index.php"
fi
# Antworte 404 Not Found wenn Datei nicht existiert
if [ ! -e "$FILE" ]; then
STATUS='HTTP/1.0 404 Not Found'
CONTENTTYPE='text/plain'
FILE="$ERROR404"
fi

View file

@ -16,5 +16,5 @@ elif [ -f "${FILE}" ]; then
else
export CONTENTTYPE="text/html"
. ./httpheaders.sh
. ./htmlfilelist.sh
. ./filelist.sh
fi