Esempio n. 1
0
function packageRequireFTP($destination_url, $files = null, $return = false)
{
    global $context, $modSettings, $package_ftp, $boarddir, $txt;
    // Try to make them writable the manual way.
    if ($files !== null) {
        foreach ($files as $k => $file) {
            // If this file doesn't exist, then we actually want to look at the directory, no?
            if (!file_exists($file)) {
                $file = dirname($file);
            }
            // This looks odd, but it's an attempt to work around PHP suExec.
            if (!@is_writable($file)) {
                @chmod($file, 0755);
            }
            if (!@is_writable($file)) {
                @chmod($file, 0777);
            }
            if (!@is_writable(dirname($file))) {
                @chmod($file, 0755);
            }
            if (!@is_writable(dirname($file))) {
                @chmod($file, 0777);
            }
            $fp = is_dir($file) ? @opendir($file) : @fopen($file, 'rb');
            if (@is_writable($file) && $fp) {
                unset($files[$k]);
                if (!is_dir($file)) {
                    fclose($fp);
                } else {
                    closedir($fp);
                }
            }
        }
        // No FTP required!
        if (empty($files)) {
            return array();
        }
    }
    // They've opted to not use FTP, and try anyway.
    if (isset($_SESSION['pack_ftp']) && $_SESSION['pack_ftp'] == false) {
        if ($files === null) {
            return array();
        }
        foreach ($files as $k => $file) {
            // This looks odd, but it's an attempt to work around PHP suExec.
            if (!file_exists($file)) {
                mktree(dirname($file), 0755);
                @touch($file);
                @chmod($file, 0755);
            }
            if (!@is_writable($file)) {
                @chmod($file, 0777);
            }
            if (!@is_writable(dirname($file))) {
                @chmod(dirname($file), 0777);
            }
            if (@is_writable($file)) {
                unset($files[$k]);
            }
        }
        return $files;
    } elseif (isset($_SESSION['pack_ftp'])) {
        // Load the file containing the ftp_connection class.
        loadClassFile('Class-Package.php');
        $package_ftp = new ftp_connection($_SESSION['pack_ftp']['server'], $_SESSION['pack_ftp']['port'], $_SESSION['pack_ftp']['username'], package_crypt($_SESSION['pack_ftp']['password']));
        if ($files === null) {
            return array();
        }
        foreach ($files as $k => $file) {
            $ftp_file = strtr($file, array($_SESSION['pack_ftp']['root'] => ''));
            // This looks odd, but it's an attempt to work around PHP suExec.
            if (!file_exists($file)) {
                mktree(dirname($file), 0755);
                $package_ftp->create_file($ftp_file);
                $package_ftp->chmod($ftp_file, 0755);
            }
            if (!@is_writable($file)) {
                $package_ftp->chmod($ftp_file, 0777);
            }
            if (!@is_writable(dirname($file))) {
                $package_ftp->chmod(dirname($ftp_file), 0777);
            }
            if (@is_writable($file)) {
                unset($files[$k]);
            }
        }
        return $files;
    }
    if (isset($_POST['ftp_none'])) {
        $_SESSION['pack_ftp'] = false;
        $files = packageRequireFTP($destination_url, $files, $return);
        return $files;
    } elseif (isset($_POST['ftp_username'])) {
        loadClassFile('Class-Package.php');
        $ftp = new ftp_connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']);
        if ($ftp->error === false) {
            // Common mistake, so let's try to remedy it...
            if (!$ftp->chdir($_POST['ftp_path'])) {
                $ftp_error = $ftp->last_message;
                $ftp->chdir(preg_replace('~^/home[2]?/[^/]+?~', '', $_POST['ftp_path']));
            }
        }
    }
    if (!isset($ftp) || $ftp->error !== false) {
        if (!isset($ftp)) {
            loadClassFile('Class-Package.php');
            $ftp = new ftp_connection(null);
        } elseif ($ftp->error !== false && !isset($ftp_error)) {
            $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
        }
        list($username, $detect_path, $found_path) = $ftp->detect_path($boarddir);
        if ($found_path) {
            $_POST['ftp_path'] = $detect_path;
        } elseif (!isset($_POST['ftp_path'])) {
            $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
        }
        if (!isset($_POST['ftp_username'])) {
            $_POST['ftp_username'] = $username;
        }
        $context['package_ftp'] = array('server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'), 'port' => isset($_POST['ftp_port']) ? $_POST['ftp_port'] : (isset($modSettings['package_port']) ? $modSettings['package_port'] : '21'), 'username' => isset($_POST['ftp_username']) ? $_POST['ftp_username'] : (isset($modSettings['package_username']) ? $modSettings['package_username'] : ''), 'path' => $_POST['ftp_path'], 'error' => empty($ftp_error) ? null : $ftp_error, 'destination' => $destination_url);
        // If we're returning dump out here.
        if ($return) {
            return $files;
        }
        $context['page_title'] = $txt['package_ftp_necessary'];
        $context['sub_template'] = 'ftp_required';
        obExit();
    } else {
        if (!in_array($_POST['ftp_path'], array('', '/'))) {
            $ftp_root = strtr($boarddir, array($_POST['ftp_path'] => ''));
            if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/')) {
                $ftp_root = substr($ftp_root, 0, -1);
            }
        } else {
            $ftp_root = $boarddir;
        }
        $_SESSION['pack_ftp'] = array('server' => $_POST['ftp_server'], 'port' => $_POST['ftp_port'], 'username' => $_POST['ftp_username'], 'password' => package_crypt($_POST['ftp_password']), 'path' => $_POST['ftp_path'], 'root' => $ftp_root);
        if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) {
            updateSettings(array('package_path' => $_POST['ftp_path']));
        }
        $files = packageRequireFTP($destination_url, $files, $return);
    }
    return $files;
}
Esempio n. 2
0
function doStep2()
{
    global $txt, $ftp;
    $chmod =& $_SESSION['webinstall_state']['chmod'];
    if (isset($_POST['ftp_username'])) {
        $ftp = new ftp_connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']);
        if ($ftp->error === false) {
            // Try it without /home/abc just in case they messed up.
            if (!$ftp->chdir($_POST['ftp_path'])) {
                $ftp->chdir(preg_replace('~^/home[2]?/[^/]+?~', '', $_POST['ftp_path']));
            }
        }
        if ($ftp->error === false) {
            foreach ($_SESSION['webinstall_state']['files_to_download'] as $i => $file) {
                $ftp->create_file('smf_install' . $i . '.tmp');
                $ftp->chmod('smf_install' . $i . '.tmp', $chmod);
            }
            if (!file_exists(dirname(__FILE__) . '/smf_install0.tmp')) {
                $ftp->error = true;
            }
        }
        if ($ftp->error === false) {
            $_SESSION['installer_temp_ftp'] = array('server' => $_POST['ftp_server'], 'port' => $_POST['ftp_port'], 'username' => $_POST['ftp_username'], 'password' => $_POST['ftp_password'], 'path' => $_POST['ftp_path']);
            run_chmod_test($ftp, $chmod);
        } elseif ($_POST['ftp_username'] != '') {
            echo '
					<div class="error_message">
						<div>', $txt['error_not_right_path'], '</div>
					</div>';
            return doStep1();
        }
    }
    if (ini_get('memory_limit') < 64) {
        ini_set('memory_limit', '64M');
    }
    foreach ($_SESSION['webinstall_state']['files_to_download'] as $i => $file) {
        if ($i < $_GET['substep']) {
            continue;
        }
        $data = fetch_web_data($file, isset($_SESSION['webinstall_state']['user_data']) ? $_SESSION['webinstall_state']['user_data'] : '');
        if (function_exists('gzinflate')) {
            $data = extract_gzip($data);
        }
        if ($data === false) {
            echo '
					<div class="error_message">
						<div>', sprintf($txt['error_unable_download'], $file), '</div>
						<br />
						<a href="', $_SERVER['PHP_SELF'], '?step=1&substep=', $i, '">', $txt['error_message_click'], '</a> ', $txt['error_message_try_again'], '
					</div>';
            return false;
        }
        file_put_contents(dirname(__FILE__) . '/smf_install' . $i . '.tmp', $data);
        if ($i < $_SESSION['webinstall_state']['files_to_download_total'] - 1) {
            $query_string = '?step=2&substep=' . ($i + 1);
            $percent_done_total = round(($i + 1) / $_SESSION['webinstall_state']['files_to_download_total'] * 100, 2);
            // Pausing time!
            echo '
				<div class="panel">
					<h2 style="margin-top: 2ex;">', $txt['not_done_yet'], '</h2>
					<h3>', $txt['download_paused'], '</h3>

					<div style="padding-left: 20%; padding-right: 20%; margin-top: 1ex;">
						<strong>', $txt['download_progress'], ':</strong>
						<div style="font-size: 8pt; height: 12pt; border: 1px solid black; background-color: white; padding: 1px; position: relative;">
							<div style="padding-top: 1pt; width: 100%; z-index: 2; color: black; position: absolute; text-align: center; font-weight: bold;">', $percent_done_total, '%</div>
							<div style="width: ', $percent_done_total, '%; height: 12pt; z-index: 1; background-color: red;">&nbsp;</div>
						</div>
					</div>
					<form action="', $_SERVER['PHP_SELF'], $query_string, '" method="post" name="autoSubmit">
						<div class="righttext" style="margin: 1ex;"><input name="b" type="submit" value="', $txt['continue'], '" /></div>
					</form>
					<script type="text/javascript"><!-- // --><![CDATA[
						window.onload = doAutoSubmit;
						var countdown = 3;

						function doAutoSubmit()
						{
							if (countdown == 0)
								document.autoSubmit.submit();
							else if (countdown == -1)
								return;

							document.autoSubmit.b.value = "', $txt['continue'], ' (" + countdown + ")";
							countdown--;

							setTimeout(doAutoSubmit, 1000);
						}
					// ]]></script>
				</div>';
            return true;
        }
    }
    $_SESSION['webinstall_state']['is_logged_in'] = false;
    $_SESSION['webinstall_state']['is_charter'] = false;
    $_SESSION['webinstall_state']['is_beta_tester'] = false;
    $_SESSION['webinstall_state']['is_team'] = false;
    $_SESSION['webinstall_state']['access'] = array(0);
    $_SESSION['webinstall_state']['can_svn'] = false;
    $_SESSION['webinstall_state']['user_data'] = '';
    $_SESSION['webinstall_state']['member_info'] = array();
    echo '
				<div class="panel">
					<h2>', $txt['download_successful'], '</h2>
					<h3>', $txt['download_successful_info'], '</h3>

					<form action="', $_SERVER['PHP_SELF'], '?step=3" method="post" name="autoSubmit">
						<div class="righttext" style="margin: 1ex;"><input type="submit" name="b" value="', $txt['continue'], '" /></div>
					</form>
					<script type="text/javascript"><!-- // --><![CDATA[
						window.onload = doAutoSubmit;
						var countdown = 3;

						function doAutoSubmit()
						{
							if (countdown == 0)
								document.autoSubmit.submit();
							else if (countdown == -1)
								return;

							document.autoSubmit.b.value = "', $txt['continue'], ' (" + countdown + ")";
							countdown--;

							setTimeout(doAutoSubmit, 1000);
						}
					// ]]></script>
				</div>';
    return true;
}