pax_global_header00006660000000000000000000000064117742460230014520gustar00rootroot0000000000000052 comment=4f5fba4d0b3b922bea7848965ef730eeab81848d Lemonldap-NG-Cli-0.1/000077500000000000000000000000001177424602300143025ustar00rootroot00000000000000Lemonldap-NG-Cli-0.1/.gitignore000066400000000000000000000000061177424602300162660ustar00rootroot00000000000000*.swp Lemonldap-NG-Cli-0.1/Changes000066400000000000000000000001751177424602300156000ustar00rootroot00000000000000Revision history for Perl extension Lemonldap::NG::Cli. 0.1 Thu Jun 28 22:12:30 2012 - original version; created by h2xs Lemonldap-NG-Cli-0.1/LICENSE000066400000000000000000000004241177424602300153070ustar00rootroot00000000000000Copyright (C) 2012 David Delassus 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. Lemonldap-NG-Cli-0.1/MANIFEST000066400000000000000000000002241177424602300154310ustar00rootroot00000000000000bin/lemonldap-ng-cli Changes lib/Lemonldap/NG/Cli.pm LICENSE Makefile.PL MANIFEST This list of files META.yml README.md t/Lemonldap-NG-Cli.t TODO Lemonldap-NG-Cli-0.1/META.yml000066400000000000000000000011471177424602300155560ustar00rootroot00000000000000--- #YAML:1.0 name: Lemonldap-NG-Cli version: 0.1 abstract: Command Line Interface to edit LemonLDAP::NG configuration. author: - David Delassus license: unknown distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 build_requires: ExtUtils::MakeMaker: 0 requires: Lemonldap::NG::Common::Conf: 1 no_index: directory: - t - inc generated_by: ExtUtils::MakeMaker version 6.57_05 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 Lemonldap-NG-Cli-0.1/Makefile.PL000066400000000000000000000013321177424602300162530ustar00rootroot00000000000000use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'Lemonldap::NG::Cli', VERSION_FROM => 'lib/Lemonldap/NG/Cli.pm', # finds $VERSION PREREQ_PM => { 'Lemonldap::NG::Common::Conf' => 1.0 }, # e.g., Module::Name => 1.1 ( $] >= 5.005 ? ## Add these new keywords supported since 5.005 ( ABSTRACT_FROM => 'lib/Lemonldap/NG/Cli.pm', # retrieve abstract from module AUTHOR => 'David Delassus ' ) : () ), EXE_FILES => ['bin/lemonldap-ng-cli'] ); Lemonldap-NG-Cli-0.1/README.md000066400000000000000000000041331177424602300155620ustar00rootroot00000000000000# What is it ? This project was started by [**9h37 SAS**](http://9h37.fr) *lemonldap-ng-cli* is a command line tool to configure **LemonLDAP::NG** from the command line. Make you able to deploy your web application faster and easier. # Installation ***To be written*** # How to use Set/get variables in the configuration: ``` lemonldap-ng-cli set lemonldap-ng-cli unset lemonldap-ng-cli get ``` Define macros: ``` lemonldap-ng-cli set-macro lemonldap-ng-cli unset-macro lemonldap-ng-cli get-macro ``` Modify application list: ``` lemonldap-ng-cli apps-set-cat lemonldap-ng-cli apps-get-cat lemonldap-ng-cli apps-add lemonldap-ng-cli apps-set-uri lemonldap-ng-cli apps-set-name lemonldap-ng-cli apps-set-desc lemonldap-ng-cli apps-set-logo lemonldap-ng-cli apps-set-display lemonldap-ng-cli apps-get lemonldap-ng-cli apps-rm ``` Manage rules: ``` lemonldap-ng-cli rules-set lemonldap-ng-cli rules-unset lemonldap-ng-cli rules-get ``` Manage exported variables: ``` lemonldap-ng-cli export-var lemonldap-ng-cli unexport-var lemonldap-ng-cli get-exported-vars ``` Manage exported headers: ``` lemonldap-ng-cli export-header lemonldap-ng-cli unexport-header lemonldap-ng-cli get-exported-headers ``` Manage virtual hosts: ``` lemonldap-ng-cli vhost-add lemonldap-ng-cli vhost-del lemonldap-ng-cli vhost-set-port lemonldap-ng-cli vhost-set-https lemonldap-ng-cli vhost-set-maintenance lemonldap-ng-cli vhost-list ``` Global Storage : ``` lemonldap-ng-cli global-storage lemonldap-ng-cli global-storage-set-dir lemonldap-ng-cli global-storage-set-lockdir ``` Lemonldap-NG-Cli-0.1/TODO000066400000000000000000000001111177424602300147630ustar00rootroot00000000000000[feature] add new virtual host [feature] change domain in all attributes Lemonldap-NG-Cli-0.1/bin/000077500000000000000000000000001177424602300150525ustar00rootroot00000000000000Lemonldap-NG-Cli-0.1/bin/lemonldap-ng-cli000077500000000000000000000051561177424602300201310ustar00rootroot00000000000000#!/usr/bin/perl -w use Lemonldap::NG::Cli; use strict; my $app = Lemonldap::NG::Cli->new (); my $ret = $app->run (@ARGV); exit ($ret); __END__ =head1 NAME =encoding utf8 lemonldap-ng-cli - Command Line Interface to edit LemonLDAP::NG configuration. =head1 SYNOPSIS Set/get variables in the configuration: lemonldap-ng-cli set lemonldap-ng-cli unset lemonldap-ng-cli get Define macros: lemonldap-ng-cli set-macro lemonldap-ng-cli unset-macro lemonldap-ng-cli get-macro Modify application list: lemonldap-ng-cli apps-set-cat lemonldap-ng-cli apps-get-cat lemonldap-ng-cli apps-add lemonldap-ng-cli apps-set-uri lemonldap-ng-cli apps-set-name lemonldap-ng-cli apps-set-desc lemonldap-ng-cli apps-set-logo lemonldap-ng-cli apps-set-display lemonldap-ng-cli apps-get lemonldap-ng-cli apps-rm Manage rules: lemonldap-ng-cli rules-set lemonldap-ng-cli rules-unset lemonldap-ng-cli rules-get Manage exported variables: lemonldap-ng-cli export-var lemonldap-ng-cli unexport-var lemonldap-ng-cli get-exported-vars Manage exported headers: lemonldap-ng-cli export-header lemonldap-ng-cli unexport-header lemonldap-ng-cli get-exported-headers Manage virtual hosts: lemonldap-ng-cli vhost-add lemonldap-ng-cli vhost-del lemonldap-ng-cli vhost-set-port lemonldap-ng-cli vhost-set-https lemonldap-ng-cli vhost-set-maintenance lemonldap-ng-cli vhost-list Global Storage: lemonldap-ng-cli global-storage lemonldap-ng-cli global-storage-set-dir lemonldap-ng-cli global-storage-set-lockdir =head1 DESCRIPTION lemonldap-ng-cli allow user to edit the configuration of Lemonldap::NG via the command line. =head1 SEE ALSO L, L =head1 AUTHOR David Delassus Edavid.jose.delassus@gmail.comE =head1 COPYRIGHT AND LICENSE Copyright (C) 2012, by David Delassus 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 Lemonldap-NG-Cli-0.1/lib/000077500000000000000000000000001177424602300150505ustar00rootroot00000000000000Lemonldap-NG-Cli-0.1/lib/Lemonldap/000077500000000000000000000000001177424602300167635ustar00rootroot00000000000000Lemonldap-NG-Cli-0.1/lib/Lemonldap/NG/000077500000000000000000000000001177424602300172675ustar00rootroot00000000000000Lemonldap-NG-Cli-0.1/lib/Lemonldap/NG/Cli.pm000066400000000000000000001334151177424602300203430ustar00rootroot00000000000000package Lemonldap::NG::Cli; # Required packages use strict; use Lemonldap::NG::Common::Conf; use feature qw (switch); # Constants our $VERSION = "0.1"; my $ERRORS = { TOO_FEW_ARGUMENTS => "Too few arguments", UNKNOWN_ACTION => "Unknown action", CONFIG_WRITE_ERROR => "Error while writting the configuration", NOT_IMPLEMENTED => "Not yet implemented", }; ## @cmethod Lemonldap::NG::Cli new () # Create a new Lemonldap::NG::Cli object # # @return New Lemonldap::NG::Cli object sub new { my ($class) = @_; my $this = { "confAccess" => Lemonldap::NG::Common::Conf->new () }; $this->{conf} = $this->{confAccess}->getConf (); bless ($this, $class); return $this; } ## @method int saveConf () # Save LemonLDAP::NG configuration # # @return Configuration identifier. sub saveConf { my ($self) = @_; my $ret = $self->{confAccess}->saveConf ($self->{conf}); return $ret; } ## @method int run (array argv) # Run the application # # @param @argv List of arguments of the command line # @return Exit code sub run { my ($self, @argv) = @_; $self->{argv} = \@argv; $self->{argc} = @argv; if (!$self->parseCmd ()) { print STDERR $self->getError (), "\n"; return 1; } if (!$self->action ()) { print STDERR $self->getError (), "\n"; return 1; } if ($self->{action}->{save}) { # Save configuration my $cfgNb = $self->saveConf (); # If there is no config identifier, then an error occured if (!$cfgNb) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}); return 0; } print "Configuration $cfgNb created!\n"; } return 0; } ## @method bool parseCmd () # Parse command line # # @return true on success, false otherwise sub parseCmd { my ($self) = @_; # check if there is at least on action specified if ($self->{argc} < 1) { $self->setError ($ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } given ($self->{argv}[0]) { ## Variables when ("set") { # set takes two parameters if ($self->{argc} < 3) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $var = $self->{argv}[1]; my $val = $self->{argv}[2]; # define action $self->{action} = { type => "set", save => 1, var => $var, val => $val, }; } when ("unset") { # unset takes one parameter if ($self->{argc} < 2) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $var = $self->{argv}[1]; # define action $self->{action} = { type => "unset", save => 1, var => $var }; } when ("get") { # get takes one parameter if ($self->{argc} < 2) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $var = $self->{argv}[1]; # define action $self->{action} = { type => "get", save => 0, var => $var, }; } ## Macros when ("set-macro") { # set-macro takes two parameters if ($self->{argc} < 3) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $m_name = $self->{argv}[1]; my $m_expr = $self->{argv}[2]; # define action $self->{action} = { type => "set-macro", save => 1, name => $m_name, expr => $m_expr }; } when ("unset-macro") { # unset-macro takes one parameter if ($self->{argc} < 2) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $m_name = $self->{argv}[1]; # define action $self->{action} = { type => "unset-macro", save => 1, var => $m_name }; } when ("get-macro") { # get-macro tkaes one parameter if ($self->{argc} < 2) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $m_name = $self->{argv}[1]; # define action $self->{action} = { type => "get-macro", save => 0, name => $m_name }; } ## Applications when ("apps-set-cat") { # apps-set-cat takes two parameter if ($self->{argc} < 3) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $catid = $self->{argv}[1]; my $catname = $self->{argv}[2]; # define action $self->{action} = { type => "apps-set-cat", save => 1, id => $catid, name => $catname }; } when ("apps-get-cat") { # apps-get-cat takes one parameter if ($self->{argc} < 2) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $catid = $self->{argv}[1]; # define action $self->{action} = { type => "apps-get-cat", save => 0, id => $catid }; } when ("apps-add") { # apps-add takes two parameters if ($self->{argc} < 3) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $appid = $self->{argv}[1]; my $catid = $self->{argv}[2]; # define action $self->{action} = { type => "apps-add", save => 1, appid => $appid, catid => $catid }; } when ("apps-set-uri") { # apps-set-uri takes two parameters if ($self->{argc} < 3) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $appid = $self->{argv}[1]; my $appuri = $self->{argv}[2]; # define action $self->{action} = { type => "apps-set-uri", save => 1, id => $appid, uri => $appuri }; } when ("apps-set-name") { # apps-set-name takes two parameters if ($self->{argc} < 3) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $appid = $self->{argv}[1]; my $appname = $self->{argv}[2]; # define action $self->{action} = { type => "apps-set-name", save => 1, id => $appid, name => $appname }; } when ("apps-set-desc") { # apps-set-desc takes two parameters if ($self->{argc} < 3) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $appid = $self->{argv}[1]; my $appdesc = $self->{argv}[2]; # define action $self->{action} = { type => "apps-set-desc", save => 1, id => $appid, desc => $appdesc }; } when ("apps-set-logo") { # apps-set-logo takes two parameters if ($self->{argc} < 3) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $appid = $self->{argv}[1]; my $applogo = $self->{argv}[2]; # define action $self->{action} = { type => "apps-set-logo", save => 1, id => $appid, logo => $applogo }; } when ("apps-set-display") { # apps-set-display takes two parameters if ($self->{argc} < 3) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $appid = $self->{argv}[1]; my $appdpy = $self->{argv}[2]; # define action $self->{action} = { type => "apps-set-display", save => 1, id => $appid, dpy => $appdpy }; } when ("apps-get") { # apps-get takes one parameter if ($self->{argc} < 2) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $appid = $self->{argv}[1]; # define action $self->{action} = { type => "apps-get", save => 0, id => $appid }; } when ("apps-rm") { # apps-rm takes one parameter if ($self->{argc} < 2) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $appid = $self->{argv}[1]; # define action $self->{action} = { type => "apps-rm", save => 1, id => $appid }; } ## Rules when ("rules-set") { # rules-set takes 3 parameters if ($self->{argc} < 4) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $uri = $self->{argv}[1]; my $expr = $self->{argv}[2]; my $rule = $self->{argv}[3]; # define action $self->{action} = { type => "rules-set", save => 1, uri => $uri, expr => $expr, rule => $rule }; } when ("rules-unset") { # rules-unset takes two parameters if ($self->{argc} < 3) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $uri = $self->{argv}[1]; my $expr = $self->{argv}[2]; # define action $self->{action} = { type => "rules-unset", save => 1, uri => $uri, expr => $expr }; } when ("rules-get") { # rules-get takes one parameter if ($self->{argc} < 2) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $uri = $self->{argv}[1]; # define action $self->{action} = { type => "rules-get", save => 0, uri => $uri }; } ## exported variables when ("export-var") { # export-var takes two parameters if ($self->{argc} < 3) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $key = $self->{argv}[1]; my $val = $self->{argv}[2]; # define action $self->{action} = { type => "export-var", save => 1, key => $key, val => $val }; } when ("unexport-var") { # unexport-var takes one parameter if ($self->{argc} < 2) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $key = $self->{argv}[1]; # define action $self->{action} = { type => "unexport-var", save => 1, key => $key }; } when ("get-exported-vars") { # get-exported-varis doesn't take any parameter # define action $self->{action} = { type => "get-exported-vars", save => 0 }; } ## exported headers when ("export-header") { # export-header takes 3 parameters if ($self->{argc} < 4) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $vhost = $self->{argv}[1]; my $header = $self->{argv}[2]; my $expr = $self->{argv}[3]; # define action $self->{action} = { type => "export-header", save => 1, vhost => $vhost, header => $header, expr => $expr }; } when ("unexport-header") { # unexport-header takes two parameter if ($self->{argc} < 3) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $vhost = $self->{argv}[1]; my $header = $self->{argv}[2]; # define action $self->{action} = { type => "unexport-header", save => 1, vhost => $vhost, header => $header, }; } when ("get-exported-headers") { # get-exported-header takes one parameter if ($self->{argc} < 2) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $vhost = $self->{argv}[1]; # define action $self->{action} = { type => "get-exported-headers", save => 0, vhost => $vhost }; } ## virtual host when ("vhost-add") { # vhost-add takes one parameter if ($self->{argc} < 2) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $vhost = $self->{argv}[1]; # define action $self->{action} = { type => "vhost-add", save => 1, vhost => $vhost }; } when ("vhost-del") { # vhost-del takes one parameter if ($self->{argc} < 2) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $vhost = $self->{argv}[1]; # define action $self->{action} = { type => "vhost-del", save => 1, vhost => $vhost }; } when ("vhost-set-port") { # vhost-set-port takes two parameters if ($self->{argc} < 3) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $vhost = $self->{argv}[1]; my $port = $self->{argv}[2]; # define action $self->{action} = { type => "vhost-set-port", save => 1, vhost => $vhost, port => $port }; } when ("vhost-set-https") { # vhost-set-https takes two parameters if ($self->{argc} < 3) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $vhost = $self->{argv}[1]; my $https = $self->{argv}[2]; # define action $self->{action} = { type => "vhost-set-https", save => 1, vhost => $vhost, https => $https }; } when ("vhost-set-maintenance") { # vhost-set-maintenance takes two parameters if ($self->{argc} < 3) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $vhost = $self->{argv}[1]; my $off = $self->{argv}[2]; # define action $self->{action} = { type => "vhost-set-maintenance", save => 1, vhost => $vhost, off => $off }; } when ("vhost-list") { # vhost-list doesn't take any parameter # define action $self->{action} = { type => "vhost-list", save => 0 }; } ## global storage when ("global-storage") { # global-storage doesn't take any parameter # define action $self->{action} = { type => "global-storage", save => 0 }; } when ("global-storage-set-dir") { # global-storage takes one parameter if ($self->{argc} < 2) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $path = $self->{argv}[1]; # define action $self->{action} = { type => "global-storage-set-dir", save => 1, path => $path }; } when ("global-storage-set-lockdir") { # global-storage takes one parameter if ($self->{argc} < 2) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $path = $self->{argv}[1]; # define action $self->{action} = { type => "global-storage-set-lockdir", save => 1, path => $path }; } ## reload URLs when ("reload-urls") { # reload-urls doesn't take any parameter # define action $self->{action} = { type => "reload-urls", save => 0 }; } when ("reload-url-add") { # reload-url-add takes two parameters if ($self->{argc} < 3) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $vhost = $self->{argv}[1]; my $url = $self->{argv}[2]; # define action $self->{action} = { type => "reload-url-add", save => 0, vhost => $vhost, url => $url }; } when ("reload-url-del") { # reload-url-del takes one parameter if ($self->{argc} < 2) { $self->setError ("$_: ".$ERRORS->{TOO_FEW_ARGUMENTS}); return 0; } my $vhost = $self->{argv}[1]; # define action $self->{action} = { type => "reload-url-del", save => 0, vhost => $vhost }; } # no action found default { $self->setError ("$_: ".$ERRORS->{UNKNOWN_ACTION}); return 0; } } return 1; } ## @method bool action () # Execute action parsed by parseCmd() method # # @return true on success, false otherwise sub action { my ($self) = @_; given ($self->{action}->{type}) { ## Variables when ("set") { my $var = $self->{action}->{var}; my $val = $self->{action}->{val}; $self->{conf}->{$var} = $val; } when ("unset") { my $var = $self->{action}->{var}; if (not defined ($self->{conf}->{$var})) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": There is no variables named '$var'"); return 0; } delete $self->{conf}->{$var}; } when ("get") { my $var = $self->{action}->{var}; if (not defined ($self->{conf}->{$var})) { $self->setError ("$_: There is no variables named '$var'"); return 0; } print "$var = '", $self->{conf}->{$var}, "'\n"; } ## Macros when ("set-macro") { my $m_name = $self->{action}->{name}; my $m_expr = $self->{action}->{expr}; $self->{conf}->{macros}->{$m_name} = $m_expr; } when ("unset-macro") { my $m_name = $self->{action}->{name}; if (not defined ($self->{conf}->{macros}->{$m_name})) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": There is no macros named '$m_name'"); return 0; } delete $self->{conf}->{macros}->{$m_name}; } when ("get-macro") { my $m_name = $self->{action}->{name}; if (not defined ($self->{conf}->{macros}->{$m_name})) { $self->setError ("$_: There is no macros named '$m_name'"); return 0; } print "$m_name = '", $self->{conf}->{macros}->{$m_name}, "'\n"; } ## Applications when ("apps-set-cat") { my $catid = $self->{action}->{id}; my $catname = $self->{action}->{name}; if (defined ($self->{conf}->{applicationList}->{$catid})) { $self->{conf}->{applicationList}->{$catid}->{catname} = $catname; } else { $self->{conf}->{applicationList}->{$catid} = { type => "category", catname => $catname }; } } when ("apps-get-cat") { my $catid = $self->{action}->{id}; if (not defined ($self->{conf}->{applicationList}->{$catid})) { $self->setError ("$_: There is no category '$catid'"); return 0; } print "$catid: ", $self->{conf}->{applicationList}->{$catid}->{catname}, "\n"; } when ("apps-add") { my $appid = $self->{action}->{appid}; my $catid = $self->{action}->{catid}; if (not defined ($self->{conf}->{applicationList}->{$catid})) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": Category '$catid' doesn't exist"); return 0; } if (defined ($self->{conf}->{applicationList}->{$catid}->{$appid})) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": Application '$appid' exists"); return 0; } $self->{conf}->{applicationList}->{$catid}->{$appid} = { type => "application", options => { logo => "demo.png", name => $appid, description => $appid, display => "auto", uri => "http://test1.example.com" } }; } when ("apps-set-uri") { my $appid = $self->{action}->{id}; my $appuri = $self->{action}->{uri}; my $found = 0; while (my ($catid, $applist) = each %{$self->{conf}->{applicationList}} and $found != 1) { while (my ($_appid, $app) = each %{$applist} and $found != 1) { if ($appid eq $_appid) { $app->{options}->{uri} = $appuri; $found = 1; } } } if ($found == 0) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": Application '$appid' not found"); return 0; } } when ("apps-set-name") { my $appid = $self->{action}->{id}; my $appname = $self->{action}->{name}; my $found = 0; while (my ($catid, $applist) = each %{$self->{conf}->{applicationList}} and $found != 1) { while (my ($_appid, $app) = each %{$applist} and $found != 1) { if ($appid eq $_appid) { $app->{options}->{name} = $appname; $found = 1; } } } if ($found == 0) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": Application '$appid' not found"); return 0; } } when ("apps-set-desc") { my $appid = $self->{action}->{id}; my $appdesc = $self->{action}->{desc}; my $found = 0; while (my ($catid, $applist) = each %{$self->{conf}->{applicationList}} and $found != 1) { while (my ($_appid, $app) = each %{$applist} and $found != 1) { if ($appid eq $_appid) { $app->{options}->{description} = $appdesc; $found = 1; } } } if ($found == 0) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": Application '$appid' not found"); return 0; } } when ("apps-set-logo") { my $appid = $self->{action}->{id}; my $applogo = $self->{action}->{logo}; my $found = 0; while (my ($catid, $applist) = each %{$self->{conf}->{applicationList}} and $found != 1) { while (my ($_appid, $app) = each %{$applist} and $found != 1) { if ($appid eq $_appid) { $app->{options}->{logo} = $applogo; $found = 1; } } } if ($found == 0) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": Application '$appid' not found"); return 0; } } when ("apps-set-display") { my $appid = $self->{action}->{id}; my $appdpy = $self->{action}->{dpy}; my $found = 0; while (my ($catid, $applist) = each %{$self->{conf}->{applicationList}} and $found != 1) { while (my ($_appid, $app) = each %{$applist} and $found != 1) { if ($appid eq $_appid) { $app->{options}->{display} = $appdpy; $found = 1; } } } if ($found == 0) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": Application '$appid' not found"); return 0; } } when ("apps-get") { my $appid = $self->{action}->{id}; my $found = 0; while (my ($catid, $applist) = each %{$self->{conf}->{applicationList}} and $found != 1) { while (my ($_appid, $app) = each %{$applist} and $found != 1) { if ($appid eq $_appid) { print "Category '$catid': ".$self->{conf}->{applicationList}->{$catid}->{catname}."\n"; print "Application '$appid': ".$app->{options}->{name}."\n"; print "- Description: ".$app->{options}->{description}."\n"; print "- URI: ".$app->{options}->{uri}."\n"; print "- Logo: ".$app->{options}->{logo}."\n"; print "- Display: ".$app->{options}->{display}."\n"; $found = 1; } } } if ($found == 0) { $self->setError ("$_: Application '$appid' not found"); return 0; } } when ("apps-rm") { my $appid = $self->{action}->{id}; my $found = 0; while (my ($catid, $applist) = each %{$self->{conf}->{applicationList}} and $found != 1) { while (my ($_appid, $app) = each %{$applist} and $found != 1) { if ($appid eq $_appid) { delete $applist->{$appid}; $found = 1; } } } } ## Rules when ("rules-set") { my $uri = $self->{action}->{uri}; my $expr = $self->{action}->{expr}; my $rule = $self->{action}->{rule}; if (not defined ($self->{conf}->{locationRules}->{$uri})) { $self->{conf}->{locationRules}->{$uri} = {}; } $self->{conf}->{locationRules}->{$uri}->{$expr} = $rule; } when ("rules-unset") { my $uri = $self->{action}->{uri}; my $expr = $self->{action}->{expr}; if (not defined ($self->{conf}->{locationRules}->{$uri})) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": There is no virtual host '$uri'"); return 0; } if (not defined ($self->{conf}->{locationRules}->{$uri}->{$expr})) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": There is rule '$expr' for virtual host '$uri'"); return 0; } delete $self->{conf}->{locationRules}->{$uri}->{$expr}; } when ("rules-get") { my $uri = $self->{action}->{uri}; if (not defined ($self->{conf}->{locationRules}->{$uri})) { $self->setError ("$_: There is no virtual host '$uri'"); return 0; } print "Virtual Host : $uri\n"; while (my ($expr, $rule) = each %{$self->{conf}->{locationRules}->{$uri}}) { print "- $expr => '$rule'\n"; } } ## exported variables when ("export-var") { my $key = $self->{action}->{key}; my $val = $self->{action}->{val}; $self->{conf}->{exportedVars}->{$key} = $val; } when ("unexport-var") { my $key = $self->{action}->{key}; if (not defined ($self->{conf}->{exportedVars}->{$key})) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": There is no exported variables named '$key'"); return 0; } delete $self->{conf}->{exportedVars}->{$key}; } when ("get-exported-vars") { while (my ($key, $val) = each %{$self->{conf}->{exportedVars}}) { print "$key = $val\n"; } } ## exported headers when ("export-header") { my $vhost = $self->{action}->{vhost}; my $header = $self->{action}->{header}; my $expr = $self->{action}->{expr}; if (not defined ($self->{conf}->{exportedHeaders}->{$vhost})) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": There is no virtual host '$vhost'\n"); return 0; } $self->{conf}->{exportedHeaders}->{$vhost}->{$header} = $expr; } when ("unexport-header") { my $vhost = $self->{action}->{vhost}; my $header = $self->{action}->{header}; my $expr = $self->{action}->{expr}; if (not defined ($self->{conf}->{exportedHeaders}->{$vhost})) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": There is no virtual host '$vhost'\n"); return 0; } if (not defined ($self->{conf}->{exportedHeaders}->{$vhost}->{$header})) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": There is no header named '$header' exported for virtual host '$vhost'\n"); return 0; } delete $self->{conf}->{exportedHeaders}->{$vhost}->{$header}; } when ("get-exported-headers") { my $vhost = $self->{action}->{vhost}; if (not defined ($self->{conf}->{exportedHeaders}->{$vhost})) { $self->setError ("$_: There is no virtual host '$vhost'\n"); return 0; } while (my ($header, $expr) = each %{$self->{conf}->{exportedHeaders}->{$vhost}}) { print "$header: '$expr'\n"; } } ## virtual hosts when ("vhost-add") { my $vhost = $self->{action}->{vhost}; if (defined ($self->{conf}->{vhostOptions}->{$vhost}) or defined ($self->{conf}->{locationRules}->{$vhost}) or defined ($self->{conf}->{exportedHeaders}->{$vhost})) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": Virtual host '$vhost' already exist"); return 0; } $self->{conf}->{vhostOptions}->{$vhost} = { vhostMaintenance => '0', vhostPort => '-1', vhostHttps => '-1' }; $self->{conf}->{locationRules}->{$vhost} = { default => "deny" }; $self->{conf}->{exportedHeaders}->{$vhost} = { "Auth-User" => "\$uid" }; } when ("vhost-del") { my $vhost = $self->{action}->{vhost}; my $error = "No virtual host in: "; my $nerror = 0; if (not defined ($self->{conf}->{vhostOptions}->{$vhost})) { $nerror++; $error .= "vhostOptions "; } else { delete $self->{conf}->{vhostOptions}->{$vhost}; } if (not defined ($self->{conf}->{locationRules}->{$vhost})) { $nerror++; $error .= "locationRules "; } else { delete $self->{conf}->{locationRules}->{$vhost}; } if (not defined ($self->{conf}->{exportedHeaders}->{$vhost})) { $nerror++; $error .= "exportedHeaders"; } else { delete $self->{conf}->{exportedHeaders}->{$vhost}; } if ($nerror == 3) { $error .= ". abortting..."; $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": $error"); return 0; } elsif ($nerror != 0) { $error .= ". ignoring..."; $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": $error"); } } when ("vhost-set-port") { my $vhost = $self->{action}->{vhost}; my $port = $self->{action}->{port}; if (not defined ($self->{conf}->{vhostOptions}->{$vhost})) { if (not defined ($self->{conf}->{locationRules}->{$vhost}) and not defined ($self->{conf}->{exportedHeaders}->{$vhost})) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": There is no virtual host '$vhost'"); return 0; } else { $self->{conf}->{vhostOptions}->{$vhost} = { vhostPort => $port, vhostHttps => '-1', vhostMaintenance => '0' }; } } else { $self->{conf}->{vhostOptions}->{$vhost}->{vhostPort} = $port; } } when ("vhost-set-https") { my $vhost = $self->{action}->{vhost}; my $https = $self->{action}->{https}; if (not defined ($self->{conf}->{vhostOptions}->{$vhost})) { if (not defined ($self->{conf}->{locationRules}->{$vhost}) and not defined ($self->{conf}->{exportedHeaders}->{$vhost})) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": There is no virtual host '$vhost'"); return 0; } else { $self->{conf}->{vhostOptions}->{$vhost} = { vhostPort => '-1', vhostHttps => $https, vhostMaintenance => '0' }; } } else { $self->{conf}->{vhostOptions}->{$vhost}->{vhostHttps} = $https; } } when ("vhost-set-maintenance") { my $vhost = $self->{action}->{vhost}; my $off = $self->{action}->{off}; if (not defined ($self->{conf}->{vhostOptions}->{$vhost})) { if (not defined ($self->{conf}->{locationRules}->{$vhost}) and not defined ($self->{conf}->{exportedHeaders}->{$vhost})) { $self->setError ("$_: ".$ERRORS->{CONFIG_WRITE_ERROR}.": There is no virtual host '$vhost'"); return 0; } else { $self->{conf}->{vhostOptions}->{$vhost} = { vhostPort => '-1', vhostHttps => '-1', vhostMaintenance => $off }; } } else { $self->{conf}->{vhostOptions}->{$vhost}->{vhostMaintenance} = $off; } } when ("vhost-list") { while (my ($vhost, $vhostoptions) = each %{$self->{conf}->{vhostOptions}}) { print "- $vhost => "; print "Maintenance: $vhostoptions->{vhostMaintenance} | "; print "Port: $vhostoptions->{vhostPort} | "; print "HTTPS: $vhostoptions->{vhostHttps}\n"; } } ## global storage when ("global-storage") { print "Global Storage options :\n"; print "- Directory: $self->{conf}->{globalStorageOptions}->{Directory}\n"; print "- Lock Directory: $self->{conf}->{globalStorageOptions}->{LockDirectory}\n"; } when ("global-storage-set-dir") { my $path = $self->{action}->{path}; $self->{conf}->{globalStorageOptions}->{Directory} = $path; } when ("global-storage-set-lockdir") { my $path = $self->{action}->{path}; $self->{conf}->{globalStorageOptions}->{LockDirectory} = $path; } # no implementation found default { $self->setError ("$_: ".$ERRORS->{NOT_IMPLEMENTED}); return 0; } } return 1; } ## @method void setError (string str) # Set error message # # @param str Text of the error sub setError { my ($self, $msg) = @_; $self->{errormsg} = $msg; } ## @method string getError () # Get error message # # @return Text of the error sub getError { my ($self) = @_; my $msg = $self->{errormsg}; return $msg; } 1; __END__ =head1 NAME =encoding utf8 Lemonldap::NG::Cli - Command Line Interface to edit LemonLDAP::NG configuration. =head1 SYNOPSIS use Lemonldap::NG::Cli; my $app = Lemonldap::NG::Cli->new (); my $ret = $app->run (\@ARGV); exit ($ret); =head1 DESCRIPTION Lemonldap::NG::Cli allow user to edit the configuration of Lemonldap::NG via the command line. =head1 SEE ALSO L, L =head1 AUTHOR David Delassus Edavid.jose.delassus@gmail.comE =head1 COPYRIGHT AND LICENSE Copyright (C) 2012, by David Delassus 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 Lemonldap-NG-Cli-0.1/t/000077500000000000000000000000001177424602300145455ustar00rootroot00000000000000Lemonldap-NG-Cli-0.1/t/Lemonldap-NG-Cli.t000066400000000000000000000007771177424602300176670ustar00rootroot00000000000000# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl Lemonldap-NG-Cli.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use strict; use warnings; use Test::More tests => 1; BEGIN { use_ok('Lemonldap::NG::Cli') }; ######################### # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script.