PageRenderTime 27ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/Administration/UpgradeWizard.php

https://gitlab.com/tjaafar/SuiteCRM
PHP | 356 lines | 187 code | 33 blank | 136 comment | 64 complexity | 305fff9018ec4629f2b9a04b61e23c71 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. require_once('modules/Administration/UpgradeWizardCommon.php');
  40. require_once('ModuleInstall/PackageManager/PackageManagerDisplay.php');
  41. require_once('ModuleInstall/ModuleScanner.php');
  42. global $mod_strings;
  43. $uh = new UpgradeHistory();
  44. function unlinkTempFiles() {
  45. global $sugar_config;
  46. @unlink($_FILES['upgrade_zip']['tmp_name']);
  47. @unlink("upload://".$_FILES['upgrade_zip']['name']);
  48. }
  49. $base_upgrade_dir = "upload://upgrades";
  50. $base_tmp_upgrade_dir = sugar_cached('upgrades/temp');
  51. // make sure dirs exist
  52. foreach( $GLOBALS['subdirs'] as $subdir ){
  53. if(!file_exists("$base_upgrade_dir/$subdir")) {
  54. sugar_mkdir("$base_upgrade_dir/$subdir", 0770, true);
  55. }
  56. }
  57. // get labels and text that are specific to either Module Loader or Upgrade Wizard
  58. if( $view == "module") {
  59. $uploaddLabel = $mod_strings['LBL_UW_UPLOAD_MODULE'];
  60. $descItemsQueued = $mod_strings['LBL_UW_DESC_MODULES_QUEUED'];
  61. $descItemsInstalled = $mod_strings['LBL_UW_DESC_MODULES_INSTALLED'];
  62. }
  63. else {
  64. $uploaddLabel = $mod_strings['LBL_UPLOAD_UPGRADE'];
  65. $descItemsQueued = $mod_strings['DESC_FILES_QUEUED'];
  66. $descItemsInstalled = $mod_strings['DESC_FILES_INSTALLED'];
  67. }
  68. //
  69. // check that the upload limit is set to 6M or greater
  70. //
  71. define('SUGARCRM_MIN_UPLOAD_MAX_FILESIZE_BYTES', 6 * 1024 * 1024); // 6 Megabytes
  72. $upload_max_filesize = ini_get('upload_max_filesize');
  73. $upload_max_filesize_bytes = return_bytes($upload_max_filesize);
  74. if($upload_max_filesize_bytes < constant('SUGARCRM_MIN_UPLOAD_MAX_FILESIZE_BYTES'))
  75. {
  76. $GLOBALS['log']->debug("detected upload_max_filesize: $upload_max_filesize");
  77. print('<p class="error">' . $mod_strings['MSG_INCREASE_UPLOAD_MAX_FILESIZE'] . ' '
  78. . get_cfg_var('cfg_file_path') . "</p>\n");
  79. }
  80. //
  81. // process "run" commands
  82. //
  83. if( isset( $_REQUEST['run'] ) && ($_REQUEST['run'] != "") ){
  84. $run = $_REQUEST['run'];
  85. if( $run == "upload" ){
  86. $perform = false;
  87. if(isset($_REQUEST['release_id']) && $_REQUEST['release_id'] != ""){
  88. require_once('ModuleInstall/PackageManager.php');
  89. $pm = new PackageManager();
  90. $tempFile = $pm->download('','',$_REQUEST['release_id']);
  91. $perform = true;
  92. $base_filename = urldecode($tempFile);
  93. } elseif(!empty($_REQUEST['load_module_from_dir'])) {
  94. //copy file to proper location then call performSetup
  95. copy($_REQUEST['load_module_from_dir'].'/'.$_REQUEST['upgrade_zip_escaped'], "upload://".$_REQUEST['upgrade_zip_escaped']);
  96. $perform = true;
  97. $base_filename = urldecode( $_REQUEST['upgrade_zip_escaped'] );
  98. } else {
  99. if( empty( $_FILES['upgrade_zip']['tmp_name'] ) ){
  100. echo $mod_strings['ERR_UW_NO_UPLOAD_FILE'];
  101. } else{
  102. $upload = new UploadFile('upgrade_zip');
  103. if(!$upload->confirm_upload() ||
  104. strtolower(pathinfo($upload->get_stored_file_name(), PATHINFO_EXTENSION)) != 'zip' ||
  105. !$upload->final_move($upload->get_stored_file_name())
  106. ) {
  107. unlinkTempFiles();
  108. sugar_die("Invalid Package");
  109. } else {
  110. $tempFile = "upload://".$upload->get_stored_file_name();
  111. $perform = true;
  112. $base_filename = urldecode( $_REQUEST['upgrade_zip_escaped'] );
  113. }
  114. }
  115. }
  116. if($perform) {
  117. $manifest_file = extractManifest( $tempFile );
  118. if(is_file($manifest_file))
  119. {
  120. //SCAN THE MANIFEST FILE TO MAKE SURE NO COPIES OR ANYTHING ARE HAPPENING IN IT
  121. $ms = new ModuleScanner();
  122. $ms->lockConfig();
  123. $fileIssues = $ms->scanFile($manifest_file);
  124. if(!empty($fileIssues)){
  125. echo '<h2>' . $mod_strings['ML_MANIFEST_ISSUE'] . '</h2><br>';
  126. $ms->displayIssues();
  127. die();
  128. }
  129. list($manifest, $installdefs) = MSLoadManifest($manifest_file);
  130. if($ms->checkConfig($manifest_file)) {
  131. echo '<h2>' . $mod_strings['ML_MANIFEST_ISSUE'] . '</h2><br>';
  132. $ms->displayIssues();
  133. die();
  134. }
  135. validate_manifest( $manifest );
  136. $upgrade_zip_type = $manifest['type'];
  137. // exclude the bad permutations
  138. if( $view == "module" ) {
  139. if ($upgrade_zip_type != "module" && $upgrade_zip_type != "theme" && $upgrade_zip_type != "langpack") {
  140. unlinkTempFiles();
  141. die($mod_strings['ERR_UW_NOT_ACCEPTIBLE_TYPE']);
  142. }
  143. } elseif( $view == "default" ) {
  144. if($upgrade_zip_type != "patch" ) {
  145. unlinkTempFiles();
  146. die($mod_strings['ERR_UW_ONLY_PATCHES']);
  147. }
  148. }
  149. $base_filename = pathinfo($tempFile, PATHINFO_BASENAME);
  150. mkdir_recursive( "$base_upgrade_dir/$upgrade_zip_type" );
  151. $target_path = "$base_upgrade_dir/$upgrade_zip_type/$base_filename";
  152. $target_manifest = remove_file_extension( $target_path ) . "-manifest.php";
  153. if( isset($manifest['icon']) && $manifest['icon'] != "" ){
  154. $icon_location = extractFile( $tempFile ,$manifest['icon'] );
  155. copy($icon_location, remove_file_extension( $target_path )."-icon.".pathinfo($icon_location, PATHINFO_EXTENSION));
  156. }
  157. if(rename( $tempFile , $target_path )) {
  158. copy( $manifest_file, $target_manifest );
  159. $GLOBALS['ML_STATUS_MESSAGE'] = $base_filename.$mod_strings['LBL_UW_UPLOAD_SUCCESS'];
  160. } else{
  161. $GLOBALS['ML_STATUS_MESSAGE'] = $mod_strings['ERR_UW_UPLOAD_ERROR'];
  162. }
  163. } else {
  164. unlinkTempFiles();
  165. die($mod_strings['ERR_UW_NO_MANIFEST']);
  166. }
  167. }
  168. } else if( $run == $mod_strings['LBL_UW_BTN_DELETE_PACKAGE'] ){
  169. if(!empty ($_REQUEST['install_file']) ){
  170. die($mod_strings['ERR_UW_NO_UPLOAD_FILE']);
  171. }
  172. $delete_me = hashToFile($delete_me);
  173. $checkFile = strtolower($delete_me);
  174. if(substr($delete_me, -4) != ".zip" || substr($delete_me, 0, 9) != "upload://" ||
  175. strpos($checkFile, "..") !== false || !file_exists($checkFile)) {
  176. die("<span class='error'>File is not a zipped archive.</span>");
  177. }
  178. if(unlink($delete_me)) { // successful deletion?
  179. echo "Package $delete_me has been removed.<br>";
  180. } else {
  181. die("Problem removing package $delete_me.");
  182. }
  183. }
  184. }
  185. if( $view == "module") {
  186. print( getClassicModuleTitle($mod_strings['LBL_MODULE_NAME'], array($mod_strings['LBL_MODULE_LOADER_TITLE']), false) );
  187. }
  188. else {
  189. print( getClassicModuleTitle($mod_strings['LBL_MODULE_NAME'], array($mod_strings['LBL_MODULE_NAME'],$mod_strings['LBL_UPGRADE_WIZARD_TITLE']), false) );
  190. }
  191. // upload link
  192. if(!empty($GLOBALS['sugar_config']['use_common_ml_dir']) && $GLOBALS['sugar_config']['use_common_ml_dir'] && !empty($GLOBALS['sugar_config']['common_ml_dir'])){
  193. //rrs
  194. $form = '<form name="move_form" action="index.php?module=Administration&view=module&action=UpgradeWizard" method="post" ><input type=hidden name="run" value="upload" /><input type=hidden name="load_module_from_dir" id="load_module_from_dir" value="'.$GLOBALS['sugar_config']['common_ml_dir'].'" /><input type=hidden name="upgrade_zip_escaped" value="" />';
  195. $form .= '<br>'.$mod_strings['LBL_MODULE_UPLOAD_DISABLE_HELP_TEXT'].'</br>';
  196. $form .='<table width="100%" class="edit view"><tr><th align="left">'.$mod_strings['LBL_ML_NAME'].'</th><th align="left">'.$mod_strings['LBL_ML_ACTION'].'</th></tr>';
  197. if ($handle = opendir($GLOBALS['sugar_config']['common_ml_dir'])) {
  198. while (false !== ($filename = readdir($handle))) {
  199. if($filename == '.' || $filename == '..' || !preg_match("#.*\.zip\$#", $filename)) {
  200. continue;
  201. }
  202. $form .= '<tr><td>'.$filename.'</td><td><input type=button class="button" value="'.$mod_strings['LBL_UW_BTN_UPLOAD'].'" onClick="document.move_form.upgrade_zip_escaped.value = escape( \''.$filename.'\');document.move_form.submit();" /></td></tr>';
  203. }
  204. }
  205. $form .= '</table></form>';
  206. //rrs
  207. }else{
  208. $form =<<<eoq
  209. <form name="the_form" enctype="multipart/form-data" action="{$form_action}" method="post" >
  210. <table width="100%" border="0" cellspacing="0" cellpadding="0" class="edit view">
  211. <tr><td>
  212. <table width="450" border="0" cellspacing="0" cellpadding="0">
  213. <tr><td style="white-space:nowrap; padding-right: 10px !important;">
  214. {$uploaddLabel}
  215. <input type="file" name="upgrade_zip" size="40" />
  216. </td>
  217. <td>
  218. <input type=button class="button" value="{$mod_strings['LBL_UW_BTN_UPLOAD']}" onClick="document.the_form.upgrade_zip_escaped.value = escape( document.the_form.upgrade_zip.value );document.the_form.submit();" />
  219. <input type=hidden name="run" value="upload" />
  220. <input type=hidden name="upgrade_zip_escaped" value="" />
  221. </td>
  222. </tr>
  223. </table></td></tr></table>
  224. </form>
  225. eoq;
  226. }
  227. $hidden_fields = "<input type=hidden name=\"run\" value=\"upload\" />";
  228. $hidden_fields .= "<input type=hidden name=\"mode\"/>";
  229. $form2 = PackageManagerDisplay::buildPackageDisplay($form, $hidden_fields, $form_action, array('module'));
  230. $form3 =<<<eoq3
  231. eoq3;
  232. echo $form2.$form3;
  233. // scan for new files (that are not installed)
  234. /*print( "$descItemsQueued<br>\n");
  235. print( "<ul>\n" );
  236. $upgrade_contents = findAllFiles( "$base_upgrade_dir", array() );
  237. $upgrades_available = 0;
  238. print( "<table>\n" );
  239. print( "<tr><th></th><th align=left>{$mod_strings['LBL_ML_NAME']}</th><th>{$mod_strings['LBL_ML_TYPE']}</th><th>{$mod_strings['LBL_ML_VERSION']}</th><th>{$mod_strings['LBL_ML_PUBLISHED']}</th><th>{$mod_strings['LBL_ML_UNINSTALLABLE']}</th><th>{$mod_strings['LBL_ML_DESCRIPTION']}</th></tr>\n" );
  240. foreach($upgrade_contents as $upgrade_content)
  241. {
  242. if(!preg_match("#.*\.zip\$#", $upgrade_content))
  243. {
  244. continue;
  245. }
  246. $upgrade_content = clean_path($upgrade_content);
  247. $the_base = basename($upgrade_content);
  248. $the_md5 = md5_file($upgrade_content);
  249. $md5_matches = $uh->findByMd5($the_md5);
  250. if(0 == sizeof($md5_matches))
  251. {
  252. $target_manifest = remove_file_extension( $upgrade_content ) . '-manifest.php';
  253. require_once($target_manifest);
  254. $name = empty($manifest['name']) ? $upgrade_content : $manifest['name'];
  255. $version = empty($manifest['version']) ? '' : $manifest['version'];
  256. $published_date = empty($manifest['published_date']) ? '' : $manifest['published_date'];
  257. $icon = '';
  258. $description = empty($manifest['description']) ? 'None' : $manifest['description'];
  259. $uninstallable = empty($manifest['is_uninstallable']) ? 'No' : 'Yes';
  260. $type = getUITextForType( $manifest['type'] );
  261. $manifest_type = $manifest['type'];
  262. if($view == 'default' && $manifest_type != 'patch')
  263. {
  264. continue;
  265. }
  266. if($view == 'module'
  267. && $manifest_type != 'module' && $manifest_type != 'theme' && $manifest_type != 'langpack')
  268. {
  269. continue;
  270. }
  271. if(empty($manifest['icon']))
  272. {
  273. $icon = getImageForType( $manifest['type'] );
  274. }
  275. else
  276. {
  277. $path_parts = pathinfo( $manifest['icon'] );
  278. $icon = "<!--not_in_theme!--><img src=\"" . remove_file_extension( $upgrade_content ) . "-icon." . $path_parts['extension'] . "\" alt =''>";
  279. }
  280. $upgrades_available++;
  281. print( "<tr><td>$icon</td><td>$name</td><td>$type</td><td>$version</td><td>$published_date</td><td>$uninstallable</td><td>$description</td>\n" );
  282. $upgrade_content = urlencode($upgrade_content);
  283. $form2 =<<<eoq
  284. <form action="{$form_action}_prepare" method="post">
  285. <td><input type=submit name="btn_mode" onclick="this.form.mode.value='Install';this.form.submit();" value="{$mod_strings['LBL_UW_BTN_INSTALL']}" /></td>
  286. <input type=hidden name="install_file" value="{$upgrade_content}" />
  287. <input type=hidden name="mode"/>
  288. </form>
  289. <form action="{$form_action}" method="post">
  290. <td><input type=submit name="run" value="{$mod_strings['LBL_UW_BTN_DELETE_PACKAGE']}" /></td>
  291. <input type=hidden name="install_file" value="{$upgrade_content}" />
  292. </form>
  293. </tr>
  294. eoq;
  295. echo $form2;
  296. }
  297. }
  298. print( "</table>\n" );
  299. if( $upgrades_available == 0 ){
  300. print($mod_strings['LBL_UW_NONE']);
  301. }
  302. print( "</ul>\n" );
  303. ?>
  304. */
  305. $GLOBALS['log']->info( "Upgrade Wizard view");
  306. ?>
  307. </td>
  308. </tr>
  309. </table></td></tr></table>