1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
<?php
/**
* $Horde: horde/admin/setup/config.php,v 1.24.4.3 2005/01/31 09:28:27 jan Exp $
*
* Copyright 1999-2005 Charles J. Hagenbuch <chuck@horde.org>
* Copyright 1999-2005 Jon Parise <jon@horde.org>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*/
@define('HORDE_BASE', dirname(__FILE__) . '/../..');
require_once HORDE_BASE . '/lib/base.php';
require_once 'Horde/Form.php';
require_once 'Horde/Form/Action.php';
require_once 'Horde/Form/Renderer.php';
require_once 'Horde/Config.php';
require_once 'Horde/Variables.php';
if (!Auth::isAdmin()) {
Horde::fatal('Forbidden.', __FILE__, __LINE__);
}
if (!Util::extensionExists('domxml') && !Util::extensionExists('dom')) {
Horde::fatal('You need the domxml PHP extension to use the configuration tool.', __FILE__, __LINE__);
}
$app = Util::getFormData('app');
$appname = $registry->get('name', $app);
$title = sprintf(_("%s Setup"), $appname);
if ($app === null &&
in_array($app, $registry->listApps(array('inactive', 'hidden', 'notoolbar', 'active', 'admin')))) {
$notification->push(_("Invalid application."), 'horde.error');
$url = Horde::applicationUrl('admin/setup/index.php', true);
header('Location: ' . $url);
exit;
}
$vars = Variables::getDefaultVariables();
$form = &new ConfigForm($vars, $app);
$form->setButtons(sprintf(_("Generate %s Configuration"), $appname));
if (file_exists($registry->get('fileroot', $app) . '/config/conf.php.bak')) {
$form->appendButtons(_("Revert Configuration"));
}
$php = '';
if (Util::getFormData('submitbutton') == _("Revert Configuration")) {
$path = $registry->get('fileroot', $app) . '/config';
if (@copy($path . '/conf.php.bak', $path . '/conf.php')) {
$notification->push(_("Successfully reverted configuration. Reload to see changes."), 'horde.success');
@unlink($path . '/conf.php.bak');
} else {
$notification->push(_("Could not revert configuration."), 'horde.error');
}
} 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.php.bak')) {
$notification->push(sprintf(_("Successfully saved the backup configuration file %s."), $path .'/conf.php.bak'), 'horde.success');
} else {
$notification->push(sprintf(_("Could not save the backup configuration file %s."), $path .'/conf.php.bak'), 'horde.warning');
}
}
if ($fp = @fopen($path . '/conf.php', 'w')) {
/* Can write, so output to file. */
fwrite($fp, String::convertCharset($php, NLS::getCharset(), 'iso-8859-1'));
fclose($fp);
$notification->push(sprintf(_("Successfully wrote %s"), $path . '/conf.php'), 'horde.success');
} else {
/* Can not 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."), $path . '/conf.php', Horde::link(Horde::url('index.php') . '#update', _("Setup")) . _("Setup") . '</a>', $path . '/conf.php'), 'horde.warning', array('content.raw'));
/* Save to session. */
$_SESSION['_config'][$app] = $php;
}
} elseif ($form->isSubmitted()) {
$notification->push(_("There was an error in the configuration form. Perhaps you left out a required field."), 'horde.error');
}
/* Render the configuration form. */
require_once 'Horde/UI/VarRenderer.php';
$renderer = &new Horde_Form_Renderer();
$renderer->setAttrColumnWidth('50%');
$form = Util::bufferOutput(array($form, 'renderActive'), $renderer, $vars, 'config.php', 'post');
/* Set up the template. */
require_once 'Horde/Template.php';
$template = &new Horde_Template();
$template->set('php', htmlspecialchars($php), true);
/* Create the link for the diff popup only if stored in session. */
if (!empty($_SESSION['_config'][$app])) {
Horde::addScriptFile('popup.js', 'horde', true);
$url = Horde::applicationUrl('admin/setup/diff.php');
$url = Util::addParameter($url, 'app', $app);
$link = Horde::link('', _("show differences"), '', '', 'popup(\'' . $url . '\',640, 480); return false;') . _("show differences") . '</a>';
$template->set('diff_popup', $link);
}
$template->set('form', $form);
$template->set('notify', Util::bufferOutput(array($notification, 'notify')));
$template->setOption('gettext', true);
require HORDE_TEMPLATES . '/common-header.inc';
require HORDE_TEMPLATES . '/admin/common-header.inc';
echo $template->fetch(HORDE_TEMPLATES . '/admin/setup/config.html');
require HORDE_TEMPLATES . '/common-footer.inc';
|