slitaz-base-files rev 267

httphelper: fix bug with HTTP POST forms where tabs, multiple spaces, and ampersands disappeared.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Wed Apr 22 11:55:25 2015 +0300 (2015-04-22)
parents 27287c7c55c9
children 09c5df0a9e5f
files rootfs/usr/lib/slitaz/httphelper.sh
line diff
     1.1 --- a/rootfs/usr/lib/slitaz/httphelper.sh	Tue Mar 31 12:11:10 2015 -0400
     1.2 +++ b/rootfs/usr/lib/slitaz/httphelper.sh	Wed Apr 22 11:55:25 2015 +0300
     1.3 @@ -9,13 +9,16 @@
     1.4  #
     1.5  # Documentation: man httphelper or /usr/share/doc/slitaz/httphelper.txt
     1.6  #
     1.7 -# Copyright (C) SliTaz 2014 - GNU GPL v2
     1.8 +# Copyright (C) SliTaz 2014-2015 - GNU GPL v2
     1.9  #
    1.10  
    1.11 +
    1.12  alias urlencode='busybox httpd -e'
    1.13  alias urldecode='busybox httpd -d'
    1.14  
    1.15 +
    1.16  # Send headers.
    1.17 +
    1.18  header() {
    1.19  	local i
    1.20  	[ -z "$1" ] && set -- "Content-type: text/html; charset=UTF-8"
    1.21 @@ -24,6 +27,7 @@
    1.22  	done
    1.23  }
    1.24  
    1.25 +
    1.26  http_urlencode() {
    1.27  	sed \
    1.28  		-e "s|%|%25|g;  s|!|%21|g; s|\*|%2A|g; s|'|%27|g;  s|(|%28|g" \
    1.29 @@ -32,38 +36,44 @@
    1.30  		-e "s|\?|%3F|g; s|#|%25|g; s|\[|%5B|g; s|\]|%5D|g; s| |+|g"
    1.31  }
    1.32  
    1.33 +
    1.34  htmlentities() {
    1.35  	echo $1 | sed \
    1.36  		-e 's|&|\&amp;|g;  s|<|\&lt;|g;       s|>|\&gt;|g' \
    1.37  		-e 's|"|\&quot;|g; s|'"'"'|\&apos;|g; s|\t|\&#09;|g'
    1.38  }
    1.39  
    1.40 -# MD5 crypt a string such as password (httpd -m dont give same result ?)
    1.41 +
    1.42 +# MD5 crypt a string such as password (httpd -m give not the same result)
    1.43 +
    1.44  md5crypt() {
    1.45  	echo -n "$1" | md5sum | awk '{print $1}'
    1.46  }
    1.47  
    1.48 +
    1.49  # MD5 crypt a string. Stronger crypto than MD5
    1.50 +
    1.51  sha512crypt() {
    1.52  	echo -n "$1" | sha512sum | awk '{print $1}'
    1.53  }
    1.54  
    1.55 -_ARRAY()
    1.56 -{
    1.57 +
    1.58 +_ARRAY() {
    1.59  	if [ -z "$2" ]; then
    1.60  		eval echo \$${1}__NAMES
    1.61  	else
    1.62 -		[ -n "$(eval echo \$${1}__NAMES)" ] && eval echo \$${1}_${2}_${3:-1}
    1.63 +		[ -n "$(eval echo \$${1}__NAMES)" ] && eval "echo \"\$${1}_${2}_${3:-1}\""
    1.64  	fi
    1.65  }
    1.66  
    1.67 +
    1.68  GET()   	{ _ARRAY GET    "$1" $2; }
    1.69  POST()  	{ _ARRAY POST   "$1" $2; }
    1.70  FILE()  	{ _ARRAY FILE   "$1" $2; }
    1.71  COOKIE()	{ _ARRAY COOKIE "$1" $2; }
    1.72  
    1.73 -httpinfo()
    1.74 -{
    1.75 +
    1.76 +httpinfo() {
    1.77  	local i
    1.78  	local j
    1.79  	local x
    1.80 @@ -86,15 +96,15 @@
    1.81  	done
    1.82  }
    1.83  
    1.84 -read_query_string()
    1.85 -{
    1.86 +
    1.87 +read_query_string() {
    1.88  	local i
    1.89  	local names
    1.90  	local cnt
    1.91  	names=""
    1.92  	IFS="&"
    1.93 -	for i in $2 ; do
    1.94 -		var=${i%%[^A-Za-z_0-9]*}
    1.95 +	for i in $2; do
    1.96 +		var=${i%%=*}
    1.97  		case " $names " in
    1.98  			*\ $var\ *)
    1.99  				eval cnt=\$${1}_${var}_count ;;
   1.100 @@ -103,7 +113,7 @@
   1.101  				names="$names $var" ;;
   1.102  		esac
   1.103  		eval ${1}_${var}_count=$((++cnt))
   1.104 -		eval ${1}_${var}_$cnt=\'$(busybox httpd -d "${i#*=}" | sed "s/'/\'\\\\\'\'/g")\'
   1.105 +		eval "${1}_${var}_$cnt='$(busybox httpd -d "${i#*=}" | sed "s/'/\'\\\\\'\'/g; s|\r||g")'"
   1.106  	done
   1.107  	unset IFS
   1.108  	eval ${1}__NAMES=\'${names# }\'
   1.109 @@ -117,8 +127,7 @@
   1.110  
   1.111  
   1.112  
   1.113 -ddcut()
   1.114 -{
   1.115 +ddcut() {
   1.116  	page=4096
   1.117  	skip=$1
   1.118  	count=$(($2 - $1 -2))