source: branches/2.2/setup/check_install.php @ 4708

Revision 4708, 17.5 KB checked in by niltonneto, 13 years ago (diff)

Ticket #2019 - Ajustando verificação do mbstring no /setup/check_install.php

  • 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                'magic_quotes_runtime' => array(
66                        'func' => 'php_ini_check',
67                        'value' => 0,
68                        'verbose_value' => 'Off',
69                        'safe_mode' => 'magic_quotes_runtime = Off'
70                ),
71                'register_globals' => array(
72                        'func' => 'php_ini_check',
73                        'value' => 0,
74                        'verbose_value' => 'Off',
75                        'warning' => lang("register_globals is turned On, eGroupWare does NOT require it and it's generaly more secure to have it turned Off")
76                ),
77                'memory_limit' => array(
78                        'func' => 'php_ini_check',
79                        'value' => '16M',
80                        'check' => '>=',
81                        'error' => lang('memory_limit is set to less than 16M: some applications of eGroupWare need more than the recommend 8M, expect occasional failures'),
82                        'change' => 'memory_limit = 16M'
83                ),
84                'max_execution_time' => array(
85                        'func' => 'php_ini_check',
86                        'value' => 30,
87                        'check' => '>=',
88                        'error' => lang('max_execution_time is set to less than 30 (seconds): eGroupWare sometimes needs a higher execution_time, expect occasional failures'),
89                        'safe_mode' => 'max_execution_time = 30'
90                ),
91                'include_path' => array(
92                        'func' => 'php_ini_check',
93                        'value' => '.',
94                        'check' => 'contain',
95                        'error' => lang('include_path need to contain "." - the current directory'),
96                        'save_mode' => 'max_execution_time = 30'
97                ),
98                'ldap' => array(
99                        'func' => 'extension_check',
100                        'warning' => "<div id='setup_info'>" . lang('The %1 extension is needed, if you plan to use a %2 database.','ldap','LDAP').'</div>'
101                ),
102                'pgsql' => array(
103                        'func' => 'extension_check',
104                        'warning' => '<div id="setup_info">' . lang('The %1 extension is needed, if you plan to use a %2 database.','pgsql','pgSQL').'</div>'
105                ),
106                'mssql' => array(
107                        'func' => 'extension_check',
108                        'warning' => '<div id="setup_info">' . lang('The %1 extension is needed, if you plan to use a %2 database.','mssql','MsSQL') . '</div>',
109                        'win_only' => True
110                ),
111                'mbstring' => array(
112                        'func' => 'extension_check',
113                        'warning' => '<div id="setup_info">' . lang('The mbstring extension is needed to fully support unicode (utf-8) or other multibyte-charsets.') . "</div>"
114                ),
115                'mbstring.func_overload' => array(
116                        'func' => 'php_ini_check',
117                        'value' => 0,
118                        'warning' => '<div id="setup_info">' . lang('The mbstring.func_overload = 0 is needed to fully support unicode (utf-8) or other multibyte-charsets.') . "</div>",
119                        'change' => extension_loaded('mbstring')  || function_exists('dl') && @dl(PHP_SHLIB_PREFIX.'mbstring.'.PHP_SHLIB_SUFFIX) ? 'mbstring.func_overload = 0' : '',
120                ),
121                'imap' => array(
122                        'func' => 'extension_check',
123                        '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>'
124                ),
125                'session' => array(
126                        'func' => 'extension_check',
127                        'warning' => '<div id="setup_info">' . lang('The session extension is needed to use php4 session (db-sessions work without).') . "</div>"
128                ),     
129                '.' => array(
130                        'func' => 'permission_check',
131                        'is_world_writable' => False,
132                        'recursiv' => True
133                ),
134                'header.inc.php' => array(
135                        'func' => 'permission_check',
136                        'is_world_readable' => False,
137                        'only_if_exists' => @$GLOBALS['phpgw_info']['setup']['stage']['header'] != 10
138                ),
139                'phpgwapi/images' => array(
140                        'func' => 'permission_check',
141                        'is_writable' => True
142                ),
143        );
144
145        // some constants for pre php4.3
146        if (!defined('PHP_SHLIB_SUFFIX'))
147        {
148                define('PHP_SHLIB_SUFFIX',$is_windows ? 'dll' : 'so');
149        }
150        if (!defined('PHP_SHLIB_PREFIX'))
151        {
152                define('PHP_SHLIB_PREFIX',PHP_SHLIB_SUFFIX == 'dll' ? 'php_' : '');
153        }
154
155        function extension_check($name,$args)
156        {
157                global $passed_icon, $error_icon, $warning_icon, $is_windows;
158
159                if (isset($args['win_only']) && $args['win_only'] && !$is_windows)
160                {
161                        return True;    // check only under windows
162                }
163                // we check for the existens of 'dl', as multithreaded webservers dont have it !!!
164                $availible = extension_loaded($name) || function_exists('dl') && @dl(PHP_SHLIB_PREFIX.$name.'.'.PHP_SHLIB_SUFFIX);
165
166                echo ($availible ? $passed_icon : $warning_icon).' '.lang('Checking extension %1 is loaded or loadable',$name).': '.($availible ? lang('True') : lang('False'))."</span><br>\n";
167
168                if (!$availible)
169                {
170                        echo $args['warning'];
171                }
172                echo "\n";
173
174                return $availible;
175        }
176
177        function verbosePerms( $in_Perms )
178        {
179                if($in_Perms & 0x1000)     // FIFO pipe
180                {
181                        $sP = 'p';
182                }
183                elseif($in_Perms & 0x2000) // Character special
184                {
185                        $sP = 'c';
186                }
187                elseif($in_Perms & 0x4000) // Directory
188                {
189                        $sP = 'd';
190                }
191                elseif($in_Perms & 0x6000) // Block special
192                {
193                        $sP = 'b';
194                }
195                elseif($in_Perms & 0x8000) // Regular
196                {
197                        $sP = '-';
198                }
199                elseif($in_Perms & 0xA000) // Symbolic Link
200                {
201                        $sP = 'l';
202                }
203                elseif($in_Perms & 0xC000) // Socket
204                {
205                        $sP = 's';
206                }
207                else                         // UNKNOWN
208                {
209                        $sP = 'u';
210                }
211
212                // owner
213                $sP .= (($in_Perms & 0x0100) ? 'r' : '-') .
214                (($in_Perms & 0x0080) ? 'w' : '-') .
215                (($in_Perms & 0x0040) ? (($in_Perms & 0x0800) ? 's' : 'x' ) :
216                (($in_Perms & 0x0800) ? 'S' : '-'));
217
218                // group
219                $sP .= (($in_Perms & 0x0020) ? 'r' : '-') .
220                (($in_Perms & 0x0010) ? 'w' : '-') .
221                (($in_Perms & 0x0008) ? (($in_Perms & 0x0400) ? 's' : 'x' ) :
222                (($in_Perms & 0x0400) ? 'S' : '-'));
223
224                // world
225                $sP .= (($in_Perms & 0x0004) ? 'r' : '-') .
226                (($in_Perms & 0x0002) ? 'w' : '-') .
227                (($in_Perms & 0x0001) ? (($in_Perms & 0x0200) ? 't' : 'x' ) :
228                (($in_Perms & 0x0200) ? 'T' : '-'));
229                return $sP;
230        }
231
232        function permission_check($name,$args,$verbose=True)
233        {
234                global $passed_icon, $error_icon, $warning_icon,$is_windows;
235                //echo "<p>permision_check('$name',".print_r($args,True).",'$verbose')</p>\n";
236
237                if (substr($name,0,3) != '../')
238                {
239                        $name = '../'.$name;
240                }
241                $rel_name = substr($name,3);
242
243                if (!file_exists($name) && isset($args['only_if_exists']) && $args['only_if_exists'])
244                {
245                        return True;
246                }
247
248                $perms = $checks = '';
249                if (file_exists($name))
250                {
251                        $owner = function_exists('posix_getpwuid') ? posix_getpwuid(@fileowner($name)) : array('name' => 'nn');
252                        $group = function_exists('posix_getgrgid') ? posix_getgrgid(@filegroup($name)) : array('name' => 'nn');
253                        $perms = "$owner[name]/$group[name] ".verbosePerms(@fileperms($name));
254                }
255
256                $checks = array();
257                if (isset($args['is_readable'])) $checks[] = (!$args['is_readable']?'not ':'').lang('readable by the webserver');
258                if (isset($args['is_writable'])) $checks[] = (!$args['is_writable']?'not ':'').lang('writable by the webserver');
259                if (isset($args['is_world_readable'])) $checks[] = (!$args['is_world_readable']?lang('not').' ':'').lang('world readable');
260                if (isset($args['is_world_writable'])) $checks[] = (!$args['is_world_writable']?lang('not').' ':'').lang('world writable');
261                $checks = implode(', ',$checks);
262
263                $icon = $passed_icon;
264                $msg = lang('Checking file-permissions of %1 for %2: %3',$rel_name,$checks,$perms)."<br>\n";
265
266                if (!file_exists($name))
267                {
268                        echo $error_icon . $msg . lang('%1 does not exist !!!',$rel_name)."</span><br/>\n";
269                        return False;
270                }
271                $warning = False;
272                if (!$GLOBALS['run_by_webserver'] && (@$args['is_readable'] || @$args['is_writable']))
273                {
274                        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";
275                        unset($args['is_readable']);
276                        unset($args['is_writable']);
277                        $warning = True;
278                }
279                $Ok = True;
280                if (isset($args['is_writable']) && is_writable($name) != $args['is_writable'])
281                {
282                        echo "$error_icon $msg ".lang('%1 is %2%3 !!!',$rel_name,$args['is_writable']?lang('not').' ':'',lang('writable by the webserver'))."</span><br/>\n";
283                        $Ok = False;
284                }
285                if (isset($args['is_readable']) && is_readable($name) != $args['is_readable'])
286                {
287                        echo "$error_icon $msg ". lang('%1 is %2%3 !!!',$rel_name,$args['is_readable']?lang('not').' ':'',lang('readable by the webserver'))."</span><br/>\n";
288                        $Ok = False;
289                }
290                if (!$is_windows && isset($args['is_world_readable']) && !(fileperms($name) & 04) == $args['is_world_readable'])
291                {
292                        echo "$error_icon $msg" . lang('%1 is %2%3 !!!',$rel_name,$args['is_world_readable']?lang('not').' ':'',lang('world readable'))."</span><br/>\n";
293                        $Ok = False;
294                }
295                if (!$is_windows && isset($args['is_world_writable']) && !(fileperms($name) & 02) == $args['is_world_writable'])
296                {
297                        echo "$error_icon $msg " . lang('%1 is %2%3 !!!',$rel_name,$args['is_world_writable']?lang('not').' ':'',lang('world writable'))."</span><br/>\n";
298                        $Ok = False;
299                }
300                if ($Ok && !$warning && $verbose)
301                {
302                        echo $passed_icon.' '.$msg;
303                }
304                if ($Ok && @$args['recursiv'] && is_dir($name))
305                {
306                        if ($verbose)
307                        {
308                                echo "<div id='setup_info'>" . lang('This might take a while, please wait ...')."</div>\n";
309                                flush();
310                        }
311                        @set_time_limit(0);
312                        $handle = @opendir($name);
313                        while($handle && ($file = readdir($handle)))
314                        {
315                                if ($file != '.' && $file != '..')
316                                {
317                                        $Ok = $Ok && permission_check(($name!='.'?$name.'/':'').$file,$args,False);
318                                }
319                        }
320                        if ($handle) closedir($handle);
321                }
322                if ($verbose) echo "\n";
323
324                return $Ok;
325        }
326
327        function mk_value($value)
328        {
329                if (!preg_match('/^([0-9]+)([mk]+)$/i',$value,$matches)) return $value;
330               
331                return (strtolower($matches[2]) == 'm' ? 1024*1024 : 1024) * (int) $matches[1];
332        }
333               
334        function php_ini_check($name,$args)
335        {
336                global $passed_icon, $error_icon, $warning_icon, $is_windows;
337
338                $safe_mode = ini_get('safe_mode');
339
340                $ini_value = ini_get($name);
341                $check = isset($args['check']) ? $args['check'] : '=';
342                $verbose_value = isset($args['verbose_value']) ? $args['verbose_value'] : $args['value'];
343                $ini_value_verbose = '';
344                if ($verbose_value == 'On' || $verbose_value == 'Off')
345                {
346                        $ini_value_verbose = ' = '.($ini_value ? 'On' : 'Off');
347                }
348                switch ($check)
349                {
350                        case 'not set':
351                                $check = lang('not set');
352                                $result = !($ini_value & $args['value']);
353                                break;
354                        case 'set':
355                                $check = lang('set');
356                                $result = !!($ini_value & $args['value']);
357                                break;
358                        case '>=':
359                                $result = !$ini_value ||        // value not used, eg. no memory limit
360                                (int) mk_value($ini_value) >= (int) mk_value($args['value']);
361                                break;
362                        case 'contain':
363                                $check = lang('contain');
364                                $sep = $is_windows ? '[; ]+' : '[: ]+';
365                                $result = in_array($args['value'],split($sep,$ini_value));
366                                break;
367                        case '=':
368                        default:
369                                $result = $ini_value == $args['value'];
370                                break;
371                }
372                $msg = ' '.lang('Checking php.ini').": $name $check $verbose_value: <div id='setup_info'>ini_get('$name')='$ini_value'$ini_value_verbose</div>\n";
373
374                if ($result)
375                {
376                        echo $passed_icon.$msg;
377                }
378                if (!$result)
379                {
380                        if (isset($args['warning']))
381                        {
382                                echo $warning_icon.$msg.$args['warning']."<br/></span>\n";
383                        }
384                        if (isset($args['error']))
385                        {
386                                echo $error_icon.$msg.$args['error']."</br></span>\n";
387                        }
388                        if (isset($args['safe_mode']) && $safe_mode || @$args['change'])
389                        {
390                                if (!isset($args['warning']) && !isset($args['error']))
391                                {
392                                        echo $error_icon.$msg."<br/></span>";
393                                }
394                                echo "<div id='setup_error'>\n";
395                                echo '*** '.lang('Please make the following change in your php.ini').' ('.get_php_ini().'): '.(@$args['safe_mode']?$args['safe_mode']:$args['change'])."<br>\n";
396                                echo '*** '.lang('AND reload your webserver, so the above changes take effect !!!')."</div>\n";
397                        }
398                }
399                return $result;
400        }
401
402        function get_php_ini()
403        {
404                ob_start();
405                phpinfo(INFO_GENERAL);
406                $phpinfo = ob_get_contents();
407                ob_end_clean();
408
409                return preg_match('/\(php.ini\).*<\/td><td[^>]*>([^ <]+)/',$phpinfo,$found) ? $found[1] : False;
410        }
411
412        function gd_check()
413        {
414                global $passed_icon, $warning_icon;
415                $available = (function_exists('imagecopyresampled')  || function_exists('imagecopyresized'));
416               
417                echo ($available ? $passed_icon : $warning_icon).' '.lang('Checking for GD support...').': '.($available ? lang('True') : lang('False'))."<br/></span>\n";
418               
419                if (!$available)
420                {
421                        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";
422                        return false;
423                }
424                return true;
425        }
426       
427        if ($run_by_webserver)
428        {
429                $tpl_root = $GLOBALS['phpgw_setup']->html->setup_tpl_dir('setup');
430                $setup_tpl = CreateObject('setup.Template',$tpl_root);
431                $setup_tpl->set_file(array(
432                        'T_head' => 'head.tpl',
433                        'T_footer' => 'footer.tpl',
434                ));
435                $ConfigDomain = get_var('ConfigDomain',Array('POST','COOKIE'));
436                if (@$_GET['intro']) {
437                        if($ConfigLang = get_var('ConfigLang',array('POST','COOKIE')))
438                        {
439                                $GLOBALS['phpgw_setup']->set_cookie('ConfigLang',$ConfigLang,(int) (time()+(1200*9)),'/');
440                        }
441                        $GLOBALS['phpgw_setup']->html->show_header(lang('Welcome to the Expresso Livre (eGroupWare) Installation'),False,'config');
442                        echo '<h1>'.lang('Welcome to the Expresso Livre (eGroupWare) Installation')."</h1>\n";
443                        if(!$ConfigLang)
444                        {
445                                echo '<p><form action="check_install.php?intro=1" method="Post">Please select your language '.lang_select(True,'en')."</form></p>\n";
446                        }
447                        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.');
448                        echo '<br /><br />'.lang('We will now run a series of tests, which may take a few minutes.  Click the link below to proceed.');
449                        echo '<h3><a href="check_install.php">'.lang('Run installation tests').'</a></h3>';
450                        $setup_tpl->pparse('out','T_footer');
451                        exit;
452                } else {
453                        $GLOBALS['phpgw_setup']->html->show_header(lang('Checking the Expresso Livre (eGroupWare) Installation'),False,'config',$ConfigDomain ? $ConfigDomain . '(' . @$phpgw_domain[$ConfigDomain]['db_type'] . ')' : '');
454                        echo '<h1>'.lang('Checking the Expresso Livre (eGroupWare) Installation')."</h1>\n";
455                }
456        }
457        else
458        {
459                echo "Checking the Expresso Livre (eGroupWare) Installation\n";
460                echo "====================================\n\n";
461        }
462
463        $Ok = True;
464        foreach ($checks as $name => $args)
465        {
466                $check_ok = $args['func']($name,$args);
467                $Ok = $Ok && $check_ok;
468        }
469
470        if ($run_by_webserver)
471        {
472
473                if ($GLOBALS['phpgw_info']['setup']['stage']['header'] != 10)
474                {
475                        if (!$Ok)
476                        {
477                                echo '<h2>'.lang('For correct instalation of Expresso Livre, the LDAP MUST be installed !!')."</h2>\n";
478                                echo '<h3>'.lang('Please fix the above errors (%1) and warnings(%2)',$error_icon,$warning_icon)."</h3>\n";
479                                echo '<h3><a href="check_install.php">'.lang('Click here to re-run the installation tests')."</a></h3>\n";
480                                echo '<h3>'.lang('or %1Continue to the Header Admin%2','<a href="manageheader.php">','</a>')."</h3>\n";
481                        }
482                        else
483                        {
484                                echo '<h2>'.lang('For correct instalation of Expresso Livre, the LDAP MUST be installed !!')."</h2>\n";
485                                echo '<h3><a href="manageheader.php">'.lang('Continue to the Header Admin')."</a></h3>\n";
486                        }
487                }
488                else
489                {
490                        echo '<h3>';
491                        if (!$Ok)
492                        {
493                                echo lang('Please fix the above errors (%1) and warnings(%2)',$error_icon,$warning_icon).'. ';
494                        }
495                        echo '<br><a href="'.str_replace('check_install.php','',$_SERVER['HTTP_REFERER']).'">'.lang('Return to Setup')."</a></h3>\n";
496                }
497                $setup_tpl->pparse('out','T_footer');
498        }
499?>
Note: See TracBrowser for help on using the repository browser.