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 /* Checing for iconv */
90 $N = msgPool::checkingFor("inconv");
91 $D = _("GOsa requires this module for the samba integration.");
92 $S = msgPool::installPhpModule("iconv");
93 $R = is_callable("iconv");
94 $M = TRUE;
95 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
97 /* Check for installed mhash module */
98 $N = msgPool::checkingFor("hash method");
99 $D = _("GOsa requires either 'mhash' or the 'sha1' module to make use of SSHA encryption.");
100 $S = msgPool::installPhpModule("mhash/sha1");
101 $R = is_callable('mhash') || is_callable('sha1');
102 $M = FALSE;
103 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
105 /* Is imap module available */
106 $N = msgPool::checkingFor("IMAP");
107 $D = _("GOsa requires this module to talk to an IMAP server.");
108 $S = msgPool::installPhpModule("IMAP");
109 $R = is_callable("imap_open");
110 $M = TRUE;
111 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
113 /* Is imap module available */
114 $N = msgPool::checkingFor(_("mbstring"));
115 $D = _("GOsa requires this module to handle Unicode strings.");
116 $S = msgPool::installPhpModule("mbstring");
117 $R = is_callable("mb_strlen");
118 $M = TRUE;
119 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
121 /* Is calendar module available/compiled/installed */
122 $N = msgPool::checkingFor(_("Calendar"));
123 $D = _("GOsa requires this module to calculate dates.");
124 $S = msgPool::installPhpModule("calendar");
125 $R = is_callable("cal_days_in_month");
126 $M = TRUE;
127 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
129 /* Mysql module loaded ? */
130 $N = msgPool::checkingFor(_("MySQL"));
131 $D = _("GOsa requires this module to communicate with several supported databases.");
132 $S = msgPool::installPhpModule("MySQL");
133 $R = is_callable("mysql_query");
134 $M = TRUE;
135 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
137 /* Checking generate LM/NT password hashes */
138 #TODO: either this, or gosa-si will do the hash generation
139 $query= "mkntpwd 2>&1";
140 $output= shell_exec ($query);
141 $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
142 if (!$have_mkntpwd){
143 $query= 'LC_ALL=C LANG=C perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen $ARGV[0]), $/;" >/dev/null';
144 system ($query, $ret);
145 $have_mkntpwd |= ($ret == 0);
146 }
148 $N = msgPool::checkingFor(_("samba hash generator"));
149 $D = _("GOsa requires this command to synchronize POSIX and samba passwords.");
150 $S = _("Deploy a gosa-si installation or install the Perl Crypt::SmbHash modules.");
151 $R = $have_mkntpwd;
152 $M = TRUE;
153 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
155 /* Read data written by convert */
156 $output= "";
157 $sh= popen("convert", 'r');
158 while (!feof($sh)){
159 $output.= fread($sh, 4096);
160 }
161 pclose($sh);
163 $N = msgPool::checkingFor(_("imagick"));
164 $D = _("GOsa requires this extension to handle images.");
165 $S = msgPool::installPhpModule("php5-imagick");
167 $IMGVER = phpversion('imagick');
169 if ($IMGVER > 1.0) {
170 $R = method_exists('imagick','getImageBlob');
171 }
172 else {
173 $R = is_callable("imagick_blob2image") || !empty($output);
174 }
176 $M = TRUE;
177 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
179 $N = msgPool::checkingFor(_("compression module"));
180 $D = _("GOsa requires this extension to handle snapshots.");
181 $S = msgPool::installPhpModule("php5-zip / php5-gzip");
182 $R = is_callable("gzcompress");
183 $M = FALSE;
184 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
187 /* PHP Configuration checks */
189 /* Register_globals off */
190 $N = "register_globals = <b>off</b>";
191 $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.");
192 $S = _("Search for 'register_globals' in your php.ini and switch it to 'Off'.");
193 $R = ini_get("register_globals") == 0;
194 $M = FALSE;
195 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
198 /* session lifetime set to >=86400 seconds ? */
199 $N = "session.gc_maxlifetime >= <b>86400</b>";
200 $D = _("PHP uses this value for the garbage collector to delete old sessions.")." ".
201 _("Setting this value to one day will prevent loosing session and cookies before they really timeout.");
202 $S = _("Search for 'session.gc_maxlifetime' in your php.ini and set it to 86400 or higher.");
203 $R = ini_get("session.gc_maxlifetime") >= 86400;
204 $M = FALSE;
205 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
207 /* Session auto start must be turned off */
208 $session_auto_start = ini_get('session.auto_start');
209 $N = "session.auto_start = <b>"._("Off")."</b>";
210 $D = _("In Order to use GOsa without any trouble, the session.auto_register option in your php.ini should be set to 'Off'.");
211 $S = _("Search for 'session.auto_start' in your php.ini and set it to 'Off'.");
212 $R = !$session_auto_start['local_value'];
213 $M = TRUE;
214 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
216 /* Check if memory limit is set to 32 or > */
217 $N = "memory_limit >= <b>32</b>";
218 $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.");
219 $S = _("Search for 'memory_limit' in your php.ini and set it to '32M' or higher.");
220 $R = ini_get('memory_limit') >= 32 ;
221 $M = TRUE;
222 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
224 /* Implicit Flush disabled can increase performance */
225 $N = "implicit_flush = <b>"._("Off")."</b>";
226 $D = _("This option influences the PHP output handling. Turn this Option off, to increase performance.");
227 $S = _("Search for 'implicit_flush' in your php.ini and set it to 'Off'.");
228 $R = !ini_get('implicit_flush');
229 $M = FALSE;
230 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
232 /* Check if execution time is set to 30 */
233 $N = "max_execution_time >= <b>30</b>";
234 $D = _("The Execution time should be at least 30 seconds.");
235 $S = _("Search for 'max_execution_time' in your php.ini and set it to '30' or higher.");
236 $R = ini_get("max_execution_time") >= 30 ;
237 $M = TRUE;
238 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
240 /* Expose php should be set to off */
241 $N = "expose_php = <b>"._("Off")."</b>";
242 $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.");
243 $S = _("Search for 'expose_php' in your php.ini and set if to 'Off'.");
244 $R = !ini_get("expose_php");
245 $M = FALSE;
246 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
248 /* Automatic quoting must be turned on */
249 $N = "magic_quotes_gpc = <b>"._("On")."</b>";
250 $D = _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case.");
251 $S = _("Search for 'magic_quotes_gpc' in your php.ini and set it to 'On'.");
252 $R = ini_get('magic_quotes_gpc');
253 $M = TRUE;
254 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
256 /* Emulating old stuff? */
257 $N = "zend.ze1_compatibility_mode = <b>"._("Off")."</b>";
258 $D = _("Increase your server performance by setting magic_quotes_gpc to 'off'.");
259 $S = _("Search for 'zend.ze1_compatibility_mode' in your php.ini and set it to 'Off'.");
260 $R = !ini_get('zend.ze1_compatibility_mode');
261 $M = FALSE;
262 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
265 /* Configuration file
266 */
268 /* Check if we can create a config file.*/
269 $N = _("Configuration writable");
270 $D = _("The configuration file can't be written");
271 $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);
272 $R = ( file_exists(CONFIG_DIR."/".CONFIG_FILE) && is_writeable(CONFIG_DIR."/".CONFIG_FILE)) // is there a config file ?
273 || (!file_exists(CONFIG_DIR."/".CONFIG_FILE) && is_writeable(CONFIG_DIR)); // There is non, but can we create a file there ?
274 $M = FALSE;
275 $this->is_writeable[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
277 }
280 function save_object()
281 {
282 /* If everything is fine, set this step to completed
283 * and allow switching to next setup step
284 */
285 $failed = false;
286 foreach(array("basic_checks","config_checks","is_writeable") as $type){
287 foreach($this->$type as $obj){
289 if($obj['MUST'] && !$obj['RESULT']){
290 $failed = true;
291 break;
292 }
293 }
294 }
295 $this->is_completed = !$failed;
296 }
299 /* Check if current PHP version is compatible
300 with the current version of GOsa */
301 function check_php_version()
302 {
303 return(version_compare(phpversion(),"5.2.0",">="));
304 }
305 }
307 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
308 ?>