PageRenderTime 51ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/UpgradeWizard/systemCheck.php

https://gitlab.com/tjaafar/SuiteCRM
PHP | 289 lines | 199 code | 26 blank | 64 comment | 18 complexity | 4063dd645437b5a2545e3a315ba4fd78 MD5 | raw file
  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. * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
  7. * Copyright (C) 2011 - 2014 Salesagility Ltd.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it under
  10. * the terms of the GNU Affero General Public License version 3 as published by the
  11. * Free Software Foundation with the addition of the following permission added
  12. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  13. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  14. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  15. *
  16. * This program is distributed in the hope that it will be useful, but WITHOUT
  17. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  18. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  19. * details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License along with
  22. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  23. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  24. * 02110-1301 USA.
  25. *
  26. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  27. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  28. *
  29. * The interactive user interfaces in modified source and object code versions
  30. * of this program must display Appropriate Legal Notices, as required under
  31. * Section 5 of the GNU Affero General Public License version 3.
  32. *
  33. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  34. * these Appropriate Legal Notices must retain the display of the "Powered by
  35. * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
  36. * reasonably feasible for technical reasons, the Appropriate Legal Notices must
  37. * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
  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. $stop = false; // flag to prevent going to next step
  46. ///////////////////////////////////////////////////////////////////////////////
  47. //// FILE CHECKS
  48. logThis('Starting file permission check...');
  49. $filesNotWritable = array();
  50. $filesNWPerms = array();
  51. // add directories here that should be skipped when doing file permissions checks (cache/upload is the nasty one)
  52. $skipDirs = array(
  53. $sugar_config['upload_dir'],
  54. '.svn',
  55. );
  56. $files = uwFindAllFiles(getcwd(), array(), true, $skipDirs);
  57. $i=0;
  58. $filesOut = "
  59. <a href='javascript:void(0); toggleNwFiles(\"filesNw\");'>{$mod_strings['LBL_UW_SHOW_NW_FILES']}</a>
  60. <div id='filesNw' style='display:none;'>
  61. <table cellpadding='3' cellspacing='0' border='0'>
  62. <tr>
  63. <th align='left'>{$mod_strings['LBL_UW_FILE']}</th>
  64. <th align='left'>{$mod_strings['LBL_UW_FILE_PERMS']}</th>
  65. <th align='left'>{$mod_strings['LBL_UW_FILE_OWNER']}</th>
  66. <th align='left'>{$mod_strings['LBL_UW_FILE_GROUP']}</th>
  67. </tr>";
  68. $isWindows = is_windows();
  69. foreach($files as $file) {
  70. if($isWindows) {
  71. if(!is_writable_windows($file)) {
  72. logThis('WINDOWS: File ['.$file.'] not readable - saving for display');
  73. // don't warn yet - we're going to use this to check against replacement files
  74. $filesNotWritable[$i] = $file;
  75. $filesNWPerms[$i] = substr(sprintf('%o',fileperms($file)), -4);
  76. $filesOut .= "<tr>".
  77. "<td><span class='error'>{$file}</span></td>".
  78. "<td>{$filesNWPerms[$i]}</td>".
  79. "<td>".$mod_strings['ERR_UW_CANNOT_DETERMINE_USER']."</td>".
  80. "<td>".$mod_strings['ERR_UW_CANNOT_DETERMINE_GROUP']."</td>".
  81. "</tr>";
  82. }
  83. } else {
  84. if(!is_writable($file)) {
  85. logThis('File ['.$file.'] not writable - saving for display');
  86. // don't warn yet - we're going to use this to check against replacement files
  87. $filesNotWritable[$i] = $file;
  88. $filesNWPerms[$i] = substr(sprintf('%o',fileperms($file)), -4);
  89. $owner = posix_getpwuid(fileowner($file));
  90. $group = posix_getgrgid(filegroup($file));
  91. $filesOut .= "<tr>".
  92. "<td><span class='error'>{$file}</span></td>".
  93. "<td>{$filesNWPerms[$i]}</td>".
  94. "<td>".$owner['name']."</td>".
  95. "<td>".$group['name']."</td>".
  96. "</tr>";
  97. }
  98. }
  99. $i++;
  100. }
  101. $filesOut .= '</table></div>';
  102. // not a stop error
  103. $errors['files']['filesNotWritable'] = (count($filesNotWritable) > 0) ? true : false;
  104. if(count($filesNotWritable) < 1) {
  105. $filesOut = "<b>{$mod_strings['LBL_UW_FILE_NO_ERRORS']}</b>";
  106. }
  107. logThis('Finished file permission check.');
  108. //// END FILE CHECKS
  109. ///////////////////////////////////////////////////////////////////////////////
  110. ///////////////////////////////////////////////////////////////////////////////
  111. //// DATABASE CHECKS
  112. logThis('Starting database permissions check...');
  113. $dbOut = "
  114. <a href='javascript:void(0); toggleNwFiles(\"dbPerms\");'>{$mod_strings['LBL_UW_SHOW_DB_PERMS']}</a>
  115. <div id='dbPerms' style='display:none;'>
  116. <table cellpadding='3' cellspacing='0' border='0'>
  117. <tr>
  118. <th align='left'>{$mod_strings['LBL_UW_DB_PERMS']}</th>
  119. </tr>";
  120. $db = DBManagerFactory::getInstance();
  121. $outs = array();
  122. $outs['skip'] = false;
  123. $outs['db'] = array();
  124. $outs['dbOut'] = $dbOut;
  125. $outs = testPermsCreate($db, $outs);
  126. $outs = testPermsInsert($db, $outs, $outs['skip']);
  127. $outs = testPermsUpdate($db, $outs, $outs['skip']);
  128. $outs = testPermsSelect($db, $outs, $outs['skip']);
  129. $outs = testPermsDelete($db, $outs, $outs['skip']);
  130. $outs = testPermsAlterTableAdd($db, $outs, $outs['skip']);
  131. $outs = testPermsAlterTableChange($db, $outs, $outs['skip']);
  132. $outs = testPermsAlterTableDrop($db, $outs, $outs['skip']);
  133. $outs = testPermsDropTable($db, $outs, $outs['skip']);
  134. $outs['dbOut'] .= '</table>';
  135. if(count($outs['db']) < 1) {
  136. logThis('No permissions errors found!');
  137. $outs['dbOut'] = "<b>".$mod_strings['LBL_UW_DB_NO_ERRORS']."</b>";
  138. }
  139. logThis('Finished database permissions check.');
  140. $dbOut = $outs['dbOut'];
  141. //// END DATABASE CHECKS
  142. ///////////////////////////////////////////////////////////////////////////////
  143. ///////////////////////////////////////////////////////////////////////////////
  144. //// INSTALLER TYPE CHECKS
  145. $result = checkSystemCompliance();
  146. $checks = array(
  147. 'phpVersion' => $mod_strings['LBL_UW_COMPLIANCE_PHP_VERSION'],
  148. 'dbVersion' => $mod_strings['LBL_UW_COMPLIANCE_DB'],
  149. 'xmlStatus' => $mod_strings['LBL_UW_COMPLIANCE_XML'],
  150. 'curlStatus' => $mod_strings['LBL_UW_COMPLIANCE_CURL'],
  151. 'imapStatus' => $mod_strings['LBL_UW_COMPLIANCE_IMAP'],
  152. 'mbstringStatus' => $mod_strings['LBL_UW_COMPLIANCE_MBSTRING'],
  153. 'safeModeStatus' => $mod_strings['LBL_UW_COMPLIANCE_SAFEMODE'],
  154. 'callTimeStatus' => $mod_strings['LBL_UW_COMPLIANCE_CALLTIME'],
  155. 'memory_msg' => $mod_strings['LBL_UW_COMPLIANCE_MEMORY'],
  156. 'stream_msg' => $mod_strings['LBL_UW_COMPLIANCE_STREAM'],
  157. 'ZipStatus' => $mod_strings['LBL_UW_COMPLIANCE_ZIPARCHIVE'],
  158. 'pcreVersion' => $mod_strings['LBL_UW_COMPLIANCE_PCRE_VERSION'],
  159. //commenting mbstring overload.
  160. //'mbstring.func_overload' => $mod_strings['LBL_UW_COMPLIANCE_MBSTRING_FUNC_OVERLOAD'],
  161. );
  162. if($result['error_found'] == true) {
  163. $stop = true;
  164. $phpIniLocation = get_cfg_var("cfg_file_path");
  165. $sysCompliance = "<a href='javascript:void(0); toggleNwFiles(\"sysComp\");'>{$mod_strings['LBL_UW_SHOW_COMPLIANCE']}</a>";
  166. $sysCompliance .= "<div id='sysComp' >";
  167. $sysCompliance .= "<table cellpadding='0' cellspacing='0' border='0'>";
  168. foreach($result as $k => $v) {
  169. if($k == 'error_found')
  170. continue;
  171. $sysCompliance .= "<tr><td valign='top'>{$checks[$k]}</td>";
  172. $sysCompliance .= "<td valign='top'>{$v}</td></tr>";
  173. }
  174. $sysCompliance .= "<tr><td valign='top'>{$mod_strings['LBL_UW_COMPLIANCE_PHP_INI']}</td>";
  175. $sysCompliance .= "<td valign='top'><b>{$phpIniLocation}</b></td></tr>";
  176. $sysCompliance .= "</table></div>";
  177. } else {
  178. $sysCompliance = "<b>{$mod_strings['LBL_UW_COMPLIANCE_ALL_OK']}</b>";
  179. }
  180. //// END INSTALLER CHECKS
  181. ///////////////////////////////////////////////////////////////////////////////
  182. //// stop on all errors
  183. foreach($errors as $k => $type) {
  184. if(is_array($type) && count($type) > 0) {
  185. foreach($type as $k => $subtype) {
  186. if($subtype == true) {
  187. $stop = true;
  188. }
  189. }
  190. }
  191. if($type === true) {
  192. logThis('Found errors during system check - disabling forward movement.');
  193. $stop = true;
  194. }
  195. }
  196. $GLOBALS['top_message'] = "{$mod_strings['LBL_UW_NEXT_TO_UPLOAD']}";
  197. $showBack = true;
  198. $showCancel = true;
  199. $showRecheck = true;
  200. $showNext = ($stop) ? false : true;
  201. $stepBack = $_REQUEST['step'] - 1;
  202. $stepNext = $_REQUEST['step'] + 1;
  203. $stepCancel = -1;
  204. $stepRecheck = $_REQUEST['step'];
  205. $_SESSION['step'][$steps['files'][$_REQUEST['step']]] = ($stop) ? 'failed' : 'success';
  206. ///////////////////////////////////////////////////////////////////////////////
  207. //// OUTPUT
  208. $uwMain =<<<eoq
  209. <style>
  210. .stop {
  211. color: #cc0000;
  212. }
  213. .go {
  214. color: #00cc00;
  215. }
  216. </style>
  217. <table cellpadding="3" cellspacing="4" border="0">
  218. <tr>
  219. <td align="left" valign="top">
  220. {$mod_strings['LBL_UW_FILE_ISSUES_PERMS']}:
  221. </td>
  222. <td>
  223. {$filesOut}
  224. </td>
  225. </tr>
  226. <tr>
  227. <td colspan="2">
  228. <p>&nbsp;</p>
  229. </td>
  230. </tr>
  231. <tr>
  232. <td align="left" valign="top">
  233. {$mod_strings['LBL_UW_DB_ISSUES_PERMS']}:
  234. </td>
  235. <td>
  236. {$dbOut}
  237. </td>
  238. </tr>
  239. <tr>
  240. <td colspan="2">
  241. <p>&nbsp;</p>
  242. </td>
  243. </tr>
  244. <tr>
  245. <td align="left" valign="top">
  246. {$mod_strings['LBL_UW_COMPLIANCE_TITLE2']}:
  247. </td>
  248. <td>
  249. {$sysCompliance}
  250. </td>
  251. </tr>
  252. </table>
  253. <div id="upgradeDiv" style="display:none">
  254. <table border="0" cellspacing="0" cellpadding="0">
  255. <tr><td>
  256. <p><!--not_in_theme!--><img src='modules/UpgradeWizard/processing.gif' alt='Processing'> <br></p>
  257. </td></tr>
  258. </table>
  259. </div>
  260. eoq;
  261. ?>