]>
git.proxmox.com Git - pmg-api.git/blob - PMG/Config.pm
1 package PMG
::Config
::Base
;
8 use PVE
::JSONSchema
qw(get_standard_option);
9 use PVE
::SectionConfig
;
11 use base
qw(PVE::SectionConfig);
15 type
=> { description
=> "Section type." },
17 description
=> "Secion ID.",
18 type
=> 'string', format
=> 'pve-configid',
27 sub format_section_header
{
28 my ($class, $type, $sectionId) = @_;
30 if ($type eq 'ldap') {
31 $sectionId =~ s/^ldap_//;
32 return "$type: $sectionId\n";
34 return "section: $type\n";
39 sub parse_section_header
{
40 my ($class, $line) = @_;
42 if ($line =~ m/^(ldap|section):\s*(\S+)\s*$/) {
43 my ($raw_type, $raw_id) = (lc($1), $2);
44 my $type = $raw_type eq 'section' ?
$raw_id : $raw_type;
45 my $section_id = "${raw_type}_${raw_id}";
46 my $errmsg = undef; # set if you want to skip whole section
47 eval { PVE
::JSONSchema
::pve_verify_configid
($raw_id); };
49 my $config = {}; # to return additional attributes
50 return ($type, $section_id, $errmsg, $config);
55 package PMG
::Config
::Administration
;
60 use base
qw(PMG::Config::Base);
63 return 'administration';
69 description
=> "Send daily reports.",
74 description
=> "Demo mode - do not start SMTP filter.",
79 description
=> "Administrator E-Mail address.",
80 type
=> 'string', format
=> 'email',
81 default => 'admin@domain.tld',
88 dailyreport
=> { optional
=> 1 },
89 demo
=> { optional
=> 1 },
93 package PMG
::Config
::Spam
;
98 use base
qw(PMG::Config::Base);
107 description
=> "This option is used to specify which languages are considered OK for incoming mail.",
109 pattern
=> '(all|([a-z][a-z])+( ([a-z][a-z])+)*)',
113 description
=> "Whether to use the naive-Bayesian-style classifier.",
117 wl_bounce_relays
=> {
118 description
=> "Whitelist legitimate bounce relays.",
122 description
=> "Additional score for bounce mails.",
129 description
=> "Enable real time blacklists (RBL) checks.",
134 description
=> "Maximum size of spam messages in bytes.",
144 wl_bounce_relays
=> { optional
=> 1 },
145 languages
=> { optional
=> 1 },
146 use_bayes
=> { optional
=> 1 },
147 bounce_score
=> { optional
=> 1 },
148 rbl_checks
=> { optional
=> 1 },
149 maxspamsize
=> { optional
=> 1 },
153 package PMG
::Config
::ClamAV
;
158 use base
qw(PMG::Config::Base);
167 description
=> "Number of files to be scanned within an archive.",
177 archivemaxfiles
=> { optional
=> 1 },
181 package PMG
::Config
::LDAP
;
186 use base
qw(PMG::Config::Base);
195 description
=> "LDAP protocol mode ('ldap' or 'ldaps').",
197 enum
=> ['ldap', 'ldaps'],
205 mode
=> { optional
=> 1 },
209 package PMG
::Config
::Mail
;
214 use PVE
::ProcFSTools
;
216 use base
qw(PMG::Config::Base);
223 sub physical_memory
{
225 return $physicalmem if $physicalmem;
227 my $info = PVE
::ProcFSTools
::read_meminfo
();
228 my $total = int($info->{memtotal
} / (1024*1024));
233 sub get_max_filters
{
234 # estimate optimal number of filter servers
238 my $memory = physical_memory
();
239 my $add_servers = int(($memory - 512)/$servermem);
240 $max_servers += $add_servers if $add_servers > 0;
241 $max_servers = 40 if $max_servers > 40;
243 return $max_servers - 2;
249 description
=> "ESMTP banner.",
252 default => 'ESMTP Proxmox',
255 description
=> "Maximum number of filter processes.",
259 default => get_max_filters
(),
262 description
=> "Hide received header in outgoing mails.",
271 banner
=> { optional
=> 1 },
272 max_filters
=> { optional
=> 1 },
273 hide_received
=> { optional
=> 1 },
286 PMG
::Config
::Administration-
>register();
287 PMG
::Config
::Mail-
>register();
288 PMG
::Config
::Spam-
>register();
289 PMG
::Config
::LDAP-
>register();
290 PMG
::Config
::ClamAV-
>register();
292 # initialize all plugins
293 PMG
::Config
::Base-
>init();
299 my $class = ref($type) || $type;
301 my $cfg = PVE
::INotify
::read_file
("pmg.conf");
303 return bless $cfg, $class;
306 # get section value or default
307 # this does not work for ldap entries
309 my ($self, $section, $key) = @_;
311 my $pdata = PMG
::Config
::Base-
>private();
312 return undef if !defined($pdata->{options
}->{$section});
313 return undef if !defined($pdata->{options
}->{$section}->{$key});
314 my $pdesc = $pdata->{propertyList
}->{$key};
315 return undef if !defined($pdesc);
317 my $configid = "section_$section";
318 if (defined($self->{ids
}->{$configid}) &&
319 defined(my $value = $self->{ids
}->{$configid}->{$key})) {
323 return $pdesc->{default};
326 # get a whole section with default value
327 # this does not work for ldap entries
329 my ($self, $section) = @_;
331 my $pdata = PMG
::Config
::Base-
>private();
332 return undef if !defined($pdata->{options
}->{$section});
336 foreach my $key (keys %{$pdata->{options
}->{$section}}) {
338 my $pdesc = $pdata->{propertyList
}->{$key};
340 my $configid = "section_$section";
341 if (defined($self->{ids
}->{$configid}) &&
342 defined(my $value = $self->{ids
}->{$configid}->{$key})) {
343 $res->{$key} = $value;
346 $res->{$key} = $pdesc->{default};
353 my ($filename, $fh) = @_;
355 local $/ = undef; # slurp mode
359 return PMG
::Config
::Base-
>parse_config($filename, $raw);
363 my ($filename, $fh, $cfg) = @_;
365 my $raw = PMG
::Config
::Base-
>write_config($filename, $cfg);
367 PVE
::Tools
::safe_print
($filename, $fh, $raw);
370 PVE
::INotify
::register_file
('pmg.conf', "/etc/proxmox/pmg.conf",