Lemonldap-NG-Manager
view release on metacpan or search on metacpan
lib/Lemonldap/NG/Manager/Build.pm view on Meta::CPAN
close F;
print STDERR "done\n";
my $ra = Regexp::Assemble->new;
foreach my $re (@ignoreKeys) {
$ra->add($re);
}
$ignoreKeys = $ra->as_string;
$reIgnoreKeys = $ra->re;
# Reinitialize $defaultValues
$defaultValues = {};
# 2. struct.json
printf STDERR $format, $self->structFile;
$mainTree = Lemonldap::NG::Manager::Build::Tree::tree();
my $jsonTree = [];
$self->scanTree( $mainTree, $jsonTree, '', '' );
$script = "\n\nfunction setScopeVars(scope) {\n";
foreach my $v (@angularScopeVars) {
$script .=
" scope.$v->[0] = scope$v->[1];\n scope.getKey(scope.$v->[0]);\n";
}
$script .= "}";
open F, ">>", $self->confTreeFile || die $!;
print F $script;
close F;
open F, ">", $self->structFile || die $!;
$jsonEnc->pretty(0);
my $tmp = $jsonEnc->encode($jsonTree);
$tmp =~ s/"(true|false)"/$1/sg;
$tmp =~ s/:\s*"(\d+)"\s*(["\}])/:$1$2/sg;
print F $tmp;
close F;
print STDERR "done\n";
$tmp = undef;
printf STDERR $format, $self->managerConstantsFile;
open F, ">", $self->managerConstantsFile or die($!);
my $exportedVars = '$'
. join( 'Keys $',
'simpleHash', 'doubleHash', 'specialNode', sort keys %cnodesRe )
. 'Keys $specialNodeHash $authParameters $issuerParameters $samlServiceParameters $oidcServiceParameters $casServiceParameters';
print F <<EOF;
# This file is generated by $module. Don't modify it by hand
package Lemonldap::NG::Common::Conf::ReConstants;
use strict;
use Exporter 'import';
use base qw(Exporter);
our \$VERSION = '$Lemonldap::NG::Manager::Build::Attributes::VERSION';
our %EXPORT_TAGS = ( 'all' => [qw($exportedVars)] );
our \@EXPORT_OK = ( \@{ \$EXPORT_TAGS{'all'} } );
our \@EXPORT = ( \@{ \$EXPORT_TAGS{'all'} } );
our \$specialNodeHash = {
virtualHosts => [qw(exportedHeaders locationRules post vhostOptions)],
samlIDPMetaDataNodes => [qw(samlIDPMetaDataXML samlIDPMetaDataExportedAttributes samlIDPMetaDataOptions)],
samlSPMetaDataNodes => [qw(samlSPMetaDataXML samlSPMetaDataExportedAttributes samlSPMetaDataOptions samlSPMetaDataMacros)],
oidcOPMetaDataNodes => [qw(oidcOPMetaDataJSON oidcOPMetaDataJWKS oidcOPMetaDataOptions oidcOPMetaDataExportedVars)],
oidcRPMetaDataNodes => [qw(oidcRPMetaDataOptions oidcRPMetaDataExportedVars oidcRPMetaDataOptionsExtraClaims oidcRPMetaDataMacros oidcRPMetaDataScopeRules)],
casSrvMetaDataNodes => [qw(casSrvMetaDataOptions casSrvMetaDataExportedVars)],
casAppMetaDataNodes => [qw(casAppMetaDataOptions casAppMetaDataExportedVars casAppMetaDataMacros)],
keyNodes => [qw(keys)],
};
EOF
# Reinitialize $attributes
$attributes = Lemonldap::NG::Manager::Build::Attributes::attributes();
$ra = Regexp::Assemble->new;
foreach (@doubleHashKeys) {
$ra->add($_);
}
print F "our \$doubleHashKeys = '" . $ra->as_string . "';\n";
$ra = Regexp::Assemble->new;
foreach (@simpleHashKeys) {
$ra->add($_);
}
print F "our \$simpleHashKeys = '"
. $ra->as_string . "';\n"
. "our \$specialNodeKeys = '${ignoreKeys}s';\n";
foreach ( sort keys %cnodesRe ) {
print F "our \$${_}Keys = '$cnodesRe{$_}';\n";
}
print F "\n";
foreach (qw(authParameters issuerParameters)) {
$tmp = "our \$$_ = {\n";
no strict 'refs';
foreach my $k ( sort keys %$$_ ) {
my $v = $$_->{$k};
$tmp .= " $k => [qw(" . join( ' ', @$v ) . ")],\n";
}
print F "$tmp};\n";
}
foreach (qw(samlServiceParameters oidcServiceParameters)) {
no strict 'refs';
$tmp = "our \$$_ = [qw(" . join( ' ', @$$_ ) . ")];\n";
print F "$tmp";
}
print F "\n1;\n";
close F;
print STDERR "done\n";
printf STDERR $format, $self->defaultValuesFile;
$defaultValues->{locationRules} = $attributes->{locationRules}->{default};
foreach ( keys %$attributes ) {
if ( not /(?:MetaData|vhost)/
and $attributes->{$_}->{default} )
{
$defaultValues->{$_} = $attributes->{$_}->{default};
}
}
my $defaultAttr = mydump( $defaultValues, 'defaultValues' );
$defaultAttr = "# This file is generated by $module. Don't modify it by hand
package Lemonldap::NG::Common::Conf::DefaultValues;
our \$VERSION = '$Lemonldap::NG::Manager::Build::Attributes::VERSION';
$defaultAttr}
1;
";
my $dst;
eval {
require Perl::Tidy;
Perl::Tidy::perltidy(
source => IO::String->new($defaultAttr),
destination => \$dst
);
};
$dst = $defaultAttr if ($@);
open( F, ">", $self->defaultValuesFile ) or die($!);
print F $dst;
close F;
print STDERR "done\n";
printf STDERR $format, $self->confConstantsFile;
$ra = Regexp::Assemble->new;
foreach ( @simpleHashKeys, @doubleHashKeys, sort keys %cnodesRe ) {
$ra->add($_);
}
foreach ( qw(
exportedHeaders locationRules post vhostOptions keys
samlIDPMetaDataXML samlIDPMetaDataExportedAttributes
samlIDPMetaDataURL samlSPMetaDataURL
samlIDPMetaDataOptions samlSPMetaDataXML
samlSPMetaDataExportedAttributes samlSPMetaDataMacros
samlSPMetaDataOptions oidcOPMetaDataJSON
oidcOPMetaDataJWKS oidcOPMetaDataOptions
oidcOPMetaDataExportedVars oidcRPMetaDataOptions
oidcRPMetaDataExportedVars oidcRPMetaDataOptionsExtraClaims
oidcRPMetaDataMacros oidcRPMetaDataScopeRules
casAppMetaDataExportedVars casAppMetaDataOptions casAppMetaDataMacros
casSrvMetaDataExportedVars casSrvMetaDataOptions
)
)
{
$ra->add($_);
}
my $sessionTypes = join( "', '", @sessionTypes );
my $confConstants =
"our \$hashParameters = qr/^" . $ra->as_string . "\$/;\n";
$ra = Regexp::Assemble->new;
foreach (@arrayParam) {
$ra->add($_);
}
# Not in Tree.pm
foreach (qw(mySessionAuthorizedRWKeys)) {
$ra->add($_);
}
$confConstants .=
"our \$arrayParameters = qr/^" . $ra->as_string . "\$/;\n";
$ra = Regexp::Assemble->new;
foreach (@bool) {
$ra->add($_);
}
$confConstants .= "our \$boolKeys = qr/^" . $ra->as_string . "\$/;\n";
open( F, ">", $self->confConstantsFile ) or die($!);
print F <<EOF;
# This file is generated by $module. Don't modify it by hand
package Lemonldap::NG::Common::Conf::Constants;
use strict;
use Exporter 'import';
use base qw(Exporter);
our \$VERSION = '$Lemonldap::NG::Manager::Build::Attributes::VERSION';
# CONSTANTS
use constant CONFIG_WAS_CHANGED => -1;
use constant UNKNOWN_ERROR => -2;
use constant DATABASE_LOCKED => -3;
use constant UPLOAD_DENIED => -4;
use constant SYNTAX_ERROR => -5;
use constant DEPRECATED => -6;
use constant DEFAULTCONFFILE => "/usr/local/lemonldap-ng/etc/lemonldap-ng.ini";
use constant DEFAULTSECTION => "all";
use constant CONFSECTION => "configuration";
use constant PORTALSECTION => "portal";
use constant HANDLERSECTION => "handler";
use constant MANAGERSECTION => "manager";
use constant SESSIONSEXPLORERSECTION => "sessionsExplorer";
use constant APPLYSECTION => "apply";
# Default configuration backend
use constant DEFAULTCONFBACKEND => "File";
use constant DEFAULTCONFBACKENDOPTIONS => (
dirName => '/usr/local/lemonldap-ng/data/conf',
);
$confConstants
lib/Lemonldap/NG/Manager/Build.pm view on Meta::CPAN
die "'form' is required when using 'group'"
unless ( $leaf->{form} );
push @$json,
{
id => "$prefix$leaf->{title}",
title => $leaf->{title},
type => $leaf->{form},
get => [ map { "${prefix}$_" } @{ $leaf->{group} } ]
};
}
# Subnode
elsif ( ref($leaf) ) {
$jleaf->{title} = $jleaf->{id} = $leaf->{title};
$jleaf->{type} = $leaf->{form} if ( $leaf->{form} );
if ( $leaf->{title} =~ /^((?:oidc|saml|cas)Service)MetaData$/ ) {
no strict 'refs';
my @tmp = $self->scanLeaf( $leaf->{nodes} );
${ $1 . 'Parameters' } = \@tmp;
}
foreach my $n (qw(nodes nodes_cond)) {
if ( $leaf->{$n} ) {
$jleaf->{"_$n"} = [];
$self->scanTree( $leaf->{$n}, $jleaf->{"_$n"}, $prefix,
"$path.$nodeName\[$ord\]" );
if ( (
$leaf->{title} eq 'authParams'
and $n eq 'nodes_cond'
)
or $leaf->{title} eq 'issuerParams'
)
{
my $vn = $leaf->{title};
$vn =~ s/Params$/Parameters/;
foreach my $sn ( @{ $leaf->{$n} } ) {
no strict 'refs';
my @cn = $self->scanLeaf( $sn->{nodes} );
${$vn}->{ $sn->{title} } = \@cn;
}
}
elsif ( $leaf->{title} eq 'issuerParams' ) {
}
if ( $n eq 'nodes_cond' ) {
foreach my $sn ( @{ $jleaf->{"_$n"} } ) {
$sn->{show} = 'false';
}
}
}
}
$jleaf->{help} = $leaf->{help} if ( $leaf->{help} );
$jleaf->{_nodes_filter} = $leaf->{nodes_filter}
if ( $leaf->{nodes_filter} );
push @$json, $jleaf;
}
# Leaf
else {
# Get data type and build tree
#
# Types : PerlModule array bool boolOrExpr catAndAppList file
# hostname int keyTextContainer lmAttrOrMacro longtext
# openidServerList oidcAttributeContainer pcre rulesContainer
# samlAssertion samlAttributeContainer samlService select text
# trool url virtualHostContainer word password
if ( $leaf =~ s/^\*// ) {
push @angularScopeVars, [ $leaf, "$path._nodes[$ord]" ];
}
if ( $leaf =~ /^(.*)(?<!notification)StorageOptions$/ ) {
push @sessionTypes, $1;
}
my $attr = $attributes->{$leaf} or die("Missing attribute $leaf");
#print STDERR "| $attr->{documentation} | $leaf |\n";
$jleaf = { id => "$prefix$leaf", title => $leaf };
unless ( $attr->{type} ) {
print STDERR "Fatal: no type: $leaf\n";
exit;
}
# TODO: change this
$attr->{type} =~
s/^(?:url|word|pcre|lmAttrOrMacro|hostname|PerlModule)$/text/;
$jleaf->{type} = $attr->{type} if ( $attr->{type} ne 'text' );
foreach my $w (qw(default help select get template)) {
$jleaf->{$w} = $attr->{$w} if ( defined $attr->{$w} );
}
if ( defined $jleaf->{default} ) {
unless ( $attr->{type} eq 'bool' and $jleaf->{default} == 0 ) {
$defaultValues->{$leaf} = $jleaf->{default};
}
if ( ref( $jleaf->{default} ) ) {
$jleaf->{default} = [];
my $type = $attr->{type};
$type =~ s/Container//;
foreach my $k ( sort keys( %{ $attr->{default} } ) ) {
# Special handling for oidcAttribute
my $default = $attr->{default}->{$k};
if ( $attr->{type} eq 'oidcAttributeContainer' ) {
$default = [ $default, "string", "auto" ];
}
push @{ $jleaf->{default} },
{
id => "$prefix$leaf/$k",
title => $k,
type => $type,
data => $default,
(
$type eq 'rule'
? ( re => $k )
: ()
),
};
}
}
}
if ($prefix) {
push @cnodesKeys, $leaf;
}
# issue 2439
# FIXME: in future versions, oidcOPMetaDataJSON and samlIDPMetaDataXML should
# behave the same
if ( $leaf =~ /^oidcOPMetaData(?:JSON|JWKS)$/ ) {
push @simpleHashKeys, $leaf;
}
if ( $attr->{type} =~ /^(?:catAndAppList|\w+Container)$/ ) {
$jleaf->{cnodes} = $prefix . $leaf;
unless ( $prefix or $leaf =~ $reIgnoreKeys ) {
push @simpleHashKeys, $leaf;
}
}
elsif ( $attr->{type} eq 'doubleHash' and $leaf !~ $reIgnoreKeys ) {
push @doubleHashKeys, $leaf;
}
else {
if ( $prefix and !$jleaf->{get} ) {
$jleaf->{get} = $prefix . $jleaf->{title};
}
( run in 1.341 second using v1.01-cache-2.11-cpan-39bf76dae61 )