diff --git a/lam/help/help.inc b/lam/help/help.inc index 9daf477f..5f15f8b5 100644 --- a/lam/help/help.inc +++ b/lam/help/help.inc @@ -4,7 +4,7 @@ $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) 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 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.")), "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.')), + "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'), "Text" => _('Please enter the DN and password to use for all jobs.')), "271" => array ("Headline" => _('Database type'), diff --git a/lam/lib/config.inc b/lam/lib/config.inc index 9c0ba826..9b98b3a2 100644 --- a/lam/lib/config.inc +++ b/lam/lib/config.inc @@ -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())) { return _("Profile name is invalid!"); } - $dir = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/"; + $dir = dirname(dirname(__FILE__)) . "/config/"; // check if template exists if (!is_file($dir . $template)) { 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)) { return _("Unable to delete profile!"); } - $dir = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/"; + $dir = dirname(dirname(__FILE__)) . "/config/"; // delete account profiles and PDF structures $subDirs = array($dir . 'pdf/' . $name . '/logos', $dir . 'pdf/' . $name, $dir . 'profiles/' . $name); for ($i = 0; $i < sizeof($subDirs); $i++) { @@ -412,6 +412,9 @@ class LAMConfig { /** Server address (e.g. ldap://127.0.0.1:389) */ private $ServerURL; + /** Display name of LDAP server */ + private $serverDisplayName; + /** enables/disables TLS encryption */ private $useTLS; @@ -539,7 +542,7 @@ class LAMConfig { /** List of all settings in config file */ 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', 'loginSearchFilter', 'searchLimit', 'lamProMailFrom', 'lamProMailReplyTo', 'lamProMailSubject', '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) 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("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"); @@ -853,6 +857,39 @@ class LAMConfig { 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. * diff --git a/lam/templates/config/confmain.php b/lam/templates/config/confmain.php index dcddfd99..bbcba1ea 100644 --- a/lam/templates/config/confmain.php +++ b/lam/templates/config/confmain.php @@ -3,7 +3,7 @@ $Id$ 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 it under the terms of the GNU General Public License as published by @@ -280,6 +280,8 @@ if (isLAMProVersion()) { // advanced options $advancedOptionsContent = new htmlTable(); +// display name +$advancedOptionsContent->addElement(new htmlTableExtendedInputField(_('Display name'), 'serverDisplayName', $conf->getServerDisplayName(), '268'), true); // referrals $followReferrals = ($conf->getFollowReferrals() === 'true'); $advancedOptionsContent->addElement(new htmlTableExtendedInputCheckbox('followReferrals', $followReferrals , _('Follow referrals'), '205'), true); @@ -529,6 +531,7 @@ function checkInput() { if (!$conf->set_ServerURL($_POST['serverurl'])) { $errors[] = array("ERROR", _("Server address is invalid!")); } + $conf->setServerDisplayName($_POST['serverDisplayName']); $conf->setUseTLS($_POST['useTLS']); 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.')); diff --git a/lam/templates/login.php b/lam/templates/login.php index 0ebfd748..ff8b1dea 100644 --- a/lam/templates/login.php +++ b/lam/templates/login.php @@ -4,7 +4,7 @@ $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) 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 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; $subTable->addElement($serverLabel); $subTable->addElement($gap); - $serverName = new htmlOutputText($config_object->get_ServerURL()); + $serverName = new htmlOutputText($config_object->getServerDisplayNameGUI()); $serverName->alignment = htmlElement::ALIGN_LEFT; $subTable->addElement($serverName, true); // server profile diff --git a/lam/tests/lib/LAMConfigTest.php b/lam/tests/lib/LAMConfigTest.php index 1be41e03..f48c6f62 100644 --- a/lam/tests/lib/LAMConfigTest.php +++ b/lam/tests/lib/LAMConfigTest.php @@ -34,7 +34,7 @@ class LAMConfigTest extends PHPUnit_Framework_TestCase { */ private $lAMConfig; - const FILE_NAME = 'phpunit'; + const FILE_NAME = 'LAMConfigTest'; /** * Prepares the environment before running a test. @@ -60,6 +60,7 @@ class LAMConfigTest extends PHPUnit_Framework_TestCase { deleteConfigProfile(LAMConfigTest::FILE_NAME); $profiles = getConfigProfiles(); $this->assertTrue(!in_array(LAMConfigTest::FILE_NAME, $profiles)); + testDeleteDefaultConfig(); parent::tearDown(); } @@ -81,7 +82,7 @@ class LAMConfigTest extends PHPUnit_Framework_TestCase { * Tests LAMConfig->getPath() */ 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()); } + /** + * 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() */ diff --git a/lam/tests/lib/securityTest.php b/lam/tests/lib/securityTest.php index 869a5b3f..c391ee2d 100644 --- a/lam/tests/lib/securityTest.php +++ b/lam/tests/lib/securityTest.php @@ -3,7 +3,7 @@ $Id$ 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 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(); } + /** + * Cleans up the environment after running a test. + */ + protected function tearDown() { + testDeleteDefaultConfig(); + parent::tearDown(); + } + public function testMinLength() { $this->cfg->passwordMinLength = 5; $this->checkPwd(array('55555', '666666'), array('1', '22', '333', '4444')); diff --git a/lam/tests/utils/configuration.inc b/lam/tests/utils/configuration.inc index 3586d0d8..c440d0b2 100644 --- a/lam/tests/utils/configuration.inc +++ b/lam/tests/utils/configuration.inc @@ -3,7 +3,7 @@ $Id$ 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 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)'; } +function testDeleteDefaultConfig() { + deleteConfigProfile('phpunit'); +} + ?> \ No newline at end of file