/** * Unpack a db backup file, if necessary * Note: This requires a minimal PEAR setup (incl. Tar and Zip classes) and a * way to set the PEAR include path. But if that doesn't work on your * setup, then chances are you won't get Geeklog up and running anyway ... * * @param string $backupPath path to the "backups" directory * @param string $backupFile backup file name * @param string $display reference to HTML string (for error msg) * @return mixed file name of unpacked file or false: error */ function INST_unpackFile($backupPath, $backupFile, &$display) { global $_CONF, $LANG_MIGRATE; if (!preg_match('/\\.(zip|tar\\.gz|tgz)$/i', $backupFile)) { // not packed return $backupFile; } require_once $_CONF['path'] . 'systems/classes/Autoload.php'; Geeklog\Autoload::initialize(); $archive = new Unpacker($backupPath . $backupFile); // we're going to extract the first .sql file we find in the archive $dirName = ''; $foundSqlFile = false; $files = $archive->getList(); foreach ($files as $file) { if (!isset($file['folder']) || !$file['folder']) { if (preg_match('/\\.sql$/', $file['filename'])) { $dirName = preg_replace('/\\/.*$/', '', $file['filename']); $foundSqlFile = true; break; } } } if (!$foundSqlFile) { // no .sql file found in archive $display .= INST_getAlertMsg(sprintf($LANG_MIGRATE[40], $backupFile)); return false; } if (isset($file) && $dirName === $file['filename']) { $dirName = ''; // no directory } if (empty($dirName)) { $unpacked_file = $file['filename']; } else { $unpacked_file = substr($file['filename'], strlen($dirName) + 1); } $success = $archive->unpack($backupPath, array($file['filename'])); if (!$success || !file_exists($backupPath . $unpacked_file)) { // error unpacking file $display .= INST_getAlertMsg(sprintf($LANG_MIGRATE[41], $unpacked_file)); return false; } unset($archive); return $unpacked_file; }
echo $output; die(1); } // this is not ideal but will stop PHP 5.3.0ff from complaining ... $system_timezone = @date_default_timezone_get(); date_default_timezone_set($system_timezone); $_REQUEST = array_merge($_GET, $_POST); // Before we begin, check if an uploaded file exceeds PHP's post_max_size if (isset($_SERVER['CONTENT_LENGTH'])) { // This code is thanks to v3 AT sonic-world DOT ru via PHP.net $POST_MAX_SIZE = ini_get('post_max_size'); $mul = substr($POST_MAX_SIZE, -1); $mul = $mul == 'M' ? 1048576 : ($mul == 'K' ? 1024 : ($mul == 'G' ? 1073741824 : 1)); if ($_SERVER['CONTENT_LENGTH'] > $mul * (int) $POST_MAX_SIZE && $POST_MAX_SIZE) { // If it does, display an error message $display = INST_getHeader($LANG_ERROR[8]) . INST_getAlertMsg($LANG_ERROR[7]) . INST_getFooter(); die($display); } } // +---------------------------------------------------------------------------+ // | Functions | // +---------------------------------------------------------------------------+ /** * Returns the beginning HTML for the installer theme. * * @param $mHeading Heading * @return string Header HTML code * */ function INST_getHeader($mHeading) {
<tr><th align="left" width="125">' . $LANG_BIGDUMP[22] . ': ' . $pct_done . '%</th><td colspan="4">' . $pct_bar . '</td></tr> </table><br' . XHTML . '>' . LB; // Finish message and restart the script if ($linenumber < $_REQUEST["start"] + $linespersession) { echo INST_getAlertMsg($LANG_BIGDUMP[23], 'success'); /*** Go back to Geeklog installer ***/ echo "<script language=\"JavaScript\" type=\"text/javascript\">window.setTimeout('location.href=\"" . 'migrate.php?step=4' . '&language=' . $language . '&site_url=' . $_REQUEST['site_url'] . '&site_admin_url=' . $_REQUEST['site_admin_url'] . "\";',3000);</script>\n"; } else { if ($delaypersession != 0) { echo '<p><b>' . $LANG_BIGDUMP[24] . $delaypersession . $LANG_BIGDUMP[25] . LB; } // Go to the next step echo '<script language="JavaScript" type="text/javascript">window.setTimeout(\'location.href="' . $_SERVER['PHP_SELF'] . '?start=' . $linenumber . '&fn=' . urlencode($curfilename) . '&foffset=' . $foffset . '&totalqueries=' . $totalqueries . '&db_connection_charset=' . $db_connection_charset . '&language=' . $language . '&site_url=' . $site_url . '&site_admin_url=' . $site_admin_url . '";\',500+' . $delaypersession . ');</script>' . LB . '<noscript>' . LB . ' <p><a href="' . $_SERVER['PHP_SELF'] . '?start=' . $linenumber . '&fn=' . urlencode($curfilename) . '&foffset=' . $foffset . '&totalqueries=' . $totalqueries . '&db_connection_charset=' . $db_connection_charset . '&language=' . $language . '&site_url=' . $site_url . '&site_admin_url=' . $site_admin_url . '">Continue from the line ' . $linenumber . '</a></p>' . LB . '</noscript>' . LB . '<p><b><a href="' . $_SERVER['PHP_SELF'] . '">' . $LANG_BIGDUMP[26] . '</a></b> ' . $LANG_BIGDUMP[27] . ' <b>' . $LANG_BIGDUMP[28] . '</b></p>' . LB; } } else { echo INST_getAlertMsg($LANG_BIGDUMP[29]); } } if ($error) { $backurl = 'migrate.php'; if (!empty($language)) { $backurl .= '?language=' . $language; } echo '<p><a href="' . $backurl . '">' . $LANG_BIGDUMP[30] . '</a> ' . $LANG_BIGDUMP[31] . '</p>' . LB; } if ($dbconnection) { mysql_close($dbconnection); } if ($file && !$gzipmode) { fclose($file); } else {
/** * Unpack a db backup file, if necessary * * Note: This requires a minimal PEAR setup (incl. Tar and Zip classes) and a * way to set the PEAR include path. But if that doesn't work on your * setup, then chances are you won't get Geeklog up and running anyway ... * * @param string $backup_path path to the "backups" directory * @param string $backup_file backup file name * @param ref $display reference to HTML string (for error msg) * @return mixed file name of unpacked file or false: error * */ function INST_unpackFile($backup_path, $backup_file, &$display) { global $_CONF, $LANG_MIGRATE; $unpacked_file = $backup_file; $type = ''; if (preg_match('/\\.zip$/i', $backup_file)) { $type = 'zip'; } elseif (preg_match('/\\.tar.gz$/i', $backup_file) || preg_match('/\\.tgz$/i', $backup_file)) { $type = 'tar'; } if (empty($type)) { // not packed return $backup_file; } $include_path = get_include_path(); if (set_include_path($_CONF['path'] . 'system/pear/' . PATH_SEPARATOR . $include_path) === false) { // couldn't set PEAR path - can't handle compressed backups $display .= INST_getAlertMsg($LANG_MIGRATE[39]); return false; } if ($type == 'zip') { require_once 'Archive/Zip.php'; $archive = new Archive_Zip($backup_path . $backup_file); } else { require_once 'Archive/Tar.php'; $archive = new Archive_Tar($backup_path . $backup_file); } // we're going to extract the first .sql file we find in the archive $found_sql_file = false; $files = $archive->listContent(); foreach ($files as $file) { if (!isset($file['folder']) || !$file['folder']) { if (preg_match('/\\.sql$/', $file['filename'])) { $dirname = preg_replace('/\\/.*$/', '', $file['filename']); $found_sql_file = true; break; } } } if (!$found_sql_file) { // no .sql file found in archive $display .= INST_getAlertMsg(sprintf($LANG_MIGRATE[40], $backup_file)); return false; } if ($dirname == $file['filename']) { $dirname = ''; // no directory } if (empty($dirname)) { $unpacked_file = $file['filename']; } else { $unpacked_file = substr($file['filename'], strlen($dirname) + 1); } $success = false; if ($type == 'zip') { $result = $archive->extract(array('add_path' => $backup_path, 'by_name' => array($file['filename']), 'remove_path' => $dirname)); if (is_array($result)) { $success = true; } } else { $result = $archive->extractList(array($file['filename']), $backup_path, $dirname); $success = $result; } if (!$success || !file_exists($backup_path . $unpacked_file)) { // error unpacking file $display .= INST_getAlertMsg(sprintf($LANG_MIGRATE[41], $unpacked_file)); return false; } unset($archive); return $unpacked_file; }