Code

Fixed text: hanling
[gosa.git] / setup / class_setupStep2.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 setup_step_2 extends setup_step
24 {
25   var $basic_checks = array();
26   var $config_checks= array();
27   var $is_writeable = array();
29   function setup_step_2()
30   {
31     $this->s_title      = _("Installation check");
32     $this->s_title_long = _("Basic installation checks");
33     $this->s_info       = _("Some basic checks for PHP version, ldap extension...");
34   }
35  
36   
37   /* Execute and display template */ 
38   function execute()
39   {
40     $this->run_checks();
41     $smarty = get_smarty();
42     $smarty->assign("basic"       ,$this->basic_checks);
43     $smarty->assign("config"      ,$this->config_checks);
44     $smarty->assign("is_writeable",$this->is_writeable);
45     return($smarty->fetch(get_template_path("setup_step2.tpl",TRUE,dirname(__FILE__))));
46   }
49   /* Execute all checks */ 
50   function run_checks()
51   {
52     $this->basic_checks = array();
53     $this->config_checks = array();
54     $this->is_writeable = array();
55  
56     /* PHP version check */
57     $N = _("Checking PHP version"); 
58     $D = sprintf(_("PHP must be of version %s or %s or above for some functions."),"4.3.10","5.2.0");
59     $S = _("GOsa requires functions that may not be available in older PHP versions, just update to a supported PHP version.");
60     $R = $this->check_php_version();
61     $M = TRUE;
62     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
64     /* Checking imap extension */
65     $N = _("Checking for ldap module");
66     $D = _("This is the main module used by GOsa and therefore really required.");
67     $S = _("The ldap module (PHP4-ldap/PHP5-ldap) is required to communicate with your ldap server.");
68     $R = is_callable("ldap_bind");
69     $M = TRUE;
70     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
72     /* Check for gettext support */
73     $N = _("Checking for gettext support");
74     $D = _("Gettext support is required for internationalized GOsa.");
75     $S = _("This should be activated while compiling your PHP. (--with-gettext)");
76     $R = is_callable("bindtextdomain");
77     $M = TRUE;
78     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
80     /* Checing for iconv */
81     $N = _("Checking for iconv support");
82     $D = _("This module is used by GOsa to convert samba munged dial informations and is therefore required. ");
83     $S = _("his should be activated while compiling your PHP. (--with-iconv)");
84     $R = is_callable("iconv");
85     $M = TRUE;
86     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
88     /* Check for installed mhash module */
89     $N = _("Checking for mhash module");
90     $D = _("To use SSHA encryption, you'll need this module. GOsa will run without it.");
91     $S = _("The mhash module for PHP 4/5 is not available, please install it. (php4-mhash/php5-mhash)");
92     $R = is_callable("mhash");
93     $M = FALSE;
94     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
96     /* Is imap module available */
97     $N = _("Checking for imap module");
98     $D = _("The IMAP module is needed to communicate with the IMAP server. It gets status informations, creates and deletes mail users.");
99     $S = _("This module is used to communicate with your mail server. Please install (PHP4-imap PHP5-imap)");
100     $R = is_callable("imap_open");
101     $M = TRUE;
102     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
104     /* Check getacl in imap module */
105     $N = _("Checking for getacl in imap");
106     $D = _("The getacl support is needed for shared folder permissions. The standard IMAP module is not capable of reading acl's. You need a recend PHP version for this feature.");
107     $S = $D;
108     $R = is_callable("imap_getacl");
109     $M = TRUE;
110     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
112     /* Mysql module loaded ? */
113     $N = _("Checking for mysql module");
114     $D = _("MySQL support is needed for reading GOfax reports from databases.");
115     $S = _("This module is required to communicate with database servers, for example used in phone and fax addons. Please install (PHP4-mysql PHP5-mysql)");
116     $R = is_callable("mysql_query");
117     $M = TRUE;
118     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
120     /* Checking for kadm5 module */
121     $N = _("Checking for kadm5 module");
122     $D = _("Managing users in kerberos requires the kadm5 module which is downloadable via PEAR network.");
123     $S = _("This module is required to manage user in kerberos, it is downloadable via PEAR network");
124     $R = is_callable("kadm5_init_with_password");
125     $M = FALSE;
126     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
128     /* Snmp module available ? */
129     $N = _("Checking for snmp Module");
130     $D = _("Simple Network Management Protocol (SNMP) is required for client monitoring.");
131     $S = _("This module is required for client monitoring. (PHP4-snmp/PHP5-snmp)");
132     $R = is_callable("snmpget");
133     $M = FALSE;
134     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
136     /* Checking for Cups module */
137     $N = _("Checking for cups module");
138     $D = _("In order to read available printers from IPP protocol instead of printcap files, you've to install the CUPS module.");
139     $S = $D; 
140     $R = is_callable("cups_get_dest_list");
141     $M = FALSE;
142     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
144     /* Checking for F ping utility */
145     $query= "LC_ALL=C LANG=C fping -v 2>&1";
146     $output= shell_exec ($query);
147     $N = _("Checking for fping utility");
148     $D = _("The fping utility is only used if you've got a thin client based terminal environment running.");
149     $S = _("The fping utility is only used in thin client based terminal environment.");
150     $R = preg_match("/^fping:/", $output);
151     $M = FALSE;
152     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
154     /* Checking generate LM/NT password hashes */
155     $query= "mkntpwd 2>&1";
156     $output= shell_exec ($query);
157     $have_mkntpwd= preg_match("/^Usage: mkntpwd /", $output);
158     if (!$have_mkntpwd){
159       $query= 'LC_ALL=C LANG=C perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen $ARGV[0]), $/;" &>/dev/null';
160       system ($query, $ret);
161       $have_mkntpwd |= ($ret == 0);
162     }
164     $N = _("Password hashes");
165     $D = _("In order to use SAMBA 2/3, you've to install some additional packages to generate password hashes.");
166     $S = _("In order to use samba 2/3 you've to install some additional packages to generate password hashes. (e.g. libmhash2)");
167     $R = $have_mkntpwd;
168     $M = TRUE;
169     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
172     /* PHP Configuration checks 
173      */
175     /* Register_globals off */
176     $N = _("register_globals"."&nbsp;"."<b>"._("Off")."</b>");
177     $D = _("register_globals is a PHP mechanism to register all global varibales to be accessible from scripts without changing the scope. This may be a security risk. GOsa will run in both modes.");
178     $S = _("Search for 'register_globals' in your php.ini and switch it to 'Off'.");
179     $R = ini_get("register_globals") == 0;
180     $M = FALSE;
181     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
184     /* session lifetime set to >=86400 seconds ? */
185     $N = ("session.gc_maxlifetime"."&nbsp;"."<b> &gt;= 86400</b>");
186     $D = _("PHP uses this value for the garbage collector to delete old sessions.")."&nbsp;".
187          _("Setting this value to one day will prevent loosing session and cookie before they really timeout.");
188     $S = _("Serach for 'session.gc_maxlifetime' in your php.ini and set it to 86400 or higher.");
189     $R = ini_get("session.gc_maxlifetime") >= 86400;
190     $M = FALSE;
191     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
193     /* Session auto start must be turned off */
194     $session_auto_start = ini_get('session.auto_start');
195     $N = _("session.auto_start"."&nbsp;"."<b>"._("Off")."</b>");
196     $D = _("In Order to use GOsa without any trouble, the session.auto_register option in your php.ini must be set to 'Off'.");
197     $S = _("Serach for 'session.auto_start' in your php.ini and set it to 'Off'.");
198     $R = !$session_auto_start['local_value'];
199     $M = TRUE;
200     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
202     /* Check if memory limit is set to 32 or > */
203     $N = _("memory_limit")."&nbsp;"."<b> &gt;= 32</b>";
204     $D = _("GOsa needs at least 32MB of memory, less will cause unpredictable errors! Increase it for larger setups.");
205     $S = _("Search for 'memory_limit' in your php.ini and set it to '32M' or higher.");
206     $R = ini_get('memory_limit') >= 32 ;
207     $M = TRUE;
208     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
210     /* Implicit Flush disabled can increase performance */
211     $N = _("implicit_flush")."&nbsp;"."<b>"._("Off")."</b>";
212     $D = _("This option influences the Output handling. Turn this Option off, to increase performance.");
213     $S = _("Search for 'implicit_flush' in your php.ini and set it to 'Off'."); 
214     $R = ini_get('implicit_flush');
215     $M = FALSE;
216     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
218     /* Check if execution time is set to 30 */
219     $N = _("max_execution_time")."&nbsp;"."<b> &gt;= 30</b>";
220     $D = _("The Execution time should be at least 30 seconds, because some actions may consume more time.");
221     $S = _("Search for 'max_execution_time' in your php.ini and set it to '30' or higher.");
222     $R = ini_get("max_execution_time") >= 30 ;
223     $M = TRUE;
224     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
226     /* Expose php should be set to off */
227     $N = _("expose_php")."&nbsp;<b>"._("Off")."</b>";
228     $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.");
229     $S = _("Search for 'expose_php' in your php.ini and set if to 'Off'.");
230     $R = !ini_get("expose_php");
231     $M = FALSE;
232     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
234     /* Automatic quoting must be turned on */
235     $N = _("magic_quotes_gpc")."&nbsp;<b>"._("On")."</b>";
236     $D = _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes   in strings in this case."); 
237     $S = _("Search for 'magic_quotes_gpc' in yout php.ini and set it to 'On'."); 
238     $R = ini_get('magic_quotes_gpc'); 
239     $M = TRUE;
240     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
243     /* Configuration file  
244      */
246     /* Check if we can create a config file.*/
247     $N = _("Configuration file writeable.");
248     $D = _("The Configuration file can't be written");
249     $S = _("The GOsa reads its configuration from a file located in (/etc/gosa/gosa.conf). The setup can write the configuration directly in this file, if it is writeable."); 
250     $R =    ( file_exists("/etc/gosa/gosa.conf") && is_writeable("/etc/gosa/gosa.conf")) // is there a config file ? 
251         ||  (!file_exists("/etc/gosa/gosa.conf") && is_writeable("/etc/gosa"));  // There is non, but can we create a file there ?
252     $M = FALSE;
253     $this->is_writeable[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
255     /* If we have writeaccess to the config dir, check if there is already a config file */
256     if($R){
258       /* check if there is already a config file. */
259       $N = _("No old configuration file.");
260       $D = "";//_("");
261       $S = _("If there is already a configuration file, this file will be overwritten when GOsa setup finishes. Please move your old config file away.");
262       $R =  !file_exists("/etc/gosa/gosa.conf");
263       $M = FALSE;
264       $this->is_writeable[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
265     }
266   }
267  
269   function save_object()
270   {
271      /* If everything is fine, set this step to completed
272      *  and allow switching to next setup step
273      */
274     $failed = false;
275     foreach(array("basic_checks","config_checks","is_writeable") as $type){
276       foreach($this->$type as $obj){
278         if($obj['MUST'] && !$obj['RESULT']){
279           $failed = true;
280           break;
281         }
282       }
283     }
284     $this->is_completed = !$failed;
285   }
286  
288   /* Check if current PHP version is compatible 
289       with the current version of GOsa */
290   function check_php_version()
291   {
292     if(preg_match("/^5/",phpversion())){
293       return(version_compare(phpversion(),"5.2.0",">=")); 
294     }else{
295       return(version_compare(phpversion(),"4.3.10",">="));
296     }
297   }
300 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
301 ?>