From a8159dc4e04f257316aca1da2844a8b7b76ac701 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 25 Dec 2014 07:31:04 +0000 Subject: [PATCH] templates for server profiles --- lam/HISTORY | 4 ++++ lam/VERSION | 2 +- lam/help/help.inc | 2 ++ lam/lib/config.inc | 22 ++++++++++++++++++++++ lam/lib/html.inc | 3 ++- lam/templates/config/profmanage.php | 18 +++++++++++++++++- 6 files changed, 48 insertions(+), 3 deletions(-) diff --git a/lam/HISTORY b/lam/HISTORY index 47b54883..0b349684 100644 --- a/lam/HISTORY +++ b/lam/HISTORY @@ -1,3 +1,7 @@ +March 2015 + - templates for server profiles + + 16.12.2014 4.8 - Active Directory: support paged result as workaround for size limit exceeded - FreeRadius: support dialupAccess and radiusProfileDn diff --git a/lam/VERSION b/lam/VERSION index ef216a53..b58727b6 100644 --- a/lam/VERSION +++ b/lam/VERSION @@ -1 +1 @@ -4.8 +4.9.TEST diff --git a/lam/help/help.inc b/lam/help/help.inc index 5f6f7810..ac8a40f4 100644 --- a/lam/help/help.inc +++ b/lam/help/help.inc @@ -183,6 +183,8 @@ $helpArray = array ( "Text" => _('Sets this account type to read-only.')), "266" => array ("Headline" => _("Paged results"), "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.')), // 300 - 399 // profile editor, file upload "301" => array ("Headline" => _("RDN identifier"), diff --git a/lam/lib/config.inc b/lam/lib/config.inc index 7e246832..7b0de246 100644 --- a/lam/lib/config.inc +++ b/lam/lib/config.inc @@ -143,6 +143,28 @@ function getConfigProfiles() { return $ret; } +/** +* Returns an array of string with all available configuration templates (without .conf.sample) +* +* @return array template names +*/ +function getConfigTemplates() { + $dir = dir(dirname(__FILE__) . "/../config"); + $ret = array(); + $pos = 0; + while ($entry = $dir->read()){ + $ext = substr($entry, strlen($entry)-12, 12); + $name = substr($entry, 0, strlen($entry) - 12); + // check if extension is right, add to profile list + if ($ext == ".conf.sample") { + $ret[$pos] = $name; + $pos ++; + } + } + sort($ret); + return $ret; +} + /** * Creates a new server profile. * diff --git a/lam/lib/html.inc b/lam/lib/html.inc index d0624201..80ce6293 100644 --- a/lam/lib/html.inc +++ b/lam/lib/html.inc @@ -1260,7 +1260,8 @@ class htmlSelect extends htmlElement { } /** - * Specifies if the elements are divided into optgroups. + * Specifies if the elements are divided into optgroups. + * In this case the provided options are an array where the key is the optgroup label and the value is an array containing the options for the optgroup. * * @param boolean $containsOptgroups activates optgroups */ diff --git a/lam/templates/config/profmanage.php b/lam/templates/config/profmanage.php index 5a02b4eb..1714bd57 100644 --- a/lam/templates/config/profmanage.php +++ b/lam/templates/config/profmanage.php @@ -57,7 +57,7 @@ if (isset($_POST['action'])) { elseif ($_POST['action'] == "add") { // check profile password if ($_POST['addpassword'] && $_POST['addpassword2'] && ($_POST['addpassword'] == $_POST['addpassword2'])) { - $result = createConfigProfile($_POST['addprofile'], $_POST['addpassword'], 'lam.conf.sample'); + $result = createConfigProfile($_POST['addprofile'], $_POST['addpassword'], $_POST['addTemplate']); if ($result === true) { $_SESSION['conf_isAuthenticated'] = $_POST['addprofile']; $_SESSION['conf_config'] = new LAMConfig($_POST['addprofile']); @@ -235,6 +235,22 @@ $profileNewPwd2->setIsPassword(true); $profileNewPwd2->setFieldSize(15); $profileNewPwd2->setSameValueFieldID('addpassword'); $container->addElement($profileNewPwd2, true); +$existing = array(); +foreach ($files as $file) { + $existing[$file] = $file . '.conf'; +} +$builtIn = array(); +foreach (getConfigTemplates() as $file) { + $builtIn[$file] = $file . '.conf.sample'; +} +$templates = array( + _('Existing server profiles') => $existing, + _('Built-in templates') => $builtIn +); +$addTemplateSelect = new htmlTableExtendedSelect('addTemplate', $templates, array('lam.conf.sample'), _('Template'), '267'); +$addTemplateSelect->setContainsOptgroups(true); +$addTemplateSelect->setHasDescriptiveElements(true); +$container->addElement($addTemplateSelect, true); $newProfileButton = new htmlButton('btnAddProfile', _('Add')); $newProfileButton->setOnClick("jQuery('#action').val('add');showConfirmationDialog('" . _("Add profile") . "', '" . _('Ok') . "', '" . _('Cancel') . "', 'passwordDialogDiv', 'profileForm', null); document.getElementById('passwd').focus();");