]> git.proxmox.com Git - pmg-api.git/commitdiff
pmgconfig: new CLI helper
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 16 Feb 2017 11:08:00 +0000 (12:08 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 16 Feb 2017 11:08:56 +0000 (12:08 +0100)
Makefile
PMG/CLI/pmgconfig.pm [new file with mode: 0644]
PMG/Config.pm
bin/pmgconfig [new file with mode: 0644]

index 8c5508f1534e8cacb4e0387e8a076f916c917620..edbcfb1b24a6b4cff4e836abee0ff4529ad7440f 100644 (file)
--- 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 (file)
index 0000000..c414e5e
--- /dev/null
@@ -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;
index ef9da510a7921910bc65f96ab957610d664c4c20..0b956ed9611b17d0ee4cd79f99e75248d8c6faa3 100755 (executable)
@@ -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 (file)
index 0000000..1b9970e
--- /dev/null
@@ -0,0 +1,8 @@
+#!/usr/bin/perl -T
+
+use strict;
+use warnings;
+
+use PMG::CLI::pmgconfig;
+
+PMG::CLI::pmgconfig->run_cli_handler();