LINUX.ORG.RU

cgi script post

 , , , ,


0

1

Пытаемся получить содержание данные post с помощью cgi. Делаем:

# curl -d "t" http://127.0.0.1:333/cgi-bin/test.cgi

получаем:

export CONTENT_LENGTH='4'
export CONTENT_TYPE='application/x-www-form-urlencoded'
export GATEWAY_INTERFACE='CGI/1.1'
export HOME='/root'
export HTTP_ACCEPT='*/*'
export HTTP_HOST='127.0.0.1:333'
export HTTP_USER_AGENT='curl/7.38.0'
export LANG='ru_RU.UTF-8'
export LOGNAME='root'
export MAIL='/var/mail/root'
export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
export PATH_INFO=''
export PWD='/srv/cgi-bin'
export QUERY_STRING=''
export REMOTE_ADDR='127.0.0.1'
export REMOTE_PORT='47943'
export REQUEST_METHOD='POST'
export REQUEST_URI='/cgi-bin/test.cgi'
export SCRIPT_FILENAME='/srv/cgi-bin/test.cgi'
export SCRIPT_NAME='/cgi-bin/test.cgi'
export SERVER_PROTOCOL='HTTP/1.0'
export SERVER_SOFTWARE='busybox httpd/1.22.1'
export SHELL='/bin/bash'
export SHLVL='2'
export SSH_CLIENT='10.99.100.10 1173 22'
export SSH_CONNECTION='10.99.100.10 1173 10.99.215.7 22'
export SSH_TTY='/dev/pts/0'
export TERM='xterm'
export USER='root'
export _='/bin/busybox'
root@srv:/#

Как получить параметры, переданные методом post?

★★★★★
#!/bin/sh
#Converts Data sent by method Post or Get
# into stdout like param1 name1 param2 name2 etc.
if [ "$REQUEST_METHOD" = "POST" ] ; then
    QUERY_STRING=`cat -`
fi

line=`echo $QUERY_STRING|sed 's/&/ /g'`

for pair in $line
do
    name=`echo $pair|sed 's/=/ /g'|awk '{print $1}'`
    type=`echo $pair|sed 's/=/ /g'|awk '{print $2}'|sed -e 's/%\(\)/\\\x/g'|sed 's/+/ /g'`
    CNTR=0
    NAME=$name
    while [ "${!name}" != "" ]
    do
        CNTR=$[ $CNTR + 1 ]
        name="${NAME}$CNTR"
    done
    eval ${name}=\"${type}\"
    printf "${name}=\"${type}\"\n"
    [ "${type}" = "" ] && eval ${name}="NULL"
done


Eddy_Em ☆☆☆☆☆
()

использует stdin

ne-vlezay ★★★★★
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.