From 4cd212faabec85ea079b393077ca8909e439e810 Mon Sep 17 00:00:00 2001 From: Dominika Date: Fri, 29 May 2020 10:43:22 +0200 Subject: [PATCH] Added PHP and Python experimental compatibility - Closes #1 --- config/master.sh | 3 +++ src/mime.sh | 6 +++++- src/response/200.sh | 17 ++++++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/config/master.sh b/config/master.sh index 0d27f65..7a2dbc3 100644 --- a/config/master.sh +++ b/config/master.sh @@ -18,3 +18,6 @@ cfg[extension]='shs' cfg[extra_headers]='server: HTTP.sh/0.9' cfg[title]='ddd defies development' + +cfg[php_enabled]=true +cfg[python_enabled]=true diff --git a/src/mime.sh b/src/mime.sh index e387bbe..dad346e 100755 --- a/src/mime.sh +++ b/src/mime.sh @@ -7,6 +7,10 @@ # CSS files (.css) -> text/css # Text files (mimetype starting with 'text/') -> text/plain (fixes XSS in pastebin) # All else -> pass real mimetype +# +# For some reason, we now have PHP and Python support (issue #1). +# PHP (.php) -> no content-type +# Python (.py) -> no content-type function get_mime() { local file=$@ @@ -15,7 +19,7 @@ function get_mime() { if [[ $file == *".htm" || $file == *".html" ]]; then content_type="text/html" return 0 - elif [[ $file == *".shs" ]]; then + elif [[ $file == *".shs" || $file == *".py" || $file == *".php" ]]; then content_type="" return 0 elif [[ $file == *".css" ]]; then diff --git a/src/response/200.sh b/src/response/200.sh index 60f5f78..b3da3c6 100755 --- a/src/response/200.sh +++ b/src/response/200.sh @@ -3,12 +3,27 @@ ${cfg[extra_headers]}\r\n" get_mime ${r[uri]} [[ $content_type != '' ]] && printf "content-type: $content_type\r\n" -if [[ ${r[uri]} =~ \.${cfg[extension]}$ ]]; then +if [[ ${cfg[php_enabled]} == true && ${r[uri]} =~ ".php" ]]; then + temp=$(mktemp) + php "${r[uri]}" > $temp + [[ ${r[headers]} != '' ]] && printf "${r[headers]}\r\n\r\n" || printf "\r\n" + cat $temp + rm $temp + +elif [[ ${cfg[python_enabled]} == true && ${r[uri]} =~ ".py" ]]; then + temp=$(mktemp) + python "${r[uri]}" > $temp + [[ ${r[headers]} != '' ]] && printf "${r[headers]}\r\n\r\n" || printf "\r\n" + cat $temp + rm $temp + +elif [[ ${r[uri]} =~ \.${cfg[extension]}$ ]]; then temp=$(mktemp) source "${r[uri]}" > $temp [[ ${r[headers]} != '' ]] && printf "${r[headers]}\r\n\r\n" || printf "\r\n" cat $temp rm $temp + else printf "\r\n" cat "${r[uri]}"