# You should have received a copy of the GNU Affero General Public License
# along with Serve0. If not, see <http://www.gnu.org/licenses/>.
-ACTION="$(echo "$_GET[\"action\"]" |egrep '^[a-zA-Z0-9_-]+$')"
+ACTION="$(printf %s "$_GET[\"action\"]" |egrep '^[a-zA-Z0-9_-]+$')"
ACTION="${_EXEC}/actions/${ACTION}.sh"
if [ -x "$ACTION" ]; then
. $ACTION
else
debug "unable to execute $ACTION"
- echo -n "Location: ?p=error\n\n"
+ printf "Location: ?p=error\n\n"
fi
cgi_get() { # parse HTTP GET string
debug "== CGI DATA: GET =="
- echo "$QUERY_STRING" |tr '&' '\n' |while read query; do
- key="$(echo -E "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')"
- val="$(echo -E "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')"
- _GET["$key"]="$(echo -e "$(echo -E "$val" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g')")"
+ printf '%s\n' "$QUERY_STRING" |tr '&' '\n' |while read query; do
+ key="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')"
+ val="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')"
+ _GET["$key"]="$(printf "$(printf %s "$val" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g')")"
debug "_GET[$key] => $val"
done
}
cgi_post() { # parse HTTP POST string
debug "== CGI DATA: POST =="
sed -u 1q |tr '&' '\n' |while read query; do
- key="$(echo -E "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')"
- val="$(echo -E "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')"
- value="$(echo -e "$(echo -E "$val" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g;')")"
+ key="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')"
+ val="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')"
+ value="$(printf "$(printf %s "$val" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g;')")"
if [ -n "$_POST[\"$key\"]" ]; then
n=0
while [ -n "$_POST[\"$key$n\"]" ]; do n=$(($n + 1)); done
cgi_refdata() { # Parse GET data from referer
debug "== CGI DATA: REFERER =="
- echo "$HTTP_REFERER" |cut -d'?' -f2- |tr '&' '\n' |while read query; do
- key="$(echo -E "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')"
- val="$(echo -E "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')"
- _REF["$key"]="$(echo -e "$(echo -E "$val" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g')")"
+ printf '%s\n' "$HTTP_REFERER" |cut -d'?' -f2- |tr '&' '\n' |while read query; do
+ key="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')"
+ val="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')"
+ _REF["$key"]="$(printf "$(printf %s "$val" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g')")"
debug "_REF[$key] => $val"
done
}
urlsave(){
- echo -E "$*" |sed 's:%:\%25:g;s:\?:\%3F:g;s:&:\%26:g;s:'\'':\%27:g;s: :\%20:g;s:!:\%21:g;s:(:\%28:g;s:):\%29:g;s:":\%22:g;'
+ printf %s "$*" |sed 's:%:\%25:g;s:\?:\%3F:g;s:&:\%26:g;s:'\'':\%27:g;s: :\%20:g;s:!:\%21:g;s:(:\%28:g;s:):\%29:g;s:":\%22:g;'
}
# You should have received a copy of the GNU Affero General Public License
# along with shcgi. If not, see <http://www.gnu.org/licenses/>.
-echo -n "Content-Type: text/html;charset=utf-8\n\n"
+printf "Content-Type: text/html;charset=utf-8\n\n"
-PAGE="$(echo -E "$_GET[\"p\"]" |egrep '^[a-zA-Z0-9_-]+$')"
+PAGE="$(printf %s "$_GET[\"p\"]" |egrep '^[a-zA-Z0-9_-]+$')"
PAGE="${_EXEC}/pages/${PAGE}.sh"
[ -x "$PAGE" ] || PAGE="${_EXEC}/pages/error.sh"
NAVIGATION() {
for each in "${_EXEC}"/pages/*.sh; do
- link="$(echo -E "$each" |sed -r "s:^.*/([^/]*)\.sh$:\1:")"
+ link="$(printf %s "$each" |sed -r "s:^.*/([^/]*)\.sh$:\1:")"
title="$($each title)"
- [ -n "$title" ] && echo -E "?p=$link $title"
+ [ -n "$title" ] && printf '%s\n' "?p=$link $title"
done
}