Zeile 1: |
Zeile 1: |
| =Code= | | =Code= |
− | * Kompliziert:
| |
| <pre> | | <pre> |
− | fkt_read_browsers_query_string () { # SENS: read and sanitize/convert query-string to useable vars
| + | fkt_eval_query_string () { |
− | # (e.g. ?A=1&B=2 changes to correct setted vars A and B)
| + | local INPUT="$QUERY_STRING" |
− | # ARG1: string, query string
| + | |
− | local QUERY_STRING="$1"
| + | test -z "$INPUT" && return |
− |
| + | |
− | test -z "$QUERY_STRING" return 1
| + | local SANITIZED="$(echo $INPUT | sed -e 's/[^%&=+-:!,@\\"-_a-z~]//g')" |
| + | local ESCAPED="$(httpd -d $SANITIZED | sed -e 's/"/\\"/g' -e 's/=/="/g' -e 's/&/";/g ' -e 's/$/"/g')" |
| | | |
− | IFS=\&
| + | eval $ESCAPED 2>/dev/null |
− | set ${QUERY_STRING%%[^%&=+-:@-_a-z~]*}
| |
− | unset IFS
| |
− | VARS="$(echo $* | sed -e 's/ /"; /g' -e 's/=/="/g' -e 's/$/"/g')"
| |
− | VARS="$(httpd -d "$VARS")"
| |
− |
| |
− | eval "$VARS"
| |
| } | | } |
| </pre> | | </pre> |
| | | |
− | * Einfach:
| + | =Code_alt (haesslich,aber tricky!)= |
| <pre> | | <pre> |
− | fkt_eval_query_string () {
| + | fkt_decode_url () { # SENS: convert encoded URL to normal (e.g. %20 = space , %40 = @-Symbol ) |
− | eval $(httpd -d "$QUERY_STRING" | sed -e 's/[^%&=+-:@-_a-z~]//g' -e 's/=/="/g' -e 's/&/"; /g ' -e 's/$/"/g') | + | s=$(echo "$1" | sed -e "s/+/%20/g") # ARG1: (maybe) dirty string |
| + | echo -n ${s%%%*} # OUT1: unescaped string |
| + | |
| + | if [ -n "$s" ] && [ "$s" != "${s#*%}" ]; then |
| + | IFS=\% |
| + | set ${s#*%} |
| + | unset IFS |
| + | |
| + | for i in "$@"; do |
| + | echo -n -e "\\x$(echo $i | dd bs=1 count=2 2>&-)" |
| + | echo -n ${i#??} |
| + | done |
| + | fi |
| + | } |
| + | |
| + | fkt_read_browsers_query_string () { # SENS: read and sanitize/convert query-string to useable vars (e.g. ?A=1&B=2 changes to correct setted vars A and B) |
| + | # ARG1: string, query string |
| + | local QUERY_STRING="$1" |
| + | local DAEMON="fkt_read_browsers_query_string" |
| + | local VARS="" |
| + | |
| + | if [ -z "$QUERY_STRING" ]; then |
| + | fkt_log "$DAEMON" "Zero query!" 1 |
| + | return |
| + | else |
| + | fkt_log "$DAEMON" "Exploring query \"$QUERY_STRING\"" 1 |
| + | fi |
| + | |
| + | IFS=\& |
| + | set ${QUERY_STRING%%[^%&=+-:@-_a-z~]*} |
| + | unset IFS |
| + | fkt_log "$DAEMON" "Escaping query \"$*\"" 1 |
| + | VARS="$(echo $* | sed -e 's/ /"; /g' -e 's/=/="/g' -e 's/$/"/g')" |
| + | fkt_log "$DAEMON" "Escaping query \"$VARS\"" 1 |
| + | VARS="$(httpd -d "$VARS")" |
| + | fkt_log "$DAEMON" "Evaluating query \"$VARS\"" 1 |
| + | eval "$VARS" |
| } | | } |
| </pre> | | </pre> |