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