From c680ecceed49c9e60346ff1470f8089286053fc0 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 28 Oct 2012 14:37:54 +0000 Subject: [PATCH] new config file structuring --- lam/HISTORY | 1 + lam/config/{ => templates}/pdf/.htaccess | 0 lam/config/templates/pdf/default.alias.xml | 6 + .../pdf/default.asteriskExt.xml | 0 .../templates/pdf/default.automountType.xml | 6 + .../{ => templates}/pdf/default.dhcp.xml | 0 lam/config/templates/pdf/default.gon.xml | 8 + .../{ => templates}/pdf/default.group.xml | 0 .../{ => templates}/pdf/default.host.xml | 0 .../{ => templates}/pdf/default.mailAlias.xml | 0 .../{ => templates}/pdf/default.netgroup.xml | 0 .../templates/pdf/default.nisObjectType.xml | 7 + .../templates/pdf/default.ppolicyType.xml | 18 ++ .../{ => templates}/pdf/default.smbDomain.xml | 0 lam/config/templates/pdf/default.sudo.xml | 11 + .../{ => templates}/pdf/default.user.xml | 0 .../pdf/default.zarafaAddressListType.xml | 8 + .../pdf/default.zarafaDynamicGroupType.xml | 10 + .../{ => templates}/pdf/logos/.htaccess | 0 .../{ => templates}/pdf/logos/printLogo.jpg | Bin lam/config/{ => templates}/profiles/.htaccess | 0 .../profiles/default.alias} | 0 .../profiles/default.asteriskExt} | 0 .../templates/profiles/default.automountType | 1 + .../{ => templates}/profiles/default.dhcp | 0 lam/config/templates/profiles/default.gon | 1 + lam/config/templates/profiles/default.group | 1 + .../{ => templates}/profiles/default.host | 0 .../profiles/default.mailAlias | 0 .../{ => templates}/profiles/default.netgroup | 0 .../templates/profiles/default.nisObjectType | 1 + .../templates/profiles/default.ppolicyType | 1 + .../profiles/default.smbDomain | 0 lam/config/templates/profiles/default.sudo | 1 + .../{ => templates}/profiles/default.user | 0 .../profiles/default.zarafaAddressListType | 1 + .../profiles/default.zarafaDynamicGroupType | 1 + lam/help/help.inc | 4 +- lam/lib/config.inc | 39 +++ lam/lib/html.inc | 40 ++- lam/lib/lamPDF.inc | 4 +- lam/lib/pdfstruct.inc | 82 +++++-- lam/lib/profiles.inc | 58 ++++- lam/lib/upgrade.inc | 227 ++++++++++++++++++ lam/templates/config/profmanage.php | 6 +- lam/templates/lib/500_lam.js | 67 ++++++ lam/templates/login.php | 29 ++- lam/templates/pdfedit/pdfmain.php | 162 ++++++++++++- lam/templates/profedit/profilemain.php | 147 +++++++++++- 49 files changed, 897 insertions(+), 51 deletions(-) rename lam/config/{ => templates}/pdf/.htaccess (100%) create mode 100644 lam/config/templates/pdf/default.alias.xml rename lam/config/{ => templates}/pdf/default.asteriskExt.xml (100%) create mode 100644 lam/config/templates/pdf/default.automountType.xml rename lam/config/{ => templates}/pdf/default.dhcp.xml (100%) create mode 100644 lam/config/templates/pdf/default.gon.xml rename lam/config/{ => templates}/pdf/default.group.xml (100%) rename lam/config/{ => templates}/pdf/default.host.xml (100%) rename lam/config/{ => templates}/pdf/default.mailAlias.xml (100%) rename lam/config/{ => templates}/pdf/default.netgroup.xml (100%) create mode 100644 lam/config/templates/pdf/default.nisObjectType.xml create mode 100644 lam/config/templates/pdf/default.ppolicyType.xml rename lam/config/{ => templates}/pdf/default.smbDomain.xml (100%) create mode 100644 lam/config/templates/pdf/default.sudo.xml rename lam/config/{ => templates}/pdf/default.user.xml (100%) create mode 100644 lam/config/templates/pdf/default.zarafaAddressListType.xml create mode 100644 lam/config/templates/pdf/default.zarafaDynamicGroupType.xml rename lam/config/{ => templates}/pdf/logos/.htaccess (100%) rename lam/config/{ => templates}/pdf/logos/printLogo.jpg (100%) rename lam/config/{ => templates}/profiles/.htaccess (100%) rename lam/config/{profiles/default.asteriskExt => templates/profiles/default.alias} (100%) rename lam/config/{profiles/default.group => templates/profiles/default.asteriskExt} (100%) create mode 100644 lam/config/templates/profiles/default.automountType rename lam/config/{ => templates}/profiles/default.dhcp (100%) create mode 100644 lam/config/templates/profiles/default.gon create mode 100644 lam/config/templates/profiles/default.group rename lam/config/{ => templates}/profiles/default.host (100%) rename lam/config/{ => templates}/profiles/default.mailAlias (100%) rename lam/config/{ => templates}/profiles/default.netgroup (100%) create mode 100644 lam/config/templates/profiles/default.nisObjectType create mode 100644 lam/config/templates/profiles/default.ppolicyType rename lam/config/{ => templates}/profiles/default.smbDomain (100%) create mode 100644 lam/config/templates/profiles/default.sudo rename lam/config/{ => templates}/profiles/default.user (100%) create mode 100644 lam/config/templates/profiles/default.zarafaAddressListType create mode 100644 lam/config/templates/profiles/default.zarafaDynamicGroupType create mode 100644 lam/lib/upgrade.inc diff --git a/lam/HISTORY b/lam/HISTORY index dd1b6819..983844af 100644 --- a/lam/HISTORY +++ b/lam/HISTORY @@ -1,4 +1,5 @@ December 2012 + - account profiles and PDF structures are now bound to server profile - IMAP: support "/" as path separator (RFE 3575692) diff --git a/lam/config/pdf/.htaccess b/lam/config/templates/pdf/.htaccess similarity index 100% rename from lam/config/pdf/.htaccess rename to lam/config/templates/pdf/.htaccess diff --git a/lam/config/templates/pdf/default.alias.xml b/lam/config/templates/pdf/default.alias.xml new file mode 100644 index 00000000..a7beba30 --- /dev/null +++ b/lam/config/templates/pdf/default.alias.xml @@ -0,0 +1,6 @@ + +
+ + +
+
\ No newline at end of file diff --git a/lam/config/pdf/default.asteriskExt.xml b/lam/config/templates/pdf/default.asteriskExt.xml similarity index 100% rename from lam/config/pdf/default.asteriskExt.xml rename to lam/config/templates/pdf/default.asteriskExt.xml diff --git a/lam/config/templates/pdf/default.automountType.xml b/lam/config/templates/pdf/default.automountType.xml new file mode 100644 index 00000000..99403acb --- /dev/null +++ b/lam/config/templates/pdf/default.automountType.xml @@ -0,0 +1,6 @@ + +
+ + +
+
\ No newline at end of file diff --git a/lam/config/pdf/default.dhcp.xml b/lam/config/templates/pdf/default.dhcp.xml similarity index 100% rename from lam/config/pdf/default.dhcp.xml rename to lam/config/templates/pdf/default.dhcp.xml diff --git a/lam/config/templates/pdf/default.gon.xml b/lam/config/templates/pdf/default.gon.xml new file mode 100644 index 00000000..c7a5bd70 --- /dev/null +++ b/lam/config/templates/pdf/default.gon.xml @@ -0,0 +1,8 @@ + +
+ + + + +
+
\ No newline at end of file diff --git a/lam/config/pdf/default.group.xml b/lam/config/templates/pdf/default.group.xml similarity index 100% rename from lam/config/pdf/default.group.xml rename to lam/config/templates/pdf/default.group.xml diff --git a/lam/config/pdf/default.host.xml b/lam/config/templates/pdf/default.host.xml similarity index 100% rename from lam/config/pdf/default.host.xml rename to lam/config/templates/pdf/default.host.xml diff --git a/lam/config/pdf/default.mailAlias.xml b/lam/config/templates/pdf/default.mailAlias.xml similarity index 100% rename from lam/config/pdf/default.mailAlias.xml rename to lam/config/templates/pdf/default.mailAlias.xml diff --git a/lam/config/pdf/default.netgroup.xml b/lam/config/templates/pdf/default.netgroup.xml similarity index 100% rename from lam/config/pdf/default.netgroup.xml rename to lam/config/templates/pdf/default.netgroup.xml diff --git a/lam/config/templates/pdf/default.nisObjectType.xml b/lam/config/templates/pdf/default.nisObjectType.xml new file mode 100644 index 00000000..26f20a5f --- /dev/null +++ b/lam/config/templates/pdf/default.nisObjectType.xml @@ -0,0 +1,7 @@ + +
+ + + +
+
\ No newline at end of file diff --git a/lam/config/templates/pdf/default.ppolicyType.xml b/lam/config/templates/pdf/default.ppolicyType.xml new file mode 100644 index 00000000..2f0c7ff4 --- /dev/null +++ b/lam/config/templates/pdf/default.ppolicyType.xml @@ -0,0 +1,18 @@ + +
+ + + + + + + + + + + + + + +
+
\ No newline at end of file diff --git a/lam/config/pdf/default.smbDomain.xml b/lam/config/templates/pdf/default.smbDomain.xml similarity index 100% rename from lam/config/pdf/default.smbDomain.xml rename to lam/config/templates/pdf/default.smbDomain.xml diff --git a/lam/config/templates/pdf/default.sudo.xml b/lam/config/templates/pdf/default.sudo.xml new file mode 100644 index 00000000..8745f37e --- /dev/null +++ b/lam/config/templates/pdf/default.sudo.xml @@ -0,0 +1,11 @@ + +
+ + + + + + + +
+
\ No newline at end of file diff --git a/lam/config/pdf/default.user.xml b/lam/config/templates/pdf/default.user.xml similarity index 100% rename from lam/config/pdf/default.user.xml rename to lam/config/templates/pdf/default.user.xml diff --git a/lam/config/templates/pdf/default.zarafaAddressListType.xml b/lam/config/templates/pdf/default.zarafaAddressListType.xml new file mode 100644 index 00000000..37e1a336 --- /dev/null +++ b/lam/config/templates/pdf/default.zarafaAddressListType.xml @@ -0,0 +1,8 @@ + +
+ + + + +
+
\ No newline at end of file diff --git a/lam/config/templates/pdf/default.zarafaDynamicGroupType.xml b/lam/config/templates/pdf/default.zarafaDynamicGroupType.xml new file mode 100644 index 00000000..7ca6725d --- /dev/null +++ b/lam/config/templates/pdf/default.zarafaDynamicGroupType.xml @@ -0,0 +1,10 @@ + +
+ + + + + + +
+
\ No newline at end of file diff --git a/lam/config/pdf/logos/.htaccess b/lam/config/templates/pdf/logos/.htaccess similarity index 100% rename from lam/config/pdf/logos/.htaccess rename to lam/config/templates/pdf/logos/.htaccess diff --git a/lam/config/pdf/logos/printLogo.jpg b/lam/config/templates/pdf/logos/printLogo.jpg similarity index 100% rename from lam/config/pdf/logos/printLogo.jpg rename to lam/config/templates/pdf/logos/printLogo.jpg diff --git a/lam/config/profiles/.htaccess b/lam/config/templates/profiles/.htaccess similarity index 100% rename from lam/config/profiles/.htaccess rename to lam/config/templates/profiles/.htaccess diff --git a/lam/config/profiles/default.asteriskExt b/lam/config/templates/profiles/default.alias similarity index 100% rename from lam/config/profiles/default.asteriskExt rename to lam/config/templates/profiles/default.alias diff --git a/lam/config/profiles/default.group b/lam/config/templates/profiles/default.asteriskExt similarity index 100% rename from lam/config/profiles/default.group rename to lam/config/templates/profiles/default.asteriskExt diff --git a/lam/config/templates/profiles/default.automountType b/lam/config/templates/profiles/default.automountType new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/lam/config/templates/profiles/default.automountType @@ -0,0 +1 @@ + diff --git a/lam/config/profiles/default.dhcp b/lam/config/templates/profiles/default.dhcp similarity index 100% rename from lam/config/profiles/default.dhcp rename to lam/config/templates/profiles/default.dhcp diff --git a/lam/config/templates/profiles/default.gon b/lam/config/templates/profiles/default.gon new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/lam/config/templates/profiles/default.gon @@ -0,0 +1 @@ + diff --git a/lam/config/templates/profiles/default.group b/lam/config/templates/profiles/default.group new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/lam/config/templates/profiles/default.group @@ -0,0 +1 @@ + diff --git a/lam/config/profiles/default.host b/lam/config/templates/profiles/default.host similarity index 100% rename from lam/config/profiles/default.host rename to lam/config/templates/profiles/default.host diff --git a/lam/config/profiles/default.mailAlias b/lam/config/templates/profiles/default.mailAlias similarity index 100% rename from lam/config/profiles/default.mailAlias rename to lam/config/templates/profiles/default.mailAlias diff --git a/lam/config/profiles/default.netgroup b/lam/config/templates/profiles/default.netgroup similarity index 100% rename from lam/config/profiles/default.netgroup rename to lam/config/templates/profiles/default.netgroup diff --git a/lam/config/templates/profiles/default.nisObjectType b/lam/config/templates/profiles/default.nisObjectType new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/lam/config/templates/profiles/default.nisObjectType @@ -0,0 +1 @@ + diff --git a/lam/config/templates/profiles/default.ppolicyType b/lam/config/templates/profiles/default.ppolicyType new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/lam/config/templates/profiles/default.ppolicyType @@ -0,0 +1 @@ + diff --git a/lam/config/profiles/default.smbDomain b/lam/config/templates/profiles/default.smbDomain similarity index 100% rename from lam/config/profiles/default.smbDomain rename to lam/config/templates/profiles/default.smbDomain diff --git a/lam/config/templates/profiles/default.sudo b/lam/config/templates/profiles/default.sudo new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/lam/config/templates/profiles/default.sudo @@ -0,0 +1 @@ + diff --git a/lam/config/profiles/default.user b/lam/config/templates/profiles/default.user similarity index 100% rename from lam/config/profiles/default.user rename to lam/config/templates/profiles/default.user diff --git a/lam/config/templates/profiles/default.zarafaAddressListType b/lam/config/templates/profiles/default.zarafaAddressListType new file mode 100644 index 00000000..8d1c8b69 --- /dev/null +++ b/lam/config/templates/profiles/default.zarafaAddressListType @@ -0,0 +1 @@ + diff --git a/lam/config/templates/profiles/default.zarafaDynamicGroupType b/lam/config/templates/profiles/default.zarafaDynamicGroupType new file mode 100644 index 00000000..8d1c8b69 --- /dev/null +++ b/lam/config/templates/profiles/default.zarafaDynamicGroupType @@ -0,0 +1 @@ + diff --git a/lam/help/help.inc b/lam/help/help.inc index 2a02a469..93f2922b 100644 --- a/lam/help/help.inc +++ b/lam/help/help.inc @@ -160,7 +160,7 @@ $helpArray = array ( "362" => array ("Headline" => _("Import profiles"), "Text" => _("Here you can import account profiles from other server profiles (overwrite existing).")), "363" => array ("Headline" => _("Export profiles"), - "Text" => _("Here you can export account profiles to other server profiles (overwrite existing).")), + "Text" => _("Here you can export account profiles to other server profiles (overwrite existing). You may also export a profile to the global templates. In this case it will always be copied to all server profiles that do not yet have a profile with this name.")), // 400 - 499 // account pages "401" => array ("Headline" => _("Load profile"), @@ -178,7 +178,7 @@ $helpArray = array ( "408" => array ("Headline" => _("Import PDF structures"), "Text" => _("Here you can import PDF structures from other server profiles (overwrite existing).")), "409" => array ("Headline" => _("Export PDF structures"), - "Text" => _("Here you can export PDF structures to other server profiles (overwrite existing).")), + "Text" => _("Here you can export PDF structures to other server profiles (overwrite existing). You may also export a structure to the global templates. In this case it will always be copied to all server profiles that do not yet have a structure with this name.")), // 500 - 599 // LAM Pro "501" => array ("Headline" => _("LDAP suffix"), diff --git a/lam/lib/config.inc b/lam/lib/config.inc index 0aa65de3..f69ae61a 100644 --- a/lam/lib/config.inc +++ b/lam/lib/config.inc @@ -116,6 +116,45 @@ function getConfigProfiles() { return $ret; } +/** + * Deletes the given server profile. + * + * @param String $name profile name + * @return String null if success or error message if failed + */ +function deleteConfigProfile($name) { + if (!preg_match("/^[a-z0-9_-]+$/i", $name)) { + return _("Unable to delete profile!"); + } + $dir = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/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++) { + if (is_dir($subDirs[$i])) { + $dirHandle = @opendir($subDirs[$i]); + while (false !== ($path = readdir($dirHandle))) { + if ($path != '.' && $path != '..') { + if (!@unlink($subDirs[$i] . '/' . $path)) { + logNewMessage(LOG_ERR, 'Unable to delete ' . $subDirs[$i] . '/' . $path); + return _("Unable to delete profile!"); + } + } + } + @closedir($dirHandle); + if (!@rmdir($subDirs[$i])) { + logNewMessage(LOG_ERR, 'Unable to delete ' . $subDirs[$i]); + return _("Unable to delete profile!"); + } + } + } + // delete config file + $confFile = $dir . $_POST['delfilename'] . ".conf"; + if (!@unlink($confFile)) { + logNewMessage(LOG_ERR, 'Unable to delete ' . $confFile); + return _("Unable to delete profile!"); + } +} + /** * Returns the version number of this LAM installation. * Format: .. diff --git a/lam/lib/html.inc b/lam/lib/html.inc index 7e17862f..e7aa321d 100644 --- a/lam/lib/html.inc +++ b/lam/lib/html.inc @@ -947,7 +947,7 @@ class htmlSelect extends htmlElement { $name = ' name="' . $this->name . '" id="' . $this->name . '"'; if ($this->multiSelect) { $multi = ' multiple'; - $name = ' name="' . $this->name . '[]"'; + $name = ' name="' . $this->name . '[]" id="' . $this->name . '"'; } $size = ' size="' . $this->size . '"'; $class = ''; @@ -2514,9 +2514,45 @@ class htmlDiv extends htmlElement { echo ''; return $return; } +} - +/** + * Creates a JavaScript element. + * + * @package metaHTML + */ +class htmlJavaScript extends htmlElement { + /** htmlElement that generates inner content */ + private $content = null; + + /** + * Constructor. + * + * @param String $content script + */ + function __construct($content) { + $this->content = $content; + } + + /** + * Prints the HTML code for this element. + * + * @param string $module Name of account module + * @param array $input List of meta-HTML elements + * @param array $values List of values which override the defaults in $input (name => value) + * @param boolean $restricted If true then no buttons will be displayed + * @param integer $tabindex Start value of tabulator index for input fields + * @param string $scope Account type + * @return array List of input field names and their type (name => type) + */ + function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) { + $return = array(); + echo ''; + return $return; + } } diff --git a/lam/lib/lamPDF.inc b/lam/lib/lamPDF.inc index 31967af8..a5f13d5f 100644 --- a/lam/lib/lamPDF.inc +++ b/lam/lib/lamPDF.inc @@ -86,13 +86,13 @@ class lamPDF extends UFPDF { $this->setMargins('10.0','10.0','10.0'); $this->setAutoPageBreak(true,'20.0'); } - + /** * Creates the PDF page header. */ function header() { if($this->page_definitions['filename'] != 'none') { - $imageFile = substr(__FILE__,0,strlen(__FILE__)- 14) . "config/pdf/logos/" . $this->page_definitions['filename']; + $imageFile = substr(__FILE__,0,strlen(__FILE__)- 14) . "config/pdf/" . $_SESSION['config']->getName() . "/logos/" . $this->page_definitions['filename']; $imgProperties = getimagesize($imageFile); $this->Image($imageFile,10,15,($imgProperties[0] / $this->k) / 5, ($imgProperties[1] / $this->k) / 5,0,"JPG"); } diff --git a/lam/lib/pdfstruct.inc b/lam/lib/pdfstruct.inc index ddc2523d..3f0b8b8d 100644 --- a/lam/lib/pdfstruct.inc +++ b/lam/lib/pdfstruct.inc @@ -37,22 +37,27 @@ include_once("ldap.inc"); /** * This function will return all available PDF structure definitions for the submitted * account scope. - * + * * @param string $scope The account scope the PDF structure definitions should be * returned. - * + * @param string $profile server profile name + * * @return array $scope All available PDF structure definitions for the submitted account - * scope. Each entry is a string being the filename that may be passed to the + * scope. Each entry is a string being the filename that may be passed to the * createModulePDF() function as second argument. */ -function getPDFStructureDefinitions($scope = "user") { +function getPDFStructureDefinitions($scope = "user", $profile = null) { $return = array(); - $path = dirname(__FILE__) . '/../config/pdf/'; + + if (!isset($profile)) { + $profile = $_SESSION['config']->getName(); + } + $path = dirname(__FILE__) . '/../config/pdf/' . $profile; if(is_dir($path)) { $dirHandle = opendir($path); while($file = readdir($dirHandle)) { $struct_file = explode('.',$file); - if(!is_dir($path.$file) && ($file != '.') && ($file != '..') && ($struct_file[1] == $scope) && ($struct_file[2] == 'xml')) { + if(!is_dir($path.$file) && ($file != '.') && ($file != '..') && (sizeof($struct_file) == 3) && ($struct_file[1] == $scope) && ($struct_file[2] == 'xml')) { array_push($return, $struct_file[0]); } } @@ -67,12 +72,12 @@ function getPDFStructureDefinitions($scope = "user") { * * @param string $scope The account scope for wich the PDF structure should be returned. * @param string $pdf_structure Structure name of selected scope wich should be returned. - * + * * @return array PDF structure */ function loadPDFStructureDefinitions($scope='user',$pdf_structure='default') { $parser = new xmlParser(); - $file = dirname(__FILE__) . '/../config/pdf/' . $pdf_structure . '.' . $scope . '.xml'; + $file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $pdf_structure . '.' . $scope . '.xml'; $xml = $parser->parse($file); $border = array(); $structure = array(); @@ -101,8 +106,8 @@ function loadPDFStructureDefinitions($scope='user',$pdf_structure='default') { function savePDFStructureDefinitions($scope,$definition) { if (!preg_match('/[a-zA-Z0-9\-\_]+/',$definition)) return 'no perms'; if (!preg_match('/[a-zA-Z]+/',$scope)) return 'no perms'; - $struct_file = dirname(__FILE__) . '/../config/pdf/' . $definition . '.' . $scope . '.xml'; - if(!is_writable(dirname(__FILE__) . '/../config/pdf/')) { + $struct_file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $definition . '.' . $scope . '.xml'; + if(!is_writable(dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName())) { return 'no perms'; } else { @@ -150,33 +155,33 @@ function savePDFStructureDefinitions($scope,$definition) { /** * Deletes XML file with PDF structure definitions. - * + * * @param string $scope account type * @param string $definition Name of definition to delete - * + * * @return boolean True if file was deleted or false if a problem occured. */ function deletePDFStructureDefinition($scope, $definition) { if (!preg_match('/[a-zA-Z0-9\-\_]+/',$definition)) return false; if (!preg_match('/[a-zA-Z]+/',$scope)) return false; - $file = dirname(__FILE__) . '/../config/pdf/' . $definition . '.' . $scope . '.xml'; + $file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $definition . '.' . $scope . '.xml'; if(is_file($file) && is_writable($file)) { return unlink($file); } else { return false; } - + } /** * This function returns an array with all aviliable logo images. - * + * * @return array list of logo files */ function getAvailableLogos() { $return = array(); - $dirPath = dirname(__FILE__) . '/../config/pdf/logos/'; + $dirPath = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/logos/'; $dirHandle = opendir($dirPath); while($file = readdir($dirHandle)) { if(!is_dir($file) && $file != '.' && $file != '..' && preg_match('/\\.(jpg|png)$/',$file)) { @@ -189,4 +194,47 @@ function getAvailableLogos() { sort($return); return $return; } -?> \ No newline at end of file + + +/** + * Copies PDF profiles to other server profiles. + * + * @param array $pdfProfiles PDF profile names + * @param String $scope account scope + * @param array $dests destinations + * + * @return boolean operation succeeded + */ +function copyPdfProfiles($pdfProfiles, $scope, $dests = array()) { + $state = true; + $profilePath = substr(__FILE__, 0, strlen(__FILE__) - 17) . 'config/pdf/'; + foreach ($pdfProfiles as $profile) { + //part 1: server profile + //part 2: account profile + $tmpArr = explode('##', $profile); + $src = $profilePath . $tmpArr[0] . '/' . $tmpArr[1] . '.' . $scope . '.xml'; + if (!empty($dests)) { + foreach ($dests as $dest) { + if ($dest == 'templates*') { + $dst = substr(__FILE__, 0, strlen(__FILE__) - 17) . 'config/templates/pdf/' . $tmpArr[1] . '.' . $scope . '.xml'; + } else { + $dst = $profilePath . $dest . '/' . $tmpArr[1] . '.' . $scope . '.xml'; + } + if (!@copy($src, $dst)) { + StatusMessage('ERROR', _('Failed to export!'), $tmpArr[1] . '.' . $scope . '.xml'); + $state = false; + } + } + } else { + $dst = $profilePath . $_SESSION['config']->getName() . '/' . $tmpArr[1] . '.' . $scope . '.xml'; + if (!@copy($src, $dst)) { + StatusMessage('ERROR', _('Failed to import!'), $tmpArr[1] . '.' . $scope . '.xml'); + $state = false; + } + } + } + + return $state; +} + +?> diff --git a/lam/lib/profiles.inc b/lam/lib/profiles.inc index d5abe2d6..84b15b29 100644 --- a/lam/lib/profiles.inc +++ b/lam/lib/profiles.inc @@ -33,10 +33,16 @@ $Id$ * Returns an array of string with all available profiles for the given account type * * @param string $scope account type +* @param string $profile server profile name * @return array profile names */ -function getAccountProfiles($scope) { - $dir = @dir(substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles"); +function getAccountProfiles($scope, $profile = null) { + if (!isset($profile)) { + $profile = $_SESSION['config']->getName(); + } + + $dir = @dir(substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/" . $profile); + $ret = array(); $pos = 0; if ($dir) { @@ -56,6 +62,7 @@ function getAccountProfiles($scope) { return $ret; } + /** * Loads an profile of the given account type * @@ -66,7 +73,7 @@ function getAccountProfiles($scope) { function loadAccountProfile($profile, $scope) { if (!preg_match("/^[0-9a-z _-]+$/i", $profile) || !preg_match("/^[a-z]+$/i", $scope)) return false; $settings = array(); - $file = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/" . $profile . "." . $scope; + $file = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/" . $_SESSION['config']->getName() . '/' . $profile . "." . $scope; if (is_file($file) == True) { $file = @fopen($file, "r"); if ($file) { @@ -114,7 +121,7 @@ function saveAccountProfile($attributes, $profile, $scope) { if (!is_array($attributes)) { return false; } - $path = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/" . $profile . "." . $scope; + $path = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/" . $_SESSION['config']->getName() . '/' . $profile . "." . $scope; $file = @fopen($path, "w"); if ($file) { // write attributes @@ -147,7 +154,7 @@ function saveAccountProfile($attributes, $profile, $scope) { function delAccountProfile($file, $scope) { if (!$_SESSION['loggedIn'] == true) return false; if (!preg_match("/^[0-9a-z _-]+$/i", $file) || !preg_match("/^[a-z]+$/i", $scope)) return false; - $prof = substr(__FILE__, 0, strlen(__FILE__) - 16) . "config/profiles/" . $file . "." . $scope; + $prof = substr(__FILE__, 0, strlen(__FILE__) - 16) . "config/profiles/". $_SESSION['config']->getName() . '/' . $file . "." . $scope; if (is_file($prof)) { return @unlink($prof); } @@ -155,4 +162,45 @@ function delAccountProfile($file, $scope) { } +/** + * Copies account profiles to other server profiles. + * + * @param array $accountProfiles account profile names + * @param String $scope account scope + * @param array $dests destinations + * + * @return boolean operation succeeded + */ +function copyAccountProfiles($accountProfiles, $scope, $dests = array()) { + $state = true; + $profilePath = substr(__FILE__, 0, strlen(__FILE__) - 17) . '/config/profiles/'; + 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; + } + } + } + + return $state; +} + ?> diff --git a/lam/lib/upgrade.inc b/lam/lib/upgrade.inc new file mode 100644 index 00000000..09c6c7b4 --- /dev/null +++ b/lam/lib/upgrade.inc @@ -0,0 +1,227 @@ + value) to an account profile + * + * @param array $profiles server profiles + */ +function upgradeConfigToServerProfileFolders($profiles) { + if (!is_writable('../config')) { + StatusMessage('ERROR', 'Upgrade failed.', 'The directory \'/config\' has missing write permissions.'); + return; + } + + // copy default configs + if (!file_exists('../config/templates')) { + @mkdir('../config/templates'); + recursiveCopy('../config/pdf/', '../config/templates/pdf/', $profiles, 'default.'); + recursiveCopy('../config/profiles/', '../config/templates/profiles/', $profiles, 'default.'); + } + + foreach ($profiles as $profile) { + // upgrade PDF configs + $dir = '../config/pdf/' . $profile; + if (!file_exists($dir)) { + recursiveCopy('../config/pdf/', $dir, $profiles); + } + + // upgrade profiles configs + $dir = '../config/profiles/' . $profile; + if (!file_exists($dir)) { + recursiveCopy('../config/profiles/', $dir, $profiles); + } + } + + // delete old files + recursiveDelete('../config/pdf', $profiles); + recursiveDelete('../config/profiles', $profiles); +} + +/** + * Saves an hash array (attribute => value) to an account profile + * + * @param array $profiles server profiles + */ +function copyConfigTemplates($profiles) { + foreach ($profiles as $profile) { + // copy templates but do not override existing files + recursiveCopy('../config/templates/pdf/', '../config/pdf/' . $profile, $profiles, null, false); + recursiveCopy('../config/templates/profiles/', '../config/profiles/' . $profile, $profiles, null, false); + } +} + +/** + * Copy a file or recursively copy a directory + * + * @param string $src - source path to file or directory + * @param string $dst - destination path to file or directory + * @param array $profiles - server profiles (used to avoid copying of newly created folders) + * @param string $fileFilter copy only files that start with the given filter + * @param boolean $overwrite overwrite existing files + */ +function recursiveCopy($src, $dst, $profiles, $fileFilter = null, $overwrite = true) { + $dir = @opendir($src); + if (!file_exists($dst)) { + $tmpState = @mkdir($dst); + if ($tmpState === false) { + StatusMessage('ERROR', 'Upgrade failed.', 'The directory \'' . $dst . '\' could not be created.'); + } + } + while (false !== ($file = readdir($dir))) { + if ($file != '.' && $file != '..' && !in_array($file, $profiles)) { + if (is_dir($src . '/' . $file) && ($file == 'logos')) { + recursiveCopy($src . '/' . $file, $dst . '/' . $file, $profiles, $fileFilter, $overwrite); + } + elseif ((isset($fileFilter) && (strpos($file, $fileFilter) === 0 || $file == '.htaccess')) + || (!isset($fileFilter))) + { + if ($overwrite || !file_exists($dst . '/' . $file)) { + $tmpState = @copy($src . '/' . $file, $dst . '/' . $file); + if ($tmpState === false) { + StatusMessage('ERROR', 'Upgrade failed.', 'The file ' . $file . ' could not be copied.'); + } + } + } + } + } + closedir($dir); +} + + +/** + * Delete a file or recursively delete a directory + * + * @param string $src - path to file or directory + * @param array $profiles - server profiles (used to avoid copying of newly created folders) + */ +function recursiveDelete($src, $profiles) { + if (is_file($src)) { + $tmpState = @unlink($src); + if ($tmpState === false) { + StatusMessage('ERROR', 'Upgrade failed.', 'The file ' . $src . ' could not be deleted.'); + } + return; + } else if (is_dir($src) && is_writable($src)) { + $dir = @opendir($src); + while (false !== ($path = readdir($dir))) { + if ($path != '.' && $path != '..' && !in_array($path, $profiles)) { + recursiveDelete($src . '/' . $path, $profiles); + } + } + @closedir($dir); + + if ($src != '../config/pdf' && $src != '../config/profiles') { + $tmpState = @rmdir($src); + if ($tmpState === false) { + StatusMessage('ERROR', 'Upgrade failed.', 'The directory ' . $src . ' could not be deleted.'); + } + } + return; + } else { + StatusMessage('ERROR', 'Upgrade failed.', 'The directory ' . $src . ' has missing write permissions.'); + return; + } +} + +?> diff --git a/lam/templates/config/profmanage.php b/lam/templates/config/profmanage.php index 6d1a4e67..468e4251 100644 --- a/lam/templates/config/profmanage.php +++ b/lam/templates/config/profmanage.php @@ -89,6 +89,10 @@ if (isset($_POST['action'])) { elseif ($_POST['action'] == "rename") { if (preg_match("/^[a-z0-9_-]+$/i", $_POST['oldfilename']) && preg_match("/^[a-z0-9_-]+$/i", $_POST['renfilename']) && !in_array($_POST['renfilename'], getConfigProfiles())) { if (rename("../../config/" . $_POST['oldfilename'] . ".conf", "../../config/" . $_POST['renfilename'] . ".conf")) { + // rename pdf and profiles folder + rename("../../config/profiles/" . $_POST['oldfilename'], "../../config/profiles/" . $_POST['renfilename']); + rename("../../config/pdf/" . $_POST['oldfilename'], "../../config/pdf/" . $_POST['renfilename']); + $msg = _("Renamed profile."); } else $error = _("Could not rename file!"); @@ -102,7 +106,7 @@ if (isset($_POST['action'])) { } // delete profile elseif ($_POST['action'] == "delete") { - if (preg_match("/^[a-z0-9_-]+$/i", $_POST['delfilename']) && @unlink("../../config/" . $_POST['delfilename'] . ".conf")) { + if (deleteConfigProfile($_POST['delfilename']) == null) { $msg = _("Profile deleted."); } else $error = _("Unable to delete profile!"); diff --git a/lam/templates/lib/500_lam.js b/lam/templates/lib/500_lam.js index c7c2f76f..a58560fb 100644 --- a/lam/templates/lib/500_lam.js +++ b/lam/templates/lib/500_lam.js @@ -320,3 +320,70 @@ function showConfirmationDialog(title, okText, cancelText, dialogDiv, formName, jQuery('#' + dialogDiv).parent().appendTo(document.forms[formName]); } +/** + * Alines the elements with the given IDs to the same width. + * + * @param elementIDs IDs + */ +function equalWidth(elementIDs) { + var maxWidth = 0; + for (var i = 0; i < elementIDs.length; ++i) { + if (jQuery(elementIDs[i]).width() > maxWidth) { + maxWidth = jQuery(elementIDs[i]).width(); + }; + } + for (var i = 0; i < elementIDs.length; ++i) { + jQuery(elementIDs[i]).css({'width': maxWidth - (jQuery(elementIDs[i]).outerWidth() - jQuery(elementIDs[i]).width())}); + } +} + +/** + * Shows the dialog to change the list settings. + * + * @param title dialog title + * @param okText text for Ok button + * @param cancelText text for Cancel button + * @param scope account type + * @param selectFieldName name of select box with profile name + * @param serverProfile profile name + */ +function showDistributionDialog(title, okText, cancelText, scope, type, selectFieldName, serverProfile) { + // show dialog + var buttonList = {}; + var dialogId = ''; + buttonList[cancelText] = function() { jQuery(this).dialog("close"); }; + + if (type == 'export') { + // show structure name to export + jQuery('#exportName').text(jQuery('[name=' + selectFieldName + ']').val()); + dialogId = 'exportDialog'; + buttonList[okText] = function() { document.forms["exportDialogForm"].submit(); }; + jQuery('').attr({ + type: 'hidden', + name: 'exportProfiles[]', + value: serverProfile + '##' + jQuery('[name=' + selectFieldName + ']').val() + }).appendTo('form'); + jQuery('').attr({ + type: 'hidden', + name: 'scope', + value: scope + }).appendTo('form'); + } else if (type == 'import') { + dialogId = 'importDialog_' + scope; + buttonList[okText] = function() { document.forms["importDialogForm_" + scope].submit(); }; + } + + jQuery('#' + dialogId).dialog({ + modal: true, + title: title, + dialogClass: 'defaultBackground', + buttons: buttonList, + width: 'auto' + }); + if (type == 'export') { + equalWidth(new Array('#passwd', '#destServerProfiles')); + } else if (type == 'import') { + equalWidth(new Array('#passwd_' + scope, '#importProfiles_' + scope)); + } +} + diff --git a/lam/templates/login.php b/lam/templates/login.php index 7f80dfd5..6a89adfb 100644 --- a/lam/templates/login.php +++ b/lam/templates/login.php @@ -43,6 +43,9 @@ include_once("../lib/selfService.inc"); /** access to configuration options */ include_once("../lib/config.inc"); // Include config.inc which provides Config class +/** Upgrade functions */ +include_once("../lib/upgrade.inc"); + // set session save path if (strtolower(session_module_name()) == 'files') { session_save_path(dirname(__FILE__) . '/../sess'); @@ -176,6 +179,20 @@ function display_LoginPage($config_object) { echo "\n"; } + // upgrade if pdf/profiles contain single files + if (containsFiles('../config/profiles') || containsFiles('../config/pdf')) { + echo 'bla'; + $result = testPermissions(); + if (sizeof($result) > 0) { + StatusMessage('ERROR', 'Unable to migrate configuration files. Please allow write access to these paths:', implode('
', $result)); + } + else { + upgradeConfigToServerProfileFolders(getConfigProfiles()); + } + } + // copy any missing default profiles + copyConfigTemplates(getConfigProfiles()); + // set focus on password field echo "