Afficher un message
Vieux 15/03/2008, 06h40   #5
mop2
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: cgi using shell script : unexpected behavior


My test:
socket micro_inetd:
http://www.acme.com/software/

In a xterm:
$ micro_inetd 8888 /tmp/cgi

In the browser:
http://localhost:8888/


Some changes in your script:
$ cat /tmp/cgi
#!/bin/sh

wd=$PWD

#echo "Content-type: text/html"
#echo

echo -en "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"

echo "<HTML><HEAD><TITLE>My first cgi</Title></HEAD>"
echo " <BODY>"
echo " <pre>"

set -x # for debug only

input=(`echo "$QUERY_STRING"`)

#check for ; and |
flag=(`echo $input | awk 'BEGIN{flag=0} /;|%3B/{flag=1} /\||%7C/
{flag=2} END{print flag}'`)

if [ $flag -eq 0 ];
then
echo "Malformed URL: invalid characters used"
echo "Please check URL"
else
burl=(`echo $input | awk '{split($0,a,"&");
split(a[1],b,"=")rint b[2]}'`);
echo "<H3>Your URL is </H3> $burl";
#push this in psql db and check if we know
#about it
echo "SELECT sitename FROM urltable WHERE sitename = '$burl';" >
$wd/query.$
flag1=(`psql -f $wd/query.sql urldb | awk 'BEGIN{a=0} /(0 rows)/
{a=1} END{$
echo $flag1

if [ $flag1 -eq 1 ]; then
echo PROBLEM IS HERE
else
echo do something
fi
#return the formatted page
fi
rm -f $wd/query.sql
echo "</BODY>"
echo "</HTML>"
exit



Another example, to play:
Basic HTTPD CGI script
###############
$ cat /tmp/http
#!/bin/bash
printf "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n"
echo ---------BROWSER:
while [ "$REPLY" != $'\r' ];do read -r -t1;[ "$P" ]||P=$REPLY;echo
"$REPLY";done
echo ---------SERVER noHEADER:
echo \$0=$0;echo P=$P
P=${P#*/};echo P=$P
P=${P% *};echo P=$P
P=${P//%20/ };echo P=$P
date;ls -l /bin/*sh|grep -- ^-
echo ---------END
$ micro_inetd 8888 /tmp/http
$ lynx "http://localhost:8888/here, my parms"

  Réponse avec citation
 
Page generated in 0,05891 seconds with 9 queries