#!/bin/zsh
cgi_post
-order="${_POST[o]}"
+order=$(validate "${_POST[o]}" 'Name|Length|Date' Name)
for fn in {0..9}; do
- type="${_POST[type$fn]}"
- category="$(echo "${_POST[category$fn]}" |sed 's/\t/ /g;s/\r//g;s/\\/\\\\/g' |head -n1)"
+ category="$(validate "${_POST[category$fn]}" '[[:alnum:]_-]+' none)"
- if [ "$type" = "neg" ]; then
- [ -z "$filters" ] && filters="!"
- [ -n "$filters" ] && egrep -q '(^|\^|\||!)$' <<<"$filters" || filters="${filters}^!"
- elif [ "$type" = "pos" ]; then
- egrep -q '(^|\^|\||!)$' <<<"$filters" || filters="${filters}^"
- fi
+ n=''; while [ -n "${_POST[cfilter${fn}_$n]}" ]; do
+ cfilter="$(validate "${_POST[cfilter${fn}_$n]}" '[[:alnum:]\?!\._=\(\)+-]+' '#')"
- n=''
- while [ -n "${_POST[cfilter${fn}_$n]}" ]; do
- cfilter="$(echo "${_POST[cfilter${fn}_$n]}" |sed 's/\t/ /g;s/\r//g;s/\\/\\\\/g' |head -n1)"
- egrep -q '(^|\^|\||!)$' <<<"${filters}" || filters="${filters}|"
- [ "$category" = "none" ] && filters="${filters}${cfilter}" || filters="${filters}${category}:${cfilter}"
- [ -z "$n" ] && n=0 || n=$(($n + 1))
+ if [ -z "$n" ]; then
+ [ -n "$filters" ] && filters="${filters}^"
+ [ "${_POST[type$fn]}" = 'neg' ] && filters="${filters}!"
+ n=0
+ else
+ filters="${filters}|"
+ n=$(($n + 1))
+ fi
+ [ "$category" = "none" ] && filters="${filters}${cfilter}" \
+ || filters="${filters}${category}:${cfilter}"
done
done
data_dirs cache meta mp4 videos thumbs trash by_length transcoded
cgi_cookie
-validate(){ printf '%s\n' "$1" |sed -rn '2q;/^'"$2"'$/{p;q};a'"$3"; }
+validate(){ printf '%s\n' "$1" |sed -rn '2q;/^('"$2"')$/{p;q};a'"$3"; }
-_GET[o]=$( validate "${_GET[o]}" '(Name|Date|Length)' Name)
+_GET[o]=$( validate "${_GET[o]}" 'Name|Date|Length' Name)
_GET[pn]=$(validate "${_GET[pn]}" '[1-9][0-9]*' 1)
_COOKIE[pagesize]=$(validate "${_COOKIE[pagesize]}" '[1-9][0-9]*' 50)