Beispiel #1
0
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
 ********************************************************************************/
/*********************************************************************************
 * Description:
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. All Rights
 * Reserved. Contributor(s): ______________________________________..
 * *******************************************************************************/
logThis('-----------------------------------------------------------------------------');
logThis('Upgrade started. At start.php');
//set the upgrade progress status.
set_upgrade_progress('start', 'in_progress');
unlinkUWTempFiles();
resetUwSession();
if (isset($_REQUEST['showUpdateWizardMessage']) && $_REQUEST['showUpdateWizardMessage'] == true) {
    // set a flag to skip the upload screen
    $_SESSION['skip_zip_upload'] = true;
    $newUWMsg = <<<eoq
\t<table cellspacing="0" cellpadding="3" border="0">
\t\t<tr>
\t\t\t<th>
\t\t\t\t{$mod_strings['LBL_UW_START_UPGRADED_UW_TITLE']}
\t\t\t</th>
\t\t</tr>
\t\t<tr>
\t\t\t<td>
\t\t\t\t{$mod_strings['LBL_UW_START_UPGRADED_UW_DESC']}
\t\t\t</td>
\t\t</tr>
Beispiel #2
0
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();
        list($base_upgrade_dir, $base_tmp_upgrade_dir) = getUWDirs();
        $unzip_dir = '';
        //Following is if User logged out unexpectedly and then logged into UpgradeWizard again.
        //also come up with mechanism to read from upgrade-progress file.
        if (!isset($_SESSION['install_file']) || empty($_SESSION['install_file']) || !is_file($_SESSION['install_file'])) {
            if (file_exists($base_tmp_upgrade_dir) && ($handle = opendir($base_tmp_upgrade_dir))) {
                while (false !== ($file = readdir($handle))) {
                    if ($file != "." && $file != "..") {
                        if (is_file($base_tmp_upgrade_dir . "/" . $file . "/manifest.php")) {
                            require_once $base_tmp_upgrade_dir . "/" . $file . "/manifest.php";
                            $package_name = $manifest['copy_files']['from_dir'];
                            if (file_exists($base_tmp_upgrade_dir . "/" . $file . "/" . $package_name) && file_exists($base_tmp_upgrade_dir . "/" . $file . "/scripts") && file_exists($base_tmp_upgrade_dir . "/" . $file . "/manifest.php")) {
                                $unzip_dir = $base_tmp_upgrade_dir . "/" . $file;
                                if (file_exists("{$base_upgrade_dir}/patch/" . $package_name . '.zip')) {
                                    $_SESSION['install_file'] = $package_name . ".zip";
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (empty($_SESSION['install_file'])) {
            unlinkUWTempFiles();
            resetUwSession();
            echo 'Upload File not found so redirecting to Upgrade Start ';
            $redirect_new_wizard = $sugar_config['site_url'] . '/index.php?module=UpgradeWizard&action=index';
            echo '<form name="redirect" action="' . $redirect_new_wizard . '"  method="POST">';
            $upgrade_directories_not_found = <<<eoq
\t<table cellpadding="3" cellspacing="0" border="0">
\t\t<tr>
\t\t\t<th colspan="2" align="left">
\t\t\t\t<span class='error'><b>'Upload file missing or has been deleted. Refresh the page to go back to UpgradeWizard start'</b></span>
\t\t\t</th>
\t\t</tr>
\t</table>
eoq;
            $uwMain = $upgrade_directories_not_found;
            return '';
        }
        $install_file = "{$base_upgrade_dir}/patch/" . basename(urldecode($_SESSION['install_file']));
        $show_files = true;
        if (empty($unzip_dir)) {
            $unzip_dir = mk_temp_dir($base_tmp_upgrade_dir);
        }
        $zip_from_dir = ".";
        $zip_to_dir = ".";
        $zip_force_copy = array();
        if (!$unzip_dir) {
            logThis('Could not create a temporary directory using mk_temp_dir( $base_tmp_upgrade_dir )');
            die($mod_strings['ERR_UW_NO_CREATE_TMP_DIR']);
        }
        //double check whether unzipped .
        if (file_exists($unzip_dir . "/scripts") && file_exists($unzip_dir . "/manifest.php")) {
            //already unzipped
        } else {
            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'];
    }
    //check if $_SESSION['unzip_dir'] and $_SESSION['zip_from_dir'] exist
    if (!isset($_SESSION['unzip_dir']) || !file_exists($_SESSION['unzip_dir']) || !isset($_SESSION['install_file']) || empty($_SESSION['install_file']) || !file_exists($_SESSION['install_file'])) {
        //redirect to start
        unlinkUWTempFiles();
        resetUwSession();
        echo 'Upload File not found so redirecting to Upgrade Start ';
        $redirect_new_wizard = $sugar_config['site_url'] . '/index.php?module=UpgradeWizard&action=index';
        echo '<form name="redirect" action="' . $redirect_new_wizard . '"  method="POST">';
        $upgrade_directories_not_found = <<<eoq
\t<table cellpadding="3" cellspacing="0" border="0">
\t\t<tr>
\t\t\t<th colspan="2" align="left">
\t\t\t\t<span class='error'><b>'Upload file missing or has been deleted. Refresh the page to go back to UpgradeWizard start'</b></span>
\t\t\t</th>
\t\t</tr>
\t</table>
eoq;
        $uwMain = $upgrade_directories_not_found;
        return '';
    }
    //copy minimum required files
    fileCopy('include/utils/sugar_file_utils.php');
    $upgradeFiles = findAllFiles(clean_path("{$unzip_dir}/{$zip_from_dir}"), array());
    $cache_html_files = 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
        // 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 = '';
                if (function_exists('sugar_fopen')) {
                    $fp = sugar_fopen($destFile, 'r');
                } else {
                    $fp = fopen($destFile, 'r');
                }
                $filesize = filesize($destFile);
                if ($filesize > 0) {
                    $fileContents = stream_get_contents($fp);
                    $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;
}