OpenPKG CVS Repository
  http://cvs.openpkg.org/
  ____________________________________________________________________________

  Server: cvs.openpkg.org                  Name:   Thomas Lotterer
  Root:   /v/openpkg/cvs                   Email:  [EMAIL PROTECTED]
  Module: openpkg-registry                 Date:   24-Nov-2005 12:21:57
  Branch: HEAD                             Handle: 2005112411215600

  Modified files:
    openpkg-registry        registry-ui.pl

  Log:
    session handling

  Summary:
    Revision    Changes     Path
    1.9         +53 -1      openpkg-registry/registry-ui.pl
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: openpkg-registry/registry-ui.pl
  ============================================================================
  $ cvs diff -u -r1.8 -r1.9 registry-ui.pl
  --- openpkg-registry/registry-ui.pl   24 Nov 2005 11:14:25 -0000      1.8
  +++ openpkg-registry/registry-ui.pl   24 Nov 2005 11:21:56 -0000      1.9
  @@ -28,10 +28,12 @@
   
   use Data::Dumper;
   use CGI;
  +use CGI::Cookie;
  +use CGI::Session;
  +use CGI::GuruMeditation;
   use DBI;
   use DBD::Pg;
   use MIME::Base64;
  -use CGI::GuruMeditation;
   use XML::Simple;
   
   #   configure optional debugging
  @@ -44,6 +46,10 @@
   my $progvers="0.0.16";
   my $progdate="19-Nov-2005";
   
  +#   determine path to OpenPKG instance
  +my $PREFIX='@l_prefix@';
  +$PREFIX=$ENV{OPENPKG_PREFIX} if ($ENV{OPENPKG_PREFIX} ne "");
  +
   #   configuration
   #
   my $cfg = {};
  @@ -61,6 +67,7 @@
   $cfg->{db}->{registry}->{password}="registry";
   $cfg->{db}->{registry}->{tablespace}="registry";
   $cfg->{db}->{registry}->{host}="127.0.0.1";
  +$cfg->{db}->{session}->{dbfile}="$PREFIX/var/openpkg-registry/ui/session.db";
   
   #   create objects
   my $cgi  = new CGI;
  @@ -74,6 +81,7 @@
   my $sth; # scratch statement handle for database operations
   my $msg; # scratch variable for message fiddling
   my $dbh; # database handle
  +my $dbs; # database handle for session
   
   sub dbopen($) {
       my ($db) = @_;
  @@ -92,6 +100,16 @@
               }
           );
       }
  +    elsif ($db eq "session") {
  +        $dbi = DBI->connect (
  +            "DBI:SQLite:dbname=".$cfg->{db}->{session}->{dbfile}, "", "",
  +            {
  +                PrintError => 0,
  +                RaiseError => 1,
  +                AutoCommit => 1
  +            }
  +        );
  +    }
       else {
           die "dbopen does not know how to handle db=\"".$db."\"";
       }
  @@ -129,6 +147,28 @@
       &printprettyerror("Registry database backend unavailable", &prettydbi());
       goto CUS;
   }
  +$dbs = &dbopen("session");
  +if (not defined $dbs) {
  +    &printprettyerror("Session database not accessible", &prettydbi());
  +    goto CUS;
  +}
  +
  +#   establish CGI Session object
  +my $session;
  +$session = undef;
  +CGI::Session->name("sid");
  +$session = new CGI::Session(
  +    "driver:sqlite;serializer:Storable;id:uuid", $cgi, { Handle => $dbs, 
TableName => 'session' }
  +);
  +if (not defined $session) {
  +    &printprettyerror("Session handling failed", "");
  +    goto CUS;
  +}
  +$session->expires("+5m");
  +if (not defined($session->param("housekeeping"))) {
  +    $session->param("housekeeping", "done");
  +    CGI::Session->find(sub {});
  +}
   
   #   continue to the pages that require database access
   #
  @@ -197,6 +237,7 @@
   #   die gracefully ;-)
   #
   CUS:
  +undef $session;
   undef $cgi;
   undef $dbh;
   exit(0);
  @@ -217,6 +258,17 @@
       if ($refresh) {
           $header->{refresh} = "$refresh; $myurl";
       }
  +
  +    #   determine HTTP response cookies for session persistency
  +    if (defined $session and $session->is_new()) {
  +        $header->{cookie} = $cgi->cookie(
  +            -name    => $session->name(),
  +            -value   => $session->id(),
  +            -expires => sprintf("+%ds", $session->expires()),
  +            -path    => $cgi->url(-absolute => 1)
  +        )
  +    }
  +
       return $cgi->header($header);
   }
   
  @@ .
______________________________________________________________________
The OpenPKG Project                                    www.openpkg.org
CVS Repository Commit List                     [email protected]

Reply via email to