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);
152 $N = msgPool::checkingFor(_("imagick"));
153 $D = _("GOsa requires this extension to handle images.");
154 $S = msgPool::installPhpModule("php5-imagick");
155 $R = is_callable("imagick_blob2image") || !empty($output);
156 $M = TRUE;
157 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
159 $N = msgPool::checkingFor(_("compression module"));
160 $D = _("GOsa requires this extension to handle snapshots.");
161 $S = msgPool::installPhpModule("php5-zip / php5-gzip");
162 $R = is_callable("gzcompress");
163 $M = FALSE;
164 $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
167 /* PHP Configuration checks */
169 /* Register_globals off */
170 $N = "register_globals = <b>off</b>";
171 $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.");
172 $S = _("Search for 'register_globals' in your php.ini and switch it to 'Off'.");
173 $R = ini_get("register_globals") == 0;
174 $M = FALSE;
175 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
178 /* session lifetime set to >=86400 seconds ? */
179 $N = "session.gc_maxlifetime >= <b>86400</b>";
180 $D = _("PHP uses this value for the garbage collector to delete old sessions.")." ".
181 _("Setting this value to one day will prevent loosing session and cookies before they really timeout.");
182 $S = _("Search for 'session.gc_maxlifetime' in your php.ini and set it to 86400 or higher.");
183 $R = ini_get("session.gc_maxlifetime") >= 86400;
184 $M = FALSE;
185 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
187 /* Session auto start must be turned off */
188 $session_auto_start = ini_get('session.auto_start');
189 $N = "session.auto_start = <b>"._("Off")."</b>";
190 $D = _("In Order to use GOsa without any trouble, the session.auto_register option in your php.ini should be set to 'Off'.");
191 $S = _("Search for 'session.auto_start' in your php.ini and set it to 'Off'.");
192 $R = !$session_auto_start['local_value'];
193 $M = TRUE;
194 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
196 /* Check if memory limit is set to 32 or > */
197 $N = "memory_limit >= <b>32</b>";
198 $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.");
199 $S = _("Search for 'memory_limit' in your php.ini and set it to '32M' or higher.");
200 $R = ini_get('memory_limit') >= 32 ;
201 $M = TRUE;
202 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
204 /* Implicit Flush disabled can increase performance */
205 $N = "implicit_flush = <b>"._("Off")."</b>";
206 $D = _("This option influences the PHP output handling. Turn this Option off, to increase performance.");
207 $S = _("Search for 'implicit_flush' in your php.ini and set it to 'Off'.");
208 $R = !ini_get('implicit_flush');
209 $M = FALSE;
210 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
212 /* Check if execution time is set to 30 */
213 $N = "max_execution_time >= <b>30</b>";
214 $D = _("The Execution time should be at least 30 seconds.");
215 $S = _("Search for 'max_execution_time' in your php.ini and set it to '30' or higher.");
216 $R = ini_get("max_execution_time") >= 30 ;
217 $M = TRUE;
218 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
220 /* Expose php should be set to off */
221 $N = "expose_php = <b>"._("Off")."</b>";
222 $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.");
223 $S = _("Search for 'expose_php' in your php.ini and set if to 'Off'.");
224 $R = !ini_get("expose_php");
225 $M = FALSE;
226 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
228 /* Automatic quoting must be turned on */
229 $N = "magic_quotes_gpc = <b>"._("On")."</b>";
230 $D = _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case.");
231 $S = _("Search for 'magic_quotes_gpc' in your php.ini and set it to 'On'.");
232 $R = ini_get('magic_quotes_gpc');
233 $M = TRUE;
234 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
236 /* Emulating old stuff? */
237 $N = "zend.ze1_compatibility_mode = <b>"._("Off")."</b>";
238 $D = _("Increase your server performance by setting magic_quotes_gpc to 'off'.");
239 $S = _("Search for 'zend.ze1_compatibility_mode' in your php.ini and set it to 'Off'.");
240 $R = !ini_get('zend.ze1_compatibility_mode');
241 $M = FALSE;
242 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
245 /* Configuration file
246 */
248 /* Check if we can create a config file.*/
249 $N = _("Configuration writeable");
250 $D = _("The configuration file can't be written");
251 $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);
252 $R = ( file_exists(CONFIG_DIR."/".CONFIG_FILE) && is_writeable(CONFIG_DIR."/".CONFIG_FILE)) // is there a config file ?
253 || (!file_exists(CONFIG_DIR."/".CONFIG_FILE) && is_writeable(CONFIG_DIR)); // There is non, but can we create a file there ?
254 $M = FALSE;
255 $this->is_writeable[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
257 }
260 function save_object()
261 {
262 /* If everything is fine, set this step to completed
263 * and allow switching to next setup step
264 */
265 $failed = false;
266 foreach(array("basic_checks","config_checks","is_writeable") as $type){
267 foreach($this->$type as $obj){
269 if($obj['MUST'] && !$obj['RESULT']){
270 $failed = true;
271 break;
272 }
273 }
274 }
275 $this->is_completed = !$failed;
276 }
279 /* Check if current PHP version is compatible
280 with the current version of GOsa */
281 function check_php_version()
282 {
283 return(version_compare(phpversion(),"5.2.0",">="));
284 }
285 }
287 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
288 ?>