line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
## @file |
2
|
|
|
|
|
|
|
# Main portal for Lemonldap::NG portal |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
## @class |
5
|
|
|
|
|
|
|
# Main portal for Lemonldap::NG portal |
6
|
|
|
|
|
|
|
package Lemonldap::NG::Portal::SharedConf; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
22896
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
71
|
|
9
|
2
|
|
|
2
|
|
1260
|
use Lemonldap::NG::Portal::Simple qw(:all); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Lemonldap::NG::Common::Conf; #link protected lmConf Configuration |
11
|
|
|
|
|
|
|
use Lemonldap::NG::Common::Conf::Constants; #inherits |
12
|
|
|
|
|
|
|
use Regexp::Assemble; |
13
|
|
|
|
|
|
|
use URI::Split qw(uri_split); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
*EXPORT_OK = *Lemonldap::NG::Portal::Simple::EXPORT_OK; |
16
|
|
|
|
|
|
|
*EXPORT_TAGS = *Lemonldap::NG::Portal::Simple::EXPORT_TAGS; |
17
|
|
|
|
|
|
|
*EXPORT = *Lemonldap::NG::Portal::Simple::EXPORT; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '1.4.2'; |
20
|
|
|
|
|
|
|
use base qw(Lemonldap::NG::Portal::Simple); |
21
|
|
|
|
|
|
|
our $confCached; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
BEGIN { |
24
|
|
|
|
|
|
|
eval { |
25
|
|
|
|
|
|
|
require threads::shared; |
26
|
|
|
|
|
|
|
threads::shared::share($confCached); |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
################## |
31
|
|
|
|
|
|
|
# OVERLOADED SUB # |
32
|
|
|
|
|
|
|
################## |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
## @method protected boolean getConf(hashRef args) |
35
|
|
|
|
|
|
|
# Copy all parameters returned by the Lemonldap::NG::Common::Conf object in $self. |
36
|
|
|
|
|
|
|
# @param args hash |
37
|
|
|
|
|
|
|
# @return True |
38
|
|
|
|
|
|
|
sub getConf { |
39
|
|
|
|
|
|
|
my $self = shift; |
40
|
|
|
|
|
|
|
my %args; |
41
|
|
|
|
|
|
|
if ( ref( $_[0] ) ) { |
42
|
|
|
|
|
|
|
%args = %{ $_[0] }; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
|
|
|
|
|
|
%args = @_; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
if ( defined( $args{configStorage} ) ) { |
49
|
|
|
|
|
|
|
$self->{configStorage} = $args{configStorage}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $num; |
53
|
|
|
|
|
|
|
my $lConf; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# If useLocalConf is set, just verify that current conf has the same number |
56
|
|
|
|
|
|
|
# than local cache one |
57
|
|
|
|
|
|
|
if ( $confCached and $confCached->{useLocalConf} ) { |
58
|
|
|
|
|
|
|
$lConf = $self->__lmConf->getLocalConf(PORTALSECTION); |
59
|
|
|
|
|
|
|
eval { $num = $lConf->{cfgNum} }; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
|
|
|
|
|
|
$num = $self->__lmConf->lastCfg(); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Reload configuration |
66
|
|
|
|
|
|
|
unless ( $confCached and $confCached->{cfgNum} == $num ) { |
67
|
|
|
|
|
|
|
$lConf ||= $self->__lmConf->getLocalConf(PORTALSECTION); |
68
|
|
|
|
|
|
|
my $prm = { cfgNum => $num }; |
69
|
|
|
|
|
|
|
if ( $args{useLocalConf} or $lConf->{useLocalConf} ) { |
70
|
|
|
|
|
|
|
$prm->{local} = 1; |
71
|
|
|
|
|
|
|
$self->lmLog( 'useLocalConf set to true', 'debug' ); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
my $gConf = $self->__lmConf->getConf($prm); |
74
|
|
|
|
|
|
|
unless ( ref($gConf) and ref($lConf) ) { |
75
|
|
|
|
|
|
|
$self->abort( "Cannot get configuration", |
76
|
|
|
|
|
|
|
$Lemonldap::NG::Common::Conf::msg ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
$self->lmLog( |
79
|
|
|
|
|
|
|
"Cached configuration too old, get configuration $num " |
80
|
|
|
|
|
|
|
. "($Lemonldap::NG::Common::Conf::msg)", |
81
|
|
|
|
|
|
|
'debug' |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
%$confCached = ( %$gConf, %$lConf ); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $re = Regexp::Assemble->new(); |
86
|
|
|
|
|
|
|
foreach my $vhost ( keys %{ $confCached->{locationRules} } ) { |
87
|
|
|
|
|
|
|
my $quotedVhost = quotemeta($vhost); |
88
|
|
|
|
|
|
|
$self->lmLog( "Vhost $vhost added in reVHosts", 'debug' ); |
89
|
|
|
|
|
|
|
$re->add($quotedVhost); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# Add aliases |
92
|
|
|
|
|
|
|
if ( $confCached->{vhostOptions}->{$vhost}->{vhostAliases} ) { |
93
|
|
|
|
|
|
|
foreach my $alias ( split /\s+/, |
94
|
|
|
|
|
|
|
$confCached->{vhostOptions}->{$vhost}->{vhostAliases} ) |
95
|
|
|
|
|
|
|
{ |
96
|
|
|
|
|
|
|
$self->lmLog( "Alias $alias added in reVHosts", 'debug' ); |
97
|
|
|
|
|
|
|
$re->add( quotemeta($alias) ); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Add portal vhost |
103
|
|
|
|
|
|
|
my ( $portal_scheme, $portal_auth ) = |
104
|
|
|
|
|
|
|
uri_split( $confCached->{portal} ); |
105
|
|
|
|
|
|
|
$re->add($portal_auth); |
106
|
|
|
|
|
|
|
$self->lmLog( "Portal vhost $portal_auth added in reVHosts", 'debug' ); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$confCached->{reVHosts} = $re->as_string; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
%$self = ( %$self, %$confCached, %args, ); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
$self->lmLog( "Now using configuration: " . $confCached->{cfgNum}, |
114
|
|
|
|
|
|
|
'debug' ); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub __lmConf { |
120
|
|
|
|
|
|
|
my $self = shift; |
121
|
|
|
|
|
|
|
return $self->{lmConf} if ( $self->{lmConf} ); |
122
|
|
|
|
|
|
|
my $r = Lemonldap::NG::Common::Conf->new( $self->{configStorage} ); |
123
|
|
|
|
|
|
|
$self->abort( |
124
|
|
|
|
|
|
|
"Cannot create configuration object", |
125
|
|
|
|
|
|
|
$Lemonldap::NG::Common::Conf::msg |
126
|
|
|
|
|
|
|
) unless ( ref($r) ); |
127
|
|
|
|
|
|
|
$self->{lmConf} = $r; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
__END__ |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 NAME |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=encoding utf8 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Lemonldap::NG::Portal::SharedConf - Module for building Lemonldap::NG |
138
|
|
|
|
|
|
|
compatible portals using a central configuration database. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 SYNOPSIS |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
use Lemonldap::NG::Portal::SharedConf; |
143
|
|
|
|
|
|
|
my $portal = new Lemonldap::NG::Portal::SharedConf( { |
144
|
|
|
|
|
|
|
configStorage => { |
145
|
|
|
|
|
|
|
type => 'DBI', |
146
|
|
|
|
|
|
|
dbiChain => "dbi:mysql:...", |
147
|
|
|
|
|
|
|
dbiUser => "lemonldap", |
148
|
|
|
|
|
|
|
dbiPassword => "password", |
149
|
|
|
|
|
|
|
dbiTable => "lmConfig", |
150
|
|
|
|
|
|
|
}, |
151
|
|
|
|
|
|
|
# Activate SOAP service |
152
|
|
|
|
|
|
|
Soap => 1 |
153
|
|
|
|
|
|
|
} ); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
if($portal->process()) { |
156
|
|
|
|
|
|
|
# Write here the menu with CGI methods. This page is displayed ONLY IF |
157
|
|
|
|
|
|
|
# the user was not redirected here. |
158
|
|
|
|
|
|
|
print $portal->header('text/html; charset=utf-8'); # DON'T FORGET THIS (see L<CGI(3)>) |
159
|
|
|
|
|
|
|
print "..."; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# or redirect the user to the menu |
162
|
|
|
|
|
|
|
print $portal->redirect( -uri => 'https://portal/menu'); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
else { |
165
|
|
|
|
|
|
|
# Write here the html form used to authenticate with CGI methods. |
166
|
|
|
|
|
|
|
# $portal->error returns the error message if athentification failed |
167
|
|
|
|
|
|
|
# Warning: by defaut, input names are "user" and "password" |
168
|
|
|
|
|
|
|
print $portal->header('text/html; charset=utf-8'); # DON'T FORGET THIS (see L<CGI(3)>) |
169
|
|
|
|
|
|
|
print "..."; |
170
|
|
|
|
|
|
|
print '<form method="POST">'; |
171
|
|
|
|
|
|
|
# In your form, the following value is required for redirection |
172
|
|
|
|
|
|
|
print '<input type="hidden" name="url" value="'.$portal->param('url').'">'; |
173
|
|
|
|
|
|
|
# Next, login and password |
174
|
|
|
|
|
|
|
print 'Login : <input name="user"><br>'; |
175
|
|
|
|
|
|
|
print 'Password : <input name="password" type="password" autocomplete="off">'; |
176
|
|
|
|
|
|
|
print '<input type="submit" value="go" />'; |
177
|
|
|
|
|
|
|
print '</form>'; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
SOAP mode authentication (client) : |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
#!/usr/bin/perl -l |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
use SOAP::Lite; |
185
|
|
|
|
|
|
|
use Data::Dumper; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
my $soap = |
188
|
|
|
|
|
|
|
SOAP::Lite->proxy('http://auth.example.com/') |
189
|
|
|
|
|
|
|
->uri('urn:/Lemonldap::NG::Common::::CGI::SOAPService'); |
190
|
|
|
|
|
|
|
my $r = $soap->getCookies( 'user', 'password' ); |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
# Catch SOAP errors |
193
|
|
|
|
|
|
|
if ( $r->fault ) { |
194
|
|
|
|
|
|
|
print STDERR "SOAP Error: " . $r->fault->{faultstring}; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
else { |
197
|
|
|
|
|
|
|
my $res = $r->result(); |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
# If authentication failed, display error |
200
|
|
|
|
|
|
|
if ( $res->{error} ) { |
201
|
|
|
|
|
|
|
print STDERR "Error: " . $soap->error( $res->{error} )->result(); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
# print session-ID |
205
|
|
|
|
|
|
|
else { |
206
|
|
|
|
|
|
|
print "Cookie: lemonldap=" . $res->{cookies}->{lemonldap}; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 DESCRIPTION |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Lemonldap::NG::Portal::SharedConf is the base module for building Lemonldap::NG |
213
|
|
|
|
|
|
|
compatible portals using a central database configuration. You have to use by |
214
|
|
|
|
|
|
|
inheritance. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
See L<Lemonldap::NG::Portal::SharedConf> for a complete example. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 METHODS |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Same as L<Lemonldap::NG::Portal::Simple>, but Lemonldap::NG::Portal::SharedConf |
221
|
|
|
|
|
|
|
adds a new sub: |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=over |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item * scanexpr: used by setGroups to read combined LDAP and Perl expressions. |
226
|
|
|
|
|
|
|
See L<Lemonldap::NG::Portal> for more. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=back |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head3 Args |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Lemonldap::NG::Portal::SharedConf use the same arguments than |
233
|
|
|
|
|
|
|
L<Lemonldap::NG::Portal::Simple>, but you can set them either using local |
234
|
|
|
|
|
|
|
variables passed to C<new()> or using variables issued from the database. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head2 EXPORT |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head3 Constants |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Same as L<Lemonldap::NG::Portal::Simple>. |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 SEE ALSO |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
L<Lemonldap::NG::Portal>, L<Lemonldap::NG::Portal::SharedConf>, |
245
|
|
|
|
|
|
|
L<Lemonldap::NG::Handler>, L<Lemonldap::NG::Manager>, |
246
|
|
|
|
|
|
|
L<http://lemonldap-ng.org/> |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head1 AUTHOR |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=over |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=item Clement Oudot, E<lt>clem.oudot@gmail.comE<gt> |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item François-Xavier Deltombe, E<lt>fxdeltombe@gmail.com.E<gt> |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=item Xavier Guimard, E<lt>x.guimard@free.frE<gt> |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=back |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head1 BUG REPORT |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
Use OW2 system to report bug or ask for features: |
263
|
|
|
|
|
|
|
L<http://jira.ow2.org> |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head1 DOWNLOAD |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Lemonldap::NG is available at |
268
|
|
|
|
|
|
|
L<http://forge.objectweb.org/project/showfiles.php?group_id=274> |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=over |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=item Copyright (C) 2006, 2007, 2008, 2009, 2010 by Xavier Guimard, E<lt>x.guimard@free.frE<gt> |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=item Copyright (C) 2012 by François-Xavier Deltombe, E<lt>fxdeltombe@gmail.com.E<gt> |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=item Copyright (C) 2006, 2009, 2010, 2011, 2012 by Clement Oudot, E<lt>clem.oudot@gmail.comE<gt> |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=back |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
283
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by |
284
|
|
|
|
|
|
|
the Free Software Foundation; either version 2, or (at your option) |
285
|
|
|
|
|
|
|
any later version. |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
288
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
289
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
290
|
|
|
|
|
|
|
GNU General Public License for more details. |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License |
293
|
|
|
|
|
|
|
along with this program. If not, see L<http://www.gnu.org/licenses/>. |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=cut |