1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class Step_Checks extends setup_step
24 {
25 var $basic_checks = array();
26 var $config_checks= array();
27 var $is_writeable = array();
28 var $header_image = "images/setup/system.png";
30 var $b_displayCheckbutton = TRUE;
32 function Step_Checks()
33 {
34 $this->update_strings();
35 }
38 function update_strings()
39 {
40 $this->s_title = _("Installation check");
41 $this->s_title_long = _("Installation check");
42 $this->s_info = _("Basic checks for PHP compatibility and extensions");
43 }
46 /* Execute and display template */
47 function execute()
48 {
49 $this->run_checks();
50 $smarty = get_smarty();
51 $smarty->assign("basic" ,$this->basic_checks);
52 $smarty->assign("config" ,$this->config_checks);
53 $smarty->assign("is_writeable",$this->is_writeable);
54 return($smarty->fetch(get_template_path("setup_checks.tpl",TRUE,dirname(__FILE__))));
55 }
58 /* Execute all checks */
59 function run_checks()
60 {
61 $this->basic_checks = array();
62 $this->config_checks = array();
63 $this->is_writeable = array();
65 /* PHP version check */
66 $N = _("Checking PHP version");
67 $D = sprintf(_("PHP must be of version %s or above."), "5.2.0");
68 $S = _("Please upgrade to a supported version.");
69 $R = $this->check_php_version();
70 $M = TRUE;
71 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
73 /* Checking imap extension */
74 $N = msgPool::checkingFor("LDAP");
75 $D = _("GOsa requires this module to talk with your LDAP server.");
76 $S = msgPool::installPhpModule("LDAP");
77 $R = is_callable("ldap_bind");
78 $M = TRUE;
79 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
81 /* Check for gettext support */
82 $N = msgPool::checkingFor("gettext");
83 $D = _("GOsa requires this module for an internationalized interface.");
84 $S = msgPool::installPhpModule("gettext");
85 $R = is_callable("bindtextdomain");
86 $M = TRUE;
87 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
89 /* Check for php5-curl support */
90 $N = msgPool::checkingFor("curl");
91 $D = _("GOsa requires this module to communicate with different types of servers and protocols.");
92 $S = msgPool::installPhpModule("php5-curl");
93 $R = is_callable("curl_init");
94 $M = TRUE;
95 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
97 /* Checing for iconv */
98 $N = msgPool::checkingFor("inconv");
99 $D = _("GOsa requires this module for the samba integration.");
100 $S = msgPool::installPhpModule("iconv");
101 $R = is_callable("iconv");
102 $M = TRUE;
103 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
105 /* Check for installed mhash module */
106 $N = msgPool::checkingFor("hash method");
107 $D = _("GOsa requires either 'mhash' or the 'sha1' module to make use of SSHA encryption.");
108 $S = msgPool::installPhpModule("mhash/sha1");
109 $R = is_callable('mhash') || is_callable('sha1');
110 $M = FALSE;
111 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
113 /* Is imap module available */
114 $N = msgPool::checkingFor("IMAP");
115 $D = _("GOsa requires this module to talk to an IMAP server.");
116 $S = msgPool::installPhpModule("IMAP");
117 $R = is_callable("imap_open");
118 $M = TRUE;
119 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
121 /* Is imap module available */
122 $N = msgPool::checkingFor(_("mbstring"));
123 $D = _("GOsa requires this module to handle Unicode strings.");
124 $S = msgPool::installPhpModule("mbstring");
125 $R = is_callable("mb_strlen");
126 $M = TRUE;
127 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
129 /* Is calendar module available/compiled/installed */
130 $N = msgPool::checkingFor(_("Calendar"));
131 $D = _("GOsa requires this module to calculate dates.");
132 $S = msgPool::installPhpModule("calendar");
133 $R = is_callable("cal_days_in_month");
134 $M = TRUE;
135 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
137 /* Mysql module loaded ? */
138 $N = msgPool::checkingFor(_("MySQL"));
139 $D = _("GOsa requires this module to communicate with several supported databases.");
140 $S = msgPool::installPhpModule("MySQL");
141 $R = is_callable("mysql_query");
142 $M = TRUE;
143 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
145 /* Checking generate LM/NT password hashes */
146 #TODO: either this, or gosa-si will do the hash generation
147 $query= "mkntpwd 2>&1";
148 $output= shell_exec ($query);
149 $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
150 if (!$have_mkntpwd){
151 $query= 'LC_ALL=C LANG=C perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen $ARGV[0]), $/;" >/dev/null';
152 system ($query, $ret);
153 $have_mkntpwd |= ($ret == 0);
154 }
156 $N = msgPool::checkingFor(_("samba hash generator"));
157 $D = _("GOsa requires this command to synchronize POSIX and samba passwords.");
158 $S = _("Deploy a gosa-si installation or install the Perl Crypt::SmbHash modules.");
159 $R = $have_mkntpwd;
160 $M = TRUE;
161 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
163 /* Read data written by convert */
164 $output= "";
165 $sh= popen("convert", 'r');
166 while (!feof($sh)){
167 $output.= fread($sh, 4096);
168 }
169 pclose($sh);
171 $N = msgPool::checkingFor(_("imagick"));
172 $D = _("GOsa requires this extension to handle images.");
173 $S = msgPool::installPhpModule("php5-imagick");
175 $IMGVER = phpversion('imagick');
177 if ($IMGVER > 1.0) {
178 $R = method_exists('imagick','getImageBlob');
179 }
180 else {
181 $R = is_callable("imagick_blob2image") || !empty($output);
182 }
184 $M = TRUE;
185 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
187 $N = msgPool::checkingFor(_("compression module"));
188 $D = _("GOsa requires this extension to handle snapshots.");
189 $S = msgPool::installPhpModule("compile with --with-zlib");
190 $R = is_callable("gzcompress");
191 $M = FALSE;
192 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
195 /* PHP Configuration checks */
197 /* Register_globals off */
198 $N = "register_globals = <b>off</b>";
199 $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.");
200 $S = _("Search for 'register_globals' in your php.ini and switch it to 'Off'.");
201 $R = ini_get("register_globals") == 0;
202 $M = FALSE;
203 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
206 /* session lifetime set to >=86400 seconds ? */
207 $N = "session.gc_maxlifetime >= <b>86400</b>";
208 $D = _("PHP uses this value for the garbage collector to delete old sessions.")." ".
209 _("Setting this value to one day will prevent loosing session and cookies before they really timeout.");
210 $S = _("Search for 'session.gc_maxlifetime' in your php.ini and set it to 86400 or higher.");
211 $R = ini_get("session.gc_maxlifetime") >= 86400;
212 $M = FALSE;
213 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
215 /* Session auto start must be turned off */
216 $session_auto_start = ini_get('session.auto_start');
217 $N = "session.auto_start = <b>"._("Off")."</b>";
218 $D = _("In Order to use GOsa without any trouble, the session.auto_register option in your php.ini should be set to 'Off'.");
219 $S = _("Search for 'session.auto_start' in your php.ini and set it to 'Off'.");
220 $R = !$session_auto_start['local_value'];
221 $M = TRUE;
222 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
224 /* Check if memory limit is set to 32 or > */
225 $N = "memory_limit >= <b>32</b>";
226 $D = _("GOsa needs at least 32MB of memory. Setting it below this limit may cause errors that are not reproducible! Increase it for larger setups.");
227 $S = _("Search for 'memory_limit' in your php.ini and set it to '32M' or higher.");
228 $R = ini_get('memory_limit') >= 32 ;
229 $M = TRUE;
230 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
232 /* Implicit Flush disabled can increase performance */
233 $N = "implicit_flush = <b>"._("Off")."</b>";
234 $D = _("This option influences the PHP output handling. Turn this Option off, to increase performance.");
235 $S = _("Search for 'implicit_flush' in your php.ini and set it to 'Off'.");
236 $R = !ini_get('implicit_flush');
237 $M = FALSE;
238 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
240 /* Check if execution time is set to 30 */
241 $N = "max_execution_time >= <b>30</b>";
242 $D = _("The Execution time should be at least 30 seconds.");
243 $S = _("Search for 'max_execution_time' in your php.ini and set it to '30' or higher.");
244 $R = ini_get("max_execution_time") >= 30 ;
245 $M = TRUE;
246 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
248 /* Expose php should be set to off */
249 $N = "expose_php = <b>"._("Off")."</b>";
250 $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.");
251 $S = _("Search for 'expose_php' in your php.ini and set if to 'Off'.");
252 $R = !ini_get("expose_php");
253 $M = FALSE;
254 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
256 /* Automatic quoting must be turned on */
257 $N = "magic_quotes_gpc = <b>"._("On")."</b>";
258 $D = _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case.");
259 $S = _("Search for 'magic_quotes_gpc' in your php.ini and set it to 'On'.");
260 $R = ini_get('magic_quotes_gpc');
261 $M = TRUE;
262 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
264 /* Emulating old stuff? */
265 $N = "zend.ze1_compatibility_mode = <b>"._("Off")."</b>";
266 $D = _("Increase your server performance by setting magic_quotes_gpc to 'off'.");
267 $S = _("Search for 'zend.ze1_compatibility_mode' in your php.ini and set it to 'Off'.");
268 $R = !ini_get('zend.ze1_compatibility_mode');
269 $M = FALSE;
270 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
273 /* Configuration file
274 */
276 /* Check if we can create a config file.*/
277 $N = _("Configuration writable");
278 $D = _("The configuration file can't be written");
279 $S = sprintf(_("GOsa reads its configuration from a file located in (%s/%s). The setup can write the configuration directly if it is writable."),CONFIG_DIR,CONFIG_FILE);
280 $R = ( file_exists(CONFIG_DIR."/".CONFIG_FILE) && is_writeable(CONFIG_DIR."/".CONFIG_FILE)) // is there a config file ?
281 || (!file_exists(CONFIG_DIR."/".CONFIG_FILE) && is_writeable(CONFIG_DIR)); // There is non, but can we create a file there ?
282 $M = FALSE;
283 $this->is_writeable[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
285 }
288 function save_object()
289 {
290 /* If everything is fine, set this step to completed
291 * and allow switching to next setup step
292 */
293 $failed = false;
294 foreach(array("basic_checks","config_checks","is_writeable") as $type){
295 foreach($this->$type as $obj){
297 if($obj['MUST'] && !$obj['RESULT']){
298 $failed = true;
299 break;
300 }
301 }
302 }
303 $this->is_completed = !$failed;
304 }
307 /* Check if current PHP version is compatible
308 with the current version of GOsa */
309 function check_php_version()
310 {
311 return(version_compare(phpversion(),"5.2.0",">="));
312 }
313 }
315 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
316 ?>