Code

Updated config registry
[gosa.git] / gosa-core / setup / class_setupStep_Checks.inc
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   }
34  
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   }
42   
43   
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     /* Is calendar module available/compiled/installed */
120     $N = msgPool::checkingFor(_("Calendar"));
121     $D = _("GOsa requires this module to calculate dates.");
122     $S = msgPool::installPhpModule("calendar");
123     $R = is_callable("cal_days_in_month");
124     $M = TRUE;
125     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
127     /* Mysql module loaded ? */
128     $N = msgPool::checkingFor(_("MySQL"));
129     $D = _("GOsa requires this module to communicate with several supported databases.");
130     $S = msgPool::installPhpModule("MySQL");
131     $R = is_callable("mysql_query");
132     $M = TRUE;
133     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
135     /* Checking generate LM/NT password hashes */
136     #TODO: either this, or gosa-si will do the hash generation
137     $query= "mkntpwd 2>&1";
138     $output= shell_exec ($query);
139     $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
140     if (!$have_mkntpwd){
141       $query= 'LC_ALL=C LANG=C perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen $ARGV[0]), $/;" >/dev/null';
142       system ($query, $ret);
143       $have_mkntpwd |= ($ret == 0);
144     }
146     $N = msgPool::checkingFor(_("samba hash generator"));
147     $D = _("GOsa requires this command to synchronize POSIX and samba passwords.");
148     $S = _("Deploy a gosa-si installation or install the perl Crypt::SmbHash modules.");
149     $R = $have_mkntpwd;
150     $M = TRUE;
151     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
153     /* Read data written by convert */
154     $output= "";
155     $sh= popen("convert", 'r');
156     while (!feof($sh)){
157       $output.= fread($sh, 4096);
158     }
159     pclose($sh);
161     $N = msgPool::checkingFor(_("imagick"));
162     $D = _("GOsa requires this extension to handle images.");
163     $S = msgPool::installPhpModule("php5-imagick");
165     $IMGVER = phpversion('imagick');
167     if ($IMGVER > 1.0) {
168         $R = method_exists('imagick','getImageBlob');
169     }
170     else {
171         $R = is_callable("imagick_blob2image") || !empty($output);
172     }
174     $M = TRUE;
175     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
177     $N = msgPool::checkingFor(_("compression module"));
178     $D = _("GOsa requires this extension to handle snapshots.");
179     $S = msgPool::installPhpModule("php5-zip / php5-gzip");
180     $R = is_callable("gzcompress");
181     $M = FALSE;
182     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
185     /* PHP Configuration checks */
187     /* Register_globals off */
188     $N = "register_globals = <b>off</b>";
189     $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.");
190     $S = _("Search for 'register_globals' in your php.ini and switch it to 'Off'.");
191     $R = ini_get("register_globals") == 0;
192     $M = FALSE;
193     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
196     /* session lifetime set to >=86400 seconds ? */
197     $N = "session.gc_maxlifetime &gt;= <b>86400</b>";
198     $D = _("PHP uses this value for the garbage collector to delete old sessions.")." ".
199          _("Setting this value to one day will prevent loosing session and cookies before they really timeout.");
200     $S = _("Search for 'session.gc_maxlifetime' in your php.ini and set it to 86400 or higher.");
201     $R = ini_get("session.gc_maxlifetime") >= 86400;
202     $M = FALSE;
203     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
205     /* Session auto start must be turned off */
206     $session_auto_start = ini_get('session.auto_start');
207     $N = "session.auto_start = <b>"._("Off")."</b>";
208     $D = _("In Order to use GOsa without any trouble, the session.auto_register option in your php.ini should be set to 'Off'.");
209     $S = _("Search for 'session.auto_start' in your php.ini and set it to 'Off'.");
210     $R = !$session_auto_start['local_value'];
211     $M = TRUE;
212     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
214     /* Check if memory limit is set to 32 or > */
215     $N = "memory_limit &gt;= <b>32</b>";
216     $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.");
217     $S = _("Search for 'memory_limit' in your php.ini and set it to '32M' or higher.");
218     $R = ini_get('memory_limit') >= 32 ;
219     $M = TRUE;
220     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
222     /* Implicit Flush disabled can increase performance */
223     $N = "implicit_flush = <b>"._("Off")."</b>";
224     $D = _("This option influences the PHP output handling. Turn this Option off, to increase performance.");
225     $S = _("Search for 'implicit_flush' in your php.ini and set it to 'Off'."); 
226     $R = !ini_get('implicit_flush');
227     $M = FALSE;
228     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
230     /* Check if execution time is set to 30 */
231     $N = "max_execution_time &gt;= <b>30</b>";
232     $D = _("The Execution time should be at least 30 seconds.");
233     $S = _("Search for 'max_execution_time' in your php.ini and set it to '30' or higher.");
234     $R = ini_get("max_execution_time") >= 30 ;
235     $M = TRUE;
236     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
238     /* Expose php should be set to off */
239     $N = "expose_php = <b>"._("Off")."</b>";
240     $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.");
241     $S = _("Search for 'expose_php' in your php.ini and set if to 'Off'.");
242     $R = !ini_get("expose_php");
243     $M = FALSE;
244     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
246     /* Automatic quoting must be turned on */
247     $N = "magic_quotes_gpc = <b>"._("On")."</b>";
248     $D = _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case."); 
249     $S = _("Search for 'magic_quotes_gpc' in your php.ini and set it to 'On'."); 
250     $R = ini_get('magic_quotes_gpc'); 
251     $M = TRUE;
252     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
254     /* Emulating old stuff? */
255     $N = "zend.ze1_compatibility_mode = <b>"._("Off")."</b>";
256     $D = _("Increase your server performance by setting magic_quotes_gpc to 'off'."); 
257     $S = _("Search for 'zend.ze1_compatibility_mode' in your php.ini and set it to 'Off'."); 
258     $R = !ini_get('zend.ze1_compatibility_mode'); 
259     $M = FALSE;
260     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
263     /* Configuration file  
264      */
266     /* Check if we can create a config file.*/
267     $N = _("Configuration writeable");
268     $D = _("The configuration file can't be written");
269     $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); 
270     $R =    ( file_exists(CONFIG_DIR."/".CONFIG_FILE) && is_writeable(CONFIG_DIR."/".CONFIG_FILE)) // is there a config file ? 
271         ||  (!file_exists(CONFIG_DIR."/".CONFIG_FILE) && is_writeable(CONFIG_DIR));  // There is non, but can we create a file there ?
272     $M = FALSE;
273     $this->is_writeable[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
275   }
276  
278   function save_object()
279   {
280      /* If everything is fine, set this step to completed
281      *  and allow switching to next setup step
282      */
283     $failed = false;
284     foreach(array("basic_checks","config_checks","is_writeable") as $type){
285       foreach($this->$type as $obj){
287         if($obj['MUST'] && !$obj['RESULT']){
288           $failed = true;
289           break;
290         }
291       }
292     }
293     $this->is_completed = !$failed;
294   }
295  
297   /* Check if current PHP version is compatible 
298       with the current version of GOsa */
299   function check_php_version()
300   {
301     return(version_compare(phpversion(),"5.2.0",">=")); 
302   }
305 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
306 ?>