Commit 8bf6a6d9 authored by Côme Bernigaud's avatar Côme Bernigaud
Browse files

Fixes #2919 Rewriting setup using simplePlugin and config classes

Conflicts:
	html/themes/default/setup.css
	plugins/config/class_configInLdap.inc
	setup/class_setupStep_Checks.inc
	setup/class_setupStep_Config1.inc
	setup/class_setupStep_Config2.inc
	setup/class_setupStep_Config3.inc
	setup/class_setupStep_Finish.inc
	setup/class_setupStep_Language.inc
	setup/class_setupStep_Ldap.inc
	setup/class_setupStep_Migrate.inc
	setup/class_setupStep_Welcome.inc
	setup/setup_checks.tpl
	setup/setup_config1.tpl
	setup/setup_config2.tpl
	setup/setup_finish.tpl
	setup/setup_frame.tpl
	setup/setup_welcome.tpl
parent b88dab84
...@@ -17,23 +17,23 @@ ...@@ -17,23 +17,23 @@
the FusionDirectory.conf(5) manual page. the FusionDirectory.conf(5) manual page.
--> -->
<main default="{$cv.location}" <main default="{$cv.location}"
{if $cv.optional.logging} {if $cv.fdLogging}
logging="TRUE" logging="TRUE"
{else} {else}
logging="FALSE" logging="FALSE"
{/if} {/if}
{if $cv.errorlvl} {if $cv.fdDisplayErrors}
displayErrors="TRUE" displayErrors="TRUE"
{else} {else}
displayErrors="FALSE" displayErrors="FALSE"
{/if} {/if}
{if $cv.optional.forcessl} {if $cv.fdForceSSL}
forceSSL="TRUE" forceSSL="TRUE"
{else} {else}
forceSSL="FALSE" forceSSL="FALSE"
{/if} {/if}
templateCompileDirectory="{$cv.optional.compile}" templateCompileDirectory="{$templateCompileDirectory}"
debugLevel="{$cv.optional.debuglevel}" debugLevel="{$cv.fdDebugLevel}"
> >
<!-- Location definition --> <!-- Location definition -->
......
...@@ -86,6 +86,7 @@ setlocale(LC_ALL, $lang); ...@@ -86,6 +86,7 @@ setlocale(LC_ALL, $lang);
$GLOBALS['t_language'] = $lang; $GLOBALS['t_language'] = $lang;
$GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/'; $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
$smarty->assign("rtl", language_is_rtl($lang)); $smarty->assign("rtl", language_is_rtl($lang));
$smarty->assign("must", '<span class="must">*</span>');
/* Set the text domain as 'fusiondirectory' */ /* Set the text domain as 'fusiondirectory' */
$domain = 'fusiondirectory'; $domain = 'fusiondirectory';
...@@ -95,6 +96,14 @@ textdomain($domain); ...@@ -95,6 +96,14 @@ textdomain($domain);
/* Load themes */ /* Load themes */
IconTheme::loadThemes('themes'); IconTheme::loadThemes('themes');
/* Minimal config */
if (!session::global_is_set('config')) {
$config = new config('');
session::global_set('config', $config);
}
$config = session::global_get('config');
load_plist(FALSE);
IconTheme::loadThemes('themes');
/* Call setup */ /* Call setup */
$display = ""; $display = "";
require_once("../setup/main.inc"); require_once("../setup/main.inc");
...@@ -119,10 +128,11 @@ $focus .= '</script>'; ...@@ -119,10 +128,11 @@ $focus .= '</script>';
/* show web frontend */ /* show web frontend */
$setup = session::global_get('setup'); $setup = session::global_get('setup');
$smarty->assign("contents", $display); $smarty->assign("contents", $display.$setup->get_bottom_html());
$smarty->assign("navigation", $setup->get_navigation_html()); $smarty->assign("navigation", $setup->get_navigation_html());
$smarty->assign("header", $setup->get_header_html()); $smarty->assign("headline_image", $setup->get_header_image());
$smarty->assign("bottom", $focus.$setup->get_bottom_html()); $smarty->assign("headline", $setup->get_header_text());
$smarty->assign("focus", $focus);
$smarty->assign("msg_dialogs", msg_dialog::get_dialogs()); $smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
if ($error_collector != "") { if ($error_collector != "") {
......
/********* /*********
* Setup * Setup
*********/ *********/
html.ltr body.setup div#header_left .plugtop {
margin-left:80px;
}
html.rtl div.setup_dialog {
text-align:left;
}
body.setup .plugin_window {
border-radius:5px;
}
div.setup_menu { div.setup_menu {
background-color:#F8F8F8; background-color:#F8F8F8;
...@@ -19,14 +8,6 @@ padding:4px 5px; ...@@ -19,14 +8,6 @@ padding:4px 5px;
border-bottom:1px solid #B0B0B0; border-bottom:1px solid #B0B0B0;
} }
/* Setup content header container */
div.setup_plug_header_container {
}
/* Setup content container */
div.setup_contents_container {
}
/* Setup footer */ /* Setup footer */
div.setup_bottom { div.setup_bottom {
clear:left; clear:left;
...@@ -65,15 +46,8 @@ padding:2px 10px; ...@@ -65,15 +46,8 @@ padding:2px 10px;
vertical-align:middle; vertical-align:middle;
} }
/* Navigation col */
#menucell.setup_navigation { #menucell.setup_navigation {
width:19%; width:200px;
}
html.ltr #menucell.setup_navigation {
float:left;
}
html.rtl #menucell.setup_navigation {
float:right;
} }
/* Navigation title */ /* Navigation title */
...@@ -95,6 +69,10 @@ padding-bottom:8px; ...@@ -95,6 +69,10 @@ padding-bottom:8px;
margin-top:5px; margin-top:5px;
margin-bottom:5px; margin-bottom:5px;
} }
div.navigation_element:first-child, div.navigation_element_active:first-child {
border-top:none;
margin-top:0;
}
/* The box used for each setup step */ /* The box used for each setup step */
#menucell.setup_navigation li.menuitem > a { #menucell.setup_navigation li.menuitem > a {
...@@ -136,6 +114,10 @@ html.rtl #menucell.setup_navigation li.menuitem a.navigation_info { ...@@ -136,6 +114,10 @@ html.rtl #menucell.setup_navigation li.menuitem a.navigation_info {
padding:4px 15px 3px 4px; padding:4px 15px 3px 4px;
} }
.setup_language select#lang_selected {
width:100%;
}
/* /*
Setup step 2 styles Setup step 2 styles
*/ */
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
<table class="framework"> <table class="framework">
<tbody> <tbody>
<tr> <tr>
{if !$hideMenus} {if !$hideMenus}
<!-- Menu --> <!-- Menu -->
<td class="optional" id="menucell"> <td class="optional" id="menucell">
......
...@@ -82,12 +82,8 @@ class config { ...@@ -82,12 +82,8 @@ class config {
*/ */
function __construct($filename, $basedir = "") function __construct($filename, $basedir = "")
{ {
$this->parser = xml_parser_create();
$this->basedir = $basedir; $this->basedir = $basedir;
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, "tag_open", "tag_close");
/* Parse config file directly? */ /* Parse config file directly? */
if ($filename != "") { if ($filename != "") {
$this->parse($filename); $this->parse($filename);
...@@ -123,9 +119,6 @@ class config { ...@@ -123,9 +119,6 @@ class config {
$this->section = ""; $this->section = "";
$this->currentLocation = ""; $this->currentLocation = "";
$this->parser = xml_parser_create();
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, "tag_open", "tag_close");
$this->parse($this->filename); $this->parse($this->filename);
$this->set_current($this->current['NAME']); $this->set_current($this->current['NAME']);
} }
...@@ -141,6 +134,16 @@ class config { ...@@ -141,6 +134,16 @@ class config {
* \param string $filename The filename of the configuration file. * \param string $filename The filename of the configuration file.
*/ */
function parse($filename) function parse($filename)
{
$this->last_modified = filemtime($filename);
$this->filename = $filename;
$fh = fopen($filename, "r");
$xmldata = fread($fh, 100000);
fclose($fh);
$this->parse_data($xmldata);
}
function parse_data ($xmldata)
{ {
$this->data = array( $this->data = array(
"TABS" => array(), "TABS" => array(),
...@@ -149,11 +152,10 @@ class config { ...@@ -149,11 +152,10 @@ class config {
"MENU" => array() "MENU" => array()
); );
$this->last_modified = filemtime($filename); $this->parser = xml_parser_create();
$this->filename = $filename; xml_set_object($this->parser, $this);
$fh = fopen($filename, "r"); xml_set_element_handler($this->parser, "tag_open", "tag_close");
$xmldata = fread($fh, 100000);
fclose($fh);
if (!xml_parse($this->parser, chop($xmldata))) { if (!xml_parse($this->parser, chop($xmldata))) {
$msg = sprintf(_("XML error in fusiondirectory.conf: %s at line %d"), $msg = sprintf(_("XML error in fusiondirectory.conf: %s at line %d"),
xml_error_string(xml_get_error_code($this->parser)), xml_error_string(xml_get_error_code($this->parser)),
...@@ -161,6 +163,7 @@ class config { ...@@ -161,6 +163,7 @@ class config {
msg_dialog::display(_("Configuration error"), $msg, FATAL_ERROR_DIALOG); msg_dialog::display(_("Configuration error"), $msg, FATAL_ERROR_DIALOG);
exit; exit;
} }
xml_parser_free($this->parser);
} }
......
...@@ -178,7 +178,7 @@ function plugin_available($plugin) ...@@ -178,7 +178,7 @@ function plugin_available($plugin)
/*! /*!
* \brief Loads plist and load it in config object * \brief Loads plist and load it in config object
*/ */
function load_plist () function load_plist ($ldap_available = TRUE)
{ {
global $config, $ui; global $config, $ui;
if (!session::global_is_set('plist')) { if (!session::global_is_set('plist')) {
...@@ -188,9 +188,11 @@ function load_plist () ...@@ -188,9 +188,11 @@ function load_plist ()
$plist = new pluglist($config, $ui); $plist = new pluglist($config, $ui);
session::global_set('plist', $plist); session::global_set('plist', $plist);
$config->loadPlist($plist); $config->loadPlist($plist);
if ($ldap_available) {
$config->get_departments(); $config->get_departments();
$config->make_idepartments(); $config->make_idepartments();
} }
}
return session::global_get('plist'); return session::global_get('plist');
} }
......
...@@ -72,6 +72,7 @@ class configInLdap extends simplePlugin ...@@ -72,6 +72,7 @@ class configInLdap extends simplePlugin
static function getAttributesInfo () static function getAttributesInfo ()
{ {
global $config;
$plugins = array(); $plugins = array();
if (session::global_is_set('plist')) { if (session::global_is_set('plist')) {
$plugins = array_keys(session::global_get('plist')->info); $plugins = array_keys(session::global_get('plist')->info);
...@@ -105,12 +106,12 @@ class configInLdap extends simplePlugin ...@@ -105,12 +106,12 @@ class configInLdap extends simplePlugin
'attrs' => array( 'attrs' => array(
new BooleanAttribute ( new BooleanAttribute (
_('rfc2307bis'), _('rfc2307bis'),
_('Enables rfc2307bis style groups. You can use member attributes instead of memberUid in this case.'), _('Enables rfc2307bis style groups. You can use "member" attributes instead of "memberUid" with this schema.'),
'fdRfc2307bis', FALSE, 'fdRfc2307bis', FALSE,
FALSE FALSE
), ),
new BooleanAttribute ( new BooleanAttribute (
_('Schema check'), _('Schema validation'),
_('Enables schema checking during login.'), _('Enables schema checking during login.'),
'fdSchemaCheck', FALSE, 'fdSchemaCheck', FALSE,
FALSE FALSE
...@@ -230,11 +231,13 @@ class configInLdap extends simplePlugin ...@@ -230,11 +231,13 @@ class configInLdap extends simplePlugin
'attrs' => array( 'attrs' => array(
new BooleanAttribute ( new BooleanAttribute (
_('Enable snapshots'), _('This enables you to save certain states of entries and restore them later on.'), _('Enable snapshots'), _('This enables you to save certain states of entries and restore them later on.'),
'fdEnableSnapshots' 'fdEnableSnapshots', FALSE,
TRUE
), ),
new StringAttribute ( new StringAttribute (
_('Snapshot base'), _('The base where snapshots should be stored inside of the LDAP.'), _('Snapshot base'), _('The base where snapshots should be stored inside of the LDAP.'),
'fdSnapshotBase' 'fdSnapshotBase', FALSE,
'ou=snapshots,'.$config->current['BASE']
), ),
) )
), ),
......
<?php <?php
/* /*
This code is part of FusionDirectory (http://www.fusiondirectory.org/) This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2012-2013 FusionDirectory Copyright (C) 2012-2014 FusionDirectory
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
...@@ -18,5 +18,5 @@ ...@@ -18,5 +18,5 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
configInLdap::mainInc('configInLdap', CONFIGRDN.$config->current['BASE'], 'tabs_configInLdap'); simplePlugin::mainInc('configInLdap', CONFIGRDN.$config->current['BASE'], 'tabs_configInLdap');
?> ?>
...@@ -25,27 +25,27 @@ require_once("class_setupStep.inc"); ...@@ -25,27 +25,27 @@ require_once("class_setupStep.inc");
class setup class setup
{ {
var $i_steps = 9; // Number of setup steps var $i_steps; // Number of setup steps
var $i_current = 1; // Current step var $i_current = 0; // Current step
var $i_last = 1; // Last setup step; var $i_previous = 0; // Previous setup step;
var $i_config = 5;
var $o_steps = array(); var $o_steps = array();
var $captured_values = array(); var $captured_values = array();
function __construct() function __construct()
{ {
$i = 1; $this->o_steps = array(
$this->o_steps[$i++] = new Step_Welcome(); new Step_Welcome(),
$this->o_steps[$i++] = new Step_Language(); new Step_Language(),
$this->o_steps[$i++] = new Step_Checks(); new Step_Checks(),
$this->o_steps[$i++] = new Step_Ldap(); new Step_Ldap(),
$this->o_steps[$i++] = new Step_Schema(); new Step_Schema(),
$this->o_steps[$i++] = new Step_Config1(); new Step_Config_before_init(),
$this->o_steps[$i++] = new Step_Config2(); new Step_Migrate(),
$this->o_steps[$i++] = new Step_Config3(); new Step_Finish(),
$this->o_steps[$i++] = new Step_Migrate(); );
$this->o_steps[$i++] = new Step_Finish();
$this->i_steps = count($this->o_steps);
$this->i_steps = $i - 1;
/* Ensure that setup is not reachable if fusiondirectory.conf exist (CONFIG_FILE) */ /* Ensure that setup is not reachable if fusiondirectory.conf exist (CONFIG_FILE) */
if (file_exists(CONFIG_DIR."/".CONFIG_FILE)) { if (file_exists(CONFIG_DIR."/".CONFIG_FILE)) {
...@@ -79,7 +79,7 @@ class setup ...@@ -79,7 +79,7 @@ class setup
$smarty = get_smarty(); $smarty = get_smarty();
$smarty->assign('usePrototype', 'true'); $smarty->assign('usePrototype', 'true');
$this->o_steps[$this->i_last]->set_active(FALSE); $this->o_steps[$this->i_previous]->set_active(FALSE);
$this->o_steps[$this->i_current]->set_active(); $this->o_steps[$this->i_current]->set_active();
$content = $this->o_steps[$this->i_current]->execute(); $content = $this->o_steps[$this->i_current]->execute();
return $content; return $content;
...@@ -118,22 +118,23 @@ class setup ...@@ -118,22 +118,23 @@ class setup
/* check if current setup step is completed now /* check if current setup step is completed now
and activate the next step if possible */ and activate the next step if possible */
for ($i = 1; $i <= $this->i_steps; $i++) { for ($i = 0; $i < $this->i_steps; $i++) {
if ($this->o_steps[$i]->is_completed()) { if ($this->o_steps[$i]->is_completed()) {
if (isset($this->o_steps[($i + 1)])) { if (isset($this->o_steps[($i + 1)])) {
$this->o_steps[($i + 1)]->set_enabled(); $this->o_steps[($i + 1)]->set_enabled();
} }
} else { } else {
$this->disable_steps_from($i + 1); $this->disable_steps_from($i + 1);
break;
} }
} }
} }
/* Disable all following steps, if one step isn't compelted right now .*/ /* Disable all following steps, if one step isn't compelted right now .*/
for ($i = 1; $i <= $this->i_steps; $i++) { for ($i = 0; $i < $this->i_steps; $i++) {
if ($this->o_steps[$i]->is_completed()) { if (!$this->o_steps[$i]->is_completed()) {
} else {
$this->disable_steps_from($i + 1); $this->disable_steps_from($i + 1);
break;
} }
} }
...@@ -151,15 +152,15 @@ class setup ...@@ -151,15 +152,15 @@ class setup
$step = $this->i_current - 1; $step = $this->i_current - 1;
} }
$once = TRUE;
foreach ($_POST as $name => $value) { foreach ($_POST as $name => $value) {
if (preg_match("/^step_[0-9]*$/", $name) && $once) { if (preg_match("/^step_[0-9]*$/", $name)) {
$step = preg_replace("/^step_/", "", $name); $step = preg_replace("/^step_/", "", $name);
break;
} }
} }
if ($this->selectable_step($step)) { if ($this->selectable_step($step)) {
$this->i_last = $this->i_current; $this->i_previous = $this->i_current;
$this->i_current = $step; $this->i_current = $step;
} }
} }
...@@ -167,18 +168,10 @@ class setup ...@@ -167,18 +168,10 @@ class setup
function disable_steps_from($start) function disable_steps_from($start)
{ {
$found = FALSE; for ($i = $start; $i < $this->i_steps; $i++) {
foreach ($this->o_steps as $key => &$step) { $this->o_steps[$i]->set_enabled(FALSE);
if ($key == $start) { $this->o_steps[$i]->set_completed(FALSE);
$found = TRUE;
} }
if ($found) {
$step->set_enabled(FALSE);
$step->set_completed(FALSE);
}
}
unset($step);
} }
...@@ -246,12 +239,16 @@ class setup ...@@ -246,12 +239,16 @@ class setup
return $str; return $str;
} }
/* Create header entry */
function get_header_text()
{
return $this->o_steps[$this->i_current]->get_long_title();
}
/* Create header entry */ /* Create header entry */
function get_header_html() function get_header_image()
{ {
$str = $this->o_steps[$this->i_current]->print_header(); return $this->o_steps[$this->i_current]->header_image;
return $str;
} }
...@@ -273,5 +270,32 @@ class setup ...@@ -273,5 +270,32 @@ class setup
} }
return 0; return 0;
} }
/* Called when LDAP is configured */
function read_ldap_config()
{
global $config;
/* Get attributes from current ldap step */
$tmp = $this->o_steps[$this->i_current]->get_attributes();
foreach ($tmp as $name => $value) {
$this->captured_values[$name] = $value;
}
$smarty = get_smarty();
$cv = $this->captured_values;
/* Fill missing values needed by config file template (config step not done yet) */
$cv['fdLogging'] = FALSE;
$cv['fdDisplayErrors'] = FALSE;
$cv['fdForceSSL'] = TRUE;
$cv['fdDebugLevel'] = 0;
$smarty->assign("cv", xmlentities($cv));
$smarty->assign("config_checksum", md5(file_get_contents(CONFIG_TEMPLATE_DIR.CONFIG_FILE)));
$smarty->assign("templateCompileDirectory", SPOOL_DIR);
$xml = $smarty->fetch(CONFIG_TEMPLATE_DIR.CONFIG_FILE);
$config->parse_data($xml);
$config->set_current($config->data['MAIN']['DEFAULT']);
session::global_un_set('plist');
load_plist();
$this->o_steps[$this->i_config] = new Step_Config($this->