Пример #1
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $appManager = \OC::$server->getAppManager();
     self::$trashBinStatus = $appManager->isEnabledForUser('files_trashbin');
     // reset backend
     \OC_User::clearBackends();
     \OC_User::useBackend('database');
     // clear share hooks
     \OC_Hook::clear('OCP\\Share');
     \OC::registerShareHooks();
     $application = new \OCA\Files_Sharing\AppInfo\Application();
     $application->registerMountProviders();
     //disable encryption
     \OC_App::disable('encryption');
     $config = \OC::$server->getConfig();
     //configure trashbin
     self::$rememberRetentionObligation = $config->getSystemValue('trashbin_retention_obligation', Files_Trashbin\Expiration::DEFAULT_RETENTION_OBLIGATION);
     $config->setSystemValue('trashbin_retention_obligation', 'auto, 2');
     // register hooks
     Files_Trashbin\Trashbin::registerHooks();
     // create test user
     self::loginHelper(self::TEST_TRASHBIN_USER2, true);
     self::loginHelper(self::TEST_TRASHBIN_USER1, true);
 }
Пример #2
0
 public function setUp()
 {
     // remember files_encryption state
     $this->stateFilesEncryption = \OC_App::isEnabled('files_encryption');
     // we want to tests with the encryption app disabled
     \OC_App::disable('files_encryption');
     $this->storage = new \OC\Files\Storage\Temporary(array());
     $textData = "dummy file data\n";
     $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
     $this->storage->mkdir('folder');
     $this->storage->file_put_contents('foo.txt', $textData);
     $this->storage->file_put_contents('foo.png', $imgData);
     $this->storage->file_put_contents('folder/bar.txt', $textData);
     $this->storage->file_put_contents('folder/bar2.txt', $textData);
     $this->scanner = $this->storage->getScanner();
     $this->scanner->scan('');
     $this->cache = $this->storage->getCache();
     \OC\Files\Filesystem::tearDown();
     if (!self::$user) {
         self::$user = uniqid();
     }
     \OC_User::createUser(self::$user, 'password');
     \OC_User::setUserId(self::$user);
     \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files');
     Filesystem::clearMounts();
     Filesystem::mount($this->storage, array(), '/' . self::$user . '/files');
     \OC_Hook::clear('OC_Filesystem');
 }
Пример #3
0
 protected function finalize()
 {
     foreach ($this->appsToDisable as $appId) {
         \OC_App::disable($appId);
     }
     parent::finalize();
 }
Пример #4
0
 public function setUp()
 {
     if (!getenv('RUN_OBJECTSTORE_TESTS')) {
         $this->markTestSkipped('objectstore tests are unreliable on travis');
     }
     \OC_App::disable('files_sharing');
     \OC_App::disable('files_versions');
     // reset backend
     \OC_User::clearBackends();
     \OC_User::useBackend('database');
     // create users
     $users = array('test');
     foreach ($users as $userName) {
         \OC_User::deleteUser($userName);
         \OC_User::createUser($userName, $userName);
     }
     // main test user
     $userName = '******';
     \OC_Util::tearDownFS();
     \OC_User::setUserId('');
     \OC\Files\Filesystem::tearDown();
     \OC_User::setUserId('test');
     $testContainer = 'oc-test-container-' . substr(md5(rand()), 0, 7);
     $params = array('username' => 'facebook100000330192569', 'password' => 'Dbdj1sXnRSHxIGc4', 'container' => $testContainer, 'autocreate' => true, 'region' => 'RegionOne', 'url' => 'http://8.21.28.222:5000/v2.0', 'tenantName' => 'facebook100000330192569', 'serviceName' => 'swift', 'user' => \OC_User::getManager()->get($userName));
     $this->objectStorage = new ObjectStoreToTest($params);
     $params['objectstore'] = $this->objectStorage;
     $this->instance = new ObjectStoreStorage($params);
 }
Пример #5
0
 function tearDown()
 {
     // reset app files_trashbin
     if ($this->stateFilesTrashbin) {
         OC_App::enable('files_trashbin');
     } else {
         OC_App::disable('files_trashbin');
     }
 }
Пример #6
0
 function tearDown()
 {
     // reset app files_encryption
     if ($this->stateFilesEncryption) {
         \OC_App::enable('files_encryption');
     } else {
         \OC_App::disable('files_encryption');
     }
 }
Пример #7
0
 protected function tearDown()
 {
     // reset app files_trashbin
     if ($this->stateFilesTrashbin) {
         \OC_App::enable('files_trashbin');
     } else {
         \OC_App::disable('files_trashbin');
     }
     parent::tearDown();
 }
Пример #8
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $appId = $input->getArgument('app-id');
     if (\OC_App::isEnabled($appId)) {
         \OC_App::disable($appId);
         $output->writeln($appId . ' disabled');
     } else {
         $output->writeln('No such app enabled: ' . $appId);
     }
 }
Пример #9
0
 function tearDown()
 {
     // reset app files_trashbin
     if ($this->stateFilesTrashbin) {
         OC_App::enable('files_trashbin');
     } else {
         OC_App::disable('files_trashbin');
     }
     $this->assertTrue(\OC_FileProxy::$enabled);
 }
Пример #10
0
 function tearDown()
 {
     // reset app files_trashbin
     if ($this->stateFilesTrashbin) {
         OC_App::enable('files_trashbin');
     } else {
         OC_App::disable('files_trashbin');
     }
     $this->assertTrue(\OC_FileProxy::$enabled);
     \OCP\Config::deleteSystemValue('cipher');
 }
Пример #11
0
 protected function tearDown()
 {
     // reset app files_trashbin
     if ($this->stateFilesTrashbin) {
         \OC_App::enable('files_trashbin');
     } else {
         \OC_App::disable('files_trashbin');
     }
     $this->assertTrue(\OC_FileProxy::$enabled);
     $this->config->deleteSystemValue('cipher');
     parent::tearDown();
 }
Пример #12
0
 /**
  * @brief Startup encryption backend upon user login
  * @note This method should never be called for users using client side encryption
  */
 public static function login($params)
 {
     $l = new \OC_L10N('files_encryption');
     //check if all requirements are met
     if (!Helper::checkRequirements()) {
         $error_msg = $l->t("Missing requirements.");
         $hint = $l->t('Please make sure that PHP 5.3.3 or newer is installed and that the OpenSSL PHP extension is enabled and configured properly. For now, the encryption app has been disabled.');
         \OC_App::disable('files_encryption');
         \OCP\Util::writeLog('Encryption library', $error_msg . ' ' . $hint, \OCP\Util::ERROR);
         \OCP\Template::printErrorPage($error_msg, $hint);
     }
     $view = new \OC_FilesystemView('/');
     // ensure filesystem is loaded
     if (!\OC\Files\Filesystem::$loaded) {
         \OC_Util::setupFS($params['uid']);
     }
     $util = new Util($view, $params['uid']);
     // setup user, if user not ready force relogin
     if (Helper::setupUser($util, $params['password']) === false) {
         return false;
     }
     $encryptedKey = Keymanager::getPrivateKey($view, $params['uid']);
     $privateKey = Crypt::decryptPrivateKey($encryptedKey, $params['password']);
     if ($privateKey === false) {
         \OCP\Util::writeLog('Encryption library', 'Private key for user "' . $params['uid'] . '" is not valid! Maybe the user password was changed from outside if so please change it back to gain access', \OCP\Util::ERROR);
     }
     $session = new \OCA\Encryption\Session($view);
     $session->setPrivateKey($privateKey);
     // Check if first-run file migration has already been performed
     $ready = false;
     if ($util->getMigrationStatus() === Util::MIGRATION_OPEN) {
         $ready = $util->beginMigration();
     }
     // If migration not yet done
     if ($ready) {
         $userView = new \OC_FilesystemView('/' . $params['uid']);
         // Set legacy encryption key if it exists, to support
         // depreciated encryption system
         if ($userView->file_exists('encryption.key') && ($encLegacyKey = $userView->file_get_contents('encryption.key'))) {
             $plainLegacyKey = Crypt::legacyDecrypt($encLegacyKey, $params['password']);
             $session->setLegacyKey($plainLegacyKey);
         }
         // Encrypt existing user files:
         // This serves to upgrade old versions of the encryption
         // app (see appinfo/spec.txt)
         if ($util->encryptAll('/' . $params['uid'] . '/' . 'files', $session->getLegacyKey(), $params['password'])) {
             \OC_Log::write('Encryption library', 'Encryption of existing files belonging to "' . $params['uid'] . '" completed', \OC_Log::INFO);
         }
         // Register successful migration in DB
         $util->finishMigration();
     }
     return true;
 }
Пример #13
0
 /**
  * @brief Startup encryption backend upon user login
  * @note This method should never be called for users using client side encryption
  */
 public static function login($params)
 {
     if (\OCP\App::isEnabled('files_encryption') === false) {
         return true;
     }
     $l = new \OC_L10N('files_encryption');
     $view = new \OC_FilesystemView('/');
     // ensure filesystem is loaded
     if (!\OC\Files\Filesystem::$loaded) {
         \OC_Util::setupFS($params['uid']);
     }
     $privateKey = \OCA\Encryption\Keymanager::getPrivateKey($view, $params['uid']);
     // if no private key exists, check server configuration
     if (!$privateKey) {
         //check if all requirements are met
         if (!Helper::checkRequirements() || !Helper::checkConfiguration()) {
             $error_msg = $l->t("Missing requirements.");
             $hint = $l->t('Please make sure that PHP 5.3.3 or newer is installed and that OpenSSL together with the PHP extension is enabled and configured properly. For now, the encryption app has been disabled.');
             \OC_App::disable('files_encryption');
             \OCP\Util::writeLog('Encryption library', $error_msg . ' ' . $hint, \OCP\Util::ERROR);
             \OCP\Template::printErrorPage($error_msg, $hint);
         }
     }
     $util = new Util($view, $params['uid']);
     // setup user, if user not ready force relogin
     if (Helper::setupUser($util, $params['password']) === false) {
         return false;
     }
     $session = $util->initEncryption($params);
     // Check if first-run file migration has already been performed
     $ready = false;
     if ($util->getMigrationStatus() === Util::MIGRATION_OPEN) {
         $ready = $util->beginMigration();
     }
     // If migration not yet done
     if ($ready) {
         $userView = new \OC_FilesystemView('/' . $params['uid']);
         // Set legacy encryption key if it exists, to support
         // depreciated encryption system
         if ($userView->file_exists('encryption.key') && ($encLegacyKey = $userView->file_get_contents('encryption.key'))) {
             $plainLegacyKey = Crypt::legacyDecrypt($encLegacyKey, $params['password']);
             $session->setLegacyKey($plainLegacyKey);
         }
         // Encrypt existing user files:
         if ($util->encryptAll('/' . $params['uid'] . '/' . 'files', $session->getLegacyKey(), $params['password'])) {
             \OC_Log::write('Encryption library', 'Encryption of existing files belonging to "' . $params['uid'] . '" completed', \OC_Log::INFO);
         }
         // Register successful migration in DB
         $util->finishMigration();
     }
     return true;
 }
Пример #14
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     // disable file proxy by default
     \OC_FileProxy::$enabled = false;
     // remember files_trashbin state
     self::$stateFilesTrashbin = \OC_App::isEnabled('files_trashbin');
     // we don't want to tests with app files_trashbin enabled
     \OC_App::disable('files_trashbin');
     // create test user
     \OC_User::deleteUser(self::TEST_USER);
     parent::loginHelper(self::TEST_USER, true);
 }
Пример #15
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $appId = $input->getArgument('app-id');
     if (\OC_App::isEnabled($appId)) {
         try {
             \OC_App::disable($appId);
             $output->writeln($appId . ' disabled');
         } catch (\Exception $e) {
             $output->writeln($e->getMessage());
             return 2;
         }
     } else {
         $output->writeln('No such app enabled: ' . $appId);
     }
 }
Пример #16
0
 public static function setUpBeforeClass()
 {
     // reset backend
     \OC_User::clearBackends();
     \OC_User::useBackend('database');
     // Filesystem related hooks
     \OCA\Encryption\Helper::registerFilesystemHooks();
     // clear and register hooks
     \OC_FileProxy::clearProxies();
     \OC_FileProxy::register(new OCA\Encryption\Proxy());
     // disable file proxy by default
     \OC_FileProxy::$enabled = false;
     // remember files_trashbin state
     self::$stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
     // we don't want to tests with app files_trashbin enabled
     \OC_App::disable('files_trashbin');
     // create test user
     \OC_User::deleteUser(\Test_Encryption_Keymanager::TEST_USER);
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Keymanager::TEST_USER, true);
 }
Пример #17
0
 /**
  * test deletion of a folder which contains share mount points. Share mount
  * points should be unshared before the folder gets deleted so
  * that the mount point doesn't end up at the trash bin
  */
 function testDeleteParentFolder()
 {
     $status = \OC_App::isEnabled('files_trashbin');
     \OC_App::enable('files_trashbin');
     \OCA\Files_Trashbin\Trashbin::registerHooks();
     $fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
     $this->assertTrue($fileinfo instanceof \OC\Files\FileInfo);
     \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     // check if user2 can see the shared folder
     $this->assertTrue($view->file_exists($this->folder));
     $foldersShared = \OCP\Share::getItemsSharedWith('folder');
     $this->assertSame(1, count($foldersShared));
     $view->mkdir("localFolder");
     $view->file_put_contents("localFolder/localFile.txt", "local file");
     $view->rename($this->folder, 'localFolder/' . $this->folder);
     // share mount point should now be moved to the subfolder
     $this->assertFalse($view->file_exists($this->folder));
     $this->assertTrue($view->file_exists('localFolder/' . $this->folder));
     $view->unlink('localFolder');
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // shared folder should be unshared
     $foldersShared = \OCP\Share::getItemsSharedWith('folder');
     $this->assertTrue(empty($foldersShared));
     // trashbin should contain the local file but not the mount point
     $rootView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
     $trashContent = \OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_FILES_SHARING_API_USER2);
     $this->assertSame(1, count($trashContent));
     $firstElement = reset($trashContent);
     $timestamp = $firstElement['mtime'];
     $this->assertTrue($rootView->file_exists('files_trashbin/files/localFolder.d' . $timestamp . '/localFile.txt'));
     $this->assertFalse($rootView->file_exists('files_trashbin/files/localFolder.d' . $timestamp . '/' . $this->folder));
     //cleanup
     $rootView->deleteAll('files_trashin');
     if ($status === false) {
         \OC_App::disable('files_trashbin');
     }
     \OC\Files\Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
 }
Пример #18
0
 public static function setUpBeforeClass()
 {
     // reset backend
     \OC_User::clearBackends();
     \OC_User::useBackend('database');
     // clear share hooks
     \OC_Hook::clear('OCP\\Share');
     \OC::registerShareHooks();
     \OCP\Util::connectHook('OC_Filesystem', 'setup', '\\OC\\Files\\Storage\\Shared', 'setup');
     //disable encryption
     self::$encryptionStatus = \OC_App::isEnabled('files_encryption');
     \OC_App::disable('files_encryption');
     //configure trashbin
     self::$rememberRetentionObligation = \OC_Config::getValue('trashbin_retention_obligation', Files_Trashbin\Trashbin::DEFAULT_RETENTION_OBLIGATION);
     \OC_Config::setValue('trashbin_retention_obligation', 2);
     self::$rememberAutoExpire = \OC_Config::getValue('trashbin_auto_expire', true);
     \OC_Config::setValue('trashbin_auto_expire', true);
     // register hooks
     Files_Trashbin\Trashbin::registerHooks();
     // create test user
     self::loginHelper(self::TEST_TRASHBIN_USER2, true);
     self::loginHelper(self::TEST_TRASHBIN_USER1, true);
 }
Пример #19
0
 /**
  * Encrypt all files in a directory
  * @param string $dirPath the directory whose files will be encrypted
  * @return bool
  * @note Encryption is recursive
  */
 public function encryptAll($dirPath)
 {
     $result = true;
     $found = $this->findEncFiles($dirPath);
     // Disable proxy to prevent file being encrypted twice
     \OC_FileProxy::$enabled = false;
     $versionStatus = \OCP\App::isEnabled('files_versions');
     \OC_App::disable('files_versions');
     $encryptedFiles = array();
     // Encrypt unencrypted files
     foreach ($found['plain'] as $plainFile) {
         //get file info
         $fileInfo = \OC\Files\Filesystem::getFileInfo($plainFile['path']);
         //relative to data/<user>/file
         $relPath = $plainFile['path'];
         //relative to /data
         $rawPath = '/' . $this->userId . '/files/' . $plainFile['path'];
         // keep timestamp
         $timestamp = $fileInfo['mtime'];
         // Open plain file handle for binary reading
         $plainHandle = $this->view->fopen($rawPath, 'rb');
         // Open enc file handle for binary writing, with same filename as original plain file
         $encHandle = fopen('crypt://' . $rawPath . '.part', 'wb');
         if (is_resource($encHandle) && is_resource($plainHandle)) {
             // Move plain file to a temporary location
             $size = stream_copy_to_stream($plainHandle, $encHandle);
             fclose($encHandle);
             fclose($plainHandle);
             $fakeRoot = $this->view->getRoot();
             $this->view->chroot('/' . $this->userId . '/files');
             $this->view->rename($relPath . '.part', $relPath);
             // set timestamp
             $this->view->touch($relPath, $timestamp);
             $encSize = $this->view->filesize($relPath);
             $this->view->chroot($fakeRoot);
             // Add the file to the cache
             \OC\Files\Filesystem::putFileInfo($relPath, array('encrypted' => true, 'size' => $encSize, 'unencrypted_size' => $size, 'etag' => $fileInfo['etag']));
             $encryptedFiles[] = $relPath;
         } else {
             \OCP\Util::writeLog('files_encryption', 'initial encryption: could not encrypt ' . $rawPath, \OCP\Util::FATAL);
             $result = false;
         }
     }
     \OC_FileProxy::$enabled = true;
     if ($versionStatus) {
         \OC_App::enable('files_versions');
     }
     $result = $result && $this->encryptVersions($encryptedFiles);
     return $result;
 }
Пример #20
0
 public static function setUpBeforeClass()
 {
     self::$trashBinStatus = \OC_App::isEnabled('files_trashbin');
     \OC_App::disable('files_trashbin');
 }
Пример #21
0
 function testDeleteHooksForSharedFiles()
 {
     self::logoutHelper();
     self::loginHelper(self::TEST_ENCRYPTION_HOOKS_USER1);
     \OC_User::setUserId(self::TEST_ENCRYPTION_HOOKS_USER1);
     // remember files_trashbin state
     $stateFilesTrashbin = \OC_App::isEnabled('files_trashbin');
     // we want to tests with app files_trashbin disabled
     \OC_App::disable('files_trashbin');
     // make sure that the trash bin is disabled
     $this->assertFalse(\OC_APP::isEnabled('files_trashbin'));
     $this->user1View->file_put_contents($this->filename, $this->data);
     // check if all keys are generated
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/fileKey'));
     // get the file info from previous created file
     $fileInfo = $this->user1View->getFileInfo($this->filename);
     // check if we have a valid file info
     $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
     // share the file with user2
     \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_HOOKS_USER2, \OCP\Constants::PERMISSION_ALL);
     // check if new share key exists
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
     self::logoutHelper();
     self::loginHelper(self::TEST_ENCRYPTION_HOOKS_USER2);
     \OC_User::setUserId(self::TEST_ENCRYPTION_HOOKS_USER2);
     // user2 update the shared file
     $this->user2View->file_put_contents($this->filename, $this->data);
     // keys should be stored at user1s dir, not in user2s
     $this->assertFalse($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
     $this->assertFalse($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/' . $this->filename . '/fileKey'));
     // delete the Shared file from user1 in data/user2/files/Shared
     $result = $this->user2View->unlink($this->filename);
     $this->assertTrue($result);
     // share key for user2 from user1s home should be gone, all other keys should still exists
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
     $this->assertFalse($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/fileKey'));
     // cleanup
     self::logoutHelper();
     self::loginHelper(self::TEST_ENCRYPTION_HOOKS_USER1);
     \OC_User::setUserId(self::TEST_ENCRYPTION_HOOKS_USER1);
     if ($stateFilesTrashbin) {
         \OC_App::enable('files_trashbin');
     } else {
         \OC_App::disable('files_trashbin');
     }
 }
Пример #22
0
 /**
  * check if the current enabled apps are compatible with the current
  * ownCloud version. disable them if not.
  * This is important if you upgrade ownCloud and have non ported 3rd
  * party apps installed.
  *
  * @return array
  * @throws \Exception
  */
 private function checkAppsRequirements()
 {
     $isCoreUpgrade = $this->isCodeUpgrade();
     $apps = OC_App::getEnabledApps();
     $version = \OCP\Util::getVersion();
     $disabledApps = [];
     foreach ($apps as $app) {
         // check if the app is compatible with this version of ownCloud
         $info = OC_App::getAppInfo($app);
         if (!OC_App::isAppCompatible($version, $info)) {
             OC_App::disable($app);
             $this->emit('\\OC\\Updater', 'incompatibleAppDisabled', array($app));
         }
         // no need to disable any app in case this is a non-core upgrade
         if (!$isCoreUpgrade) {
             continue;
         }
         // shipped apps will remain enabled
         if (OC_App::isShipped($app)) {
             continue;
         }
         // authentication and session apps will remain enabled as well
         if (OC_App::isType($app, ['session', 'authentication'])) {
             continue;
         }
         // disable any other 3rd party apps if not overriden
         if (!$this->skip3rdPartyAppsDisable) {
             \OC_App::disable($app);
             $disabledApps[] = $app;
             $this->emit('\\OC\\Updater', 'thirdPartyAppDisabled', array($app));
         }
     }
     return $disabledApps;
 }
Пример #23
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;
 }
Пример #24
0
 public static function tearDownAfterClass()
 {
     // cleanup users
     \OC_User::deleteUser(self::TEST_FILES_SHARING_API_USER1);
     \OC_User::deleteUser(self::TEST_FILES_SHARING_API_USER2);
     \OC_User::deleteUser(self::TEST_FILES_SHARING_API_USER3);
     // delete group
     \OC_Group::deleteGroup(self::TEST_FILES_SHARING_API_GROUP1);
     // reset app files_encryption
     if (self::$stateFilesEncryption) {
         \OC_App::enable('files_encryption');
     } else {
         \OC_App::disable('files_encryption');
     }
 }
Пример #25
0
<?php
OCP\JSON::checkAdminUser();
OCP\JSON::callCheck();

if (!array_key_exists('appid', $_POST)) {
	OC_JSON::error();
	exit;
}

$appId = $_POST['appid'];
$appId = OC_App::cleanAppId($appId);

// FIXME: Clear the cache - move that into some sane helper method
\OC::$server->getMemCacheFactory()->create('settings')->remove('listApps-0');
\OC::$server->getMemCacheFactory()->create('settings')->remove('listApps-1');

OC_App::disable($appId);
OC_JSON::success();
<?php

// Init owncloud
require_once '../../lib/base.php';
OC_JSON::checkAdminUser();
OC_JSON::setContentTypeHeader();
OC_App::disable($_POST['appid']);
Пример #27
0
 function testDecryptAll()
 {
     $filename = "/decryptAll" . $this->getUniqueID() . ".txt";
     $datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/');
     $userdir = $datadir . '/' . $this->userId . '/files/';
     $this->view->file_put_contents($this->userId . '/files/' . $filename, $this->dataShort);
     $fileInfoEncrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
     $this->assertTrue($fileInfoEncrypted instanceof \OC\Files\FileInfo);
     $this->assertEquals($fileInfoEncrypted['encrypted'], 1);
     $encContent = file_get_contents($userdir . $filename);
     \OC_App::disable('files_encryption');
     $user = \OCP\User::getUser();
     $this->logoutHelper();
     $this->loginHelper($user, false, false, false);
     $content = file_get_contents($userdir . $filename);
     //content should be encrypted
     $this->assertSame($encContent, $content);
     // now we load the encryption app again
     \OC_App::loadApp('files_encryption');
     // init encryption app
     $params = array('uid' => \OCP\User::getUser(), 'password' => \OCP\User::getUser());
     $view = new \OC\Files\View('/');
     $util = new \OCA\Files_Encryption\Util($view, \OCP\User::getUser());
     $result = $util->initEncryption($params);
     $this->assertTrue($result instanceof \OCA\Files_Encryption\Session);
     $successful = $util->decryptAll();
     $this->assertTrue($successful);
     $this->logoutHelper();
     $this->loginHelper($user, false, false, false);
     // file should be unencrypted and fileInfo should contain the correct values
     $content = file_get_contents($userdir . $filename);
     // now we should get the plain data
     $this->assertSame($this->dataShort, $content);
     $fileInfoUnencrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
     $this->assertTrue($fileInfoUnencrypted instanceof \OC\Files\FileInfo);
     // check if mtime and etags unchanged
     $this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']);
     $this->assertSame($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']);
     // file should no longer be encrypted
     $this->assertEquals(0, $fileInfoUnencrypted['encrypted']);
     $backupPath = $this->getBackupPath('decryptAll');
     // check if the keys where moved to the backup location
     $this->assertTrue($this->view->is_dir($backupPath . '/keys'));
     $this->assertTrue($this->view->file_exists($backupPath . '/keys/' . $filename . '/fileKey'));
     $this->assertTrue($this->view->file_exists($backupPath . '/keys/' . $filename . '/' . $user . '.shareKey'));
     // cleanup
     $this->view->unlink($this->userId . '/files/' . $filename);
     $this->view->deleteAll($backupPath);
     \OC_App::enable('files_encryption');
 }
Пример #28
0
 /**
  * check if the current enabled apps are compatible with the current
  * ownCloud version. disable them if not.
  * This is important if you upgrade ownCloud and have non ported 3rd
  * party apps installed.
  */
 public static function checkAppsRequirements($apps = array())
 {
     if (empty($apps)) {
         $apps = OC_App::getEnabledApps();
     }
     $version = OC_Util::getVersion();
     foreach ($apps as $app) {
         // check if the app is compatible with this version of ownCloud
         $info = OC_App::getAppInfo($app);
         if (!isset($info['require']) or !self::isAppVersionCompatible($version, $info['require'])) {
             OC_Log::write('core', 'App "' . $info['name'] . '" (' . $app . ') can\'t be used because it is' . ' not compatible with this version of ownCloud', OC_Log::ERROR);
             OC_App::disable($app);
             OC_Hook::emit('update', 'success', 'Disabled ' . $info['name'] . ' app because it is not compatible');
         }
     }
 }
Пример #29
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;
 }
Пример #30
0
 /**
  * Handle the request
  */
 public static function handleRequest()
 {
     \OC::$server->getEventLogger()->start('handle_request', 'Handle request');
     $systemConfig = \OC::$server->getSystemConfig();
     // load all the classpaths from the enabled apps so they are available
     // in the routing files of each app
     OC::loadAppClassPaths();
     // Check if ownCloud is installed or in maintenance (update) mode
     if (!$systemConfig->getValue('installed', false)) {
         \OC::$server->getSession()->clear();
         $setupHelper = new OC\Setup(\OC::$server->getConfig(), \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), new \OC_Defaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom());
         $controller = new OC\Core\Controller\SetupController($setupHelper);
         $controller->run($_POST);
         exit;
     }
     $request = \OC::$server->getRequest();
     // Check if requested URL matches 'index.php/occ'
     $isOccControllerRequested = preg_match('|/index\\.php$|', $request->getScriptName()) === 1 && strpos($request->getPathInfo(), '/occ/') === 0;
     $requestPath = $request->getRawPathInfo();
     if (substr($requestPath, -3) !== '.js') {
         // we need these files during the upgrade
         self::checkMaintenanceMode($request);
         $needUpgrade = self::checkUpgrade(!$isOccControllerRequested);
     }
     // emergency app disabling
     if ($requestPath === '/disableapp' && $request->getMethod() === 'POST' && (string) $request->getParam('appid') !== '') {
         \OCP\JSON::callCheck();
         \OCP\JSON::checkAdminUser();
         $appId = (string) $request->getParam('appid');
         $appId = \OC_App::cleanAppId($appId);
         \OC_App::disable($appId);
         \OC_JSON::success();
         exit;
     }
     try {
         // Always load authentication apps
         OC_App::loadApps(['authentication']);
     } catch (\OC\NeedsUpdateException $e) {
         if ($isOccControllerRequested && $needUpgrade) {
             OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo());
             return;
         }
         throw $e;
     }
     // Load minimum set of apps
     if (!self::checkUpgrade(false) && !$systemConfig->getValue('maintenance', false)) {
         // For logged-in users: Load everything
         if (OC_User::isLoggedIn()) {
             OC_App::loadApps();
         } else {
             // For guests: Load only filesystem and logging
             OC_App::loadApps(array('filesystem', 'logging'));
             self::handleLogin($request);
         }
     }
     if (!self::$CLI) {
         try {
             if (!$systemConfig->getValue('maintenance', false) && !self::checkUpgrade(false)) {
                 OC_App::loadApps(array('filesystem', 'logging'));
                 OC_App::loadApps();
             }
             self::checkSingleUserMode();
             OC_Util::setupFS();
             OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo());
             return;
         } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) {
             //header('HTTP/1.0 404 Not Found');
         } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) {
             OC_Response::setStatus(405);
             return;
         }
     }
     // Handle WebDAV
     if ($_SERVER['REQUEST_METHOD'] == 'PROPFIND') {
         // not allowed any more to prevent people
         // mounting this root directly.
         // Users need to mount remote.php/webdav instead.
         header('HTTP/1.1 405 Method Not Allowed');
         header('Status: 405 Method Not Allowed');
         return;
     }
     // Someone is logged in
     if (OC_User::isLoggedIn()) {
         OC_App::loadApps();
         OC_User::setupBackends();
         OC_Util::setupFS();
         // FIXME
         // Redirect to default application
         OC_Util::redirectToDefaultPage();
     } else {
         // Not handled and not logged in
         header('Location: ' . \OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm'));
     }
 }