Code

- fix for debian bug 535872
[gosa.git] / setup / class_setupStep_Checks.inc
1 <?php
3 /*
4    This code is part of GOsa (https://gosa.gonicus.de)
5    Copyright (C) 2007 Fabian Hickert
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 */
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/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 version and required 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();
62  
63     /* PHP version check */
64     $N = _("Checking PHP version"); 
65     $D = sprintf(_("PHP must be of version %s / %s or above."),"4.3.10","5.2.0");
66     $S = _("GOsa requires functionality that is not available (or buggy) in older PHP versions. Please update 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 = _("Checking for LDAP support");
73     $D = _("This is the main extension used by GOsa and therefore really required.");
74     $S = _("The ldap extension (php4-ldap/php5-ldap) is required to communicate with your LDAP server.");
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 = _("Checking for gettext support");
81     $D = _("Gettext support is required for internationalization.");
82     $S = _("Please make sure that the extension is activated.");
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 = _("Checking for iconv support");
89     $D = _("This module is used by GOsa to convert samba munged dial informations and is therefore required. ");
90     $S = _("Please make sure that the extension is activated.");
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 = _("Checking for mhash support");
97     $D = _("You'll need this module to make use of SSHA encryption");
98     $S = _("The mhash module for PHP 4/5 is not available.Please install php4-mhash/php5-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 = _("Checking for IMAP support");
105     $D = _("The IMAP module is needed to communicate with the IMAP server. GOsa retrieves status information, creates and deletes mail users, etc.");
106     $S = _("This module is used to communicate with your mail server. Please install php4-imap/php5-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 = _("Checking for multi byte support");
113     $D = _("The multi byte string support is required by some plugins.");
114     $S = _("Please compile php with enabled multi byte support '--enable-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     /* Check getacl in imap module */
120     $N = _("Checking for getacl in IMAP implementation");
121     $D = _("The getacl support is needed to handle shared folder permissions. Old IMAP extensions are not capable of reading acl's. You need a recent PHP version to use this feature.");
122     $S = $D;
123     $R = is_callable("imap_getacl");
124     $M = TRUE;
125     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
127     /* Mysql module loaded ? */
128     $N = _("Checking for MySQL support");
129     $D = _("MySQL support is needed to communicate with several supported databases.");
130     $S = _("This module is required to communicate with database servers (GOfax, asterisk, GLPI, etc.). Please install php4-mysql/php5-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 for kadm5 module */
136     $N = _("Checking for kadm5 support");
137     $D = _("Managing users in kerberos requires the kadm5 module which is downloadable via PEAR network.");
138     $S = _("This module is required to manage user in kerberos, it is downloadable via PEAR network");
139     $R = is_callable("kadm5_init_with_password");
140     $M = FALSE;
141     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
143     /* Snmp module available ? */
144     $N = _("Checking for SNMP support");
145     $D = _("The simple network management protocol is needed to get status information from clients.");
146     $S = _("This module is required for client monitoring. Please install php4-snmp/php5-snmp.");
147     $R = is_callable("snmpget");
148     $M = FALSE;
149     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
151     /* Checking for Cups module */
152     $N = _("Checking for CUPS support");
153     $D = _("In order to read available printers via the IPP protocol instead of printcap files, you've to install the CUPS module.");
154     $S = $D; 
155     $R = is_callable("cups_get_dest_list");
156     $M = FALSE;
157     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
159     /* Checking for F ping utility */
160     $query= "LC_ALL=C LANG=C fping -v 2>&1";
161     $output= shell_exec ($query);
162     $N = _("Checking for fping utility");
163     $D = _("The fping utility is used if you've got a thin client based terminal environment.");
164     $S = _("The fping utility is only used in thin client based terminal environment.");
165     $R = preg_match("/^fping:/", $output);
166     $M = FALSE;
167     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
169     /* Checking generate LM/NT password hashes */
170     $query= "mkntpwd 2>&1";
171     $output= shell_exec ($query);
172     $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
173     if (!$have_mkntpwd){
174       $query= 'LC_ALL=C LANG=C perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen $ARGV[0]), $/;" &>/dev/null';
175       system ($query, $ret);
176       $have_mkntpwd |= ($ret == 0);
177     }
179     $N = _("SAMBA password hash generation");
180     $D = _("In order to use SAMBA 2/3 passwords, you've to install additional packages to generate password hashes.");
181     $S = _("In order to use SAMBA 2/3 you've to install additional perl libraries. Take a look at mkntpasswd.");
182     $R = $have_mkntpwd;
183     $M = TRUE;
184     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
187     /* PHP Configuration checks 
188      */
190     /* Register_globals off */
191     $N = "register_globals = <b>"._("Off")."</b>";
192     $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.");
193     $S = _("Search for 'register_globals' in your php.ini and switch it to 'Off'.");
194     $R = ini_get("register_globals") == 0;
195     $M = FALSE;
196     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
199     /* session lifetime set to >=86400 seconds ? */
200     $N = "session.gc_maxlifetime &gt;= <b>86400</b>";
201     $D = _("PHP uses this value for the garbage collector to delete old sessions.")." ".
202          _("Setting this value to one day will prevent loosing session and cookies before they really timeout.");
203     $S = _("Search for 'session.gc_maxlifetime' in your php.ini and set it to 86400 or higher.");
204     $R = ini_get("session.gc_maxlifetime") >= 86400;
205     $M = FALSE;
206     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
208     /* Session auto start must be turned off */
209     $session_auto_start = ini_get('session.auto_start');
210     $N = "session.auto_start = <b>"._("Off")."</b>";
211     $D = _("In Order to use GOsa without any trouble, the session.auto_register option in your php.ini should be set to 'Off'.");
212     $S = _("Search for 'session.auto_start' in your php.ini and set it to 'Off'.");
213     $R = !$session_auto_start['local_value'];
214     $M = TRUE;
215     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
217     /* Check if memory limit is set to 32 or > */
218     $N = "memory_limit &gt;= <b>32</b>";
219     $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.");
220     $S = _("Search for 'memory_limit' in your php.ini and set it to '32M' or higher.");
221     $R = ini_get('memory_limit') >= 32 ;
222     $M = TRUE;
223     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
225     /* Implicit Flush disabled can increase performance */
226     $N = "implicit_flush = <b>"._("Off")."</b>";
227     $D = _("This option influences the PHP output handling. Turn this Option off, to increase performance.");
228     $S = _("Search for 'implicit_flush' in your php.ini and set it to 'Off'."); 
229     $R = !ini_get('implicit_flush');
230     $M = FALSE;
231     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
233     /* Check if execution time is set to 30 */
234     $N = "max_execution_time &gt;= <b>30</b>";
235     $D = _("The Execution time should be at least 30 seconds.");
236     $S = _("Search for 'max_execution_time' in your php.ini and set it to '30' or higher.");
237     $R = ini_get("max_execution_time") >= 30 ;
238     $M = TRUE;
239     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
241     /* Expose php should be set to off */
242     $N = "expose_php = <b>"._("Off")."</b>";
243     $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.");
244     $S = _("Search for 'expose_php' in your php.ini and set if to 'Off'.");
245     $R = !ini_get("expose_php");
246     $M = FALSE;
247     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
249     /* Automatic quoting must be turned on */
250     $N = "magic_quotes_gpc = <b>"._("On")."</b>";
251     $D = _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case."); 
252     $S = _("Search for 'magic_quotes_gpc' in your php.ini and set it to 'On'."); 
253     $R = ini_get('magic_quotes_gpc'); 
254     $M = TRUE;
255     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
257     /* Emulating old stuff? */
258     if (!preg_match('/^4/', phpversion())){
259       $N = "zend.ze1_compatibility_mode = <b>"._("Off")."</b>";
260       $D = _("Increase your server performance by setting magic_quotes_gpc to 'off'."); 
261       $S = _("Search for 'zend.ze1_compatibility_mode' in your php.ini and set it to 'Off'."); 
262       $R = !ini_get('zend.ze1_compatibility_mode'); 
263       $M = FALSE;
264       $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
265     }
268     /* Configuration file  
269      */
271     /* Check if we can create a config file.*/
272     $N = _("Configuration writeable");
273     $D = _("The configuration file can't be written");
274     $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); 
275     $R =    ( file_exists(CONFIG_DIR."/".CONFIG_FILE) && is_writeable(CONFIG_DIR."/".CONFIG_FILE)) // is there a config file ? 
276         ||  (!file_exists(CONFIG_DIR."/".CONFIG_FILE) && is_writeable(CONFIG_DIR));  // There is non, but can we create a file there ?
277     $M = FALSE;
278     $this->is_writeable[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
280     /* If we have writeaccess to the config dir, check if there is already a config file */
281 #    if($R){
283 #      /* check if there is already a config file. */
284 #      $N = _("No old configuration file.");
285 #      $D = "";//_("");
286 #      $S = _("If there is already a configuration file, this file will be overwritten when GOsa setup finishes. Please move your old config file away.");
287 #      $R =  !file_exists(CONFIG_DIR."/".CONFIG_FILE);
288 #      $M = FALSE;
289 #      $this->is_writeable[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
290 #    }
291   }
292  
294   function save_object()
295   {
296      /* If everything is fine, set this step to completed
297      *  and allow switching to next setup step
298      */
299     $failed = false;
300     foreach(array("basic_checks","config_checks","is_writeable") as $type){
301       foreach($this->$type as $obj){
303         if($obj['MUST'] && !$obj['RESULT']){
304           $failed = true;
305           break;
306         }
307       }
308     }
309     $this->is_completed = !$failed;
310   }
311  
313   /* Check if current PHP version is compatible 
314       with the current version of GOsa */
315   function check_php_version()
316   {
317     if(preg_match("/^5/",phpversion())){
318       return(version_compare(phpversion(),"5.2.0",">=")); 
319     }else{
320       return(version_compare(phpversion(),"4.3.10",">="));
321     }
322   }
325 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
326 ?>