1# -*- indent-tabs-mode: nil; -*- 2# vim:ft=perl:et:sw=4 3# $Id$ 4 5# Sympa - SYsteme de Multi-Postage Automatique 6# 7# Copyright (c) 1997, 1998, 1999 Institut Pasteur & Christophe Wolfhugel 8# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 9# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites 10# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER 11# Copyright 2017, 2018, 2019, 2020 The Sympa Community. See the AUTHORS.md 12# file at the top-level directory of this distribution and at 13# <https://github.com/sympa-community/sympa.git>. 14# 15# This program is free software; you can redistribute it and/or modify 16# it under the terms of the GNU General Public License as published by 17# the Free Software Foundation; either version 2 of the License, or 18# (at your option) any later version. 19# 20# This program is distributed in the hope that it will be useful, 21# but WITHOUT ANY WARRANTY; without even the implied warranty of 22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23# GNU General Public License for more details. 24# 25# You should have received a copy of the GNU General Public License 26# along with this program. If not, see <http://www.gnu.org/licenses/>. 27 28package Sympa::ConfDef; 29 30use strict; 31use warnings; 32 33use Sympa::Config::Schema; 34 35our @params; 36 37my $group = ''; 38my @pinfo = _filter({%Sympa::Config::Schema::pinfo}); 39foreach my $item (@pinfo) { 40 if ($item->{group} and $group ne $item->{group}) { 41 $group = $item->{group}; 42 my $title = { 43 %{ $Sympa::Config::Schema::pgroup{$group} 44 // {gettext_id => $group} 45 } 46 }; 47 delete $title->{order}; 48 delete $title->{gettext_comment} unless $title->{gettext_comment}; 49 push @params, $title; 50 } 51 #delete @{$item}{qw(group order)}; 52 push @params, $item; 53} 54 55sub _filter { 56 my $pinfo = shift; 57 my $pnames = shift || []; 58 59 return map { 60 my $item = $pinfo->{$_}; 61 my $name = join '.', @$pnames, $_; 62 63 my @ret; 64 if (ref $item->{format} eq 'HASH') { 65 (_filter($item->{format}, [@$pnames, $_])); 66 } elsif ( 67 $item->{context} 68 and grep { 69 'domain' eq $_ 70 } @{$item->{context}} 71 ) { 72 my $i = { 73 %$item, 74 name => $name, 75 vhost => '1', 76 ( ( ($item->{occurrence} // '') =~ /^0/ 77 and not defined $item->{default} 78 ) ? (optional => '1') : () 79 ), 80 ( (($item->{field_type} // '') eq 'password') 81 ? (obfuscated => '1') 82 : () 83 ), 84 #edit => undef 85 }; 86 delete @{$i}{qw(file_format)}; 87 ($i); 88 } elsif ( 89 not $item->{context} 90 or grep { 91 'site' eq $_ 92 } @{$item->{context}} 93 ) { 94 my $i = { 95 %$item, 96 name => $name, 97 ( ( ($item->{occurrence} // '') =~ /^0/ 98 and not defined $item->{default} 99 ) ? (optional => '1') : () 100 ), 101 ( (($item->{field_type} // '') eq 'password') 102 ? (obfuscated => '1') 103 : () 104 ), 105 #edit => undef 106 }; 107 delete @{$i}{qw(file_format)}; 108 ($i); 109 } else { 110 (); 111 } 112 } sort { 113 by_order($pinfo, $a, $b) 114 } keys %$pinfo; 115} 116 117sub by_order { 118 my $pinfo = shift; 119 my $a = shift; 120 my $b = shift; 121 122 return ( 123 ($pinfo->{$a}->{order} // 9999) <=> ($pinfo->{$b}->{order} // 9999)) 124 || (($a // '') cmp($b // '')); 125} 126 1271; 128__END__ 129 130=encoding utf-8 131 132=head1 NAME 133 134Sympa::ConfDef - Definition of site and robot configuration parameters 135 136=head1 DESCRIPTION 137 138This module keeps definition of configuration parameters for site default 139and each robot. 140 141=head2 Global variable 142 143=over 144 145=item @params 146 147Includes items in order parameters are shown. 148It is then used to load, save, view, edit config files. 149See L<Sympa::Config::Schema> for details about the content. 150 151=back 152 153=head1 SEE ALSO 154 155L<sympa.conf(5)>, L<robot.conf(5)>. 156 157=head1 HISTORY 158 159L<confdef> was separated from L<Conf> on Sympa 6.0a, 160and renamed to L<Sympa::ConfDef> on 6.2a.39. 161On Sympa 6.2.57b, its content was moved to L<Sympa::Config::Schema>. 162 163=cut 164