2021-09-22 14:52:03 +02:00
|
|
|
#!/usr/bin/env bash
|
2020-05-23 22:13:11 +02:00
|
|
|
|
|
|
|
# mime.sh - determine what Content-Type should be passed on
|
|
|
|
#
|
|
|
|
# Common HTML files (.html/.htm) -> text/html
|
|
|
|
# Shell Server Scripts (.shs) -> leaves without any content type, TBD by the browser
|
|
|
|
# CSS files (.css) -> text/css
|
|
|
|
# Text files (mimetype starting with 'text/') -> text/plain (fixes XSS in pastebin)
|
|
|
|
# All else -> pass real mimetype
|
2020-05-29 10:43:22 +02:00
|
|
|
#
|
|
|
|
# For some reason, we now have PHP and Python support (issue #1).
|
|
|
|
# PHP (.php) -> no content-type
|
|
|
|
# Python (.py) -> no content-type
|
2020-05-23 22:13:11 +02:00
|
|
|
|
|
|
|
function get_mime() {
|
2021-01-01 07:15:51 +01:00
|
|
|
local file="$@"
|
|
|
|
local mime="$(file --mime-type -b "$file")"
|
2020-05-23 22:13:11 +02:00
|
|
|
if [[ $file == *".htm" || $file == *".html" ]]; then
|
2021-02-02 17:11:18 +01:00
|
|
|
mimetype="text/html"
|
2020-05-29 10:43:22 +02:00
|
|
|
elif [[ $file == *".shs" || $file == *".py" || $file == *".php" ]]; then
|
2021-02-02 17:11:18 +01:00
|
|
|
mimetype=""
|
2020-05-23 22:13:11 +02:00
|
|
|
elif [[ $file == *".css" ]]; then
|
2021-02-02 17:11:18 +01:00
|
|
|
mimetype="text/css"
|
2021-07-26 23:05:41 +02:00
|
|
|
elif [[ $mime == "text/"* && $mime != "text/xml" ]]; then
|
2021-02-02 17:11:18 +01:00
|
|
|
mimetype="text/plain"
|
2020-05-23 22:13:11 +02:00
|
|
|
else
|
2021-02-02 17:11:18 +01:00
|
|
|
mimetype="$mime"
|
2020-05-23 22:13:11 +02:00
|
|
|
fi
|
|
|
|
}
|