Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 633
  • Last Modified:

sh or bash cgi

I'm designing a high school web page and i would like to add a student poll with 5 radio buttons.  I would like the cgi script to use a select case to determine which choice was not null.  I need help on the code for shell script, like how do i parse input from the html form like i can in Perl with the cgi-bin.pl library?  I need to be able to assign a varible to each 'name' element in the form. Please help me.  Thank you for your help.
0
alphamorgan
Asked:
alphamorgan
  • 2
1 Solution
 
ozoCommented:
#!/bin/sh
echo Content-type: text/plain
echo
if [ "$REQUEST_METHOD"  =  "POST" ]
then
read QUERY_STRING
fi
case $QUERY_STRING in
*radio=button1*) echo button1 was selected;;
*radio=button2*) echo button2 was selected;;
*radio=button3*) echo button3 was selected;;
*radio=button4*) echo button4 was selected;;
*radio=button5*) echo button5 was selected;;
esac
for name in `echo $QUERY_STRING | tr '&' ' '`
do
echo $name
#this only works if your form variables are named like sh variables
eval $name
done
set
0
 
ozoCommented:
But I should warn you that the
eval $name
could be dangerous if your script is called with something like
http://cgi.sh?/usr/bin/rm*.*
so you should really validate your input first.
0
 
grantkCommented:
The biggest danger with CGI shell-scripting is the security.
Why can't you use perl with the -T option?
0
 
mikal120797Commented:
You should be able to find all the sample scripts that you need, as well as possibly one to do just what you want (why reinvent the wheel?) at the following URL:

http://www.yahoo.com/Computers_and_Internet/Internet/World_Wide_Web/CGI___Common_Gateway_Interface/
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now