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

Compare commits

...

35 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
14 changed files with 49 additions and 63 deletions

View file

@ -4,8 +4,8 @@
## Installation
### *Recomended*: Release installation
1. Download a release from the [Tags](https://gitlab.com/niansa/simpsh-httpd/tags/)
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"
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 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
View file

11
config.sh Normal file → Executable file
View 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://localhost:$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
View 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

View file

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

0
httpheaders.sh Normal file → Executable file
View file

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"

8
main.sh Normal file → Executable file
View file

@ -12,14 +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 file
rm $OUTFILE

2
mkdeb.sh Normal file → Executable file
View 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
View file

0
readrequest.sh Normal file → Executable file
View file

14
sendfile.sh Normal file → Executable file
View file

@ -1,20 +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

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

@ -2,17 +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,"$SUPARM"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,"$SUPARM",fork SYSTEM:"./main.sh"
socat TCP-LISTEN:"$PORT",reuseaddr,"$SUPARM",fork SYSTEM:"./main.sh"
fi

8
urlcheck.sh Normal file → Executable file
View 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'