Code

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