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: 07-Jul-2006 01:02:58 Branch: HEAD Handle: 2006070700025700 Modified files: openpkg-registry registry-ui.pl Log: leverage OSSP::cfg; make ase URL a run-time configuration; no attempts to fetch empty URLs to retrieve foreign canvas Summary: Revision Changes Path 1.66 +85 -28 openpkg-registry/registry-ui.pl ____________________________________________________________________________ patch -p0 <<'@@ .' Index: openpkg-registry/registry-ui.pl ============================================================================ $ cvs diff -u -r1.65 -r1.66 registry-ui.pl --- openpkg-registry/registry-ui.pl 5 Jul 2006 15:41:42 -0000 1.65 +++ openpkg-registry/registry-ui.pl 6 Jul 2006 23:02:57 -0000 1.66 @@ -31,6 +31,7 @@ use CGI::Cookie; use CGI::Session; use CGI::GuruMeditation; +use OSSP::cfg; use DBI; use DBD::Pg; use MIME::Base64; @@ -57,32 +58,86 @@ $response->{message} = new String::Divert; $response->{message}->fold("message"); -# configuration +# configuration preset defaults then read config # -my $cfg = {}; -# user identification -# -# constant - no authentication at all, assume single constant default user -# naive - no authentication at all, ask for username and just trust it -# basicauth - believe in webserver's basic authentication -# ase - OSSP affiliation services environment -# -$cfg->{identification}->{mode} = "ase"; -$cfg->{identification}->{default} = "anonymous"; -$cfg->{db}->{registry}->{username}="registry"; -$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"; -#FIXME $cfg->{canvas}->{url} = "http://meta.openpkg.org/?path=project.registry&pane=1&stretch=body"; -$cfg->{canvas}->{urlcache} = 1; -$cfg->{canvas}->{mark_head}="<!-- CANVAS: HEAD -->"; -$cfg->{canvas}->{mark_body}="<!-- CANVAS: BODY -->"; -$cfg->{page}->{default} = undef; -$cfg->{status}->{showuser} = 1; -$cfg->{status}->{showversion} = 0; -$cfg->{status}->{showsid} = 0; +my $cfg = qq{ + ## + ## registry-ui.cfg - OpenPKG Registry User Interface Configuration + ## + + # user identification + # + identification { + mode constant; /* constant, naive, basicauth, ase */ + ase { + server "http://my.example.com/ase"; + }; + default anonymous; + }; + + # databases for registry and session + # + db { + registry { + username registry; + password registry; + tablespace registry; + host 127.0.0.1; + }; + session { + dbfile "$PREFIX/var/openpkg-registry/ui/session.db"; + }; + }; + + # canvas integration + # + canvas { + url ""; /* "http://my.example.com/canvas" */ + urlcache; + mark_head "<!-- CANVAS: HEAD -->"; + mark_body "<!-- CANVAS: BODY -->"; + }; + + # entry page + # + page { + default ""; /* "", dropxml, login, association, logout */ + }; + + ## status line + # + status { + showuser 1; + showversion 0; + showsid 0; + }; +}; +$cfg =~ s/^[ ]{4}//mg; +$cfg =~ s/^\n//s; + +sub readconfig ($) +{ + my ($cfgfile) = @_; + my $osspcfg = new OSSP::cfg::simple; + + die "no config file specified" unless (defined $cfgfile); + my $io = new IO::File "<$cfgfile"; + die "cannot open \"$cfgfile\" for reading ($!)" if(not defined $io); + my $txt = ''; $txt .= $_ while (<$io>); + $io->close(); + $osspcfg->parse($txt) || die "error parsing config file"; + $cfg = $osspcfg->unpack(-index => '.*', -strip => '.*', -flatten => 1) || die "error unpacking config file"; + return($cfg); +} +$cfg = &readconfig("$PREFIX/etc/openpkg-registry/registry-ui.cfg"); +#FIXME die Dumper($cfg); # currently default config is ignored and replaced by readconfig. They should merge. + +# outside CGI environment just print default config (useful during installation) +if ($ENV{GATEWAY_INTERFACE} !~ m/^CGI/) { + print $cfg; + exit 0; +} my $ase; $ase = undef; @@ -193,7 +248,7 @@ # establish ASE object # $ase = new OSSP::ase::client( - -server => "http://registry.openpkg.org/ase", + -server => $cfg->{identification}->{ase}->{server}, -cgi => $cgi, -mode => "page", -session => $session, @@ -1760,9 +1815,11 @@ my ($content_type, $expires, $content); undef $content; - ($content_type, $expires, $content) = &getcache($url) if ($cfg->{canvas}->{urlcache}); - ($content_type, $expires, $content) = &fetchurl($url) if (not defined $content); - &setcache($url, $content_type, $expires, $content) if (defined $content and $cfg->{canvas}->{urlcache}); + if ($url ne "") { + ($content_type, $expires, $content) = &getcache($url) if ($cfg->{canvas}->{urlcache}); + ($content_type, $expires, $content) = &fetchurl($url) if (not defined $content); + &setcache($url, $content_type, $expires, $content) if (defined $content and $cfg->{canvas}->{urlcache}); + } return $content_type, $expires, $content; } @@ . ______________________________________________________________________ The OpenPKG Project www.openpkg.org CVS Repository Commit List openpkg-cvs@openpkg.org