[- BEGIN { unshift(@INC, $ENV{SW_PERLDIR}); } use HTML::Table; use SW::Site::rcm; use SW::XML::Object::LoginID; use SW::DB::rcm; use XML::LibXSLT; use XML::LibXML; use Data::Dumper; #use XML::Sablotron; # break any cache $http_headers_out{'Expires'} = "Fri, 30 Oct 1998 14:19:41 GMT"; $http_headers_out{'Cache-Control'} = "max-age=1, must-revalidate"; # # create site object and connect to db # my $site = SW::Site::rcm->new( $ENV{SW_CONFIG} ); $site->title( 'SRC Client Login' ); #$site->{show_top} = 0; my $db = SW::DB::rcm->new( $ENV{SW_CONFIG} ); if ( $db->connect() ) { } else { print OUT $site->start(); print OUT "sorry can't connect to db"; print OUT $site->end(); exit; } my $content; # # create login object # my $login = SW::XML::Object::LoginID->new( $db ); $login->fromHash( \%fdat ); #if ( ! $login->createTable ) { # $content .= "Can't create table"; #} # # stylesheet selection # $style_base = $site->base_dir . '/client/'; my $default = 'login'; my $xslfile = $default; # select different xsl file if provided if ( defined( $fdat{s} ) ) { $xslfile = $fdat{s}; } # # validate login # #$content .= $fdat{username}; $show_toc = 0; if ( defined( $fdat{username} ) && defined($fdat{passwd}) ) { my $login_id = undef; $login_id = $login->validate( $fdat{username}, $fdat{passwd}); if ( $login_id ) { $show_toc = 1; $xslfile = "success"; # print OUT "hey!!!"; # set md5 cookie my $code = $db->getLoginCode( $login_id ); my $cookie_data = "lid=$code;"; my $table = $req_rec->headers_out; $table->add( 'Set-Cookie' => $cookie_data ); # update last access my $x = $db->lastAccess( $login_id ); # print OUT $x; # exit; } else { $xslfile = "fail"; } } $xslfile = $style_base . $xslfile . '.xsl'; sub myMHMakeCode { my ($self, $processor, $severity, $facility, $code); return $code; # I can deal with internal numbers } sub myMHLog { my ($self, $processor, $code, $level, @fields); # open( FILE, ">>/tmp/sablo.log" ); # print FILE @_; # close( FILE ); } sub myMHError { # my ($self, $processor, $code, $level, @fields); open( FILE, ">>/tmp/sablo.err" ); foreach my $m(@_) { print FILE $m."\n"; } close( FILE ); } #my $sab = new XML::Sablotron; #my $sit = new XML::Sablotron::Situation; # $sab->RegHandler(0, { MHMakeCode => \&myMHMakeCode, # MHLog => \&myMHLog, # MHError => \&myMHError }); #$content.=$sab->process($sit, $xslfile, $login->toXML, 'arg:/output'); #my $result = $sab->getResultArg('arg:/output'); #$content .= $result; my $parser = XML::LibXML->new(); my $xslt = XML::LibXSLT->new(); # trap errors eval <<'EndOfEval'; $start = __LINE__; $source = $parser->parse_string( $login->toXML() ); my $style_doc = $parser->parse_file( $xslfile ) if ( !$@ ); my $stylesheet = $xslt->parse_stylesheet( $style_doc ) if ( !$@ ); my $results; if ( defined($fdat{t} ) ) { $results = $stylesheet->transform( $source, XML::LibXSLT::xpath_to_string( tab => $fdat{t} )) if ( !$@ ); } else { $results = $stylesheet->transform( $source ) if ( !$@); } $content .= $stylesheet->output_string($results) if ( !$@ ); #$content .= "-->" . $login->toXML(); EndOfEval if ( $@ ) { $content .= "Error processing XML: $@"; } # # show toc # my $toc; if ( $show_toc ) { $toc = "Log in successful. Forwarding to your secure area."; $http_headers_out{Location} = "/client/view.epl"; } if ( $@ ) { $toc .= "Error processing XML: $@"; } # # output page # #$site->{leftmenu} = $site->image( 'logo_colour.png', 'Strategic Risk Control Inc.' ); if ( $show_toc ) { print OUT $site->showContent( $toc ); } else { print OUT $site->showContent( $content ); } -]