#!/usr/bin/perl package Apache::TWikiAuthen; use strict; BEGIN{ unshift @INC, "/usr/local/apache/htdocs/dakar/bin"; unshift @INC, "/usr/local/apache/htdocs/dakar/lib"; unshift @INC, "/usr/local/apache/htdocs/dakar/lib/CPAN/lib"; require 'setlib.cfg'; require 'LocalSite.cfg'; }; use CGI::Carp qw(fatalsToBrowser); use CGI; use TWiki; use CGI::Session; sub handler { my $r = shift; my $noguest = $r->dir_config("Access"); return "DECLINED" unless defined $noguest; ## Decline if "Access NoGuest/guest..." is not defined return "OK" if lc($noguest) eq 'guest'; ## Want to allow access to everyone my $filepath = $r->filename; ### exact path of the file ## Catch the cookie detals and get the username from cookie. my $sessdetails = $r->header_in("Cookie"); my ($TWIKISID, $sid) = split /=/, $sessdetails; my $session = CGI::Session->load($sid); my $wikiuser = $session->param('AUTHUSER'); if (defined($wikiuser)) {; } else {$wikiuser = "TWikiGuest";} my $query = new CGI(); $TWiki::Plugins::SESSION = new TWiki($wikiuser, $query); ## Constrct the wiki instance my $pubdir = $r->dir_config("pubdir"); ## get the pubdir from .htaccess file my $oopstemplate = $r->dir_config("oopstemplate"); ### get the opps templatename from .htaccess file $filepath =~ s/$pubdir//g; ## remove till pub including pub my ($web, $topic, $filename) = split /\//, $filepath; ## Web/Topic/Filename my $access = TWiki::Func::checkAccessPermission("VIEW", "Main.".$wikiuser, $topic, $web); if ($access) { return "OK"; } else { my $url = TWiki::Func::getOopsUrl($web, $topic, $oopstemplate, "Dont Try"); TWiki::Func::redirectCgiQuery(undef, $url); return "OK"; } return "OK"; } 1;