Fellow Monks,
I can get the following code to run fine from command line (without the CGI stuff), but not in this CGI script. I am not getting any errors either (to the screen or in the logs). Anyone know what I'm doing wrong?
Snippet of code from the form which asks for the filename:
start_multipart_form( { -action => "action_upload.cgi",
-enctype => "application/x-www-form-urlencoded",
-method => "post" } ),
.............some html table code.................................
Tr( { -style => "background-color:#CCCCCC" },
td( strong( "Enter the file you want to upload" ) ),
td( filefield( { -name=>'file',
-default=>'starting value',
-size=>30,
-maxlength=>80 } )
), #end td
), #end Tr
action_upload.cgi script:
#!/usr/bin/perl -w
use strict;
use DBI;
use CGI::Carp 'fatalsToBrowser';
use CGI qw/:standard/;
my $infile = upload ('file') or die "$!";
my $message1 = "<u>The data was inserted into the database successfull
+y </u>";
my ($ip,$port);
my %data;
do_work();
dbi();
display_page("$message1");
sub do_work {
while (<$infile>){
if (/(\d+\.\d+\.\d+\.\d+)\s+(\S+)/) {
$ip = $1;
$data{$ip}{cname} = $2;
next;
}
if(m/^\s{1}\|___\s+(\d+)\s\s(.*)/){
$port = $1;
$data{$ip}{ports}{$port}{service} = $2;
$data{$ip}{ports}{$port}{banner} = '';
next;
}
if(m/^\t\s{1}\|___\s+(.*)/){
$data{$ip}{ports}{$port}{banner} = $1;
next;
}
}
}
sub dbi {
my ($i,$j);
### Enable error checking
my %attr = (
PrintError => 0,
RaiseError => 1,
);
### Connect to database
my $dbh = DBI->connect("DBI:mysql:audit", username, password, \%attr)
+;
my $sth = $dbh->prepare("insert into Supersearch (ip, svr_name, port,
+ service, banner) values (?,?,?,?,?)");
for $i (keys %data) {
for $j (keys %{$data{$i}{ports}}) {
$sth->execute($i, $data{$i}{cname}, $j, $data{$i}{ports}{$j}{s
+ervice}, $data{$i}{ports}{$j}{banner});
}
}
### Disconnect from db
$dbh->disconnect;
}
sub display_page {
my $message = "$_[0]";
print
header,
start_html( "-title" => "Results Page"),
p(" "),
p( strong( $message ) ),
p(" "),
end_html;
}
Thanks,
Dru
Another satisfied monk.