Commit 4cd212fa authored by Dominika Liberda's avatar Dominika Liberda 💽

Added PHP and Python experimental compatibility - Closes #1

parent f5734a5b
......@@ -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
......@@ -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
......
......@@ -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]}"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment