/** * Unzip the file by using the ZipReader class from contao * * @param sring $strZipPath Path to the zip * @return array A list with current path and taget path. * @throws Exception */ protected function unzipByContao($strZipPath) { $arrMoveList = array(); $objZipReader = new ZipReader($strZipPath); // Create tmp folder new Folder(self::TEMP_PATH . '/syncCtoAutoUpdate'); foreach ($objZipReader->getFileList() as $value) { // Check if the file part of the folder "FILES" if (!preg_match("/^" . self::ZIP_FILE_PATH . "\\//i", $value)) { continue; } $movePath = preg_replace("/^" . self::ZIP_FILE_PATH . "\\//i", "", $value); $targetPath = self::TEMP_PATH . 'syncCtoAutoUpdate/' . $movePath; $arrMoveList[$targetPath] = $movePath; // Write file $objZipReader->getFile($value); $objFile = new File($targetPath); $objFile->write($objZipReader->unzip()); $objFile->close(); unset($objFile); } return $arrMoveList; }
/** * Run the live update * @param BackendTemplate */ protected function runLiveUpdate(BackendTemplate $objTemplate) { $archive = 'system/tmp/' . $this->Input->get('token'); // Download the archive if (!file_exists(TL_ROOT . '/' . $archive)) { $objRequest = new Request(); $objRequest->send($GLOBALS['TL_CONFIG']['liveUpdateBase'] . 'request.php?token=' . $this->Input->get('token')); if ($objRequest->hasError()) { $objTemplate->updateClass = 'tl_error'; $objTemplate->updateMessage = $objRequest->response; return; } $objFile = new File($archive); $objFile->write($objRequest->response); $objFile->close(); } // Create a minimalistic HTML5 document echo '<!DOCTYPE html>' .'<head>' .'<meta charset="utf-8">' .'<title>Contao Live Update</title>' .'<style>' .'body { background:#f5f5f5 url("../system/themes/default/images/hbg.jpg") left top repeat-x; font-family:Verdana,sans-serif; font-size:11px; color:#444; padding:1em; }' .'div { max-width:680px; margin:0 auto; border:1px solid #bbb; background:#fff; }' .'h1 { font-size:12px; color:#fff; margin:1px; padding:2px 6px 4px; background:#b3b6b3 url("../system/themes/default/images/headline.gif") left top repeat-x; }' .'h2 { font-size:14px; color:#8ab858; margin:18px 15px; padding:6px 42px 8px; background:url("../system/themes/default/images/current.gif") left center no-repeat; }' .'ol { border:1px solid #ccc; max-height:430px; margin:0 15px 18px; overflow:auto; padding:3px 18px 3px 48px; background:#fcfcfc; }' .'li { margin-bottom:3px; }' .'p { margin:0 12px; padding:0; overflow:hidden; }' .'.button { font-family:"Trebuchet MS",Verdana,sans-serif; font-size:12px; display:block; float:right; margin:0 3px 18px; border-radius:3px; background:#808080; text-decoration:none; color:#fff; padding:4px 18px; box-shadow:0 1px 3px #bbb; text-shadow:1px 1px 0 #666; }' .'.button:hover,.button:focus { box-shadow:0 0 6px #8ab858; }' .'.button:active { background:#8ab858; }' .'</style>' .'<body>' .'<div>'; $objArchive = new ZipReader($archive); // Table of contents if ($this->Input->get('toc')) { $arrFiles = $objArchive->getFileList(); array_shift($arrFiles); echo '<hgroup>' .'<h1>Contao Live Update</h1>' .'<h2>' . $GLOBALS['TL_LANG']['tl_maintenance']['toc'] . '</h2>' .'</hgroup>' .'<ol>' .'<li>' . implode('</li><li>', $arrFiles) . '</li>' .'</ol>' .'<p>' .'<a href="' . ampersand(str_replace('toc=1', 'toc=', $this->Environment->base . $this->Environment->request)) . '" class="button">' . $GLOBALS['TL_LANG']['MSC']['continue'] . '</a>' .'<a href="' . $this->Environment->base . 'contao/main.php?do=maintenance" class="button">' . $GLOBALS['TL_LANG']['MSC']['cancelBT'] . '</a>' .'</p>' .'</div>'; exit; } // Backup if ($this->Input->get('bup')) { echo '<hgroup>' .'<h1>Contao Live Update</h1>' .'<h2>' . $GLOBALS['TL_LANG']['tl_maintenance']['backup'] . '</h2>' .'</hgroup>' .'<ol>'; $arrFiles = $objArchive->getFileList(); $objBackup = new ZipWriter('LU' . date('YmdHi') . '.zip'); foreach ($arrFiles as $strFile) { if ($strFile == 'TOC.txt' || $strFile == 'system/runonce.php') { continue; } try { $objBackup->addFile($strFile); echo '<li>Backed up ' . $strFile . '</li>'; } catch (Exception $e) { echo '<li>' . $e->getMessage() . ' (skipped)</li>'; } } $objBackup->close(); echo '</ol>' .'<p>' .'<a href="' . ampersand(str_replace('bup=1', 'bup=', $this->Environment->base . $this->Environment->request)) . '" id="continue" class="button">' . $GLOBALS['TL_LANG']['MSC']['continue'] . '</a>' .'<a href="' . $this->Environment->base . 'contao/main.php?do=maintenance" id="back" class="button">' . $GLOBALS['TL_LANG']['MSC']['cancelBT'] . '</a>' .'</p>' .'</div>'; exit; } echo '<hgroup>' .'<h1>Contao Live Update</h1>' .'<h2>' . $GLOBALS['TL_LANG']['tl_maintenance']['update'] . '</h2>' .'</hgroup>' .'<ol>'; // Update while ($objArchive->next()) { if ($objArchive->file_name == 'TOC.txt') { continue; } try { $objFile = new File($objArchive->file_name); $objFile->write($objArchive->unzip()); $objFile->close(); echo '<li>Updated ' . $objArchive->file_name . '</li>'; } catch (Exception $e) { echo '<li><span style="color:#c55">Error updating ' . $objArchive->file_name . ': ' . $e->getMessage() . '</span></li>'; } } // Delete the archive $this->import('Files'); $this->Files->delete($archive); // Add a log entry $this->log('Live update from version ' . VERSION . '.' . BUILD . ' to version ' . $GLOBALS['TL_CONFIG']['latestVersion'] . ' completed', 'LiveUpdate run()', TL_GENERAL); echo '</ol>' .'<p>' .'<a href="' . $this->Environment->base . 'contao/main.php?do=maintenance&act=runonce" id="continue" class="button">' . $GLOBALS['TL_LANG']['MSC']['continue'] . '</a>' .'</p>' .'</div>'; exit; }
public function restoreBackup($restoreFile, $boolDB = false, $boolFiles = false) { $arrOutput = array(); if ($restoreFile) { $c2gFile = new File("backups/" . $restoreFile); if ($c2gFile->extension == 'c2g') { $c2gZipFile = new ZipReader("backups/" . $restoreFile); $descFile = $c2gZipFile->getFile("description.php"); if ($descFile) { unset($GLOBALS["package"]); eval($c2gZipFile->unzip()); $arrOutput[] = sprintf($GLOBALS['TL_LANG']['tl_content']['c2g_restorebackup'], $GLOBALS["package"]["Name"]); $dirName = TL_ROOT . '/' . $GLOBALS["package"]["RootDir"] . '/' . $GLOBALS["package"]["Name"]; if ($boolFiles) { $strRestoreFolder = new Folder($GLOBALS["package"]["RootDir"] . @'/' . $GLOBALS["package"]["Name"] . @'/'); if ($GLOBALS["package"]["RootDir"] != '.' && is_dir($dirName)) { $this->c2g_functions->rrmdir($dirName); $arrOutput[] = sprintf($GLOBALS['TL_LANG']['tl_content']['c2g_restorebackup_cleandir'], $GLOBALS["package"]["Name"]); } $directoryFile = $c2gZipFile->getFile("directories.dat"); if ($directoryFile) { $strDirectories = $c2gZipFile->unzip(); $arrDirectories = explode("\r\n", $strDirectories); if (is_array($arrDirectories)) { foreach ($arrDirectories as $dir) { $objDir = new Folder($dir); } } } $c2gZipFile->first(); $arrFileList = $c2gZipFile->getFileList(); foreach ($arrFileList as $file) { $c2gZipFile->getFile($file); $objFile = new File('vhosts/' . $file); $strData = $c2gZipFile->unzip(); if (basename($file) == 'localconfig.php') { $objFile->write($strData); $objFile->close(); $arrConfigReturn = @$this->c2g_functions->loadVHostConfig(TL_ROOT . '/vhosts/' . $GLOBALS["package"]["Name"], false); $objFile = new File('vhosts/' . $file); $strData = $this->c2g_functions->rewriteLocalconfig($strData, $GLOBALS['TL_CONFIG']['dbHost'], $GLOBALS['TL_CONFIG']['dbPort'], $arrConfigReturn['localconfig']['dbDatabase'], $GLOBALS['TL_CONFIG']['dbUser'], $GLOBALS['TL_CONFIG']['dbPass'], $arrConfigReturn['localconfig']['websitePath']); } $objFile->write($strData); $objFile->close(); // let the directorystructure create, but remove .empty file if (basename($file) == '.empty') { $objFile->delete(); } } $arrOutput[] = $GLOBALS['TL_LANG']['tl_content']['c2g_restorebackup_filesystemrestored']; } $arrConfigReturn = $this->c2g_functions->loadVHostConfig(TL_ROOT . '/vhosts/' . $GLOBALS["package"]["Name"]); if (IS_CONTAO3) { $objFile = new File('vhosts/' . $GLOBALS["package"]["Name"] . '/system/config/pathconfig.php', true); $objFile->write("<?php\n\n// Relative path to the installation\nreturn '/vhosts/" . $GLOBALS["package"]["Name"] . "';\n"); $objFile->close(); $arrOutput[] = $GLOBALS['TL_LANG']['tl_content']['c2g_createpathconfig']; } if ($boolDB) { $file = $c2gFile->filename . '.sql'; $c2gZipFile->getFile($file); $objFile = new File('vhosts/' . $file); $objFile->write($c2gZipFile->unzip()); $objFile->close(); $sqlDump = new File($GLOBALS["package"]["RootDir"] . '/' . $file); $this->c2g_functions->restoreDump($sqlDump->getContent()); $sqlDump->close(); $arrOutput[] = $GLOBALS['TL_LANG']['tl_content']['c2g_restorebackup_sqlrestored']; } $objDescFile = new File($GLOBALS["package"]["RootDir"] . '/description.php'); $objDescFile->delete(); $objDirFile = new File($GLOBALS["package"]["RootDir"] . '/directories.dat'); $objDirFile->delete(); $objSQLFile = new File($GLOBALS["package"]["RootDir"] . '/' . $c2gFile->filename . '.sql'); $objSQLFile->delete(); } } $arrOutput[] = sprintf('<a href="%s" title="%s">%s</a>', $this->pathMySelf, $GLOBALS['TL_LANG']['tl_content']['c2g_backupreturntooverview'], $GLOBALS['TL_LANG']['tl_content']['c2g_backupreturntooverview']); $pathBackups = $this->replaceInsertTags(sprintf('{{link_url::%s}}', $this->c2g_listvhosts)); $arrOutput[] = sprintf('<a href="%s" title="%s">%s</a>', $pathBackups, $GLOBALS['TL_LANG']['tl_content']['c2g_backupreturntovhosts'], $GLOBALS['TL_LANG']['tl_content']['c2g_backupreturntovhosts']); } return implode("<br />", $arrOutput); }