allow to set a display name for the server

This commit is contained in:
Roland Gruber 2016-01-03 10:56:57 +00:00
parent 410948f612
commit 856b35ae05
7 changed files with 88 additions and 11 deletions

View File

@ -4,7 +4,7 @@ $Id$
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) 2003 - 2006 Michael Duergner Copyright (C) 2003 - 2006 Michael Duergner
2003 - 2015 Roland Gruber 2003 - 2016 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
@ -187,6 +187,8 @@ $helpArray = array (
"Text" => _("This is a workaround for Active Directory. Enable it if you get messages about size limit exceeded.")), "Text" => _("This is a workaround for Active Directory. Enable it if you get messages about size limit exceeded.")),
"267" => array ("Headline" => _('Template'), "267" => array ("Headline" => _('Template'),
"Text" => _('Please select the template for the new server profile. You can either select an existing server profile or use one of the built-in templates.')), "Text" => _('Please select the template for the new server profile. You can either select an existing server profile or use one of the built-in templates.')),
"268" => array ("Headline" => _('Display name'),
"Text" => _('This name is shown on the login page as server name. Defaults to server address if empty.')),
"270" => array ("Headline" => _('Bind user and password'), "270" => array ("Headline" => _('Bind user and password'),
"Text" => _('Please enter the DN and password to use for all jobs.')), "Text" => _('Please enter the DN and password to use for all jobs.')),
"271" => array ("Headline" => _('Database type'), "271" => array ("Headline" => _('Database type'),

View File

@ -177,7 +177,7 @@ function createConfigProfile($name, $password, $template) {
if (!preg_match("/^[a-z0-9_-]+$/i", $name) || !preg_match("/^[a-z0-9\\._-]+$/i", $template) || in_array($name, getConfigProfiles())) { if (!preg_match("/^[a-z0-9_-]+$/i", $name) || !preg_match("/^[a-z0-9\\._-]+$/i", $template) || in_array($name, getConfigProfiles())) {
return _("Profile name is invalid!"); return _("Profile name is invalid!");
} }
$dir = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/"; $dir = dirname(dirname(__FILE__)) . "/config/";
// check if template exists // check if template exists
if (!is_file($dir . $template)) { if (!is_file($dir . $template)) {
return "The file config/$template was not found. Please restore it."; return "The file config/$template was not found. Please restore it.";
@ -209,7 +209,7 @@ function deleteConfigProfile($name) {
if (!preg_match("/^[a-z0-9_-]+$/i", $name)) { if (!preg_match("/^[a-z0-9_-]+$/i", $name)) {
return _("Unable to delete profile!"); return _("Unable to delete profile!");
} }
$dir = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/"; $dir = dirname(dirname(__FILE__)) . "/config/";
// delete account profiles and PDF structures // delete account profiles and PDF structures
$subDirs = array($dir . 'pdf/' . $name . '/logos', $dir . 'pdf/' . $name, $dir . 'profiles/' . $name); $subDirs = array($dir . 'pdf/' . $name . '/logos', $dir . 'pdf/' . $name, $dir . 'profiles/' . $name);
for ($i = 0; $i < sizeof($subDirs); $i++) { for ($i = 0; $i < sizeof($subDirs); $i++) {
@ -412,6 +412,9 @@ class LAMConfig {
/** Server address (e.g. ldap://127.0.0.1:389) */ /** Server address (e.g. ldap://127.0.0.1:389) */
private $ServerURL; private $ServerURL;
/** Display name of LDAP server */
private $serverDisplayName;
/** enables/disables TLS encryption */ /** enables/disables TLS encryption */
private $useTLS; private $useTLS;
@ -539,7 +542,7 @@ class LAMConfig {
/** List of all settings in config file */ /** List of all settings in config file */
private $settings = array("ServerURL", "useTLS", "followReferrals", 'pagedResults', "Passwd", "Admins", "treesuffix", private $settings = array("ServerURL", "useTLS", "followReferrals", 'pagedResults', "Passwd", "Admins", "treesuffix",
"defaultLanguage", "scriptPath", "scriptServer", "scriptRights", "cachetimeout", "defaultLanguage", "scriptPath", "scriptServer", "scriptRights", "cachetimeout", 'serverDisplayName',
"modules", "activeTypes", "types", "tools", "accessLevel", 'loginMethod', 'loginSearchSuffix', "modules", "activeTypes", "types", "tools", "accessLevel", 'loginMethod', 'loginSearchSuffix',
'loginSearchFilter', 'searchLimit', 'lamProMailFrom', 'lamProMailReplyTo', 'lamProMailSubject', 'loginSearchFilter', 'searchLimit', 'lamProMailFrom', 'lamProMailReplyTo', 'lamProMailSubject',
'lamProMailText', 'lamProMailIsHTML', 'lamProMailAllowAlternateAddress', 'httpAuthentication', 'loginSearchDN', 'lamProMailText', 'lamProMailIsHTML', 'lamProMailAllowAlternateAddress', 'httpAuthentication', 'loginSearchDN',
@ -722,6 +725,7 @@ class LAMConfig {
} }
// check if we have to add new entries (e.g. if user upgraded LAM and has an old config file) // check if we have to add new entries (e.g. if user upgraded LAM and has an old config file)
if (!in_array("ServerURL", $saved)) array_push($file_array, "\n\n# server address (e.g. ldap://localhost:389 or ldaps://localhost:636)\n" . "serverURL: " . $this->ServerURL . "\n"); if (!in_array("ServerURL", $saved)) array_push($file_array, "\n\n# server address (e.g. ldap://localhost:389 or ldaps://localhost:636)\n" . "serverURL: " . $this->ServerURL . "\n");
if (!in_array("serverDisplayName", $saved)) array_push($file_array, "\n\nserverDisplayName: " . $this->serverDisplayName . "\n");
if (!in_array("useTLS", $saved)) array_push($file_array, "\n\n# enable TLS encryption\n" . "useTLS: " . $this->useTLS . "\n"); if (!in_array("useTLS", $saved)) array_push($file_array, "\n\n# enable TLS encryption\n" . "useTLS: " . $this->useTLS . "\n");
if (!in_array("followReferrals", $saved)) array_push($file_array, "\n\n# follow referrals\n" . "followReferrals: " . $this->followReferrals . "\n"); if (!in_array("followReferrals", $saved)) array_push($file_array, "\n\n# follow referrals\n" . "followReferrals: " . $this->followReferrals . "\n");
if (!in_array("pagedResults", $saved)) array_push($file_array, "\n\n# paged results\n" . "pagedResults: " . $this->pagedResults . "\n"); if (!in_array("pagedResults", $saved)) array_push($file_array, "\n\n# paged results\n" . "pagedResults: " . $this->pagedResults . "\n");
@ -853,6 +857,39 @@ class LAMConfig {
return true; return true;
} }
/**
* Returns the server display name. Defaults to server URL if empty display name.
*
* @return string server display name
*/
public function getServerDisplayNameGUI() {
if (empty($this->serverDisplayName)) {
return $this->ServerURL;
}
return $this->serverDisplayName;
}
/**
* Returns the server display name.
*
* @return string server display name
*/
public function getServerDisplayName() {
return $this->serverDisplayName;
}
/**
* Sets the server display name
*
* @param string $value new server display name
* @return boolean true if $value has correct format
*/
public function setServerDisplayName($value) {
if (is_string($value)) $this->serverDisplayName = $value;
else return false;
return true;
}
/** /**
* Returns if TLS is activated. * Returns if TLS is activated.
* *

View File

@ -3,7 +3,7 @@
$Id$ $Id$
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) 2003 - 2014 Roland Gruber Copyright (C) 2003 - 2016 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
@ -280,6 +280,8 @@ if (isLAMProVersion()) {
// advanced options // advanced options
$advancedOptionsContent = new htmlTable(); $advancedOptionsContent = new htmlTable();
// display name
$advancedOptionsContent->addElement(new htmlTableExtendedInputField(_('Display name'), 'serverDisplayName', $conf->getServerDisplayName(), '268'), true);
// referrals // referrals
$followReferrals = ($conf->getFollowReferrals() === 'true'); $followReferrals = ($conf->getFollowReferrals() === 'true');
$advancedOptionsContent->addElement(new htmlTableExtendedInputCheckbox('followReferrals', $followReferrals , _('Follow referrals'), '205'), true); $advancedOptionsContent->addElement(new htmlTableExtendedInputCheckbox('followReferrals', $followReferrals , _('Follow referrals'), '205'), true);
@ -529,6 +531,7 @@ function checkInput() {
if (!$conf->set_ServerURL($_POST['serverurl'])) { if (!$conf->set_ServerURL($_POST['serverurl'])) {
$errors[] = array("ERROR", _("Server address is invalid!")); $errors[] = array("ERROR", _("Server address is invalid!"));
} }
$conf->setServerDisplayName($_POST['serverDisplayName']);
$conf->setUseTLS($_POST['useTLS']); $conf->setUseTLS($_POST['useTLS']);
if ((strpos($_POST['serverurl'], 'ldaps://') !== false) && ($_POST['useTLS'] == 'yes')) { if ((strpos($_POST['serverurl'], 'ldaps://') !== false) && ($_POST['useTLS'] == 'yes')) {
$errors[] = array("ERROR", _('You cannot use SSL and TLS encryption at the same time. Please use either "ldaps://" or TLS.')); $errors[] = array("ERROR", _('You cannot use SSL and TLS encryption at the same time. Please use either "ldaps://" or TLS.'));

View File

@ -4,7 +4,7 @@ $Id$
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) 2003 - 2006 Michael Duergner Copyright (C) 2003 - 2006 Michael Duergner
2005 - 2015 Roland Gruber 2005 - 2016 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
@ -464,7 +464,7 @@ function display_LoginPage($config_object, $cfgMain) {
$serverLabel->alignment = htmlElement::ALIGN_RIGHT; $serverLabel->alignment = htmlElement::ALIGN_RIGHT;
$subTable->addElement($serverLabel); $subTable->addElement($serverLabel);
$subTable->addElement($gap); $subTable->addElement($gap);
$serverName = new htmlOutputText($config_object->get_ServerURL()); $serverName = new htmlOutputText($config_object->getServerDisplayNameGUI());
$serverName->alignment = htmlElement::ALIGN_LEFT; $serverName->alignment = htmlElement::ALIGN_LEFT;
$subTable->addElement($serverName, true); $subTable->addElement($serverName, true);
// server profile // server profile

View File

@ -34,7 +34,7 @@ class LAMConfigTest extends PHPUnit_Framework_TestCase {
*/ */
private $lAMConfig; private $lAMConfig;
const FILE_NAME = 'phpunit'; const FILE_NAME = 'LAMConfigTest';
/** /**
* Prepares the environment before running a test. * Prepares the environment before running a test.
@ -60,6 +60,7 @@ class LAMConfigTest extends PHPUnit_Framework_TestCase {
deleteConfigProfile(LAMConfigTest::FILE_NAME); deleteConfigProfile(LAMConfigTest::FILE_NAME);
$profiles = getConfigProfiles(); $profiles = getConfigProfiles();
$this->assertTrue(!in_array(LAMConfigTest::FILE_NAME, $profiles)); $this->assertTrue(!in_array(LAMConfigTest::FILE_NAME, $profiles));
testDeleteDefaultConfig();
parent::tearDown(); parent::tearDown();
} }
@ -81,7 +82,7 @@ class LAMConfigTest extends PHPUnit_Framework_TestCase {
* Tests LAMConfig->getPath() * Tests LAMConfig->getPath()
*/ */
public function testGetPath() { public function testGetPath() {
$this->assertEquals(dirname(dirname(dirname(__FILE__))) . '/config/phpunit.conf', $this->lAMConfig->getPath()); $this->assertEquals(dirname(dirname(dirname(__FILE__))) . '/config/' . LAMConfigTest::FILE_NAME . '.conf', $this->lAMConfig->getPath());
} }
/** /**
@ -95,6 +96,28 @@ class LAMConfigTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($url, $this->lAMConfig->get_ServerURL()); $this->assertEquals($url, $this->lAMConfig->get_ServerURL());
} }
/**
* Tests LAMConfig->get_ServerDisplayName() and LAMConfig->set_ServerDisplayName().
*/
public function testServerDisplayName() {
$url = 'ldap://localhost:123';
$name = 'PROD';
$this->lAMConfig->set_ServerURL($url);
$this->lAMConfig->setServerDisplayName('');
$this->assertEquals('', $this->lAMConfig->getServerDisplayName());
$this->assertEquals($url, $this->lAMConfig->getServerDisplayNameGUI());
$this->doSave();
$this->assertEquals('', $this->lAMConfig->getServerDisplayName());
$this->assertEquals($url, $this->lAMConfig->getServerDisplayNameGUI());
$this->lAMConfig->setServerDisplayName($name);
$this->assertEquals($name, $this->lAMConfig->getServerDisplayNameGUI());
$this->assertEquals($name, $this->lAMConfig->getServerDisplayName());
$this->doSave();
$this->assertEquals($name, $this->lAMConfig->getServerDisplayNameGUI());
$this->assertEquals($name, $this->lAMConfig->getServerDisplayName());
}
/** /**
* Tests LAMConfig->getUseTLS() and LAMConfig->setUseTLS() * Tests LAMConfig->getUseTLS() and LAMConfig->setUseTLS()
*/ */

View File

@ -3,7 +3,7 @@
$Id$ $Id$
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) 2014 Roland Gruber Copyright (C) 2014 - 2016 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
@ -42,6 +42,14 @@ class SecurityTest extends PHPUnit_Framework_TestCase {
$this->resetPasswordRules(); $this->resetPasswordRules();
} }
/**
* Cleans up the environment after running a test.
*/
protected function tearDown() {
testDeleteDefaultConfig();
parent::tearDown();
}
public function testMinLength() { public function testMinLength() {
$this->cfg->passwordMinLength = 5; $this->cfg->passwordMinLength = 5;
$this->checkPwd(array('55555', '666666'), array('1', '22', '333', '4444')); $this->checkPwd(array('55555', '666666'), array('1', '22', '333', '4444'));

View File

@ -3,7 +3,7 @@
$Id$ $Id$
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) 2014 Roland Gruber Copyright (C) 2014 - 2016 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
@ -40,4 +40,8 @@ function testCreateDefaultConfig() {
$_SESSION['language'] = 'en_GB.utf8:UTF-8:English (Great Britain)'; $_SESSION['language'] = 'en_GB.utf8:UTF-8:English (Great Britain)';
} }
function testDeleteDefaultConfig() {
deleteConfigProfile('phpunit');
}
?> ?>