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
......@@ -5,8 +5,8 @@
Old services that are not based on simpleService needs to be listed here
-->
<serverservice>
<tab class="serviceDHCP" />
<tab class="serviceDNS" />
<tab class="serviceDHCP" />
<tab class="serviceDNS" />
</serverservice>
<!-- Main section **********************************************************
......@@ -17,23 +17,23 @@
the FusionDirectory.conf(5) manual page.
-->
<main default="{$cv.location}"
{if $cv.optional.logging}
{if $cv.fdLogging}
logging="TRUE"
{else}
logging="FALSE"
{/if}
{if $cv.errorlvl}
{if $cv.fdDisplayErrors}
displayErrors="TRUE"
{else}
displayErrors="FALSE"
{/if}
{if $cv.optional.forcessl}
{if $cv.fdForceSSL}
forceSSL="TRUE"
{else}
forceSSL="FALSE"
{/if}
templateCompileDirectory="{$cv.optional.compile}"
debugLevel="{$cv.optional.debuglevel}"
templateCompileDirectory="{$templateCompileDirectory}"
debugLevel="{$cv.fdDebugLevel}"
>
<!-- Location definition -->
......
......@@ -86,6 +86,7 @@ setlocale(LC_ALL, $lang);
$GLOBALS['t_language'] = $lang;
$GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
$smarty->assign("rtl", language_is_rtl($lang));
$smarty->assign("must", '<span class="must">*</span>');
/* Set the text domain as 'fusiondirectory' */
$domain = 'fusiondirectory';
......@@ -95,6 +96,14 @@ textdomain($domain);
/* Load 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 */
$display = "";
require_once("../setup/main.inc");
......@@ -119,11 +128,12 @@ $focus .= '</script>';
/* show web frontend */
$setup = session::global_get('setup');
$smarty->assign("contents", $display);
$smarty->assign("navigation", $setup->get_navigation_html());
$smarty->assign("header", $setup->get_header_html());
$smarty->assign("bottom", $focus.$setup->get_bottom_html());
$smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
$smarty->assign("contents", $display.$setup->get_bottom_html());
$smarty->assign("navigation", $setup->get_navigation_html());
$smarty->assign("headline_image", $setup->get_header_image());
$smarty->assign("headline", $setup->get_header_text());
$smarty->assign("focus", $focus);
$smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
if ($error_collector != "") {
$smarty->assign("php_errors", preg_replace("/%BUGBODY%/", $error_collector_mailto, $error_collector)."</div>");
......
/*********
* 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 {
background-color:#F8F8F8;
......@@ -19,14 +8,6 @@ padding:4px 5px;
border-bottom:1px solid #B0B0B0;
}
/* Setup content header container */
div.setup_plug_header_container {
}
/* Setup content container */
div.setup_contents_container {
}
/* Setup footer */
div.setup_bottom {
clear:left;
......@@ -65,15 +46,8 @@ padding:2px 10px;
vertical-align:middle;
}
/* Navigation col */
#menucell.setup_navigation {
width:19%;
}
html.ltr #menucell.setup_navigation {
float:left;
}
html.rtl #menucell.setup_navigation {
float:right;
width:200px;
}
/* Navigation title */
......@@ -95,6 +69,10 @@ padding-bottom:8px;
margin-top: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 */
#menucell.setup_navigation li.menuitem > a {
......@@ -136,6 +114,10 @@ html.rtl #menucell.setup_navigation li.menuitem a.navigation_info {
padding:4px 15px 3px 4px;
}
.setup_language select#lang_selected {
width:100%;
}
/*
Setup step 2 styles
*/
......
......@@ -25,31 +25,30 @@
</div>
</div>
<table class="framework">
<tbody>
<tr>
<table class="framework">
<tbody>
<tr>
{if !$hideMenus}
<!-- Menu -->
<td class="optional" id="menucell">
{$menu}
<br/>
</td>
{/if}
{if !$hideMenus}
<!-- Menu -->
<td class="optional" id="menucell">
{$menu}
<br/>
</td>
<!-- Plugin window -->
<td id="maincell">
{$msg_dialogs}
<div class="plugin_window">
{$contents}
</div>
{if $channel != ""}
<input type="hidden" name="_channel_" value="{$channel}"/>
{/if}
<!-- Plugin window -->
<td id="maincell">
{$msg_dialogs}
<div class="plugin_window">
{$contents}
</div>
{if $channel != ""}
<input type="hidden" name="_channel_" value="{$channel}"/>
{/if}
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
{$errors}
{$focus}
......
......@@ -82,12 +82,8 @@ class config {
*/
function __construct($filename, $basedir = "")
{
$this->parser = xml_parser_create();
$this->basedir = $basedir;
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, "tag_open", "tag_close");
/* Parse config file directly? */
if ($filename != "") {
$this->parse($filename);
......@@ -123,9 +119,6 @@ class config {
$this->section = "";
$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->set_current($this->current['NAME']);
}
......@@ -141,6 +134,16 @@ class config {
* \param string $filename The filename of the configuration file.
*/
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(
"TABS" => array(),
......@@ -149,11 +152,10 @@ class config {
"MENU" => array()
);
$this->last_modified = filemtime($filename);
$this->filename = $filename;
$fh = fopen($filename, "r");
$xmldata = fread($fh, 100000);
fclose($fh);
$this->parser = xml_parser_create();
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, "tag_open", "tag_close");
if (!xml_parse($this->parser, chop($xmldata))) {
$msg = sprintf(_("XML error in fusiondirectory.conf: %s at line %d"),
xml_error_string(xml_get_error_code($this->parser)),
......@@ -161,6 +163,7 @@ class config {
msg_dialog::display(_("Configuration error"), $msg, FATAL_ERROR_DIALOG);
exit;
}
xml_parser_free($this->parser);
}
......
......@@ -178,7 +178,7 @@ function plugin_available($plugin)
/*!
* \brief Loads plist and load it in config object
*/
function load_plist ()
function load_plist ($ldap_available = TRUE)
{
global $config, $ui;
if (!session::global_is_set('plist')) {
......@@ -188,8 +188,10 @@ function load_plist ()
$plist = new pluglist($config, $ui);
session::global_set('plist', $plist);
$config->loadPlist($plist);
$config->get_departments();
$config->make_idepartments();
if ($ldap_available) {
$config->get_departments();
$config->make_idepartments();
}
}
return session::global_get('plist');
}
......
......@@ -72,6 +72,7 @@ class configInLdap extends simplePlugin
static function getAttributesInfo ()
{
global $config;
$plugins = array();
if (session::global_is_set('plist')) {
$plugins = array_keys(session::global_get('plist')->info);
......@@ -105,12 +106,12 @@ class configInLdap extends simplePlugin
'attrs' => array(
new BooleanAttribute (
_('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,
FALSE
),
new BooleanAttribute (
_('Schema check'),
_('Schema validation'),
_('Enables schema checking during login.'),
'fdSchemaCheck', FALSE,
FALSE
......@@ -230,11 +231,13 @@ class configInLdap extends simplePlugin
'attrs' => array(
new BooleanAttribute (
_('Enable snapshots'), _('This enables you to save certain states of entries and restore them later on.'),
'fdEnableSnapshots'
'fdEnableSnapshots', FALSE,
TRUE
),
new StringAttribute (
_('Snapshot base'), _('The base where snapshots should be stored inside of the LDAP.'),
'fdSnapshotBase'
'fdSnapshotBase', FALSE,
'ou=snapshots,'.$config->current['BASE']
),
)
),
......
<?php
/*
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
it under the terms of the GNU General Public License as published by
......@@ -18,5 +18,5 @@
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");
class setup
{
var $i_steps = 9; // Number of setup steps
var $i_current = 1; // Current step
var $i_last = 1; // Last setup step;
var $i_steps; // Number of setup steps
var $i_current = 0; // Current step
var $i_previous = 0; // Previous setup step;
var $i_config = 5;
var $o_steps = array();
var $captured_values = array();
function __construct()
{
$i = 1;
$this->o_steps[$i++] = new Step_Welcome();
$this->o_steps[$i++] = new Step_Language();
$this->o_steps[$i++] = new Step_Checks();
$this->o_steps[$i++] = new Step_Ldap();
$this->o_steps[$i++] = new Step_Schema();
$this->o_steps[$i++] = new Step_Config1();
$this->o_steps[$i++] = new Step_Config2();
$this->o_steps[$i++] = new Step_Config3();
$this->o_steps[$i++] = new Step_Migrate();
$this->o_steps[$i++] = new Step_Finish();
$this->i_steps = $i - 1;
$this->o_steps = array(
new Step_Welcome(),
new Step_Language(),
new Step_Checks(),
new Step_Ldap(),
new Step_Schema(),
new Step_Config_before_init(),
new Step_Migrate(),
new Step_Finish(),
);
$this->i_steps = count($this->o_steps);
/* Ensure that setup is not reachable if fusiondirectory.conf exist (CONFIG_FILE) */
if (file_exists(CONFIG_DIR."/".CONFIG_FILE)) {
......@@ -79,7 +79,7 @@ class setup
$smarty = get_smarty();
$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();
$content = $this->o_steps[$this->i_current]->execute();
return $content;
......@@ -118,22 +118,23 @@ class setup
/* check if current setup step is completed now
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 (isset($this->o_steps[($i + 1)])) {
$this->o_steps[($i + 1)]->set_enabled();
}
} else {
$this->disable_steps_from($i + 1);
break;
}
}
}
/* Disable all following steps, if one step isn't compelted right now .*/
for ($i = 1; $i <= $this->i_steps; $i++) {
if ($this->o_steps[$i]->is_completed()) {
} else {
for ($i = 0; $i < $this->i_steps; $i++) {
if (!$this->o_steps[$i]->is_completed()) {
$this->disable_steps_from($i + 1);
break;
}
}
......@@ -151,34 +152,26 @@ class setup
$step = $this->i_current - 1;
}
$once = TRUE;
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);
break;
}
}
if ($this->selectable_step($step)) {
$this->i_last = $this->i_current;
$this->i_current = $step;
$this->i_previous = $this->i_current;
$this->i_current = $step;
}
}
function disable_steps_from($start)
{
$found = FALSE;
foreach ($this->o_steps as $key => &$step) {
if ($key == $start) {
$found = TRUE;
}
if ($found) {
$step->set_enabled(FALSE);
$step->set_completed(FALSE);
}
for ($i = $start; $i < $this->i_steps; $i++) {
$this->o_steps[$i]->set_enabled(FALSE);
$this->o_steps[$i]->set_completed(FALSE);
}
unset($step);
}
......@@ -246,12 +239,16 @@ class setup
return $str;
}
/* Create header entry */
function get_header_text()
{
return $this->o_steps[$this->i_current]->get_long_title();
}
/* Create header entry */
function get_header_html()
function get_header_image()
{
$str = $this->o_steps[$this->i_current]->print_header();
return $str;
return $this->o_steps[$this->i_current]->header_image;
}
......@@ -273,5 +270,32 @@ class setup
}
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->captured_values);
}
}
?>
......@@ -19,6 +19,147 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class setupStep extends simplePlugin
{
protected $s_title = "Still undefined";
protected $s_title_long = "Still undefined";
protected $s_info = "Still undefined";
var $is_active = FALSE;
var $is_enabled = FALSE;
var $is_completed = FALSE;
var $header_image = "images/setup/user.png";
static function getAttributesInfo()
{
return array();
}
function __construct()
{
global $config;
parent::__construct($config);
$this->update_strings();
}
function update_strings()
{
die('abstract method');
}
function get_title()
{
return $this->s_title;
}
function get_long_title()
{
return $this->s_title_long;
}
function get_small_info()
{
return $this->s_info;
}
function is_active()
{
return $this->is_active;
}
function is_enabled()
{
return $this->is_enabled;
}
function is_completed()
{
return $this->is_completed;
}
function set_active($value = TRUE)
{
$this->is_active = ($value == TRUE);
}
function set_enabled($value = TRUE)
{
$this->is_enabled = ($value == TRUE);
}
function set_completed($value = TRUE)
{
$this->is_completed = ($value == TRUE);
}
/* Return attributes handled by this setup step */
function get_attributes()
{
$tmp = array();
foreach (array_keys($this->attributesAccess) as $attr) {
$tmp[$attr] = $this->$attr;
}
return $tmp;
}
/* bypass acl system as there is no user login */
function acl_is_writeable($attribute, $skip_write = FALSE)
{
return TRUE;
}
function acl_is_readable($attribute)
{
return TRUE;
}
function acl_is_createable($base = "")
{
return TRUE;
}
function acl_is_removeable($base = "")
{