new type API

This commit is contained in:
Roland Gruber 2017-01-03 20:02:29 +01:00
parent e93d59740c
commit 22cfb56f60
5 changed files with 326 additions and 165 deletions

View File

@ -1461,4 +1461,31 @@ function validateReCAPTCHA($secretKey) {
return $responseJSON->{'success'} === true; return $responseJSON->{'success'} === true;
} }
class LAMException extends Exception {
private $title;
/**
* Constructor.
*
* @param string $title title
* @param string $message message (optional)
* @param Exception $cause (optional)
*/
public function __construct($title, $message = null, $cause = null) {
parent::__construct($message, null, $cause);
$this->title = $title;
}
/**
* Returns the message title.
*
* @return string title
*/
public function getTitle() {
return $this->title;
}
}
?> ?>

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 - 2006 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
@ -32,26 +32,26 @@ $Id$
/** /**
* Returns an array of string with all available profiles for the given account type * Returns an array of string with all available profiles for the given account type
* *
* @param string $scope account type * @param string $typeId account type
* @param string $profile server profile name * @param string $profile server profile name
* @return array profile names * @return array profile names
*/ */
function getAccountProfiles($scope, $profile = null) { function getAccountProfiles($typeId, $profile = null) {
if (!isset($profile)) { if (!isset($profile)) {
$profile = $_SESSION['config']->getName(); $profile = $_SESSION['config']->getName();
} }
$dir = @dir(substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/" . $profile); $dir = @dir(dirname(__FILE__) . "/../config/profiles/" . $profile);
$ret = array(); $ret = array();
$pos = 0; $pos = 0;
if ($dir) { if ($dir) {
$entry = $dir->read(); $entry = $dir->read();
while ($entry){ while ($entry){
// check if filename ends with .<scope> // check if filename ends with .<typeId>
if (strrpos($entry, '.')) { if (strrpos($entry, '.')) {
$pos = strrpos($entry, '.'); $pos = strrpos($entry, '.');
if (substr($entry, $pos + 1) == $scope) { if (substr($entry, $pos + 1) == $typeId) {
$name = substr($entry, 0, $pos); $name = substr($entry, 0, $pos);
$ret[] = $name; $ret[] = $name;
} }
@ -67,13 +67,17 @@ function getAccountProfiles($scope, $profile = null) {
* Loads an profile of the given account type * Loads an profile of the given account type
* *
* @param string $profile name of the profile (without .<scope> extension) * @param string $profile name of the profile (without .<scope> extension)
* @param string $scope account type * @param string $typeId account type
* @return array hash array (attribute => value) * @return array hash array (attribute => value)
*/ */
function loadAccountProfile($profile, $scope) { function loadAccountProfile($profile, $typeId) {
if (!preg_match("/^[0-9a-z _-]+$/i", $profile) || !preg_match("/^[a-z]+$/i", $scope)) return false; $typeManager = new \LAM\TYPES\TypeManager();
$type = $typeManager->getConfiguredType($typeId);
if (!isValidProfileName($profile) || !preg_match("/^[a-z0-9_]+$/i", $typeId) || ($type == null)) {
return false;
}
$settings = array(); $settings = array();
$file = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/" . $_SESSION['config']->getName() . '/' . $profile . "." . $scope; $file = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/" . $_SESSION['config']->getName() . '/' . $profile . "." . $typeId;
if (is_file($file) == True) { if (is_file($file) == True) {
$file = @fopen($file, "r"); $file = @fopen($file, "r");
if ($file) { if ($file) {
@ -111,17 +115,21 @@ function loadAccountProfile($profile, $scope) {
* *
* @param array $attributes hash array (attribute => value) * @param array $attributes hash array (attribute => value)
* @param string $profile name of the account profile (without .<scope> extension) * @param string $profile name of the account profile (without .<scope> extension)
* @param string $scope account type * @param string $typeId account type
* @return boolean true, if saving succeeded * @return boolean true, if saving succeeded
*/ */
function saveAccountProfile($attributes, $profile, $scope) { function saveAccountProfile($attributes, $profile, $typeId) {
if (!isLoggedIn()) return false; if (!isLoggedIn()) return false;
// check profile name // check profile name and type id
if (!preg_match("/^[0-9a-z _-]+$/i", $profile) || !preg_match("/^[a-z]+$/i", $scope)) return false; $typeManager = new \LAM\TYPES\TypeManager();
$type = $typeManager->getConfiguredType($typeId);
if (!isValidProfileName($profile) || !preg_match("/^[a-z0-9_]+$/i", $typeId) || ($type == null)) {
return false;
}
if (!is_array($attributes)) { if (!is_array($attributes)) {
return false; return false;
} }
$path = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/" . $_SESSION['config']->getName() . '/' . $profile . "." . $scope; $path = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/" . $_SESSION['config']->getName() . '/' . $profile . "." . $typeId;
$file = @fopen($path, "w"); $file = @fopen($path, "w");
if ($file) { if ($file) {
// write attributes // write attributes
@ -148,59 +156,78 @@ function saveAccountProfile($attributes, $profile, $scope) {
* Deletes an account profile * Deletes an account profile
* *
* @param string $file name of profile (Without .<scope> extension) * @param string $file name of profile (Without .<scope> extension)
* @param string $scope account type * @param string $typeId account type
* @return boolean true if profile was deleted * @return boolean true if profile was deleted
*/ */
function delAccountProfile($file, $scope) { function delAccountProfile($file, $typeId) {
if (!isLoggedIn()) return false; if (!isLoggedIn()) {
if (!preg_match("/^[0-9a-z _-]+$/i", $file) || !preg_match("/^[a-z]+$/i", $scope)) return false; return false;
$prof = substr(__FILE__, 0, strlen(__FILE__) - 16) . "config/profiles/". $_SESSION['config']->getName() . '/' . $file . "." . $scope; }
$typeManager = new \LAM\TYPES\TypeManager();
$type = $typeManager->getConfiguredType($typeId);
if (!isValidProfileName($file) || !preg_match("/^[a-z0-9_]+$/i", $typeId) || ($type == null)) {
return false;
}
$prof = substr(__FILE__, 0, strlen(__FILE__) - 16) . "config/profiles/". $_SESSION['config']->getName() . '/' . $file . "." . $typeId;
if (is_file($prof)) { if (is_file($prof)) {
return @unlink($prof); return @unlink($prof);
} }
else return false; else return false;
} }
/**
* Returns if the given profile name is valid.
*
* @param string $name profile name
*/
function isValidProfileName($name) {
return preg_match("/^[0-9a-z _-]+$/i", $name);
}
/** /**
* Copies account profiles to other server profiles. * Copies an account profile from the given source to target.
* *
* @param array $accountProfiles account profile names * @param \LAM\TYPES\ConfiguredType $sourceType source type
* @param String $scope account scope * @param string $sourceProfileName profile name
* @param array $dests destinations * @param \LAM\TYPES\ConfiguredType $targetType target type
* * @throws Exception
* @return boolean operation succeeded
*/ */
function copyAccountProfiles($accountProfiles, $scope, $dests = array()) { function copyAccountProfile($sourceType, $sourceProfileName, $targetType) {
$state = true; if (!isValidProfileName($sourceProfileName)) {
$profilePath = substr(__FILE__, 0, strlen(__FILE__) - 17) . '/config/profiles/'; throw new LAMException(_('Failed to copy'));
foreach ($accountProfiles as $profile) {
//part 1: server profile
//part 2: account profile
$tmpArr = explode('##', $profile);
$src = $profilePath . $tmpArr[0] . '/' . $tmpArr[1] . '.' . $scope;
if (!empty($dests)) {
foreach ($dests as $dest) {
if ($dest == 'templates*') {
$dst = substr(__FILE__, 0, strlen(__FILE__) - 17) . '/config/templates/profiles/' . $tmpArr[1] . '.' . $scope;
} else {
$dst = $profilePath . $dest . '/' . $tmpArr[1] . '.' . $scope;
}
if (!@copy($src, $dst)) {
StatusMessage('ERROR', _('Failed to export!'), $tmpArr[1] . '.' . $scope);
$state = false;
}
}
} else {
$dst = $profilePath . $_SESSION['config']->getName() . '/' . $tmpArr[1] . '.' . $scope;
if (!@copy($src, $dst)) {
StatusMessage('ERROR', _('Failed to import!'), $tmpArr[1] . '.' . $scope);
$state = false;
}
}
} }
$sourceConfig = $sourceType->getTypeManager()->getConfig()->getName();
$sourceTypeId = $sourceType->getId();
$targetConfig = $targetType->getTypeManager()->getConfig()->getName();
$targetTypeId = $targetType->getId();
$profilePath = dirname(__FILE__) . '/../config/profiles/';
$src = $profilePath . $sourceConfig . '/' . $sourceProfileName . '.' . $sourceTypeId;
$dst = $profilePath . $targetConfig . '/' . $sourceProfileName . '.' . $targetTypeId;
if (!@copy($src, $dst)) {
throw new LAMException(_('Failed to copy'), $sourceConfig . ': ' . $sourceProfileName);
}
}
return $state; /**
* Copies an account profile from the given source to global templates.
*
* @param \LAM\TYPES\ConfiguredType $sourceType source type
* @param string $sourceProfileName profile name
* @throws Exception
*/
function copyAccountProfileToTemplates($sourceType, $sourceProfileName) {
if (!isValidProfileName($sourceProfileName)) {
throw new LAMException(_('Failed to copy'));
}
$sourceConfig = $sourceType->getTypeManager()->getConfig()->getName();
$sourceTypeId = $sourceType->getId();
$profilePath = dirname(__FILE__) . '/../config/profiles/';
$templatePath = dirname(__FILE__) . '/../config/templates/profiles/';
$src = $profilePath . $sourceConfig . '/' . $sourceProfileName . '.' . $sourceTypeId;
$dst = $templatePath . $sourceProfileName . '.' . $sourceType->getScope();
if (!@copy($src, $dst)) {
throw new LAMException(_('Failed to copy'), $sourceConfig . ': ' . $sourceProfileName);
}
} }
?> ?>

View File

@ -172,9 +172,12 @@ class ConfiguredType {
private $baseType; private $baseType;
private $typeManager;
/** /**
* Constructor * Constructor
* *
* @param TypeManager $typeManager type manager
* @param string $scope account type * @param string $scope account type
* @param string $id unique ID for this configuration * @param string $id unique ID for this configuration
* @param string $suffix LDAP base suffix * @param string $suffix LDAP base suffix
@ -183,8 +186,9 @@ class ConfiguredType {
* @param string $ldapFilter additional LDAP filter * @param string $ldapFilter additional LDAP filter
* @param boolean $hidden hidden in GUI * @param boolean $hidden hidden in GUI
*/ */
public function __construct($scope, $id, $suffix, $attributes, $alias, public function __construct(&$typeManager, $scope, $id, $suffix, $attributes, $alias,
$ldapFilter, $hidden) { $ldapFilter, $hidden) {
$this->typeManager = &$typeManager;
$this->scope = $scope; $this->scope = $scope;
$this->id = $id; $this->id = $id;
$this->suffix = $suffix; $this->suffix = $suffix;
@ -194,10 +198,19 @@ class ConfiguredType {
$this->hidden = $hidden; $this->hidden = $hidden;
} }
/**
* Returns the owning type manager.
*
* @return TypeManager type manager
*/
public function getTypeManager() {
return $this->typeManager;
}
/** /**
* Returns the account type (e.g. 'user'). * Returns the account type (e.g. 'user').
* *
* @return string $scope account type * @return string account type
*/ */
public function getScope() { public function getScope() {
return $this->scope; return $this->scope;
@ -206,7 +219,7 @@ class ConfiguredType {
/** /**
* Returns a unique id for this configuration. * Returns a unique id for this configuration.
* *
* @return string $id unique id * @return string unique id
*/ */
public function getId() { public function getId() {
return $this->id; return $this->id;
@ -215,7 +228,7 @@ class ConfiguredType {
/** /**
* Returns the LDAP suffix. * Returns the LDAP suffix.
* *
* @return string $suffix LDAP suffix * @return string LDAP suffix
*/ */
public function getSuffix() { public function getSuffix() {
return $this->suffix; return $this->suffix;
@ -224,7 +237,7 @@ class ConfiguredType {
/** /**
* Returns a list of configured attributes. * Returns a list of configured attributes.
* *
* @return ListAttribute[] $attributes list of ListAttribute * @return ListAttribute[] list of ListAttribute
*/ */
public function getAttributes() { public function getAttributes() {
return $this->attributes; return $this->attributes;
@ -233,7 +246,7 @@ class ConfiguredType {
/** /**
* Returns the alias name. * Returns the alias name.
* *
* @return string $alias alias name * @return string alias name
*/ */
public function getAlias() { public function getAlias() {
return $this->alias; return $this->alias;
@ -242,7 +255,7 @@ class ConfiguredType {
/** /**
* Returns the additional LDAP filter. * Returns the additional LDAP filter.
* *
* @return string $ldapFilter LDAP filter * @return string LDAP filter
*/ */
public function getAdditionalLdapFilter() { public function getAdditionalLdapFilter() {
return $this->additionalLdapFilter; return $this->additionalLdapFilter;
@ -251,7 +264,7 @@ class ConfiguredType {
/** /**
* Returns if this configuration is hidden. * Returns if this configuration is hidden.
* *
* @return boolean $hidden hidden * @return boolean hidden
*/ */
public function isHidden() { public function isHidden() {
return $this->hidden; return $this->hidden;
@ -458,7 +471,7 @@ class TypeManager {
$alias = getTypeAlias($typeId, $this->config); $alias = getTypeAlias($typeId, $this->config);
$ldapFilter = $this->config->get_Suffix($typeId); $ldapFilter = $this->config->get_Suffix($typeId);
$hidden = isAccountTypeHidden($typeId); $hidden = isAccountTypeHidden($typeId);
return new ConfiguredType($scope, $typeId, $suffix, $attributes, $alias, $ldapFilter, $hidden); return new ConfiguredType($this, $scope, $typeId, $suffix, $attributes, $alias, $ldapFilter, $hidden);
} }
/** /**
@ -495,6 +508,15 @@ class TypeManager {
return $scope . '_' . $counter; return $scope . '_' . $counter;
} }
/**
* Returns the associated config object.
*
* @return \LAMConfig config
*/
public function getConfig() {
return $this->config;
}
} }
?> ?>

View File

@ -422,33 +422,21 @@ function equalHeight(elementIDs) {
* @param title dialog title * @param title dialog title
* @param okText text for Ok button * @param okText text for Ok button
* @param cancelText text for Cancel button * @param cancelText text for Cancel button
* @param scope account type * @param typeId account type
* @param selectFieldName name of select box with profile name * @param selectFieldName name of select box with profile name
* @param serverProfile profile name
*/ */
function showDistributionDialog(title, okText, cancelText, scope, type, selectFieldName, serverProfile) { function showDistributionDialog(title, okText, cancelText, typeId, type, selectFieldName) {
// show dialog // show dialog
var buttonList = {}; var buttonList = {};
var dialogId = ''; var dialogId = '';
if (type == 'export') { if (type == 'export') {
// show structure name to export jQuery('#name_' + typeId).val(jQuery('#' + selectFieldName).val());
jQuery('#exportName').text(jQuery('[name=' + selectFieldName + ']').val()); dialogId = 'exportDialog_' + typeId;
dialogId = 'exportDialog'; buttonList[okText] = function() { document.forms["exportDialogForm_" + typeId].submit(); };
buttonList[okText] = function() { document.forms["exportDialogForm"].submit(); };
jQuery('<input>').attr({
type: 'hidden',
name: 'exportProfiles[]',
value: serverProfile + '##' + jQuery('[name=' + selectFieldName + ']').val()
}).appendTo('form');
jQuery('<input>').attr({
type: 'hidden',
name: 'scope',
value: scope
}).appendTo('form');
} else if (type == 'import') { } else if (type == 'import') {
dialogId = 'importDialog_' + scope; dialogId = 'importDialog_' + typeId;
buttonList[okText] = function() { document.forms["importDialogForm_" + scope].submit(); }; buttonList[okText] = function() { document.forms["importDialogForm_" + typeId].submit(); };
} }
buttonList[cancelText] = function() { jQuery(this).dialog("close"); }; buttonList[cancelText] = function() { jQuery(this).dialog("close"); };
@ -460,9 +448,9 @@ function showDistributionDialog(title, okText, cancelText, scope, type, selectFi
width: 'auto' width: 'auto'
}); });
if (type == 'export') { if (type == 'export') {
equalWidth(new Array('#passwd', '#destServerProfiles')); equalWidth(new Array('#passwd_' + typeId, '#destServerProfiles_' + typeId));
} else if (type == 'import') { } else if (type == 'import') {
equalWidth(new Array('#passwd_' + scope, '#importProfiles_' + scope)); equalWidth(new Array('#passwd_' + typeId, '#importProfiles'));
} }
} }

View File

@ -77,6 +77,7 @@ foreach ($types as $type) {
} }
$profileClassesTemp[$type->getAlias()] = array( $profileClassesTemp[$type->getAlias()] = array(
'typeId' => $type->getId(), 'typeId' => $type->getId(),
'scope' => $type->getScope(),
'title' => $type->getAlias(), 'title' => $type->getAlias(),
'profiles' => ""); 'profiles' => "");
} }
@ -134,30 +135,54 @@ if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) {
} }
} }
// check if profiles should be imported or exported $configProfiles = getConfigProfiles();
if (isset($_POST['importexport']) && ($_POST['importexport'] === '1')) { $serverProfiles = array();
foreach ($configProfiles as $profileName) {
$serverProfiles[$profileName] = new \LAMConfig($profileName);
}
// import profiles
if (!empty($_POST['import'])) {
$cfg = new LAMCfgMain(); $cfg = new LAMCfgMain();
$impExpMessage = null; // check master password
if (isset($_POST['importProfiles_' . $_POST['typeId']])) { $impMessage = null;
// check master password if (!$cfg->checkPassword($_POST['passwd_i_' . $_POST['typeId']])) {
if (!$cfg->checkPassword($_POST['passwd_' . $_POST['typeId']])) { $impMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!'));
$impExpMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!'));
}
elseif (copyAccountProfiles($_POST['importProfiles_' . $_POST['typeId']], $_POST['typeId'])) {
$impExpMessage = new htmlStatusMessage('INFO', _('Import successful'));
}
} else if (isset($_POST['exportProfiles'])) {
// check master password
if (!$cfg->checkPassword($_POST['passwd'])) {
$impExpMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!'));
}
elseif (copyAccountProfiles($_POST['exportProfiles'], $_POST['typeId'], $_POST['destServerProfiles'])) {
$impExpMessage = new htmlStatusMessage('INFO', _('Export successful'));
}
} }
if ($impExpMessage != null) { elseif (!empty($_POST['importProfiles'])) {
$impExpMessage->colspan = 10; $options = array();
$container->addElement($impExpMessage, true); foreach ($_POST['importProfiles'] as $importProfiles) {
$parts = explode('##', $importProfiles);
$options[] = array('conf' => $parts[0], 'typeId' => $parts[1], 'name' => $parts[2]);
}
$impMessage = importProfiles($_POST['typeId'], $options, $serverProfiles, $typeManager);
}
if ($impMessage != null) {
$impMessage->colspan = 10;
$container->addElement($impMessage, true);
}
}
// export profiles
if (!empty($_POST['export'])) {
$cfg = new LAMCfgMain();
// check master password
$impMessage = null;
if (!$cfg->checkPassword($_POST['passwd_e_' . $_POST['typeId']])) {
$impMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!'));
}
elseif (!empty($_POST['exportProfiles'])) {
$options = array();
foreach ($_POST['exportProfiles'] as $importProfiles) {
$parts = explode('##', $importProfiles);
$options[] = array('conf' => $parts[0], 'typeId' => $parts[1]);
}
$typeId = $_POST['typeId'];
$name = $_POST['name_' . $typeId];
$impMessage = exportProfiles($typeId, $name, $options, $serverProfiles, $typeManager);
}
if ($impMessage != null) {
$impMessage->colspan = 10;
$container->addElement($impMessage, true);
} }
} }
@ -199,8 +224,6 @@ $container->addElement(new htmlSubTitle(_('Manage existing profiles')), true);
$existingContainer = new htmlTable(); $existingContainer = new htmlTable();
$existingContainer->colspan = 5; $existingContainer->colspan = 5;
$configProfiles = getConfigProfiles();
for ($i = 0; $i < sizeof($profileClasses); $i++) { for ($i = 0; $i < sizeof($profileClasses); $i++) {
if ($i > 0) { if ($i > 0) {
$existingContainer->addElement(new htmlSpacer(null, '10px'), true); $existingContainer->addElement(new htmlSpacer(null, '10px'), true);
@ -231,7 +254,7 @@ for ($i = 0; $i < sizeof($profileClasses); $i++) {
$exportLink = new htmlLink(null, '#', '../../graphics/export.png'); $exportLink = new htmlLink(null, '#', '../../graphics/export.png');
$exportLink->setTitle(_('Export profile')); $exportLink->setTitle(_('Export profile'));
$exportLink->setOnClick("showDistributionDialog('" . _("Export profile") . "', '" . $exportLink->setOnClick("showDistributionDialog('" . _("Export profile") . "', '" .
_('Ok') . "', '" . _('Cancel') . "', '" . $profileClasses[$i]['typeId'] . "', 'export', '" . 'profile_' . $profileClasses[$i]['typeId'] . "', '" . $_SESSION['config']->getName() . "');"); _('Ok') . "', '" . _('Cancel') . "', '" . $profileClasses[$i]['typeId'] . "', 'export', '" . 'profile_' . $profileClasses[$i]['typeId'] . "');");
$existingContainer->addElement($exportLink); $existingContainer->addElement($exportLink);
$existingContainer->addNewLine(); $existingContainer->addNewLine();
} }
@ -247,13 +270,18 @@ echo "</div>\n";
for ($i = 0; $i < sizeof($profileClasses); $i++) { for ($i = 0; $i < sizeof($profileClasses); $i++) {
$typeId = $profileClasses[$i]['typeId']; $typeId = $profileClasses[$i]['typeId'];
$tmpArr = array(); $scope = $profileClasses[$i]['scope'];
$importOptions = array();
foreach ($configProfiles as $profile) { foreach ($configProfiles as $profile) {
if ($profile != $_SESSION['config']->getName()) { $typeManagerImport = new \LAM\TYPES\TypeManager($serverProfiles[$profile]);
$accountProfiles = getAccountProfiles($typeId, $profile); $typesImport = $typeManagerImport->getConfiguredTypesForScope($scope);
if (!empty($accountProfiles)) { foreach ($typesImport as $typeImport) {
for ($p = 0; $p < sizeof($accountProfiles); $p++) { if (($profile != $_SESSION['config']->getName()) || ($typeImport->getId() != $typeId)) {
$tmpArr[$profile][$accountProfiles[$p]] = $profile . '##' . $accountProfiles[$p]; $accountProfiles = getAccountProfiles($typeImport->getId(), $profile);
if (!empty($accountProfiles)) {
for ($p = 0; $p < sizeof($accountProfiles); $p++) {
$importOptions[$profile][$typeImport->getAlias() . ': ' . $accountProfiles[$p]] = $profile . '##' . $typeImport->getId() . '##' . $accountProfiles[$p];
}
} }
} }
} }
@ -266,7 +294,7 @@ for ($i = 0; $i < sizeof($profileClasses); $i++) {
$container = new htmlTable(); $container = new htmlTable();
$container->addElement(new htmlOutputText(_('Profiles')), true); $container->addElement(new htmlOutputText(_('Profiles')), true);
$select = new htmlSelect('importProfiles_' . $typeId, $tmpArr, array(), count($tmpArr, 1) < 15 ? count($tmpArr, 1) : 15); $select = new htmlSelect('importProfiles', $importOptions, array(), count($importOptions, 1) < 15 ? count($importOptions, 1) : 15);
$select->setMultiSelect(true); $select->setMultiSelect(true);
$select->setHasDescriptiveElements(true); $select->setHasDescriptiveElements(true);
$select->setContainsOptgroups(true); $select->setContainsOptgroups(true);
@ -278,11 +306,11 @@ for ($i = 0; $i < sizeof($profileClasses); $i++) {
$container->addElement(new htmlSpacer(null, '10px'), true); $container->addElement(new htmlSpacer(null, '10px'), true);
$container->addElement(new htmlOutputText(_("Master password")), true); $container->addElement(new htmlOutputText(_("Master password")), true);
$exportPasswd = new htmlInputField('passwd_' . $typeId); $exportPasswd = new htmlInputField('passwd_i_' . $typeId);
$exportPasswd->setIsPassword(true); $exportPasswd->setIsPassword(true);
$container->addElement($exportPasswd); $container->addElement($exportPasswd);
$container->addElement(new htmlHelpLink('236')); $container->addElement(new htmlHelpLink('236'));
$container->addElement(new htmlHiddenInput('importexport', '1')); $container->addElement(new htmlHiddenInput('import', '1'));
$container->addElement(new htmlHiddenInput('typeId', $typeId), true); $container->addElement(new htmlHiddenInput('typeId', $typeId), true);
addSecurityTokenToMetaHTML($container); addSecurityTokenToMetaHTML($container);
@ -290,55 +318,53 @@ for ($i = 0; $i < sizeof($profileClasses); $i++) {
echo '</form>'; echo '</form>';
echo "</div>\n"; echo "</div>\n";
//export dialog
echo "<div id=\"exportDialog_$typeId\" class=\"hidden\">\n";
echo "<form id=\"exportDialogForm_$typeId\" method=\"post\" action=\"profilemain.php\">\n";
$container = new htmlTable();
$container->addElement(new htmlOutputText(_("Target server profile")), true);
$exportOptions = array();
foreach ($configProfiles as $profile) {
$typeManagerExport = new \LAM\TYPES\TypeManager($serverProfiles[$profile]);
$typesExport = $typeManagerExport->getConfiguredTypesForScope($scope);
foreach ($typesExport as $typeExport) {
if (($profile != $_SESSION['config']->getName()) || ($typeExport->getId() != $typeId)) {
$exportOptions[$typeManagerExport->getConfig()->getName()][$typeExport->getAlias()] = $profile . '##' . $typeExport->getId();
}
}
}
$exportOptions['*' . _('Global templates')][_('Global templates')] = 'templates*##';
$select = new htmlSelect('exportProfiles', $exportOptions, array(), count($exportOptions) < 10 ? count($exportOptions) : 10);
$select->setHasDescriptiveElements(true);
$select->setContainsOptgroups(true);
$select->setMultiSelect(true);
$container->addElement($select);
$container->addElement(new htmlHelpLink('363'), true);
$container->addElement(new htmlSpacer(null, '10px'), true);
$container->addElement(new htmlOutputText(_("Master password")), true);
$exportPasswd = new htmlInputField('passwd_e_' . $typeId);
$exportPasswd->setIsPassword(true);
$container->addElement($exportPasswd);
$container->addElement(new htmlHelpLink('236'));
$container->addElement(new htmlHiddenInput('export', '1'), true);
$container->addElement(new htmlHiddenInput('typeId', $typeId), true);
$container->addElement(new htmlHiddenInput('name_' . $typeId, '_'), true);
addSecurityTokenToMetaHTML($container);
parseHtml(null, $container, array(), false, $tabindex, 'user');
echo '</form>';
echo "</div>\n";
} }
//export dialog
echo "<div id=\"exportDialog\" class=\"hidden\">\n";
echo "<form id=\"exportDialogForm\" method=\"post\" action=\"profilemain.php\">\n";
$container = new htmlTable();
$container->addElement(new htmlOutputText(_('Profile name')), true);
$expStructGroup = new htmlTable();
$expStructGroup->addElement(new htmlSpacer('10px', null));
$expStructGroup->addElement(new htmlDiv('exportName', ''));
$container->addElement($expStructGroup, true);
$container->addElement(new htmlSpacer(null, '10px'), true);
$container->addElement(new htmlOutputText(_("Target server profile")), true);
foreach ($configProfiles as $key => $value) {
$tmpProfiles[$value] = $value;
}
natcasesort($tmpProfiles);
$tmpProfiles['*' . _('Global templates')] = 'templates*';
$findProfile = array_search($_SESSION['config']->getName(), $tmpProfiles);
if ($findProfile !== false) {
unset($tmpProfiles[$findProfile]);
}
$select = new htmlSelect('destServerProfiles', $tmpProfiles, array(), count($tmpProfiles) < 10 ? count($tmpProfiles) : 10);
$select->setHasDescriptiveElements(true);
$select->setSortElements(false);
$select->setMultiSelect(true);
$container->addElement($select);
$container->addElement(new htmlHelpLink('363'), true);
$container->addElement(new htmlSpacer(null, '10px'), true);
$container->addElement(new htmlOutputText(_("Master password")), true);
$exportPasswd = new htmlInputField('passwd');
$exportPasswd->setIsPassword(true);
$container->addElement($exportPasswd);
$container->addElement(new htmlHelpLink('236'));
$container->addElement(new htmlHiddenInput('importexport', '1'), true);
addSecurityTokenToMetaHTML($container);
parseHtml(null, $container, array(), false, $tabindex, 'user');
echo '</form>';
echo "</div>\n";
// form for delete action // form for delete action
echo '<div id="deleteProfileDialog" class="hidden"><form id="deleteProfileForm" action="profilemain.php" method="post">'; echo '<div id="deleteProfileDialog" class="hidden"><form id="deleteProfileForm" action="profilemain.php" method="post">';
echo _("Do you really want to delete this profile?"); echo _("Do you really want to delete this profile?");
@ -352,4 +378,75 @@ echo '</form></div>';
include '../main_footer.php'; include '../main_footer.php';
/**
* Imports the selected account profiles.
*
* @param string $typeId type id
* @param array $options options
* @param \LAMConfig[] $serverProfiles server profiles (name => profile object)
* @param \LAM\TYPES\TypeManager $typeManager type manager
* @return \htmlStatusMessage message or null
*/
function importProfiles($typeId, $options, &$serverProfiles, &$typeManager) {
foreach ($options as $option) {
$sourceConfName = $option['conf'];
$sourceTypeId = $option['typeId'];
$sourceName = $option['name'];
$sourceTypeManager = new \LAM\TYPES\TypeManager($serverProfiles[$sourceConfName]);
$sourceType = $sourceTypeManager->getConfiguredType($sourceTypeId);
$targetType = $typeManager->getConfiguredType($typeId);
if (($sourceType != null) && ($targetType != null)) {
try {
\copyAccountProfile($sourceType, $sourceName, $targetType);
}
catch (\LAMException $e) {
return new \htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage());
}
}
}
return new \htmlStatusMessage('INFO', _('Import successful'));
}
/**
* Exports the selected account profile.
*
* @param string $typeId source type id
* @param string $name profile name
* @param array $options options
* @param \LAMConfig[] $serverProfiles server profiles (name => profile object)
* @param \LAM\TYPES\TypeManager $typeManager type manager
* @return \htmlStatusMessage message or null
*/
function exportProfiles($typeId, $name, $options, &$serverProfiles, &$typeManager) {
$sourceType = $typeManager->getConfiguredType($typeId);
if ($sourceType == null) {
return null;
}
foreach ($options as $option) {
$targetConfName = $option['conf'];
if ($targetConfName == 'templates*') {
try {
\copyAccountProfileToTemplates($sourceType, $name);
}
catch (\LAMException $e) {
return new \htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage());
}
}
else {
$targetTypeId = $option['typeId'];
$targetTypeManager = new \LAM\TYPES\TypeManager($serverProfiles[$targetConfName]);
$targetType = $targetTypeManager->getConfiguredType($targetTypeId);
if ($targetType != null) {
try {
\copyAccountProfile($sourceType, $name, $targetType);
}
catch (\LAMException $e) {
return new \htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage());
}
}
}
}
return new \htmlStatusMessage('INFO', _('Export successful'));
}
?> ?>