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` * `cd ~/simpsh-httpd`
* `./start-socat.sh` * `./start-socat.sh`
6. Have fun with simpsh-httpd! 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 #! /bin/bash
# Wo ist der Webroot (Hauptverzeichniss)? # 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. # 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! # 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? # 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) # Port zum lauschen (Falls start-socat.sh als startscript verwendet wird)
export PORT=8888 PORT=8888
# Wie heisst die Webseite (URL des obersten Verzeichnis)? # 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" status="$URL"
# Statisches HTML # Dynamisches HTML
echo '<html> echo '<html>
<head> <head>
<title>'"${HTMLTITLE}"'</title> <title>'"${HTMLTITLE}"'</title>
@ -11,8 +11,6 @@ echo '<html>
<p>'"$status"'</p> <p>'"$status"'</p>
<h2>Directory list:</h2><br /> <h2>Directory list:</h2><br />
<a href="../">..</a><br />' >> $OUTFILE <a href="../">..</a><br />' >> $OUTFILE
# Erstelle Dateiliste im HTML-Format
for i in $( ls "${FILE}" ); do for i in $( ls "${FILE}" ); do
echo ' <a href="./'"${i}"'">'"${i}"'</a><br />' >> $OUTFILE echo ' <a href="./'"${i}"'">'"${i}"'</a><br />' >> $OUTFILE
done done

View file

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

View file

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

View file

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

View file

@ -6,4 +6,6 @@ read header
# Verarbeite den request # Verarbeite den request
URL="${header#GET }" URL="${header#GET }"
URL="${URL% HTTP/*}" 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? # Überprüfe: Muss eine Dateiliste ausgegeben werden? Ist es ein PHP-script?
if [[ "$FILE" == *.php ]]; then if [[ "$FILE" == *.php ]]; then
export ANSWER="HTTP/1.0 200 OK" CONTENTTYPE="text/html"
export CONTENTTYPE="text/html"
. ./httpheaders.sh . ./httpheaders.sh
php "$FILE" >> $OUTFILE php "$FILE" >> $OUTFILE
elif [ -f "${FILE}" ]; then elif [ -f "${FILE}" ]; then
export ANSWER="HTTP/1.0 200 OK" CONTENTTYPE="$DEFAULTCONTENTTYPE"
export CONTENTTYPE="$DEFAULTCONTENTTYPE"
. ./httpheaders.sh . ./httpheaders.sh
cat "${FILE}" >> ${OUTFILE} cat "${FILE}" >> ${OUTFILE}
else else
export ANSWER="HTTP/1.0 200 OK" CONTENTTYPE="text/html"
export CONTENTTYPE="text/html"
. ./httpheaders.sh . ./httpheaders.sh
. ./filelist.sh . ./filelist.sh
fi fi

View file

@ -2,29 +2,36 @@
# Blockiere Versuche, das restliche Dateisystem zu lesen # Blockiere Versuche, das restliche Dateisystem zu lesen
if [[ "$URL" == *..* ]]; then if [[ "$URL" == *..* ]]; then
export URL='/' URL='/'
export FILE="$FILES" FILE="$FILES"
fi fi
# Verhindere "/"-bug # Verhindere "/"-bug
if [ -d "$FILE" ]; then if [ -d "$FILE" ]; then
if [[ "$URL" != */ ]]; then if [[ "$URL" != */ ]]; then
export ANSWER='HTTP/1.0 302 Moved permanently STATUS='HTTP/1.0 302 Moved permanently
Location: '"${WEBSITE}${URL}"'/' Location: '"${WEBSITE}${URL}"'/'
export CONTENTTYPE="$DEFAULTCONTENTTYPE" CONTENTTYPE="$DEFAULTCONTENTTYPE"
. ./httpheaders.sh . ./httpheaders.sh
export DONE=true DONE=true
fi fi
fi fi
# Erkenne index.html # Finde index.html
if [ -f "${FILE}index.html" ]; then if [ -f "${FILE}index.html" ]; then
export URL="${URL}index.html" URL="${URL}index.html"
export FILE="${FILE}index.html" FILE="${FILE}index.html"
fi fi
# Erkenne index.php # Finde index.php
if [ -f "${FILE}index.php" ]; then if [ -f "${FILE}index.php" ]; then
export URL="${URL}index.php" URL="${URL}index.php"
export FILE="${FILE}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 fi

View file

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