Merge pull request #73 from LDAPAccountManager/refactoring_lamdaemon

added getConfiguredScriptServers()
This commit is contained in:
gruberroland 2019-10-22 21:26:30 +02:00 committed by GitHub
commit 21e50208ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 227 additions and 180 deletions

View File

@ -332,6 +332,20 @@
<para><ulink
url="https://hub.docker.com/r/ldapaccountmanager/lampro">https://hub.docker.com/r/ldapaccountmanager/lampro</ulink></para>
<para><emphasis role="bold">Configuration files</emphasis></para>
<para>All configuration files are stored in:</para>
<itemizedlist>
<listitem>
<para>/etc/ldap-account-manager</para>
</listitem>
<listitem>
<para>/var/lib/ldap-account-manager</para>
</listitem>
</itemizedlist>
</section>
<section>

View File

@ -1,5 +1,6 @@
<?php
use \LAM\LIB\TWO_FACTOR\TwoFactorProviderService;
use \LAM\REMOTE\RemoteServerConfiguration;
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
@ -1450,6 +1451,30 @@ class LAMConfig {
return $this->scriptServer;
}
/**
* Returns the list of configureed servers.
*
* @return RemoteServerConfiguration[] servers
*/
public function getConfiguredScriptServers() {
$servers = array();
if (empty($this->scriptServer)) {
return $servers;
}
$serverChunks = explode(';', $this->scriptServer);
foreach ($serverChunks as $serverChunk) {
if (empty($serverChunk)) {
continue;
}
$serverSettings = explode(':', $serverChunk);
$serverName = $serverSettings[0];
$serverLabel = isset($serverSettings[1]) ? $serverSettings[1] : null;
$serverHomedirPrefix = isset($serverSettings[2]) ? $serverSettings[2] : null;
$servers[] = new RemoteServerConfiguration($serverName, $serverLabel, $serverHomedirPrefix);
}
return $servers;
}
/**
* Sets the servers of the external script
*
@ -1470,21 +1495,25 @@ class LAMConfig {
// Explode name and IP, if a name exists
if (preg_match("/:/", $arr_value)) {
$arr_value_explode = explode(":", $arr_value);
$ip = $arr_value_explode[1];
$servername = $arr_value_explode[0];
$label = $arr_value_explode[1];
$homedirPrefix = isset($arr_value_explode[2]) ? $arr_value_explode[2] : '';
}
else {
$ip = $arr_value;
$servername = "";
$servername = $arr_value;
$label = '';
$homedirPrefix = '';
}
if (isset($ip) && is_string($ip) && preg_match("/^[a-z0-9-]+(\\.[a-z0-9-]+)*(,[0-9]+)?$/i", $ip)) {
// Check if the IP has a server name
if (!empty($servername)) {
$valid_ips[] = $servername.":".$ip;
if (isset($servername) && is_string($servername) && preg_match("/^[a-z0-9-]+(\\.[a-z0-9-]+)*(,[0-9]+)?$/i", $servername)) {
$serverData = array($servername);
if (!empty($label)) {
$serverData[] = $label;
}
else {
$valid_ips[] = $ip;
if (!empty($homedirPrefix)) {
$serverData[] = $homedirPrefix;
}
$serverChunk = implode(':', $serverData);
$valid_ips[] = $serverChunk;
}
else {
// wrong format
@ -1492,7 +1521,7 @@ class LAMConfig {
}
}
// Check that the array is not empty
if ($array_string > 0) {
if (!empty($array_string)) {
$this->scriptServer = implode(";", $valid_ips);
return true;
}

View File

@ -199,6 +199,11 @@ class posixAccount extends baseModule implements passwordService {
$return['upload_preDepends'] = array('inetOrgPerson');
// user specific upload options
if (($this->get_scope() == 'user') && isLoggedIn()) {
$lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers();
$lamdaemonOptions = array();
foreach ($lamdaemonServers as $lamdaemonServer) {
$lamdaemonOptions[] = $lamdaemonServer->getServer();
}
$return['upload_columns'] = array(
array(
'name' => 'posixAccount_userName',
@ -239,7 +244,7 @@ class posixAccount extends baseModule implements passwordService {
'description' => _('Create home directory'),
'help' => 'createhomedir',
'example' => 'localhost',
'values' => $_SESSION['config']->get_scriptServers()
'values' => implode(', ', $lamdaemonOptions)
),
array(
'name' => 'posixAccount_shell',
@ -702,18 +707,14 @@ class posixAccount extends baseModule implements passwordService {
$messages = array_merge($messages, $this->setExopPassword($this->moduleSettings));
// create home directories if needed
$homeDirAttr = $this->getHomedirAttrName($modules);
$lamdaemonServerList = $_SESSION['config']->getConfiguredScriptServers();
$lamdaemonServerNames = array();
foreach ($lamdaemonServerList as $lamdaemonServer) {
$lamdaemonServerNames[] = $lamdaemonServer->getServer();
}
if (sizeof($this->lamdaemonServers) > 0) {
$server = null;
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
$temp = explode(":", $lamdaemonServers[$i]);
$server = $temp[0];
if (isset($temp[1])) {
if (!in_array($temp[1], $this->lamdaemonServers)) {
continue;
}
}
elseif (!in_array($temp[0], $this->lamdaemonServers)) {
foreach ($lamdaemonServerNames as $server) {
if (!in_array($server, $this->lamdaemonServers)) {
continue;
}
$remote = new \LAM\REMOTE\Remote();
@ -746,13 +747,7 @@ class posixAccount extends baseModule implements passwordService {
// move home directory if needed
if (!empty($this->orig[$homeDirAttr][0]) && !empty($this->attributes[$homeDirAttr][0])
&& ($this->orig[$homeDirAttr][0] != $this->attributes[$homeDirAttr][0])) {
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
if (empty($lamdaemonServers[$i])) {
continue;
}
$temp = explode(":", $lamdaemonServers[$i]);
$server = $temp[0];
foreach ($lamdaemonServerNames as $server) {
$remote = new \LAM\REMOTE\Remote();
$remote->connect($server);
$result = $remote->execute(
@ -779,13 +774,7 @@ class posixAccount extends baseModule implements passwordService {
// set new group on homedirectory
if (!empty($this->orig[$homeDirAttr][0]) && !empty($this->attributes[$homeDirAttr][0])
&& ($this->orig['gidNumber'][0] != $this->attributes['gidNumber'][0])) {
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
if (empty($lamdaemonServers[$i])) {
continue;
}
$temp = explode(":", $lamdaemonServers[$i]);
$server = $temp[0];
foreach ($lamdaemonServerNames as $server) {
$remote = new \LAM\REMOTE\Remote();
$remote->connect($server);
$result = $remote->execute(
@ -941,16 +930,12 @@ class posixAccount extends baseModule implements passwordService {
$modules = $this->getAccountContainer()->get_type()->getModules();
$homeDirAttr = $this->getHomedirAttrName($modules);
// get list of lamdaemon servers
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
$temp = explode(":", $lamdaemonServers[$i]);
$lamdaemonServers[$i] = $temp[0];
}
$lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers();
// try to delete directory on all servers
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
foreach ($lamdaemonServers as $lamdaemonServer) {
$remote = new \LAM\REMOTE\Remote();
try {
$remote->connect($lamdaemonServers[$i]);
$remote->connect($lamdaemonServer->getServer());
$result = $remote->execute(
implode(
self::$SPLIT_DELIMITER,
@ -1036,7 +1021,9 @@ class posixAccount extends baseModule implements passwordService {
$this->attributes['loginShell'][0] = $_POST['loginShell'];
}
if (!$this->isBooleanConfigOptionSet('posixAccount_' . $typeId . '_hidegecos')) {
if (isset($_POST['gecos'])) $this->attributes['gecos'][0] = $_POST['gecos'];
if (isset($_POST['gecos'])) {
$this->attributes['gecos'][0] = $_POST['gecos'];
}
}
if (isset($this->orig['uid'][0]) && ($this->orig['uid'][0] != '') && (trim($_POST['uid']) != $this->attributes['uid'][0])) {
$errors[] = $this->messages['uid'][0];
@ -1067,16 +1054,11 @@ class posixAccount extends baseModule implements passwordService {
$errors[] = $errorMessage;
}
// get list of DNS names or IPs
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
$temp = explode(":", $lamdaemonServers[$i]);
if (isset($temp[1])) $lamdaemonServers[$i] = $temp[1];
else $lamdaemonServers[$i] = $temp[0];
}
$lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers();
$this->lamdaemonServers = array();
for ($h = 0; $h < sizeof($lamdaemonServers); $h++) {
if (isset($_POST['createhomedir_' . $h]) && ($_POST['createhomedir_' . $h] = 'on')) {
$this->lamdaemonServers[] = $lamdaemonServers[$h];
$this->lamdaemonServers[] = $lamdaemonServers[$h]->getServer();
}
}
if (isset($_POST['homeDirectory'])) {
@ -1483,12 +1465,11 @@ class posixAccount extends baseModule implements passwordService {
function process_homedir() {
$return = array();
// get list of lamdaemon servers
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
$lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers();
$modules = $this->getAccountContainer()->get_type()->getModules();
$homeDirAttr = $this->getHomedirAttrName($modules);
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
$temp = explode(":", $lamdaemonServers[$i]);
$server = $temp[0];
$server = $lamdaemonServers[$i]->getServer();
if (isset($_POST['form_subpage_' . get_class($this) . '_homedir_create_' . $i])) {
$remote = new \LAM\REMOTE\Remote();
$remote->connect($server);
@ -1676,21 +1657,12 @@ class posixAccount extends baseModule implements passwordService {
if (($_SESSION['config']->get_scriptPath() != null) && ($_SESSION['config']->get_scriptPath() != '')) {
if ($this->getAccountContainer()->isNewAccount) {
// get list of lamdaemon servers
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
$temp = explode(":", $lamdaemonServers[$i]);
if (isset($temp[1])) {
$lamdaemonServers[$i] = $temp[1];
}
else {
$lamdaemonServers[$i] = $temp[0];
}
}
$lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers();
$homeDirLabel = new htmlOutputText(_('Create home directory'));
$return->addLabel($homeDirLabel);
$homeServerContainer = new htmlTable();
for ($h = 0; $h < sizeof($lamdaemonServers); $h++) {
$homeServerContainer->addElement(new htmlTableExtendedInputCheckbox('createhomedir_' . $h, in_array($lamdaemonServers[$h], $this->lamdaemonServers), $lamdaemonServers[$h], null, false));
$homeServerContainer->addElement(new htmlTableExtendedInputCheckbox('createhomedir_' . $h, in_array($lamdaemonServers[$h], $this->lamdaemonServers), $lamdaemonServers[$h]->getLabel(), null, false));
if ($h === 0) {
$homeDirHelp = new htmlHelpLink('createhomedir');
$homeServerContainer->addElement($homeDirHelp);
@ -1936,14 +1908,10 @@ class posixAccount extends baseModule implements passwordService {
$return->addField(new htmlOutputText($this->attributes[$homeDirAttr][0]));
$return->addVerticalSpacer('2rem');
// get list of lamdaemon servers
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
$lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers();
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
$temp = explode(":", $lamdaemonServers[$i]);
$server = $temp[0];
$label = $temp[0];
if (isset($temp[1])) {
$label = $temp[1];
}
$server = $lamdaemonServers[$i]->getServer();
$label = $lamdaemonServers[$i]->getLabel();
$remote = new \LAM\REMOTE\Remote();
$remote->connect($server);
$result = $remote->execute(
@ -2036,14 +2004,11 @@ class posixAccount extends baseModule implements passwordService {
// lamdaemon settings
if ($_SESSION['config']->get_scriptPath() != null) {
$return->add(new htmlSubTitle(_('Create home directory')), 12);
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
$temp = explode(":", $lamdaemonServers[$i]);
if (isset($temp[1])) $lamdaemonServers[$i] = $temp[1];
else $lamdaemonServers[$i] = $temp[0];
}
$lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers();
for ($h = 0; $h < sizeof($lamdaemonServers); $h++) {
$return->add(new htmlResponsiveInputCheckbox('posixAccount_createHomedir_' . $h, in_array($lamdaemonServers[$h], $this->lamdaemonServers), $lamdaemonServers[$h], 'createhomedir', false), 12);
$server = $lamdaemonServers[$h]->getServer();
$label = $lamdaemonServers[$h]->getLabel();
$return->add(new htmlResponsiveInputCheckbox('posixAccount_createHomedir_' . $h, in_array($server, $this->lamdaemonServers), $label, 'createhomedir', false), 12);
}
}
}
@ -2090,16 +2055,11 @@ class posixAccount extends baseModule implements passwordService {
}
// lamdaemon
if (($this->get_scope() == 'user') && $this->getAccountContainer()->isNewAccount) {
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
$temp = explode(":", $lamdaemonServers[$i]);
if (isset($temp[1])) $lamdaemonServers[$i] = $temp[1];
else $lamdaemonServers[$i] = $temp[0];
}
$lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers();
$this->lamdaemonServers = array();
for ($h = 0; $h < sizeof($lamdaemonServers); $h++) {
if (isset($profile['posixAccount_createHomedir_' . $h][0]) && ($profile['posixAccount_createHomedir_' . $h][0] == 'true')) {
$this->lamdaemonServers[] = $lamdaemonServers[$h];
$this->lamdaemonServers[] = $lamdaemonServers[$h]->getServer();
}
}
}

View File

@ -183,10 +183,9 @@ class quota extends baseModule {
}
}
// get list of lamdaemon servers
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($s = 0; $s < sizeof($lamdaemonServers); $s++) {
$temp = explode(":", $lamdaemonServers[$s]);
$server = $temp[0];
$lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers();
foreach ($lamdaemonServers as $lamdaemonServer) {
$server = $lamdaemonServer->getServer();
// get quotas
$remote = new \LAM\REMOTE\Remote();
$remote->connect($server);
@ -277,14 +276,6 @@ class quota extends baseModule {
$id = $this->getCn();
}
// get list of lamdaemon servers
$serverDescriptions = array();
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($s = 0; $s < sizeof($lamdaemonServers); $s++) {
$temp = explode(":", $lamdaemonServers[$s]);
if (isset($temp[1])) {
$serverDescriptions[$temp[0]] = $temp[1];
}
}
$servers = array_keys($this->quota);
for ($q = 0; $q < sizeof($servers); $q++) {
$server = $servers[$q];
@ -366,14 +357,6 @@ class quota extends baseModule {
$id = $this->getCn();
}
// get list of lamdaemon servers
$serverDescriptions = array();
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($s = 0; $s < sizeof($lamdaemonServers); $s++) {
$temp = explode(":", $lamdaemonServers[$s]);
if (isset($temp[1])) {
$serverDescriptions[$temp[0]] = $temp[1];
}
}
$servers = array_keys($this->quota);
for ($q = 0; $q < sizeof($servers); $q++) {
$server = $servers[$q];
@ -403,14 +386,6 @@ class quota extends baseModule {
}
$errors = array();
// get list of lamdaemon servers
$serverDescriptions = array();
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($s = 0; $s < sizeof($lamdaemonServers); $s++) {
$temp = explode(":", $lamdaemonServers[$s]);
if (isset($temp[1])) {
$serverDescriptions[$temp[0]] = $temp[1];
}
}
$servers = array_keys($this->quota);
for ($q = 0; $q < sizeof($servers); $q++) {
$server = $servers[$q];
@ -467,19 +442,17 @@ class quota extends baseModule {
}
// get list of lamdaemon servers
$serverDescriptions = array();
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
$lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers();
for ($s = 0; $s < sizeof($lamdaemonServers); $s++) {
$temp = explode(":", $lamdaemonServers[$s]);
if (isset($temp[1])) {
$serverDescriptions[$temp[0]] = $temp[1];
}
$lamdaemonServer = $lamdaemonServers[$s];
$serverDescriptions[$lamdaemonServer->getServer()] = $lamdaemonServer->getLabel();
}
$servers = array_keys($this->quota);
for ($q = 0; $q < sizeof($servers); $q++) {
$server = $servers[$q];
$id = $this->replaceSpecialChars($server);
$title = $server;
if (isset($serverDescriptions[$server])) {
if ($serverDescriptions[$server] != $server) {
$title = $serverDescriptions[$server] . " (" . $server . ")";
}
$return->add(new htmlSubTitle($title), 12);
@ -544,15 +517,14 @@ class quota extends baseModule {
$return = new htmlResponsiveRow();
$optionsAvailable = false;
// get list of lamdaemon servers
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
$lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers();
try {
for ($s = 0; $s < sizeof($lamdaemonServers); $s++) {
$temp = explode(":", $lamdaemonServers[$s]);
$server = $temp[0];
foreach ($lamdaemonServers as $lamdaemonServer) {
$server = $lamdaemonServer->getServer();
$id = $this->replaceSpecialChars($server);
$description = $temp[0];
if (isset($temp[1])) {
$description = $temp[1] . ' (' . $temp[0] . ')';
$description = $lamdaemonServer->getLabel();
if ($description != $server) {
$description = $description . ' (' . $server . ')';
}
// Get quotas
$remote = new \LAM\REMOTE\Remote();
@ -614,10 +586,9 @@ class quota extends baseModule {
function check_profileOptions($options, $typeId) {
$return = array();
// get list of lamdaemon servers
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($s = 0; $s < sizeof($lamdaemonServers); $s++) {
$temp = explode(":", $lamdaemonServers[$s]);
$server = $temp[0];
$lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers();
foreach ($lamdaemonServers as $lamdaemonServer) {
$server = $lamdaemonServer->getServer();
$id = $this->replaceSpecialChars($server);
// Get quotas
$remote = new \LAM\REMOTE\Remote();
@ -717,13 +688,12 @@ class quota extends baseModule {
if (sizeof($this->quota) > 0) {
$pdfTable = new PDFTable();
// get list of lamdaemon servers
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($s = 0; $s < sizeof($lamdaemonServers); $s++) {
$temp = explode(":", $lamdaemonServers[$s]);
$server = $temp[0];
$description = $server;
if (isset($temp[1])) {
$description = $temp[1] . " (" . $server . ")";
$lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers();
foreach ($lamdaemonServers as $lamdaemonServer) {
$server = $lamdaemonServer->getServer();
$description = $lamdaemonServer->getLabel();
if ($description != $server) {
$description = $description . " (" . $server . ")";
}
if (!isset($this->quota[$server]) || (sizeof($this->quota[$server]) < 1)) {
continue;
@ -778,10 +748,9 @@ class quota extends baseModule {
$return = array();
if (sizeof($this->quota) > 0) {
// get list of lamdaemon servers
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($s = 0; $s < sizeof($lamdaemonServers); $s++) {
$temp = explode(":", $lamdaemonServers[$s]);
$server = $temp[0];
$lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers();
foreach ($lamdaemonServers as $lamdaemonServer) {
$server = $lamdaemonServer->getServer();
// Get quotas
$remote = new \LAM\REMOTE\Remote();
$remote->connect($server);

View File

@ -1542,14 +1542,11 @@ class sambaSamAccount extends baseModule implements passwordService {
$homeServerContainer = new htmlTable();
$homeServerContainer->colspan = 5;
// get list of remote servers
$remoteServers = explode(";", $_SESSION['config']->get_scriptServers());
$remoteServers = $_SESSION['config']->getConfiguredScriptServers();
for ($i = 0; $i < sizeof($remoteServers); $i++) {
$temp = explode(":", $remoteServers[$i]);
$server = $temp[0];
$label = $temp[0];
if (isset($temp[1])) {
$label = $temp[1];
}
$remoteServer = $remoteServers[$i];
$server = $remoteServer->getServer();
$label = $remoteServer->getLabel();
$remote = new \LAM\REMOTE\Remote();
$remote->connect($server);
$result = $remote->execute(
@ -1617,10 +1614,10 @@ class sambaSamAccount extends baseModule implements passwordService {
return;
}
// get list of remote servers
$remoteServers = explode(";", $_SESSION['config']->get_scriptServers());
$remoteServers = $_SESSION['config']->getConfiguredScriptServers();
for ($i = 0; $i < sizeof($remoteServers); $i++) {
$temp = explode(":", $remoteServers[$i]);
$server = $temp[0];
$remoteServer = $remoteServers[$i];
$server = $remoteServer->getServer();
if (isset($_POST['form_subpage_' . get_class($this) . '_homedir_create_' . $i])) {
$remote = new \LAM\REMOTE\Remote();
$remote->connect($server);
@ -1640,13 +1637,12 @@ class sambaSamAccount extends baseModule implements passwordService {
// remote command results
if (!empty($result)) {
$singleresult = explode(",", $result);
if (is_array($singleresult)) {
if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) {
if (is_array($singleresult)
&& (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO'))) {
$return[] = $singleresult;
}
}
}
}
elseif (isset($_POST['form_subpage_' . get_class($this) . '_homedir_delete_' . $i])) {
$remote = new \LAM\REMOTE\Remote();
$remote->connect($server);
@ -1665,14 +1661,13 @@ class sambaSamAccount extends baseModule implements passwordService {
// remote command results
if (!empty($result)) {
$singleresult = explode(",", $result);
if (is_array($singleresult)) {
if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) {
if (is_array($singleresult)
&& (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO'))) {
$return[] = $singleresult;
}
}
}
}
}
return $return;
}

View File

@ -174,4 +174,63 @@ class Remote {
}
/**
* Server configuration.
*
* @author Roland Gruber
*/
class RemoteServerConfiguration {
private $server;
private $label;
private $homeDirPrefix;
/**
* Constructor
*
* @param string $server server DNS name
* @param string $label label for GUI
* @param string $homeDirPrefix prefix for home directories
*/
public function __construct($server, $label, $homeDirPrefix) {
$this->server = $server;
$this->label = $label;
if (empty($label)) {
$this->label = $server;
}
$this->homeDirPrefix = $homeDirPrefix;
if (empty($homeDirPrefix)) {
$this->homeDirPrefix = '';
}
}
/**
* Returns the server's DNS name.
*
* @return string server name
*/
public function getServer() {
return $this->server;
}
/**
* Returns a descriptive label.
*
* @return string label
*/
public function getLabel() {
return $this->label;
}
/**
* Returns the prefix for user home directories.
*
* @return string prefix for user home directories
*/
public function getHomeDirPrefix() {
return $this->homeDirPrefix;
}
}
?>

View File

@ -15,7 +15,7 @@ use \htmlResponsiveRow;
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2006 - 2018 Roland Gruber
Copyright (C) 2006 - 2019 Roland Gruber
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -51,7 +51,9 @@ startSecureSession();
enforceUserIsLoggedIn();
// die if no write access
if (!checkIfWriteAccessIsAllowed()) die();
if (!checkIfWriteAccessIsAllowed()) {
die();
}
checkIfToolIsActive('toolTests');
@ -64,33 +66,31 @@ echo "<form action=\"lamdaemonTest.php\" method=\"post\">\n";
$container = new htmlResponsiveRow();
$container->add(new htmlTitle(_("Lamdaemon test")), 12);
$servers = explode(";", $_SESSION['config']->get_scriptServers());
$servers = $_SESSION['config']->getConfiguredScriptServers();
$serverIDs = array();
$serverTitles = array();
for ($i = 0; $i < sizeof($servers); $i++) {
$serverParts = explode(":", $servers[$i]);
$serverName = $serverParts[0];
$title = $serverName;
if (isset($serverParts[1])) {
$title = $serverParts[1] . " (" . $serverName . ")";
foreach ($servers as $server) {
$serverName = $server->getServer();
$label = $server->getLabel();
if ($label !== $serverName) {
$label = $label . " (" . $serverName . ")";
}
$serverIDs[] = $serverName;
$serverTitles[$serverName] = $title;
$serverTitles[$serverName] = $label;
}
if (isset($_POST['runTest'])) {
lamRunTestSuite($_POST['server'], $serverTitles[$_POST['server']] , isset($_POST['checkQuotas']), $container);
}
else if ((sizeof($servers) > 0) && isset($servers[0]) && ($servers[0] != '')) {
elseif (!empty($servers)) {
$serverOptions = array();
for ($i = 0; $i < sizeof($servers); $i++) {
$servers[$i] = explode(":", $servers[$i]);
$serverName = $servers[$i][0];
$title = $serverName;
if (isset($servers[$i][1])) {
$title = $servers[$i][1] . " (" . $serverName . ")";
foreach ($servers as $server) {
$serverName = $server->getServer();
$label = $server->getLabel();
if ($label !== $serverName) {
$label = $label . " (" . $serverName . ")";
}
$serverOptions[$title] = $serverName;
$serverOptions[$label] = $serverName;
}
$serverSelect = new htmlResponsiveSelect('server', $serverOptions, array(), _("Server"));
$serverSelect->setHasDescriptiveElements(true);
@ -245,7 +245,6 @@ function lamRunTestSuite($serverName, $serverTitle, $testQuota, $container) {
if (!$stopTest) {
$container->add(new htmlOutputText(_("SSH connection")), 10, 4);
flush();
$sshOk = false;
try {
$remote->connect($serverName);
$container->add(new htmlImage($okImage), 2);

View File

@ -279,12 +279,34 @@ class LAMConfigTest extends PHPUnit_Framework_TestCase {
public function testscriptServers() {
$this->assertFalse($this->lAMConfig->set_scriptServers(';;..'));
$val = 'server;server';
$this->lAMConfig->set_scriptServers($val);
$this->assertTrue($this->lAMConfig->set_scriptServers($val));
$this->assertEquals($val, $this->lAMConfig->get_scriptServers());
$this->doSave();
$this->assertEquals($val, $this->lAMConfig->get_scriptServers());
}
/**
* Tests LAMConfig->getConfiguredScriptServers().
*/
public function testGetConfiguredScriptServers() {
$val = 'server1;server2:label2;server3:label3:/prefix';
$this->assertTrue($this->lAMConfig->set_scriptServers($val));
$servers = $this->lAMConfig->getConfiguredScriptServers();
$this->assertEquals(3, sizeof($servers));
$this->doSave();
$servers = $this->lAMConfig->getConfiguredScriptServers();
$this->assertEquals(3, sizeof($servers));
$this->assertEquals('server1', $servers[0]->getServer());
$this->assertEquals('server2', $servers[1]->getServer());
$this->assertEquals('server3', $servers[2]->getServer());
$this->assertEquals('server1', $servers[0]->getLabel());
$this->assertEquals('label2', $servers[1]->getLabel());
$this->assertEquals('label3', $servers[2]->getLabel());
$this->assertEquals('', $servers[0]->getHomeDirPrefix());
$this->assertEquals('', $servers[1]->getHomeDirPrefix());
$this->assertEquals('/prefix', $servers[2]->getHomeDirPrefix());
}
/**
* Tests LAMConfig->get_scriptRights() and LAMConfig->set_scriptRights()
*/