source: trunk/setup/check_install.php @ 2

Revision 2, 18.2 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare - Setup Check Installation                                    *
4  * http://www.eGroupWare.org                                                *
5  * --------------------------------------------                             *
6  *  This program is free software; you can redistribute it and/or modify it *
7  *  under the terms of the GNU General Public License as published by the   *
8  *  Free Software Foundation; either version 2 of the License, or (at your  *
9  *  option) any later version.                                              *
10  \**************************************************************************/
11
12
13        $run_by_webserver = !!$_SERVER['PHP_SELF'];
14        $is_windows = strtoupper(substr(PHP_OS,0,3)) == 'WIN';
15
16
17        if ($run_by_webserver)
18        {
19                $phpgw_info = array();
20                $GLOBALS['phpgw_info']['flags'] = array(
21                        'noheader' => True,
22                        'nonavbar' => True,
23                        'currentapp' => 'home',
24                        'noapi' => True
25                );
26                $safe_er = error_reporting();
27                include ('./inc/functions.inc.php');
28                error_reporting($safe_er);
29
30                $GLOBALS['phpgw_info']['setup']['stage']['header'] = $GLOBALS['phpgw_setup']->detection->check_header();
31                if ($GLOBALS['phpgw_info']['setup']['stage']['header'] == '10')
32                {
33                        // Check header and authentication
34                        if (!$GLOBALS['phpgw_setup']->auth('Config') && !$GLOBALS['phpgw_setup']->auth('Header'))
35                        {
36                                Header('Location: index.php');
37                                exit;
38                        }
39                }
40                $passed_icon = '<img src="templates/default/images/completed.png" title="Passed" align="middle"> ';
41                $error_icon = '<img src="templates/default/images/incomplete.png" title="Error" align="middle"><span id="setup_error">';
42                $warning_icon = '<img src="templates/default/images/dep.png" title="Warning" align="middle"><span id="setup_warning"> ';
43        }
44        else
45        {
46                $passed_icon = '>>> Passed ';
47                $error_icon = '*** Error: ';
48                $warning_icon = '!!! Warning: ';
49
50                function lang($msg,$arg1=NULL,$arg2=NULL,$arg3=NULL,$arg4=NULL)
51                {
52                        return is_null($arg1) ? $msg : str_replace(array('%1','%2','%3','%4'),array($arg1,$arg2,$arg3,$arg4),$msg);
53                }
54        }
55        $checks = array(
56                'safe_mode' => array(
57                        'func' => 'php_ini_check',
58                        'value' => 0,
59                        'verbose_value' => 'Off',
60                        'warning' => lang('safe_mode is turned on, which is generaly a good thing as it makes your install more secure.')."\n".
61                                lang('If safe_mode is turned on, eGW is not able to change certain settings on runtime, nor can we load any not yet loaded module.')."\n".
62                                lang('*** You have to do the changes manualy in your php.ini (usualy in /etc on linux) in order to get eGW fully working !!!')."\n".
63                                lang('*** Do NOT update your database via setup, as the update might be interrupted by the max_execution_time, which leaves your DB in an unrecoverable state (your data is lost) !!!')
64                ),
65/* not longer needed, as it gets set now on runtime (works even with safe_mode)
66                'error_reporting' => array(
67                        'func' => 'php_ini_check',
68                        'value' => E_NOTICE,
69                        'verbose_value' => 'E_NOTICE',
70                        'check' => 'not set',
71                        'safe_mode' => 'error_reporting = E_ALL & ~E_NOTICE'
72                ),
73*/
74                'magic_quotes_runtime' => array(
75                        'func' => 'php_ini_check',
76                        'value' => 0,
77                        'verbose_value' => 'Off',
78                        'safe_mode' => 'magic_quotes_runtime = Off'
79                ),
80                'register_globals' => array(
81                        'func' => 'php_ini_check',
82                        'value' => 0,
83                        'verbose_value' => 'Off',
84                        'warning' => lang("register_globals is turned On, eGroupWare does NOT require it and it's generaly more secure to have it turned Off")
85                ),
86                'memory_limit' => array(
87                        'func' => 'php_ini_check',
88                        'value' => '16M',
89                        'check' => '>=',
90                        'error' => lang('memory_limit is set to less than 16M: some applications of eGroupWare need more than the recommend 8M, expect occasional failures'),
91                        'change' => 'memory_limit = 16M'
92                ),
93                'max_execution_time' => array(
94                        'func' => 'php_ini_check',
95                        'value' => 30,
96                        'check' => '>=',
97                        'error' => lang('max_execution_time is set to less than 30 (seconds): eGroupWare sometimes needs a higher execution_time, expect occasional failures'),
98                        'safe_mode' => 'max_execution_time = 30'
99                ),
100                'include_path' => array(
101                        'func' => 'php_ini_check',
102                        'value' => '.',
103                        'check' => 'contain',
104                        'error' => lang('include_path need to contain "." - the current directory'),
105                        'save_mode' => 'max_execution_time = 30'
106                ),
107#               'mysql' => array(
108#                       'func' => 'extension_check',
109#                       'warning' => "<div id='setup_info'>" . lang('The %1 extension is needed, if you plan to use a %2 database.','mysql','MySQL').'</div>'
110#               ),
111                'ldap' => array(
112                        'func' => 'extension_check',
113                        'warning' => "<div id='setup_info'>" . lang('The %1 extension is needed, if you plan to use a %2 database.','ldap','LDAP').'</div>'
114                ),
115                'pgsql' => array(
116                        'func' => 'extension_check',
117                        'warning' => '<div id="setup_info">' . lang('The %1 extension is needed, if you plan to use a %2 database.','pgsql','pgSQL').'</div>'
118                ),
119                'mssql' => array(
120                        'func' => 'extension_check',
121                        'warning' => '<div id="setup_info">' . lang('The %1 extension is needed, if you plan to use a %2 database.','mssql','MsSQL') . '</div>',
122                        'win_only' => True
123                ),
124                'mbstring' => array(
125                        'func' => 'extension_check',
126                        'warning' => '<div id="setup_info">' . lang('The mbstring extension is needed to fully support unicode (utf-8) or other multibyte-charsets.') . "</div>"
127                ),
128                'mbstring.func_overload' => array(
129                        'func' => 'php_ini_check',
130                        'value' => 7,
131                        'warning' => '<div id="setup_info">' . lang('The mbstring.func_overload = 7 is needed to fully support unicode (utf-8) or other multibyte-charsets.') . "</div>",
132                        'change' => extension_loaded('mbstring')  || function_exists('dl') && @dl(PHP_SHLIB_PREFIX.'mbstring.'.PHP_SHLIB_SUFFIX) ? 'mbstring.func_overload = 7' : '',
133                ),
134                'imap' => array(
135                        'func' => 'extension_check',
136                        'warning' => '<div id="setup_info">' . lang('The imap extension is needed by the two email apps (even if you use email with pop3 as protocoll).') . '</div>'
137                ),
138                'session' => array(
139                        'func' => 'extension_check',
140                        'warning' => '<div id="setup_info">' . lang('The session extension is needed to use php4 session (db-sessions work without).') . "</div>"
141                ),     
142                '.' => array(
143                        'func' => 'permission_check',
144                        'is_world_writable' => False,
145                        'recursiv' => True
146                ),
147                'header.inc.php' => array(
148                        'func' => 'permission_check',
149                        'is_world_readable' => False,
150                        'only_if_exists' => @$GLOBALS['phpgw_info']['setup']['stage']['header'] != 10
151                ),
152                'phpgwapi/images' => array(
153                        'func' => 'permission_check',
154                        'is_writable' => True
155                ),
156#               'fudforum' => array(
157#                       'func' => 'permission_check',
158#                       'is_writable' => True,
159#                       'only_if_exists' => True
160#               ),
161#               'gd' => array(
162#                       'func' => 'gd_check'
163#               )
164        );
165
166        // some constants for pre php4.3
167        if (!defined('PHP_SHLIB_SUFFIX'))
168        {
169                define('PHP_SHLIB_SUFFIX',$is_windows ? 'dll' : 'so');
170        }
171        if (!defined('PHP_SHLIB_PREFIX'))
172        {
173                define('PHP_SHLIB_PREFIX',PHP_SHLIB_SUFFIX == 'dll' ? 'php_' : '');
174        }
175
176        function extension_check($name,$args)
177        {
178                global $passed_icon, $error_icon, $warning_icon, $is_windows;
179
180                if (isset($args['win_only']) && $args['win_only'] && !$is_windows)
181                {
182                        return True;    // check only under windows
183                }
184                // we check for the existens of 'dl', as multithreaded webservers dont have it !!!
185                $availible = extension_loaded($name) || function_exists('dl') && @dl(PHP_SHLIB_PREFIX.$name.'.'.PHP_SHLIB_SUFFIX);
186
187                echo ($availible ? $passed_icon : $warning_icon).' '.lang('Checking extension %1 is loaded or loadable',$name).': '.($availible ? lang('True') : lang('False'))."</span><br>\n";
188
189                if (!$availible)
190                {
191                        echo $args['warning'];
192                }
193                echo "\n";
194
195                return $availible;
196        }
197
198        function verbosePerms( $in_Perms )
199        {
200                if($in_Perms & 0x1000)     // FIFO pipe
201                {
202                        $sP = 'p';
203                }
204                elseif($in_Perms & 0x2000) // Character special
205                {
206                        $sP = 'c';
207                }
208                elseif($in_Perms & 0x4000) // Directory
209                {
210                        $sP = 'd';
211                }
212                elseif($in_Perms & 0x6000) // Block special
213                {
214                        $sP = 'b';
215                }
216                elseif($in_Perms & 0x8000) // Regular
217                {
218                        $sP = '-';
219                }
220                elseif($in_Perms & 0xA000) // Symbolic Link
221                {
222                        $sP = 'l';
223                }
224                elseif($in_Perms & 0xC000) // Socket
225                {
226                        $sP = 's';
227                }
228                else                         // UNKNOWN
229                {
230                        $sP = 'u';
231                }
232
233                // owner
234                $sP .= (($in_Perms & 0x0100) ? 'r' : '-') .
235                (($in_Perms & 0x0080) ? 'w' : '-') .
236                (($in_Perms & 0x0040) ? (($in_Perms & 0x0800) ? 's' : 'x' ) :
237                (($in_Perms & 0x0800) ? 'S' : '-'));
238
239                // group
240                $sP .= (($in_Perms & 0x0020) ? 'r' : '-') .
241                (($in_Perms & 0x0010) ? 'w' : '-') .
242                (($in_Perms & 0x0008) ? (($in_Perms & 0x0400) ? 's' : 'x' ) :
243                (($in_Perms & 0x0400) ? 'S' : '-'));
244
245                // world
246                $sP .= (($in_Perms & 0x0004) ? 'r' : '-') .
247                (($in_Perms & 0x0002) ? 'w' : '-') .
248                (($in_Perms & 0x0001) ? (($in_Perms & 0x0200) ? 't' : 'x' ) :
249                (($in_Perms & 0x0200) ? 'T' : '-'));
250                return $sP;
251        }
252
253        function permission_check($name,$args,$verbose=True)
254        {
255                global $passed_icon, $error_icon, $warning_icon,$is_windows;
256                //echo "<p>permision_check('$name',".print_r($args,True).",'$verbose')</p>\n";
257
258                if (substr($name,0,3) != '../')
259                {
260                        $name = '../'.$name;
261                }
262                $rel_name = substr($name,3);
263
264                if (!file_exists($name) && isset($args['only_if_exists']) && $args['only_if_exists'])
265                {
266                        return True;
267                }
268
269                $perms = $checks = '';
270                if (file_exists($name))
271                {
272                        $owner = function_exists('posix_getpwuid') ? posix_getpwuid(@fileowner($name)) : array('name' => 'nn');
273                        $group = function_exists('posix_getgrgid') ? posix_getgrgid(@filegroup($name)) : array('name' => 'nn');
274                        $perms = "$owner[name]/$group[name] ".verbosePerms(@fileperms($name));
275                }
276
277                $checks = array();
278                if (isset($args['is_readable'])) $checks[] = (!$args['is_readable']?'not ':'').lang('readable by the webserver');
279                if (isset($args['is_writable'])) $checks[] = (!$args['is_writable']?'not ':'').lang('writable by the webserver');
280                if (isset($args['is_world_readable'])) $checks[] = (!$args['is_world_readable']?lang('not').' ':'').lang('world readable');
281                if (isset($args['is_world_writable'])) $checks[] = (!$args['is_world_writable']?lang('not').' ':'').lang('world writable');
282                $checks = implode(', ',$checks);
283
284                $icon = $passed_icon;
285                $msg = lang('Checking file-permissions of %1 for %2: %3',$rel_name,$checks,$perms)."<br>\n";
286
287                if (!file_exists($name))
288                {
289                        echo $error_icon . $msg . lang('%1 does not exist !!!',$rel_name)."</span><br/>\n";
290                        return False;
291                }
292                $warning = False;
293                if (!$GLOBALS['run_by_webserver'] && (@$args['is_readable'] || @$args['is_writable']))
294                {
295                        echo $warning_icon.' '.$msg. lang('Check can only be performed, if called via a webserver, as the user-id/-name of the webserver is not known.')."</span><br/>\n";
296                        unset($args['is_readable']);
297                        unset($args['is_writable']);
298                        $warning = True;
299                }
300                $Ok = True;
301                if (isset($args['is_writable']) && is_writable($name) != $args['is_writable'])
302                {
303                        echo "$error_icon $msg ".lang('%1 is %2%3 !!!',$rel_name,$args['is_writable']?lang('not').' ':'',lang('writable by the webserver'))."</span><br/>\n";
304                        $Ok = False;
305                }
306                if (isset($args['is_readable']) && is_readable($name) != $args['is_readable'])
307                {
308                        echo "$error_icon $msg ". lang('%1 is %2%3 !!!',$rel_name,$args['is_readable']?lang('not').' ':'',lang('readable by the webserver'))."</span><br/>\n";
309                        $Ok = False;
310                }
311                if (!$is_windows && isset($args['is_world_readable']) && !(fileperms($name) & 04) == $args['is_world_readable'])
312                {
313                        echo "$error_icon $msg" . lang('%1 is %2%3 !!!',$rel_name,$args['is_world_readable']?lang('not').' ':'',lang('world readable'))."</span><br/>\n";
314                        $Ok = False;
315                }
316                if (!$is_windows && isset($args['is_world_writable']) && !(fileperms($name) & 02) == $args['is_world_writable'])
317                {
318                        echo "$error_icon $msg " . lang('%1 is %2%3 !!!',$rel_name,$args['is_world_writable']?lang('not').' ':'',lang('world writable'))."</span><br/>\n";
319                        $Ok = False;
320                }
321                if ($Ok && !$warning && $verbose)
322                {
323                        echo $passed_icon.' '.$msg;
324                }
325                if ($Ok && @$args['recursiv'] && is_dir($name))
326                {
327                        if ($verbose)
328                        {
329                                echo "<div id='setup_info'>" . lang('This might take a while, please wait ...')."</div>\n";
330                                flush();
331                        }
332                        @set_time_limit(0);
333                        $handle = @opendir($name);
334                        while($handle && ($file = readdir($handle)))
335                        {
336                                if ($file != '.' && $file != '..')
337                                {
338                                        $Ok = $Ok && permission_check(($name!='.'?$name.'/':'').$file,$args,False);
339                                }
340                        }
341                        if ($handle) closedir($handle);
342                }
343                if ($verbose) echo "\n";
344
345                return $Ok;
346        }
347
348        function mk_value($value)
349        {
350                if (!preg_match('/^([0-9]+)([mk]+)$/i',$value,$matches)) return $value;
351               
352                return (strtolower($matches[2]) == 'm' ? 1024*1024 : 1024) * (int) $matches[1];
353        }
354               
355        function php_ini_check($name,$args)
356        {
357                global $passed_icon, $error_icon, $warning_icon, $is_windows;
358
359                $safe_mode = ini_get('safe_mode');
360
361                $ini_value = ini_get($name);
362                $check = isset($args['check']) ? $args['check'] : '=';
363                $verbose_value = isset($args['verbose_value']) ? $args['verbose_value'] : $args['value'];
364                $ini_value_verbose = '';
365                if ($verbose_value == 'On' || $verbose_value == 'Off')
366                {
367                        $ini_value_verbose = ' = '.($ini_value ? 'On' : 'Off');
368                }
369                switch ($check)
370                {
371                        case 'not set':
372                                $check = lang('not set');
373                                $result = !($ini_value & $args['value']);
374                                break;
375                        case 'set':
376                                $check = lang('set');
377                                $result = !!($ini_value & $args['value']);
378                                break;
379                        case '>=':
380                                $result = !$ini_value ||        // value not used, eg. no memory limit
381                                (int) mk_value($ini_value) >= (int) mk_value($args['value']);
382                                break;
383                        case 'contain':
384                                $check = lang('contain');
385                                $sep = $is_windows ? '[; ]+' : '[: ]+';
386                                $result = in_array($args['value'],split($sep,$ini_value));
387                                break;
388                        case '=':
389                        default:
390                                $result = $ini_value == $args['value'];
391                                break;
392                }
393                $msg = ' '.lang('Checking php.ini').": $name $check $verbose_value: <div id='setup_info'>ini_get('$name')='$ini_value'$ini_value_verbose</div>\n";
394
395                if ($result)
396                {
397                        echo $passed_icon.$msg;
398                }
399                if (!$result)
400                {
401                        if (isset($args['warning']))
402                        {
403                                echo $warning_icon.$msg.$args['warning']."<br/></span>\n";
404                        }
405                        if (isset($args['error']))
406                        {
407                                echo $error_icon.$msg.$args['error']."</br></span>\n";
408                        }
409                        if (isset($args['safe_mode']) && $safe_mode || @$args['change'])
410                        {
411                                if (!isset($args['warning']) && !isset($args['error']))
412                                {
413                                        echo $error_icon.$msg."<br/></span>";
414                                }
415                                echo "<div id='setup_error'>\n";
416                                echo '*** '.lang('Please make the following change in your php.ini').' ('.get_php_ini().'): '.(@$args['safe_mode']?$args['safe_mode']:$args['change'])."<br>\n";
417                                echo '*** '.lang('AND reload your webserver, so the above changes take effect !!!')."</div>\n";
418                        }
419                }
420                return $result;
421        }
422
423        function get_php_ini()
424        {
425                ob_start();
426                phpinfo(INFO_GENERAL);
427                $phpinfo = ob_get_contents();
428                ob_end_clean();
429
430                return preg_match('/\(php.ini\).*<\/td><td[^>]*>([^ <]+)/',$phpinfo,$found) ? $found[1] : False;
431        }
432
433        function gd_check()
434        {
435                global $passed_icon, $warning_icon;
436                $available = (function_exists('imagecopyresampled')  || function_exists('imagecopyresized'));
437               
438                echo ($available ? $passed_icon : $warning_icon).' '.lang('Checking for GD support...').': '.($available ? lang('True') : lang('False'))."<br/></span>\n";
439               
440                if (!$available)
441                {
442                        echo lang('Your PHP installation does not have appropriate GD support. You need gd library version 1.8 or newer to see Gantt charts in projects.')."\n";
443                        return false;
444                }
445                return true;
446        }
447       
448        if ($run_by_webserver)
449        {
450                $tpl_root = $GLOBALS['phpgw_setup']->html->setup_tpl_dir('setup');
451                $setup_tpl = CreateObject('setup.Template',$tpl_root);
452                $setup_tpl->set_file(array(
453                        'T_head' => 'head.tpl',
454                        'T_footer' => 'footer.tpl',
455                ));
456                $ConfigDomain = get_var('ConfigDomain',Array('POST','COOKIE'));
457                if (@$_GET['intro']) {
458                        if($ConfigLang = get_var('ConfigLang',array('POST','COOKIE')))
459                        {
460                                $GLOBALS['phpgw_setup']->set_cookie('ConfigLang',$ConfigLang,(int) (time()+(1200*9)),'/');
461                        }
462                        $GLOBALS['phpgw_setup']->html->show_header(lang('Welcome to the Expresso Livre (eGroupWare) Installation'),False,'config');
463                        echo '<h1>'.lang('Welcome to the Expresso Livre (eGroupWare) Installation')."</h1>\n";
464                        if(!$ConfigLang)
465                        {
466                                echo '<p><form action="check_install.php?intro=1" method="Post">Please select your language '.lang_select(True,'en')."</form></p>\n";
467                        }
468                        echo '<p>'.lang('The first step in installing Expresso Livre (eGroupWare) is to ensure your environment has the necessary settings to correctly run the application.');
469                        echo '<br /><br />'.lang('We will now run a series of tests, which may take a few minutes.  Click the link below to proceed.');
470                        echo '<h3><a href="check_install.php">'.lang('Run installation tests').'</a></h3>';
471                        $setup_tpl->pparse('out','T_footer');
472                        exit;
473                } else {
474                        $GLOBALS['phpgw_setup']->html->show_header(lang('Checking the Expresso Livre (eGroupWare) Installation'),False,'config',$ConfigDomain ? $ConfigDomain . '(' . @$phpgw_domain[$ConfigDomain]['db_type'] . ')' : '');
475                        echo '<h1>'.lang('Checking the Expresso Livre (eGroupWare) Installation')."</h1>\n";
476                        # echo "<pre style=\"text-align: left;\">\n";;
477                }
478        }
479        else
480        {
481                echo "Checking the Expresso Livre (eGroupWare) Installation\n";
482                echo "====================================\n\n";
483        }
484
485        $Ok = True;
486        foreach ($checks as $name => $args)
487        {
488                $check_ok = $args['func']($name,$args);
489                $Ok = $Ok && $check_ok;
490        }
491
492        if ($run_by_webserver)
493        {
494                # echo "</pre>\n";;
495
496                if ($GLOBALS['phpgw_info']['setup']['stage']['header'] != 10)
497                {
498                        if (!$Ok)
499                        {
500                                echo '<h2>'.lang('For correct instalation of Expresso Livre, the LDAP MUST be installed !!')."</h2>\n";
501                                echo '<h3>'.lang('Please fix the above errors (%1) and warnings(%2)',$error_icon,$warning_icon)."</h3>\n";
502                                echo '<h3><a href="check_install.php">'.lang('Click here to re-run the installation tests')."</a></h3>\n";
503                                echo '<h3>'.lang('or %1Continue to the Header Admin%2','<a href="manageheader.php">','</a>')."</h3>\n";
504                        }
505                        else
506                        {
507                                echo '<h2>'.lang('For correct instalation of Expresso Livre, the LDAP MUST be installed !!')."</h2>\n";
508                                echo '<h3><a href="manageheader.php">'.lang('Continue to the Header Admin')."</a></h3>\n";
509                        }
510                }
511                else
512                {
513                        echo '<h3>';
514                        if (!$Ok)
515                        {
516                                echo lang('Please fix the above errors (%1) and warnings(%2)',$error_icon,$warning_icon).'. ';
517                        }
518                        echo '<br><a href="'.str_replace('check_install.php','',$_SERVER['HTTP_REFERER']).'">'.lang('Return to Setup')."</a></h3>\n";
519                }
520                $setup_tpl->pparse('out','T_footer');
521                //echo "</body>\n</html>\n";
522        }
523?>
Note: See TracBrowser for help on using the repository browser.