Added PHP and Python experimental compatibility - Closes #1

merge-requests/2/head
Dominika 2020-05-29 10:43:22 +02:00
parent f5734a5b5c
commit 4cd212faab
3 changed files with 24 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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]}"