%# $Id: layout.mc,v 1.25 2008-04-02 12:51:46 mike Exp $ <%args> $debug => undef $title $component <%once> use Encode; use URI::Escape qw(uri_escape_utf8 uri_unescape); use HTML::Entities; use Keystone::Resolver::Admin; use Keystone::Resolver::Utils qw(encode_hash decode_hash utf8param); <%perl> $r->content_type("text/html; charset=utf-8"); my $admin = Keystone::Resolver::Admin->admin(); my $host = $ENV{HTTP_HOST}; # Or we could use SERVER_NAME my $tag = $admin->hostname2tag($host); my $site; eval { $site = $admin->site($tag); }; if ($@) { print <<__EOT__; It was not possible to connect to the Keystone Resolver database.
Please see /usr/share/libkeystone-resolver-perl/db/README

Detailed error message follows, but you can probably ignore it:
$@
__EOT__ return; } if (!defined $site) { print <<__EOT__; Unknown Keystone Resolver site '$tag' (host $host)
Please see /usr/share/libkeystone-resolver-perl/db/README.sites
__EOT__ return; } $m->notes(site => $site); # Totally chiropteral-excrementally crazy ... you have to use a # different cookie API depending on whether you're running under # Apache 1.x or 2.x. And the fetch() and bake() methods in Apache 2 # have different parameters from the same methods in Apache 1. # Thanks, Apache guys! I'm sure you know best! # my $cookiePackage; my $api = $ENV{MOD_PERL_API_VERSION}; if ($api && $api == 2) { $cookiePackage = "Apache2::Cookie"; } else { $cookiePackage = "Apache::Cookie"; } my $cookieModule = $cookiePackage; $cookieModule =~ s/::/\//g; require "$cookieModule.pm"; my $cookies = $cookiePackage->fetch($cookiePackage eq 'Apache2::Cookie' ? $r : ()); my $cookie = $cookies->{session}; #warn "cookieModule=[$cookieModule], cookies=[$cookies], cookie=[$cookie]"; my $session = undef; my $user = undef; if (defined $cookie) { my $cval = $cookie->value(); $session = $site->session1(cookie => $cval); if (!defined $session) { # Old cookie for a session that's no longer around. We just # delete the cookie, silently logging the user out if he was # logged in. $site->log(1, "expiring old session $cval"); my $cookie = new $cookiePackage($r, -name => "session", -value => $cval, -expires => '-1d'); $cookie->bake($cookiePackage eq 'Apache2::Cookie' ? $r : ()); } } if (!defined $session) { $session = $site->create_session(); my $cookie = new $cookiePackage($r, -name => "session", -value => $session->cookie()); $cookie->bake($cookiePackage eq 'Apache2::Cookie' ? $r : ()); } $m->notes(session => $session); my $uid = $session->user_id(); if ($uid) { $user = $site->user1(id => $uid); die "Invalid user-ID '$uid'" if !defined $user; $m->notes(user => $user); } # Generate the text of the client area before emitting the framework: # this allows it to affect the state, so that for example a login or # logout $component can set or unset $user. my $text; eval { $text = $m->scomp($component, %ARGS); }; if ($@ && (!ref $@ || $@->isa("HTML::Mason::Exception")) && $@ =~ /Unknown column/) { print <<__EOT__; A column was missing from a table in the Keystone Resolver database.
This probably means that the structure of your database is out of date
Please see /usr/share/libkeystone-resolver-perl/db/README.update

Detailed error message follows, but you can probably ignore it:
$@
__EOT__ return; } elsif ($@) { die $@; } $user = $m->notes("user"); Keystone Resolver: <% encode_entities($title) %> % $m->comp("/mc/debug/cookies.mc", cookies => $cookies) if $debug;

Keystone Resolver: <% $title %>

% if ($user) {
<% encode_entities($user->name()) %> | Details | Password
Logout
% } else {
Login or Register
% }
<% $text %>
Index Data