# You should have received a copy of the GNU Affero General Public License
# along with CGIlite. If not, see <http://www.gnu.org/licenses/>.
+[ -n "$include_cgilite" ] && return 0
+# guard set after webserver part
+
# ksh and zsh workaround
# set -o posix # ksh, not portable
setopt -o OCTAL_ZEROES 2>&-
exit 0
fi
+include_cgilite="$0"
+
if [ "${REQUEST_METHOD}" = POST -a "${CONTENT_LENGTH:-0}" -gt 0 -a \
"${CONTENT_TYPE}" = "application/x-www-form-urlencoded" ]; then
cgilite_post="$(head -c "$CONTENT_LENGTH")"
fi
+debug(){ [ $# -gt 0 ] && printf '%s\n' "$@" >&2 || tee -a /dev/stderr; }
[ "${DEBUG+x}" ] && env >&2
cgilite_count(){
}
HTML(){
+ # Escape HTML cahracters
+ # Also escape [, ], and \n for use in html-sh
local str out
[ $# -eq 0 ] && str="$(cat)" || str="$*"
while [ "$str" ]; do
\>*) out="${out}>";;
\"*) out="${out}"";;
\'*) out="${out}'";;
+ \[*) out="${out}[";;
+ \]*) out="${out}]";;
+ "${CR}"*) out="${out}
";;
+ "${BR}"*) out="${out}
";;
*) out="${out}${str%"${str#?}"}";;
esac
str="${str#?}"
}
URL(){
+ # Escape pathes, so they can be used in link tags and HTTP Headers
local str out
[ $# -eq 0 ] && str="$(cat)" || str="$*"
while [ "$str" ]; do
\'*) out="${out}%27";;
\?*) out="${out}%3F";;
\#*) out="${out}%23";;
+ \[*) out="${out}%5B";;
+ \]*) out="${out}%5D";;
+ \ *) out="${out}%20";;
+ " "*) out="${out}%09";;
+ "${CR}"*) out="${out}%0D";;
+ "${BR}"*) out="${out}%0A";;
%*) out="${out}%25";;
*) out="${out}${str%"${str#?}"}";;
esac