lemonldap-ng/modules/lemonldap-ng-handler/example/menu.pl
2008-08-22 15:21:39 +00:00

67 lines
1.7 KiB
Perl

#!/usr/bin/perl -w
# Example of menu
# This program is an auto-protected CGI that reads a HTML file and replace
# tagged links :
# * by links if the connected user is authorized to access to this site
# * by italic text else
#
# The tagged links have to be written so :
# [[http://my-protected-site/welcome Comment to display in the link]]
# Set here the path to the HTML file to read
my $html_file = '/path/to/html/template';
# DEBIAN Users : uncomment this
# require "/usr/share/lemonldap-ng/configStorage.pm";
use Lemonldap::NG::Handler::CGI;
use strict;
# Initialization
our $cgi;
$cgi = Lemonldap::NG::Handler::CGI->new(
{
localStorage => "Cache::FileCache",
localStorageOptions => {
'namespace' => 'MyNamespace',
'default_expires_in' => 600,
'directory_umask' => '007',
'cache_root' => '/tmp',
'cache_depth' => 5,
},
# DEBIAN USERS : use this instead of classic configStorage
#configStorage => $Lemonldap::NG::Conf::configStorage,
configStorage => {
type => 'File',
dirName => '__CONFDIR__',
},
https => 0,
}
) or die;
# Authentication
$cgi->authenticate();
open F, $html_file or die "Template \"$html_file\" not found !";
# HTTP Headers
print $cgi->header(
-type => 'text/html',
-charset => 'ISO-8859-1',
);
while(<F>) {
#print "TOTO" if(m#[[(https?://\S+)\s+(.*?)]]#);
s#\[\[(https?://\S+)\s+(.*?)\]\]#&link($1,$2)#eg;
print;
}
close F;
sub link {
my($l,$t)=@_;
return ( $cgi->testUri($l) ? "<a href=\"$l\">$t</a>" : "<i>$t</i>" );
}