|
| I have included the code below. The problem is this:
I have created a couple variables (@sensors,$s_dbh,$session) that must
be accessible from within all subroutines. They are, yet the $session
variable behaves oddly. If I attempt to use the program as is, the die
results in a sessionid being printed to the browser...but no record
created in the database. If I simply add a "my" in front of the
"$session =" statement, the die results in a sessionid being printed to
the browser...AND the record created in the database. Why is that?
--------------------------------------
package NetSec::Sensor;
use strict;
use warnings;
use base 'CGI::Application';
use Data::Dumper;
use DBI;
use CGI::Session;
my @sensors =
("25-fw-dmz-c7","26-fw-dmz-c1","27-fw-dmz-c1","28-fw-dmz-c7");
my $s_dbh = DBI->connect("DBI:mysql:session", "processid", "password",
{ RaiseError=>1, AutoCommit=>1 })
or die "Error connecting to Database: " . DBI->errstr;
# Define our run modes
sub setup {
my $self = shift;
$self->start_mode('config_task_select');
$self->error_mode('error');
$self->mode_param('rm');
$self->run_modes(
'config_task_select' => 'config_task_select',
'config_types_select' => 'config_types_select',
'config_view' => 'config_view',
'sensor_select' => 'sensor_select',
'copy_config' => 'copy_config',
'approve_config' => 'approve_config'
);
}
# Execute the following before we execute the requested run mode
sub cgiapp_prerun {
my $self = shift;
my $error = shift;
my $q = $self->query;
$session = CGI::Session->new("driver:mysql",$q, {Handle=>$s_dbh});
die $session->id();
# new session created, finish setting it up
if ( (!$q->cookie("CGISESSID")) or ($session->id() ne
$q->cookie("CGISESSID")) ) {
$session->expire('+8h'); ## expire the session in the db after 1
hour (cookie is not persistent on client).
$session->param('user' => $ENV{REMOTE_USER});
my $cookie = $q->cookie(-name=>'CGISESSID',
-value=>$session->id,
-secure=>1);
$self->header_add(-cookie=>[$cookie]);
}
}
|
|