Merge branch 'develop' of git@github.com:LDAPAccountManager/lam.git into develop

This commit is contained in:
Roland Gruber 2019-10-23 18:57:10 +02:00
commit 04c00f0850
11 changed files with 248 additions and 197 deletions

View File

@ -332,6 +332,20 @@
<para><ulink <para><ulink
url="https://hub.docker.com/r/ldapaccountmanager/lampro">https://hub.docker.com/r/ldapaccountmanager/lampro</ulink></para> 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>
<section> <section>

View File

@ -1,5 +1,6 @@
<?php <?php
use \LAM\LIB\TWO_FACTOR\TwoFactorProviderService; use \LAM\LIB\TWO_FACTOR\TwoFactorProviderService;
use \LAM\REMOTE\RemoteServerConfiguration;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
@ -1450,6 +1451,30 @@ class LAMConfig {
return $this->scriptServer; 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 * Sets the servers of the external script
* *
@ -1470,21 +1495,25 @@ class LAMConfig {
// Explode name and IP, if a name exists // Explode name and IP, if a name exists
if (preg_match("/:/", $arr_value)) { if (preg_match("/:/", $arr_value)) {
$arr_value_explode = explode(":", $arr_value); $arr_value_explode = explode(":", $arr_value);
$ip = $arr_value_explode[1];
$servername = $arr_value_explode[0]; $servername = $arr_value_explode[0];
$label = $arr_value_explode[1];
$homedirPrefix = isset($arr_value_explode[2]) ? $arr_value_explode[2] : '';
} }
else { else {
$ip = $arr_value; $servername = $arr_value;
$servername = ""; $label = '';
$homedirPrefix = '';
} }
if (isset($ip) && is_string($ip) && preg_match("/^[a-z0-9-]+(\\.[a-z0-9-]+)*(,[0-9]+)?$/i", $ip)) { if (isset($servername) && is_string($servername) && preg_match("/^[a-z0-9-]+(\\.[a-z0-9-]+)*(,[0-9]+)?$/i", $servername)) {
// Check if the IP has a server name $serverData = array($servername);
if (!empty($servername)) { if (!empty($label)) {
$valid_ips[] = $servername.":".$ip; $serverData[] = $label;
} }
else { if (!empty($homedirPrefix)) {
$valid_ips[] = $ip; $serverData[] = $homedirPrefix;
} }
$serverChunk = implode(':', $serverData);
$valid_ips[] = $serverChunk;
} }
else { else {
// wrong format // wrong format
@ -1492,7 +1521,7 @@ class LAMConfig {
} }
} }
// Check that the array is not empty // Check that the array is not empty
if ($array_string > 0) { if (!empty($array_string)) {
$this->scriptServer = implode(";", $valid_ips); $this->scriptServer = implode(";", $valid_ips);
return true; return true;
} }
@ -2585,7 +2614,7 @@ class LAMCfgMain {
* @return boolean true if file was readable * @return boolean true if file was readable
*/ */
private function reload() { private function reload() {
if (is_file($this->conffile) == True) { if (is_file($this->conffile)) {
$file = @fopen($this->conffile, "r"); $file = @fopen($this->conffile, "r");
if (!$file) { if (!$file) {
return false; // abort if file is not readable return false; // abort if file is not readable

View File

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

View File

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

View File

@ -261,7 +261,7 @@ class sambaMungedDial
} }
$ctxField=""; $ctxField="";
if($this->old_behavior==true) { if($this->old_behavior) {
$ctxField= substr(base64_decode($munge), (strlen(SAMBA_MUNGEDDIAL_FILEHEADER_OLD)) / 2); $ctxField= substr(base64_decode($munge), (strlen(SAMBA_MUNGEDDIAL_FILEHEADER_OLD)) / 2);
} else { } else {
$ctxField= substr(base64_decode($munge), (strlen(SAMBA_MUNGEDDIAL_FILEHEADER)+4) / 2); $ctxField= substr(base64_decode($munge), (strlen(SAMBA_MUNGEDDIAL_FILEHEADER)+4) / 2);
@ -445,7 +445,7 @@ class sambaMungedDial
*/ */
function getShadow () function getShadow ()
{ {
if($this->old_behavior==true) { if($this->old_behavior) {
$result= substr($this->ctx['CtxCfgFlags1'], 1, 1); $result= substr($this->ctx['CtxCfgFlags1'], 1, 1);
} else { } else {
$result= substr($this->ctx['CtxShadow'], 1, 1); $result= substr($this->ctx['CtxShadow'], 1, 1);
@ -457,7 +457,7 @@ class sambaMungedDial
function setShadow ($checked, $value) function setShadow ($checked, $value)
{ {
if ($checked) { if ($checked) {
if($this->old_behavior==true) { if($this->old_behavior) {
// We need to reset the old setting // We need to reset the old setting
$this->ctx['CtxCfgFlags1'][1]= sprintf('%1X', $value); $this->ctx['CtxCfgFlags1'][1]= sprintf('%1X', $value);
} }

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

@ -329,7 +329,7 @@ function checkInput() {
} }
// check dependencies // check dependencies
$depends = check_module_depends($selected, getModulesDependencies($scope)); $depends = check_module_depends($selected, getModulesDependencies($scope));
if ($depends != false) { if ($depends !== false) {
for ($i = 0; $i < sizeof($depends); $i++) { for ($i = 0; $i < sizeof($depends); $i++) {
$errors[] = array('ERROR', $type->getAlias(), _("Unsolved dependency:") . ' ' . $errors[] = array('ERROR', $type->getAlias(), _("Unsolved dependency:") . ' ' .
$depends[$i][0] . " (" . $depends[$i][1] . ")"); $depends[$i][0] . " (" . $depends[$i][1] . ")");
@ -337,7 +337,7 @@ function checkInput() {
} }
// check conflicts // check conflicts
$conflicts = check_module_conflicts($selected, getModulesDependencies($scope)); $conflicts = check_module_conflicts($selected, getModulesDependencies($scope));
if ($conflicts != false) { if ($conflicts !== false) {
for ($i = 0; $i < sizeof($conflicts); $i++) { for ($i = 0; $i < sizeof($conflicts); $i++) {
$errors[] = array('ERROR', $type->getAlias(), _("Conflicting module:") . ' ' . $errors[] = array('ERROR', $type->getAlias(), _("Conflicting module:") . ' ' .
$conflicts[$i][0] . " (" . $conflicts[$i][1] . ")"); $conflicts[$i][0] . " (" . $conflicts[$i][1] . ")");

View File

@ -28,7 +28,7 @@ window.lam = window.lam || {};
*/ */
function list_click(box) { function list_click(box) {
var cbox = document.getElementsByName(box)[0]; var cbox = document.getElementsByName(box)[0];
if (cbox.checked == true) { if (cbox.checked) {
cbox.checked = false; cbox.checked = false;
} }
else { else {
@ -383,8 +383,10 @@ function equalWidth(elementIDs) {
// no action if invalid width value (e.g. because of hidden tab) // no action if invalid width value (e.g. because of hidden tab)
return; return;
} }
for (var i = 0; i < elementIDs.length; ++i) { for (var elementId = 0; elementId < elementIDs.length; ++elementId) {
jQuery(elementIDs[i]).css({'width': maxWidth - (jQuery(elementIDs[i]).outerWidth() - jQuery(elementIDs[i]).width())}); jQuery(elementIDs[elementId]).css({
'width': maxWidth - (jQuery(elementIDs[elementId]).outerWidth() - jQuery(elementIDs[elementId]).width())
});
} }
} }
@ -400,8 +402,10 @@ function equalHeight(elementIDs) {
max = jQuery(elementIDs[i]).height(); max = jQuery(elementIDs[i]).height();
} }
} }
for (var i = 0; i < elementIDs.length; ++i) { for (var elementId = 0; elementId < elementIDs.length; ++elementId) {
jQuery(elementIDs[i]).css({'height': max - (jQuery(elementIDs[i]).outerHeight() - jQuery(elementIDs[i]).height())}); jQuery(elementIDs[elementId]).css({
'height': max - (jQuery(elementIDs[elementId]).outerHeight() - jQuery(elementIDs[elementId]).height())
});
} }
} }
@ -567,7 +571,7 @@ function checkPasswordStrength(fieldID, ajaxURL, tokenName, tokenValue) {
*/ */
function checkPasswordStrengthHandleReply(data, fieldID) { function checkPasswordStrengthHandleReply(data, fieldID) {
var field = jQuery('#' + fieldID); var field = jQuery('#' + fieldID);
if (data.result == true) { if (data.result === true) {
field.removeClass('markFail'); field.removeClass('markFail');
field.addClass('markOk'); field.addClass('markOk');
field.prop('title', ''); field.prop('title', '');
@ -601,11 +605,11 @@ function updateModulePositions(id, oldPos, newPos) {
positions[newPos] = save; positions[newPos] = save;
} }
if (newPos < oldPos) { if (newPos < oldPos) {
var save = positions[oldPos]; var oldPosition = positions[oldPos];
for (var i = oldPos; i > newPos; i--) { for (var position = oldPos; position > newPos; position--) {
positions[i] = positions[i - 1]; positions[position] = positions[position - 1];
} }
positions[newPos] = save; positions[newPos] = oldPosition;
} }
jQuery('#' + id).val(positions.join(',')); jQuery('#' + id).val(positions.join(','));
} }

View File

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

View File

@ -279,12 +279,34 @@ class LAMConfigTest extends PHPUnit_Framework_TestCase {
public function testscriptServers() { public function testscriptServers() {
$this->assertFalse($this->lAMConfig->set_scriptServers(';;..')); $this->assertFalse($this->lAMConfig->set_scriptServers(';;..'));
$val = 'server;server'; $val = 'server;server';
$this->lAMConfig->set_scriptServers($val); $this->assertTrue($this->lAMConfig->set_scriptServers($val));
$this->assertEquals($val, $this->lAMConfig->get_scriptServers()); $this->assertEquals($val, $this->lAMConfig->get_scriptServers());
$this->doSave(); $this->doSave();
$this->assertEquals($val, $this->lAMConfig->get_scriptServers()); $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() * Tests LAMConfig->get_scriptRights() and LAMConfig->set_scriptRights()
*/ */