lemonldap-ng/modules/lemonldap-ng-portal/example/index_skin.pl

286 lines
9.7 KiB
Perl
Raw Normal View History

2008-05-10 20:05:46 +02:00
#!/usr/bin/perl
use Lemonldap::NG::Portal::SharedConf;
use HTML::Template;
use strict;
2008-05-10 20:05:46 +02:00
my $portal = Lemonldap::NG::Portal::SharedConf->new(
{
# ACCESS TO CONFIGURATION
# By default, Lemonldap::NG uses the default lemonldap-ng.ini file to
# know where to find its configuration
2009-12-04 10:59:21 +01:00
# (generaly /etc/lemonldap-ng/lemonldap-ng.ini)
# You can specify by yourself this file :
#configStorage => { confFile => '/path/to/my/file' },
# or set explicitely parameters :
#configStorage => {
2009-12-04 10:59:21 +01:00
# type => 'File',
# dirName => '/usr/local/lemonldap-ng/data//conf'
#},
# Note that YOU HAVE TO SET configStorage here if you've declared this
# portal as SOAP configuration server in the manager
# OTHERS
# You can also overload any parameter issued from manager
# configuration. Example:
#globalStorage => 'Apache::Session::File',
#globalStorageOptions => {
# 'Directory' => '/var/lib/lemonldap-ng/sessions/',
# 'LockDirectory' => '/var/lib/lemonldap-ng/sessions/lock/',
#},
# Note that YOU HAVE TO SET globalStorage here if you've declared this
# portal as SOAP session server in the manager
2008-05-10 20:05:46 +02:00
}
);
# Get skin value
2010-03-20 18:14:28 +01:00
my $skin = $portal->{portalSkin};
2010-02-11 09:31:23 +01:00
my $skin_dir = $ENV{DOCUMENT_ROOT} . "/skins";
2010-01-13 13:19:55 +01:00
my ( $skinfile, %templateParams );
2010-01-13 13:46:19 +01:00
####################
# QUERY PROCESSING #
####################
# I - GOOD AUTHENTICATION
2008-05-10 20:05:46 +02:00
if ( $portal->process() ) {
2010-01-12 12:05:01 +01:00
# 1.1 Image mode
if ( $portal->{error} == PE_IMG_OK || $portal->{error} == PE_IMG_NOK ) {
2010-05-12 06:04:10 +02:00
$skinfile = "$skin_dir/common/"
. (
$portal->{error} == PE_IMG_OK
? 'ok.png'
: 'warning.png'
);
$portal->printImage( $skinfile, 'image/png' );
exit;
}
# 1.2 Case : there is a message to display
elsif ( my $info = $portal->info() ) {
2010-01-13 13:19:55 +01:00
$skinfile = 'info.tpl';
%templateParams = (
AUTH_ERROR_TYPE => $portal->error_type,
MSG => $info,
SKIN => $skin,
URL => $portal->{urldc},
HIDDEN_INPUTS => $portal->buildHiddenForm(),
2010-08-18 17:10:30 +02:00
ACTIVE_TIMER => $portal->{activeTimer},
FORM_METHOD => $portal->{infoFormMethod},
);
}
2008-05-10 20:05:46 +02:00
# 1.3 Case : display menu
2010-01-13 13:19:55 +01:00
else {
$skinfile = 'menu.tpl';
# Menu creation
use Lemonldap::NG::Portal::Menu;
my $menu = Lemonldap::NG::Portal::Menu->new(
{
portalObject => $portal,
2010-03-20 18:14:28 +01:00
modules => {
appslist => $portal->{portalDisplayAppslist},
password => $portal->{portalDisplayChangePassword},
logout => $portal->{portalDisplayLogout},
},
}
);
2010-01-13 13:19:55 +01:00
%templateParams = (
AUTH_USER => $portal->{sessionInfo}->{ $portal->{portalUserAttr} },
AUTOCOMPLETE => $portal->{portalAutocomplete},
SKIN => $skin,
AUTH_ERROR => $portal->error,
AUTH_ERROR_TYPE => $portal->error_type,
2010-01-13 13:19:55 +01:00
DISPLAY_APPSLIST => $menu->displayModule("appslist"),
DISPLAY_PASSWORD => $menu->displayModule("password"),
DISPLAY_LOGOUT => $menu->displayModule("logout"),
DISPLAY_TAB => $menu->displayTab,
LOGOUT_URL => "$ENV{SCRIPT_NAME}?logout=1",
REQUIRE_OLDPASSWORD => $portal->{portalRequireOldPassword},
);
if ( $menu->displayModule("appslist") ) {
%templateParams = (
%templateParams,
2010-03-20 18:14:28 +01:00
APPSLIST_MENU => $menu->appslistMenu,
APPSLIST_DESC => $menu->appslistDescription
);
}
}
}
2010-01-13 13:46:19 +01:00
# II - USER NOT AUTHENTICATED
# 2.1 A notification has to be done (session is created but hidden and unusable
# until the user has accept the message)
2009-04-07 11:27:23 +02:00
elsif ( my $notif = $portal->notification ) {
2010-01-13 13:19:55 +01:00
$skinfile = 'notification.tpl';
%templateParams = (
AUTH_ERROR_TYPE => $portal->error_type,
NOTIFICATION => $notif,
SKIN => $skin,
HIDDEN_INPUTS => $portal->buildHiddenForm(),
);
}
2010-01-13 13:46:19 +01:00
# 2.2 An authentication (or userDB) module needs to ask a question
# before processing to the request
2010-01-12 12:05:01 +01:00
elsif ( $portal->{error} == PE_CONFIRM ) {
2010-01-13 13:19:55 +01:00
$skinfile = 'confirm.tpl';
%templateParams = (
AUTH_ERROR => $portal->error,
AUTH_ERROR_TYPE => $portal->error_type,
2010-09-01 10:11:34 +02:00
URL => $portal->get_url,
2010-01-13 13:19:55 +01:00
MSG => $portal->info(),
SKIN => $skin,
HIDDEN_INPUTS => $portal->buildHiddenForm(),
2010-08-18 17:10:30 +02:00
ACTIVE_TIMER => $portal->{activeTimer},
FORM_METHOD => $portal->{confirmFormMethod},
2010-01-12 12:05:01 +01:00
);
}
2010-01-13 13:46:19 +01:00
# 2.3 There is a message to display
elsif ( my $info = $portal->info() ) {
$skinfile = 'info.tpl';
%templateParams = (
AUTH_ERROR => $portal->error,
AUTH_ERROR_TYPE => $portal->error_type,
MSG => $info,
SKIN => $skin,
URL => $portal->{urldc},
HIDDEN_INPUTS => $portal->buildHiddenForm(),
2010-08-18 17:10:30 +02:00
ACTIVE_TIMER => $portal->{activeTimer},
FORM_METHOD => $portal->{infoFormMethod},
);
}
2010-08-27 17:34:03 +02:00
# 2.4 OpenID menu page
2010-09-01 14:56:15 +02:00
elsif ($portal->{error} == PE_OPENID_EMPTY
or $portal->{error} == PE_OPENID_BADID )
{
$skinfile = 'openid.tpl';
my $p = $portal->{portal} . $portal->{issuerDBOpenIDPath};
2010-08-27 17:34:03 +02:00
$p =~ s#(?<!:)/\^?/#/#g;
%templateParams = (
2010-09-01 14:56:15 +02:00
AUTH_ERROR => $portal->error,
AUTH_ERROR_TYPE => $portal->error_type,
2010-08-27 17:34:03 +02:00
SKIN => $skin,
2010-09-01 14:56:15 +02:00
PROVIDERURI => $p,
ID => $portal->{_openidPortal}
. $portal->{sessionInfo}
->{ $portal->{OpenIdAttr} || $portal->{whatToTrace} }
2010-08-27 17:34:03 +02:00
);
}
# 2.5 Authentication has been refused OR this is the first access
else {
2010-01-13 13:19:55 +01:00
$skinfile = 'login.tpl';
%templateParams = (
AUTH_ERROR => $portal->error,
AUTH_ERROR_TYPE => $portal->error_type,
AUTH_URL => $portal->get_url,
LOGIN => $portal->get_user,
AUTOCOMPLETE => $portal->{portalAutocomplete},
SKIN => $skin,
DISPLAY_RESETPASSWORD => $portal->{portalDisplayResetPassword},
DISPLAY_FORM => 1,
MAIL_URL => $portal->{mailUrl},
HIDDEN_INPUTS => $portal->buildHiddenForm(),
LOGIN_INFO => $portal->loginInfo(),
);
# Authentication loop
if ( $portal->{authLoop} ) {
%templateParams = (
%templateParams,
AUTH_LOOP => $portal->{authLoop},
CHOICE_PARAM => $portal->{authChoiceParam},
);
}
2010-03-20 18:14:28 +01:00
# Adapt template if password policy error
if (
2010-03-20 18:14:28 +01:00
$portal->{portalDisplayChangePassword}
and ( $portal->{error} == PE_PP_CHANGE_AFTER_RESET
2010-03-20 18:14:28 +01:00
or $portal->{error} == PE_PP_MUST_SUPPLY_OLD_PASSWORD
or $portal->{error} == PE_PP_INSUFFICIENT_PASSWORD_QUALITY
or $portal->{error} == PE_PP_PASSWORD_TOO_SHORT
or $portal->{error} == PE_PP_PASSWORD_TOO_YOUNG
or $portal->{error} == PE_PP_PASSWORD_IN_HISTORY
or $portal->{error} == PE_PASSWORD_MISMATCH
or $portal->{error} == PE_BADOLDPASSWORD )
)
{
%templateParams = (
%templateParams,
2010-03-20 18:14:28 +01:00
REQUIRE_OLDPASSWORD => 1,
DISPLAY_PASSWORD => 1,
DISPLAY_RESETPASSWORD => 0,
DISPLAY_FORM => 0
);
}
2010-03-15 11:44:16 +01:00
# Adapt template for OpenID
if ( $portal->get_module("auth") =~ /openid/i ) {
%templateParams = (
%templateParams,
DISPLAY_RESETPASSWORD => 0,
DISPLAY_FORM => 0,
DISPLAY_OPENID_FORM => 1,
);
}
2010-03-20 18:14:28 +01:00
# Adapt template if external authentication error
2010-02-18 18:22:04 +01:00
# or logout is OK
if ( $portal->{error} == PE_BADCERTIFICATE
2010-03-20 18:14:28 +01:00
or $portal->{error} == PE_CERTIFICATEREQUIRED
2010-02-18 18:22:04 +01:00
or $portal->{error} == PE_ERROR
2010-07-05 17:38:02 +02:00
or $portal->{error} == PE_SAML_ERROR
or $portal->{error} == PE_SAML_LOAD_SERVICE_ERROR
or $portal->{error} == PE_SAML_LOAD_IDP_ERROR
or $portal->{error} == PE_SAML_SSO_ERROR
or $portal->{error} == PE_SAML_UNKNOWN_ENTITY
or $portal->{error} == PE_SAML_DESTINATION_ERROR
or $portal->{error} == PE_SAML_CONDITIONS_ERROR
or $portal->{error} == PE_SAML_IDPSSOINITIATED_NOTALLOWED
or $portal->{error} == PE_SAML_SLO_ERROR
or $portal->{error} == PE_SAML_SIGNATURE_ERROR
or $portal->{error} == PE_SAML_ART_ERROR
or $portal->{error} == PE_SAML_SESSION_ERROR
or $portal->{error} == PE_SAML_LOAD_SP_ERROR
or $portal->{error} == PE_SAML_ATTR_ERROR
2010-02-18 18:22:04 +01:00
or $portal->{error} == PE_LOGOUT_OK )
{
%templateParams = (
%templateParams,
2010-03-20 18:14:28 +01:00
DISPLAY_RESETPASSWORD => 0,
DISPLAY_FORM => 0,
2010-03-15 11:44:16 +01:00
DISPLAY_OPENID_FORM => 0,
2010-02-18 18:22:04 +01:00
PORTAL_URL => $portal->{portal},
2010-04-27 17:11:53 +02:00
MSG => $portal->info(),
2010-03-20 18:14:28 +01:00
);
}
2010-01-13 13:19:55 +01:00
}
2010-01-13 13:46:19 +01:00
# HTML template creation
2010-01-13 13:19:55 +01:00
my $template = HTML::Template->new(
filename => "$skin_dir/$skin/$skinfile",
die_on_bad_params => 0,
cache => 0,
filter => sub { $portal->translate_template(@_) }
);
2010-01-13 13:46:19 +01:00
# Give parameters to the template
2010-01-13 13:19:55 +01:00
while ( my ( $k, $v ) = each %templateParams ) {
$template->param( $k, $v );
2008-05-10 20:05:46 +02:00
}
2010-01-13 13:46:19 +01:00
# Display it
2010-01-13 13:19:55 +01:00
print $portal->header('text/html; charset=utf-8');
print $template->output;