PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/install/installSystemCheck.php

https://github.com/mikmagic/sugarcrm_dev
PHP | 421 lines | 312 code | 53 blank | 56 comment | 50 complexity | d8b035f439553f09bb2a03a66fd36e4a MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause, AGPL-3.0
  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. $_SESSION['setup_license_accept'] = true;
  38. function runCheck($install_script = false, $mod_strings){
  39. installLog("Begin System Check Process *************");
  40. if( !isset( $install_script ) || !$install_script ){
  41. installLog("Error:: ".$mod_strings['ERR_NO_DIRECT_SCRIPT']);
  42. die($mod_strings['ERR_NO_DIRECT_SCRIPT']);
  43. }
  44. if(!defined('SUGARCRM_MIN_MEM')) {
  45. define('SUGARCRM_MIN_MEM', 40);
  46. }
  47. // for keeping track of whether to enable/disable the 'Next' button
  48. $error_found = false;
  49. $error_txt = '';
  50. // check IIS and FastCGI
  51. $server_software = $_SERVER["SERVER_SOFTWARE"];
  52. if ((strpos($_SERVER["SERVER_SOFTWARE"],'Microsoft-IIS') !== false)
  53. && php_sapi_name() == 'cgi-fcgi'
  54. && ini_get('fastcgi.logging') != '0')
  55. {
  56. installLog($mod_strings['ERR_CHECKSYS_FASTCGI_LOGGING']);
  57. $iisVersion = "<b><span class=stop>{$mod_strings['ERR_CHECKSYS_FASTCGI_LOGGING']}</span></b>";
  58. $error_found = true;
  59. $error_txt .= '
  60. <tr>
  61. <td><b>'.$mod_strings['LBL_CHECKSYS_FASTCGI'].'</b></td>
  62. <td ><span class="error">'.$iisVersion.'</span></td>
  63. </tr>';
  64. }
  65. if(strpos($server_software,'Microsoft-IIS') !== false)
  66. {
  67. $iis_version = '';
  68. if(preg_match_all("/^.*\/(\d+\.?\d*)$/", $server_software, $out))
  69. $iis_version = $out[1][0];
  70. $check_iis_version_result = check_iis_version($iis_version);
  71. if($check_iis_version_result == -1) {
  72. installLog($mod_strings['ERR_CHECKSYS_IIS_INVALID_VER'].' '.$iis_version);
  73. $iisVersion = "<b><span class=stop>{$mod_strings['ERR_CHECKSYS_IIS_INVALID_VER']} {$iis_version}</span></b>";
  74. $error_found = true;
  75. $error_txt .= '
  76. <tr>
  77. <td><b>'.$mod_strings['LBL_CHECKSYS_IISVER'].'</b></td>
  78. <td ><span class="error">'.$iisVersion.'</span></td>
  79. </tr>';
  80. } else if(php_sapi_name() != 'cgi-fcgi')
  81. {
  82. installLog($mod_strings['ERR_CHECKSYS_FASTCGI'].' '.$iis_version);
  83. $iisVersion = "<b><span class=stop>{$mod_strings['ERR_CHECKSYS_FASTCGI']}</span></b>";
  84. $error_found = true;
  85. $error_txt .= '
  86. <tr>
  87. <td><b>'.$mod_strings['LBL_CHECKSYS_FASTCGI'].'</b></td>
  88. <td ><span class="error">'.$iisVersion.'</span></td>
  89. </tr>';
  90. } else if(ini_get('fastcgi.logging') != '0')
  91. {
  92. installLog($mod_strings['ERR_CHECKSYS_FASTCGI_LOGGING'].' '.$iis_version);
  93. $iisVersion = "<b><span class=stop>{$mod_strings['ERR_CHECKSYS_FASTCGI_LOGGING']}</span></b>";
  94. $error_found = true;
  95. $error_txt .= '
  96. <tr>
  97. <td><b>'.$mod_strings['LBL_CHECKSYS_FASTCGI'].'</b></td>
  98. <td ><span class="error">'.$iisVersion.'</span></td>
  99. </tr>';
  100. }
  101. }
  102. // PHP VERSION
  103. $php_version = constant('PHP_VERSION');
  104. $check_php_version_result = check_php_version($php_version);
  105. if($check_php_version_result == -1) {
  106. installLog($mod_strings['ERR_CHECKSYS_PHP_INVALID_VER'].' '.$php_version);
  107. $phpVersion = "<b><span class=stop>{$mod_strings['ERR_CHECKSYS_PHP_INVALID_VER']} {$php_version} )</span></b>";
  108. $error_found = true;
  109. $error_txt .= '
  110. <tr>
  111. <td><b>'.$mod_strings['LBL_CHECKSYS_PHPVER'].'</b></td>
  112. <td ><span class="error">'.$phpVersion.'</span></td>
  113. </tr>';
  114. }
  115. //Php Backward compatibility checks
  116. if(ini_get("zend.ze1_compatibility_mode")) {
  117. installLog($mod_strings['LBL_BACKWARD_COMPATIBILITY_ON'].' '.'Php Backward Compatibility');
  118. $phpCompatibility = "<b><span class=stop>{$mod_strings['LBL_BACKWARD_COMPATIBILITY_ON']}</span></b>";
  119. $error_found = true;
  120. $error_txt .= '
  121. <tr>
  122. <td><b>Php Backward Compatibility</b></td>
  123. <td ><span class="error">'.$phpCompatibility.'</span></td>
  124. </tr>';
  125. }
  126. // database and connect
  127. if (!empty($_REQUEST['setup_db_type']))
  128. $_SESSION['setup_db_type'] = $_REQUEST['setup_db_type'];
  129. $mssqlStatus = '';
  130. $dbVersion = '';
  131. // Removed php_sqlsrv install support until the driver support is out of beta status
  132. $supported_dbs = array("mysql_connect",
  133. "mysqli_connect",
  134. "mssql_connect",
  135. "sqlsrv_connect",
  136. );
  137. $db_support_exists = false;
  138. foreach ($supported_dbs as $dbfunct){
  139. if( function_exists( $dbfunct) ){
  140. $db_support_exists = true;
  141. installLog("Found at least one supported DB Type");
  142. break;
  143. }
  144. }
  145. if( !$db_support_exists ){
  146. $db_name = $mod_strings['LBL_DB_UNAVAILABLE'];
  147. installLog("ERROR:: {$mod_strings['LBL_CHECKSYS_DB_SUPPORT_NOT_AVAILABLE']}");
  148. $dbStatus = "<b><span class=stop>{$mod_strings['LBL_CHECKSYS_DB_SUPPORT_NOT_AVAILABLE']}</span></b>";
  149. $error_found = true;
  150. $error_txt .= '
  151. <tr>
  152. <td><strong>'.$db_name.'</strong></td>
  153. <td class="error">'.$dbStatus.'</td>
  154. </tr>';
  155. }
  156. // XML Parsing
  157. if(!function_exists('xml_parser_create')) {
  158. $xmlStatus = "<b><span class=stop>{$mod_strings['LBL_CHECKSYS_XML_NOT_AVAILABLE']}</span></b>";
  159. installLog("ERROR:: {$mod_strings['LBL_CHECKSYS_XML_NOT_AVAILABLE']}");
  160. $error_found = true;
  161. $error_txt .= '
  162. <tr>
  163. <td><strong>'.$mod_strings['LBL_CHECKSYS_XML'].'</strong></td>
  164. <td class="error">'.$xmlStatus.'</td>
  165. </tr>';
  166. }else{
  167. installLog("XML Parsing Support Found");
  168. }
  169. // mbstrings
  170. if(!function_exists('mb_strlen')) {
  171. $mbstringStatus = "<b><span class=stop>{$mod_strings['ERR_CHECKSYS_MBSTRING']}</font></b>";
  172. installLog("ERROR:: {$mod_strings['ERR_CHECKSYS_MBSTRING']}");
  173. $error_found = true;
  174. $error_txt .= '
  175. <tr>
  176. <td><strong>'.$mod_strings['LBL_CHECKSYS_MBSTRING'].'</strong></td>
  177. <td class="error">'.$mbstringStatus.'</td>
  178. </tr>';
  179. }else{
  180. installLog("MBString Support Found");
  181. }
  182. // zip
  183. if(!class_exists('ZipArchive')) {
  184. $zipStatus = "<b><span class=stop>{$mod_strings['ERR_CHECKSYS_ZIP']}</font></b>";
  185. installLog("ERROR:: {$mod_strings['ERR_CHECKSYS_ZIP']}");
  186. }else{
  187. installLog("ZIP Support Found");
  188. }
  189. // config.php
  190. if(file_exists('./config.php') && (!(make_writable('./config.php')) || !(is_writable('./config.php')))) {
  191. installLog("ERROR:: {$mod_strings['ERR_CHECKSYS_CONFIG_NOT_WRITABLE']}");
  192. $configStatus = "<b><span class='stop'>{$mod_strings['ERR_CHECKSYS_CONFIG_NOT_WRITABLE']}</span></b>";
  193. $error_found = true;
  194. $error_txt .= '
  195. <tr>
  196. <td><strong>'.$mod_strings['LBL_CHECKSYS_CONFIG'].'</strong></td>
  197. <td class="error">'.$configStatus.'</td>
  198. </tr>';
  199. }
  200. // custom dir
  201. if(!make_writable('./custom')) {
  202. $customStatus = "<b><span class='stop'>{$mod_strings['ERR_CHECKSYS_CUSTOM_NOT_WRITABLE']}</font></b>";
  203. installLog("ERROR:: {$mod_strings['ERR_CHECKSYS_CUSTOM_NOT_WRITABLE']}");
  204. $error_found = true;
  205. $error_txt .= '
  206. <tr>
  207. <td><strong>'.$mod_strings['LBL_CHECKSYS_CUSTOM'].'</strong></td>
  208. <td class="error">'.$customStatus.'</td>
  209. </tr>';
  210. }else{
  211. installLog("/custom directory and subdirectory check passed");
  212. }
  213. // data dir
  214. if(!make_writable('./data') || !make_writable('./data/upload')) {
  215. $dataStatus = "<b><span class='stop'>{$mod_strings['ERR_CHECKSYS_FILES_NOT_WRITABLE']}</span></b>";
  216. installLog("ERROR:: {$mod_strings['ERR_CHECKSYS_FILES_NOT_WRITABLE']}");
  217. $error_found = true;
  218. $error_txt .= '
  219. <tr>
  220. <td><strong>'.$mod_strings['LBL_CHECKSYS_DATA'].'</strong></td>
  221. <td class="error">'.$dataStatus
  222. .'</td>
  223. </tr><tr>
  224. <td colspan="2">
  225. <b>'.$mod_strings['LBL_CHECKSYS_FIX_FILES'].'</b>';
  226. if(!make_writable('./data')) {
  227. $error_txt .='<br>'.getcwd().'/data';
  228. }
  229. if(!make_writable('./data/upload')) {
  230. $error_txt .='<br>'.getcwd().'/data/upload';
  231. }
  232. $error_txt .= '</td>
  233. </tr>';
  234. }else{
  235. installLog("/data/upoad directory and subdirectory check passed");
  236. }
  237. // cache dir
  238. $cache_files[] = '/cache';
  239. $cache_files[] = '/cache/images';
  240. $cache_files[] = '/cache/import';
  241. $cache_files[] = '/cache/layout';
  242. $cache_files[] = '/cache/pdf';
  243. $cache_files[] = '/cache/upload';
  244. $cache_files[] = '/cache/xml';
  245. $filelist = '';
  246. foreach($cache_files as $c_file)
  247. {
  248. $dirname = ".".$c_file;
  249. $ok = false;
  250. 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
  251. {
  252. $ok = make_writable($dirname);
  253. }
  254. if (!$ok)
  255. {
  256. $filelist .= '<br>'.getcwd().$c_file;
  257. }
  258. }
  259. if (strlen($filelist)>0)
  260. {
  261. $error_found = true;
  262. installLog("ERROR:: Some subdirectories in cache subfolder were not read/writeable:");
  263. installLog($filelist);
  264. $error_txt .= '
  265. <tr>
  266. <td><strong>'.$mod_strings['LBL_CHECKSYS_CACHE'].'</strong></td>
  267. <td align="right" class="error" class="error"><b><span class="stop">'.$mod_strings['ERR_CHECKSYS_FILES_NOT_WRITABLE'].'</span></b></td>
  268. </tr>
  269. <tr>
  270. <td colspan="2"><b>'.$mod_strings['LBL_CHECKSYS_FIX_FILES'].'</b>'.$filelist. '</td>
  271. </tr>';
  272. }else{
  273. installLog("/cache directory and subdirectory check passed");
  274. }
  275. // check modules dir
  276. $_SESSION['unwriteable_module_files'] = array();
  277. //if(!$writeableFiles['ret_val']) {
  278. $passed_write = recursive_make_writable('./modules');
  279. if (isset($_SESSION['unwriteable_module_files']['failed']) && $_SESSION['unwriteable_module_files']['failed']){
  280. $passed_write = false;
  281. }
  282. if(!$passed_write) {
  283. $moduleStatus = "<b><span class='stop'>{$mod_strings['ERR_CHECKSYS_NOT_WRITABLE']}</span></b>";
  284. installLog("ERROR:: Module directories and the files under them are not writeable.");
  285. $error_found = true;
  286. $error_txt .= '
  287. <tr>
  288. <td><strong>'.$mod_strings['LBL_CHECKSYS_MODULE'].'</strong></td>
  289. <td align="right" class="error">'.$moduleStatus.'</td>
  290. </tr>';
  291. //list which module directories are not writeable, if there are less than 10
  292. $error_txt .= '
  293. <tr>
  294. <td colspan="2">
  295. <b>'.$mod_strings['LBL_CHECKSYS_FIX_MODULE_FILES'].'</b>';
  296. foreach($_SESSION['unwriteable_module_files'] as $key=>$file){
  297. if($key !='.' && $key != 'failed'){
  298. $error_txt .='<br>'.$file;
  299. }
  300. }
  301. $error_txt .= '
  302. </td>
  303. </tr>';
  304. }else{
  305. installLog("/module directory and subdirectory check passed");
  306. }
  307. // PHP.ini
  308. $phpIniLocation = get_cfg_var("cfg_file_path");
  309. installLog("php.ini location found. {$phpIniLocation}");
  310. // disable form if error found
  311. if($error_found){
  312. installLog("Outputting HTML for System check");
  313. installLog("Errors were found *************");
  314. $disabled = $error_found ? 'disabled="disabled"' : '';
  315. $help_url = get_help_button_url();
  316. ///////////////////////////////////////////////////////////////////////////////
  317. //// BEGIN PAGE OUTPUT
  318. $out =<<<EOQ
  319. <table cellspacing="0" cellpadding="0" border="0" align="center" class="shell">
  320. <tr>
  321. <th width="400">{$mod_strings['LBL_CHECKSYS_TITLE']}</th>
  322. <th width="200" height="30" style="text-align: right;"><a href="http://www.sugarcrm.com" target=
  323. "_blank"><IMG src="include/images/sugarcrm_login.png" width="145" height="30" alt="SugarCRM" border="0"></a>
  324. <br><a href="{$help_url}" target='_blank'>{$mod_strings['LBL_HELP']} </a>
  325. </th>
  326. </tr>
  327. <tr>
  328. <td colspan="2" width="600">
  329. <p>{$mod_strings['ERR_CHECKSYS']}</p>
  330. <table cellpadding="0" cellspacing="0" border="0" width="100%" class="StyleDottedHr">
  331. <tr>
  332. <th align="left">{$mod_strings['LBL_CHECKSYS_COMPONENT']}</th>
  333. <th style="text-align: right;">{$mod_strings['LBL_CHECKSYS_STATUS']}</th>
  334. </tr>
  335. $error_txt
  336. </table>
  337. <div align="center" style="margin: 5px;">
  338. <i>{$mod_strings['LBL_CHECKSYS_PHP_INI']}<br>{$phpIniLocation}</i>
  339. </div>
  340. </td>
  341. </tr>
  342. <tr>
  343. <td align="right" colspan="2">
  344. <hr>
  345. <form action="install3.php" method="post" name="theForm" id="theForm">
  346. <table cellspacing="0" cellpadding="0" border="0" class="stdTable">
  347. <tr>
  348. <td><input class="button" type="button" onclick="window.open('http://www.sugarcrm.com/forums/');" value="{$mod_strings['LBL_HELP']}" /></td>
  349. <td>
  350. <input class="button" type="button" name="Re-check" value="{$mod_strings['LBL_CHECKSYS_RECHECK']}" onclick="callSysCheck();" id="button_next2"/>
  351. </td>
  352. </tr>
  353. </table>
  354. </form>
  355. </td>
  356. </tr>
  357. </table><br>
  358. EOQ;
  359. return $out;
  360. }else{
  361. installLog("Outputting HTML for System check");
  362. installLog("No Errors were found *************");
  363. return 'passed';
  364. }
  365. }
  366. //// END PAGEOUTPUT
  367. ///////////////////////////////////////////////////////////////////////////////
  368. ?>