REPOID=`./repoid.pl .git`
SERVICES = pmgdaemon pmgproxy
+CLITOOLS = proxdb
+
+CLI_CLASSES = $(addprefix, 'PMG/API2/', $(addsuffix '.pm', ${CLITOOLS}))
+CLI_BINARIES = $(addprefix, 'bin/', ${CLITOOLS})
LIBSOURCES = \
PMG/pmgcfg.pm \
PMG/HTTPServer.pm \
PMG/Ticket.pm \
PMG/AccessControl.pm \
- PMG/API2/Network.pm \
+ PMG/CLI/proxdb.pm \
+ ${CLI_CLASSES} \
+ PMG/API2/Network.pm \
PMG/API2/Services.pm \
PMG/API2/Tasks.pm \
PMG/API2/Nodes.pm \
PMG/API2/AccessControl.pm \
PMG/API2.pm
-all: ${LIBSOURCES}
+all: ${LIBSOURCES} ${CLI_BINARIES}
.PHONY: deb
-deb ${DEB}: ${LIBSOURCES}
+deb ${DEB}: ${LIBSOURCES} ${CLI_BINARIES}
rm -rf build
rsync -a * build
cd build; dpkg-buildpackage -b -us -uc
sed -e s/@VERSION@/${PKGVER}/ -e s/@PACKAGERELEASE@/${PKGREL}/ -e s/@PACKAGE@/${PACKAGE}/ -e s/@REPOID@/${REPOID}/ $< >$@.tmp
mv $@.tmp $@
+%.bash-completion:
+ perl -I. -T -e "use PMG::CLI::$*; PMG::CLI::$*->generate_bash_completions();" >$@.tmp
+ mv $@.tmp $@
+
%.service-bash-completion:
- perl -I.. -T -e "use PMG::Service::$*; PMG::Service::$*->generate_bash_completions();" >$@.tmp
+ perl -I. -T -e "use PMG::Service::$*; PMG::Service::$*->generate_bash_completions();" >$@.tmp
mv $@.tmp $@
-install: ${BTDATA} $(addsuffix .pm, $(addprefix PMG/Service/, ${SERVICES})) $(addsuffix .service-bash-completion, ${SERVICES}) ${LIBSOURCES}
+install: ${BTDATA} $(addsuffix .pm, $(addprefix PMG/Service/, ${SERVICES})) $(addsuffix .service-bash-completion, ${SERVICES}) ${LIBSOURCES} ${CLI_BINARIES} $(addsuffix .bash-completion, ${CLITOOLS})
for i in ${SERVICES}; do perl -I. -T -e "use PMG::Service::$$i; PMG::Service::$$i->verify_api();"; done
+ for i in ${CLITOOLS}; do perl -I. -T -e "use PMG::CLI::$$i; PMG::CLI::$$i->verify_api();"; done
install -d -m 0755 ${DESTDIR}/usr/bin
install -d -m 0700 -o www-data -g www-data ${DESTDIR}/var/log/pmgproxy
install -d -m 0755 ${DOCDIR}
for i in ${SERVICES}; do install -D -m 0644 PMG/Service/$$i.pm ${PERL5DIR}/PMG/Service/$$i.pm; done
for i in ${SERVICES}; do install -m 0755 bin/$$i ${DESTDIR}/usr/bin; done
for i in ${SERVICES}; do install -m 0644 -D $$i.service-bash-completion ${BASHCOMPLDIR}/$$i; done
-
+ for i in ${CLITOOLS}; do install -D -m 0644 PMG/CLI/$$i.pm ${PERL5DIR}/PMG/CLI/$$i.pm; done
+ for i in ${CLITOOLS}; do install -D -m 0755 bin/$$i ${DESTDIR}/usr/bin/$$i; done
+ for i in ${CLITOOLS}; do install -D -m 0644 $$i.bash-completion ${BASHCOMPLDIR}/$$i; done
.PHONY: upload
upload: ${DEB}
distclean: clean
clean:
- rm -rf ./build *.deb *.changes *.buildinfo
+ rm -rf ./build *.deb *.changes *.buildinfo *.bash-completion *.service-bash-completion
if test -d .git; then rm -f PMG/pmgcfg.pm; fi
find . -name '*~' -exec rm {} ';'
--- /dev/null
+package PMG::CLI::proxdb;
+
+use strict;
+use warnings;
+use Data::Dumper;
+
+use PVE::SafeSyslog;
+use PVE::Tools qw(extract_param);
+use PVE::INotify;
+
+use base qw(PVE::CLIHandler);
+
+my $nodename = PVE::INotify::nodename();
+
+my $upid_exit = sub {
+ my $upid = shift;
+ my $status = PVE::Tools::upid_read_status($upid);
+ exit($status eq 'OK' ? 0 : -1);
+};
+
+__PACKAGE__->register_method ({
+ name => 'dump',
+ path => 'dump',
+ method => 'GET',
+ description => "Print the PMG rule database.",
+ parameters => {
+ additionalProperties => 0,
+ },
+ returns => { type => 'null'},
+ code => sub {
+ my ($param) = @_;
+
+ print "DUMP\n";
+
+ return undef;
+ }});
+
+
+__PACKAGE__->register_method ({
+ name => 'delete',
+ path => 'delete',
+ method => 'DELETE',
+ description => "Delete PMG rule database.",
+ parameters => {
+ additionalProperties => 0,
+ },
+ returns => { type => 'null'},
+ code => sub {
+ my ($param) = @_;
+
+ syslog('info', "delete rule database");
+
+ print "DELETE\n";
+
+ return undef;
+ }});
+
+
+__PACKAGE__->register_method ({
+ name => 'update',
+ path => 'update',
+ method => 'POST',
+ description => "Update or initialize PMG rule database.",
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ init => {
+ type => 'boolean',
+ description => "Initialize the database.",
+ optional => 1,
+ default => 0,
+ },
+ fail => {
+ type => 'boolean',
+ description => "Fail if databse already exists. We normally try to update and reinitialize the existing database.",
+ requires => 'init',
+ optional => 1,
+ default => 0,
+ },
+ statistics => {
+ type => 'boolean',
+ description => "Update/initialize statistic database (this is done by default).",
+ optional => 1,
+ default => 1,
+ },
+ }
+ },
+ returns => { type => 'null'},
+ code => sub {
+ my ($param) = @_;
+
+ syslog('info', "init rule database");
+
+ print "INIT\n";
+ print Dumper($param);
+
+ return undef;
+ }});
+
+
+our $cmddef = {
+ 'dump' => [ __PACKAGE__, 'dump', []],
+ delete => [ __PACKAGE__, 'delete', []],
+ update => [ __PACKAGE__, 'update', []],
+};
+
+1;