function preflightCheckJsonDiffFiles($persistence) { global $sugar_version; global $mod_strings; if (empty($sugar_version)) { require 'sugar_version.php'; } // get md5 sums $md5_string = array(); $finalZipDir = $persistence['unzip_dir'] . '/' . $persistence['zip_from_dir']; if (is_file(getcwd() . '/files.md5')) { require getcwd() . '/files.md5'; } // initialize pass array $manualDiff = array(); // file preflight checks logThis('verifying md5 checksums for files...'); $cache_html_files = findAllFilesRelative(sugar_cached("layout"), array()); foreach ($persistence['upgrade_files'] as $file) { if (strpos($file, '.md5')) { continue; } // skip md5 file // normalize file paths $file = clean_path($file); // check that we can move/delete the upgraded file if (!is_writable($file)) { $errors[] = $mod_strings['ERR_UW_FILE_NOT_WRITABLE'] . ": " . $file; } // check that destination files are writable $destFile = getcwd() . str_replace($finalZipDir, '', $file); if (is_file($destFile)) { // of course it needs to exist first... if (!is_writable($destFile)) { $errors[] = $mod_strings['ERR_UW_FILE_NOT_WRITABLE'] . ": " . $destFile; } } /////////////////////////////////////////////////////////////////////// //// DIFFS // compare md5s and build up a manual merge list $targetFile = clean_path("." . str_replace(getcwd(), '', $destFile)); $targetMd5 = '0'; if (is_file($destFile)) { if (strpos($targetFile, '.php')) { // handle PHP files that were hit with the security regex $filesize = filesize($destFile); if ($filesize > 0) { $fileContents = file_get_contents($destFile); $targetMd5 = md5($fileContents); } } else { $targetMd5 = md5_file($destFile); } } if (isset($md5_string[$targetFile]) && $md5_string[$targetFile] != $targetMd5) { logThis('found a file with a differing md5: [' . $targetFile . ']'); $manualDiff[] = $destFile; } //// END DIFFS /////////////////////////////////////////////////////////////////////// echo "."; } logThis('md5 verification done.'); $persistence['manual'] = $manualDiff; $persistence['diff_errors'] = $errors; return $persistence; }
echo $mod_strings['LBL_ML_CANCEL']; ?> " class="button" onClick="location.href='index.php?module=Administration&action=UpgradeWizard&view=module';"/> <?php if ($remove_tables == 'prompt' && $mode == 'Uninstall') { print "<br/><br/>"; print "<input type='radio' id='remove_tables_true' name='remove_tables' value='true' checked>" . $mod_strings['ML_LBL_REMOVE_TABLES'] . " "; print "<input type='radio' id='remove_tables_false' name='remove_tables' value='false'>" . $mod_strings['ML_LBL_DO_NOT_REMOVE_TABLES'] . "<br>"; } $count = 0; if ($show_files == true) { $count = 0; $new_studio_mod_files = array(); $new_sugar_mod_files = array(); $cache_html_files = findAllFilesRelative(sugar_cached("layout"), array()); foreach ($new_files as $the_file) { if (substr(strtolower($the_file), -5, 5) == '.html' && in_array($the_file, $cache_html_files)) { array_push($new_studio_mod_files, $the_file); } else { array_push($new_sugar_mod_files, $the_file); } } echo '<script> function toggle_these(start, end, ca) { while(start < end) { elem = eval("document.forms.files.copy_" + start); if(!ca.checked) elem.checked = false; else elem.checked = true; start++; }
foreach ($script_files as $script_name => $script_filename) { if (is_file("{$unzip_dir}/{$script_filename}")) { //echo "Found {$script_name} script: <i>{$script_filename}</i><br>"; } } ?> <p> <?php $count = 0; if ($show_files == true) { $count = 0; $new_studio_mod_files = array(); $new_sugar_mod_files = array(); $cache_html_files = findAllFilesRelative("cache/layout", array()); foreach ($new_files as $the_file) { if (substr(strtolower($the_file), -5, 5) == '.html' && in_array($the_file, $cache_html_files)) { array_push($new_studio_mod_files, $the_file); } else { array_push($new_sugar_mod_files, $the_file); } } echo '<script> function toggle_these(start, end, ca) { while(start < end) { elem = eval("document.forms.files.copy_" + start); if(!ca.checked) elem.checked = false; else elem.checked = true; start++; }
echo $mod_strings['LBL_ML_CANCEL']; ?> " class="button" onClick="location.href='index.php?module=Administration&action=UpgradeWizard&view=module';"/> <?php if ($remove_tables == 'prompt' && $mode == 'Uninstall') { print "<br/><br/>"; print "<input type='radio' id='remove_tables_true' name='remove_tables' value='true' checked>" . $mod_strings['ML_LBL_REMOVE_TABLES'] . " "; print "<input type='radio' id='remove_tables_false' name='remove_tables' value='false'>" . $mod_strings['ML_LBL_DO_NOT_REMOVE_TABLES'] . "<br>"; } $count = 0; if ($show_files == true) { $count = 0; $new_studio_mod_files = array(); $new_sugar_mod_files = array(); $cache_html_files = findAllFilesRelative("{$GLOBALS['sugar_config']['cache_dir']}layout", array()); foreach ($new_files as $the_file) { if (substr(strtolower($the_file), -5, 5) == '.html' && in_array($the_file, $cache_html_files)) { array_push($new_studio_mod_files, $the_file); } else { array_push($new_sugar_mod_files, $the_file); } } echo '<script> function toggle_these(start, end, ca) { while(start < end) { elem = eval("document.forms.files.copy_" + start); if(!ca.checked) elem.checked = false; else elem.checked = true; start++; }
function preflightCheck() { require_once 'modules/UpgradeWizard/uw_files.php'; global $sugar_config; global $mod_strings; global $sugar_version; if (!isset($sugar_version) || empty($sugar_version)) { require_once './sugar_version.php'; } unset($_SESSION['rebuild_relationships']); unset($_SESSION['rebuild_extensions']); // don't bother if are rechecking $manualDiff = array(); if (!isset($_SESSION['unzip_dir']) || empty($_SESSION['unzip_dir'])) { logThis('unzipping files in upgrade archive...'); $errors = array(); $base_upgrade_dir = $sugar_config['upload_dir'] . "/upgrades"; $base_tmp_upgrade_dir = "{$base_upgrade_dir}/temp"; $install_file = urldecode($_SESSION['install_file']); $show_files = true; $unzip_dir = mk_temp_dir($base_tmp_upgrade_dir); $zip_from_dir = "."; $zip_to_dir = "."; $zip_force_copy = array(); unzip($install_file, $unzip_dir); // assumption -- already validated manifest.php at time of upload require_once "{$unzip_dir}/manifest.php"; if (isset($manifest['copy_files']['from_dir']) && $manifest['copy_files']['from_dir'] != "") { $zip_from_dir = $manifest['copy_files']['from_dir']; } if (isset($manifest['copy_files']['to_dir']) && $manifest['copy_files']['to_dir'] != "") { $zip_to_dir = $manifest['copy_files']['to_dir']; } if (isset($manifest['copy_files']['force_copy']) && $manifest['copy_files']['force_copy'] != "") { $zip_force_copy = $manifest['copy_files']['force_copy']; } if (isset($manifest['version'])) { $version = $manifest['version']; } if (!is_writable("config.php")) { return $mod_strings['ERR_UW_CONFIG']; } $_SESSION['unzip_dir'] = clean_path($unzip_dir); $_SESSION['zip_from_dir'] = clean_path($zip_from_dir); logThis('unzip done.'); } else { $unzip_dir = $_SESSION['unzip_dir']; $zip_from_dir = $_SESSION['zip_from_dir']; } $upgradeFiles = findAllFiles(clean_path("{$unzip_dir}/{$zip_from_dir}"), array()); $cache_html_files = findAllFilesRelative("cache/layout", array()); // get md5 sums $md5_string = array(); if (file_exists(clean_path(getcwd() . '/files.md5'))) { require clean_path(getcwd() . '/files.md5'); } // file preflight checks logThis('verifying md5 checksums for files...'); foreach ($upgradeFiles as $file) { if (in_array(str_replace(clean_path("{$unzip_dir}/{$zip_from_dir}") . "/", '', $file), $uw_files)) { continue; } // skip already loaded files if (strpos($file, '.md5')) { continue; } // skip md5 file // normalize file paths $file = clean_path($file); // check that we can move/delete the upgraded file if (!is_writable($file)) { $errors[] = $mod_strings['ERR_UW_FILE_NOT_WRITABLE'] . ": " . $file; } // check that destination files are writable $destFile = getcwd() . str_replace(clean_path($unzip_dir . '/' . $zip_from_dir), '', $file); if (is_file($destFile)) { // of course it needs to exist first... if (!is_writable($destFile)) { $errors[] = $mod_strings['ERR_UW_FILE_NOT_WRITABLE'] . ": " . $destFile; } } /////////////////////////////////////////////////////////////////////// //// DIFFS // <= 4.0.1, use cache/layout files to compare if (version_compare($sugar_version, '4.0.1', '<=')) { $relativeFile = str_replace(getcwd(), './', $file); if (substr(strtolower($relativeFile), -5, 5) == '.html' && in_array($relativeFile, $cache_html_files)) { $manualDiff[] = $file; logThis('found a cache file template to preserve: [' . $file . ']'); } } else { // compare md5s and build up a manual merge list $targetFile = clean_path("." . str_replace(getcwd(), '', $destFile)); $targetMd5 = '0'; if (is_file($destFile)) { if (strpos($targetFile, '.php')) { // handle PHP files that were hit with the security regex $fp = fopen($destFile, 'r'); $filesize = filesize($destFile); if ($filesize > 0) { $fileContents = fread($fp, $filesize); $targetMd5 = md5($fileContents); } } else { $targetMd5 = md5_file($destFile); } } if (isset($md5_string[$targetFile]) && $md5_string[$targetFile] != $targetMd5) { logThis('found a file with a differing md5: [' . $targetFile . ']'); $manualDiff[] = $destFile; } } //// END DIFFS /////////////////////////////////////////////////////////////////////// } logThis('md5 verification done.'); $errors['manual'] = $manualDiff; return $errors; }