class_setup.inc 9.52 KiB
<?php
/*
  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
  Copyright (C) 2003  Cajus Pollmeier
  Copyright (C) 2011-2019  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
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
require_once("class_setupStep.inc");
class setup implements FusionDirectoryDialog
  /* Number of setup steps */
  var $i_steps;
  /* Current step */
  var $i_current        = 0;
  /* Previous setup step */
  var $i_previous       = 0;
  var $i_config         = 4;
  var $o_steps          = [];
  var $captured_values  = [];
  function __construct ()
    $this->o_steps = [
      new setupStepWelcome($this),
      new setupStepLanguage($this),
      new setupStepChecks($this),
      new setupStepLdap($this),
      new setupStepConfigBeforeInit($this),
      new setupStepMigrate($this),
      new setupStepFinish($this),
    $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)) {
      session::destroy('Invalid setup.php call');
      header('Location: index.php');
      exit();
  public function render (): string
    /* Display phpinfo() dialog when $_GET['info'] is set,
     *  but only do this, if user is allowed to use the setup.
     * If setupsetupStepWelcome is_completed, we are allowed to view those infos-
    if (isset($_GET['info']) && preg_match('/setupStepWelcome/i', get_class($this->o_steps[0])) && $this->o_steps[0]->is_completed()) {
      phpinfo();
      exit();
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
$smarty = get_smarty(); $smarty->assign('usePrototype', 'true'); $this->o_steps[$this->i_previous]->set_active(FALSE); $this->o_steps[$this->i_current]->set_active(); return $this->o_steps[$this->i_current]->render(); } /* Save posted attributes */ public function readPost () { /* Call readPost for current setup step */ $this->o_steps[$this->i_current]->readPost(); /* Check if image button requests next page */ foreach ($_POST as $name => $value) { if (preg_match('/^next_(x|y)/', $name)) { $_POST['next'] = TRUE; } if (preg_match('/^last_(x|y)/', $name)) { $_POST['last'] = TRUE; } } /* Detect target step */ $step = -1; if (isset($_POST['setup_goto_step'])) { $step = $_POST['setup_goto_step']; } if (isset($_GET['step'])) { $step = $_GET['step']; } elseif (isset($_POST['next'])) { $step = $this->i_current + 1; } elseif (isset($_POST['last'])) { $step = $this->i_current - 1; } foreach ($_POST as $name => $value) { if (preg_match("/^step_[0-9]*$/", $name)) { $step = preg_replace("/^step_/", "", $name); break; } } $this->i_previous = $this->i_current; $this->i_current = $step; } public function update (): bool { $this->o_steps[$this->i_previous]->update(); /* Get attributes from setup step */ $tmp = $this->o_steps[$this->i_previous]->get_attributes(); foreach ($tmp as $name => $value) { $this->captured_values[$name] = $value; } /* Set parent */ foreach ($this->o_steps as $key => $value) { $this->o_steps[$key]->parent = $this; } /* Display step error messages */ $msgs = $this->o_steps[$this->i_previous]->check(); msg_dialog::displayChecks($msgs);
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
for ($i = 0; $i < $this->i_steps; $i++) { if ($this->o_steps[$i]->is_completed()) { /* If step is completed, activate the next step if possible */ if (isset($this->o_steps[($i + 1)])) { $this->o_steps[($i + 1)]->set_enabled(); } } else { /* Disable all following steps, if one step isn't completed right now */ $this->disable_steps_from($i + 1); break; } } if (!$this->selectable_step($this->i_current)) { $this->i_current = $this->i_previous; } if ($this->i_current != $this->i_previous) { $this->o_steps[$this->i_current]->update(); } return TRUE; } function disable_steps_from ($start) { for ($i = $start; $i < $this->i_steps; $i++) { $this->o_steps[$i]->set_enabled(FALSE); $this->o_steps[$i]->set_completed(FALSE); } } /* Create navigation menu */ function get_navigation_html () { $str = '<ul class="menu"><li><a>FusionDirectory Setup</a><ul>'; foreach ($this->o_steps as $key => $step) { $step->update_strings(); $s_short_name = $step->get_short_name(); $s_description = $step->get_description(); $b_active = $step->is_active(); $b_enabled = $step->is_enabled(); $b_completed = $step->is_completed(); if ($b_completed) { $s = '<img src="geticon.php?context=status&amp;icon=task-complete&amp;size=16" alt="'._('Completed').'" class="center optional"/>&nbsp;'; } else { $s = '<img src="images/empty.png" alt=" " class="center optional"/>&nbsp;'; } if ($b_enabled) { if ($b_active) { $str .= '<li class="menuitem menucurrent" title="'.$s_description.'">'; $str .= '<a class="navigation-title">'.$s.$s_short_name.'</a>'; $str .= '<a class="navigation-info">'.$s_description.'</a>'; $str .= '</li>'; } else { $str .= '<li class="menuitem" title="'.$s_description.'">'; $str .= '<a onClick="document.mainform.setup_goto_step.value=\''.$key.'\';document.mainform.submit();" class="navigation-title">'.$s.$s_short_name.'</a>'; $str .= '</li>'; } } else { $str .= '<li class="menuitem disabled" title="'.$s_description.'">'; $str .= '<a class="navigation-title">'.$s.$s_short_name.'</a>'; $str .= '</li>'; }