I am trying to use CGI to query network devices using snmp via perl. I have a perl script that can do this but I would like to make it available on the web. Can any offer some examples of CGI and perl. I have been looking at cgi programming with perl but I don't see any examples that would help me with my project. Thanks in advance for any assistance.
Comments
:
The main things you need to do to make it a CGI are:-
1) Send a valid HTML header *before* any other output. E.G.
print "Content-type: text/html
";
2) Send HTML output, apart from when you're not wanting to send HTML output. ;-)
3) Accept parameters that are POST'd or in the query string, if you need to feed parameters to your script. You can get them put in a hash by calling the following sub like:-
my %formdata = parseForm;
[code]sub parseForm {
#Create a hash for formdata output.
my %formdata = ();
#We have normal form data. Work out request method and split data into pairs array.
my @pairs = ();
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
$self->{'REQUEST_METHOD'} = 'GET';
} else {
my $buffer = '';
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
$self->{'REQUEST_METHOD'} = 'POST';
}
#Put results in a hash.
foreach my $pair (@pairs) {
#Split up result pairs.
my ($key, $value) = split (/=/, $pair);
#Proccess it all.
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
#If the key already exists....
if ($formdata{$key}) {
#Add it to the end.
$formdata{$key} .= ", $value";
} else {
#Otherwise, just set the key.
$formdata{$key} = $value;
}
}
#Return formdata.
return %formdata;
}[/code]
If you want to do fancier stuff you may need cookies. There's also CGI.pm, Perl's included CGI module, which may or may not interest you.
Jonathan
###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");