/** * @param array $parameters * @return OC_OCS_Result */ public function getApps($parameters) { $apps = OC_App::listAllApps(); $list = []; foreach ($apps as $app) { $list[] = $app['id']; } $filter = isset($_GET['filter']) ? $_GET['filter'] : false; if ($filter) { switch ($filter) { case 'enabled': return new OC_OCS_Result(array('apps' => \OC_App::getEnabledApps())); break; case 'disabled': $enabled = OC_App::getEnabledApps(); return new OC_OCS_Result(array('apps' => array_diff($list, $enabled))); break; default: // Invalid filter variable return new OC_OCS_Result(null, 101); break; } } else { return new OC_OCS_Result(array('apps' => $list)); } }
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); }
function enableApp($app) { try { OC_App::enable($app); } catch (Exception $e) { echo $e; } }
/** * Deletes the given file by moving it into the trashbin. * * @param string $path */ public function unlink($path) { if (self::$disableTrash || !\OC_App::isEnabled('files_trashbin')) { return $this->storage->unlink($path); } $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path); $result = true; if (!isset($this->deletedFiles[$normalized])) { $view = Filesystem::getView(); $this->deletedFiles[$normalized] = $normalized; if ($filesPath = $view->getRelativePath($normalized)) { $filesPath = trim($filesPath, '/'); $result = \OCA\Files_Trashbin\Trashbin::move2trash($filesPath); // in cross-storage cases the file will be copied // but not deleted, so we delete it here if ($result) { $this->storage->unlink($path); } } else { $result = $this->storage->unlink($path); } unset($this->deletedFiles[$normalized]); } else { if ($this->storage->file_exists($path)) { $result = $this->storage->unlink($path); } } return $result; }
/** * @param string $script */ public function doFind($script) { $theme_dir = 'themes/' . $this->theme . '/'; if (strpos($script, '3rdparty') === 0 && $this->appendIfExist($this->thirdpartyroot, $script . '.js')) { return; } if (strpos($script, '/l10n/') !== false) { // For language files we try to load them all, so themes can overwrite // single l10n strings without having to translate all of them. $found = 0; $found += $this->appendIfExist($this->serverroot, 'core/' . $script . '.js'); $found += $this->appendIfExist($this->serverroot, $theme_dir . 'core/' . $script . '.js'); $found += $this->appendIfExist($this->serverroot, $script . '.js'); $found += $this->appendIfExist($this->serverroot, $theme_dir . $script . '.js'); $found += $this->appendIfExist($this->serverroot, $theme_dir . 'apps/' . $script . '.js'); if ($found) { return; } } else { if ($this->appendIfExist($this->serverroot, $theme_dir . 'apps/' . $script . '.js') || $this->appendIfExist($this->serverroot, $theme_dir . $script . '.js') || $this->appendIfExist($this->serverroot, $script . '.js') || $this->appendIfExist($this->serverroot, $theme_dir . 'core/' . $script . '.js') || $this->appendIfExist($this->serverroot, 'core/' . $script . '.js')) { return; } } $app = substr($script, 0, strpos($script, '/')); $script = substr($script, strpos($script, '/') + 1); $app_path = \OC_App::getAppPath($app); $app_url = \OC_App::getAppWebPath($app); // missing translations files fill be ignored if (strpos($script, 'l10n/') === 0) { $this->appendIfExist($app_path, $script . '.js', $app_url); return; } $this->append($app_path, $script . '.js', $app_url); }
public function update($tmpDir = '') { Helper::mkdir($tmpDir, true); $this->collect(); try { foreach ($this->appsToUpdate as $appId) { if (!@file_exists($this->newBase . '/' . $appId)){ continue; } $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); } else { // The app is new and doesn't exist in the current instance $pathData = first(\OC::$APPSROOTS); Helper::move($this->newBase . '/' . $appId, $pathData['path'] . '/' . $appId); } } $this->finalize(); } catch (\Exception $e) { $this->rollback(true); throw $e; } }
protected function execute(InputInterface $input, OutputInterface $output) { if ($input->getOption('shipped') === 'true' || $input->getOption('shipped') === 'false') { $shouldFilterShipped = true; $shippedFilter = $input->getOption('shipped') === 'true'; } else { $shouldFilterShipped = false; } $apps = \OC_App::getAllApps(); $enabledApps = $disabledApps = []; $versions = \OC_App::getAppVersions(); //sort enabled apps above disabled apps foreach ($apps as $app) { if ($shouldFilterShipped && \OC_App::isShipped($app) !== $shippedFilter) { continue; } if (\OC_App::isEnabled($app)) { $enabledApps[] = $app; } else { $disabledApps[] = $app; } } $apps = ['enabled' => [], 'disabled' => []]; sort($enabledApps); foreach ($enabledApps as $app) { $apps['enabled'][$app] = isset($versions[$app]) ? $versions[$app] : true; } sort($disabledApps); foreach ($disabledApps as $app) { $apps['disabled'][$app] = null; } $this->writeAppList($input, $output, $apps); }
/** * handles an api call * @param array $parameters */ public static function call($parameters) { $request = \OC::$server->getRequest(); $method = $request->getMethod(); // Prepare the request variables if ($method === 'PUT') { $parameters['_put'] = $request->getParams(); } else { if ($method === 'DELETE') { $parameters['_delete'] = $request->getParams(); } } $name = $parameters['_route']; // Foreach registered action $responses = array(); foreach (self::$actions[$name] as $action) { // Check authentication and availability if (!self::isAuthorised($action)) { $responses[] = array('app' => $action['app'], 'response' => new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'Unauthorised'), 'shipped' => OC_App::isShipped($action['app'])); continue; } if (!is_callable($action['action'])) { $responses[] = array('app' => $action['app'], 'response' => new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'Api method not found'), 'shipped' => OC_App::isShipped($action['app'])); continue; } // Run the action $responses[] = array('app' => $action['app'], 'response' => call_user_func($action['action'], $parameters), 'shipped' => OC_App::isShipped($action['app'])); } $response = self::mergeResponses($responses); $format = self::requestedFormat(); if (self::$logoutRequired) { OC_User::logout(); } self::respond($response, $format); }
protected function finalize() { foreach ($this->appsToDisable as $appId) { \OC_App::disable($appId); } parent::finalize(); }
/** * @param OutputInterface $output */ public function loadCommands(OutputInterface $output) { // $application is required to be defined in the register_command scripts $application = $this->application; require_once \OC::$SERVERROOT . '/core/register_command.php'; if ($this->config->getSystemValue('installed', false)) { if (!\OCP\Util::needUpgrade()) { OC_App::loadApps(); foreach (\OC::$server->getAppManager()->getInstalledApps() as $app) { $appPath = \OC_App::getAppPath($app); \OC::$loader->addValidRoot($appPath); $file = $appPath . '/appinfo/register_command.php'; if (file_exists($file)) { require $file; } } } else { $output->writeln("ownCloud or one of the apps require upgrade - only a limited number of commands are available"); } } else { $output->writeln("ownCloud is not installed - only a limited number of commands are available"); } $input = new ArgvInput(); if ($input->getFirstArgument() !== 'check') { $errors = \OC_Util::checkServer(\OC::$server->getConfig()); if (!empty($errors)) { foreach ($errors as $error) { $output->writeln((string) $error['error']); $output->writeln((string) $error['hint']); $output->writeln(''); } throw new \Exception("Environment not properly prepared."); } } }
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); }
public static function sendEmail($args) { $isEncrypted = OC_App::isEnabled('files_encryption'); if (!$isEncrypted || isset($_POST['continue'])) { $continue = true; } else { $continue = false; } if (OC_User::userExists($_POST['user']) && $continue) { $token = hash('sha256', OC_Util::generate_random_bytes(30) . OC_Config::getValue('passwordsalt', '')); OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', hash('sha256', $token)); // Hash the token again to prevent timing attacks $email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', ''); if (!empty($email)) { $link = OC_Helper::linkToRoute('core_lostpassword_reset', array('user' => $_POST['user'], 'token' => $token)); $link = OC_Helper::makeURLAbsolute($link); $tmpl = new OC_Template('core/lostpassword', 'email'); $tmpl->assign('link', $link, false); $msg = $tmpl->fetchPage(); $l = OC_L10N::get('core'); $from = OCP\Util::getDefaultEmailAddress('lostpassword-noreply'); try { OC_Mail::send($email, $_POST['user'], $l->t('ownCloud password reset'), $msg, $from, 'ownCloud'); } catch (Exception $e) { OC_Template::printErrorPage('A problem occurs during sending the e-mail please contact your administrator.'); } self::displayLostPasswordPage(false, true); } else { self::displayLostPasswordPage(true, false); } } else { self::displayLostPasswordPage(true, false); } }
/** * Check if the app is enabled, send json error msg if not */ public static function checkAppEnabled($app) { if( !OC_App::isEnabled($app)) { $l = OC_L10N::get('lib'); self::error(array( 'data' => array( 'message' => $l->t('Application is not enabled') ))); exit(); } }
public static function showShare($args) { \OC_Util::checkAppEnabled('files_sharing'); $token = $args['token']; \OC_App::loadApp('files_sharing'); \OC_User::setIncognitoMode(true); require_once \OC_App::getAppPath('files_sharing') . '/public.php'; }
/** * @param string $appId * @return array */ public function analyse($appId) { $appPath = \OC_App::getAppPath($appId); if ($appPath === false) { throw new \RuntimeException("No app with given id <{$appId}> known."); } return $this->analyseFolder($appPath); }
/** * Check if the app is enabled, send json error msg if not * @param string $app * @deprecated Use the AppFramework instead. It will automatically check if the app is enabled. */ public static function checkAppEnabled($app) { if (!OC_App::isEnabled($app)) { $l = \OC::$server->getL10N('lib'); self::error(array('data' => array('message' => $l->t('Application is not enabled'), 'error' => 'application_not_enabled'))); exit; } }
protected function httpGet($uri) { $range = $this->getHTTPRange(); if (OC_App::isEnabled('files_encryption') && $range) { // encryption does not support range requests $this->ignoreRangeHeader = true; } return parent::httpGet($uri); }
function tearDown() { // reset app files_trashbin if ($this->stateFilesTrashbin) { OC_App::enable('files_trashbin'); } else { OC_App::disable('files_trashbin'); } }
/** * @param string $appId * @return array */ public function analyse($appId) { $appPath = \OC_App::getAppPath($appId); if ($appPath === false) { throw new \RuntimeException("No app with given id <{$appId}> known."); } $errors = []; $info = $this->infoParser->parse($appPath . '/appinfo/info.xml'); foreach ($info as $key => $value) { if (is_array($value)) { $value = json_encode($value); } if (in_array($key, $this->mandatoryFields)) { $this->emit('InfoChecker', 'mandatoryFieldFound', [$key, $value]); continue; } if (in_array($key, $this->optionalFields)) { $this->emit('InfoChecker', 'optionalFieldFound', [$key, $value]); continue; } if (in_array($key, $this->deprecatedFields)) { // skip empty arrays - empty arrays for remote and public are always added if ($value === '[]' && in_array($key, ['public', 'remote', 'info'])) { continue; } $this->emit('InfoChecker', 'deprecatedFieldFound', [$key, $value]); continue; } $this->emit('InfoChecker', 'unusedFieldFound', [$key, $value]); } foreach ($this->mandatoryFields as $key) { if (!isset($info[$key])) { $this->emit('InfoChecker', 'mandatoryFieldMissing', [$key]); $errors[] = ['type' => 'mandatoryFieldMissing', 'field' => $key]; } } $versionFile = $appPath . '/appinfo/version'; if (is_file($versionFile)) { $version = trim(file_get_contents($versionFile)); if (isset($info['version'])) { if ($info['version'] !== $version) { $this->emit('InfoChecker', 'differentVersions', [$version, $info['version']]); $errors[] = ['type' => 'differentVersions', 'message' => 'appinfo/version: ' . $version . ' - appinfo/info.xml: ' . $info['version']]; } else { $this->emit('InfoChecker', 'sameVersions', [$versionFile]); } } else { $this->emit('InfoChecker', 'migrateVersion', [$version]); } } else { if (!isset($info['version'])) { $this->emit('InfoChecker', 'mandatoryFieldMissing', ['version']); $errors[] = ['type' => 'mandatoryFieldMissing', 'field' => 'version']; } } return $errors; }
function tearDown() { // reset app files_encryption if ($this->stateFilesEncryption) { \OC_App::enable('files_encryption'); } else { \OC_App::disable('files_encryption'); } }
public function __construct() { $this->filePath = \OC_App::getAppPath('owncollab_talks') . '/config/config.php'; if (is_file($this->filePath)) { $this->read(); } else { $this->error = 'File "owncollab_talks/config/config.php" not exist'; } }
/** * update script for the removal of the logical "Shared" folder, we create physical "Shared" folder and * update the users file_target so that it doesn't make any difference for the user * @note parameters are just for testing, please ignore them */ function removeSharedFolder($mkdirs = true, $chunkSize = 99) { $query = OCP\DB::prepare('SELECT * FROM `*PREFIX*share`'); $result = $query->execute(); $view = new \OC\Files\View('/'); $users = array(); $shares = array(); //we need to set up user backends OC_User::useBackend(new OC_User_Database()); OC_Group::useBackend(new OC_Group_Database()); OC_App::loadApps(array('authentication')); //we need to set up user backends, otherwise creating the shares will fail with "because user does not exist" while ($row = $result->fetchRow()) { //collect all user shares if ((int) $row['share_type'] === 0 && ($row['item_type'] === 'file' || $row['item_type'] === 'folder')) { $users[] = $row['share_with']; $shares[$row['id']] = $row['file_target']; } else { if ((int) $row['share_type'] === 1 && ($row['item_type'] === 'file' || $row['item_type'] === 'folder')) { //collect all group shares $users = array_merge($users, \OC_group::usersInGroup($row['share_with'])); $shares[$row['id']] = $row['file_target']; } else { if ((int) $row['share_type'] === 2) { $shares[$row['id']] = $row['file_target']; } } } } $unique_users = array_unique($users); if (!empty($unique_users) && !empty($shares)) { // create folder Shared for each user if ($mkdirs) { foreach ($unique_users as $user) { \OC\Files\Filesystem::initMountPoints($user); if (!$view->file_exists('/' . $user . '/files/Shared')) { $view->mkdir('/' . $user . '/files/Shared'); } } } $chunkedShareList = array_chunk($shares, $chunkSize, true); $connection = \OC_DB::getConnection(); foreach ($chunkedShareList as $subList) { $statement = "UPDATE `*PREFIX*share` SET `file_target` = CASE `id` "; //update share table $ids = implode(',', array_keys($subList)); foreach ($subList as $id => $target) { $statement .= "WHEN " . $connection->quote($id, \PDO::PARAM_INT) . " THEN " . $connection->quote('/Shared' . $target, \PDO::PARAM_STR); } $statement .= ' END WHERE `id` IN (' . $ids . ')'; $query = OCP\DB::prepare($statement); $query->execute(array()); } // set config to keep the Shared folder as the default location for new shares \OCA\Files_Sharing\Helper::setShareFolder('/Shared'); } }
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); }
public static function tearDownAfterClass() { \OC_FileProxy::$enabled = true; // cleanup test user \OC_User::deleteUser(\Test_Encryption_Keymanager::TEST_USER); // reset app files_trashbin if (self::$stateFilesTrashbin) { OC_App::enable('files_trashbin'); } }
/** * @PublicPage * @NoCSRFRequired * * @return TemplateResponse */ public function generateFileURL($file) { $url = sha1($file . mt_rand()); $app_path = \OC_App::getAppPath("libreonline"); $tmp_path = $app_path . '/tmp'; //FIXME: We should use owncloud api here. copy("/var/www/owncloud/data/" . $this->userId . "/files{$file}", "{$tmp_path}/{$url}"); $uri = \OC_App::getAppWebPath('libreonline') . "/tmp/{$url}"; return $uri; }
protected function tearDown() { // reset app files_trashbin if ($this->stateFilesTrashbin) { \OC_App::enable('files_trashbin'); } else { \OC_App::disable('files_trashbin'); } parent::tearDown(); }
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); } }
public static function tearDownAfterClass() { // cleanup test user \OC_User::deleteUser(self::TEST_TRASHBIN_USER1); if (self::$encryptionStatus === true) { \OC_App::enable('files_encryption'); } \OC_Config::setValue('trashbin_retention_obligation', self::$rememberRetentionObligation); \OC_Config::setValue('trashbin_auto_expire', self::$rememberAutoExpire); \OC_Hook::clear(); }
/** * Executes the current command. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * @return null|int null or 0 if everything went fine, or an error code */ protected function execute(InputInterface $input, OutputInterface $output) { $appName = $input->getArgument('app'); $path = \OC_App::getAppPath($appName); if ($path !== false) { $output->writeln($path); return 0; } // App not found, exit with non-zero return 1; }
/** * @param string $style */ public function doFind($style) { if (strpos($style, '3rdparty') === 0 && $this->appendIfExist($this->thirdpartyroot, $style . '.css') || $this->appendIfExist($this->serverroot, $style . '.css') || $this->appendIfExist($this->serverroot, 'core/' . $style . '.css')) { return; } $app = substr($style, 0, strpos($style, '/')); $style = substr($style, strpos($style, '/') + 1); $app_path = \OC_App::getAppPath($app); $app_url = \OC_App::getAppWebPath($app); $this->append($app_path, $style . '.css', $app_url); }