3
* Script to show the differences between the currently saved and the newly
4
* generated configuration.
6
* $Horde: horde/admin/setup/diff.php,v 1.4.10.1 2005/01/03 12:25:29 jan Exp $
8
* Copyright 2004-2005 The Horde Project (http://www.horde.org/)
10
* See the enclosed file COPYING for license information (LGPL). If you
11
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
14
define('HORDE_BASE', dirname(__FILE__) . '/../..');
15
require_once HORDE_BASE . '/lib/base.php';
16
require_once 'Horde/Form.php';
17
require_once 'Horde/Config.php';
18
require_once 'Horde/Template.php';
19
include_once 'Text/Diff.php';
20
include_once 'Text/Diff/Renderer.php';
22
if (!Auth::isAdmin()) {
23
Horde::fatal('Forbidden.', __FILE__, __LINE__);
26
/* Set up the diff renderer. */
27
$render_type = Util::getFormData('render', 'inline');
28
include_once 'Text/Diff/Renderer/' . $render_type . '.php';
29
$class = 'Text_Diff_Renderer_' . $render_type;
30
$renderer = &new $class();
33
* Private function to render the differences for a specific app.
35
function _getDiff($app)
37
global $renderer, $registry;
39
/* Read the existing configuration. */
41
$path = $registry->get('fileroot', $app) . '/config';
42
$size = @filesize($path . '/conf.php');
43
if ($size && is_resource($fp = @fopen($path . '/conf.php', 'r'))) {
44
$current_config = @fread($fp, $size);
47
/* Calculate the differences. */
48
$diff = &new Text_Diff(explode("\n", htmlentities($current_config)),
49
explode("\n", htmlentities($_SESSION['_config'][$app])));
50
//return nl2br($renderer->render($diff));
51
$diff = $renderer->render($diff);
55
return _("No change.");
60
/* Only bother to do anything if there is any config. */
61
if (!empty($_SESSION['_config'])) {
62
/* Set up the toggle button for inline/unified. */
63
$url = Horde::applicationUrl('admin/setup/diff.php');
64
$url = Util::addParameter($url, 'render', ($render_type == 'inline') ? 'unified' : 'inline');
66
if ($app = Util::getFormData('app')) {
67
/* Handle a single app request. */
68
$toggle_renderer = Horde::link($url . '#' . $app) . (($render_type == 'inline') ? _("unified") : _("inline")) . '</a>';
69
$diffs[] = array('app' => $app,
70
'diff' => _getDiff($app),
71
'toggle_renderer' => $toggle_renderer);
73
/* List all the apps with generated configuration. */
74
ksort($_SESSION['_config']);
75
foreach ($_SESSION['_config'] as $app => $config) {
76
$toggle_renderer = Horde::link($url . '#' . $app) . (($render_type == 'inline') ? _("unified") : _("inline")) . '</a>';
77
$diffs[] = array('app' => $app,
78
'diff' => _getDiff($app),
79
'toggle_renderer' => $toggle_renderer);
84
/* Set up the template. */
85
$template = &new Horde_Template();
86
$template->setOption('gettext', true);
87
$template->set('diffs', $diffs, true);
89
$title = _("Configuration Differences");
90
require HORDE_TEMPLATES . '/common-header.inc';
91
echo $template->fetch(HORDE_TEMPLATES . '/admin/setup/diff.html');
92
require HORDE_TEMPLATES . '/common-footer.inc';