mirror of
https://gitlab.com/niansa/simpsh-httpd.git
synced 2025-03-06 20:53:36 +01:00
Compare commits
29 commits
Author | SHA1 | Date | |
---|---|---|---|
|
ec3174b204 | ||
|
84f6721954 | ||
|
3a1d6062c9 | ||
|
ba19b2d8b6 | ||
|
144f4ecd09 | ||
|
7962a5d901 | ||
|
6e700524e3 | ||
|
8feb3f24b1 | ||
|
df16ff520a | ||
|
482feb559a | ||
|
f4b00e82ab | ||
|
9a91175fba | ||
|
c1223801ae | ||
|
0d35ec2a9e | ||
|
5331253809 | ||
|
45cfd2f92e | ||
|
cb40468346 | ||
|
3b4e1e6701 | ||
|
a535f19585 | ||
|
c8369dcebf | ||
|
ca527e1a78 | ||
|
64f1631578 | ||
|
6288a86887 | ||
|
da817cdd97 | ||
|
543fafb364 | ||
|
1443f73e1c | ||
|
68a369a35c | ||
|
2b720e7c24 | ||
|
c6542ec98d |
13 changed files with 42 additions and 38 deletions
25
README.md
25
README.md
|
@ -5,7 +5,7 @@
|
|||
|
||||
### *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 "Standart installation"
|
||||
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 curl git`
|
||||
|
@ -14,7 +14,7 @@
|
|||
4. Edit /etc/simpsh-httpd/config.sh: `sudoedit /etc/simpsh-httpd/config.sh`
|
||||
5. Start simpsh-httpd: `simpsh-httpd-socat -d`
|
||||
|
||||
### Standart installation
|
||||
### Standard installation
|
||||
1. Install following packages: `bash socat dos2unix`
|
||||
2. Download simpsh-httpd:
|
||||
* `$ cd ~`
|
||||
|
@ -32,9 +32,26 @@
|
|||
## Similar projects
|
||||
|
||||
### XMB-HTTPD-2
|
||||
http://xmb.ovh/codes/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.
|
||||
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...
|
||||
|
|
0
ci-test.sh
Normal file → Executable file
0
ci-test.sh
Normal file → Executable file
11
config.sh
Normal file → Executable file
11
config.sh
Normal file → Executable file
|
@ -6,21 +6,12 @@ SUUSER=""
|
|||
# Here is the webroot (homefolder for the website)
|
||||
FILES="/var/www/html/"
|
||||
|
||||
# Title of the file list, the URL is inside $URL
|
||||
HTMLTITLE="Datei: $URL"
|
||||
|
||||
# The finished Document will saved here. ${OUTFILEID} must be included!
|
||||
OUTFILE="/tmp/simpsh-html.${OUTFILEID}.html"
|
||||
|
||||
# This Content-Type send the Server, if the requested File isn't a folder or phpfile
|
||||
DEFAULTCONTENTTYPE="text/html"
|
||||
|
||||
# This port will used for listening
|
||||
PORT=8888
|
||||
|
||||
# This is the URL of the website (Example: "http://example.org:$PORT")
|
||||
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"
|
||||
|
||||
|
@ -29,4 +20,4 @@ ENABLE_MARKDOWN="false"
|
|||
|
||||
# Error code pages, they need to be HTML documents
|
||||
ERROR404="${FILES}/404.html"
|
||||
ERROR403="${FILES}/403.html"
|
||||
ERROR403="${FILES}/403.html"
|
||||
|
|
9
filelist.sh
Normal file → Executable file
9
filelist.sh
Normal file → Executable file
|
@ -1,20 +1,17 @@
|
|||
#! /bin/bash
|
||||
|
||||
status="$URL"
|
||||
|
||||
# Dynamic 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
|
||||
|
||||
# Static HTML
|
||||
echo ' </body>
|
||||
</html>' >> $OUTFILE
|
||||
|
|
0
httpheaders.sh
Normal file → Executable file
0
httpheaders.sh
Normal file → Executable file
1
init.sh
Normal file → Executable file
1
init.sh
Normal file → Executable file
|
@ -1,4 +1,5 @@
|
|||
#! /bin/bash
|
||||
|
||||
# Default variables
|
||||
STATUS="HTTP/1.0 200 OK"
|
||||
OUTFILEID="$RANDOM"
|
||||
|
|
9
main.sh
Normal file → Executable file
9
main.sh
Normal file → Executable file
|
@ -12,17 +12,14 @@
|
|||
# Some URL checks and modifications
|
||||
. ./urlcheck.sh
|
||||
|
||||
# Skip following step, if the document is already created successfully
|
||||
# Skip following step, if the document was already created successfully
|
||||
if [ "$DONE" != "true" ]; then
|
||||
# Write finished file
|
||||
. ./sendfile.sh
|
||||
fi
|
||||
|
||||
# Convert Unix to Dos
|
||||
unix2dos $OUTFILE &> /dev/null
|
||||
|
||||
# Print finished document
|
||||
cat $OUTFILE
|
||||
|
||||
# Remove the temporary files
|
||||
rm $OUTFILE
|
||||
# Remove the temporary file
|
||||
rm $OUTFILE
|
||||
|
|
2
mkdeb.sh
Normal file → Executable file
2
mkdeb.sh
Normal file → Executable file
|
@ -19,7 +19,7 @@ Maintainer: nisa/niansa <nisa@bitcoinshell.mooo.com>
|
|||
Priority: extra
|
||||
Architecture: all
|
||||
Depends: bash, socat
|
||||
Recommends: php7.2-cli, markdown
|
||||
Recommends: php-cli, pandoc
|
||||
Description: An usable bash-httpserver with easy configuration and very simple PHP' > ~/simpsh-httpd-pkg/DEBIAN/control
|
||||
cd ..
|
||||
|
||||
|
|
0
mkpackage.sh
Normal file → Executable file
0
mkpackage.sh
Normal file → Executable file
0
readrequest.sh
Normal file → Executable file
0
readrequest.sh
Normal file → Executable file
13
sendfile.sh
Normal file → Executable file
13
sendfile.sh
Normal file → Executable file
|
@ -1,21 +1,22 @@
|
|||
#! /bin/bash
|
||||
|
||||
# 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 ]] && [ "$(which php)" != "" ] && [ "$ENABLE_PHP" = "true" ]; then
|
||||
CONTENTTYPE="text/html"
|
||||
if [[ "$FILE" == *.php ]] && [ "$ENABLE_PHP" = "true" ]; then
|
||||
. ./httpheaders.sh
|
||||
php "$FILE" >> $OUTFILE
|
||||
elif [[ "$FILE" == *.md ]] && [ "$(which markdown)" != "" ] && [ "$ENABLE_MARKDOWN" = "true" ]; then
|
||||
CONTENTTYPE="text/html"
|
||||
elif [[ "$FILE" == *.md ]] && [ "$ENABLE_MARKDOWN" = "true" ]; then
|
||||
. ./httpheaders.sh
|
||||
pandoc -f markdown_github "$FILE" >> $OUTFILE
|
||||
pandoc -f gfm "$FILE" >> $OUTFILE
|
||||
elif [ -f "${FILE}" ]; then
|
||||
CONTENTTYPE=$(file -b -i "$FILE")
|
||||
. ./httpheaders.sh
|
||||
cat "${FILE}" >> ${OUTFILE}
|
||||
else
|
||||
CONTENTTYPE="text/html"
|
||||
. ./httpheaders.sh
|
||||
. ./filelist.sh
|
||||
fi
|
||||
|
|
2
start-socat.sh
Normal file → Executable file
2
start-socat.sh
Normal file → Executable file
|
@ -2,7 +2,7 @@
|
|||
|
||||
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.
|
||||
'
|
||||
|
|
8
urlcheck.sh
Normal file → Executable file
8
urlcheck.sh
Normal file → Executable file
|
@ -10,8 +10,8 @@ fi
|
|||
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
|
||||
|
@ -29,14 +29,14 @@ if [ -f "${FILE}index.php" ]; then
|
|||
FILE="${FILE}index.php"
|
||||
fi
|
||||
|
||||
# Answer 404 if the file doesn't exist
|
||||
# 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
|
||||
|
||||
# Answer 403 if the file isn't readable
|
||||
# Respond 403 if the file isn't readable
|
||||
if [ ! -r "$FILE" ]; then
|
||||
STATUS='HTTP/1.0 403 Forbidden'
|
||||
CONTENTTYPE='text/html'
|
||||
|
|
Loading…
Add table
Reference in a new issue