LScli : add parameter to select LDAP server and connect to it

This commit is contained in:
Benjamin Renard 2020-04-29 17:14:04 +02:00
parent 72b4c27651
commit 1ebdc91d30

View file

@ -77,6 +77,9 @@ class LScli {
echo " -q|--quiet Quiet mode\n"; echo " -q|--quiet Quiet mode\n";
echo " -d|--debug Debug mode\n"; echo " -d|--debug Debug mode\n";
echo " -C|--console Log on console\n"; echo " -C|--console Log on console\n";
echo " -S|--ldap-server Connect to a specific LDAP server: you could specify a LDAP\n";
echo " server by its declaration order in configuration (default:\n";
echo " first one).\n";
echo " -L|--load-class Load specific class to permit access to its CLI commands\n"; echo " -L|--load-class Load specific class to permit access to its CLI commands\n";
echo " -A|--load-addons Load specific addon to permit access to its CLI commands\n"; echo " -A|--load-addons Load specific addon to permit access to its CLI commands\n";
echo " command Command to run\n"; echo " command Command to run\n";
@ -107,6 +110,7 @@ class LScli {
public static function handle_args() { public static function handle_args() {
global $argv; global $argv;
$log_level = 'INFO'; $log_level = 'INFO';
$ldap_server_id = false;
$command = false; $command = false;
$command_args = array(); $command_args = array();
LSlog :: debug("handle_args :\n".varDump($argv)); LSlog :: debug("handle_args :\n".varDump($argv));
@ -135,6 +139,13 @@ class LScli {
case '--console': case '--console':
LSlog :: logOnConsole(); LSlog :: logOnConsole();
break; break;
case '-S':
case '--ldap-server':
$i++;
$ldap_server_id = intval($argv[$i]);
if(!LSsession :: setLdapServer($ldap_server_id))
self :: usage("Fail to select LDAP server #$ldap_server_id.");
break;
case '-L': case '-L':
case '--load-class': case '--load-class':
$i++; $i++;
@ -168,6 +179,12 @@ class LScli {
self :: usage(); self :: usage();
} }
// Connect to LDAP server
if ($ldap_server_id === false && !LSsession :: setLdapServer(0))
LSlog :: fatal('Fail to select first LDAP server.');
if (!LSsession :: LSldapConnect())
LSlog :: fatal('Fail to connect to LDAP server.');
// Run command // Run command
LSlog :: debug('Run '.basename($argv[0])." command $command with argument(s) '".implode("', '", $command_args)."'"); LSlog :: debug('Run '.basename($argv[0])." command $command with argument(s) '".implode("', '", $command_args)."'");
try { try {