/**
  * Perform backup
  * @return string
  */
 public static function create()
 {
     $collection = new Collection();
     $locations = Helper::getPreparedLocations();
     foreach ($locations as $type => $dirs) {
         foreach ($dirs as $name => $path) {
             Helper::checkr($path, $collection);
         }
     }
     if (count($collection->getNotReadable()) || count($collection->getNotWritable())) {
         $e = new PermissionException();
         $e->setCollection($collection);
         throw $e;
     }
     try {
         Helper::mkdir(self::getPath(), true);
         foreach ($locations as $type => $dirs) {
             $backupFullPath = self::getPath() . '/' . $type . '/';
             Helper::mkdir($backupFullPath, true);
             foreach ($dirs as $name => $path) {
                 Helper::copyr($path, $backupFullPath . $name);
             }
         }
     } catch (\Exception $e) {
         App::log('Backup creation failed. Disk full?');
         self::cleanUp();
         throw new FsException($e->getMessage());
     }
     return self::getPath();
 }
 public static function update($version, $backupBase)
 {
     if (!is_dir($backupBase)) {
         throw new \Exception("Backup directory {$backupBase} is not found");
     }
     set_include_path($backupBase . PATH_SEPARATOR . $backupBase . '/core/lib' . PATH_SEPARATOR . $backupBase . '/core/config' . PATH_SEPARATOR . $backupBase . '/3rdparty' . PATH_SEPARATOR . $backupBase . '/apps' . PATH_SEPARATOR . get_include_path());
     $tempDir = self::getTempDir();
     Helper::mkdir($tempDir, true);
     $installed = Helper::getDirectories();
     $sources = Helper::getSources($version);
     try {
         $thirdPartyUpdater = new Location_3rdparty($installed[Helper::THIRDPARTY_DIRNAME], $sources[Helper::THIRDPARTY_DIRNAME]);
         $thirdPartyUpdater->update($tempDir . '/' . Helper::THIRDPARTY_DIRNAME);
         self::$processed[] = $thirdPartyUpdater;
         $coreUpdater = new Location_Core($installed[Helper::CORE_DIRNAME], $sources[Helper::CORE_DIRNAME]);
         $coreUpdater->update($tempDir . '/' . Helper::CORE_DIRNAME);
         self::$processed[] = $coreUpdater;
         $appsUpdater = new Location_Apps('', $sources[Helper::APP_DIRNAME]);
         $appsUpdater->update($tempDir . '/' . Helper::APP_DIRNAME);
         self::$processed[] = $appsUpdater;
     } catch (\Exception $e) {
         self::rollBack();
         self::cleanUp();
         throw $e;
     }
     // zip backup
     $zip = new \ZipArchive();
     if ($zip->open($backupBase . ".zip", \ZIPARCHIVE::CREATE) === true) {
         Helper::addDirectoryToZip($zip, $backupBase, $backupBase);
         $zip->close();
         \OCP\Files::rmdirr($backupBase);
     }
     return true;
 }
Exemple #3
0
 public static function update($version, $backupBase)
 {
     if (!is_dir($backupBase)) {
         throw new \Exception("Backup directory {$backupBase} is not found");
     }
     set_include_path($backupBase . PATH_SEPARATOR . $backupBase . '/core/lib' . PATH_SEPARATOR . $backupBase . '/core/config' . PATH_SEPARATOR . $backupBase . '/3rdparty' . PATH_SEPARATOR . $backupBase . '/apps' . PATH_SEPARATOR . get_include_path());
     $tempDir = self::getTempDir();
     Helper::mkdir($tempDir, true);
     try {
         foreach (self::prepare($version) as $location) {
             Helper::move($location['src'], $location['dst']);
             self::$processed[] = array('src' => $location['dst'], 'dst' => $location['src']);
         }
     } catch (\Exception $e) {
         self::rollBack();
         self::cleanUp();
         throw $e;
     }
     $config = "/config/config.php";
     copy($backupBase . "/" . Helper::CORE_DIRNAME . $config, \OC::$SERVERROOT . $config);
     // zip backup
     $zip = new \ZipArchive();
     if ($zip->open($backupBase . ".zip", \ZIPARCHIVE::CREATE) === true) {
         Helper::addDirectoryToZip($zip, $backupBase, $backupBase);
         $zip->close();
         \OC_Helper::rmdirr($backupBase);
     }
     // Disable removed apps
     foreach (self::getAppsToRemove() as $appId) {
         \OC_App::disable($appId);
     }
     return true;
 }
	public function update($tmpDir = '') {
		Helper::mkdir($tmpDir, true);
		$collected = $this->collect();

		try {
			foreach ($collected['old'] as $src) {
				$dst = str_replace($this->oldBase, $tmpDir, $src);
				Helper::move($src, $dst);

				// ! reverted intentionally
				$this->done [] = array(
					'dst' => $src,
					'src' => $dst
				);
			}

			foreach ($collected['new'] as $src) {
				$dst = str_replace($this->newBase, $this->oldBase, $src);
				Helper::move($src, $dst);
			}

			$this->finalize();
		} catch (\Exception $e) {
			$this->rollback(true);
			throw $e;
		}
	}
Exemple #5
0
 public static function getPackage($url, $version)
 {
     self::$package = App::getBackupBase() . $version;
     if (preg_match('/\\.zip$/i', $url)) {
         $type = '.zip';
     } elseif (preg_match('/(\\.tgz|\\.tar\\.gz)$/i', $url)) {
         $type = '.tgz';
     } elseif (preg_match('/\\.tar\\.bz2$/i', $url)) {
         $type = '.tar.bz2';
     } else {
         throw new \Exception('Unable to extract package ' . $url . ': unknown format');
     }
     self::$package = self::$package . $type;
     try {
         // Reuse already downloaded package
         if (!file_exists(self::$package)) {
             if (self::fetch($url) === false) {
                 throw new \Exception("Error storing package content");
             }
             App::log('Downloaded ' . filesize(self::$package) . ' bytes.', \OCP\Util::DEBUG);
         } else {
             App::log('Use already downloaded package ' . self::$package . '. Size is ' . filesize(self::$package) . ' bytes.', \OCP\Util::DEBUG);
         }
         $extractDir = self::getPackageDir($version);
         Helper::mkdir($extractDir, true);
         $archive = \OC_Archive::open(self::$package);
         if (!$archive || !$archive->extract($extractDir)) {
             throw new \Exception(self::$package . " extraction error");
         }
     } catch (\Exception $e) {
         App::log('Retrieving ' . $url);
         self::cleanUp($version);
         throw $e;
     }
     //  Prepare extracted data
     //  to have '3rdparty', 'apps' and 'core' subdirectories
     $baseDir = $extractDir . '/' . self::PACKAGE_ROOT;
     if (!file_exists($baseDir)) {
         App::log('Expected fresh sources in ' . $baseDir . '. Nothing is found. Something is wrong with OC_Archive.');
         App::log($extractDir . ' content: ' . implode(' ', scandir($extractDir)));
         if ($type === '.zip' && !extension_loaded('zip')) {
             $hint = App::$l10n->t('Please ask your server administrator to enable PHP zip extension.');
         }
         throw new \Exception(self::$package . " extraction error. " . $hint);
     }
     include $baseDir . '/version.php';
     Helper::checkVersion($OC_Version, $OC_VersionString);
     $sources = Helper::getSources($version);
     rename($baseDir . '/' . Helper::THIRDPARTY_DIRNAME, $sources[Helper::THIRDPARTY_DIRNAME]);
     rename($baseDir . '/' . Helper::APP_DIRNAME, $sources[Helper::APP_DIRNAME]);
     rename($baseDir, $sources[Helper::CORE_DIRNAME]);
 }
Exemple #6
0
 public static function update($version, $backupBase)
 {
     if (!is_dir($backupBase)) {
         throw new \Exception("Backup directory {$backupBase} is not found");
     }
     // Switch include paths to backup
     $pathsArray = explode(PATH_SEPARATOR, get_include_path());
     $pathsTranslated = [];
     foreach ($pathsArray as $path) {
         //Update all 3rdparty paths
         if (preg_match('|^' . preg_quote(\OC::$THIRDPARTYROOT . '/3rdparty') . '|', $path)) {
             $pathsTranslated[] = preg_replace('|^' . preg_quote(\OC::$THIRDPARTYROOT . '/3rdparty') . '|', $backupBase . '/3rdparty', $path);
             continue;
         }
         // Update all OC webroot paths
         $pathsTranslated[] = preg_replace('|^' . preg_quote(\OC::$SERVERROOT) . '|', $backupBase, $path);
     }
     set_include_path(implode(PATH_SEPARATOR, $pathsTranslated));
     $tempDir = self::getTempDir();
     Helper::mkdir($tempDir, true);
     $installed = Helper::getDirectories();
     $sources = Helper::getSources($version);
     try {
         $thirdPartyUpdater = new \OCA\Updater\Location\Thirdparty($installed[Helper::THIRDPARTY_DIRNAME], $sources[Helper::THIRDPARTY_DIRNAME]);
         $thirdPartyUpdater->update($tempDir . '/' . Helper::THIRDPARTY_DIRNAME);
         self::$processed[] = $thirdPartyUpdater;
         $coreUpdater = new \OCA\Updater\Location\Core($installed[Helper::CORE_DIRNAME], $sources[Helper::CORE_DIRNAME]);
         $coreUpdater->update($tempDir . '/' . Helper::CORE_DIRNAME);
         self::$processed[] = $coreUpdater;
         $appsUpdater = new \OCA\Updater\Location\Apps('', $sources[Helper::APP_DIRNAME]);
         $appsUpdater->update($tempDir . '/' . Helper::APP_DIRNAME);
         self::$processed[] = $appsUpdater;
     } catch (\Exception $e) {
         self::rollBack();
         self::cleanUp();
         throw $e;
     }
     // zip backup
     $zip = new \ZipArchive();
     if ($zip->open($backupBase . ".zip", \ZIPARCHIVE::CREATE) === true) {
         Helper::addDirectoryToZip($zip, $backupBase);
         $zip->close();
         \OCP\Files::rmdirr($backupBase);
     }
     return true;
 }
Exemple #7
0
 /**
  * Perform backup
  * @return string
  */
 public static function create()
 {
     try {
         $locations = Helper::getPreparedLocations();
         Helper::mkdir(self::getPath(), true);
         foreach ($locations as $type => $dirs) {
             $backupFullPath = self::getPath() . '/' . $type . '/';
             Helper::mkdir($backupFullPath, true);
             foreach ($dirs as $name => $path) {
                 Helper::copyr($path, $backupFullPath . $name);
             }
         }
     } catch (\Exception $e) {
         self::cleanUp();
         throw $e;
     }
     return self::getPath();
 }
Exemple #8
0
 public static function getPackage($url, $version)
 {
     self::$package = \OC_Helper::tmpFile();
     if (!self::$package) {
         throw new \Exception('Unable to create a temporary file');
     }
     try {
         if (file_put_contents(self::$package, self::fetch($url)) === false) {
             throw new \Exception("Error storing package content");
         }
         if (preg_match('/\\.zip$/i', $url)) {
             rename(self::$package, self::$package . '.zip');
             self::$package .= '.zip';
         } elseif (preg_match('/(\\.tgz|\\.tar\\.gz)$/i', $url)) {
             rename(self::$package, self::$package . '.tgz');
             self::$package .= '.tgz';
         } elseif (preg_match('/\\.tar\\.bz2$/i', $url)) {
             rename(self::$package, self::$package . '.tar.bz2');
             self::$package .= '.tar.bz2';
         } else {
             throw new \Exception('Unable to extract package');
         }
         $extractDir = self::getPackageDir($version);
         Helper::mkdir($extractDir, true);
         $archive = \OC_Archive::open(self::$package);
         if (!$archive || !$archive->extract($extractDir)) {
             throw new \Exception(self::$package . " extraction error");
         }
     } catch (\Exception $e) {
         App::log('Retrieving ' . $url);
         self::cleanUp($version);
         throw $e;
     }
     Helper::removeIfExists(self::$package);
     //  Prepare extracted data
     //  to have '3rdparty', 'apps' and 'core' subdirectories
     $sources = Helper::getSources($version);
     $baseDir = $extractDir . '/' . self::PACKAGE_ROOT;
     @rename($baseDir . '/' . Helper::THIRDPARTY_DIRNAME, $sources[Helper::THIRDPARTY_DIRNAME]);
     @rename($baseDir . '/' . Helper::APP_DIRNAME, $sources[Helper::APP_DIRNAME]);
     @rename($baseDir, $sources[Helper::CORE_DIRNAME]);
 }
Exemple #9
0
 public function update($tmpDir = '')
 {
     Helper::mkdir($tmpDir, true);
     $this->collect(true);
     try {
         foreach ($this->appsToUpdate as $appId) {
             $path = \OC_App::getAppPath($appId);
             if ($path) {
                 Helper::move($path, $tmpDir . '/' . $appId);
                 // ! reverted intentionally
                 $this->done[] = array('dst' => $path, 'src' => $tmpDir . '/' . $appId);
                 Helper::move($this->newBase . '/' . $appId, $path);
             }
         }
         $this->finalize();
     } catch (\Exception $e) {
         $this->rollback(true);
         throw $e;
     }
 }
Exemple #10
0
 public static function update($version, $backupBase)
 {
     if (!is_dir($backupBase)) {
         throw new \Exception("Backup directory {$backupBase} is not found");
     }
     set_include_path($backupBase . PATH_SEPARATOR . $backupBase . '/core/lib' . PATH_SEPARATOR . $backupBase . '/core/config' . PATH_SEPARATOR . $backupBase . '/3rdparty' . PATH_SEPARATOR . $backupBase . '/apps' . PATH_SEPARATOR . get_include_path());
     $tempDir = self::getTempDir();
     Helper::mkdir($tempDir, true);
     try {
         foreach (self::prepare($version) as $location) {
             Helper::move($location['src'], $location['dst']);
             self::$processed[] = array('src' => $location['dst'], 'dst' => $location['src']);
         }
     } catch (\Exception $e) {
         App::log('Something went wrong. Rolling back.');
         self::rollBack();
         self::cleanUp();
         throw $e;
     }
     // move old config files
     $backupConfigPath = $backupBase . "/" . Helper::CORE_DIRNAME . "/config/";
     foreach (glob($backupConfigPath . "*.php") as $configFile) {
         $target = \OC::$SERVERROOT . "/config/" . basename($configFile);
         if (!file_exists($target)) {
             copy($configFile, $target);
         }
     }
     // zip backup
     $zip = new \ZipArchive();
     if ($zip->open($backupBase . ".zip", \ZIPARCHIVE::CREATE) === true) {
         Helper::addDirectoryToZip($zip, $backupBase, $backupBase);
         $zip->close();
         \OC_Helper::rmdirr($backupBase);
     }
     // Disable removed apps
     foreach (self::getAppsToRemove() as $appId) {
         \OC_App::disable($appId);
     }
     return true;
 }
Exemple #11
0
 public static function getPackage($url, $version)
 {
     self::$package = \OC_Helper::tmpFile();
     try {
         if (!copy($url, self::$package)) {
             throw new \Exception("Failed to download {$url} package");
         }
         if (preg_match('/\\.zip$/i', $url)) {
             rename(self::$package, self::$package . '.zip');
             self::$package .= '.zip';
         } elseif (preg_match('/(\\.tgz|\\.tar\\.gz)$/i', $url)) {
             rename(self::$package, self::$package . '.tgz');
             self::$package .= '.tgz';
         } elseif (preg_match('/\\.tar\\.bz2$/i', $url)) {
             rename(self::$package, self::$package . '.tar.bz2');
             self::$package .= '.tar.bz2';
         } else {
             throw new \Exception('Unable to extract package');
         }
         $extractDir = self::getPackageDir($version);
         Helper::mkdir($extractDir, true);
         $archive = \OC_Archive::open(self::$package);
         if ($archive) {
             $archive->extract($extractDir);
         } else {
             throw new \Exception(self::$package . " extraction error");
         }
     } catch (\Exception $e) {
         self::cleanUp($version);
         throw $e;
     }
     Helper::removeIfExists(self::$package);
     //  Prepare extracted data
     //  to have '3rdparty', 'apps' and 'core' subdirectories
     $sources = Helper::getSources($version);
     $baseDir = $extractDir . '/' . self::PACKAGE_ROOT;
     @rename($baseDir . '/' . Helper::THIRDPARTY_DIRNAME, $sources[Helper::THIRDPARTY_DIRNAME]);
     @rename($baseDir . '/' . Helper::APP_DIRNAME, $sources[Helper::APP_DIRNAME]);
     @rename($baseDir, $sources[Helper::CORE_DIRNAME]);
 }
Exemple #12
0
 /**
  * Perform backup
  * @return string
  */
 public static function create($version)
 {
     $collection = new Collection();
     $installed = Helper::getDirectories();
     $sources = Helper::getSources($version);
     $thirdPartyUpdater = new \OCA\Updater\Location\Thirdparty($installed[Helper::THIRDPARTY_DIRNAME], $sources[Helper::THIRDPARTY_DIRNAME]);
     $coreUpdater = new \OCA\Updater\Location\Core($installed[Helper::CORE_DIRNAME], $sources[Helper::CORE_DIRNAME]);
     $appUpdater = new \OCA\Updater\Location\Apps($installed[Helper::APP_DIRNAME], '');
     $thirdPartyFiles = $thirdPartyUpdater->collect(true);
     $coreFiles = $coreUpdater->collect(true);
     $appFiles = $appUpdater->collect(true);
     $locations = array(Helper::THIRDPARTY_DIRNAME => $thirdPartyFiles['old'], Helper::CORE_DIRNAME => $coreFiles['old'], Helper::APP_DIRNAME => $appFiles['old']);
     foreach ($locations as $type => $dirs) {
         foreach ($dirs as $name => $path) {
             Helper::checkr($path, $collection);
         }
     }
     if (count($collection->getNotReadable()) || count($collection->getNotWritable())) {
         $e = new PermissionException();
         $e->setCollection($collection);
         throw $e;
     }
     try {
         Helper::mkdir(self::getPath(), true);
         foreach ($locations as $type => $dirs) {
             $backupFullPath = self::getPath() . '/' . $type . '/';
             Helper::mkdir($backupFullPath, true);
             foreach ($dirs as $name => $path) {
                 Helper::copyr($path, $backupFullPath . $name);
             }
         }
     } catch (\Exception $e) {
         \OC::$server->getLogger()->error('Backup creation failed. Disk full?', ['app' => 'updater']);
         self::cleanUp();
         throw new FsException($e->getMessage());
     }
     return self::getPath();
 }
Exemple #13
0
 static function internalImgs($html, $outDir = null, $headers = array())
 {
     $root = Helper::getWebroot(true);
     //Diretório raiz do site
     $basePath = dirname(Helper::normalizeSeps(Yii::app()->basePath, '/'));
     $baseUrlFull = Helper::getBaseUrl(true);
     if ($outDir == null) {
         $outDir = $root . DS . 'assets' . DS . 'external';
     }
     Helper::mkdir($outDir);
     $imgs = self::extrairImgs($html, true);
     CRequests::downloadFiles($imgs, $outDir, $headers, true);
     foreach ($imgs as $img) {
         $path = $img[0] == '/' ? $root . $img : $img;
         //Gera um path ou usa o que foi lido
         if (strpos($path, $baseUrlFull) !== 0) {
             $internalPath = CRequests::downloadFile($path, $outDir, $headers, true);
             $internalPath = Helper::normalizeSeps($internalPath, '/');
             $internalUrl = str_replace($basePath, $baseUrlFull, $internalPath);
             $html = str_replace($path, $internalUrl, $html);
         }
     }
     return $html;
 }
Exemple #14
0
<?php

/**
 * ownCloud - Updater plugin
 *
 * @author Victor Dubiniuk
 * @copyright 2012-2013 Victor Dubiniuk victor.dubiniuk@gmail.com
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 */
namespace OCA\Updater;

\OCP\User::checkAdminUser();
\OCP\Util::addScript(App::APP_ID, '3rdparty/angular');
\OCP\Util::addScript(App::APP_ID, 'app');
\OCP\Util::addScript(App::APP_ID, 'controllers');
\OCP\Util::addStyle(App::APP_ID, 'updater');
if (!@file_exists(App::getBackupBase())) {
    Helper::mkdir(App::getBackupBase());
}
$data = App::getFeed();
$isNewVersionAvailable = isset($data['version']) && $data['version'] != '' && $data['version'] !== array();
$tmpl = new \OCP\Template(App::APP_ID, 'admin');
$lastCheck = \OC_Appconfig::getValue('core', 'lastupdatedat');
$tmpl->assign('checkedAt', \OCP\Util::formatDate($lastCheck));
$tmpl->assign('isNewVersionAvailable', $isNewVersionAvailable ? 'true' : 'false');
$tmpl->assign('channels', Channel::getChannels());
$tmpl->assign('currentChannel', Channel::getCurrentChannel());
$tmpl->assign('version', isset($data['versionstring']) ? $data['versionstring'] : '');
return $tmpl->fetchPage();