class_setup.inc 9.51 KB
Newer Older
1
2
3
4
<?php
/*
  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
  Copyright (C) 2003  Cajus Pollmeier
5
  Copyright (C) 2011-2015  FusionDirectory
6
7
8
9
10
11
12
13
14
15
16
17
18

  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
19
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20
21
22
23
*/

require_once("class_setupStep.inc");

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class fake_userinfo extends userinfo
{
  function __construct()
  {
    global $config;
    $this->config = &$config;

    $this->cn   = 'fake_cn';
    $this->dn   = 'fake_dn';
    $this->uid  = 'fake_uid';
    $this->ip   = $_SERVER['REMOTE_ADDR'];

    /* This fake user have all rights */
    $this->ignoreACL = TRUE;

    /* Initialize ACL_CACHE */
    $this->reset_acl_cache();
  }
}
43

44
class setup
45
{
46
47
48
  var $i_steps;               // Number of setup steps
  var $i_current        = 0;  // Current step
  var $i_previous       = 0;  // Previous setup step;
49
  var $i_config         = 4;
50
51
  var $o_steps          = array();
  var $captured_values  = array();
52

53
  function __construct()
54
  {
55
56
57
58
59
60
61
62
63
64
65
    $this->o_steps = array(
      new Step_Welcome(),
      new Step_Language(),
      new Step_Checks(),
      new Step_Ldap(),
      new Step_Config_before_init(),
      new Step_Migrate(),
      new Step_Finish(),
    );

    $this->i_steps = count($this->o_steps);
66

67
    /* Ensure that setup is not reachable if fusiondirectory.conf exist (CONFIG_FILE) */
68
    if (file_exists(CONFIG_DIR."/".CONFIG_FILE)) {
69
      session::destroy();
70
      header("Location: index.php");
71
72
      exit();
    }
73

74
75
    foreach ($this->o_steps as &$step) {
      $step->parent = &$this;
76
    }
77
    unset($step);
78
79
80
81
82
83
84
85
  }

  function execute()
  {
    /* Display phpinfo() dialog when $_GET['info'] is set,
     *  but only do this, if user is allowed to use the setup.
     * If setupStep_Welcome is_completed, we are allowed to view those infos-
     */
86
    if (isset($_GET['info']) && preg_match("/Step_Welcome/i", get_class($this->o_steps[1])) && $this->o_steps[1]->is_completed()) {
87
88
89
90
      phpinfo();
      exit();
    }

91
92
    $smarty = get_smarty();
    $smarty->assign('usePrototype', 'true');
93
    $this->o_steps[$this->i_previous]->set_active(FALSE);
94
95
    $this->o_steps[$this->i_current]->set_active();
    $content = $this->o_steps[$this->i_current]->execute();
96
    return $content;
97
98
99
100
101
102
103
  }


  /* Save posted attributes  */
  function save_object()
  {
    /* Call save_object for current setup step */
104
    $this->o_steps[$this->i_current]->save_object();
105
106
107

    /* Get attributes from setup step */
    $tmp = $this->o_steps[$this->i_current]->get_attributes();
108
    foreach ($tmp as $name => $value) {
109
110
111
112
      $this->captured_values[$name] = $value;
    }

    /* Set parent */
113
    foreach ($this->o_steps as $key => $value) {
114
115
116
117
      $this->o_steps[$key]->parent = $this;
    }

    /* Check if image button requests next page */
118
119
    foreach ($_POST as $name => $value) {
      if (preg_match("/^next_(x|y)/", $name)) {
120
121
        $_POST['next'] = TRUE;
      }
122
      if (preg_match("/^last_(x|y)/", $name)) {
123
124
125
126
        $_POST['last'] = TRUE;
      }
    }

127
128
129
130
131
132
    /* display step error msgs */
    $msgs = $this->o_steps[$this->i_current]->check();
    foreach ($msgs as $msg) {
      msg_dialog::display(_("Setup error"), $msg, ERROR_DIALOG);
    }

133
    /* Check if step was selected */
134
    if (isset($_GET['step']) || isset($_POST['next']) || isset($_POST['last'])) {
135

136
      /* check if current setup step is completed now
137
          and activate the next step if possible */
138
      for ($i = 0; $i < $this->i_steps; $i++) {
139
140
141
        if ($this->o_steps[$i]->is_completed()) {
          if (isset($this->o_steps[($i + 1)])) {
            $this->o_steps[($i + 1)]->set_enabled();
142
          }
143
        } else {
144
          $this->disable_steps_from($i + 1);
145
          break;
146
147
148
        }
      }
    }
149

150
    /* Disable all following steps, if one step isn't compelted right now .*/
151
152
    for ($i = 0; $i < $this->i_steps; $i++) {
      if (!$this->o_steps[$i]->is_completed()) {
153
        $this->disable_steps_from($i + 1);
154
        break;
155
156
      }
    }
157

158
159
    $step = -1;

160
161
    if (isset($_POST['setup_goto_step'])) {
      $step = $_POST['setup_goto_step'];
162
163
    }

164
    if (isset($_GET['step'])) {
165
      $step = $_GET['step'];
166
    } elseif (isset($_POST['next'])) {
167
      $step = $this->i_current + 1;
168
    } elseif (isset($_POST['last'])) {
169
170
      $step = $this->i_current - 1;
    }
171

172
    foreach ($_POST as $name => $value) {
173
      if (preg_match("/^step_[0-9]*$/", $name)) {
174
        $step = preg_replace("/^step_/", "", $name);
175
        break;
176
177
178
      }
    }

179
    if ($this->selectable_step($step)) {
180
181
      $this->i_previous = $this->i_current;
      $this->i_current  = $step;
182
183
184
185
186
187
    }
  }


  function disable_steps_from($start)
  {
188
189
190
    for ($i = $start; $i < $this->i_steps; $i++) {
      $this->o_steps[$i]->set_enabled(FALSE);
      $this->o_steps[$i]->set_completed(FALSE);
191
192
193
194
195
196
197
    }
  }


  /* Create navigation menu */
  function get_navigation_html()
  {
Côme Bernigaud's avatar
Côme Bernigaud committed
198
    $str = '<ul class="menu"><li><a>FusionDirectory Setup</a><ul>';
199
    foreach ($this->o_steps as $key => $step) {
200

201
      $step->update_strings();
202

203
204
205
206
207
      $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();
208

209
      if ($b_completed) {
210
        $s = '<img src="geticon.php?context=status&amp;icon=task-complete&amp;size=16" alt="'._('Completed').'" class="center optional"/>&nbsp;';
211
      } else {
Côme Bernigaud's avatar
Côme Bernigaud committed
212
        $s = '<img src="images/empty.png" alt=" " class="center optional"/>&nbsp;';
213
214
      }

215
216
      if ($b_enabled) {
        if ($b_active) {
217
218
219
          $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>';
Côme Bernigaud's avatar
Côme Bernigaud committed
220
          $str .= '</li>';
221
        } else {
222
          $str .= '<li class="menuitem" title="'.$s_description.'">';
Côme Bernigaud's avatar
Côme Bernigaud committed
223
          $str .= '<a onClick="document.mainform.setup_goto_step.value=\''.$key.'\';document.mainform.submit();"
224
            class="navigation_title">'.$s.$s_short_name.'</a>';
Côme Bernigaud's avatar
Côme Bernigaud committed
225
          $str .= '</li>';
226
        }
227
      } else {
228
229
        $str .= '<li class="menuitem disabled" title="'.$s_description.'">';
        $str .= '<a class="navigation_title">'.$s.$s_short_name.'</a>';
Côme Bernigaud's avatar
Côme Bernigaud committed
230
        $str .= '</li>';
231
232
      }
    }
Côme Bernigaud's avatar
Côme Bernigaud committed
233
    $str .= '</li></ul>';
234
    return $str;
235
236
237
238
239
  }


  function get_bottom_html()
  {
240
241
    /* Skip adding forward/backward button,
     *  if the currently opened step is a sub dialog
242
     */
243
    if ($this->o_steps[$this->i_current]->dialog) {
Côme Bernigaud's avatar
Côme Bernigaud committed
244
      $str = '';
245
    } else {
Côme Bernigaud's avatar
Côme Bernigaud committed
246
      $str = '   <p class="plugbottom">';
247
      if (isset($this->o_steps[$this->i_current - 1]) && $this->o_steps[$this->i_current - 1]->is_enabled()) {
Côme Bernigaud's avatar
Côme Bernigaud committed
248
        $str .= '<input type="submit" name="last" value="'.msgPool::backButton().'"/>';
249
      } else {
Côme Bernigaud's avatar
Côme Bernigaud committed
250
        $str .= '<input type="button" name="last" value="'.msgPool::backButton().'" disabled="disabled"/>';
251
      }
Côme Bernigaud's avatar
Côme Bernigaud committed
252
253
254
      $str .= '&nbsp;';
      $str .= '<input type="submit" name="next" value="'._('Next').'"/>';
      $str .= '</p>';
255
    }
256
    return $str;
257
258
  }

259
260
261
  /* Create header entry */
  function get_header_text()
  {
262
    return $this->o_steps[$this->i_current]->get_title();
263
  }
264

265
  /* Create header entry */
266
  function get_header_image()
267
  {
268
    return $this->o_steps[$this->i_current]->header_image;
269
270
271
272
273
274
  }


  /* Check if the given step id is valid and selectable */
  function selectable_step($id)
  {
275
276
    if (isset($this->o_steps[$id]) && $this->o_steps[$id]->is_enabled()) {
      return TRUE;
277
    }
278
    return FALSE;
279
280
281
282
  }

  function step_name_to_id($name)
  {
283
284
285
    foreach ($this->o_steps as $id => $class) {
      if (get_class($class) == $name) {
        return $id;
286
287
      }
    }
288
    return 0;
289
  }
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305

  /* 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;
306
    $cv['debugLevel']       = 0;
307
308
309
310
311
312
313
    $smarty->assign("cv",                       xmlentities($cv));
    $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();
314
    $this->reBuildConfigStep();
315
  }
316
317
318
319
320

  function getDebugLevel ()
  {
    return $this->o_steps[$this->i_config]->attributesAccess['fdDebugLevel']->computeLdapValue();
  }
321
322
323
324
325
326
327
328

  function reBuildConfigStep ($completed = NULL)
  {
    $this->o_steps[$this->i_config] = new Step_Config($this->captured_values);
    if ($completed !== NULL) {
      $this->o_steps[$this->i_config]->is_completed = $completed;
    }
  }
329
330
}
?>