]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/UpgradeWizard/systemCheck.php
Release 6.4.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-2011 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         'mysqlVersion'                          => $mod_strings['LBL_UW_COMPLIANCE_MYSQL'],
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         //commenting mbstring overload.
170         //'mbstring.func_overload'      => $mod_strings['LBL_UW_COMPLIANCE_MBSTRING_FUNC_OVERLOAD'],
171 );
172 if($result['error_found'] == true) {
173         $stop = true;
174         $phpIniLocation = get_cfg_var("cfg_file_path");
175
176         $sysCompliance  = "<a href='javascript:void(0); toggleNwFiles(\"sysComp\");'>{$mod_strings['LBL_UW_SHOW_COMPLIANCE']}</a>";
177         $sysCompliance .= "<div id='sysComp' >";
178         $sysCompliance .= "<table cellpadding='0' cellspacing='0' border='0'>";
179         foreach($result as $k => $v) {
180                 if($k == 'error_found')
181                         continue;
182                 $sysCompliance .= "<tr><td valign='top'>{$checks[$k]}</td>";
183                 $sysCompliance .= "<td valign='top'>{$v}</td></tr>";
184         }
185         $sysCompliance .= "<tr><td valign='top'>{$mod_strings['LBL_UW_COMPLIANCE_PHP_INI']}</td>";
186         $sysCompliance .= "<td valign='top'><b>{$phpIniLocation}</b></td></tr>";
187         $sysCompliance .= "</table></div>";
188 } else {
189         $sysCompliance = "<b>{$mod_strings['LBL_UW_COMPLIANCE_ALL_OK']}</b>";
190 }
191
192 ////    END INSTALLER CHECKS
193 ///////////////////////////////////////////////////////////////////////////////
194
195 ////    stop on all errors
196 foreach($errors as $k => $type) {
197         if(is_array($type) && count($type) > 0) {
198                 foreach($type as $k => $subtype) {
199                         if($subtype == true) {
200                                 $stop = true;
201                         }
202                 }
203         }
204
205         if($type === true) {
206                 logThis('Found errors during system check - disabling forward movement.');
207                 $stop = true;
208         }
209 }
210
211 $GLOBALS['top_message'] = "{$mod_strings['LBL_UW_NEXT_TO_UPLOAD']}";
212 $showBack               = true;
213 $showCancel             = true;
214 $showRecheck    = true;
215 $showNext               = ($stop) ? false : true;
216
217 $stepBack               = $_REQUEST['step'] - 1;
218 $stepNext               = $_REQUEST['step'] + 1;
219 $stepCancel             = -1;
220 $stepRecheck    = $_REQUEST['step'];
221
222 $_SESSION['step'][$steps['files'][$_REQUEST['step']]] = ($stop) ? 'failed' : 'success';
223
224
225 ///////////////////////////////////////////////////////////////////////////////
226 ////    OUTPUT
227
228 $uwMain =<<<eoq
229 <style>
230 .stop {
231         color: #cc0000;
232         }
233 .go {
234         color: #00cc00;
235         }
236
237 </style>
238 <table cellpadding="3" cellspacing="4" border="0">
239         <tr>
240                 <td align="left" valign="top">
241                         {$mod_strings['LBL_UW_FILE_ISSUES_PERMS']}:
242                 </td>
243                 <td>
244                         {$filesOut}
245                 </td>
246         </tr>
247         <tr>
248                 <td colspan="2">
249                         <p>&nbsp;</p>
250                 </td>
251         </tr>
252         <tr>
253                 <td align="left" valign="top">
254                         {$mod_strings['LBL_UW_DB_ISSUES_PERMS']}:
255                 </td>
256                 <td>
257                         {$dbOut}
258                 </td>
259         </tr>
260         <tr>
261                 <td colspan="2">
262                         <p>&nbsp;</p>
263                 </td>
264         </tr>
265         <tr>
266                 <td align="left" valign="top">
267                         {$mod_strings['LBL_UW_COMPLIANCE_TITLE2']}:
268                 </td>
269                 <td>
270                         {$sysCompliance}
271                 </td>
272         </tr>
273 </table>
274 <div id="upgradeDiv" style="display:none">
275     <table border="0" cellspacing="0" cellpadding="0">
276         <tr><td>
277            <p><!--not_in_theme!--><img src='modules/UpgradeWizard/processing.gif' alt='Processing'> <br></p>
278         </td></tr>
279      </table>
280  </div>
281 eoq;
282
283 ?>