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

Compare commits

...

110 commits

Author SHA1 Message Date
niansa
ec3174b204 Deleted cport because it's garbage 2020-12-18 22:25:04 +01:00
niansa
84f6721954 Made cport compile in all compilers 2020-09-12 21:02:44 +00:00
niansa
3a1d6062c9 Hardcoded defaultcontenttype 2020-08-04 19:44:49 +02:00
niansa
ba19b2d8b6 Updated C databuffer library 2020-08-04 18:07:11 +02:00
niansa
144f4ecd09 Marked cport/main.sh executable 2020-08-04 15:10:53 +02:00
niansa
7962a5d901 Updated ctest documentation 2020-08-04 15:08:23 +02:00
niansa
6e700524e3 Added cport documentation 2020-08-04 15:06:50 +02:00
niansa
8feb3f24b1 Added C port to tree 2020-08-04 14:53:23 +02:00
niansa
df16ff520a Updated pandoc usage 2020-08-04 14:48:43 +02:00
niansa
482feb559a WEBSITE setting no longer required 2020-08-04 14:03:07 +02:00
niansa
f4b00e82ab No longer use unix2dos 2020-08-04 13:56:25 +02:00
niansa
9a91175fba Minor decomplexiation 2020-08-04 13:36:00 +02:00
niansa
c1223801ae Removed checks if commands exist 2020-08-04 12:59:29 +02:00
niansa
0d35ec2a9e Little structural improvement 2020-08-03 18:08:24 +02:00
niansa
5331253809 More little improvements 2020-08-03 17:20:50 +02:00
niansa
45cfd2f92e Small documentation improvement 2020-08-03 16:45:13 +02:00
niansa
cb40468346 Set CONTENTTYPE in sendfile.sh just once 2020-08-03 16:43:29 +02:00
niansa
3b4e1e6701 When checking if pandoc is available, actually check for "pandoc" 2020-08-03 16:41:07 +02:00
niansa
a535f19585 chmod a+x'ed all .sh files 2020-08-02 22:24:46 +02:00
niansa
c8369dcebf Updated Readme 2019-10-31 01:31:27 +01:00
niansa
ca527e1a78 Added history 2019-10-31 01:29:34 +01:00
niansa
64f1631578 Fixed "Standart" installation 🤣 2019-05-31 16:57:21 +00:00
niansa
6288a86887 Update main.sh 2019-05-01 11:03:35 +00:00
niansa
da817cdd97 Update main.sh 2019-05-01 10:59:13 +00:00
niansa
543fafb364 Update urlcheck.sh 2019-05-01 10:56:33 +00:00
niansa
1443f73e1c Update init.sh 2019-05-01 10:55:44 +00:00
niansa
68a369a35c Update README.md 2019-05-01 10:48:34 +00:00
niansa
2b720e7c24 Update start-socat.sh 2019-01-22 13:42:40 +00:00
niansa
c6542ec98d Update mkdeb.sh 2019-01-11 16:46:35 +00:00
niansa
92cf8d99b2 Update README.md 2019-01-11 16:28:38 +00:00
niansa
9e75ddabf2 Update sendfile.sh 2019-01-11 16:27:17 +00:00
niansa
6352d21192 Delete htmlfilelist.sh 2019-01-11 16:14:50 +00:00
niansa
7c49789c9b Update config.sh 2019-01-11 16:09:15 +00:00
niansa
48374a7eec Update main.sh 2018-09-24 13:33:52 +00:00
niansa
609d19a287 Update start-socat.sh 2018-07-15 09:56:45 +00:00
niansa
cf1c5694ba Update config.sh, sendfile.sh files 2018-07-15 09:41:29 +00:00
niansa
cc3734e2f1 Delete writehtml.sh 2018-07-15 09:36:51 +00:00
niansa
a601aba795 Update mkdeb.sh, config.sh, sendfile.sh files 2018-07-15 09:30:30 +00:00
niansa
7117ecacaf Update README.md 2018-07-15 09:13:54 +00:00
niansa
fe3580e776 Update README.md 2018-07-15 09:13:19 +00:00
niansa
4c030ab5bb Update README.md 2018-07-15 09:04:03 +00:00
niansa
138caa6ec7 Update config.sh 2018-07-15 09:02:48 +00:00
niansa
26f767532c Update README.md 2018-07-15 08:58:40 +00:00
niansa
ee9145b3a5 Update sendfile.sh 2018-07-15 08:54:28 +00:00
niansa
08692030c7 Update config.sh 2018-07-15 08:54:04 +00:00
niansa
b773ca7aca Update sendfile.sh 2018-07-15 08:52:46 +00:00
niansa
ebbe1cf65a Update ci-test.sh 2018-07-15 08:48:01 +00:00
niansa
6205888968 Update ci-test.sh 2018-07-15 08:46:36 +00:00
niansa
bdf8c224bb Update ci-test.sh 2018-07-15 08:45:20 +00:00
niansa
a714550f23 Update ci-test.sh 2018-07-15 08:44:01 +00:00
niansa
fab4b83c1e Update ci-test.sh 2018-07-15 08:41:13 +00:00
niansa
c64178fd03 Update ci-test.sh 2018-07-15 08:40:56 +00:00
niansa
5c0e379078 Update config.sh 2018-07-15 08:39:39 +00:00
niansa
248905e487 Update config.sh 2018-07-15 08:37:13 +00:00
niansa
82930f4dd1 Update start-socat.sh 2018-07-15 08:28:50 +00:00
niansa
99937bf9ae Update start-socat.sh 2018-07-15 08:26:44 +00:00
niansa
a0a7631e0e Update start-socat.sh 2018-07-15 08:24:27 +00:00
niansa
1f1781f911 Update config.sh 2018-07-15 08:23:48 +00:00
niansa
9e8eb031dd Update start-socat.sh 2018-07-15 08:23:30 +00:00
niansa
671678c573 Update config.sh 2018-07-15 08:22:32 +00:00
niansa
9f90ed22e9 Update start-socat.sh 2018-07-15 08:17:12 +00:00
niansa
5fbf0cb95b Update config.sh 2018-07-15 08:15:54 +00:00
niansa
cb15992a8d Update README.md 2018-07-15 08:12:55 +00:00
niansa
aa8914259e Update README.md 2018-07-15 07:48:31 +00:00
niansa
16ed196e0f Update sendfile.sh 2018-07-15 07:47:18 +00:00
niansa
d3bc9d4edb Update mkpackage.sh 2018-07-15 07:41:23 +00:00
niansa
89d7dce9ac Update mkpackage.sh 2018-07-15 07:40:28 +00:00
niansa
a0ea76cddb Update mkdeb.sh 2018-07-15 07:37:48 +00:00
niansa
b7b7a10358 Update mkdeb.sh 2018-07-15 07:36:04 +00:00
niansa
4a39a37f87 Update mkdeb.sh 2018-07-15 07:34:40 +00:00
niansa
13d321498c Update mkdeb.sh 2018-07-15 07:32:23 +00:00
niansa
5ac6f6404a Update README.md 2018-07-15 07:28:04 +00:00
niansa
14bd41264e Update README.md 2018-07-15 07:27:12 +00:00
niansa
4039accefd Update README.md 2018-07-15 07:26:12 +00:00
niansa
9180357bd6 Update sendfile.sh 2018-07-15 07:24:39 +00:00
niansa
2d432acdfa Update ci-test.sh 2018-07-12 14:24:58 +00:00
niansa
0889b980fe Update ci-test.sh 2018-07-12 14:21:05 +00:00
niansa
63a78f11e9 Update ci-test.sh 2018-07-12 14:18:45 +00:00
niansa
a5140f24d8 Update ci-test.sh 2018-07-12 14:16:02 +00:00
niansa
cb64f53d7b Update .gitlab-ci.yml 2018-07-12 14:14:15 +00:00
niansa
0e551109f7 Add new file 2018-07-12 14:13:15 +00:00
niansa
9946e672c1 Update .gitlab-ci.yml 2018-07-12 14:11:40 +00:00
niansa
a5e64f20bd Update .gitlab-ci.yml 2018-07-12 14:11:10 +00:00
niansa
142a1d4e9d Update .gitlab-ci.yml 2018-07-12 13:57:51 +00:00
niansa
f6446cb9f7 Update .gitlab-ci.yml 2018-07-12 13:55:35 +00:00
niansa
d64e7111db Update .gitlab-ci.yml 2018-07-12 13:53:39 +00:00
niansa
f7258eddfa Update .gitlab-ci.yml 2018-07-12 13:50:51 +00:00
niansa
2ab7a080ff Update .gitlab-ci.yml 2018-07-12 13:49:05 +00:00
niansa
9a7922024d Update .gitlab-ci.yml 2018-07-12 13:41:33 +00:00
niansa
0698650a68 Update .gitlab-ci.yml 2018-07-12 13:39:18 +00:00
niansa
95fac94170 Update .gitlab-ci.yml 2018-07-12 13:36:43 +00:00
niansa
76a49d2b3e Add new file 2018-07-12 13:34:20 +00:00
niansa
f439810637 Update README.md 2018-07-10 04:41:47 +00:00
niansa
7753d3eff7 Update config.sh 2018-07-03 16:43:20 +00:00
niansa
f808c3f852 Update README.md 2018-07-03 16:42:49 +00:00
niansa
15a8ff1c09 Update writehtml.sh 2018-07-03 16:33:11 +00:00
niansa
2dddace612 Update mkdeb.sh 2018-07-03 16:32:24 +00:00
niansa
3fe0bc0a08 Update urlcheck.sh 2018-07-03 16:29:38 +00:00
niansa
232abbb467 Update sendfile.sh 2018-07-03 16:27:02 +00:00
niansa
52e63d6f90 Update readrequest.sh 2018-07-03 16:25:42 +00:00
niansa
348682f157 Update mkdeb.sh 2018-07-03 16:25:00 +00:00
niansa
8d116aaac8 Update mkpackage.sh 2018-07-03 16:24:30 +00:00
niansa
8a00db6458 Update mkpackage.sh 2018-07-03 16:24:07 +00:00
niansa
1e9a30ba1b Update mkdeb.sh 2018-07-03 16:21:43 +00:00
niansa
5c711243e4 Update mkdeb.sh 2018-07-03 16:21:29 +00:00
niansa
c1ca209835 Update main.sh 2018-07-03 16:19:22 +00:00
niansa
d9a68f5333 Update httpheaders.sh 2018-07-03 16:16:35 +00:00
niansa
2fdc38a4dd Update htmlfilelist.sh 2018-07-03 16:15:48 +00:00
niansa
35e7706a70 Update filelist.sh 2018-07-03 16:14:42 +00:00
niansa
e862dceacf Update config.sh 2018-07-03 16:14:12 +00:00
16 changed files with 142 additions and 122 deletions

3
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,3 @@
job:
script:
- chmod +x ./ci-test.sh && ./ci-test.sh

View file

@ -1,40 +1,26 @@
# simpsh-httpd
An usable bash-httpserver with easy configuration and PHP.
## Installation
### *Recomended*: Release installation
1. Download a release from the [Tags](https://gitlab.com/niansa/simpsh-httpd/tags/) page
2. Follow step 4 and 5 of "Installation as package" if you selected to download and install the Prebuild Debian package. Otherwise follow step 3-6 of "Standard installation"
### Installation as package (Debian based distros only)
1. Install build dependencies: `sudo apt install fakeroot`
2. Build package: `cd ; curl https://gitlab.com/niansa/simpsh-httpd/raw/master/mkdeb.sh | bash -`
3. Install package: `sudo dpkg --install ./simpsh-httpd.deb && sudo apt -f install`
4. Edit /etc/simpsh-httpd/config.sh: `sudoedit /etc/simpsh-httpd/config.sh`:
* `FILES` Here is the webroot (homefolder for the website).
* `HTMLTITLE` This is the title for the filelist.
* `OUTFILE` The finished Document will saved here. ${OUTFILEID} must be included!
* `DEFAULTCONTENTTYPE` This Content-Type send the Server, if the requested File isn't a folder or phpfile.
* `PORT` This port will used for listening.
* `WEBSITE` This is the URL of the website (Example: "http://localhost:$PORT")
* `ERROR404` This is the error page 404
* `ERROR403` This is the error page 403
1. Install build dependencies: `sudo apt install fakeroot curl git`
2. Build package: `curl https://gitlab.com/niansa/simpsh-httpd/raw/master/mkdeb.sh | bash -`
3. Install package: `sudo apt install ~/simpsh-httpd.deb`
4. Edit /etc/simpsh-httpd/config.sh: `sudoedit /etc/simpsh-httpd/config.sh`
5. Start simpsh-httpd: `simpsh-httpd-socat -d`
### Standard installation
1. Install following packages: `bash socat dos2unix`
2. Download simpsh-httpd:
* `$ cd ~`
* `$ git clone https://github.com/niansa/simpsh-httpd.git`
* `$ cd ./simpsh-httpd`
3. Edit config.sh:
* `FILES` Here is the webroot (homefolder for the website).
* `HTMLTITLE` This is the title for the filelist.
* `OUTFILE` The finished Document will saved here. ${OUTFILEID} must be included!
* `DEFAULTCONTENTTYPE` This Content-Type send the Server, if the requested File isn't a folder or phpfile.
* `PORT` This port will used for listening.
* `WEBSITE` This is the URL of the website (Example: "http://localhost:$PORT")
* `ERROR404` This is the error page 404
* `ERROR403` This is the error page 403
3. Edit ./config.sh: `nano ./config.sh`
4. Make all files executable
* `chmod -R a+x ~/simpsh-httpd`
5. Start simpsh-httpd:
@ -43,5 +29,29 @@ An usable bash-httpserver with easy configuration and PHP.
6. Have fun with simpsh-httpd!
## Similar projects
Tip: You don't need to restart simpsh-httpd after update/configchange!
### XMB-HTTPD-2
http://xmb.ovh/codes/xmb-httpd-2 (Webpage is down)
Another HTTPD which is written in bash.
### Iwanttobash
https://github.com/plutesci/Iwanttobash
A tool for bash scripting with options for python html etc.
## Entstehung
Irgendwann Mitte des Jahres 2016 fing ich an das HTTP-Protokoll zu
untersuchen. Ich fand es so interessant, dass ich anfing einen
Webserver (HTTPD) zu schreiben! Damals habe ich Bash für alles
eingesetzt, also setzte ich es auch für den Webserver ein... Ich
hatte damals auf einem shell Provider (bitcoinshell) ein Kommando
entdeckt, was mir den Inhalt eines Ordners in HTML als Liste
zurückgab. Da ich dachte, mit dem Kommando ließe sich ein
Dateiindex wohl sehr einfach einbauen, fing ich damit an. Es wurde
aber schwer, als ich feststellte, dass das Kommando nur dort zu
finden war! Also schrieb ich den Dateiindexer selber. Nun kam der
nächste schwere Punkt: kann man auf einem Port lauschen? Ich
probierte es erst mit netcat, was sich als sehr schwierig erwies,
schlussendlich erfüllte socat den Zweck.
Und so fing dieses kleine Projekt an...

21
ci-test.sh Executable file
View file

@ -0,0 +1,21 @@
alias git='"true" ' &&
echo "Installing depencies..." &&
apt update -qq &&
apt install -qq -y fakeroot curl &&
echo "Building Debian package..." &&
mkdir /tmp/simpsh-httpd &&
mv ./* /tmp/simpsh-httpd/ &&
mv ./.git /tmp/simpsh-httpd/ &&
export HOME="/tmp/" &&
cd &&
chmod -R a+x ./simpsh-httpd &&
./simpsh-httpd/mkdeb.sh &&
apt -y install ./simpsh-httpd.deb &&
echo "Starting simpsh-httpd..." &&
mkdir -p /var/www/html &&
simpsh-httpd-socat -d &&
echo "Creating test document..." &&
(echo "This is a test!" > /var/www/html/testdocument.txt) &&
echo "Loading test document from server..."
testdoc="$(curl http://localhost:8888/testdocument.txt)" &&
(if [[ $testdoc == "This is a test!" ]]; then echo "Server returned expected document"; else echo "Something went wrong... Server returned: $testdoc"; exit 1; fi)

24
config.sh Normal file → Executable file
View file

@ -1,23 +1,23 @@
#! /bin/bash
# Wo ist der Webroot (Hauptverzeichniss)?
# The web server is running under this user (requires to start the socat script as root!). This option may be empty
SUUSER=""
# Here is the webroot (homefolder for the website)
FILES="/var/www/html/"
# Wie soll der Titel der Dateiliste sein, die aufgerufene URL ist in $URL enthalten.
HTMLTITLE="Datei: $URL"
# Wo soll das Fertige HTML-Dokument gespeichert werden? Die Variable $OUTFILEID muss enthalten sein!
# The finished Document will saved here. ${OUTFILEID} must be included!
OUTFILE="/tmp/simpsh-html.${OUTFILEID}.html"
# Welcher Content-Type soll bei einem Unbekannten Dateityp gesendet werden?
DEFAULTCONTENTTYPE="text/html"
# Port zum lauschen (Falls start-socat.sh als startscript verwendet wird)
# This port will used for listening
PORT=8888
# Wie heisst die Webseite (URL des obersten Verzeichnis)?
WEBSITE="http://localhost:$PORT"
# Should PHP be enabled? You need to install php-cli package to use it. May be false or true
ENABLE_PHP="false"
# Statuscode-Seiten (Müssen html-Dateien sein)
# Should Markdown be enabled? You need to install pandoc package to use it. May be false or true
ENABLE_MARKDOWN="false"
# Error code pages, they need to be HTML documents
ERROR404="${FILES}/404.html"
ERROR403="${FILES}/403.html"

9
filelist.sh Normal file → Executable file
View file

@ -1,20 +1,17 @@
#! /bin/bash
status="$URL"
# Dynamisches HTML
echo '<html>
<head>
<title>'"${HTMLTITLE}"'</title>
<title>Index of: '"$URL"'</title>
</head>
<body>
<p>'"$status"'</p>
<p>'"$URL"'</p>
<h2>Directory list:</h2><br />
<a href="../">..</a><br />' >> $OUTFILE
for i in $( ls "${FILE}" ); do
echo ' <a href="./'"${i}"'">'"${i}"'</a><br />' >> $OUTFILE
done
# Statisches HTML
echo ' </body>
</html>' >> $OUTFILE

View file

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

2
httpheaders.sh Normal file → Executable file
View file

@ -1,4 +1,6 @@
#! /bin/bash
# Generation of the HTTP-headers
echo "$STATUS" >> $OUTFILE
echo 'Date: '"$(date)" >> $OUTFILE
echo 'Server: httpd' >> $OUTFILE

1
init.sh Normal file → Executable file
View file

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

20
main.sh Normal file → Executable file
View file

@ -1,25 +1,25 @@
#! /bin/bash
# Initalisiere Variablen
# Variable initalisation
. ./init.sh
# Lese configdatei
# Read the config file
. ./config.sh
# Lese HTTP-Anfrage
# Read the HTTP-request
. ./readrequest.sh
# Und vieles andere...
# Some URL checks and modifications
. ./urlcheck.sh
# Wenn das Dokument schon fertig ist, dann den folgenden Schritt überspringen
# Skip following step, if the document was already created successfully
if [ "$DONE" != "true" ]; then
# Schreibe fertiges HTML-Dokument
# Write finished file
. ./sendfile.sh
fi
# Verwende unix2dos auf das Dokument...
unix2dos $OUTFILE &> /dev/null
# Gebe fertiges HTML-Dokument aus
# Print finished document
cat $OUTFILE
# Remove the temporary file
rm $OUTFILE

22
mkdeb.sh Normal file → Executable file
View file

@ -1,15 +1,31 @@
cd ~
git clone https://github.com/niansa/simpsh-httpd.git
# Change to users home
cd
# Clone the repository
git clone https://gitlab.com/niansa/simpsh-httpd.git
# Make the mkpackage script executable
chmod +x ./simpsh-httpd/mkpackage.sh
# Call package-generator script
./simpsh-httpd/mkpackage.sh ~/simpsh-httpd/ ~/simpsh-httpd-pkg/
# Create Package info
mkdir ~/simpsh-httpd-pkg/DEBIAN
cd ./simpsh-httpd/
echo 'Package: simpsh-httpd
Version: 1.2.0
Version: '"$(git rev-list --all --count)"'
Maintainer: nisa/niansa <nisa@bitcoinshell.mooo.com>
Priority: extra
Architecture: all
Depends: bash, socat
Recommends: php-cli, pandoc
Description: An usable bash-httpserver with easy configuration and very simple PHP' > ~/simpsh-httpd-pkg/DEBIAN/control
cd ..
# Build package
fakeroot dpkg -b ~/simpsh-httpd-pkg ~/simpsh-httpd.deb
# Clean up
rm -rf ~/simpsh-httpd-pkg
rm -rf ~/simpsh-httpd

12
mkpackage.sh Normal file → Executable file
View file

@ -1,11 +1,14 @@
echo "Bitte warten... Please wait..."
# Create directories
mkdir "$2"
cd "$2"
mkdir etc
mkdir etc/simpsh-httpd
mkdir usr
mkdir usr/bin
mkdir -p etc/simpsh-httpd
mkdir -p usr/bin
mkdir usr/share
mkdir -p var/www/html
# Copy some files
cp -r "$1" usr/share/simpsh-httpd
echo 'cd /usr/share/simpsh-httpd
./main.sh' > usr/bin/simpsh-httpd
@ -14,4 +17,5 @@ echo 'cd /usr/share/simpsh-httpd/
mv usr/share/simpsh-httpd/config.sh etc/simpsh-httpd
ln -sf /etc/simpsh-httpd/config.sh usr/share/simpsh-httpd/config.sh
chmod -R a+x .
echo "Fertig! Done!"

4
readrequest.sh Normal file → Executable file
View file

@ -1,9 +1,9 @@
#! /bin/bash
# Lese den request
# Read the request
read header
# Verarbeite den request
# Process the request
URL="${header#GET }"
URL="${URL% HTTP/*}"
FILE="$FILES$URL"

16
sendfile.sh Normal file → Executable file
View file

@ -1,16 +1,22 @@
#! /bin/bash
# Überprüfe: Muss eine Dateiliste ausgegeben werden? Ist es ein PHP-script?
if [[ "$FILE" == *.php ]]; then
CONTENTTYPE="text/html"
# TODO: Create a Plugin system
# Default content type to text/html
CONTENTTYPE="text/html"
# Check: Is it a Directory, a PHP script or something else?
if [[ "$FILE" == *.php ]] && [ "$ENABLE_PHP" = "true" ]; then
. ./httpheaders.sh
php "$FILE" >> $OUTFILE
elif [[ "$FILE" == *.md ]] && [ "$ENABLE_MARKDOWN" = "true" ]; then
. ./httpheaders.sh
pandoc -f gfm "$FILE" >> $OUTFILE
elif [ -f "${FILE}" ]; then
CONTENTTYPE="$DEFAULTCONTENTTYPE"
CONTENTTYPE=$(file -b -i "$FILE")
. ./httpheaders.sh
cat "${FILE}" >> ${OUTFILE}
else
CONTENTTYPE="text/html"
. ./httpheaders.sh
. ./filelist.sh
fi

12
start-socat.sh Normal file → Executable file
View file

@ -2,15 +2,17 @@
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo 'simpsh-httpd Copyright (C) 2018 niansa
echo 'simpsh-httpd Copyright (C) 2019 niansa
This program comes with ABSOLUTELY NO WARRANTY; for details read "'"$(pwd)/LICENSE.md"'".
This is free software, and you are welcome to redistribute it under certain conditions; read "'"$(pwd)/LICENSE.md"'" for details.
'
. $DIR/config.sh
. "$DIR"/config.sh
if [ "$SUUSER" != "" ]; then SUPARM='su="'"$SUUSER"'",'; fi
echo "Listening at Port $PORT"
if [ "$1" = "-d" -o "$1" = "--daemon" ]; then
setsid socat TCP-LISTEN:$PORT,reuseaddr,fork SYSTEM:"./main.sh" > /dev/null 2>&1 &
if [ "$1" = "-d" ] || [ "$1" = "--daemon" ]; then
setsid socat TCP-LISTEN:"$PORT",reuseaddr,"$SUPARM"fork SYSTEM:"./main.sh" > /dev/null 2>&1 &
else
socat TCP-LISTEN:$PORT,reuseaddr,fork SYSTEM:"./main.sh"
socat TCP-LISTEN:"$PORT",reuseaddr,"$SUPARM",fork SYSTEM:"./main.sh"
fi

16
urlcheck.sh Normal file → Executable file
View file

@ -1,42 +1,42 @@
#! /bin/bash
# Blockiere Versuche, das restliche Dateisystem zu lesen
# Block tries to read documents outside the document root
if [[ "$URL" == *..* ]]; then
URL='/'
FILE="$FILES"
fi
# Verhindere "/"-bug
# Avoid a bug
if [ -d "$FILE" ]; then
if [[ "$URL" != */ ]]; then
STATUS='HTTP/1.0 302 Moved permanently
Location: '"${WEBSITE}${URL}"'/'
CONTENTTYPE="$DEFAULTCONTENTTYPE"
Location: '"$URL"'/'
CONTENTTYPE="text/html"
. ./httpheaders.sh
DONE=true
fi
fi
# Finde index.html
# Find index.html
if [ -f "${FILE}index.html" ]; then
URL="${URL}index.html"
FILE="${FILE}index.html"
fi
# Finde index.php
# Find index.php
if [ -f "${FILE}index.php" ]; then
URL="${URL}index.php"
FILE="${FILE}index.php"
fi
# Antworte 404 Not Found wenn Datei nicht existiert
# Respond 404 if the file doesn't exist
if [ ! -e "$FILE" ]; then
STATUS='HTTP/1.0 404 Not Found'
CONTENTTYPE='text/html'
FILE="$ERROR404"
fi
# Antworte 403 Forbidden wenn Datei nicht lesbar ist
# Respond 403 if the file isn't readable
if [ ! -r "$FILE" ]; then
STATUS='HTTP/1.0 403 Forbidden'
CONTENTTYPE='text/html'

View file

@ -1,20 +0,0 @@
#! /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="text/html"
. ./httpheaders.sh
php "$FILE" >> $HTMLFILE
elif [ -f "${FILE}" ]; then
export CONTENTTYPE="$DEFAULTCONTENT"
. ./httpheaders.sh
cat "${FILE}" >> ${HTMLFILE}
else
export CONTENTTYPE="text/html"
. ./httpheaders.sh
. ./filelist.sh
fi