Commit c964cec6 authored by Xavier Guimard's avatar Xavier Guimard

Finish cli (Closes: #921)

parent 2523d816
......@@ -427,21 +427,17 @@ install_bin: install_conf_dir
${SRCCOMMONDIR}/scripts/lmMigrateConfFiles2ini \
${SRCCOMMONDIR}/scripts/rotateOidcKeys \
${SRCMANAGERDIR}/scripts/lmConfigEditor \
${SRCMANAGERDIR}/scripts/lemonldap-ng-cli \
${SRCCOMMONDIR}/scripts/lemonldap-ng-cli \
$(RBINDIR)
@if [ ! "$(APACHEUSER)" ]; then \
$(PERL) -i -pe 's#__APACHEUSER__#nobody#g;' $(RBINDIR)/lmConfigEditor; \
$(PERL) -i -pe 's#__APACHEUSER__#nobody#g;' $(RBINDIR)/lemonldap-ng-cli; \
else \
$(PERL) -i -pe 's#__APACHEUSER__#$(APACHEUSER)#g;' $(RBINDIR)/lmConfigEditor; \
$(PERL) -i -pe 's#__APACHEUSER__#$(APACHEUSER)#g;' $(RBINDIR)/lemonldap-ng-cli; \
fi
@if [ ! "$(APACHEGROUP)" ]; then \
$(PERL) -i -pe 's#__APACHEGROUP__#nobody#g;' $(RBINDIR)/lmConfigEditor; \
$(PERL) -i -pe 's#__APACHEGROUP__#nobody#g;' $(RBINDIR)/lemonldap-ng-cli; \
else \
$(PERL) -i -pe 's#__APACHEGROUP__#$(APACHEGROUP)#g;' $(RBINDIR)/lmConfigEditor; \
$(PERL) -i -pe 's#__APACHEGROUP__#$(APACHEGROUP)#g;' $(RBINDIR)/lemonldap-ng-cli; \
fi
@chmod +x $(RBINDIR)/*
......@@ -894,7 +890,7 @@ debian-diff:
@$(DIFF) $(SRCMANAGERDIR)/site/static $(DIFFPREFIX)/var/lib/lemonldap-ng/manager/static ||true
@$(DIFF) $(SRCMANAGERDIR)/site/templates $(DIFFPREFIX)/var/lib/lemonldap-ng/manager/templates ||true
@$(DIFF) --ignore-matching-lines='set.*get.*\[2\]' $(SRCMANAGERDIR)/scripts/lmConfigEditor $(DIFFPREFIX)/usr/share/lemonldap-ng/bin/lmConfigEditor ||true
@$(DIFF) --ignore-matching-lines='giveUpPrivileges' $(SRCMANAGERDIR)/scripts/lemonldap-ng-cli $(DIFFPREFIX)/usr/share/lemonldap-ng/bin/lemonldap-ng-cli ||true
@$(DIFF) --ignore-matching-lines='giveUpPrivileges' $(SRCCOMMONDIR)/scripts/lemonldap-ng-cli $(DIFFPREFIX)/usr/share/lemonldap-ng/bin/lemonldap-ng-cli ||true
default-diff:
@# Portal
......@@ -924,7 +920,7 @@ default-diff:
@$(DIFF) $(SRCMANAGERDIR)/site/static $(LMPREFIX)/htdocs/manager/static ||true
@$(DIFF) $(SRCMANAGERDIR)/site/templates $(LMPREFIX)/htdocs/manager/templates ||true
@$(DIFF) --ignore-matching-lines='set.*get.*\[2\]' $(SRCMANAGERDIR)/scripts/lmConfigEditor $(LMPREFIX)/bin/lmConfigEditor ||true
@$(DIFF) --ignore-matching-lines='giveUpPrivileges' $(SRCMANAGERDIR)/scripts/lemonldap-ng-cli $(LMPREFIX)/bin/lemonldap-ng-cli ||true
@$(DIFF) --ignore-matching-lines='giveUpPrivileges' $(SRCCOMMONDIR)/scripts/lemonldap-ng-cli $(LMPREFIX)/bin/lemonldap-ng-cli ||true
test-diff:
@for file in `find lemonldap-ng-*/lib -type f`; do \
......
......@@ -11,6 +11,7 @@ lib/Lemonldap/NG/Common/Captcha.pm
lib/Lemonldap/NG/Common/CGI.pm
lib/Lemonldap/NG/Common/CGI/SOAPServer.pm
lib/Lemonldap/NG/Common/CGI/SOAPService.pm
lib/Lemonldap/NG/Common/Cli.pm
lib/Lemonldap/NG/Common/Conf.pm
lib/Lemonldap/NG/Common/Conf/_DBI.pm
lib/Lemonldap/NG/Common/Conf/CDBI.pm
......
package Lemonldap::NG::Common::Cli;
use strict;
use Mouse;
use Data::Dumper;
use Lemonldap::NG::Common::Conf;
has confAccess => (
is => 'rw',
isa => 'HashRef',
builder => sub {
my $res =
Lemonldap::NG::Common::Conf->new( { confFile => $_[0]->{iniFile} } );
die $Lemonldap::NG::Common::Conf::msg unless ($res);
return $res;
},
);
has cfgNum => (
is => 'rw',
isa => 'Int',
);
sub info {
my ($self) = @_;
my $conf = $self->confAccess( { cfgNum => $self->cfgNum, raw => 1 } )
or die $Lemonldap::NG::Common::Conf::msg;
print qq{
Num : $conf->{cfgNum}
Author : $conf->{cfgAuthor}
Author IP: $conf->{cfgAuthorIP}
Date : $conf->{cfgDate}
Log : $conf->{cfgLog}
};
}
sub updateCache {
my $self = shift;
my $conf = $self->confAccess( { noCache => 1, raw => 1 } );
die "Must not be launched as root" unless ($>);
print STDERR
qq{Cache updated to configuration $conf->{cfgNum} for user $>\n};
}
sub run {
my $self = shift;
# Options simply call corresponding accessor
my $args;
while ( $_[0] =~ s/^--?// ) {
my $k = shift;
my $v = shift;
if ( ref $self ) {
eval { $self->$k($v) };
if ($@) {
die "Unknown option -$k or bad value ($@)";
}
}
else {
$args->{$k} = $v;
}
}
unless ( ref $self ) {
$self = $self->new($args);
}
unless (@_) {
die 'nothing to do, aborting';
}
$self->confAccess()->lastCfg() unless ( $self->cfgNum );
my $action = shift;
unless ( $action =~ /^(?:info|update-cache)$/ ) {
die "unknown action $action. Only info or update are accepted";
}
$self->$action(@_);
}
1;
......@@ -3,14 +3,25 @@
use warnings;
use strict;
if ( $ARGV[0] =~ /^(?:[gs]et|(?:add|del)Key)$/ ) {
my $action;
for ( my $i = 0 ; $i < @ARGV ; $i++ ) {
if ( $ARGV[$i] =~ /^-/ ) {
$i++;
next;
}
$action = $ARGV[$i];
last;
}
if ( $action =~ /^(?:[gs]et|(?:add|del)Key)$/ ) {
eval { require Lemonldap::NG::Manager::Cli; };
die 'Manager libraries not available, aborting' if ($@);
Lemonldap::NG::Manager::Cli->run(@ARGV);
}
elsif ( $ARGV[0] =~ /^(?:info|update-cache)$/ ) {
elsif ( $action =~ /^(?:info|update-cache)$/ ) {
eval { require Lemonldap::NG::Common::Cli; };
die 'Lemonldap::NG common libraries not available, aborting' if ($@);
die "Lemonldap::NG common libraries not available, aborting ($@)" if ($@);
Lemonldap::NG::Common::Cli->run(@ARGV);
}
else {
......@@ -29,6 +40,7 @@ Available actions:
- addKey <key> <subkey> <value> : add or set a subkey in a parameter
- delKey <key> <subkey> : delete subkey of a parameter
See Lemonldap::NG::Common::Cli(3) or Lemonldap::NG::Manager::CLi(3) for more};
See Lemonldap::NG::Common::Cli(3) or Lemonldap::NG::Manager::CLi(3) for more
};
}
......@@ -26,7 +26,6 @@ ok( $resBody->{result} == 0, "JSON response contains \"result:0\"" )
ok( @{ $resBody->{details}->{__errors__} } == 1, '1 error detected' );
count(5);
print STDERR Dumper($resBody);
done_testing( count() );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment