Debian Codegraph @

lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Parser.pm

raw
1 package Lemonldap::NG::Manager::Conf::Parser;
2
3 # This module is called either to parse a new configuration in JSON format (as
4 # posted by the web interface) and test a new configuration object.
5 #
6 # The new object must be built with the following properties:
7 # - refConf: the actual configuration
8 # - req : the Lemonldap::NG::Common::PSGI::Request
9 # - tree : the new configuration in JSON format
10 # or
11 # - newConf: the configuration to test
12 #
13 # The main method is check() which calls:
14 # - scanTree() if configuration is not parsed (JSON string)
15 # - testNewConf()
16 #
17 # It returns a boolean. Errors, warnings and changes are stored as array
18 # containing `{ message => 'Explanation' }. A main message is stored in
19 # `message` property.
20
21 use strict;
22 use utf8;
23 use Crypt::URandom;
24 use Mouse;
25 use JSON 'to_json';
26 use Lemonldap::NG::Common::Conf::ReConstants;
27 use Lemonldap::NG::Manager::Attributes;
28
29 our $VERSION = '2.23.1';
30
31 extends 'Lemonldap::NG::Common::Conf::Compact';
32
33 # High debugging for developers, set this to 1
34 use constant HIGHDEBUG => 0;
35
36 # Messages storage
37 has errors => (
38 is => 'rw',
39 isa => 'ArrayRef',
40 default => sub { return [] }
41 );
42 has warnings => (
43 is => 'rw',
44 isa => 'ArrayRef',
45 default => sub { return [] },
46 trigger => sub {
47 hdebug( 'warnings contains', $_[0]->{warnings} );
48 }
49 );
50 has changes => ( is => 'rw', isa => 'ArrayRef', default => sub { return [] } );
51 has message => (
52 is => 'rw',
53 isa => 'Str',
54 lazy => 1,
55 default => sub {
56 return join( ', ', map { $_->{message} } @{ $_[0]->errors } );
57 },
58 trigger => sub {
59 hdebug( "Message becomes " . $_[0]->{message} );
60 }
61 );
62 has needConfirmation =>
63 ( is => 'rw', isa => 'ArrayRef', default => sub { return [] } );
64
65 # Booleans
66 has confChanged => (
67 is => 'rw',
68 isa => 'Bool',
69 default => 0,
70 trigger => sub {
71 hdebug( "condChanged: " . $_[0]->{confChanged} );
72 }
73 );
74
75 # Properties required during build
76 has refConf => ( is => 'ro', isa => 'HashRef', required => 1 );
77 has req => ( is => 'ro', required => 1 );
78 has newConf => ( is => 'rw', isa => 'HashRef' );
79 has tree => ( is => 'rw', isa => 'ArrayRef' );
80
81 # High debug method
82 sub hdebug {
83 if (HIGHDEBUG) {
84 foreach my $d (@_) {
85 if ( ref $d ) {
86 require Data::Dumper;
87 $Data::Dumper::Useperl = 1;
88 print STDERR Data::Dumper::Dumper($d);
89 }
90 else { print STDERR "$d\n" }
91 }
92 }
93 undef;
94 }
95
96 ##@method boolean check()
97 # Main method
98 #@return result
99 sub check {
100 my ( $self, $localConf ) = @_;
101
102 hdebug("# check()");
103 unless ( $self->newConf ) {
104 return 0 unless ( $self->scanTree );
105 }
106 unless ( $self->testNewConf($localConf) ) {
107 hdebug(" testNewConf() failed");
108 return 0;
109 }
110 my $separator = $self->newConf->{multiValuesSeparator} || '; ';
111 hdebug(" tests succeed");
112 my %conf = %{ $self->newConf };
113 my %compactedConf = %{ $self->compactConf( $self->newConf ) };
114 my @removedKeys = ();
115 unless ( $self->confChanged ) {
116 hdebug(" no change detected");
117 $self->message('__confNotChanged__');
118 return 0;
119 }
120
121 # Return removed keys if conf compacted
122 @removedKeys = map { exists $compactedConf{$_} ? () : $_ } sort keys %conf
123 if ( $self->newConf->{compactConf} );
124 push @{ $self->changes },
125 (
126 $self->{newConf}->{compactConf}
127 ? {
128 confCompacted => '1',
129 removedKeys => join( $separator, @removedKeys )
130 }
131 : { confCompacted => '0' }
132 );
133
134 return 1;
135 }
136
137 ##@method boolean scanTree()
138 # Methods to build new conf from JSON string
139 #@result true if succeed
140 sub scanTree {
141 my $self = shift;
142 hdebug("# scanTree()");
143 $self->newConf( {} );
144 $self->_scanNodes( $self->tree ) or return 0;
145
146 # Set cfgNum to ref cfgNum (will be changed when saving), set other
147 # metadata and set a value to the key if empty
148 $self->newConf->{cfgNum} = $self->req->params('cfgNum');
149 my $envUser;
150 foreach (qw(REMOTE_USER SUDO_USER USER)) {
151 ( $envUser = $self->req->env->{$_} || $ENV{$_} ) and last;
152 }
153 $envUser = '' unless $envUser =~ /\w/;
154 $self->newConf->{cfgAuthor} =
155 $self->req->userData->{ Lemonldap::NG::Handler::Main->tsv->{whatToTrace}
156 || '_whatToTrace' }
157 || $envUser
158 || "anonymous";
159 $self->newConf->{cfgAuthorIP} = $self->req->address;
160 $self->newConf->{cfgAuthorIP} .=
161 ' (maybe '
162 . ( $self->req->env->{'X-Real-IP'}
163 || $self->req->env->{HTTP_X_FORWARDED_FOR} )
164 . ')'
165 if $self->req->env->{'X-Real-IP'}
166 or $self->req->env->{HTTP_X_FORWARDED_FOR};
167 $self->newConf->{cfgDate} = time;
168 $self->newConf->{cfgVersion} = $Lemonldap::NG::Manager::VERSION;
169 $self->newConf->{key} ||= join( '',
170 map { chr( int( ord( Crypt::URandom::urandom(1) ) * 94 / 256 ) + 33 ) }
171 ( 1 .. 16 ) );
172
173 return 1;
174 }
175
176 use feature 'state';
177
178 ##@method private boolean _scanNodes()
179 # Recursive JSON parser
180 #@result true if succeed
181 sub _scanNodes {
182 my ( $self, $tree, ) = @_;
183 hdebug("# _scanNodes()");
184 state ( $knownCat, %newNames );
185 unless ( ref($tree) eq 'ARRAY' ) {
186 print STDERR 'Fatal: node is not an array';
187 push @{ $self->errors }, { message => 'Fatal: node is not an array' };
188 return 0;
189 }
190 unless (@$tree) {
191 hdebug(' empty tree !?');
192 }
193 foreach my $leaf (@$tree) {
194 my $name = $leaf->{title};
195 hdebug("Looking to $name");
196
197 # subnode
198 my $subNodes = $leaf->{nodes} // $leaf->{_nodes};
199 my $subNodesCond = $leaf->{nodes_cond} // $leaf->{_nodes_cond};
200
201 ##################################
202 # VirtualHosts and SAML partners #
203 ##################################
204
205 # Root nodes
206 if ( $leaf->{id} =~ /^($specialNodeKeys)$/i ) {
207 hdebug("Root special node detected $leaf->{id}");
208
209 # If node has not been opened
210 if ( $leaf->{cnodes} ) {
211 hdebug(" not opened");
212 foreach my $k ( @{ $specialNodeHash->{ $leaf->{id} } } ) {
213 hdebug(" copying $k");
214 $self->newConf->{$k} = $self->refConf->{$k};
215 }
216 next;
217 }
218 $self->_scanNodes($subNodes);
219
220 # Check deleted keys
221 my $field = $specialNodeHash->{ $leaf->{id} }->[0];
222 my @old = keys %{ $self->refConf->{$field} };
223 foreach my $k ( keys %{ $self->newConf->{$field} } ) {
224 @old = grep { $_ ne $k } @old;
225 }
226 if (@old) {
227 hdebug( "Keys detected as removed:", \@old );
228 $self->confChanged(1);
229 foreach my $deletedHost (@old) {
230 push @{ $self->changes },
231 { key => $leaf->{id}, old => $deletedHost };
232 }
233 }
234 next;
235 }
236
237 # 1st sublevel
238 elsif ( $leaf->{id} =~ /^($specialNodeKeys)\/([^\/]+)$/i ) {
239 hdebug("Special node chield detected $leaf->{id}");
240 my ( $base, $host ) = ( $1, $2 );
241
242 # Check hostname/partner name changes (id points to the old name)
243 $newNames{$host} = $leaf->{title};
244 if ( $newNames{$host} ne $host and $host !~ /^new__/ ) {
245 hdebug(" $host becomes $newNames{$host}");
246 $self->confChanged(1);
247 push @{ $self->changes },
248 { key => $base, old => $host, new => $newNames{$host} };
249 }
250
251 $self->_scanNodes($subNodes);
252 next;
253 }
254
255 # Other sub levels
256 elsif ( $leaf->{id} =~
257 /^($specialNodeKeys)\/([^\/]+)\/([^\/]+)(?:\/(.*))?$/i )
258 {
259 my ( $base, $key, $oldName, $target, $h ) =
260 ( $1, $newNames{$2}, $2, $3, $4 );
261 hdebug(
262 "Special node chield subnode detected $leaf->{id}",
263 " base $base, key $key, target $target, h "
264 . ( $h ? $h : 'undef' )
265 );
266
267 # VirtualHosts
268 if ( $base eq 'virtualHosts' ) {
269 hdebug(" virtualhost");
270 if ( $target =~ /^(?:locationRules|exportedHeaders|post)$/ ) {
271 if ( $leaf->{cnodes} ) {
272 hdebug(' unopened subnode');
273 $self->newConf->{$target}->{$key} =
274 $self->refConf->{$target}->{$oldName} // {};
275 }
276
277 elsif ($h) {
278 hdebug(' 4 levels');
279 if ( $target eq 'locationRules' ) {
280 hdebug(' locationRules');
281 my $k =
282 $leaf->{comment}
283 ? "(?#$leaf->{comment})$leaf->{re}"
284 : $leaf->{re};
285 $k .= "(?#AuthnLevel=$leaf->{level})"
286 if $leaf->{level};
287 $self->set( $target, $key, $k, $leaf->{data} );
288 }
289 else {
290 hdebug(' other than locationrules');
291 $self->set( $target, $key, $leaf->{title},
292 $leaf->{data} );
293 }
294 }
295
296 # Unless $h is set, scan subnodes and check changes
297 else {
298 hdebug(' 3 levels only (missing $h)');
299 if ( ref $subNodes ) {
300 hdebug(' has subnodes');
301 $self->_scanNodes($subNodes)
302 or return 0;
303 }
304 if ( exists $self->refConf->{$target}->{$key}
305 and %{ $self->refConf->{$target}->{$key} } )
306 {
307 hdebug(' old conf subnode has values');
308 my $c = $self->newConf->{$target};
309 foreach my $k (
310 keys %{ $self->refConf->{$target}->{$key} } )
311 {
312 unless ( defined $c->{$key}->{$k} ) {
313 hdebug(' missing value in old conf');
314 $self->confChanged(1);
315 push @{ $self->changes },
316 {
317 key => "$target, $key",
318 old => $k,
319 };
320 }
321 }
322 }
323 elsif ( exists $self->newConf->{$target}->{$key}
324 and %{ $self->newConf->{$target}->{$key} } )
325 {
326 hdebug(" '$key' has values");
327 $self->confChanged(1);
328 push @{ $self->changes },
329 { key => "$target", new => $key };
330 }
331 }
332 }
333 elsif ( $target =~ /^$virtualHostKeys$/ ) {
334 $self->set( 'vhostOptions', [ $oldName, $key ],
335 $target, $leaf->{data} );
336 }
337 else {
338 push @{ $self->errors },
339 { message => "Unknown vhost key $target" };
340 return 0;
341 }
342 next;
343 }
344
345 # SAML
346 elsif ( $base =~ /^saml(?:S|ID)PMetaDataNodes$/ ) {
347 hdebug('SAML');
348 if ( defined $leaf->{data}
349 and ref( $leaf->{data} ) eq 'ARRAY' )
350 {
351 hdebug(" SAML data is an array, serializing");
352 $leaf->{data} = join ';', @{ $leaf->{data} };
353 }
354 if ( $target =~
355 /^saml(?:S|ID)PMetaData(?:ExportedAttributes|Macros)$/ )
356 {
357 if ( $leaf->{cnodes} ) {
358 hdebug(" $target: unopened node");
359 $self->newConf->{$target}->{$key} =
360 $self->refConf->{$target}->{$oldName} // {};
361 }
362 elsif ($h) {
363 hdebug(" $target: opened node");
364 $self->confChanged(1);
365 $self->set( $target, $key, $leaf->{title},
366 $leaf->{data} );
367 }
368 elsif ( !@$subNodes ) {
369 hdebug(" $target: no subnodes");
370 $self->confChanged(1);
371 }
372 else {
373 hdebug(" $target: scanning subnodes");
374 $self->_scanNodes($subNodes);
375 }
376 }
377 elsif ( $target =~ /^saml(?:S|ID)PMetaDataXML$/ ) {
378 hdebug(" $target");
379 $self->set( $target, [ $oldName, $key ],
380 $target, $leaf->{data} );
381 }
382 elsif ( $target =~ /^saml(?:S|ID)PMetaDataURL$/ ) {
383 hdebug(" $target");
384 $self->set( $target, [ $oldName, $key ],
385 $target, $leaf->{data} );
386 }
387 elsif ( $target =~ /^saml(?:ID|S)PMetaDataOptions/ ) {
388 my $optKey = $&;
389 hdebug(" $base sub key: $target");
390 if ( $target =~
391 /^(?:$samlIDPMetaDataNodeKeys|$samlSPMetaDataNodeKeys)/
392 )
393 {
394 $self->set(
395 $optKey, [ $oldName, $key ],
396 $target, $leaf->{data}
397 );
398 }
399 else {
400 push @{ $self->errors },
401 { message => "Unknown SAML metadata option $target" };
402 return 0;
403 }
404 }
405 else {
406 push @{ $self->errors },
407 { message => "Unknown SAML key $target" };
408 return 0;
409 }
410 next;
411 }
412
413 # OIDC
414 elsif ( $base =~ /^oidc(?:O|R)PMetaDataNodes$/ ) {
415 hdebug('OIDC');
416 if ( $target =~ /^oidc(?:O|R)PMetaDataOptions$/ ) {
417 hdebug(" $target: looking for subnodes");
418 $self->_scanNodes($subNodes);
419 $self->set( $target, $key, $leaf->{title}, $leaf->{data} );
420 }
421 elsif ( $target =~ /^oidcOPMetaData(?:JSON|JWKS)$/ ) {
422 hdebug(" $target");
423 $self->set( $target, $key, $leaf->{data} );
424 }
425 elsif ( $target =~ /^oidcRPMetaDataExportedVars$/ ) {
426 hdebug(" $target");
427 if ( $leaf->{cnodes} ) {
428 hdebug(' unopened');
429 $self->newConf->{$target}->{$key} =
430 $self->refConf->{$target}->{$oldName} // {};
431 }
432 elsif ($h) {
433 hdebug(' opened');
434 $self->confChanged(1);
435 my $tmp = $leaf->{data};
436 if ( ref( $leaf->{data} ) eq 'ARRAY' ) {
437
438 # Forward compatibility. If Type and Array have
439 # default values, store in old format
440 if ( $leaf->{data}->[1] eq "string"
441 and $leaf->{data}->[2] eq "auto" )
442 {
443 $tmp = $leaf->{data}->[0];
444 }
445 else {
446 $tmp = join ';', @{ $leaf->{data} };
447 }
448 }
449 $self->set( $target, $key, $leaf->{title}, $tmp );
450 }
451 elsif ( !@$subNodes ) {
452 hdebug(" $target: no subnodes");
453 $self->confChanged(1);
454 }
455 else {
456 hdebug(" $target: scanning subnodes");
457 $self->_scanNodes($subNodes);
458 }
459 }
460 elsif ( $target =~
461 /^oidc(?:O|R)PMetaData(?:ExportedVars|Macros|ScopeRules)$/ )
462 {
463 hdebug(" $target");
464 if ( $leaf->{cnodes} ) {
465 hdebug(' unopened');
466 $self->newConf->{$target}->{$key} =
467 $self->refConf->{$target}->{$oldName} // {};
468 }
469 elsif ($h) {
470 hdebug(' opened');
471 $self->confChanged(1);
472 $self->set( $target, $key, $leaf->{title},
473 $leaf->{data} );
474 }
475 elsif ( !@$subNodes ) {
476 hdebug(" $target: no subnodes");
477 $self->confChanged(1);
478 }
479 else {
480 hdebug(" $target: scanning subnodes");
481 $self->_scanNodes($subNodes);
482 }
483 }
484 elsif ( $target =~ /^oidc(?:O|R)PMetaDataOptions/ ) {
485 my $optKey = $&;
486 hdebug " $base sub key: $target";
487 if ( $target eq 'oidcRPMetaDataOptionsExtraClaims' ) {
488 if ( $leaf->{cnodes} ) {
489 hdebug(' unopened');
490 $self->newConf->{$target}->{$key} =
491 $self->refConf->{$target}->{$oldName} // {};
492 }
493 elsif ($h) {
494 hdebug(' opened');
495 $self->set( $target, $key, $leaf->{title},
496 $leaf->{data} );
497 }
498 elsif ( !@$subNodes ) {
499 hdebug(" $target: no subnodes");
500 $self->confChanged(1);
501 }
502 else {
503 hdebug(" $target: scanning subnodes");
504 $self->_scanNodes($subNodes);
505 }
506 }
507 elsif ( $target eq
508 'oidcOPMetaDataOptionsAuthEndpointExtraParams' )
509 {
510 if ( $leaf->{cnodes} ) {
511 hdebug(' unopened');
512 $self->newConf->{$optKey}->{$key}->{$target} =
513 $self->refConf->{$optKey}->{$oldName}->{$target}
514 // {};
515 }
516 elsif ($h) {
517 hdebug(' opened');
518 $self->set( $optKey, [ $oldName, $key ],
519 $target, $leaf->{title}, $leaf->{data} );
520 }
521 elsif ( !@$subNodes ) {
522 hdebug(" $target: no subnodes");
523 $self->confChanged(1);
524 }
525 else {
526 hdebug(" $target: scanning subnodes");
527 my @oldKeys =
528 keys %{ $self->refConf->{$optKey}->{$oldName}
529 ->{$target} };
530 $self->_scanNodes($subNodes);
531 my @newKeys = keys
532 %{ $self->newConf->{$optKey}->{$key}->{$target} };
533
534 # Detect deleted nodes
535 my %seen = map { $_ => 1 } @newKeys;
536 my @deleted = grep { !$seen{$_} } @oldKeys;
537 $self->confChanged(1) if @deleted;
538 }
539 }
540 elsif ( $target =~
541 /^(?:$oidcOPMetaDataNodeKeys|$oidcRPMetaDataNodeKeys)/ )
542 {
543 $self->set(
544 $optKey, [ $oldName, $key ],
545 $target, $leaf->{data}
546 );
547 }
548 else {
549 push @{ $self->errors },
550 { message => "Unknown OIDC metadata option $target" };
551 return 0;
552 }
553 }
554 else {
555 push @{ $self->errors },
556 { message => "Unknown OIDC key $target" };
557 return 0;
558 }
559 next;
560 }
561
562 # CAS
563 elsif ( $base =~ /^cas(?:App|Srv)MetaDataNodes$/ ) {
564 my $optKey = $&;
565 hdebug('CAS');
566 if ( $target =~ /^cas(?:App|Srv)MetaDataOptions$/ ) {
567 hdebug(" $target: looking for subnodes");
568 $self->_scanNodes($subNodes);
569 $self->set( $target, $key, $leaf->{title}, $leaf->{data} );
570 }
571 elsif ( $target =~
572 /^cas(?:App|Srv)MetaData(?:ExportedVars|Macros)$/ )
573 {
574 hdebug(" $target");
575 if ( $leaf->{cnodes} ) {
576 hdebug(' unopened');
577 $self->newConf->{$target}->{$key} =
578 $self->refConf->{$target}->{$oldName} // {};
579 }
580 elsif ($h) {
581 hdebug(' opened');
582 $self->confChanged(1);
583 $self->set( $target, $key, $leaf->{title},
584 $leaf->{data} );
585 }
586 elsif ( !@$subNodes ) {
587 hdebug(" $target: no subnodes");
588 $self->confChanged(1);
589 }
590 else {
591 hdebug(" $target: scanning subnodes");
592 $self->_scanNodes($subNodes);
593 }
594 }
595 elsif ( $target =~ /^cas(?:Srv|App)MetaDataOptions/ ) {
596 my $optKey = $&;
597 hdebug " $base sub key: $target";
598 if ( $target eq 'casSrvMetaDataOptionsProxiedServices' ) {
599 if ( $leaf->{cnodes} ) {
600 hdebug(' unopened');
601 $self->newConf->{$target}->{$key} =
602 $self->refConf->{$target}->{$oldName} // {};
603 }
604 elsif ($h) {
605 hdebug(' opened');
606 $self->set( $target, $key, $leaf->{title},
607 $leaf->{data} );
608 }
609 elsif ( !@$subNodes ) {
610 hdebug(" $target: no subnodes");
611 $self->confChanged(1);
612 }
613 else {
614 hdebug(" $target: scanning subnodes");
615 $self->_scanNodes($subNodes);
616 }
617 }
618 elsif ( $target =~
619 /^(?:$casSrvMetaDataNodeKeys|$casAppMetaDataNodeKeys)/ )
620 {
621 $self->set(
622 $optKey, [ $oldName, $key ],
623 $target, $leaf->{data}
624 );
625 }
626 else {
627 push @{ $self->errors },
628 { message => "Unknown CAS metadata option $target" };
629 return 0;
630 }
631 }
632 else {
633 push @{ $self->errors },
634 { message => "Unknown CAS option $target" };
635 return 0;
636 }
637 next;
638 }
639 elsif ( $base eq 'keyNodes' ) {
640 hdebug('Keys');
641 hdebug("target $target");
642 hdebug("key $key");
643 if ( $target eq "KeyMaterial" ) {
644 if ( $leaf->{data} ) {
645 hdebug(' opened');
646 for my $data ( @{ $leaf->{data} } ) {
647 $self->set( "keys", $key, $data->{title},
648 $data->{data} );
649 }
650 }
651 else {
652 hdebug(' unopened');
653 for my $opt (qw/keyPrivate keyPrivatePwd keyPublic/) {
654 $self->set( "keys", $key, $opt, undef );
655 }
656 }
657 }
658 else {
659 $self->set( "keys", $key, $leaf->{title}, $leaf->{data} );
660 }
661 next;
662 }
663 else {
664 push @{ $self->errors },
665 { message => "Fatal: unknown special sub node $base" };
666 return 0;
667 }
668 }
669
670 ####################
671 # Application list #
672 ####################
673
674 # Application list root node
675 elsif ( $leaf->{title} eq 'applicationList' ) {
676 hdebug( $leaf->{title} );
677 if ( $leaf->{cnodes} ) {
678 hdebug(' unopened');
679 $self->newConf->{applicationList} =
680 $self->refConf->{applicationList} // {};
681 }
682 else {
683 $self->_scanNodes($subNodes) or return 0;
684
685 # Check for deleted
686 my @listCatRef =
687 map { $self->refConf->{applicationList}->{$_}->{catname} }
688 keys %{ $self->refConf->{applicationList} };
689 my @listCatNew =
690 map { $self->newConf->{applicationList}->{$_}->{catname} }
691 keys(
692 %{
693 ref $self->newConf->{applicationList}
694 ? $self->newConf->{applicationList}
695 : {}
696 }
697 );
698
699 @listCatRef = map { $_ ? $_ : () } @listCatRef;
700 @listCatNew = map { $_ ? $_ : () } @listCatNew;
701 @listCatRef = sort @listCatRef;
702 @listCatNew = sort @listCatNew;
703 hdebug( '# @listCatRef : ', \@listCatRef );
704 hdebug( '# @listCatNew : ', \@listCatNew );
705
706 # Check for deleted
707 my @diff =
708 grep !${ { map { $_, 1 } @listCatNew } }{$_}, @listCatRef;
709 if ( scalar @diff ) {
710 $self->confChanged(1);
711 push @{ $self->changes },
712 {
713 new => join( ', ', 'categoryList', @listCatNew ),
714 key => join( ', ', 'Deletes in cat(s)', @diff ),
715 old => join( ', ', 'categoryList', @listCatRef ),
716 };
717 }
718 }
719 next;
720 }
721
722 # Application list sub nodes
723 elsif ( $leaf->{id} =~ /^applicationList\/(.+)$/ ) {
724 hdebug('Application list subnode');
725 use feature 'state';
726 my @cats = split /\//, $1;
727 my $app = pop @cats;
728 $self->newConf->{applicationList} //= {};
729
730 # $cn is a pointer to the parent
731 my $cn = $self->newConf->{applicationList};
732 my $cmp = $self->refConf->{applicationList};
733 my @path;
734
735 # Makes $cn point to the parent
736 foreach my $cat (@cats) {
737 hdebug(" looking to cat $cat");
738 unless ( defined $knownCat->{$cat} ) {
739 push @{ $self->{errors} },
740 { message =>
741 "Fatal: sub cat/app before parent ($leaf->{id})" };
742 return 0;
743 }
744 $cn = $cn->{ $knownCat->{$cat} };
745 push @path, $cn->{catname};
746 $cmp->{$cat} //= {};
747 $cmp = $cmp->{$cat};
748 }
749
750 my $newapp = $app;
751
752 # Compute a nice name for new nodes, taking care of potential conflicts
753 # For some reason, the manager sends /nNaN sometimes
754 if ( $newapp =~ /^n(\d+|NaN)$/ ) {
755
756 # Remove all special characters
757 my $baseName = $leaf->{title} =~ s/\W//gr;
758 $baseName = lc $baseName;
759 $newapp = $baseName;
760 my $cnt = 1;
761 while ( exists $cn->{$newapp} ) {
762 $newapp = "${baseName}_" . $cnt++;
763 }
764 }
765
766 # Create new category
767 #
768 # Note that this works because nodes are ordered so "cat/cat2/app"
769 # is looked after "cat" and "cat/cat2"
770 if ( $leaf->{type} eq 'menuCat' ) {
771 hdebug(' menu cat');
772 $knownCat->{__id}++;
773 $knownCat->{$app} = $newapp;
774 $cn->{$newapp} = {
775 catname => $leaf->{title},
776 type => 'category',
777 order => $knownCat->{__id}
778 };
779 unless ($cmp->{$app}
780 and $cmp->{$app}->{catname} eq $cn->{$newapp}->{catname} )
781 {
782 $self->confChanged(1);
783 push @{ $self->changes },
784 {
785 key => join(
786 ', ', 'applicationList', @path, $leaf->{title}
787 ),
788 new => $cn->{$newapp}->{catname},
789 old => (
790 $cn->{$newapp} ? $cn->{$newapp}->{catname} : undef
791 )
792 };
793 }
794 if ( ref $subNodes ) {
795 $self->_scanNodes($subNodes) or return 0;
796 }
797 my @listCatRef = keys %{ $cmp->{$app} };
798 my @listCatNew = keys %{ $cn->{$newapp} };
799
800 # Check for deleted
801 unless ( @listCatRef == @listCatNew ) {
802 $self->confChanged(1);
803 push @{ $self->changes },
804 {
805 key => join( ', ', 'applicationList', @path ),
806 new => 'Changes in cat(s)/app(s)',
807 };
808 }
809 }
810
811 # Create new apps
812 if ( $leaf->{type} eq 'menuApp' ) {
813 hdebug(' new app');
814 $knownCat->{__id}++;
815 $cn->{$newapp} = {
816 type => 'application',
817 options => $leaf->{data},
818 order => $knownCat->{__id}
819 };
820 $cn->{$newapp}->{options}->{name} = $leaf->{title};
821 unless ( $cmp->{$app} ) {
822 $self->confChanged(1);
823 push @{ $self->changes },
824 {
825 key => join( ', ', 'applicationList', @path ),
826 new => $leaf->{title},
827 };
828 }
829 else {
830 # Check for change in ordering
831 if ( ( $cn->{$newapp}->{order} || 0 ) !=
832 ( $cmp->{$newapp}->{order} || 0 ) )
833 {
834 $self->confChanged(1);
835 }
836
837 # Check for change in options
838 foreach my $k ( keys %{ $cn->{$newapp}->{options} } ) {
839 unless ( $cmp->{$app}->{options}->{$k} eq
840 $cn->{$newapp}->{options}->{$k} )
841 {
842 $self->confChanged(1);
843 push @{ $self->changes },
844 {
845 key => join( ', ',
846 'applicationList', @path,
847 $leaf->{title}, $k ),
848 new => $cn->{$newapp}->{options}->{$k},
849 old => $cmp->{$app}->{options}->{$k}
850 };
851 }
852 }
853 }
854 }
855 next;
856 }
857 elsif ( $leaf->{id} eq 'grantSessionRules' ) {
858 hdebug('grantSessionRules');
859 if ( $leaf->{cnodes} ) {
860 hdebug(' unopened');
861 $self->newConf->{$name} = $self->refConf->{$name} // {};
862 }
863 else {
864 hdebug(' opened');
865 $subNodes //= [];
866 my $count = 0;
867 my $ref = $self->refConf->{grantSessionRules};
868 my $new = $self->newConf->{grantSessionRules};
869 my @old = ref $ref ? keys %$ref : ();
870 $self->newConf->{grantSessionRules} = {};
871 foreach my $n (@$subNodes) {
872 hdebug(" looking at $n subnode");
873 my $k =
874 $n->{re} . ( $n->{comment} ? "##$n->{comment}" : '' );
875 $self->newConf->{grantSessionRules}->{$k} = $n->{data};
876 $count++;
877 unless ( defined $ref->{$k} ) {
878 $self->confChanged(1);
879 push @{ $self->changes },
880 { keys => 'grantSessionRules', new => $k };
881 }
882 elsif ( $ref->{$k} ne $n->{data} ) {
883 $self->confChanged(1);
884 push @{ $self->changes },
885 {
886 key => "grantSessionRules, $k",
887 old => $self->refConf->{grantSessionRules}->{$k},
888 new => $n->{data}
889 };
890 }
891 @old = grep { $_ ne $k } @old;
892 }
893 if (@old) {
894 $self->confChanged(1);
895 push @{ $self->changes },
896 { key => 'grantSessionRules', old => $_, }
897 foreach (@old);
898 }
899 }
900 next;
901 }
902
903 # openIdIDPList: data is splitted by Conf.pm into a boolean and a
904 # string
905 elsif ( $name eq 'openIdIDPList' ) {
906 hdebug('openIdIDPList');
907 if ( $leaf->{data} ) {
908 unless ( ref $leaf->{data} eq 'ARRAY' ) {
909 push @{ $self->{errors} },
910 { message => 'Malformed openIdIDPList ' . $leaf->{data} };
911 return 0;
912 }
913 $self->set( $name, join( ';', @{ $leaf->{data} } ) );
914 }
915 else {
916 $self->set( $name, undef );
917 }
918 next;
919 }
920
921 ####################
922 # Other hash nodes #
923 ####################
924 elsif ( $leaf->{title} =~ /^$simpleHashKeys$/
925 and not $leaf->{title} eq 'applicationList' )
926 {
927 hdebug( $leaf->{title} );
928
929 # If a `cnodes` key is found, keep old key unchanges
930 if ( $leaf->{cnodes} ) {
931 hdebug(' unopened');
932 $self->newConf->{$name} = $self->refConf->{$name} // {};
933 }
934 else {
935 hdebug(' opened');
936
937 # combModules: just to replace "over" key
938 if ( $name eq 'combModules' ) {
939 hdebug(' combModules');
940 $self->newConf->{$name} = {};
941 foreach my $node ( @{ $leaf->{nodes} } ) {
942 my $tmp;
943 $tmp->{$_} = $node->{data}->{$_} foreach (qw(type for));
944 $tmp->{over} = {};
945 foreach ( @{ $node->{data}->{over} } ) {
946 $tmp->{over}->{ $_->[0] } = $_->[1];
947 }
948 $self->newConf->{$name}->{ $node->{title} } = $tmp;
949 }
950
951 # TODO: check changes
952 $self->confChanged(1);
953 next;
954 }
955
956 # sfExtra: just to replace "over" key
957 if ( $name eq 'sfExtra' ) {
958 hdebug(' sfExtra');
959 $self->newConf->{$name} = {};
960 foreach my $node ( @{ $leaf->{nodes} } ) {
961 my $tmp;
962 $tmp->{$_} = $node->{data}->{$_}
963 foreach (qw(type rule logo level label regrule));
964 $tmp->{register} = $node->{data}->{register} ? 1 : 0;
965 $tmp->{over} = {};
966 foreach ( @{ $node->{data}->{over} } ) {
967 $tmp->{over}->{ $_->[0] } = $_->[1];
968 }
969 $self->newConf->{$name}->{ $node->{title} } = $tmp;
970 }
971
972 # TODO: check changes
973 $self->confChanged(1);
974 next;
975 }
976
977 $subNodes //= [];
978 my $count = 0;
979 my @old = (
980 ref( $self->refConf->{$name} )
981 ? ( keys %{ $self->refConf->{$name} } )
982 : ()
983 );
984 $self->newConf->{$name} = {};
985 foreach my $n (@$subNodes) {
986 hdebug(" looking at $n subnode");
987 if ( ref $n->{data} and ref $n->{data} eq 'ARRAY' ) {
988
989 # authChoiceModules
990 if ( $name eq 'authChoiceModules' ) {
991 hdebug(' authChoiceModules');
992 if ( ref( $n->{data}->[5] ) eq 'ARRAY' ) {
993 $n->{data}->[5] =
994 to_json( { map { @$_ } @{ $n->{data}->[5] } },
995 { canonical => 1 } );
996 }
997 else {
998 $n->{data}->[5] = '{}';
999 }
1000 }
1001
1002 $n->{data} = join ';', @{ $n->{data} };
1003 }
1004 $self->newConf->{$name}->{ $n->{title} } = $n->{data};
1005 $count++;
1006 unless ( defined $self->refConf->{$name}->{ $n->{title} } )
1007 {
1008 $self->confChanged(1);
1009 push @{ $self->changes },
1010 { key => $name, new => $n->{title}, };
1011 }
1012 elsif (
1013 $self->refConf->{$name}->{ $n->{title} } ne $n->{data} )
1014 {
1015 $self->confChanged(1);
1016 push @{ $self->changes },
1017 {
1018 key => "$name, $n->{title}",
1019 old => $self->refConf->{$name}->{ $n->{title} },
1020 new => $n->{data}
1021 };
1022 }
1023 @old = grep { $_ ne $n->{title} } @old;
1024 }
1025 if (@old) {
1026 $self->confChanged(1);
1027 push @{ $self->changes }, { key => $name, old => $_, }
1028 foreach (@old);
1029 }
1030 }
1031 next;
1032 }
1033
1034 # Double hash nodes
1035 elsif ( $leaf->{title} =~ /^$doubleHashKeys$/ ) {
1036 hdebug( $leaf->{title} );
1037 my @oldHosts = (
1038 ref( $self->refConf->{$name} )
1039 ? ( keys %{ $self->refConf->{$name} } )
1040 : ()
1041 );
1042 $self->newConf->{$name} = {};
1043 unless ( defined $leaf->{data} ) {
1044 hdebug(' unopened');
1045 $self->newConf->{$name} = $self->refConf->{$name} || {};
1046 next;
1047 }
1048 foreach my $getHost ( @{ $leaf->{data} } ) {
1049 my $change = 0;
1050 my @oldKeys;
1051 my $host = $getHost->{k};
1052 hdebug(" looking at host: $host");
1053 $self->newConf->{$name}->{$host} = {};
1054 unless ( defined $self->refConf->{$name}->{$host} ) {
1055 $self->confChanged(1);
1056 $change++;
1057 push @{ $self->changes }, { key => $name, new => $host };
1058 hdebug(" $host is new");
1059 }
1060 else {
1061 @oldHosts = grep { $_ ne $host } @oldHosts;
1062 @oldKeys = keys %{ $self->refConf->{$name}->{$host} };
1063 }
1064 foreach my $prm ( @{ $getHost->{h} } ) {
1065 $self->newConf->{$name}->{$host}->{ $prm->{k} } =
1066 $prm->{v};
1067 if (
1068 !$change
1069 and (
1070 not defined(
1071 $self->refConf->{$name}->{$host}->{ $prm->{k} }
1072 )
1073 or $self->newConf->{$name}->{$host}->{ $prm->{k} }
1074 ne $self->refConf->{$name}->{$host}->{ $prm->{k} }
1075 )
1076 )
1077 {
1078 $self->confChanged(1);
1079 hdebug(" key $prm->{k} has been changed");
1080 push @{ $self->changes },
1081 { key => "$name/$host", new => $prm->{k} };
1082 }
1083 elsif ( !$change ) {
1084 @oldKeys = grep { $_ ne $prm->{k} } @oldKeys;
1085 }
1086 }
1087 if (@oldKeys) {
1088 $self->confChanged(1);
1089 hdebug( " old keys: " . join( ' ', @oldKeys ) );
1090 push @{ $self->changes },
1091 { key => "$name/$host", old => $_ }
1092 foreach (@oldKeys);
1093 }
1094 }
1095 if (@oldHosts) {
1096 $self->confChanged(1);
1097 hdebug( " old hosts " . join( ' ', @oldHosts ) );
1098 push @{ $self->changes }, { key => "$name", old => $_ }
1099 foreach (@oldHosts);
1100 }
1101 next;
1102 }
1103
1104 ###############
1105 # Other nodes #
1106 ###############
1107
1108 # Check if subnodes
1109 my $n = 0;
1110 if ( ref $subNodesCond ) {
1111 hdebug(' conditional subnodes detected');
1112
1113 # Bad idea,subnode unopened are not read
1114 #$subNodesCond = [ grep { $_->{show} } @$subNodesCond ];
1115 $self->_scanNodes($subNodesCond) or return 0;
1116 $n++;
1117 }
1118 if ( ref $subNodes ) {
1119 hdebug(' subnodes detected');
1120 $self->_scanNodes($subNodes) or return 0;
1121 $n++;
1122 }
1123 if ($n) {
1124 next;
1125 }
1126 if ( defined $leaf->{data} and ref( $leaf->{data} ) eq 'ARRAY' ) {
1127 if ( ref( $leaf->{data}->[0] ) eq 'HASH' ) {
1128 hdebug(" array found");
1129 $self->_scanNodes( $leaf->{data} ) or return 0;
1130 }
1131 else {
1132 $self->set( $name, join( ';', @{ $leaf->{data} } ) );
1133 }
1134 }
1135
1136 # Grouped nodes not opened
1137 elsif ( $leaf->{get} and ref $leaf->{get} eq 'ARRAY' ) {
1138 hdebug(" unopened grouped node");
1139 foreach my $subkey ( @{ $leaf->{get} } ) {
1140 $self->set( $subkey, undef );
1141 }
1142 }
1143
1144 # Normal leaf
1145 else {
1146 $self->set( $name, $leaf->{data} );
1147 }
1148 }
1149 return 1;
1150 }
1151
1152 ##@method private void set($target, @path, $data)
1153 # Store a value in the $target key (following subkeys if @path is set)
1154 sub set {
1155 my $self = shift;
1156 my $data = pop;
1157 my @confs = ( $self->refConf, $self->newConf );
1158 my @path;
1159 while ( @_ > 1 ) {
1160 my $tmp = shift;
1161 push @path, $tmp;
1162 foreach my $i ( 0, 1 ) {
1163 my $v = ref($tmp) ? $tmp->[$i] : $tmp;
1164 $confs[$i]->{$v} //= {};
1165 $confs[$i] = $confs[$i]->{$v};
1166 }
1167 }
1168 my $target = shift;
1169 hdebug( "# set() called:",
1170 { data => $data, path => \@path, target => $target } );
1171 die @path unless ($target);
1172
1173 # Check new value
1174 if ( defined $data ) {
1175 hdebug(" data defined");
1176
1177 # TODO: remove if $data == default value
1178 $confs[1]->{$target} = $data;
1179 eval {
1180 unless (
1181 $target eq 'cfgLog'
1182 or ( defined $confs[0]->{$target}
1183 and $confs[0]->{$target} eq $data )
1184 or ( !defined $confs[0]->{$target}
1185 and defined $self->defaultValue($target)
1186 and $data eq $self->defaultValue($target) )
1187 )
1188 {
1189 $self->confChanged(1);
1190 push @{ $self->changes },
1191 {
1192 key => join( ', ', @path, $target ),
1193 old => $confs[0]->{$target} // $self->defaultValue($target),
1194 new => $confs[1]->{$target}
1195 };
1196 }
1197 };
1198 }
1199
1200 # Set old value if exists
1201 else {
1202 hdebug(" data undefined");
1203 if ( exists $confs[0]->{$target} ) {
1204 hdebug(" old value exists");
1205 $confs[1]->{$target} = $confs[0]->{$target};
1206 }
1207 else {
1208 hdebug(" no old value, skipping");
1209 }
1210 }
1211 }
1212
1213 sub defaultValue {
1214 my ( $self, $target ) = @_;
1215 hdebug("# defaultValue($target)");
1216 die unless ($target);
1217 my $res = eval {
1218 &Lemonldap::NG::Manager::Attributes::attributes()->{$target}
1219 ->{'default'};
1220 };
1221 return $res;
1222 }
1223
1224 ##@method boolean testNewConf()
1225 # Launch _unitTest() and _globaTest()
1226 #
1227 #@return true if tests succeed
1228 sub testNewConf {
1229 my ( $self, $localConf ) = @_;
1230
1231 hdebug('# testNewConf()');
1232 return $self->_unitTest( $self->newConf(), $localConf )
1233 && $self->_globalTest($localConf);
1234 }
1235
1236 ##@method private boolean _unitTest()
1237 # Launch unit tests declared in Lemonldap::NG::Manager::Build::Attributes file
1238 #
1239 #@return true if tests succeed
1240 sub _unitTest {
1241 my ( $self, $conf, $localConf ) = @_;
1242 hdebug('# _unitTest()');
1243 my $types = &Lemonldap::NG::Manager::Attributes::types();
1244 my $attrs = &Lemonldap::NG::Manager::Attributes::attributes();
1245 my $res = 1;
1246
1247 foreach my $key ( keys %$conf ) {
1248 if ( $localConf
1249 and $localConf->{skippedUnitTests}
1250 and $localConf->{skippedUnitTests} =~ /\b$key\b/ )
1251 {
1252 $localConf->logger->debug("-> Ignore test for $key\n");
1253 next;
1254 }
1255 hdebug("Testing $key");
1256 my $attr = $attrs->{$key};
1257 my $type = $types->{ $attr->{type} } if $attr;
1258 unless ( $type or $attr->{test} ) {
1259 $localConf->logger->debug("Unknown attribute $key, deleting it\n")
1260 if $localConf;
1261 delete $conf->{$key};
1262 next;
1263 }
1264
1265 # Vhost, CAS, SAML, OIDC options
1266 if ( $key =~
1267 /^(?^:(?:(?:(?:saml(?:ID|S)|oidc[OR])P|cas(?:App|Srv))MetaData|vhost)Options)$/
1268 )
1269 {
1270
1271 # Iterate on vhost names, or saml/cas/oidc configuration keys
1272 for my $vhost ( keys %{ $conf->{$key} } ) {
1273 my $options = $conf->{$key}->{$vhost};
1274 if ( ref($options) eq "HASH" ) {
1275
1276 # Recurse on option list,
1277 # FIXME this does check for oidcRPMetaDataOptionsXXX
1278 # appearing under samlSPMetadataOptions
1279 $res = 0
1280 unless $self->_unitTest( $options, $localConf,
1281 "$key/$vhost/" );
1282 }
1283 }
1284 }
1285
1286 else {
1287
1288 # Check if key exists
1289 unless ($attr) {
1290 push @{ $self->errors }, { message => "__unknownKey__: $key" };
1291 $res = 0;
1292 next;
1293 }
1294
1295 # Hash parameters
1296 if ( $key =~ /^$simpleHashKeys$/ ) {
1297 $conf->{$key} //= {};
1298 unless ( ref $conf->{$key} eq 'HASH' ) {
1299 push @{ $self->errors },
1300 { message => "$key is not a hash ref" };
1301 $res = 0;
1302 next;
1303 }
1304 }
1305 elsif ( $attr->{type} =~ /Container$/ ) {
1306
1307 #TODO
1308 }
1309 if ( $key =~ /^(?:$simpleHashKeys|$doubleHashKeys)$/
1310 or $attr->{type} =~ /Container$/ )
1311 {
1312 $res = 0
1313 unless (
1314 $self->_execTest( {
1315 keyTest => $attr->{keyTest} // $type->{keyTest},
1316 keyMsgFail => $attr->{keyMsgFail}
1317 // $type->{keyMsgFail},
1318 test => $attr->{test} // $type->{test},
1319 msgFail => $attr->{msgFail} // $type->{msgFail},
1320 },
1321 $conf->{$key},
1322 $key, $attr, undef, $conf
1323 )
1324 );
1325 }
1326 elsif ( defined $attr->{keyTest} ) {
1327
1328 #TODO
1329 }
1330 else {
1331 my $msg = $attr->{msgFail} // $type->{msgFail};
1332 $res = 0
1333 unless (
1334 $self->_execTest(
1335 $attr->{test} // $type->{test},
1336 $conf->{$key}, $key, $attr, $msg, $conf
1337 )
1338 );
1339 }
1340 }
1341 }
1342 return $res;
1343 }
1344
1345 ##@method private boolean _execTest($test, $value)
1346 # Execute the given test with value
1347 #@param test that can be a code-ref, or a regexp
1348 #@return result of test
1349 sub _execTest {
1350 my ( $self, $test, $value, $key, $attr, $msg, $conf ) = @_;
1351 my $ref;
1352 die
1353 "Malformed test for $key: only regexp ref or sub are accepted (type \"$ref\")"
1354 unless ( $ref = ref($test) and $ref =~ /^(CODE|Regexp|HASH)$/ );
1355 if ( $ref eq 'CODE' ) {
1356 my ( $r, $m ) = ( $test->( $value, $conf, $attr ) );
1357 if ($m) {
1358 push @{
1359 $self->{ (
1360 $r > 0
1361 ? 'warnings'
1362 : ( $r < 0 ? 'needConfirmation' : 'errors' )
1363 )
1364 }
1365 },
1366 { message => "$key: $m" };
1367 }
1368 elsif ( !$r ) {
1369 push @{ $self->{errors} }, { message => "$key: $msg" };
1370 }
1371 return $r;
1372 }
1373 elsif ( $ref eq 'Regexp' ) {
1374 my $r = $value =~ $test;
1375 push @{ $self->errors }, { message => "$key: $msg" } unless ($r);
1376 return $r;
1377 }
1378
1379 # Recursive test (for locationRules,...)
1380 else {
1381 my $res = 1;
1382 return $res unless ( ref($value) eq 'HASH' );
1383 foreach my $k ( keys %$value ) {
1384 $res = 0
1385 unless (
1386 $self->_execTest(
1387 $test->{keyTest}, $k, "$key/$k",
1388 $attr, $test->{keyMsgFail}, $conf
1389 )
1390 and $self->_execTest(
1391 $test->{test}, $value->{$k}, "$key/$k",
1392 $attr, $test->{msgFail}, $conf
1393 )
1394 );
1395 }
1396 return $res;
1397 }
1398 }
1399
1400 ##@method private boolean _globalTest()
1401 # Launch all tests declared in Lemonldap::NG::Manager::Conf::Tests::tests()
1402 #
1403 #@return true if tests succeed
1404 sub _globalTest {
1405 my ( $self, $localConf ) = @_;
1406
1407 require Lemonldap::NG::Manager::Conf::Tests;
1408 hdebug('# _globalTest()');
1409 my $result = 1;
1410 my $tests = &Lemonldap::NG::Manager::Conf::Tests::tests( $self->newConf );
1411
1412 foreach my $name ( keys %$tests ) {
1413 if ( $localConf
1414 and $localConf->{skippedGlobalTests}
1415 and $localConf->{skippedGlobalTests} =~ /\b$name\b/ )
1416 {
1417 $localConf->logger->debug("-> Ignore test for $name\n")
1418 if $localConf;
1419 next;
1420 }
1421 my $sub = $tests->{$name};
1422 my ( $res, $msg );
1423 eval {
1424 ( $res, $msg ) = $sub->();
1425 if ( $res == -1 ) {
1426 push @{ $self->needConfirmation }, { message => $msg };
1427 }
1428 elsif ($res) {
1429 if ($msg) {
1430 push @{ $self->warnings }, { message => $msg };
1431 }
1432 }
1433 else {
1434 $result = 0;
1435 push @{ $self->errors }, { message => $msg };
1436 }
1437 };
1438 if ($@) {
1439 push @{ $self->warnings }, "Test $name failed: $@";
1440 $localConf->logger->debug("Test $name failed: $@\n") if $localConf;
1441 }
1442 }
1443 return $result;
1444 }
1445
1446 1;
1447 __END__
1448
1449 =head1 NAME
1450
1451 =encoding utf8
1452
1453 Lemonldap::NG::Manager::Conf::Parser - Perl extension for parsing new uploaded
1454 configurations.
1455
1456 =head1 SYNOPSIS
1457
1458 require Lemonldap::NG::Manager::Conf::Parser;
1459 my $parser = Lemonldap::NG::Manager::Conf::Parser->new(
1460 { tree => $new, refConf => $self->currentConf }
1461 );
1462 my $res = { result => $parser->check };
1463 $res->{message} = $parser->{message};
1464 foreach my $t (qw(errors warnings changes)) {
1465 push @{ $res->{details} }, { message => $t, items => $parser->$t }
1466 if ( @{$parser->$t} );
1467 }
1468
1469 =head1 DESCRIPTION
1470
1471 Lemonldap::NG::Manager::Conf::Parser checks new configuration
1472
1473 This package is used by Manager to examine uploaded configuration. It is
1474 currently called using check() which return a boolean.
1475 check() looks if a newConf is available. If not, it builds it from uploaded
1476 JSON (using scanTree() subroutine)
1477
1478 Messages are stored in errors(), warnings() and changes() as arrays.
1479
1480 This interface uses L<Plack> to be compatible with CGI, FastCGI,...
1481
1482 =head1 SEE ALSO
1483
1484 L<Lemonldap::NG::Manager>, L<http://lemonldap-ng.org/>
1485
1486 =head1 AUTHORS
1487
1488 =over
1489
1490 =item LemonLDAP::NG team L<http://lemonldap-ng.org/team>
1491
1492 =back
1493
1494 =head1 BUG REPORT
1495
1496 Use OW2 system to report bug or ask for features:
1497 L<https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues>
1498
1499 If you want to report a bug concerning configuration upload, please change
1500 HIGHDEBUG constant value to produce more logs. Then post them in the Gitlab
1501 ticket.
1502
1503 =head1 DOWNLOAD
1504
1505 Lemonldap::NG is available at
1506 L<https://lemonldap-ng.org/download>
1507
1508 =head1 COPYRIGHT AND LICENSE
1509
1510 See COPYING file for details.
1511
1512 This library is free software; you can redistribute it and/or modify
1513 it under the terms of the GNU General Public License as published by
1514 the Free Software Foundation; either version 2, or (at your option)
1515 any later version.
1516
1517 This program is distributed in the hope that it will be useful,
1518 but WITHOUT ANY WARRANTY; without even the implied warranty of
1519 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1520 GNU General Public License for more details.
1521
1522 You should have received a copy of the GNU General Public License
1523 along with this program. If not, see L<http://www.gnu.org/licenses/>.
1524
1525 =cut