PageRenderTime 26ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/UpgradeWizard/systemCheck.php

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