]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/UpgradeWizard/systemCheck.php
Release 6.5.0
[Github/sugarcrm.git] / modules / UpgradeWizard / systemCheck.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-2012 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
40  * Description:
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. All Rights
42  * Reserved. Contributor(s): ______________________________________..
43  * *******************************************************************************/
44 logThis('[At systemCheck.php]');
45
46 $stop = false; // flag to prevent going to next step
47
48 ///////////////////////////////////////////////////////////////////////////////
49 ////    FILE CHECKS
50 logThis('Starting file permission check...');
51 $filesNotWritable = array();
52 $filesNWPerms = array();
53
54 // add directories here that should be skipped when doing file permissions checks (cache/upload is the nasty one)
55 $skipDirs = array(
56         $sugar_config['upload_dir'],
57         '.svn',
58 );
59 $files = uwFindAllFiles(getcwd(), array(), true, $skipDirs);
60
61 $i=0;
62 $filesOut = "
63         <a href='javascript:void(0); toggleNwFiles(\"filesNw\");'>{$mod_strings['LBL_UW_SHOW_NW_FILES']}</a>
64         <div id='filesNw' style='display:none;'>
65         <table cellpadding='3' cellspacing='0' border='0'>
66         <tr>
67                 <th align='left'>{$mod_strings['LBL_UW_FILE']}</th>
68                 <th align='left'>{$mod_strings['LBL_UW_FILE_PERMS']}</th>
69                 <th align='left'>{$mod_strings['LBL_UW_FILE_OWNER']}</th>
70                 <th align='left'>{$mod_strings['LBL_UW_FILE_GROUP']}</th>
71         </tr>";
72
73 $isWindows = is_windows();
74 foreach($files as $file) {
75         if($isWindows) {
76                 if(!is_writable_windows($file)) {
77                         logThis('WINDOWS: File ['.$file.'] not readable - saving for display');
78                         // don't warn yet - we're going to use this to check against replacement files
79                         $filesNotWritable[$i] = $file;
80                         $filesNWPerms[$i] = substr(sprintf('%o',fileperms($file)), -4);
81                         $filesOut .= "<tr>".
82                                                         "<td><span class='error'>{$file}</span></td>".
83                                                         "<td>{$filesNWPerms[$i]}</td>".
84                                                         "<td>".$mod_strings['ERR_UW_CANNOT_DETERMINE_USER']."</td>".
85                                                         "<td>".$mod_strings['ERR_UW_CANNOT_DETERMINE_GROUP']."</td>".
86                                                   "</tr>";
87                 }
88         } else {
89                 if(!is_writable($file)) {
90                         logThis('File ['.$file.'] not writable - saving for display');
91                         // don't warn yet - we're going to use this to check against replacement files
92                         $filesNotWritable[$i] = $file;
93                         $filesNWPerms[$i] = substr(sprintf('%o',fileperms($file)), -4);
94                         $owner = posix_getpwuid(fileowner($file));
95                         $group = posix_getgrgid(filegroup($file));
96                         $filesOut .= "<tr>".
97                                                         "<td><span class='error'>{$file}</span></td>".
98                                                         "<td>{$filesNWPerms[$i]}</td>".
99                                                         "<td>".$owner['name']."</td>".
100                                                         "<td>".$group['name']."</td>".
101                                                   "</tr>";
102                 }
103         }
104         $i++;
105 }
106
107 $filesOut .= '</table></div>';
108 // not a stop error
109 $errors['files']['filesNotWritable'] = (count($filesNotWritable) > 0) ? true : false;
110 if(count($filesNotWritable) < 1) {
111         $filesOut = "<b>{$mod_strings['LBL_UW_FILE_NO_ERRORS']}</b>";
112 }
113
114 logThis('Finished file permission check.');
115 ////    END FILE CHECKS
116 ///////////////////////////////////////////////////////////////////////////////
117
118 ///////////////////////////////////////////////////////////////////////////////
119 ////    DATABASE CHECKS
120 logThis('Starting database permissions check...');
121 $dbOut = "
122         <a href='javascript:void(0); toggleNwFiles(\"dbPerms\");'>{$mod_strings['LBL_UW_SHOW_DB_PERMS']}</a>
123         <div id='dbPerms' style='display:none;'>
124         <table cellpadding='3' cellspacing='0' border='0'>
125         <tr>
126                 <th align='left'>{$mod_strings['LBL_UW_DB_PERMS']}</th>
127         </tr>";
128
129 $db = DBManagerFactory::getInstance();
130 $outs = array();
131 $outs['skip'] = false;
132 $outs['db'] = array();
133 $outs['dbOut'] = $dbOut;
134 $outs = testPermsCreate($db, $outs);
135 $outs = testPermsInsert($db, $outs, $outs['skip']);
136 $outs = testPermsUpdate($db, $outs, $outs['skip']);
137 $outs = testPermsSelect($db, $outs, $outs['skip']);
138 $outs = testPermsDelete($db, $outs, $outs['skip']);
139 $outs = testPermsAlterTableAdd($db, $outs, $outs['skip']);
140 $outs = testPermsAlterTableChange($db, $outs, $outs['skip']);
141 $outs = testPermsAlterTableDrop($db, $outs, $outs['skip']);
142 $outs = testPermsDropTable($db, $outs, $outs['skip']);
143 $outs['dbOut'] .= '</table>';
144
145
146 if(count($outs['db']) < 1) {
147         logThis('No permissions errors found!');
148         $outs['dbOut'] = "<b>".$mod_strings['LBL_UW_DB_NO_ERRORS']."</b>";
149 }
150 logThis('Finished database permissions check.');
151 $dbOut = $outs['dbOut'];
152 ////    END DATABASE CHECKS
153 ///////////////////////////////////////////////////////////////////////////////
154
155
156 ///////////////////////////////////////////////////////////////////////////////
157 ////    INSTALLER TYPE CHECKS
158 $result = checkSystemCompliance();
159 $checks = array(
160         'phpVersion'                            => $mod_strings['LBL_UW_COMPLIANCE_PHP_VERSION'],
161     'dbVersion'                 => $mod_strings['LBL_UW_COMPLIANCE_DB'],
162         'xmlStatus'                                     => $mod_strings['LBL_UW_COMPLIANCE_XML'],
163         'curlStatus'                            => $mod_strings['LBL_UW_COMPLIANCE_CURL'],
164         'imapStatus'                            => $mod_strings['LBL_UW_COMPLIANCE_IMAP'],
165         'mbstringStatus'                        => $mod_strings['LBL_UW_COMPLIANCE_MBSTRING'],
166         'safeModeStatus'                        => $mod_strings['LBL_UW_COMPLIANCE_SAFEMODE'],
167         'callTimeStatus'                        => $mod_strings['LBL_UW_COMPLIANCE_CALLTIME'],
168         'memory_msg'                            => $mod_strings['LBL_UW_COMPLIANCE_MEMORY'],
169     'ZipStatus'                         => $mod_strings['LBL_UW_COMPLIANCE_ZIPARCHIVE'],
170         //commenting mbstring overload.
171         //'mbstring.func_overload'      => $mod_strings['LBL_UW_COMPLIANCE_MBSTRING_FUNC_OVERLOAD'],
172 );
173 if($result['error_found'] == true) {
174         $stop = true;
175         $phpIniLocation = get_cfg_var("cfg_file_path");
176
177         $sysCompliance  = "<a href='javascript:void(0); toggleNwFiles(\"sysComp\");'>{$mod_strings['LBL_UW_SHOW_COMPLIANCE']}</a>";
178         $sysCompliance .= "<div id='sysComp' >";
179         $sysCompliance .= "<table cellpadding='0' cellspacing='0' border='0'>";
180         foreach($result as $k => $v) {
181                 if($k == 'error_found')
182                         continue;
183                 $sysCompliance .= "<tr><td valign='top'>{$checks[$k]}</td>";
184                 $sysCompliance .= "<td valign='top'>{$v}</td></tr>";
185         }
186         $sysCompliance .= "<tr><td valign='top'>{$mod_strings['LBL_UW_COMPLIANCE_PHP_INI']}</td>";
187         $sysCompliance .= "<td valign='top'><b>{$phpIniLocation}</b></td></tr>";
188         $sysCompliance .= "</table></div>";
189 } else {
190         $sysCompliance = "<b>{$mod_strings['LBL_UW_COMPLIANCE_ALL_OK']}</b>";
191 }
192
193 ////    END INSTALLER CHECKS
194 ///////////////////////////////////////////////////////////////////////////////
195
196 ////    stop on all errors
197 foreach($errors as $k => $type) {
198         if(is_array($type) && count($type) > 0) {
199                 foreach($type as $k => $subtype) {
200                         if($subtype == true) {
201                                 $stop = true;
202                         }
203                 }
204         }
205
206         if($type === true) {
207                 logThis('Found errors during system check - disabling forward movement.');
208                 $stop = true;
209         }
210 }
211
212 $GLOBALS['top_message'] = "{$mod_strings['LBL_UW_NEXT_TO_UPLOAD']}";
213 $showBack               = true;
214 $showCancel             = true;
215 $showRecheck    = true;
216 $showNext               = ($stop) ? false : true;
217
218 $stepBack               = $_REQUEST['step'] - 1;
219 $stepNext               = $_REQUEST['step'] + 1;
220 $stepCancel             = -1;
221 $stepRecheck    = $_REQUEST['step'];
222
223 $_SESSION['step'][$steps['files'][$_REQUEST['step']]] = ($stop) ? 'failed' : 'success';
224
225
226 ///////////////////////////////////////////////////////////////////////////////
227 ////    OUTPUT
228
229 $uwMain =<<<eoq
230 <style>
231 .stop {
232         color: #cc0000;
233         }
234 .go {
235         color: #00cc00;
236         }
237
238 </style>
239 <table cellpadding="3" cellspacing="4" border="0">
240         <tr>
241                 <td align="left" valign="top">
242                         {$mod_strings['LBL_UW_FILE_ISSUES_PERMS']}:
243                 </td>
244                 <td>
245                         {$filesOut}
246                 </td>
247         </tr>
248         <tr>
249                 <td colspan="2">
250                         <p>&nbsp;</p>
251                 </td>
252         </tr>
253         <tr>
254                 <td align="left" valign="top">
255                         {$mod_strings['LBL_UW_DB_ISSUES_PERMS']}:
256                 </td>
257                 <td>
258                         {$dbOut}
259                 </td>
260         </tr>
261         <tr>
262                 <td colspan="2">
263                         <p>&nbsp;</p>
264                 </td>
265         </tr>
266         <tr>
267                 <td align="left" valign="top">
268                         {$mod_strings['LBL_UW_COMPLIANCE_TITLE2']}:
269                 </td>
270                 <td>
271                         {$sysCompliance}
272                 </td>
273         </tr>
274 </table>
275 <div id="upgradeDiv" style="display:none">
276     <table border="0" cellspacing="0" cellpadding="0">
277         <tr><td>
278            <p><!--not_in_theme!--><img src='modules/UpgradeWizard/processing.gif' alt='Processing'> <br></p>
279         </td></tr>
280      </table>
281  </div>
282 eoq;
283
284 ?>