2008-12-03 14:27:30 +01:00
|
|
|
## @file
|
|
|
|
# Main portal for Lemonldap::NG portal
|
|
|
|
|
|
|
|
## @class
|
|
|
|
# Main portal for Lemonldap::NG portal
|
2006-12-18 12:32:33 +01:00
|
|
|
package Lemonldap::NG::Portal::SharedConf;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Lemonldap::NG::Portal::Simple qw(:all);
|
2009-12-11 22:17:06 +01:00
|
|
|
use Lemonldap::NG::Common::Conf; #link protected lmConf Configuration
|
2009-12-02 16:08:35 +01:00
|
|
|
use Lemonldap::NG::Common::Conf::Constants; #inherits
|
2012-08-09 20:42:40 +02:00
|
|
|
use Regexp::Assemble;
|
2014-08-19 12:05:15 +02:00
|
|
|
use URI::Split qw(uri_split);
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
*EXPORT_OK = *Lemonldap::NG::Portal::Simple::EXPORT_OK;
|
|
|
|
*EXPORT_TAGS = *Lemonldap::NG::Portal::Simple::EXPORT_TAGS;
|
|
|
|
*EXPORT = *Lemonldap::NG::Portal::Simple::EXPORT;
|
|
|
|
|
2016-03-03 21:25:16 +01:00
|
|
|
our $VERSION = '1.9.1';
|
2008-12-03 14:27:30 +01:00
|
|
|
use base qw(Lemonldap::NG::Portal::Simple);
|
2010-09-19 11:25:47 +02:00
|
|
|
our $confCached;
|
2006-12-18 12:32:33 +01:00
|
|
|
|
2010-10-30 21:25:38 +02:00
|
|
|
BEGIN {
|
|
|
|
eval {
|
|
|
|
require threads::shared;
|
|
|
|
threads::shared::share($confCached);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2007-01-11 07:42:57 +01:00
|
|
|
##################
|
2007-01-13 20:34:03 +01:00
|
|
|
# OVERLOADED SUB #
|
2007-01-11 07:42:57 +01:00
|
|
|
##################
|
|
|
|
|
2009-02-17 15:56:38 +01:00
|
|
|
## @method protected boolean getConf(hashRef args)
|
2008-12-26 18:58:48 +01:00
|
|
|
# Copy all parameters returned by the Lemonldap::NG::Common::Conf object in $self.
|
|
|
|
# @param args hash
|
2008-12-28 09:36:52 +01:00
|
|
|
# @return True
|
2006-12-18 12:32:33 +01:00
|
|
|
sub getConf {
|
|
|
|
my $self = shift;
|
2007-02-28 23:36:19 +01:00
|
|
|
my %args;
|
|
|
|
if ( ref( $_[0] ) ) {
|
|
|
|
%args = %{ $_[0] };
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
%args = @_;
|
|
|
|
}
|
2009-11-30 17:46:14 +01:00
|
|
|
|
2013-08-23 14:59:03 +02:00
|
|
|
if ( defined( $args{configStorage} ) ) {
|
|
|
|
$self->{configStorage} = $args{configStorage};
|
|
|
|
}
|
|
|
|
|
2013-10-22 14:02:44 +02:00
|
|
|
my $num;
|
|
|
|
my $lConf;
|
|
|
|
|
|
|
|
# If useLocalConf is set, just verify that current conf has the same number
|
|
|
|
# than local cache one
|
|
|
|
if ( $confCached and $confCached->{useLocalConf} ) {
|
|
|
|
$lConf = $self->__lmConf->getLocalConf(PORTALSECTION);
|
|
|
|
eval { $num = $lConf->{cfgNum} };
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$num = $self->__lmConf->lastCfg();
|
|
|
|
}
|
2011-02-03 15:49:12 +01:00
|
|
|
|
2011-12-05 15:21:24 +01:00
|
|
|
# Reload configuration
|
2010-09-19 11:25:47 +02:00
|
|
|
unless ( $confCached and $confCached->{cfgNum} == $num ) {
|
2013-10-22 14:02:44 +02:00
|
|
|
$lConf ||= $self->__lmConf->getLocalConf(PORTALSECTION);
|
|
|
|
my $prm = { cfgNum => $num };
|
|
|
|
if ( $args{useLocalConf} or $lConf->{useLocalConf} ) {
|
|
|
|
$prm->{local} = 1;
|
|
|
|
$self->lmLog( 'useLocalConf set to true', 'debug' );
|
|
|
|
}
|
|
|
|
my $gConf = $self->__lmConf->getConf($prm);
|
2011-07-07 17:08:45 +02:00
|
|
|
unless ( ref($gConf) and ref($lConf) ) {
|
|
|
|
$self->abort( "Cannot get configuration",
|
|
|
|
$Lemonldap::NG::Common::Conf::msg );
|
|
|
|
}
|
2013-10-22 14:02:44 +02:00
|
|
|
$self->lmLog(
|
|
|
|
"Cached configuration too old, get configuration $num "
|
|
|
|
. "($Lemonldap::NG::Common::Conf::msg)",
|
|
|
|
'debug'
|
|
|
|
);
|
2011-07-07 17:08:45 +02:00
|
|
|
%$confCached = ( %$gConf, %$lConf );
|
2012-08-09 20:42:40 +02:00
|
|
|
|
|
|
|
my $re = Regexp::Assemble->new();
|
2013-10-03 11:09:47 +02:00
|
|
|
foreach my $vhost ( keys %{ $confCached->{locationRules} } ) {
|
|
|
|
my $quotedVhost = quotemeta($vhost);
|
|
|
|
$self->lmLog( "Vhost $vhost added in reVHosts", 'debug' );
|
|
|
|
$re->add($quotedVhost);
|
|
|
|
|
|
|
|
# Add aliases
|
|
|
|
if ( $confCached->{vhostOptions}->{$vhost}->{vhostAliases} ) {
|
|
|
|
foreach my $alias ( split /\s+/,
|
|
|
|
$confCached->{vhostOptions}->{$vhost}->{vhostAliases} )
|
|
|
|
{
|
|
|
|
$self->lmLog( "Alias $alias added in reVHosts", 'debug' );
|
|
|
|
$re->add( quotemeta($alias) );
|
|
|
|
}
|
|
|
|
}
|
2012-08-09 20:42:40 +02:00
|
|
|
}
|
|
|
|
|
2014-08-19 12:05:15 +02:00
|
|
|
# Add portal vhost
|
|
|
|
my ( $portal_scheme, $portal_auth ) =
|
|
|
|
uri_split( $confCached->{portal} );
|
|
|
|
$re->add($portal_auth);
|
|
|
|
$self->lmLog( "Portal vhost $portal_auth added in reVHosts", 'debug' );
|
|
|
|
|
|
|
|
$confCached->{reVHosts} = $re->as_string;
|
2009-12-04 10:44:37 +01:00
|
|
|
}
|
2011-02-03 15:49:12 +01:00
|
|
|
|
2010-09-19 11:47:38 +02:00
|
|
|
%$self = ( %$self, %$confCached, %args, );
|
2011-02-03 15:49:12 +01:00
|
|
|
|
|
|
|
$self->lmLog( "Now using configuration: " . $confCached->{cfgNum},
|
|
|
|
'debug' );
|
|
|
|
|
2006-12-19 21:55:23 +01:00
|
|
|
1;
|
2006-12-18 12:32:33 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 11:25:47 +02:00
|
|
|
sub __lmConf {
|
2009-02-24 18:53:59 +01:00
|
|
|
my $self = shift;
|
2010-09-19 11:25:47 +02:00
|
|
|
return $self->{lmConf} if ( $self->{lmConf} );
|
|
|
|
my $r = Lemonldap::NG::Common::Conf->new( $self->{configStorage} );
|
|
|
|
$self->abort(
|
|
|
|
"Cannot create configuration object",
|
|
|
|
$Lemonldap::NG::Common::Conf::msg
|
|
|
|
) unless ( ref($r) );
|
|
|
|
$self->{lmConf} = $r;
|
2009-11-30 17:46:14 +01:00
|
|
|
}
|
|
|
|
|
2006-12-18 12:32:33 +01:00
|
|
|
1;
|
|
|
|
__END__
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2010-01-03 09:09:59 +01:00
|
|
|
=encoding utf8
|
|
|
|
|
2006-12-18 12:32:33 +01:00
|
|
|
Lemonldap::NG::Portal::SharedConf - Module for building Lemonldap::NG
|
|
|
|
compatible portals using a central configuration database.
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
2006-12-24 09:37:27 +01:00
|
|
|
use Lemonldap::NG::Portal::SharedConf;
|
|
|
|
my $portal = new Lemonldap::NG::Portal::SharedConf( {
|
|
|
|
configStorage => {
|
|
|
|
type => 'DBI',
|
|
|
|
dbiChain => "dbi:mysql:...",
|
|
|
|
dbiUser => "lemonldap",
|
|
|
|
dbiPassword => "password",
|
|
|
|
dbiTable => "lmConfig",
|
|
|
|
},
|
2008-12-07 21:07:52 +01:00
|
|
|
# Activate SOAP service
|
|
|
|
Soap => 1
|
2006-12-24 09:37:27 +01:00
|
|
|
} );
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
if($portal->process()) {
|
|
|
|
# Write here the menu with CGI methods. This page is displayed ONLY IF
|
|
|
|
# the user was not redirected here.
|
2013-10-17 21:21:45 +02:00
|
|
|
print $portal->header('text/html; charset=utf-8'); # DON'T FORGET THIS (see L<CGI(3)>)
|
2006-12-18 12:32:33 +01:00
|
|
|
print "...";
|
|
|
|
|
|
|
|
# or redirect the user to the menu
|
|
|
|
print $portal->redirect( -uri => 'https://portal/menu');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
# Write here the html form used to authenticate with CGI methods.
|
|
|
|
# $portal->error returns the error message if athentification failed
|
|
|
|
# Warning: by defaut, input names are "user" and "password"
|
2013-10-17 21:21:45 +02:00
|
|
|
print $portal->header('text/html; charset=utf-8'); # DON'T FORGET THIS (see L<CGI(3)>)
|
2006-12-18 12:32:33 +01:00
|
|
|
print "...";
|
|
|
|
print '<form method="POST">';
|
|
|
|
# In your form, the following value is required for redirection
|
|
|
|
print '<input type="hidden" name="url" value="'.$portal->param('url').'">';
|
|
|
|
# Next, login and password
|
|
|
|
print 'Login : <input name="user"><br>';
|
2015-06-11 14:59:20 +02:00
|
|
|
print 'Password : <input name="password" type="password">';
|
2006-12-18 12:32:33 +01:00
|
|
|
print '<input type="submit" value="go" />';
|
|
|
|
print '</form>';
|
|
|
|
}
|
|
|
|
|
2008-12-07 21:07:52 +01:00
|
|
|
SOAP mode authentication (client) :
|
|
|
|
|
|
|
|
#!/usr/bin/perl -l
|
|
|
|
|
|
|
|
use SOAP::Lite;
|
|
|
|
use Data::Dumper;
|
|
|
|
|
|
|
|
my $soap =
|
|
|
|
SOAP::Lite->proxy('http://auth.example.com/')
|
2009-02-05 18:05:18 +01:00
|
|
|
->uri('urn:/Lemonldap::NG::Common::::CGI::SOAPService');
|
2008-12-07 21:07:52 +01:00
|
|
|
my $r = $soap->getCookies( 'user', 'password' );
|
|
|
|
|
|
|
|
# Catch SOAP errors
|
|
|
|
if ( $r->fault ) {
|
|
|
|
print STDERR "SOAP Error: " . $r->fault->{faultstring};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
my $res = $r->result();
|
|
|
|
|
|
|
|
# If authentication failed, display error
|
|
|
|
if ( $res->{error} ) {
|
2012-02-15 12:58:32 +01:00
|
|
|
print STDERR "Error: " . $soap->error( $res->{error} )->result();
|
2008-12-07 21:07:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# print session-ID
|
|
|
|
else {
|
|
|
|
print "Cookie: lemonldap=" . $res->{cookies}->{lemonldap};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-18 12:32:33 +01:00
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
Lemonldap::NG::Portal::SharedConf is the base module for building Lemonldap::NG
|
|
|
|
compatible portals using a central database configuration. You have to use by
|
|
|
|
inheritance.
|
|
|
|
|
2006-12-24 09:37:27 +01:00
|
|
|
See L<Lemonldap::NG::Portal::SharedConf> for a complete example.
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
=head1 METHODS
|
|
|
|
|
|
|
|
Same as L<Lemonldap::NG::Portal::Simple>, but Lemonldap::NG::Portal::SharedConf
|
|
|
|
adds a new sub:
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item * scanexpr: used by setGroups to read combined LDAP and Perl expressions.
|
|
|
|
See L<Lemonldap::NG::Portal> for more.
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
=head3 Args
|
|
|
|
|
|
|
|
Lemonldap::NG::Portal::SharedConf use the same arguments than
|
|
|
|
L<Lemonldap::NG::Portal::Simple>, but you can set them either using local
|
|
|
|
variables passed to C<new()> or using variables issued from the database.
|
|
|
|
|
|
|
|
=head2 EXPORT
|
|
|
|
|
|
|
|
=head3 Constants
|
|
|
|
|
|
|
|
Same as L<Lemonldap::NG::Portal::Simple>.
|
|
|
|
|
|
|
|
=head1 SEE ALSO
|
|
|
|
|
2006-12-24 09:37:27 +01:00
|
|
|
L<Lemonldap::NG::Portal>, L<Lemonldap::NG::Portal::SharedConf>,
|
2007-04-02 21:13:05 +02:00
|
|
|
L<Lemonldap::NG::Handler>, L<Lemonldap::NG::Manager>,
|
2010-10-26 08:08:16 +02:00
|
|
|
L<http://lemonldap-ng.org/>
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
2013-01-31 06:33:10 +01:00
|
|
|
=over
|
|
|
|
|
|
|
|
=item Clement Oudot, E<lt>clem.oudot@gmail.comE<gt>
|
|
|
|
|
2013-10-19 18:34:20 +02:00
|
|
|
=item François-Xavier Deltombe, E<lt>fxdeltombe@gmail.com.E<gt>
|
2013-01-31 06:33:10 +01:00
|
|
|
|
|
|
|
=item Xavier Guimard, E<lt>x.guimard@free.frE<gt>
|
|
|
|
|
|
|
|
=back
|
2006-12-18 12:32:33 +01:00
|
|
|
|
2007-04-14 15:12:11 +02:00
|
|
|
=head1 BUG REPORT
|
|
|
|
|
|
|
|
Use OW2 system to report bug or ask for features:
|
2010-10-26 08:08:16 +02:00
|
|
|
L<http://jira.ow2.org>
|
2007-04-14 15:12:11 +02:00
|
|
|
|
|
|
|
=head1 DOWNLOAD
|
|
|
|
|
|
|
|
Lemonldap::NG is available at
|
|
|
|
L<http://forge.objectweb.org/project/showfiles.php?group_id=274>
|
|
|
|
|
2006-12-18 12:32:33 +01:00
|
|
|
=head1 COPYRIGHT AND LICENSE
|
|
|
|
|
2013-01-31 06:33:10 +01:00
|
|
|
=over
|
|
|
|
|
2016-01-21 22:15:19 +01:00
|
|
|
=item Copyright (C) 2005-2015 by Xavier Guimard, E<lt>x.guimard@free.frE<gt>
|
2013-01-31 06:33:10 +01:00
|
|
|
|
2013-10-19 18:34:20 +02:00
|
|
|
=item Copyright (C) 2012 by François-Xavier Deltombe, E<lt>fxdeltombe@gmail.com.E<gt>
|
2013-01-31 06:33:10 +01:00
|
|
|
|
2016-01-21 22:15:19 +01:00
|
|
|
=item Copyright (C) 2006-2015 by Clement Oudot, E<lt>clem.oudot@gmail.comE<gt>
|
2013-01-31 06:33:10 +01:00
|
|
|
|
|
|
|
=back
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify
|
2013-01-31 06:33:10 +01:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see L<http://www.gnu.org/licenses/>.
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
=cut
|