Commit 2de9bca8 authored by Xavier Guimard's avatar Xavier Guimard

Prepare new lemonldap-ng-cli

parent ae1a0638
#!/usr/bin/env perl
use warnings;
use strict;
if ( $ARGV[0] =~ /^(?:[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)$/ ) {
eval { require Lemonldap::NG::Common::Cli; };
die 'Lemonldap::NG common libraries not available, aborting' if ($@);
Lemonldap::NG::Common::Cli->run(@ARGV);
}
else {
help();
}
sub help {
print STDERR qq{Usage: $0 <options> action <parameters>
Available actions:
- help : print this
- info : get currentconfiguration info
- update-cache : force configuration cache to be updated
- get <keys> : get values of parameters
- set <key> <value> : set parameter(s) value(s)
- 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};
}
......@@ -331,7 +331,9 @@ Using get, you can read several keys. Example:
=head1 SEE ALSO
L<Lemonldap::NG::Manager>, L<http://lemonldap-ng.org/>
For other features of llng-cli, see L<Lemonldap::NG::Common::Cli>
Other links: L<Lemonldap::NG::Manager>, L<http://lemonldap-ng.org/>
=head1 AUTHORS
......
#!/usr/bin/perl -w
use Lemonldap::NG::Manager::Cli;
use POSIX qw(setuid setgid);
use strict;
sub giveUpPrivileges {
my ( $user, $group ) = @_;
$user = "nobody" unless defined($user);
$group = "nobody" unless defined($group);
# become $user:$group and give up root privileges
setgid( ( getgrnam($group) )[2] );
setuid( ( getpwnam($user) )[2] );
# if we are still root
if ( $> == 0 ) {
print STDERR
"$0 must not be launched as root since local cache can be corrupted.\n";
print STDERR "Continue (y/N)? ";
my $res = <STDIN>;
exit 1 unless ( $res =~ /^y/i );
}
}
## main program
if ( !@ARGV ) {
print STDERR "Usage: $0 <action> <params>\n";
print STDERR "- help: list available actions\n";
print STDERR "- info: view current configuration information\n";
exit 1;
}
giveUpPrivileges( "__APACHEUSER__", "__APACHEGROUP__" );
my ( $cli, $action, $method, $ret );
$cli = new Lemonldap::NG::Manager::Cli;
# Do not increment configuration by default
$cli->{confAccess}->{cfgNumFixed} = 1;
$action = shift(@ARGV);
$method = $cli->determineMethod($action);
unless ( $cli->can($method) ) {
print STDERR "Action $action unknown\n";
print STDERR "Enter $0 help to get more information\n";
exit 1;
}
# The config is stored in ASCII
foreach(@ARGV){ utf8::decode $_; }
binmode(STDOUT, ':utf8');
@ARGV ? $cli->run( $method, @ARGV ) : $cli->run($method);
# Display error if any
if ( $cli->getError() ) {
print $cli->getError() . "\n";
exit 1;
}
# Save configuration if modified
if ( $cli->{confModified} ) {
$ret = $cli->saveConf();
print "Configuration $ret saved\n";
}
exit 0;
__END__
=head1 NAME
=encoding utf8
lemonldap-ng-cli - Command Line Interface to edit LemonLDAP::NG configuration.
=head1 SYNOPSIS
Do lemonldap-ng-cli help to get list of all commands
=head1 DESCRIPTION
lemonldap-ng-cli allow user to edit the configuration of LemonLDAP::NG via the
command line.
=head1 SEE ALSO
L<Lemonldap::NG::Manager::Cli>, L<http://lemonldap-ng.org/>
=head1 AUTHOR
David Delassus E<lt>david.jose.delassus@gmail.comE<gt>
Sandro Cazzaniga E<lt>cazzaniga.sandro@gmail.comE<gt>
Clement Oudot E<lt>clem.oudot@gmail.comE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2012, by David Delassus
Copyright (C) 2013, by Sandro Cazzaniga
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.0 or,
at your option, any later version of Perl 5 you may have available.
=cut
#!/usr/bin/env perl
use warnings;
use strict;
use Lemonldap::NG::Manager::Cli;
Lemonldap::NG::Manager::Cli->run(@ARGV);
#!/usr/bin/perl -w
use Lemonldap::NG::Manager::Cli;
use POSIX qw(setuid setgid);
use strict;
sub giveUpPrivileges {
my ( $user, $group ) = @_;
$user = "nobody" unless defined($user);
$group = "nobody" unless defined($group);
# become $user:$group and give up root privileges
setgid( ( getgrnam($group) )[2] );
setuid( ( getpwnam($user) )[2] );
# if we are still root
if ( $> == 0 ) {
print STDERR
"$0 must not be launched as root since local cache can be corrupted.\n";
print STDERR "Continue (y/N)? ";
my $res = <STDIN>;
exit 1 unless ( $res =~ /^y/i );
}
}
## main program
if ( !@ARGV ) {
print STDERR "Usage: $0 <action> <params>\n";
print STDERR "- help: list available actions\n";
print STDERR "- info: view current configuration information\n";
exit 1;
}
giveUpPrivileges( "__APACHEUSER__", "__APACHEGROUP__" );
my ( $cli, $action, $method, $ret );
$cli = new Lemonldap::NG::Manager::Cli;
# Do not increment configuration by default
$cli->{confAccess}->{cfgNumFixed} = 1;
$action = shift(@ARGV);
$method = $cli->determineMethod($action);
unless ( $cli->can($method) ) {
print STDERR "Action $action unknown\n";
print STDERR "Enter $0 help to get more information\n";
exit 1;
}
# The config is stored in ASCII
foreach(@ARGV){ utf8::decode $_; }
binmode(STDOUT, ':utf8');
@ARGV ? $cli->run( $method, @ARGV ) : $cli->run($method);
# Display error if any
if ( $cli->getError() ) {
print $cli->getError() . "\n";
exit 1;
}
# Save configuration if modified
if ( $cli->{confModified} ) {
$ret = $cli->saveConf();
print "Configuration $ret saved\n";
}
exit 0;
__END__
=head1 NAME
=encoding utf8
lemonldap-ng-cli - Command Line Interface to edit LemonLDAP::NG configuration.
=head1 SYNOPSIS
Do lemonldap-ng-cli help to get list of all commands
=head1 DESCRIPTION
lemonldap-ng-cli allow user to edit the configuration of LemonLDAP::NG via the
command line.
=head1 SEE ALSO
L<Lemonldap::NG::Manager::Cli>, L<http://lemonldap-ng.org/>
=head1 AUTHOR
David Delassus E<lt>david.jose.delassus@gmail.comE<gt>
Sandro Cazzaniga E<lt>cazzaniga.sandro@gmail.comE<gt>
Clement Oudot E<lt>clem.oudot@gmail.comE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2012, by David Delassus
Copyright (C) 2013, by Sandro Cazzaniga
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.0 or,
at your option, any later version of Perl 5 you may have available.
=cut
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