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 function Step_Checks()
31 {
32 $this->update_strings();
33 }
36 function update_strings()
37 {
38 $this->s_title = _("Installation check");
39 $this->s_title_long = _("Installation check");
40 $this->s_info = _("Basic checks for PHP compatibility and extensions");
41 }
44 /* Execute and display template */
45 function execute()
46 {
47 $this->run_checks();
48 $smarty = get_smarty();
49 $smarty->assign("basic" ,$this->basic_checks);
50 $smarty->assign("config" ,$this->config_checks);
51 $smarty->assign("is_writeable",$this->is_writeable);
52 return($smarty->fetch(get_template_path("setup_checks.tpl",TRUE,dirname(__FILE__))));
53 }
56 /* Execute all checks */
57 function run_checks()
58 {
59 $this->basic_checks = array();
60 $this->config_checks = array();
61 $this->is_writeable = array();
63 /* PHP version check */
64 $N = _("Checking PHP version");
65 $D = sprintf(_("PHP must be of version %s or above."), "5.2.0");
66 $S = _("Please upgrade to a supported version.");
67 $R = $this->check_php_version();
68 $M = TRUE;
69 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
71 /* Checking imap extension */
72 $N = msgPool::checkingFor("LDAP");
73 $D = _("GOsa requires this module to talk with your LDAP server.");
74 $S = msgPool::installPhpModule("LDAP");
75 $R = is_callable("ldap_bind");
76 $M = TRUE;
77 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
79 /* Check for gettext support */
80 $N = msgPool::checkingFor("gettext");
81 $D = _("GOsa requires this module for an internationalized interface.");
82 $S = msgPool::installPhpModule("gettext");
83 $R = is_callable("bindtextdomain");
84 $M = TRUE;
85 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
87 /* Checing for iconv */
88 $N = msgPool::checkingFor("inconv");
89 $D = _("GOsa requires this module for the samba integration.");
90 $S = msgPool::installPhpModule("iconv");
91 $R = is_callable("iconv");
92 $M = TRUE;
93 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
95 /* Check for installed mhash module */
96 $N = msgPool::checkingFor("mhash");
97 $D = _("GOsa requires this module to make use of SSHA encryption.");
98 $S = msgPool::installPhpModule("mhash");
99 $R = is_callable("mhash");
100 $M = FALSE;
101 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
103 /* Is imap module available */
104 $N = msgPool::checkingFor("IMAP");
105 $D = _("GOsa requires this module to talk to an IMAP server.");
106 $S = msgPool::installPhpModule("IMAP");
107 $R = is_callable("imap_open");
108 $M = TRUE;
109 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
111 /* Is imap module available */
112 $N = msgPool::checkingFor(_("mbstring"));
113 $D = _("GOsa requires this module to handle unicode strings.");
114 $S = msgPool::installPhpModule("mbstring");
115 $R = is_callable("mb_strlen");
116 $M = TRUE;
117 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
119 /* Mysql module loaded ? */
120 $N = msgPool::checkingFor(_("MySQL"));
121 $D = _("GOsa requires this module to communicate with several supported databases.");
122 $S = msgPool::installPhpModule("MySQL");
123 $R = is_callable("mysql_query");
124 $M = TRUE;
125 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
127 /* Checking generate LM/NT password hashes */
128 #TODO: either this, or gosa-si will do the hash generation
129 $query= "mkntpwd 2>&1";
130 $output= shell_exec ($query);
131 $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
132 if (!$have_mkntpwd){
133 $query= 'LC_ALL=C LANG=C perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen $ARGV[0]), $/;" >/dev/null';
134 system ($query, $ret);
135 $have_mkntpwd |= ($ret == 0);
136 }
138 $N = msgPool::checkingFor(_("samba hash generator"));
139 $D = _("GOsa requires this command to synchronize POSIX and samba passwords.");
140 $S = _("Deploy a gosa-si installation or install the perl Crypt::SmbHash modules.");
141 $R = $have_mkntpwd;
142 $M = TRUE;
143 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
145 /* Read data written by convert */
146 $output= "";
147 $sh= popen("convert", 'r');
148 while (!feof($sh)){
149 $output.= fread($sh, 4096);
150 }
151 pclose($sh);
153 $N = msgPool::checkingFor(_("imagick"));
154 $D = _("GOsa requires this extension to handle images.");
155 $S = msgPool::installPhpModule("php5-imagick");
157 $IMGVER = phpversion('imagick');
159 if ($IMGVER > 1.0) {
160 $R = method_exists('imagick','getImageBlob');
161 }
162 else {
163 $R = is_callable("imagick_blob2image") || !empty($output);
164 }
166 $M = TRUE;
167 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
169 $N = msgPool::checkingFor(_("compression module"));
170 $D = _("GOsa requires this extension to handle snapshots.");
171 $S = msgPool::installPhpModule("php5-zip / php5-gzip");
172 $R = is_callable("gzcompress");
173 $M = FALSE;
174 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
177 /* PHP Configuration checks */
179 /* Register_globals off */
180 $N = "register_globals = <b>off</b>";
181 $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.");
182 $S = _("Search for 'register_globals' in your php.ini and switch it to 'Off'.");
183 $R = ini_get("register_globals") == 0;
184 $M = FALSE;
185 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
188 /* session lifetime set to >=86400 seconds ? */
189 $N = "session.gc_maxlifetime >= <b>86400</b>";
190 $D = _("PHP uses this value for the garbage collector to delete old sessions.")." ".
191 _("Setting this value to one day will prevent loosing session and cookies before they really timeout.");
192 $S = _("Search for 'session.gc_maxlifetime' in your php.ini and set it to 86400 or higher.");
193 $R = ini_get("session.gc_maxlifetime") >= 86400;
194 $M = FALSE;
195 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
197 /* Session auto start must be turned off */
198 $session_auto_start = ini_get('session.auto_start');
199 $N = "session.auto_start = <b>"._("Off")."</b>";
200 $D = _("In Order to use GOsa without any trouble, the session.auto_register option in your php.ini should be set to 'Off'.");
201 $S = _("Search for 'session.auto_start' in your php.ini and set it to 'Off'.");
202 $R = !$session_auto_start['local_value'];
203 $M = TRUE;
204 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
206 /* Check if memory limit is set to 32 or > */
207 $N = "memory_limit >= <b>32</b>";
208 $D = _("GOsa needs at least 32MB of memory. Setting it below this limit may cause errors that are not reproducable! Increase it for larger setups.");
209 $S = _("Search for 'memory_limit' in your php.ini and set it to '32M' or higher.");
210 $R = ini_get('memory_limit') >= 32 ;
211 $M = TRUE;
212 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
214 /* Implicit Flush disabled can increase performance */
215 $N = "implicit_flush = <b>"._("Off")."</b>";
216 $D = _("This option influences the PHP output handling. Turn this Option off, to increase performance.");
217 $S = _("Search for 'implicit_flush' in your php.ini and set it to 'Off'.");
218 $R = !ini_get('implicit_flush');
219 $M = FALSE;
220 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
222 /* Check if execution time is set to 30 */
223 $N = "max_execution_time >= <b>30</b>";
224 $D = _("The Execution time should be at least 30 seconds.");
225 $S = _("Search for 'max_execution_time' in your php.ini and set it to '30' or higher.");
226 $R = ini_get("max_execution_time") >= 30 ;
227 $M = TRUE;
228 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
230 /* Expose php should be set to off */
231 $N = "expose_php = <b>"._("Off")."</b>";
232 $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.");
233 $S = _("Search for 'expose_php' in your php.ini and set if to 'Off'.");
234 $R = !ini_get("expose_php");
235 $M = FALSE;
236 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
238 /* Automatic quoting must be turned on */
239 $N = "magic_quotes_gpc = <b>"._("On")."</b>";
240 $D = _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case.");
241 $S = _("Search for 'magic_quotes_gpc' in your php.ini and set it to 'On'.");
242 $R = ini_get('magic_quotes_gpc');
243 $M = TRUE;
244 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
246 /* Emulating old stuff? */
247 $N = "zend.ze1_compatibility_mode = <b>"._("Off")."</b>";
248 $D = _("Increase your server performance by setting magic_quotes_gpc to 'off'.");
249 $S = _("Search for 'zend.ze1_compatibility_mode' in your php.ini and set it to 'Off'.");
250 $R = !ini_get('zend.ze1_compatibility_mode');
251 $M = FALSE;
252 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
255 /* Configuration file
256 */
258 /* Check if we can create a config file.*/
259 $N = _("Configuration writeable");
260 $D = _("The configuration file can't be written");
261 $S = sprintf(_("GOsa reads its configuration from a file located in (%s/%s). The setup can write the configuration directly if it is writeable."),CONFIG_DIR,CONFIG_FILE);
262 $R = ( file_exists(CONFIG_DIR."/".CONFIG_FILE) && is_writeable(CONFIG_DIR."/".CONFIG_FILE)) // is there a config file ?
263 || (!file_exists(CONFIG_DIR."/".CONFIG_FILE) && is_writeable(CONFIG_DIR)); // There is non, but can we create a file there ?
264 $M = FALSE;
265 $this->is_writeable[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
267 }
270 function save_object()
271 {
272 /* If everything is fine, set this step to completed
273 * and allow switching to next setup step
274 */
275 $failed = false;
276 foreach(array("basic_checks","config_checks","is_writeable") as $type){
277 foreach($this->$type as $obj){
279 if($obj['MUST'] && !$obj['RESULT']){
280 $failed = true;
281 break;
282 }
283 }
284 }
285 $this->is_completed = !$failed;
286 }
289 /* Check if current PHP version is compatible
290 with the current version of GOsa */
291 function check_php_version()
292 {
293 return(version_compare(phpversion(),"5.2.0",">="));
294 }
295 }
297 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
298 ?>