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 );
146 /* PHP Configuration checks */
148 /* Register_globals off */
149 $N = "register_globals = <b>off</b>";
150 $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.");
151 $S = _("Search for 'register_globals' in your php.ini and switch it to 'Off'.");
152 $R = ini_get("register_globals") == 0;
153 $M = FALSE;
154 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
157 /* session lifetime set to >=86400 seconds ? */
158 $N = "session.gc_maxlifetime >= <b>86400</b>";
159 $D = _("PHP uses this value for the garbage collector to delete old sessions.")." ".
160 _("Setting this value to one day will prevent loosing session and cookies before they really timeout.");
161 $S = _("Search for 'session.gc_maxlifetime' in your php.ini and set it to 86400 or higher.");
162 $R = ini_get("session.gc_maxlifetime") >= 86400;
163 $M = FALSE;
164 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
166 /* Session auto start must be turned off */
167 $session_auto_start = ini_get('session.auto_start');
168 $N = "session.auto_start = <b>"._("Off")."</b>";
169 $D = _("In Order to use GOsa without any trouble, the session.auto_register option in your php.ini should be set to 'Off'.");
170 $S = _("Search for 'session.auto_start' in your php.ini and set it to 'Off'.");
171 $R = !$session_auto_start['local_value'];
172 $M = TRUE;
173 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
175 /* Check if memory limit is set to 32 or > */
176 $N = "memory_limit >= <b>32</b>";
177 $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.");
178 $S = _("Search for 'memory_limit' in your php.ini and set it to '32M' or higher.");
179 $R = ini_get('memory_limit') >= 32 ;
180 $M = TRUE;
181 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
183 /* Implicit Flush disabled can increase performance */
184 $N = "implicit_flush = <b>"._("Off")."</b>";
185 $D = _("This option influences the PHP output handling. Turn this Option off, to increase performance.");
186 $S = _("Search for 'implicit_flush' in your php.ini and set it to 'Off'.");
187 $R = !ini_get('implicit_flush');
188 $M = FALSE;
189 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
191 /* Check if execution time is set to 30 */
192 $N = "max_execution_time >= <b>30</b>";
193 $D = _("The Execution time should be at least 30 seconds.");
194 $S = _("Search for 'max_execution_time' in your php.ini and set it to '30' or higher.");
195 $R = ini_get("max_execution_time") >= 30 ;
196 $M = TRUE;
197 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
199 /* Expose php should be set to off */
200 $N = "expose_php = <b>"._("Off")."</b>";
201 $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.");
202 $S = _("Search for 'expose_php' in your php.ini and set if to 'Off'.");
203 $R = !ini_get("expose_php");
204 $M = FALSE;
205 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
207 /* Automatic quoting must be turned on */
208 $N = "magic_quotes_gpc = <b>"._("On")."</b>";
209 $D = _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case.");
210 $S = _("Search for 'magic_quotes_gpc' in your php.ini and set it to 'On'.");
211 $R = ini_get('magic_quotes_gpc');
212 $M = TRUE;
213 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
215 /* Emulating old stuff? */
216 $N = "zend.ze1_compatibility_mode = <b>"._("Off")."</b>";
217 $D = _("Increase your server performance by setting magic_quotes_gpc to 'off'.");
218 $S = _("Search for 'zend.ze1_compatibility_mode' in your php.ini and set it to 'Off'.");
219 $R = !ini_get('zend.ze1_compatibility_mode');
220 $M = FALSE;
221 $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
224 /* Configuration file
225 */
227 /* Check if we can create a config file.*/
228 $N = _("Configuration writeable");
229 $D = _("The configuration file can't be written");
230 $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);
231 $R = ( file_exists(CONFIG_DIR."/".CONFIG_FILE) && is_writeable(CONFIG_DIR."/".CONFIG_FILE)) // is there a config file ?
232 || (!file_exists(CONFIG_DIR."/".CONFIG_FILE) && is_writeable(CONFIG_DIR)); // There is non, but can we create a file there ?
233 $M = FALSE;
234 $this->is_writeable[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
236 /* If we have writeaccess to the config dir, check if there is already a config file */
237 # if($R){
238 #
239 # /* check if there is already a config file. */
240 # $N = _("No old configuration file.");
241 # $D = "";//_("");
242 # $S = _("If there is already a configuration file, this file will be overwritten when GOsa setup finishes. Please move your old config file away.");
243 # $R = !file_exists(CONFIG_DIR."/".CONFIG_FILE);
244 # $M = FALSE;
245 # $this->is_writeable[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
246 # }
247 }
250 function save_object()
251 {
252 /* If everything is fine, set this step to completed
253 * and allow switching to next setup step
254 */
255 $failed = false;
256 foreach(array("basic_checks","config_checks","is_writeable") as $type){
257 foreach($this->$type as $obj){
259 if($obj['MUST'] && !$obj['RESULT']){
260 $failed = true;
261 break;
262 }
263 }
264 }
265 $this->is_completed = !$failed;
266 }
269 /* Check if current PHP version is compatible
270 with the current version of GOsa */
271 function check_php_version()
272 {
273 return(version_compare(phpversion(),"5.2.0",">="));
274 }
275 }
277 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
278 ?>