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-03-09 09:00:09 +01:00 committed by GitHub
parent 8cb834f9ed
commit 5f9e224c3d
8 changed files with 103 additions and 0 deletions

19
config.sh Normal file
View file

@ -0,0 +1,19 @@
#! /bin/bash
# Wo ist der zu nutzende Speicherplatz?
export FILES="/var/www/html"
# Wie soll der titel der Seite sein, die aufgerufene URL ist in $URL enthalten
export HTMLTITLE="Datei: $URL"
# Wo soll das Fertige HTML-Dokument gespeichert werden? Die Variable $HTMLFILEID muss enthalten sein!
export HTMLFILE="/tmp/storage.${HTMLFILEID}.html"
# Welcher Content-Type soll bei einer Unbekannten Datei gesendet werden?
export DEFAULTCONTENT="text/html"
# Port zum lauschen (Falls start-socat.sh als startscript verwendet wird)
export PORT=8888
# Wie heisst die Webseite (URL des obersten Verzeichnis)?
export WEBSITE="http://localhost:$PORT"

22
htmlfilelist.sh Normal file
View file

@ -0,0 +1,22 @@
#! /bin/bash
status="$URL"
# Statisches HTML
echo '<html>
<head>
<title>'"${HTMLTITLE}"'</title>
</head>
<body>
<p>'"$status"'</p>
<h2>Directory list:</h2><br />
<a href="'"${WEBSITE}${URL}/../"'">..</a><br />' >> $HTMLFILE
# Erstelle Dateiliste im HTML-Format
for i in $( ls "${FILE}" ); do
echo ' <a href="'"${WEBSITE}${URL}/${i}"'">'"${i}"'</a><br />' >> $HTMLFILE
done
# Statisches HTML
echo ' </body>
</html>' >> $HTMLFILE

14
httpheaders.sh Normal file
View file

@ -0,0 +1,14 @@
#! /bin/bash
if [ "$CONTENTTYPE" = "html" ]; then
echo 'HTTP/1.1 200 OK' >> $HTMLFILE
echo 'Date: '"$(date)" >> $HTMLFILE
echo 'Server: httpd' >> $HTMLFILE
echo 'Content-Type: text/html' >> $HTMLFILE
echo '' >> $HTMLFILE
else
echo 'HTTP/1.1 200 OK' >> $HTMLFILE
echo 'Date: '"$(date)" >> $HTMLFILE
echo 'Server: httpd' >> $HTMLFILE
echo 'Content-Type: '"$CONTENT" >> $HTMLFILE
echo '' >> $HTMLFILE
fi

3
init.sh Normal file
View file

@ -0,0 +1,3 @@
#! /bin/bash
export HTMLFILEID="$RANDOM"

14
readrequest.sh Normal file
View file

@ -0,0 +1,14 @@
#! /bin/bash
# Notwendige Variablen definieren
header=' '
# Falls im nächsten Bereich keine Datein ausgewertet werden, bleiben folgende Variablen gesetzt
export URL='/'
# Lese anfrage...
read header
URL="${header#GET }"
URL="${URL% HTTP/*}"
export FILE="$FILES$URL"

5
start-socat.sh Normal file
View file

@ -0,0 +1,5 @@
#! /bin/bash
. ./config.sh
socat TCP-LISTEN:$PORT,reuseaddr,fork SYSTEM:"./main.sh" || exit 1
echo "Listening at Port: $PORT"

6
urlcheck.sh Normal file
View file

@ -0,0 +1,6 @@
#! /bin/bash
# Überprüfe auf Versuche, das restliche Dateisystem zu lesen
if [ "$URL" = "*..*" ]; then
export URL='/'
fi

20
writehtml.sh Normal file
View file

@ -0,0 +1,20 @@
#! /bin/bash
# Überprüfe: Ist $FILE ein Verzeichniss und enthält es eine index.* ?
# TODO
# Überprüfe: Datei oder Verzeichniss?
if [[ "$FILE" == *.php ]]; then
export CONTENTTYPE="html"
. ./httpheaders.sh
php "$FILE" >> $HTMLFILE
elif [ -f "${FILE}" ]; then
export CONTENTTYPE="$DEFAULTCONTENT"
. ./httpheaders.sh
cat "${FILE}" >> ${HTMLFILE}
else
export CONTENTTYPE="html"
. ./httpheaders.sh
. ./htmlfilelist.sh
fi