PageRenderTime 44ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/branch/vtigercrm-530-540-patch-original/include/install/resources/utils.php

https://code.google.com/p/vtiger-ru-fork/
PHP | 1554 lines | 1218 code | 191 blank | 145 comment | 253 complexity | e2522dad2740fa7ad06b29ec9f5c093c MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, GPL-2.0, LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*+**********************************************************************************
  3. * The contents of this file are subject to the vtiger CRM Public License Version 1.0
  4. * ("License"); You may not use this file except in compliance with the License
  5. * The Original Code is: vtiger CRM Open Source
  6. * The Initial Developer of the Original Code is vtiger.
  7. * Portions created by vtiger are Copyright (C) vtiger.
  8. * All Rights Reserved.
  9. ************************************************************************************/
  10. /**
  11. * Provides few utility functions for installation/migration process
  12. * @package install
  13. */
  14. class Installation_Utils {
  15. static function getInstallableOptionalModules() {
  16. $optionalModules = Common_Install_Wizard_Utils::getInstallableModulesFromPackages();
  17. return $optionalModules;
  18. }
  19. // Function to install Vtlib Compliant - Optional Modules
  20. static function installOptionalModules($selected_modules){
  21. Common_Install_Wizard_Utils::installSelectedOptionalModules($selected_modules);
  22. }
  23. static function getDbOptions() {
  24. $dbOptions = array();
  25. if(function_exists('mysql_connect')) {
  26. $dbOptions['mysql'] = 'MySQL';
  27. }
  28. if(function_exists('pg_connect')) {
  29. $dbOptions['pgsql'] = 'Postgres';
  30. }
  31. return $dbOptions;
  32. }
  33. static function checkDbConnection($db_type, $db_hostname, $db_username, $db_password, $db_name, $create_db=false, $create_utf8_db=true, $root_user='', $root_password='') {
  34. global $installationStrings, $vtiger_current_version;
  35. $dbCheckResult = array();
  36. require_once('include/DatabaseUtil.php');
  37. $db_type_status = false; // is there a db type?
  38. $db_server_status = false; // does the db server connection exist?
  39. $db_creation_failed = false; // did we try to create a database and fail?
  40. $db_exist_status = false; // does the database exist?
  41. $db_utf8_support = false; // does the database support utf8?
  42. $vt_charset = ''; // set it based on the database charset support
  43. //Checking for database connection parameters
  44. if($db_type) {
  45. $conn = &NewADOConnection($db_type);
  46. $db_type_status = true;
  47. if(@$conn->Connect($db_hostname,$db_username,$db_password)) {
  48. $db_server_status = true;
  49. $serverInfo = $conn->ServerInfo();
  50. if(Common_Install_Wizard_Utils::isMySQL($db_type)) {
  51. $mysql_server_version = Common_Install_Wizard_Utils::getMySQLVersion($serverInfo);
  52. }
  53. if($create_db) {
  54. // drop the current database if it exists
  55. $dropdb_conn = &NewADOConnection($db_type);
  56. if(@$dropdb_conn->Connect($db_hostname, $root_user, $root_password, $db_name)) {
  57. $query = "drop database ".$db_name;
  58. $dropdb_conn->Execute($query);
  59. $dropdb_conn->Close();
  60. }
  61. // create the new database
  62. $db_creation_failed = true;
  63. $createdb_conn = &NewADOConnection($db_type);
  64. if(@$createdb_conn->Connect($db_hostname, $root_user, $root_password)) {
  65. $query = "create database ".$db_name;
  66. if($create_utf8_db == 'true') {
  67. if(Common_Install_Wizard_Utils::isMySQL($db_type))
  68. $query .= " default character set utf8 default collate utf8_general_ci";
  69. $db_utf8_support = true;
  70. }
  71. if($createdb_conn->Execute($query)) {
  72. $db_creation_failed = false;
  73. }
  74. $createdb_conn->Close();
  75. }
  76. }
  77. // test the connection to the database
  78. if(@$conn->Connect($db_hostname, $db_username, $db_password, $db_name))
  79. {
  80. $db_exist_status = true;
  81. if(!$db_utf8_support) {
  82. // Check if the database that we are going to use supports UTF-8
  83. $db_utf8_support = check_db_utf8_support($conn);
  84. }
  85. }
  86. $conn->Close();
  87. }
  88. }
  89. $dbCheckResult['db_utf8_support'] = $db_utf8_support;
  90. $error_msg = '';
  91. $error_msg_info = '';
  92. if(!$db_type_status || !$db_server_status) {
  93. $error_msg = $installationStrings['ERR_DATABASE_CONNECTION_FAILED'].'. '.$installationStrings['ERR_INVALID_MYSQL_PARAMETERS'];
  94. $error_msg_info = $installationStrings['MSG_LIST_REASONS'].':<br>
  95. - '.$installationStrings['MSG_DB_PARAMETERS_INVALID'].'. <a href="http://www.vtiger.com/products/crm/help/'.$vtiger_current_version.'/vtiger_CRM_Database_Hostname.pdf" target="_blank">'.$installationStrings['LBL_MORE_INFORMATION'].'</a><BR>
  96. - '.$installationStrings['MSG_DB_USER_NOT_AUTHORIZED'];
  97. }
  98. elseif(Common_Install_Wizard_Utils::isMySQL($db_type) && $mysql_server_version < '4.1') {
  99. $error_msg = $mysql_server_version.' -> '.$installationStrings['ERR_INVALID_MYSQL_VERSION'];
  100. }
  101. elseif($db_creation_failed) {
  102. $error_msg = $installationStrings['ERR_UNABLE_CREATE_DATABASE'].' '.$db_name;
  103. $error_msg_info = $installationStrings['MSG_DB_ROOT_USER_NOT_AUTHORIZED'];
  104. }
  105. elseif(!$db_exist_status) {
  106. $error_msg = $db_name.' -> '.$installationStrings['ERR_DB_NOT_FOUND'];
  107. }
  108. else {
  109. $dbCheckResult['flag'] = true;
  110. return $dbCheckResult;
  111. }
  112. $dbCheckResult['flag'] = false;
  113. $dbCheckResult['error_msg'] = $error_msg;
  114. $dbCheckResult['error_msg_info'] = $error_msg_info;
  115. return $dbCheckResult;
  116. }
  117. }
  118. class Migration_Utils {
  119. static function verifyMigrationInfo($migrationInfo) {
  120. global $installationStrings, $vtiger_current_version;
  121. $dbVerifyResult = array();
  122. $dbVerifyResult['flag'] = false;
  123. $configInfo = array();
  124. if (isset($migrationInfo['source_directory'])) $source_directory = $migrationInfo['source_directory'];
  125. if (isset($migrationInfo['root_directory'])) $configInfo['root_directory'] = $migrationInfo['root_directory'];
  126. if(is_dir($source_directory)){
  127. if(!is_file($source_directory."config.inc.php")){
  128. $dbVerifyResult['error_msg'] = $installationStrings['ERR_NO_CONFIG_FILE'];
  129. return $dbVerifyResult;
  130. }
  131. if(!is_dir($source_directory."user_privileges")){
  132. $dbVerifyResult['error_msg'] = $installationStrings['ERR_NO_USER_PRIV_DIR'];
  133. return $dbVerifyResult;
  134. }
  135. if(!is_dir($source_directory."storage")){
  136. $dbVerifyResult['error_msg'] = $installationStrings['ERR_NO_STORAGE_DIR'];
  137. return $dbVerifyResult;
  138. }
  139. } else {
  140. $dbVerifyResult['error_msg'] = $installationStrings['ERR_NO_SOURCE_DIR'];
  141. return $dbVerifyResult;
  142. }
  143. global $dbconfig;
  144. require_once($source_directory."config.inc.php");
  145. $old_db_name = $dbconfig['db_name'];
  146. $db_hostname = $dbconfig['db_server'].$dbconfig['db_port'];
  147. $db_username = $dbconfig['db_username'];
  148. $db_password = $dbconfig['db_password'];
  149. $db_type = $dbconfig['db_type'];
  150. if (isset($migrationInfo['user_name'])) $user_name = $migrationInfo['user_name'];
  151. if (isset($migrationInfo['user_pwd'])) $user_pwd = $migrationInfo['user_pwd'];
  152. if (isset($migrationInfo['old_version'])) $source_version = $migrationInfo['old_version'];
  153. if (isset($migrationInfo['new_dbname'])) $new_db_name = $migrationInfo['new_dbname'];
  154. $configInfo['db_name'] = $new_db_name;
  155. $configInfo['db_type'] = $db_type;
  156. $configInfo['db_hostname'] = $db_hostname;
  157. $configInfo['db_username'] = $db_username;
  158. $configInfo['db_password'] = $db_password;
  159. $configInfo['admin_email'] = $HELPDESK_SUPPORT_EMAIL_ID;
  160. $configInfo['currency_name'] = $currency_name;
  161. $dbVerifyResult['old_dbname'] = $old_db_name;
  162. $db_type_status = false; // is there a db type?
  163. $db_server_status = false; // does the db server connection exist?
  164. $old_db_exist_status = false; // does the old database exist?
  165. $db_utf8_support = false; // does the database support utf8?
  166. $new_db_exist_status = false; // does the new database exist?
  167. $new_db_has_tables = false; // does the new database has tables in it?
  168. require_once('include/DatabaseUtil.php');
  169. //Checking for database connection parameters and copying old database into new database
  170. if($db_type) {
  171. $conn = &NewADOConnection($db_type);
  172. $db_type_status = true;
  173. if(@$conn->Connect($db_hostname,$db_username,$db_password)) {
  174. $db_server_status = true;
  175. $serverInfo = $conn->ServerInfo();
  176. if(Common_Install_Wizard_Utils::isMySQL($db_type)) {
  177. $mysql_server_version = Common_Install_Wizard_Utils::getMySQLVersion($serverInfo);
  178. }
  179. // test the connection to the old database
  180. $olddb_conn = &NewADOConnection($db_type);
  181. if(@$olddb_conn->Connect($db_hostname, $db_username, $db_password, $old_db_name))
  182. {
  183. $old_db_exist_status = true;
  184. if(version_compare(PHP_VERSION, '5.3.0') >= 0) {
  185. $sql = 'alter table vtiger_users change user_password user_password varchar(128)';
  186. $alterResult = $olddb_conn->_Execute($sql);
  187. if(!is_object($alterResult)) {
  188. $dbVerifyResult['error_msg'] =
  189. $installationStrings['LBL_PASSWORD_FIELD_CHANGE_FAILURE'];
  190. }
  191. if(!is_array($_SESSION['migration_info']['user_messages'])) {
  192. unset($_SESSION['migration_info']['user_messages']);
  193. $_SESSION['migration_info']['user_messages'] = array();
  194. $_SESSION['migration_info']['user_messages'][] = array(
  195. 'status' => "<span style='color: red;font-weight: bold'>".
  196. $installationStrings['LBL_IMPORTANT_NOTE']."</span>",
  197. 'msg' => "<span style='color: #3488cc;font-weight: bold'>".
  198. $installationStrings['LBL_USER_PASSWORD_CHANGE_NOTE']."</span>"
  199. );
  200. }
  201. if(self::resetUserPasswords($olddb_conn)) {
  202. $_SESSION['migration_info']['user_pwd'] = $user_name;
  203. $migrationInfo['user_pwd'] = $user_name;
  204. $user_pwd = $user_name;
  205. }
  206. }
  207. if(Migration_Utils::authenticateUser($olddb_conn, $user_name,$user_pwd)==true) {
  208. $is_admin = true;
  209. } else{
  210. $dbVerifyResult['error_msg'] = $installationStrings['ERR_NOT_VALID_USER'];
  211. return $dbVerifyResult;
  212. }
  213. $olddb_conn->Close();
  214. }
  215. // test the connection to the new database
  216. $newdb_conn = &NewADOConnection($db_type);
  217. if(@$newdb_conn->Connect($db_hostname, $db_username, $db_password, $new_db_name))
  218. {
  219. $new_db_exist_status = true;
  220. $noOfTablesInNewDb = Migration_Utils::getNumberOfTables($newdb_conn);
  221. if($noOfTablesInNewDb > 0){
  222. $new_db_has_tables = true;
  223. }
  224. $db_utf8_support = check_db_utf8_support($newdb_conn);
  225. $configInfo['vt_charset'] = ($db_utf8_support)? "UTF-8" : "ISO-8859-1";
  226. $newdb_conn->Close();
  227. }
  228. }
  229. $conn->Close();
  230. }
  231. if(!$db_type_status || !$db_server_status) {
  232. $error_msg = $installationStrings['ERR_DATABASE_CONNECTION_FAILED'].'. '.$installationStrings['ERR_INVALID_MYSQL_PARAMETERS'];
  233. $error_msg_info = $installationStrings['MSG_LIST_REASONS'].':<br>
  234. - '.$installationStrings['MSG_DB_PARAMETERS_INVALID'].'. <a href="http://www.vtiger.com/products/crm/help/'.$vtiger_current_version.'/vtiger_CRM_Database_Hostname.pdf" target="_blank">'.$installationStrings['LBL_MORE_INFORMATION'].'</a><BR>
  235. - '.$installationStrings['MSG_DB_USER_NOT_AUTHORIZED'];
  236. } elseif(Common_Install_Wizard_Utils::isMySQL($db_type) && $mysql_server_version < '4.1') {
  237. $error_msg = $mysql_server_version.' -> '.$installationStrings['ERR_INVALID_MYSQL_VERSION'];
  238. } elseif(!$old_db_exist_status) {
  239. $error_msg = $old_db_name.' -> '.$installationStrings['ERR_DATABASE_NOT_FOUND'];
  240. } elseif(!$new_db_exist_status) {
  241. $error_msg = $new_db_name.' -> '.$installationStrings['ERR_DATABASE_NOT_FOUND'];
  242. } elseif(!$new_db_has_tables) {
  243. $error_msg = $new_db_name.' -> '.$installationStrings['ERR_MIGRATION_DATABASE_IS_EMPTY'];
  244. } else {
  245. $web_root = ($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"]:$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'];
  246. $web_root .= $_SERVER["REQUEST_URI"];
  247. $web_root = preg_replace("/\/install.php(.)*/i", "", $web_root);
  248. $site_URL = "http://".$web_root;
  249. $configInfo['site_URL'] = $site_URL;
  250. $dbVerifyResult['config_info'] = $configInfo;
  251. $dbVerifyResult['flag'] = true;
  252. return $dbVerifyResult;
  253. }
  254. $dbVerifyResult['config_info'] = $configInfo;
  255. $dbVerifyResult['error_msg'] = $error_msg;
  256. $dbVerifyResult['error_msg_info'] = $error_msg_info;
  257. return $dbVerifyResult;
  258. }
  259. private static function authenticateUser($dbConnection, $userName,$userPassword){
  260. $userResult = $dbConnection->_Execute("SELECT * FROM vtiger_users WHERE user_name = '$userName'");
  261. $noOfRows = $userResult->NumRows($userResult);
  262. if ($noOfRows > 0) {
  263. $userInfo = $userResult->GetRowAssoc(0);
  264. $cryptType = $userInfo['crypt_type'];
  265. $userEncryptedPassword = $userInfo['user_password'];
  266. $userStatus = $userInfo['status'];
  267. $isAdmin = $userInfo['is_admin'];
  268. $computedEncryptedPassword = self::getEncryptedPassword($userName, $cryptType,
  269. $userPassword);
  270. if($userEncryptedPassword == $computedEncryptedPassword && $userStatus == 'Active' && $isAdmin == 'on'){
  271. return true;
  272. }
  273. }
  274. return false;
  275. }
  276. private static function getNumberOfTables($dbConnection) {
  277. $metaTablesSql = $dbConnection->metaTablesSQL;
  278. $noOfTables = 0;
  279. if(!empty($metaTablesSql)) {
  280. $tablesResult = $dbConnection->_Execute($metaTablesSql);
  281. $noOfTables = $tablesResult->NumRows($tablesResult);
  282. }
  283. return $noOfTables;
  284. }
  285. static function copyRequiredFiles($sourceDirectory, $destinationDirectory) {
  286. if (realpath($sourceDirectory) == realpath($destinationDirectory)) return;
  287. @Migration_Utils::getFilesFromFolder($sourceDirectory."user_privileges/",$destinationDirectory."user_privileges/",
  288. // Force copy these files - Overwrite if they exist in destination directory.
  289. array($sourceDirectory."user_privileges/default_module_view.php")
  290. );
  291. @Migration_Utils::getFilesFromFolder($sourceDirectory."storage/",$destinationDirectory."storage/");
  292. @Migration_Utils::getFilesFromFolder($sourceDirectory."test/contact/",$destinationDirectory."test/contact/");
  293. @Migration_Utils::getFilesFromFolder($sourceDirectory."test/logo/",$destinationDirectory."test/logo/");
  294. @Migration_Utils::getFilesFromFolder($sourceDirectory."test/product/",$destinationDirectory."test/product/");
  295. @Migration_Utils::getFilesFromFolder($sourceDirectory."test/user/",$destinationDirectory."test/user/");
  296. }
  297. private static function getFilesFromFolder($source, $dest, $forcecopy=false) {
  298. if(!$forcecopy) $forcecopy = Array();
  299. if ($handle = opendir($source)) {
  300. while (false != ($file = readdir($handle))) {
  301. if (is_file($source.$file)) {
  302. if(!file_exists($dest.$file) || in_array($source.$file, $forcecopy)){
  303. $file_handle = fopen($dest.$file,'w');
  304. fclose($file_handle);
  305. copy($source.$file, $dest.$file);
  306. }
  307. } elseif ($file != '.' && $file != '..' && is_dir($source.$file)) {
  308. if(!file_exists("$dest.$file")) {
  309. mkdir($dest.$file.'/',0777);
  310. }
  311. Migration_Utils::getFilesFromFolder($source.$file.'/', $dest.$file.'/');
  312. }
  313. }
  314. }
  315. @closedir($handle);
  316. }
  317. static function getInstallableOptionalModules() {
  318. $optionalModules = Common_Install_Wizard_Utils::getInstallableModulesFromPackages();
  319. $skipModules = array();
  320. if(!empty($optionalModules['install'])) $skipModules = array_merge($skipModules,array_keys($optionalModules['install']));
  321. if(!empty($optionalModules['update'])) $skipModules = array_merge($skipModules,array_keys($optionalModules['update']));
  322. $mandatoryModules = Common_Install_Wizard_Utils::getMandatoryModuleList();
  323. $oldVersion = str_replace(array('.', ' '), array('', ''),
  324. $_SESSION['migration_info']['old_version']);
  325. $customModules = array();
  326. if (version_compare($oldVersion, '502') > 0) {
  327. $customModules = Migration_Utils::getCustomModulesFromDB(array_merge($skipModules,
  328. $mandatoryModules));
  329. }
  330. $optionalModules = array_merge($optionalModules, $customModules);
  331. return $optionalModules;
  332. }
  333. static function getCustomModulesFromDB($skipModules) {
  334. global $optionalModuleStrings, $adb;
  335. require_once('vtlib/Vtiger/Package.php');
  336. require_once('vtlib/Vtiger/Module.php');
  337. require_once('vtlib/Vtiger/Version.php');
  338. $customModulesResult = $adb->pquery('SELECT tabid, name FROM vtiger_tab WHERE customized=1 AND
  339. name NOT IN ('. generateQuestionMarks($skipModules).')', $skipModules);
  340. $noOfCustomModules = $adb->num_rows($customModulesResult);
  341. $customModules = array();
  342. for($i=0;$i<$noOfCustomModules;++$i) {
  343. $tabId = $adb->query_result($customModulesResult,$i,'tabid');
  344. $moduleName = $adb->query_result($customModulesResult,$i,'name');
  345. $moduleDetails = array();
  346. $moduleDetails['description'] = $optionalModuleStrings[$moduleName.'_description'];
  347. $moduleDetails['selected'] = false;
  348. $moduleDetails['enabled'] = false;
  349. if(Vtiger_Utils::checkTable('vtiger_tab_info')) {
  350. $tabInfo = getTabInfo($tabId);
  351. if(Vtiger_Version::check($tabInfo['vtiger_min_version'],'>=') && Vtiger_Version::check($tabInfo['vtiger_max_version'],'<')) {
  352. $moduleDetails['selected'] = true;
  353. $moduleDetails['enabled'] = false;
  354. }
  355. }
  356. $customModules['copy'][$moduleName] = $moduleDetails;
  357. }
  358. return $customModules;
  359. }
  360. // Function to install Vtlib Compliant - Optional Modules
  361. static function installOptionalModules($selectedModules, $sourceDirectory, $destinationDirectory){
  362. Migration_Utils::copyCustomModules($selectedModules, $sourceDirectory, $destinationDirectory);
  363. Common_Install_Wizard_Utils::installSelectedOptionalModules($selectedModules, $sourceDirectory, $destinationDirectory);
  364. }
  365. private static function copyCustomModules($selectedModules, $sourceDirectory, $destinationDirectory) {
  366. global $adb;
  367. $selectedModules = explode(":",$selectedModules);
  368. $customModulesResult = $adb->pquery('SELECT tabid, name FROM vtiger_tab WHERE customized = 1', array());
  369. $noOfCustomModules = $adb->num_rows($customModulesResult);
  370. $mandatoryModules = Common_Install_Wizard_Utils::getMandatoryModuleList();
  371. $optionalModules = Common_Install_Wizard_Utils::getInstallableModulesFromPackages();
  372. $skipModules = array_merge($mandatoryModules, $optionalModules);
  373. for($i=0;$i<$noOfCustomModules;++$i) {
  374. $moduleName = $adb->query_result($customModulesResult,$i,'name');
  375. if(!in_array($moduleName, $skipModules)) {
  376. Migration_Utils::copyModuleFiles($moduleName, $sourceDirectory, $destinationDirectory);
  377. if(!in_array($moduleName,$selectedModules)) {
  378. vtlib_toggleModuleAccess((string)$moduleName, false);
  379. }
  380. }
  381. }
  382. }
  383. static function copyModuleFiles($moduleName, $sourceDirectory, $destinationDirectory) {
  384. $sourceDirectory = realpath($sourceDirectory);
  385. $destinationDirectory = realpath($destinationDirectory);
  386. if (!empty($moduleName) && !empty($sourceDirectory) && !empty($destinationDirectory) && $sourceDirectory != $destinationDirectory) {
  387. if(file_exists("$sourceDirectory/modules/$moduleName")) {
  388. if(!file_exists("$destinationDirectory/modules/$moduleName")) {
  389. mkdir("$destinationDirectory/modules/$moduleName".'/',0777);
  390. }
  391. Migration_Utils::getFilesFromFolder("{$sourceDirectory}/modules/$moduleName/","{$destinationDirectory}/modules/$moduleName/");
  392. }
  393. if(file_exists("$sourceDirectory/Smarty/templates/modules/$moduleName")) {
  394. if(!file_exists("$destinationDirectory/Smarty/templates/modules/$moduleName")) {
  395. mkdir("$destinationDirectory/Smarty/templates/modules/$moduleName".'/',0777);
  396. }
  397. Migration_Utils::getFilesFromFolder("{$sourceDirectory}/Smarty/templates/modules/$moduleName/","{$destinationDirectory}/Smarty/templates/modules/$moduleName/");
  398. }
  399. if(file_exists("$sourceDirectory/cron/modules/$moduleName")) {
  400. if(!file_exists("$destinationDirectory/cron/modules/$moduleName")) {
  401. mkdir("$destinationDirectory/cron/modules/$moduleName".'/',0777);
  402. }
  403. Migration_Utils::getFilesFromFolder("{$sourceDirectory}/cron/modules/$moduleName/","{$destinationDirectory}/cron/modules/$moduleName/");
  404. }
  405. }
  406. }
  407. function migrate($migrationInfo){
  408. global $installationStrings;
  409. $completed = false;
  410. set_time_limit(0);//ADDED TO AVOID UNEXPECTED TIME OUT WHILE MIGRATING
  411. global $dbconfig;
  412. require ($migrationInfo['root_directory'] . '/config.inc.php');
  413. $dbtype = $dbconfig['db_type'];
  414. $host = $dbconfig['db_server'].$dbconfig['db_port'];
  415. $dbname = $dbconfig['db_name'];
  416. $username = $dbconfig['db_username'];
  417. $passwd = $dbconfig['db_password'];
  418. global $adb,$migrationlog;
  419. $adb = new PearDatabase($dbtype,$host,$dbname,$username,$passwd);
  420. $query = " ALTER DATABASE ".$adb->escapeDbName($dbname)." DEFAULT CHARACTER SET utf8";
  421. $adb->query($query);
  422. $source_directory = $migrationInfo['source_directory'];
  423. if(file_exists($source_directory.'user_privileges/CustomInvoiceNo.php')) {
  424. require_once($source_directory.'user_privileges/CustomInvoiceNo.php');
  425. }
  426. $migrationlog =& LoggerManager::getLogger('MIGRATION');
  427. if (isset($migrationInfo['old_version'])) $source_version = $migrationInfo['old_version'];
  428. if(!isset($source_version) || empty($source_version)) {
  429. //If source version is not set then we cannot proceed
  430. echo "<br> ".$installationStrings['LBL_SOURCE_VERSION_NOT_SET'];
  431. exit;
  432. }
  433. $reach = 0;
  434. include($migrationInfo['root_directory']."/modules/Migration/versions.php");
  435. foreach($versions as $version => $label) {
  436. if($version == $source_version || $reach == 1) {
  437. $reach = 1;
  438. $temp[] = $version;
  439. }
  440. }
  441. $temp[] = $current_version;
  442. global $adb, $dbname;
  443. $_SESSION['adodb_current_object'] = $adb;
  444. @ini_set('zlib.output_compression', 0);
  445. @ini_set('output_buffering','off');
  446. ob_implicit_flush(true);
  447. echo '<table width="98%" border="1px" cellpadding="3" cellspacing="0" height="100%">';
  448. if(is_array($_SESSION['migration_info']['user_messages'])) {
  449. foreach ($_SESSION['migration_info']['user_messages'] as $infoMap) {
  450. echo "<tr><td>".$infoMap['status']."</td><td>".$infoMap['msg']."</td></tr>";
  451. }
  452. }
  453. echo "<tr><td colspan='2'><b>{$installationStrings['LBL_GOING_TO_APPLY_DB_CHANGES']}...</b></td></tr>";
  454. for($patch_count=0;$patch_count<count($temp);$patch_count++) {
  455. //Here we have to include all the files (all db differences for each release will be included)
  456. $filename = "modules/Migration/DBChanges/".$temp[$patch_count]."_to_".$temp[$patch_count+1].".php";
  457. $empty_tag = "<tr><td colspan='2'>&nbsp;</td></tr>";
  458. $start_tag = "<tr><td colspan='2'><b><font color='red'>&nbsp;";
  459. $end_tag = "</font></b></td></tr>";
  460. if(is_file($filename)) {
  461. echo $empty_tag.$start_tag.$temp[$patch_count]." ==> ".$temp[$patch_count+1]. " " .$installationStrings['LBL_DATABASE_CHANGES'] ." -- ". $installationStrings['LBL_STARTS'] .".".$end_tag;
  462. include($filename);//include the file which contains the corresponding db changes
  463. echo $start_tag.$temp[$patch_count]." ==> ".$temp[$patch_count+1]. " " .$installationStrings['LBL_DATABASE_CHANGES'] ." -- ". $installationStrings['LBL_ENDS'] .".".$end_tag;
  464. }
  465. }
  466. /* Install Vtlib Compliant Modules */
  467. Common_Install_Wizard_Utils::installMandatoryModules();
  468. Migration_Utils::installOptionalModules($migrationInfo['selected_optional_modules'], $migrationInfo['source_directory'], $migrationInfo['root_directory']);
  469. Migration_utils::copyLanguageFiles($migrationInfo['source_directory'], $migrationInfo['root_directory']);
  470. //Here we have to update the version in table. so that when we do migration next time we will get the version
  471. $res = $adb->query('SELECT * FROM vtiger_version');
  472. global $vtiger_current_version;
  473. require($migrationInfo['root_directory'].'/vtigerversion.php');
  474. if($adb->num_rows($res)) {
  475. $res = ExecuteQuery("UPDATE vtiger_version SET old_version='$versions[$source_version]',current_version='$vtiger_current_version'");
  476. $completed = true;
  477. } else {
  478. ExecuteQuery("INSERT INTO vtiger_version (id, old_version, current_version) values (".$adb->getUniqueID('vtiger_version').", '$versions[$source_version]', '$vtiger_current_version');");
  479. $completed = true;
  480. }
  481. echo '</table><br><br>';
  482. create_tab_data_file();
  483. create_parenttab_data_file();
  484. return $completed;
  485. }
  486. public static function resetUserPasswords($con) {
  487. $sql = 'select * from vtiger_users';
  488. $result = $con->_Execute($sql, false);
  489. $rowList = $result->GetRows();
  490. foreach ($rowList as $row) {
  491. if(!isset($row['crypt_type'])) {
  492. return false;
  493. }
  494. $cryptType = $row['crypt_type'];
  495. if(strtolower($cryptType) == 'md5' && version_compare(PHP_VERSION, '5.3.0') >= 0) {
  496. $cryptType = 'PHP5.3MD5';
  497. }
  498. $encryptedPassword = self::getEncryptedPassword($row['user_name'], $cryptType,
  499. $row['user_name']);
  500. $userId = $row['id'];
  501. $sql = "update vtiger_users set user_password=?,crypt_type=? where id=?";
  502. $updateResult = $con->Execute($sql, array($encryptedPassword, $cryptType, $userId));
  503. if(!is_object($updateResult)) {
  504. $_SESSION['migration_info']['user_messages'][] = array(
  505. 'status' => "<span style='color: red;font-weight: bold'>Failed: </span>",
  506. 'msg' => "$sql<br />".var_export(array($encryptedPassword, $userId))
  507. );
  508. }
  509. }
  510. return true;
  511. }
  512. public static function getEncryptedPassword($userName, $cryptType, $userPassword) {
  513. $salt = substr($userName, 0, 2);
  514. // For more details on salt format look at: http://in.php.net/crypt
  515. if($cryptType == 'MD5') {
  516. $salt = '$1$' . $salt . '$';
  517. } elseif($cryptType == 'BLOWFISH') {
  518. $salt = '$2$' . $salt . '$';
  519. } elseif($cryptType == 'PHP5.3MD5') {
  520. //only change salt for php 5.3 or higher version for backward
  521. //compactibility.
  522. //crypt API is lot stricter in taking the value for salt.
  523. $salt = '$1$' . str_pad($salt, 9, '0');
  524. }
  525. $computedEncryptedPassword = crypt($userPassword, $salt);
  526. return $computedEncryptedPassword;
  527. }
  528. public static function copyLanguageFiles($sourceDirectory, $destinationDirectory) {
  529. global $adb;
  530. $result = $adb->pquery('select * from vtiger_language', array());
  531. $it = new SqlResultIterator($adb, $result);
  532. $installedLanguages = array();
  533. $defaultLanguage = 'en_us';
  534. foreach ($it as $row) {
  535. if($row->prefix !== $defaultLanguage) {
  536. $installedLanguages[] = $row->prefix;
  537. }
  538. }
  539. self::copyLanguageFileFromFolder($sourceDirectory, $destinationDirectory,
  540. $installedLanguages);
  541. }
  542. public static function copyLanguageFileFromFolder($sourceDirectory, $destinationDirectory,
  543. $installedLanguages) {
  544. $ignoreDirectoryList = array('.', '..', 'storage','themes','fckeditor', 'HTMLPurifier');
  545. if ($handle = opendir($sourceDirectory)) {
  546. while (false !== ($file = readdir($handle))) {
  547. if(is_dir($sourceDirectory.DIRECTORY_SEPARATOR.$file) && !in_array($file,
  548. $ignoreDirectoryList)) {
  549. self::copyLanguageFileFromFolder($sourceDirectory.DIRECTORY_SEPARATOR.$file,
  550. $destinationDirectory.DIRECTORY_SEPARATOR.$file,$installedLanguages);
  551. continue;
  552. } elseif(in_array($file, $ignoreDirectoryList)) {
  553. continue;
  554. }
  555. $found = false;
  556. foreach ($installedLanguages as $prefix) {
  557. if(strpos($file, $prefix) === 0) {
  558. $found = true;
  559. break;
  560. }
  561. }
  562. if (!empty($file) && $found == true) {
  563. copy($sourceDirectory.DIRECTORY_SEPARATOR.$file, $destinationDirectory.
  564. DIRECTORY_SEPARATOR.$file);
  565. }
  566. }
  567. closedir($handle);
  568. }
  569. }
  570. }
  571. class ConfigFile_Utils {
  572. private $rootDirectory;
  573. private $dbHostname;
  574. private $dbPort;
  575. private $dbUsername;
  576. private $dbPassword;
  577. private $dbName;
  578. private $dbType;
  579. private $siteUrl;
  580. private $cacheDir;
  581. private $vtCharset;
  582. private $currencyName;
  583. private $adminEmail;
  584. function ConfigFile_Utils($configFileParameters) {
  585. if (isset($configFileParameters['root_directory']))
  586. $this->rootDirectory = $configFileParameters['root_directory'];
  587. if (isset($configFileParameters['db_hostname'])) {
  588. if(strpos($configFileParameters['db_hostname'], ":")) {
  589. list($this->dbHostname,$this->dbPort) = explode(":",$configFileParameters['db_hostname']);
  590. } else {
  591. $this->dbHostname = $configFileParameters['db_hostname'];
  592. }
  593. }
  594. if (isset($configFileParameters['db_username'])) $this->dbUsername = $configFileParameters['db_username'];
  595. if (isset($configFileParameters['db_password'])) $this->dbPassword = $configFileParameters['db_password'];
  596. if (isset($configFileParameters['db_name'])) $this->dbName = $configFileParameters['db_name'];
  597. if (isset($configFileParameters['db_type'])) $this->dbType = $configFileParameters['db_type'];
  598. if (isset($configFileParameters['site_URL'])) $this->siteUrl = $configFileParameters['site_URL'];
  599. if (isset($configFileParameters['admin_email'])) $this->adminEmail = $configFileParameters['admin_email'];
  600. if (isset($configFileParameters['currency_name'])) $this->currencyName = $configFileParameters['currency_name'];
  601. if (isset($configFileParameters['vt_charset'])) $this->vtCharset = $configFileParameters['vt_charset'];
  602. // update default port
  603. if ($this->dbPort == '') $this->dbPort = ConfigFile_Utils::getDbDefaultPort($this->dbType);
  604. $this->cacheDir = 'cache/';
  605. }
  606. static function getDbDefaultPort($dbType) {
  607. if(Common_Install_Wizard_Utils::isMySQL($dbType)) {
  608. return "3306";
  609. }
  610. if(Common_Install_Wizard_Utils::isPostgres($dbType)) {
  611. return "5432";
  612. }
  613. if(Common_Install_Wizard_Utils::isOracle($dbType)) {
  614. return '1521';
  615. }
  616. }
  617. function createConfigFile() {
  618. if (is_file('config.inc.php'))
  619. $is_writable = is_writable('config.inc.php');
  620. else
  621. $is_writable = is_writable('.');
  622. /* open template configuration file read only */
  623. $templateFilename = 'config.template.php';
  624. $templateHandle = fopen($templateFilename, "r");
  625. if($templateHandle) {
  626. /* open include configuration file write only */
  627. $includeFilename = 'config.inc.php';
  628. $includeHandle = fopen($includeFilename, "w");
  629. if($includeHandle) {
  630. while (!feof($templateHandle)) {
  631. $buffer = fgets($templateHandle);
  632. /* replace _DBC_ variable */
  633. $buffer = str_replace( "_DBC_SERVER_", $this->dbHostname, $buffer);
  634. $buffer = str_replace( "_DBC_PORT_", $this->dbPort, $buffer);
  635. $buffer = str_replace( "_DBC_USER_", $this->dbUsername, $buffer);
  636. $buffer = str_replace( "_DBC_PASS_", $this->dbPassword, $buffer);
  637. $buffer = str_replace( "_DBC_NAME_", $this->dbName, $buffer);
  638. $buffer = str_replace( "_DBC_TYPE_", $this->dbType, $buffer);
  639. $buffer = str_replace( "_SITE_URL_", $this->siteUrl, $buffer);
  640. /* replace dir variable */
  641. $buffer = str_replace( "_VT_ROOTDIR_", $this->rootDirectory, $buffer);
  642. $buffer = str_replace( "_VT_CACHEDIR_", $this->cacheDir, $buffer);
  643. $buffer = str_replace( "_VT_TMPDIR_", $this->cacheDir."images/", $buffer);
  644. $buffer = str_replace( "_VT_UPLOADDIR_", $this->cacheDir."upload/", $buffer);
  645. $buffer = str_replace( "_DB_STAT_", "true", $buffer);
  646. /* replace charset variable */
  647. $buffer = str_replace( "_VT_CHARSET_", $this->vtCharset, $buffer);
  648. /* replace master currency variable */
  649. $buffer = str_replace( "_MASTER_CURRENCY_", $this->currencyName, $buffer);
  650. /* replace the application unique key variable */
  651. $buffer = str_replace( "_VT_APP_UNIQKEY_", md5(time() + rand(1,9999999) + md5($this->rootDirectory)) , $buffer);
  652. /* replace support email variable */
  653. $buffer = str_replace( "_USER_SUPPORT_EMAIL_", $this->adminEmail, $buffer);
  654. fwrite($includeHandle, $buffer);
  655. }
  656. fclose($includeHandle);
  657. }
  658. fclose($templateHandle);
  659. }
  660. if ($templateHandle && $includeHandle) {
  661. return true;
  662. }
  663. return false;
  664. }
  665. function getConfigFileContents() {
  666. $configFileContents = "<?php
  667. /*********************************************************************************
  668. * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
  669. * (\"License\"); You may not use this file except in compliance with the
  670. * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
  671. * Software distributed under the License is distributed on an \"AS IS\" basis,
  672. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  673. * the specific language governing rights and limitations under the License.
  674. * The Original Code is: SugarCRM Open Source
  675. * The Initial Developer of the Original Code is SugarCRM, Inc.
  676. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
  677. * All Rights Reserved.
  678. * Contributor(s): ______________________________________.
  679. ********************************************************************************/
  680. include('vtigerversion.php');
  681. // more than 8MB memory needed for graphics
  682. // memory limit default value = 64M
  683. ini_set('memory_limit','64M');
  684. // show or hide calendar, world clock, calculator, chat and CKEditor
  685. // Do NOT remove the quotes if you set these to false!
  686. \$CALENDAR_DISPLAY = 'true';
  687. \$WORLD_CLOCK_DISPLAY = 'true';
  688. \$CALCULATOR_DISPLAY = 'true';
  689. \$CHAT_DISPLAY = 'true';
  690. \$USE_RTE = 'true';
  691. // url for customer portal (Example: http://vtiger.com/portal)
  692. \$PORTAL_URL = 'http://vtiger.com/customerportal';
  693. // helpdesk support email id and support name (Example: 'support@vtiger.com' and 'vtiger support')
  694. \$HELPDESK_SUPPORT_EMAIL_ID = '{$this->adminEmail}';
  695. \$HELPDESK_SUPPORT_NAME = 'your-support name';
  696. \$HELPDESK_SUPPORT_EMAIL_REPLY_ID = \$HELPDESK_SUPPORT_EMAIL_ID;
  697. /* database configuration
  698. db_server
  699. db_port
  700. db_hostname
  701. db_username
  702. db_password
  703. db_name
  704. */
  705. \$dbconfig['db_server'] = '{$this->dbHostname}';
  706. \$dbconfig['db_port'] = ':{$this->dbPort}';
  707. \$dbconfig['db_username'] = '{$this->dbUsername}';
  708. \$dbconfig['db_password'] = '{$this->dbPassword}';
  709. \$dbconfig['db_name'] = '{$this->dbName}';
  710. \$dbconfig['db_type'] = '{$this->dbType}';
  711. \$dbconfig['db_status'] = 'true';
  712. // TODO: test if port is empty
  713. // TODO: set db_hostname dependending on db_type
  714. \$dbconfig['db_hostname'] = \$dbconfig['db_server'].\$dbconfig['db_port'];
  715. // log_sql default value = false
  716. \$dbconfig['log_sql'] = false;
  717. // persistent default value = true
  718. \$dbconfigoption['persistent'] = true;
  719. // autofree default value = false
  720. \$dbconfigoption['autofree'] = false;
  721. // debug default value = 0
  722. \$dbconfigoption['debug'] = 0;
  723. // seqname_format default value = '%s_seq'
  724. \$dbconfigoption['seqname_format'] = '%s_seq';
  725. // portability default value = 0
  726. \$dbconfigoption['portability'] = 0;
  727. // ssl default value = false
  728. \$dbconfigoption['ssl'] = false;
  729. \$host_name = \$dbconfig['db_hostname'];
  730. \$site_URL = '{$this->siteUrl}';
  731. // root directory path
  732. \$root_directory = '{$this->rootDirectory}';
  733. // cache direcory path
  734. \$cache_dir = '{$this->cacheDir}';
  735. // tmp_dir default value prepended by cache_dir = images/
  736. \$tmp_dir = '{$this->cacheDir}images/';
  737. // import_dir default value prepended by cache_dir = import/
  738. \$import_dir = 'cache/import/';
  739. // upload_dir default value prepended by cache_dir = upload/
  740. \$upload_dir = '{$this->cacheDir}upload/';
  741. // maximum file size for uploaded files in bytes also used when uploading import files
  742. // upload_maxsize default value = 3000000
  743. \$upload_maxsize = 3000000;
  744. // flag to allow export functionality
  745. // 'all' to allow anyone to use exports
  746. // 'admin' to only allow admins to export
  747. // 'none' to block exports completely
  748. // allow_exports default value = all
  749. \$allow_exports = 'all';
  750. // files with one of these extensions will have '.txt' appended to their filename on upload
  751. \$upload_badext = array('php', 'php3', 'php4', 'php5', 'pl', 'cgi', 'py', 'asp', 'cfm', 'js', 'vbs', 'html', 'htm', 'exe', 'bin', 'bat', 'sh', 'dll', 'phps', 'phtml', 'xhtml', 'rb', 'msi', 'jsp', 'shtml', 'sth', 'shtm');
  752. // full path to include directory including the trailing slash
  753. // includeDirectory default value = \$root_directory..'include/
  754. \$includeDirectory = \$root_directory.'include/';
  755. // list_max_entries_per_page default value = 20
  756. \$list_max_entries_per_page = '20';
  757. // limitpage_navigation default value = 5
  758. \$limitpage_navigation = '5';
  759. // history_max_viewed default value = 5
  760. \$history_max_viewed = '5';
  761. // default_module default value = Home
  762. \$default_module = 'Home';
  763. // default_action default value = index
  764. \$default_action = 'index';
  765. // set default theme
  766. // default_theme default value = blue
  767. \$default_theme = 'softed';
  768. // show or hide time to compose each page
  769. // calculate_response_time default value = true
  770. \$calculate_response_time = true;
  771. // default text that is placed initially in the login form for user name
  772. // no default_user_name default value
  773. \$default_user_name = '';
  774. // default text that is placed initially in the login form for password
  775. // no default_password default value
  776. \$default_password = '';
  777. // create user with default username and password
  778. // create_default_user default value = false
  779. \$create_default_user = false;
  780. // default_user_is_admin default value = false
  781. \$default_user_is_admin = false;
  782. // if your MySQL/PHP configuration does not support persistent connections set this to true to avoid a large performance slowdown
  783. // disable_persistent_connections default value = false
  784. \$disable_persistent_connections = false;
  785. //Master currency name
  786. \$currency_name = '{$this->currencyName}';
  787. // default charset
  788. // default charset default value = 'UTF-8' or 'ISO-8859-1'
  789. \$default_charset = '{$this->vtCharset}';
  790. // default language
  791. // default_language default value = en_us
  792. \$default_language = 'en_us';
  793. // add the language pack name to every translation string in the display.
  794. // translation_string_prefix default value = false
  795. \$translation_string_prefix = false;
  796. //Option to cache tabs permissions for speed.
  797. \$cache_tab_perms = true;
  798. //Option to hide empty home blocks if no entries.
  799. \$display_empty_home_blocks = false;
  800. //Disable Stat Tracking of vtiger CRM instance
  801. \$disable_stats_tracking = false;
  802. // Generating Unique Application Key
  803. \$application_unique_key = '".md5(time() + rand(1,9999999) + md5($this->rootDirectory)) ."';
  804. // trim descriptions, titles in listviews to this value
  805. \$listview_max_textlength = 40;
  806. // Maximum time limit for PHP script execution (in seconds)
  807. \$php_max_execution_time = 0;
  808. // Set the default timezone as per your preference
  809. //\$default_timezone = '';
  810. /** If timezone is configured, try to set it */
  811. if(isset(\$default_timezone) && function_exists('date_default_timezone_set')) {
  812. @date_default_timezone_set(\$default_timezone);
  813. }
  814. ?>";
  815. return $configFileContents;
  816. }
  817. }
  818. class Common_Install_Wizard_Utils {
  819. public static $recommendedDirectives = array (
  820. 'safe_mode' => 'Off',
  821. 'display_errors' => 'On',
  822. 'file_uploads' => 'On',
  823. 'register_globals' => 'On',
  824. 'output_buffering' => 'On',
  825. 'max_execution_time' => '600',
  826. 'memory_limit' => '32',
  827. 'error_reporting' => 'E_WARNING & ~E_NOTICE',
  828. 'allow_call_time_pass_reference' => 'On',
  829. 'log_errors' => 'Off',
  830. 'short_open_tag' => 'On'
  831. );
  832. public static $writableFilesAndFolders = array (
  833. 'Configuration File' => './config.inc.php',
  834. 'Tabdata File' => './tabdata.php',
  835. 'Installation File' => './install.php',
  836. 'Parent Tabdata File' => './parent_tabdata.php',
  837. 'Cache Directory' => './cache/',
  838. 'Image Cache Directory' => './cache/images/',
  839. 'Import Cache Directory' => './cache/import/',
  840. 'Storage Directory' => './storage/',
  841. 'Install Directory' => './install/',
  842. 'User Privileges Directory' => './user_privileges/',
  843. 'Smarty Cache Directory' => './Smarty/cache/',
  844. 'Smarty Compile Directory' => './Smarty/templates_c/',
  845. 'Email Templates Directory' => './modules/Emails/templates/',
  846. 'Modules Directory' => './modules/',
  847. 'Cron Modules Directory' => './cron/modules/',
  848. 'Vtlib Test Directory' => './test/vtlib/',
  849. 'Vtlib Test HTML Directory' => './test/vtlib/HTML',
  850. 'Backup Directory' => './backup/',
  851. 'Smarty Modules Directory' => './Smarty/templates/modules/',
  852. 'Mail Merge Template Directory' => './test/wordtemplatedownload/',
  853. 'Product Image Directory' => './test/product/',
  854. 'User Image Directory' => './test/user/',
  855. 'Contact Image Directory' => './test/contact/',
  856. 'Logo Directory' => './test/logo/',
  857. 'Logs Directory' => './logs/',
  858. 'Webmail Attachments Directory' => './modules/Webmails/tmp/'
  859. );
  860. public static $gdInfoAlternate = 'function gd_info() {
  861. $array = Array(
  862. "GD Version" => "",
  863. "FreeType Support" => 0,
  864. "FreeType Support" => 0,
  865. "FreeType Linkage" => "",
  866. "T1Lib Support" => 0,
  867. "GIF Read Support" => 0,
  868. "GIF Create Support" => 0,
  869. "JPG Support" => 0,
  870. "PNG Support" => 0,
  871. "WBMP Support" => 0,
  872. "XBM Support" => 0
  873. );
  874. $gif_support = 0;
  875. ob_start();
  876. eval("phpinfo();");
  877. $info = ob_get_contents();
  878. ob_end_clean();
  879. foreach(explode("\n", $info) as $line) {
  880. if(strpos($line, "GD Version")!==false)
  881. $array["GD Version"] = trim(str_replace("GD Version", "", strip_tags($line)));
  882. if(strpos($line, "FreeType Support")!==false)
  883. $array["FreeType Support"] = trim(str_replace("FreeType Support", "", strip_tags($line)));
  884. if(strpos($line, "FreeType Linkage")!==false)
  885. $array["FreeType Linkage"] = trim(str_replace("FreeType Linkage", "", strip_tags($line)));
  886. if(strpos($line, "T1Lib Support")!==false)
  887. $array["T1Lib Support"] = trim(str_replace("T1Lib Support", "", strip_tags($line)));
  888. if(strpos($line, "GIF Read Support")!==false)
  889. $array["GIF Read Support"] = trim(str_replace("GIF Read Support", "", strip_tags($line)));
  890. if(strpos($line, "GIF Create Support")!==false)
  891. $array["GIF Create Support"] = trim(str_replace("GIF Create Support", "", strip_tags($line)));
  892. if(strpos($line, "GIF Support")!==false)
  893. $gif_support = trim(str_replace("GIF Support", "", strip_tags($line)));
  894. if(strpos($line, "JPG Support")!==false)
  895. $array["JPG Support"] = trim(str_replace("JPG Support", "", strip_tags($line)));
  896. if(strpos($line, "PNG Support")!==false)
  897. $array["PNG Support"] = trim(str_replace("PNG Support", "", strip_tags($line)));
  898. if(strpos($line, "WBMP Support")!==false)
  899. $array["WBMP Support"] = trim(str_replace("WBMP Support", "", strip_tags($line)));
  900. if(strpos($line, "XBM Support")!==false)
  901. $array["XBM Support"] = trim(str_replace("XBM Support", "", strip_tags($line)));
  902. }
  903. if($gif_support==="enabled") {
  904. $array["GIF Read Support"] = 1;
  905. $array["GIF Create Support"] = 1;
  906. }
  907. if($array["FreeType Support"]==="enabled"){
  908. $array["FreeType Support"] = 1; }
  909. if($array["T1Lib Support"]==="enabled")
  910. $array["T1Lib Support"] = 1;
  911. if($array["GIF Read Support"]==="enabled"){
  912. $array["GIF Read Support"] = 1; }
  913. if($array["GIF Create Support"]==="enabled")
  914. $array["GIF Create Support"] = 1;
  915. if($array["JPG Support"]==="enabled")
  916. $array["JPG Support"] = 1;
  917. if($array["PNG Support"]==="enabled")
  918. $array["PNG Support"] = 1;
  919. if($array["WBMP Support"]==="enabled")
  920. $array["WBMP Support"] = 1;
  921. if($array["XBM Support"]==="enabled")
  922. $array["XBM Support"] = 1;
  923. return $array;
  924. }';
  925. function getRecommendedDirectives() {
  926. if(version_compare(PHP_VERSION, '5.3.0') >= 0) {
  927. self::$recommendedDirectives['error_reporting'] = 'E_WARNING & ~E_NOTICE & ~E_DEPRECATED';
  928. }
  929. return self::$recommendedDirectives;
  930. }
  931. /** Function to check the file access is made within web root directory. */
  932. static function checkFileAccess($filepath) {
  933. global $root_directory, $installationStrings;
  934. // Set the base directory to compare with
  935. $use_root_directory = $root_directory;
  936. if(empty($use_root_directory)) {
  937. $use_root_directory = realpath(dirname(__FILE__).'/../../..');
  938. }
  939. $realfilepath = realpath($filepath);
  940. /** Replace all \\ with \ first */
  941. $realfilepath = str_replace('\\\\', '\\', $realfilepath);
  942. $rootdirpath = str_replace('\\\\', '\\', $use_root_directory);
  943. /** Replace all \ with / now */
  944. $realfilepath = str_replace('\\', '/', $realfilepath);
  945. $rootdirpath = str_replace('\\', '/', $rootdirpath);
  946. if(stripos($realfilepath, $rootdirpath) !== 0) {
  947. die($installationStrings['ERR_RESTRICTED_FILE_ACCESS']);
  948. }
  949. }
  950. /** Function to check the file access is made within web root directory. */
  951. static function checkFileAccessForInclusion($filepath) {
  952. global $root_directory, $installationStrings;
  953. // Set the base directory to compare with
  954. $use_root_directory = $root_directory;
  955. if(empty($use_root_directory)) {
  956. $use_root_directory = realpath(dirname(__FILE__).'/../../..');
  957. }
  958. $unsafeDirectories = array('storage', 'cache', 'test');
  959. $realfilepath = realpath($filepath);
  960. /** Replace all \\ with \ first */
  961. $realfilepath = str_replace('\\\\', '\\', $realfilepath);
  962. $rootdirpath = str_replace('\\\\', '\\', $use_root_directory);
  963. /** Replace all \ with / now */
  964. $realfilepath = str_replace('\\', '/', $realfilepath);
  965. $rootdirpath = str_replace('\\', '/', $rootdirpath);
  966. $relativeFilePath = str_replace($rootdirpath, '', $realfilepath);
  967. $filePathParts = explode('/', $relativeFilePath);
  968. if(stripos($realfilepath, $rootdirpath) !== 0 || in_array($filePathParts[0], $unsafeDirectories)) {
  969. die($installationStrings['ERR_RESTRICTED_FILE_ACCESS']);
  970. }
  971. }
  972. static function getFailedPermissionsFiles() {
  973. $writableFilesAndFolders = Common_Install_Wizard_Utils::$writableFilesAndFolders;
  974. $failedPermissions = array();
  975. require_once ('include/utils/VtlibUtils.php');
  976. foreach ($writableFilesAndFolders as $index => $value) {
  977. if (!vtlib_isWriteable($value)) {
  978. $failedPermissions[$index] = $value;
  979. }
  980. }
  981. return $failedPermissions;
  982. }
  983. static function getCurrentDirectiveValue() {
  984. $directiveValues = array();
  985. if (ini_get('safe_mode') == '1' || stripos(ini_get('safe_mode'), 'On') > -1)
  986. $directiveValues['safe_mode'] = 'On';
  987. if (ini_get('display_errors') != '1' || stripos(ini_get('display_errors'), 'Off') > -1)
  988. $directiveValues['display_errors'] = 'Off';
  989. if (ini_get('file_uploads') != '1' || stripos(ini_get('file_uploads'), 'Off') > -1)
  990. $directiveValues['file_uploads'] = 'Off';
  991. if (ini_get('register_globals') == '1' || stripos(ini_get('register_globals'), 'On') > -1)
  992. $directiveValues['register_globals'] = 'On';
  993. if (ini_get(('output_buffering') < '4096' && ini_get('output_buffering') != '0') || stripos(ini_get('output_buffering'), 'Off') > -1)
  994. $directiveValues['output_buffering'] = 'Off';
  995. if (ini_get('max_execution_time') < 600)
  996. $directiveValues['max_execution_time'] = ini_get('max_execution_time');
  997. if (ini_get('memory_limit') < 32)
  998. $directiveValues['memory_limit'] = ini_get('memory_limit');
  999. $errorReportingValue = E_WARNING & ~E_NOTICE;
  1000. if(version_compare(PHP_VERSION, '5.3.0') >= 0) {
  1001. $errorReportingValue = E_WARNING & ~E_NOTICE & ~E_DEPRECATED;
  1002. }
  1003. if (ini_get('error_reporting') != $errorReportingValue)
  1004. $directiveValues['error_reporting'] = 'NOT RECOMMENDED';
  1005. if (ini_get('allow_call_time_pass_reference') != '1' || stripos(ini_get('allow_call_time_pass_reference'), 'Off') > -1)
  1006. $directiveValues['allow_call_time_pass_reference'] = 'Off';
  1007. if (ini_get('log_errors') == '1' || stripos(ini_get('log_errors'), 'On') > -1)
  1008. $directiveValues['log_errors'] = 'On';
  1009. if (ini_get('short_open_tag') != '1' || stripos(ini_get('short_open_tag'), 'Off') > -1)
  1010. $directiveValues['short_open_tag'] = 'Off';
  1011. return $directiveValues;
  1012. }
  1013. // Fix for ticket 6605 : detect mysql extension during installation
  1014. static function check_mysql_extension() {
  1015. if(function_exists('mysql_connect')) {
  1016. $mysql_extension = true;
  1017. }
  1018. else {
  1019. $mysql_extension = false;
  1020. }
  1021. return $mysql_extension;
  1022. }
  1023. static function isMySQL($dbType) {
  1024. return (stripos($dbType ,'mysql') === 0);
  1025. }
  1026. static function isOracle($dbType) {
  1027. return $dbType == 'oci8';
  1028. }
  1029. static function isPostgres($dbType) {
  1030. return $dbType == 'pgsql';
  1031. }
  1032. public static function getInstallableModulesFromPackages() {
  1033. global $optionalModuleStrings;
  1034. require_once('vtlib/Vtiger/Package.php');
  1035. require_once('vtlib/Vtiger/Module.php');
  1036. require_once('vtlib/Vtiger/Version.php');
  1037. $packageDir = 'packages/vtiger/optional/';
  1038. $handle = opendir($packageDir);
  1039. $optionalModules = array();
  1040. while (false !== ($file = readdir($handle))) {
  1041. $packageNameParts = explode(".",$file);
  1042. if($packageNameParts[count($packageNameParts)-1] != 'zip'){
  1043. continue;
  1044. }
  1045. array_pop($packageNameParts);
  1046. $packageName = implode("",$packageNameParts);
  1047. if (!empty($packageName)) {
  1048. $packagepath = "$packageDir/$file";
  1049. $package = new Vtiger_Package();
  1050. $moduleName = $package->getModuleNameFromZip($packagepath);
  1051. if($package->isModuleBundle()) {
  1052. $bundleOptionalModule = array();
  1053. $unzip = new Vtiger_Unzip($packagepath);
  1054. $unzip->unzipAllEx($package->getTemporaryFilePath());
  1055. $moduleInfoList = $package->getAvailableModuleInfoFromModuleBundle();
  1056. foreach($moduleInfoList as $moduleInfo) {
  1057. $moduleInfo = (Array)$moduleInfo;
  1058. $packagepath = $package->getTemporaryFilePath($moduleInfo['filepath']);
  1059. $subModule = new Vtiger_Package();
  1060. $subModule->getModuleNameFromZip($packagepath);
  1061. $bundleOptionalModule = self::getOptionalModuleDetails($subModule,
  1062. $bundleOptionalModule);
  1063. }
  1064. $moduleDetails = array();
  1065. $moduleDetails['description'] = $optionalModuleStrings[$moduleName.'_description'];
  1066. $moduleDetails['selected'] = true;
  1067. $moduleDetails['enabled'] = true;
  1068. $migrationAction = 'install';
  1069. if(count($bundleOptionalModule['update']) > 0 ) {
  1070. $moduleDetails['enabled'] = false;
  1071. $migrationAction = 'update';
  1072. }
  1073. $optionalModules[$migrationAction]['module'][$moduleName] = $moduleDetails;
  1074. } else {
  1075. if($package->isLanguageType()) {
  1076. $package = new Vtiger_Language();
  1077. $package->getModuleNameFromZip($packagepath);
  1078. }
  1079. $optionalModules = self::getOptionalModuleDetails($p

Large files files are truncated, but you can click here to view the full file