]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - install/installSystemCheck.php
Release 6.5.16
[Github/sugarcrm.git] / install / installSystemCheck.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39 $_SESSION['setup_license_accept'] = true;
40
41 function runCheck($install_script = false, $mod_strings){
42 installLog("Begin System Check Process *************");
43
44 if( !isset( $install_script ) || !$install_script ){
45     installLog("Error:: ".$mod_strings['ERR_NO_DIRECT_SCRIPT']);
46     die($mod_strings['ERR_NO_DIRECT_SCRIPT']);
47 }
48
49 if(!defined('SUGARCRM_MIN_MEM')) {
50     define('SUGARCRM_MIN_MEM', 40);
51 }
52
53
54
55 // for keeping track of whether to enable/disable the 'Next' button
56 $error_found = false;
57 $error_txt = '';
58
59
60 // check IIS and FastCGI
61 $server_software = $_SERVER["SERVER_SOFTWARE"];
62 if ((strpos($_SERVER["SERVER_SOFTWARE"],'Microsoft-IIS') !== false)
63     && php_sapi_name() == 'cgi-fcgi'
64     && ini_get('fastcgi.logging') != '0')
65 {
66     installLog($mod_strings['ERR_CHECKSYS_FASTCGI_LOGGING']);
67     $iisVersion = "<b><span class=stop>{$mod_strings['ERR_CHECKSYS_FASTCGI_LOGGING']}</span></b>";
68     $error_found = true;
69     $error_txt .= '
70           <tr>
71             <td><b>'.$mod_strings['LBL_CHECKSYS_FASTCGI'].'</b></td>
72             <td ><span class="error">'.$iisVersion.'</span></td>
73           </tr>';
74 }
75
76 if(strpos($server_software,'Microsoft-IIS') !== false)
77 {
78         $iis_version = '';
79         if(preg_match_all("/^.*\/(\d+\.?\d*)$/",  $server_software, $out))
80         $iis_version = $out[1][0];
81
82         $check_iis_version_result = check_iis_version($iis_version);
83         if($check_iis_version_result == -1) {
84                 installLog($mod_strings['ERR_CHECKSYS_IIS_INVALID_VER'].' '.$iis_version);
85         $iisVersion = "<b><span class=stop>{$mod_strings['ERR_CHECKSYS_IIS_INVALID_VER']} {$iis_version}</span></b>";
86                 $error_found = true;
87         $error_txt .= '
88           <tr>
89             <td><b>'.$mod_strings['LBL_CHECKSYS_IISVER'].'</b></td>
90             <td ><span class="error">'.$iisVersion.'</span></td>
91           </tr>';
92         } else if(php_sapi_name() != 'cgi-fcgi')
93         {
94                 installLog($mod_strings['ERR_CHECKSYS_FASTCGI'].' '.$iis_version);
95                 $iisVersion = "<b><span class=stop>{$mod_strings['ERR_CHECKSYS_FASTCGI']}</span></b>";
96                 $error_found = true;
97         $error_txt .= '
98           <tr>
99             <td><b>'.$mod_strings['LBL_CHECKSYS_FASTCGI'].'</b></td>
100             <td ><span class="error">'.$iisVersion.'</span></td>
101           </tr>';
102         } else if(ini_get('fastcgi.logging') != '0')
103     {
104         installLog($mod_strings['ERR_CHECKSYS_FASTCGI_LOGGING'].' '.$iis_version);
105                 $iisVersion = "<b><span class=stop>{$mod_strings['ERR_CHECKSYS_FASTCGI_LOGGING']}</span></b>";
106                 $error_found = true;
107         $error_txt .= '
108           <tr>
109             <td><b>'.$mod_strings['LBL_CHECKSYS_FASTCGI'].'</b></td>
110             <td ><span class="error">'.$iisVersion.'</span></td>
111           </tr>';
112     }
113 }
114
115 // PHP VERSION
116 $php_version = constant('PHP_VERSION');
117 $check_php_version_result = check_php_version($php_version);
118
119 if($check_php_version_result == -1) {
120         installLog($mod_strings['ERR_CHECKSYS_PHP_INVALID_VER'].'  '.$php_version);
121         $phpVersion = "<b><span class=stop>{$mod_strings['ERR_CHECKSYS_PHP_INVALID_VER']} {$php_version} )</span></b>";
122         $error_found = true;
123         $error_txt .= '
124           <tr>
125             <td><b>'.$mod_strings['LBL_CHECKSYS_PHPVER'].'</b></td>
126             <td ><span class="error">'.$phpVersion.'</span></td>
127           </tr>';
128
129 }
130
131 //Php Backward compatibility checks
132 if(ini_get("zend.ze1_compatibility_mode")) {
133     installLog($mod_strings['LBL_BACKWARD_COMPATIBILITY_ON'].'  '.'Php Backward Compatibility');
134     $phpCompatibility = "<b><span class=stop>{$mod_strings['LBL_BACKWARD_COMPATIBILITY_ON']}</span></b>";
135     $error_found = true;
136     $error_txt .= '
137       <tr>
138         <td><b>Php Backward Compatibility</b></td>
139         <td ><span class="error">'.$phpCompatibility.'</span></td>
140       </tr>';
141
142 }
143
144 // database and connect
145
146 if (!empty($_REQUEST['setup_db_type']))
147     $_SESSION['setup_db_type'] = $_REQUEST['setup_db_type'];
148
149 $drivers = DBManagerFactory::getDbDrivers();
150
151 if( empty($drivers) ){
152     $db_name = $mod_strings['LBL_DB_UNAVAILABLE'];
153     installLog("ERROR:: {$mod_strings['LBL_CHECKSYS_DB_SUPPORT_NOT_AVAILABLE']}");
154     $dbStatus = "<b><span class=stop>{$mod_strings['LBL_CHECKSYS_DB_SUPPORT_NOT_AVAILABLE']}</span></b>";
155     $error_found = true;
156     $error_txt .= '
157       <tr>
158         <td><strong>'.$db_name.'</strong></td>
159         <td class="error">'.$dbStatus.'</td>
160       </tr>';
161 }
162
163 // XML Parsing
164 if(!function_exists('xml_parser_create')) {
165     $xmlStatus = "<b><span class=stop>{$mod_strings['LBL_CHECKSYS_XML_NOT_AVAILABLE']}</span></b>";
166     installLog("ERROR:: {$mod_strings['LBL_CHECKSYS_XML_NOT_AVAILABLE']}");
167     $error_found = true;
168     $error_txt .= '
169       <tr>
170         <td><strong>'.$mod_strings['LBL_CHECKSYS_XML'].'</strong></td>
171         <td class="error">'.$xmlStatus.'</td>
172       </tr>';
173 }else{
174     installLog("XML Parsing Support Found");
175 }
176
177
178 // mbstrings
179 if(!function_exists('mb_strlen')) {
180     $mbstringStatus = "<b><span class=stop>{$mod_strings['ERR_CHECKSYS_MBSTRING']}</font></b>";
181     installLog("ERROR:: {$mod_strings['ERR_CHECKSYS_MBSTRING']}");
182     $error_found = true;
183     $error_txt .= '
184       <tr>
185         <td><strong>'.$mod_strings['LBL_CHECKSYS_MBSTRING'].'</strong></td>
186         <td class="error">'.$mbstringStatus.'</td>
187       </tr>';
188 }else{
189     installLog("MBString Support Found");
190 }
191
192 // zip
193 if(!class_exists('ZipArchive')) {
194     $zipStatus = "<b><span class=stop>{$mod_strings['ERR_CHECKSYS_ZIP']}</font></b>";
195     installLog("ERROR:: {$mod_strings['ERR_CHECKSYS_ZIP']}");
196 }else{
197     installLog("ZIP Support Found");
198 }
199
200 // config.php
201 if(file_exists('./config.php') && (!(make_writable('./config.php')) ||  !(is_writable('./config.php')))) {
202     installLog("ERROR:: {$mod_strings['ERR_CHECKSYS_CONFIG_NOT_WRITABLE']}");
203     $configStatus = "<b><span class='stop'>{$mod_strings['ERR_CHECKSYS_CONFIG_NOT_WRITABLE']}</span></b>";
204     $error_found = true;
205     $error_txt .= '
206       <tr>
207         <td><strong>'.$mod_strings['LBL_CHECKSYS_CONFIG'].'</strong></td>
208         <td class="error">'.$configStatus.'</td>
209       </tr>';
210 }
211
212 // config_override.php
213 if(file_exists('./config_override.php') && (!(make_writable('./config_override.php')) ||  !(is_writable('./config_override.php')))) {
214     installLog("ERROR:: {$mod_strings['ERR_CHECKSYS_CONFIG_OVERRIDE_NOT_WRITABLE']}");
215     $configStatus = "<b><span class='stop'>{$mod_strings['ERR_CHECKSYS_CONFIG_OVERRIDE_NOT_WRITABLE']}</span></b>";
216     $error_found = true;
217     $error_txt .= '
218       <tr>
219         <td><strong>'.$mod_strings['LBL_CHECKSYS_OVERRIDE_CONFIG'].'</strong></td>
220         <td class="error">'.$configStatus.'</td>
221       </tr>';
222 }
223
224 // custom dir
225 if(!make_writable('./custom')) {
226     $customStatus = "<b><span class='stop'>{$mod_strings['ERR_CHECKSYS_CUSTOM_NOT_WRITABLE']}</font></b>";
227     installLog("ERROR:: {$mod_strings['ERR_CHECKSYS_CUSTOM_NOT_WRITABLE']}");
228     $error_found = true;
229     $error_txt .= '
230       <tr>
231         <td><strong>'.$mod_strings['LBL_CHECKSYS_CUSTOM'].'</strong></td>
232         <td class="error">'.$customStatus.'</td>
233       </tr>';
234 }else{
235  installLog("/custom directory and subdirectory check passed");
236 }
237
238
239 // cache dir
240     $cache_files[] = '';
241     $cache_files[] = 'images';
242     $cache_files[] = 'layout';
243     $cache_files[] = 'pdf';
244     $cache_files[] = 'xml';
245     $cache_files[] = 'include/javascript';
246     $filelist = '';
247
248         foreach($cache_files as $c_file)
249         {
250                 $dirname = sugar_cached($c_file);
251                 $ok = false;
252                 if ((is_dir($dirname)) || @sugar_mkdir($dirname,0555)) // set permissions to restrictive - use make_writable to change in a standard way to the required permissions
253                 {
254                         $ok = make_writable($dirname);
255                 }
256                 if (!$ok)
257                 {
258                         $filelist .= '<br>'.getcwd()."/$dirname";
259
260                 }
261         }
262         if (strlen($filelist)>0)
263         {
264             $error_found = true;
265         installLog("ERROR:: Some subdirectories in cache subfolder were not read/writeable:");
266         installLog($filelist);
267             $error_txt .= '
268                 <tr>
269                 <td><strong>'.$mod_strings['LBL_CHECKSYS_CACHE'].'</strong></td>
270                 <td align="right" class="error" class="error"><b><span class="stop">'.$mod_strings['ERR_CHECKSYS_FILES_NOT_WRITABLE'].'</span></b></td>
271                 </tr>
272                 <tr>
273                 <td colspan="2"><b>'.$mod_strings['LBL_CHECKSYS_FIX_FILES'].'</b>'.$filelist. '</td>
274                 </tr>';
275         }else{
276      installLog("cache directory and subdirectory check passed");
277     }
278
279
280 // check modules dir
281 $_SESSION['unwriteable_module_files'] = array();
282 //if(!$writeableFiles['ret_val']) {
283 $passed_write = recursive_make_writable('./modules');
284 if (isset($_SESSION['unwriteable_module_files']['failed']) && $_SESSION['unwriteable_module_files']['failed']){
285     $passed_write = false;
286 }
287
288 if(!$passed_write) {
289
290     $moduleStatus = "<b><span class='stop'>{$mod_strings['ERR_CHECKSYS_NOT_WRITABLE']}</span></b>";
291     installLog("ERROR:: Module directories and the files under them are not writeable.");
292     $error_found = true;
293     $error_txt .= '
294       <tr>
295         <td><strong>'.$mod_strings['LBL_CHECKSYS_MODULE'].'</strong></td>
296         <td align="right" class="error">'.$moduleStatus.'</td>
297       </tr>';
298
299         //list which module directories are not writeable, if there are less than 10
300         $error_txt .= '
301           <tr>
302             <td colspan="2">
303             <b>'.$mod_strings['LBL_CHECKSYS_FIX_MODULE_FILES'].'</b>';
304         foreach($_SESSION['unwriteable_module_files'] as $key=>$file){
305             if($key !='.' && $key != 'failed'){
306                 $error_txt .='<br>'.$file;
307             }
308         }
309         $error_txt .= '
310             </td>
311           </tr>';
312
313 }else{
314  installLog("/module  directory and subdirectory check passed");
315 }
316
317 // check upload dir
318 if (!make_writable('./upload'))
319 {
320     $uploadStatus = "<b><span class='stop'>{$mod_strings['ERR_CHECKSYS_NOT_WRITABLE']}</span></b>";
321     installLog("ERROR: Upload directory is not writable.");
322     $error_found = true;
323     $error_txt .= '
324     <tr>
325         <td><strong>'.$mod_strings['LBL_CHECKSYS_UPLOAD'].'</strong></td>
326         <td align="right" class="error">'.$uploadStatus.'</td>
327     </tr>';
328 } else {
329     installLog("/upload directory check passed");
330 }
331
332 // check zip file support
333 if (!class_exists("ZipArchive"))
334 {
335         $zipStatus = "<span class='stop'><b>{$mod_strings['ERR_CHECKSYS_ZIP']}</b></span>";
336
337     installLog("ERROR: Zip support not found.");
338     $error_found = true;
339     $error_txt .= '
340           <tr>
341             <td><strong>'.$mod_strings['LBL_CHECKSYS_ZIP'].'</strong></td>
342             <td  align="right" class="error">'.$zipStatus.'</td>
343           </tr>';
344 } else {
345     installLog("/zip check passed");
346
347 }
348
349
350 // check PCRE version
351 if (defined('PCRE_VERSION'))
352 {
353     if (version_compare(PCRE_VERSION, '7.0') < 0) {
354         installLog("ERROR: PCRE Version is less than 7.0.");
355         $error_found = true;
356         $pcreStatus = "<span class='stop'><b>{$mod_strings['ERR_CHECKSYS_PCRE_VER']}</b></span>";
357         $error_txt .= '
358           <tr>
359             <td><strong>'.$mod_strings['LBL_CHECKSYS_PCRE'].'</strong></td>
360             <td  align="right" class="error">'.$pcreStatus.'</td>
361           </tr>';
362     }
363     else {
364         installLog("PCRE version check passed");
365     }
366 }
367 else {
368     installLog("ERROR: PCRE not found.");
369     $error_found = true;
370     $pcreStatus = "<span class='stop'><b>{$mod_strings['ERR_CHECKSYS_PCRE']}</b></span>";
371     $error_txt .= '
372       <tr>
373         <td><strong>'.$mod_strings['LBL_CHECKSYS_PCRE'].'</strong></td>
374         <td  align="right" class="error">'.$pcreStatus.'</td>
375       </tr>';
376 }
377
378
379 $customSystemChecks = installerHook('additionalCustomSystemChecks');
380 if($customSystemChecks != 'undefined'){
381         if($customSystemChecks['error_found'] == true){
382                 $error_found = true;
383         }
384         if(!empty($customSystemChecks['error_txt'])){
385                 $error_txt .= $customSystemChecks['error_txt'];
386         }
387 }
388
389 // PHP.ini
390 $phpIniLocation = get_cfg_var("cfg_file_path");
391 installLog("php.ini location found. {$phpIniLocation}");
392 // disable form if error found
393
394 if($error_found){
395     installLog("Outputting HTML for System check");
396     installLog("Errors were found *************");
397     $disabled = $error_found ? 'disabled="disabled"' : '';
398
399     $help_url = get_help_button_url();
400 ///////////////////////////////////////////////////////////////////////////////
401 ////    BEGIN PAGE OUTPUT
402     $out =<<<EOQ
403
404   <table cellspacing="0" cellpadding="0" border="0" align="center" class="shell">
405     <tr>
406       <th width="400">{$mod_strings['LBL_CHECKSYS_TITLE']}</th>
407       <th width="200" height="30" style="text-align: right;"><a href="http://www.sugarcrm.com" target=
408       "_blank"><IMG src="include/images/sugarcrm_login.png" alt="SugarCRM" border="0"></a>
409        <br><a href="{$help_url}" target='_blank'>{$mod_strings['LBL_HELP']} </a>
410        </th>
411     </tr>
412
413     <tr>
414       <td colspan="2" width="600">
415         <p>{$mod_strings['ERR_CHECKSYS']}</p>
416
417         <table cellpadding="0" cellspacing="0" border="0" width="100%" class="StyleDottedHr">
418           <tr>
419             <th align="left">{$mod_strings['LBL_CHECKSYS_COMPONENT']}</th>
420             <th style="text-align: right;">{$mod_strings['LBL_CHECKSYS_STATUS']}</th>
421           </tr>
422             $error_txt
423
424         </table>
425
426         <div align="center" style="margin: 5px;">
427           <i>{$mod_strings['LBL_CHECKSYS_PHP_INI']}<br>{$phpIniLocation}</i>
428         </div>
429       </td>
430     </tr>
431
432     <tr>
433       <td align="right" colspan="2">
434         <hr>
435         <form action="install3.php" method="post" name="theForm" id="theForm">
436
437         <table cellspacing="0" cellpadding="0" border="0" class="stdTable">
438           <tr>
439             <td><input class="button" type="button" onclick="window.open('http://www.sugarcrm.com/forums/');" value="{$mod_strings['LBL_HELP']}" /></td>
440             <td>
441                 <input class="button" type="button" name="Re-check" value="{$mod_strings['LBL_CHECKSYS_RECHECK']}" onclick="callSysCheck();" id="button_next2"/>
442             </td>
443           </tr>
444         </table>
445         </form>
446       </td>
447     </tr>
448   </table><br>
449 EOQ;
450 return $out;
451 }else{
452     installLog("Outputting HTML for System check");
453     installLog("No Errors were found *************");
454  return 'passed';
455 }
456
457 }
458 ////    END PAGEOUTPUT
459 ///////////////////////////////////////////////////////////////////////////////
460 ?>