From cfa027b623a922b02b6c382549bbae80708c958a Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Thu, 18 Nov 2010 13:44:55 +0100 Subject: [PATCH] Follow symlinks if necessary. --- horde/admin/config/config.php | 19 +++++++++++-------- horde/admin/config/scripts.php | 16 ++++++++++------ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/horde/admin/config/config.php b/horde/admin/config/config.php index 382564e1b..e217d8b43 100644 --- a/horde/admin/config/config.php +++ b/horde/admin/config/config.php @@ -34,9 +34,13 @@ if (file_exists($registry->get('fileroot', $app) . '/config/conf.bak.php')) { } $php = ''; +$path = $registry->get('fileroot', $app) . '/config'; +$configFile = $path . '/conf.php'; +if (is_link($configFile)) { + $configFile = readlink($configFile); +} if (Horde_Util::getFormData('submitbutton') == _("Revert Configuration")) { - $path = $registry->get('fileroot', $app) . '/config'; - if (@copy($path . '/conf.bak.php', $path . '/conf.php')) { + if (@copy($path . '/conf.bak.php', $configFile)) { $notification->push(_("Successfully reverted configuration. Reload to see changes."), 'horde.success'); @unlink($path . '/conf.bak.php'); } else { @@ -45,24 +49,23 @@ if (Horde_Util::getFormData('submitbutton') == _("Revert Configuration")) { } elseif ($form->validate($vars)) { $config = new Horde_Config($app); $php = $config->generatePHPConfig($vars); - $path = $registry->get('fileroot', $app) . '/config'; - if (file_exists($path . '/conf.php')) { - if (@copy($path . '/conf.php', $path . '/conf.bak.php')) { + if (file_exists($configFile)) { + if (@copy($configFile, $path . '/conf.bak.php')) { $notification->push(sprintf(_("Successfully saved the backup configuration file %s."), Horde_Util::realPath($path . '/conf.bak.php')), 'horde.success'); } else { $notification->push(sprintf(_("Could not save the backup configuration file %s."), Horde_Util::realPath($path . '/conf.bak.php')), 'horde.warning'); } } - if ($fp = @fopen($path . '/conf.php', 'w')) { + if ($fp = @fopen($configFile, 'w')) { /* Can write, so output to file. */ fwrite($fp, $php); fclose($fp); - $notification->push(sprintf(_("Successfully wrote %s"), Horde_Util::realPath($path . '/conf.php')), 'horde.success'); + $notification->push(sprintf(_("Successfully wrote %s"), Horde_Util::realPath($configFile)), 'horde.success'); $registry->clearCache(); Horde::url('admin/config/index.php', true)->redirect(); } else { /* Cannot write. */ - $notification->push(sprintf(_("Could not save the configuration file %s. You can either use one of the options to save the code back on %s or copy manually the code below to %s."), Horde_Util::realPath($path . '/conf.php'), Horde::link(Horde::url('admin/config/index.php') . '#update', _("Configuration")) . _("Configuration") . '', Horde_Util::realPath($path . '/conf.php')), 'horde.warning', array('content.raw')); + $notification->push(sprintf(_("Could not save the configuration file %s. You can either use one of the options to save the code back on %s or copy manually the code below to %s."), Horde_Util::realPath($configFile), Horde::link(Horde::url('admin/config/index.php') . '#update', _("Configuration")) . _("Configuration") . '', Horde_Util::realPath($configFile)), 'horde.warning', array('content.raw')); /* Save to session. */ $session->set('horde', 'config/' . $app, $php); diff --git a/horde/admin/config/scripts.php b/horde/admin/config/scripts.php index 1cad990ef..57f019f35 100644 --- a/horde/admin/config/scripts.php +++ b/horde/admin/config/scripts.php @@ -40,22 +40,26 @@ if ($clean == 'tmp') { $data = ''; if ($setup == 'conf' && $type == 'php') { - /* A bit ugly here, save PHP code into a string for creating the script - * to be run at the command prompt. */ + /* Save PHP code into a string for creating the script to be run at the + * command prompt. */ $data = '#!/usr/bin/env php' . "\n"; $data .= 'get('horde', 'config/') as $app => $php) { $path = $registry->get('fileroot', $app) . '/config'; + $data .= '$conf = \'' . $path . '/conf.php\';' . "\n"; /* Add code to save backup. */ - $data .= 'if (file_exists(\'' . $path . '/conf.php\')) {' . "\n"; - $data .= ' if (@copy(\'' . $path . '/conf.php\', \'' . $path . '/conf.bak.php\')) {' . "\n"; + $data .= 'if (file_exists(\'$conf\')) {' . "\n"; + $data .= ' if (is_link(\'$conf\')) {' . "\n"; + $data .= ' $conf = readlink($conf);' . "\n"; + $data .= ' }' . "\n"; + $data .= ' if (@copy(\'$conf\', \'' . $path . '/conf.bak.php\')) {' . "\n"; $data .= ' echo \'Successfully saved backup configuration.\' . "\n";' . "\n"; $data .= ' } else {' . "\n"; $data .= ' echo \'Could NOT save a backup configuation.\' . "\n";' . "\n"; $data .= ' }' . "\n"; $data .= '}' . "\n"; - $data .= 'if ($fp = @fopen(\'' . $path . '/conf.php\', \'w\')) {' . "\n"; + $data .= 'if ($fp = @fopen(\'$conf\', \'w\')) {' . "\n"; $data .= ' fwrite($fp, \''; $data .= str_replace(array('\\', '\''), array('\\\\', '\\\''), $php); $data .= '\');' . "\n"; @@ -78,7 +82,7 @@ if ($save != 'tmp') { $tmp_dir = Horde::getTempDir(); /* Add self-destruct code. */ $data .= 'echo \'Self-destructing...\' . "\n";' . "\n"; -$data .= 'if (unlink(__FILE__)) {' . "\n"; +$data .= 'if (@unlink(__FILE__)) {' . "\n"; $data .= ' echo \'Upgrade script deleted.\' . "\n";' . "\n"; $data .= '} else {' . "\n"; $data .= ' echo \'WARNING!!! REMOVE SCRIPT MANUALLY FROM ' . $tmp_dir . '\' . "\n";' . "\n"; -- 2.11.0