class_setupStep_Checks.inc 10.3 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-2016  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
class Step_Checks extends setupStep
23
{
24
  var $header_image = 'geticon.php?context=categories&icon=checks&size=48';
25

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  static function getAttributesInfo()
  {
    return array(
      'modules' => array(
        'name'      => _('PHP module and extension checks'),
        'template'  => get_template_path("setup_checks.tpl", TRUE, dirname(__FILE__)),
        'attrs'     => array(
          new FakeAttribute('basic_checks')
        )
      ),
      'setup' => array(
        'name'      => _('PHP setup configuration (<a href="?info" target="_blank">show information)</a>)'),
        'template'  => get_template_path("setup_checks.tpl", TRUE, dirname(__FILE__)),
        'attrs'     => array(
          new FakeAttribute('config_checks')
        )
      )
    );
  }

46
47
  function update_strings()
  {
48
49
50
    $this->s_short_name   = _('Installation check');
    $this->s_title        = _('Installation check');
    $this->s_description  = _('Basic checks for PHP compatibility and extensions');
51
  }
52
53

  /* Execute and display template */
54
55
56
  function execute()
  {
    $this->run_checks();
57
    return parent::execute();
58
59
  }

60
  /* Execute all checks */
61
62
  function run_checks()
  {
63
64
    $basic_checks   = array();
    $config_checks  = array();
65
66

    /* PHP version check */
67
    $N = _("Checking PHP version");
68
69
70
71
    $D = sprintf(_("PHP must be of version %s or above."), "5.2.0");
    $S = _("Please upgrade to a supported version.");
    $R = $this->check_php_version();
    $M = TRUE;
72
    $basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
73

74
    /* Check for LDAP extension */
75
    $N = msgPool::checkingFor("LDAP");
76
    $D = _("FusionDirectory requires this module to talk with your LDAP server.");
77
78
79
    $S = msgPool::installPhpModule("LDAP");
    $R = is_callable("ldap_bind");
    $M = TRUE;
80
    $basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
81
82
83

    /* Check for gettext support */
    $N = msgPool::checkingFor("gettext");
84
    $D = _("FusionDirectory requires this module for an internationalized interface.");
85
86
87
    $S = msgPool::installPhpModule("gettext");
    $R = is_callable("bindtextdomain");
    $M = TRUE;
88
    $basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
89

90
91
92
93
94
    /* Check for curl support */
    $N = msgPool::checkingFor('curl');
    $D = _('FusionDirectory requires this module to communicate with different types of servers and protocols.');
    $S = msgPool::installPhpModule('curl');
    $R = is_callable('curl_init');
Benoit Mortier's avatar
Benoit Mortier committed
95
    $M = TRUE;
96
    $basic_checks[] = array('NAME' => $N , 'DESC' => $D , 'RESULT' => $R , 'SOLUTION' => $S , 'MUST' => $M );
Benoit Mortier's avatar
Benoit Mortier committed
97

98
    /* Check for iconv */
99
    $N = msgPool::checkingFor("iconv");
100
    $D = _("FusionDirectory requires this module for the samba integration.");
101
102
103
    $S = msgPool::installPhpModule("iconv");
    $R = is_callable("iconv");
    $M = TRUE;
104
    $basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
105
106
107

    /* Check for installed mhash module */
    $N = msgPool::checkingFor("hash method");
108
    $D = _("FusionDirectory requires either 'mhash' or the 'sha1' module to make use of SSHA encryption.");
109
110
111
    $S = msgPool::installPhpModule("mhash/sha1");
    $R = is_callable('mhash') || is_callable('sha1');
    $M = FALSE;
112
    $basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
113

114
    /* Check if imap module is available */
115
    $N = msgPool::checkingFor("IMAP");
116
    $D = _("FusionDirectory requires this module to talk to an IMAP server.");
117
118
119
    $S = msgPool::installPhpModule("IMAP");
    $R = is_callable("imap_open");
    $M = TRUE;
120
    $basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
121

122
    /* Check if mbstring module is available */
123
    $N = msgPool::checkingFor(_("mbstring"));
124
    $D = _("FusionDirectory requires this module to handle unicode strings.");
125
126
127
    $S = msgPool::installPhpModule("mbstring");
    $R = is_callable("mb_strlen");
    $M = TRUE;
128
    $basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
129

130
131
132
    $N = msgPool::checkingFor(_('imagick'));
    $D = _('FusionDirectory requires this extension to handle images.');
    $S = msgPool::installPhpModule('imagick');
133
    $R = class_exists('Imagick', FALSE);
134
    $M = TRUE;
135
    $basic_checks[] = array('NAME' => $N , 'DESC' => $D , 'RESULT' => $R , 'SOLUTION' => $S , 'MUST' => $M );
136
137

    $N = msgPool::checkingFor(_("compression module"));
138
    $D = _("FusionDirectory requires this extension to handle snapshots.");
139
140
141
    $S = msgPool::installPhpModule("compile with --with-zlib");
    $R = is_callable("gzcompress");
    $M = FALSE;
142
    $basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
143
144
145
146
147
148
149
150
151

    /* PHP Configuration checks */

    /* Register_globals off */
    $N = "register_globals = <b>off</b>";
    $D = _("register_globals is a PHP mechanism to register all global variables to be accessible from scripts without changing the scope. This may be a security risk.");
    $S = _("Search for 'register_globals' in your php.ini and switch it to 'Off'.");
    $R = ini_get("register_globals") == 0;
    $M = FALSE;
152
    $config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
153
154
155
156
157
158
159
160

    /* session lifetime set to >=86400 seconds ? */
    $N = "session.gc_maxlifetime &gt;= <b>86400</b>";
    $D = _("PHP uses this value for the garbage collector to delete old sessions.")." ".
         _("Setting this value to one day will prevent loosing session and cookies before they really timeout.");
    $S = _("Search for 'session.gc_maxlifetime' in your php.ini and set it to 86400 or higher.");
    $R = ini_get("session.gc_maxlifetime") >= 86400;
    $M = FALSE;
161
    $config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
162
163
164
165

    /* Session auto start must be turned off */
    $session_auto_start = ini_get('session.auto_start');
    $N = "session.auto_start = <b>"._("Off")."</b>";
166
    $D = _("In Order to use FusionDirectory without any trouble, the session.auto_start option in your php.ini should be set to 'Off'.");
167
    $S = _("Search for 'session.auto_start' in your php.ini and set it to 'Off'.");
168
    $R = !$session_auto_start;
169
    $M = TRUE;
170
    $config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
171

172
173
174
175
176
    /* Check if memory limit is set to 128 or > */
    $N = "memory_limit &gt;= <b>128</b>";
    $D = _("FusionDirectory needs at least 128MB of memory. Setting it below this limit may cause errors that are not reproducable! Increase it for larger setups.");
    $S = _("Search for 'memory_limit' in your php.ini and set it to '128M' or higher.");
    $R = ini_get('memory_limit') >= 128;
177
    $M = TRUE;
178
    $config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
179
180
181
182

    /* Implicit Flush disabled can increase performance */
    $N = "implicit_flush = <b>"._("Off")."</b>";
    $D = _("This option influences the PHP output handling. Turn this Option off, to increase performance.");
183
    $S = _("Search for 'implicit_flush' in your php.ini and set it to 'Off'.");
184
185
    $R = !ini_get('implicit_flush');
    $M = FALSE;
186
    $config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
187
188
189
190
191

    /* Check if execution time is set to 30 */
    $N = "max_execution_time &gt;= <b>30</b>";
    $D = _("The Execution time should be at least 30 seconds.");
    $S = _("Search for 'max_execution_time' in your php.ini and set it to '30' or higher.");
192
    $R = ini_get("max_execution_time") >= 30;
193
    $M = TRUE;
194
    $config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
195
196
197
198
199
200
201

    /* Expose php should be set to off */
    $N = "expose_php = <b>"._("Off")."</b>";
    $D = _("Increase the server security by setting expose_php to 'off'. PHP won't send any information about the server you are running in this case.");
    $S = _("Search for 'expose_php' in your php.ini and set if to 'Off'.");
    $R = !ini_get("expose_php");
    $M = FALSE;
202
    $config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
203
204
205

    /* Emulating old stuff? */
    $N = "zend.ze1_compatibility_mode = <b>"._("Off")."</b>";
206
207
208
    $D = _("Increase your server performance by setting magic_quotes_gpc to 'off'.");
    $S = _("Search for 'zend.ze1_compatibility_mode' in your php.ini and set it to 'Off'.");
    $R = !ini_get('zend.ze1_compatibility_mode');
209
    $M = FALSE;
210
    $config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
211

212
213
    $this->basic_checks   = $basic_checks;
    $this->config_checks  = $config_checks;
214
  }
215

216
217
  function save_object()
  {
218
    parent::save_object();
219
     /* If everything is fine, set this step to completed
220
221
     *  and allow switching to next setup step */
    $failed = FALSE;
222
    foreach (array('basic_checks','config_checks') as $type) {
223
224
225
      foreach ($this->$type as $obj) {
        if ($obj['MUST'] && !$obj['RESULT']) {
          $failed = TRUE;
226
227
228
229
230
231
232
          break;
        }
      }
    }
    $this->is_completed = !$failed;
  }

233
  /* Check if current PHP version is compatible
234
      with the current version of FusionDirectory */
235
236
  function check_php_version()
  {
237
    return version_compare(phpversion(), '5.2.0', '>=');
238
239
240
241
  }
}

?>