From f983300fb5a9c697cebfc1de06cbacaa21011ea0 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 16 Feb 2017 12:08:00 +0100 Subject: [PATCH] pmgconfig: new CLI helper --- Makefile | 2 +- PMG/CLI/pmgconfig.pm | 68 ++++++++++++++++++++++++++++++++++++++++++++ PMG/Config.pm | 7 +++++ bin/pmgconfig | 8 ++++++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 PMG/CLI/pmgconfig.pm create mode 100644 bin/pmgconfig diff --git a/Makefile b/Makefile index 8c5508f..edbcfb1 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ BASHCOMPLDIR=${DESTDIR}/usr/share/bash-completion/completions/ REPOID=`./repoid.pl .git` SERVICES = pmgdaemon pmgproxy -CLITOOLS = pmgdb +CLITOOLS = pmgdb pmgconfig CLI_CLASSES = $(addprefix, 'PMG/API2/', $(addsuffix '.pm', ${CLITOOLS})) CLI_BINARIES = $(addprefix, 'bin/', ${CLITOOLS}) diff --git a/PMG/CLI/pmgconfig.pm b/PMG/CLI/pmgconfig.pm new file mode 100644 index 0000000..c414e5e --- /dev/null +++ b/PMG/CLI/pmgconfig.pm @@ -0,0 +1,68 @@ +package PMG::CLI::pmgconfig; + +use strict; +use warnings; +use IO::File; +use Data::Dumper; + +use PVE::SafeSyslog; +use PVE::Tools qw(extract_param); +use PVE::INotify; +use PVE::CLIHandler; + +use PMG::Cluster; +use PMG::LDAPSet; +use PMG::Config; + +use base qw(PVE::CLIHandler); + +__PACKAGE__->register_method ({ + name => 'pmgconfig', + path => 'pmgconfig', + method => 'POST', + description => "Syncronize Proxmox Mail Gateway configurations with system configuration. Prints the configuration when no options specified.", + parameters => { + additionalProperties => 0, + properties => { + syncronize => { + description => "Re-generate all configuration files.", + type => 'boolean', + default => 0, + optional => 1, + }, + ldapsync => { + description => "Re-generate ldap database.", + type => 'boolean', + default => 0, + optional => 1, + }, + }, + }, + returns => { type => 'null'}, + code => sub { + my ($param) = @_; + + my $cfg = PMG::Config->new(); + + if (!scalar(keys %$param)) { + my $raw = PMG::Config::Base->write_config('pmg.conf', $cfg); + print $raw; + return undef; + } + + if ($param->{syncronize}) { + $cfg->rewrite_config(); + return undef; + } + + if ($param->{ldapsync}) { + PMG::LDAPSet::ldap_resync($cfg, 1); + } + + return undef; + }}); + +our $cmddef = [ __PACKAGE__, 'pmgconfig', []]; + + +1; diff --git a/PMG/Config.pm b/PMG/Config.pm index ef9da51..0b956ed 100755 --- a/PMG/Config.pm +++ b/PMG/Config.pm @@ -610,4 +610,11 @@ sub rewrite_config_clam { $self->rewrite_config_file('freshclam.conf.in', '/etc/clamav/freshclam.conf'); } +sub rewrite_config { + my ($self) = @_; + + $self->rewrite_config_spam(); + $self->rewrite_config_clam(); +} + 1; diff --git a/bin/pmgconfig b/bin/pmgconfig new file mode 100644 index 0000000..1b9970e --- /dev/null +++ b/bin/pmgconfig @@ -0,0 +1,8 @@ +#!/usr/bin/perl -T + +use strict; +use warnings; + +use PMG::CLI::pmgconfig; + +PMG::CLI::pmgconfig->run_cli_handler(); -- 2.39.5