public function setUp() { if (OC_Util::runningOnWindows()) { $this->markTestSkipped('tar archives are not supported on windows'); } parent::setUp(); }
protected function setUp() { parent::setUp(); if (\OC_Util::runningOnWindows()) { $this->markTestSkipped('[Windows] tar archives are not supported on Windows'); } }
protected function setUp() { parent::setUp(); if (\OC_Util::runningOnWindows()) { $this->markTestSkipped('[Windows] '); } }
/** * Remove all entries from the files map table * @param string $dataDir */ protected static function tearDownAfterClassCleanFileMapper($dataDir) { if (\OC_Util::runningOnWindows()) { $mapper = new \OC\Files\Mapper($dataDir); $mapper->removePath($dataDir, true, true); } }
/** * Tests that the root path matches the data dir */ public function testRoot() { if (\OC_Util::runningOnWindows()) { // Windows removes trailing slashes when returning paths $this->assertEquals(rtrim($this->tmpDir, '/'), $this->instance->getLocalFolder('')); } else { $this->assertEquals($this->tmpDir, $this->instance->getLocalFolder('')); } }
function testGetStringMimeType() { if (\OC_Util::runningOnWindows()) { $this->markTestSkipped('[Windows] Strings have mimetype application/octet-stream on Windows'); } $result = OC_Helper::getStringMimeType("/data/data.tar.gz"); $expected = 'text/plain; charset=us-ascii'; $this->assertEquals($result, $expected); }
public function testDetectString() { if (\OC_Util::runningOnWindows()) { $this->markTestSkipped('[Windows] Strings have mimetype application/octet-stream on Windows'); } $result = $this->detection->detectString("/data/data.tar.gz"); $expected = 'text/plain; charset=us-ascii'; $this->assertEquals($expected, $result); }
/** * Load storage backends provided by this app */ protected function loadBackends() { $container = $this->getContainer(); $service = $container->query('OCA\\Files_External\\Service\\BackendService'); $service->registerBackends([$container->query('OCA\\Files_External\\Lib\\Backend\\Local'), $container->query('OCA\\Files_External\\Lib\\Backend\\FTP'), $container->query('OCA\\Files_External\\Lib\\Backend\\DAV'), $container->query('OCA\\Files_External\\Lib\\Backend\\OwnCloud'), $container->query('OCA\\Files_External\\Lib\\Backend\\SFTP'), $container->query('OCA\\Files_External\\Lib\\Backend\\AmazonS3'), $container->query('OCA\\Files_External\\Lib\\Backend\\Dropbox'), $container->query('OCA\\Files_External\\Lib\\Backend\\Google'), $container->query('OCA\\Files_External\\Lib\\Backend\\Swift'), $container->query('OCA\\Files_External\\Lib\\Backend\\SFTP_Key')]); if (!\OC_Util::runningOnWindows()) { $service->registerBackends([$container->query('OCA\\Files_External\\Lib\\Backend\\SMB'), $container->query('OCA\\Files_External\\Lib\\Backend\\SMB_OC')]); } }
public function dataFileNameProvider() { $path = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR; $filePaths = array(array($path . 'lorem.txt', 446)); if (!\OC_Util::runningOnWindows()) { $filePaths[] = array($path . 'strängé filename (duplicate #2).txt', 446); } return $filePaths; }
/** * @{inheritdoc} */ public function getBackends() { $container = $this->getContainer(); $backends = [$container->query('OCA\\Files_External\\Lib\\Backend\\Local'), $container->query('OCA\\Files_External\\Lib\\Backend\\FTP'), $container->query('OCA\\Files_External\\Lib\\Backend\\DAV'), $container->query('OCA\\Files_External\\Lib\\Backend\\OwnCloud'), $container->query('OCA\\Files_External\\Lib\\Backend\\SFTP'), $container->query('OCA\\Files_External\\Lib\\Backend\\AmazonS3'), $container->query('OCA\\Files_External\\Lib\\Backend\\Dropbox'), $container->query('OCA\\Files_External\\Lib\\Backend\\Google'), $container->query('OCA\\Files_External\\Lib\\Backend\\Swift'), $container->query('OCA\\Files_External\\Lib\\Backend\\SFTP_Key')]; if (!\OC_Util::runningOnWindows()) { $backends[] = $container->query('OCA\\Files_External\\Lib\\Backend\\SMB'); $backends[] = $container->query('OCA\\Files_External\\Lib\\Backend\\SMB_OC'); } return $backends; }
public function tearDown() { \OC_User::setUserId($this->user); foreach ($this->storages as $storage) { $cache = $storage->getCache(); $ids = $cache->getAll(); $cache->clear(); } if ($this->tempStorage && !\OC_Util::runningOnWindows()) { system('rm -rf ' . escapeshellarg($this->tempStorage->getDataDir())); } }
public function testEtagChange() { if (\OC_Util::runningOnWindows()) { $this->markTestSkipped('On Windows platform we have no stable etag generation - yet'); } $this->instance->file_put_contents('test.txt', 'foo'); $this->instance->touch('test.txt', time() - 2); $etag1 = $this->instance->getETag('test.txt'); $this->instance->file_put_contents('test.txt', 'bar'); $etag2 = $this->instance->getETag('test.txt'); $this->assertNotEquals($etag1, $etag2); }
public function testMimeType() { $img = new \OC_Image(OC::$SERVERROOT . '/tests/data/testimage.png'); $this->assertEquals('image/png', $img->mimeType()); $img = new \OC_Image(null); $this->assertEquals('', $img->mimeType()); if (\OC_Util::runningOnWindows()) { $this->markTestSkipped('[Windows] Images created with imagecreate() are pngs on windows'); } $img = new \OC_Image(file_get_contents(OC::$SERVERROOT . '/tests/data/testimage.jpg')); $this->assertEquals('image/jpeg', $img->mimeType()); $img = new \OC_Image(base64_encode(file_get_contents(OC::$SERVERROOT . '/tests/data/testimage.gif'))); $this->assertEquals('image/gif', $img->mimeType()); }
$template->assign('suggestedOverwriteCliUrl', $suggestedOverwriteCliUrl); $template->assign('allowLinks', $appConfig->getValue('core', 'shareapi_allow_links', 'yes')); $template->assign('enforceLinkPassword', \OCP\Util::isPublicLinkPasswordRequired()); $template->assign('allowPublicUpload', $appConfig->getValue('core', 'shareapi_allow_public_upload', 'yes')); $template->assign('allowResharing', $appConfig->getValue('core', 'shareapi_allow_resharing', 'yes')); $template->assign('allowPublicMailNotification', $appConfig->getValue('core', 'shareapi_allow_public_notification', 'no')); $template->assign('allowMailNotification', $appConfig->getValue('core', 'shareapi_allow_mail_notification', 'no')); $template->assign('onlyShareWithGroupMembers', \OC\Share\Share::shareWithGroupMembersOnly()); $databaseOverload = strpos(\OCP\Config::getSystemValue('dbtype'), 'sqlite') !== false; $template->assign('databaseOverload', $databaseOverload); $template->assign('cronErrors', $appConfig->getValue('core', 'cronErrors')); // warn if php is not setup properly to get system variables with getenv $path = getenv('PATH'); $template->assign('getenvServerNotWorking', empty($path)); // warn if Windows is used $template->assign('WindowsWarning', OC_Util::runningOnWindows()); // warn if outdated version of a memcache module is used $caches = ['apcu' => ['name' => $l->t('APCu'), 'version' => '4.0.6'], 'redis' => ['name' => $l->t('Redis'), 'version' => '2.2.5']]; $outdatedCaches = []; foreach ($caches as $php_module => $data) { $isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<'); if ($isOutdated) { $outdatedCaches[$php_module] = $data; } } $template->assign('OutdatedCacheWarning', $outdatedCaches); // add hardcoded forms from the template $forms = OC_App::getForms('admin'); $formsAndMore = array(); if ($request->getServerProtocol() !== 'https' || !OC_Util::isAnnotationsWorking() || $suggestedOverwriteCliUrl || !OC_Util::isSetLocaleWorking() || !OC_Util::fileInfoLoaded() || $databaseOverload) { $formsAndMore[] = array('anchor' => 'security-warning', 'section-name' => $l->t('Security & setup warnings'));
/** * Register the default providers (if enabled) */ protected function registerCoreProviders() { if ($this->registeredCoreProviders) { return; } $this->registeredCoreProviders = true; $this->registerCoreProvider('OC\\Preview\\TXT', '/text\\/plain/'); $this->registerCoreProvider('OC\\Preview\\MarkDown', '/text\\/(x-)?markdown/'); $this->registerCoreProvider('OC\\Preview\\PNG', '/image\\/png/'); $this->registerCoreProvider('OC\\Preview\\JPEG', '/image\\/jpeg/'); $this->registerCoreProvider('OC\\Preview\\GIF', '/image\\/gif/'); $this->registerCoreProvider('OC\\Preview\\BMP', '/image\\/bmp/'); $this->registerCoreProvider('OC\\Preview\\XBitmap', '/image\\/x-xbitmap/'); $this->registerCoreProvider('OC\\Preview\\MP3', '/audio\\/mpeg/'); // SVG, Office and Bitmap require imagick if (extension_loaded('imagick')) { $checkImagick = new \Imagick(); $imagickProviders = ['SVG' => ['mimetype' => '/image\\/svg\\+xml/', 'class' => '\\OC\\Preview\\SVG'], 'TIFF' => ['mimetype' => '/image\\/tiff/', 'class' => '\\OC\\Preview\\TIFF'], 'PDF' => ['mimetype' => '/application\\/pdf/', 'class' => '\\OC\\Preview\\PDF'], 'AI' => ['mimetype' => '/application\\/illustrator/', 'class' => '\\OC\\Preview\\Illustrator'], 'PSD' => ['mimetype' => '/application\\/x-photoshop/', 'class' => '\\OC\\Preview\\Photoshop'], 'EPS' => ['mimetype' => '/application\\/postscript/', 'class' => '\\OC\\Preview\\Postscript'], 'TTF' => ['mimetype' => '/application\\/(?:font-sfnt|x-font$)/', 'class' => '\\OC\\Preview\\Font']]; foreach ($imagickProviders as $queryFormat => $provider) { $class = $provider['class']; if (!in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) { continue; } if (count($checkImagick->queryFormats($queryFormat)) === 1) { $this->registerCoreProvider($class, $provider['mimetype']); } } if (count($checkImagick->queryFormats('PDF')) === 1) { // Office previews are currently not supported on Windows if (!\OC_Util::runningOnWindows() && \OC_Helper::is_function_enabled('shell_exec')) { $officeFound = is_string($this->config->getSystemValue('preview_libreoffice_path', null)); if (!$officeFound) { //let's see if there is libreoffice or openoffice on this machine $whichLibreOffice = shell_exec('command -v libreoffice'); $officeFound = !empty($whichLibreOffice); if (!$officeFound) { $whichOpenOffice = shell_exec('command -v openoffice'); $officeFound = !empty($whichOpenOffice); } } if ($officeFound) { $this->registerCoreProvider('\\OC\\Preview\\MSOfficeDoc', '/application\\/msword/'); $this->registerCoreProvider('\\OC\\Preview\\MSOffice2003', '/application\\/vnd.ms-.*/'); $this->registerCoreProvider('\\OC\\Preview\\MSOffice2007', '/application\\/vnd.openxmlformats-officedocument.*/'); $this->registerCoreProvider('\\OC\\Preview\\OpenDocument', '/application\\/vnd.oasis.opendocument.*/'); $this->registerCoreProvider('\\OC\\Preview\\StarOffice', '/application\\/vnd.sun.xml.*/'); } } } } // Video requires avconv or ffmpeg and is therefor // currently not supported on Windows. if (in_array('OC\\Preview\\Movie', $this->getEnabledDefaultProvider()) && !\OC_Util::runningOnWindows()) { $avconvBinary = \OC_Helper::findBinaryPath('avconv'); $ffmpegBinary = $avconvBinary ? null : \OC_Helper::findBinaryPath('ffmpeg'); if ($avconvBinary || $ffmpegBinary) { // FIXME // a bit hacky but didn't want to use subclasses \OC\Preview\Movie::$avconvBinary = $avconvBinary; \OC\Preview\Movie::$ffmpegBinary = $ffmpegBinary; $this->registerCoreProvider('\\OC\\Preview\\Movie', '/video\\/.*/'); } } }
/** * @param $options * @return array */ public static function install($options) { $l = self::getTrans(); $error = array(); $dbType = $options['dbtype']; if (empty($options['adminlogin'])) { $error[] = $l->t('Set an admin username.'); } if (empty($options['adminpass'])) { $error[] = $l->t('Set an admin password.'); } if (empty($options['directory'])) { $options['directory'] = OC::$SERVERROOT . "/data"; } if (!isset(self::$dbSetupClasses[$dbType])) { $dbType = 'sqlite'; } $username = htmlspecialchars_decode($options['adminlogin']); $password = htmlspecialchars_decode($options['adminpass']); $dataDir = htmlspecialchars_decode($options['directory']); $class = self::$dbSetupClasses[$dbType]; /** @var \OC\Setup\AbstractDatabase $dbSetup */ $dbSetup = new $class(self::getTrans(), 'db_structure.xml'); $error = array_merge($error, $dbSetup->validate($options)); // validate the data directory if (!is_dir($dataDir) and !mkdir($dataDir) or !is_writable($dataDir)) { $error[] = $l->t("Can't create or write into the data directory %s", array($dataDir)); } if (count($error) != 0) { return $error; } //no errors, good if (isset($options['trusted_domains']) && is_array($options['trusted_domains'])) { $trustedDomains = $options['trusted_domains']; } else { $trustedDomains = array(OC_Request::serverHost()); } if (OC_Util::runningOnWindows()) { $dataDir = rtrim(realpath($dataDir), '\\'); } //use sqlite3 when available, otherwise sqlite2 will be used. if ($dbType == 'sqlite' and class_exists('SQLite3')) { $dbType = 'sqlite3'; } //generate a random salt that is used to salt the local user passwords $salt = \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(30); \OC::$server->getConfig()->setSystemValue('passwordsalt', $salt); // generate a secret $secret = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(48); \OC::$server->getConfig()->setSystemValue('secret', $secret); //write the config file \OC::$server->getConfig()->setSystemValue('trusted_domains', $trustedDomains); \OC::$server->getConfig()->setSystemValue('datadirectory', $dataDir); \OC::$server->getConfig()->setSystemValue('overwrite.cli.url', \OC_Request::serverProtocol() . '://' . \OC_Request::serverHost() . OC::$WEBROOT); \OC::$server->getConfig()->setSystemValue('dbtype', $dbType); \OC::$server->getConfig()->setSystemValue('version', implode('.', OC_Util::getVersion())); try { $dbSetup->initialize($options); $dbSetup->setupDatabase($username); } catch (DatabaseSetupException $e) { $error[] = array('error' => $e->getMessage(), 'hint' => $e->getHint()); return $error; } catch (Exception $e) { $error[] = array('error' => 'Error while trying to create admin user: '******'hint' => ''); return $error; } //create the user and group try { OC_User::createUser($username, $password); } catch (Exception $exception) { $error[] = $exception->getMessage(); } if (count($error) == 0) { $appConfig = \OC::$server->getAppConfig(); $appConfig->setValue('core', 'installedat', microtime(true)); $appConfig->setValue('core', 'lastupdatedat', microtime(true)); OC_Group::createGroup('admin'); OC_Group::addToGroup($username, 'admin'); OC_User::login($username, $password); //guess what this does OC_Installer::installShippedApps(); // create empty file in data dir, so we can later find // out that this is indeed an ownCloud data directory file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT . '/data') . '/.ocdata', ''); // Update htaccess files for apache hosts if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { self::updateHtaccess(); self::protectDataDirectory(); } //and we are done OC_Config::setValue('installed', true); } return $error; }
/** * @inheritdoc */ public function verifyPath($path, $fileName) { if (isset($fileName[255])) { throw new FileNameTooLongException(); } // NOTE: $path will remain unverified for now if (\OC_Util::runningOnWindows()) { $this->verifyWindowsPath($fileName); } else { $this->verifyPosixPath($fileName); } }
public static function install($options) { $l = self::getTrans(); $error = array(); $dbtype = $options['dbtype']; if (empty($options['adminlogin'])) { $error[] = $l->t('Set an admin username.'); } if (empty($options['adminpass'])) { $error[] = $l->t('Set an admin password.'); } if (empty($options['directory'])) { $options['directory'] = OC::$SERVERROOT . "/data"; } if (!isset(self::$dbSetupClasses[$dbtype])) { $dbtype = 'sqlite'; } $class = self::$dbSetupClasses[$dbtype]; $dbSetup = new $class(self::getTrans(), 'db_structure.xml'); $error = array_merge($error, $dbSetup->validate($options)); if (count($error) != 0) { return $error; } //no errors, good $username = htmlspecialchars_decode($options['adminlogin']); $password = htmlspecialchars_decode($options['adminpass']); $datadir = htmlspecialchars_decode($options['directory']); if (isset($options['trusted_domains']) && is_array($options['trusted_domains'])) { $trustedDomains = $options['trusted_domains']; } else { $trustedDomains = array(OC_Request::serverHost()); } if (OC_Util::runningOnWindows()) { $datadir = rtrim(realpath($datadir), '\\'); } //use sqlite3 when available, otherise sqlite2 will be used. if ($dbtype == 'sqlite' and class_exists('SQLite3')) { $dbtype = 'sqlite3'; } //generate a random salt that is used to salt the local user passwords $salt = OC_Util::generateRandomBytes(30); OC_Config::setValue('passwordsalt', $salt); //write the config file OC_Config::setValue('trusted_domains', $trustedDomains); OC_Config::setValue('datadirectory', $datadir); OC_Config::setValue('dbtype', $dbtype); OC_Config::setValue('version', implode('.', OC_Util::getVersion())); try { $dbSetup->initialize($options); $dbSetup->setupDatabase($username); } catch (DatabaseSetupException $e) { $error[] = array('error' => $e->getMessage(), 'hint' => $e->getHint()); return $error; } catch (Exception $e) { $error[] = array('error' => 'Error while trying to create admin user: '******'hint' => ''); return $error; } //create the user and group try { OC_User::createUser($username, $password); } catch (Exception $exception) { $error[] = $exception->getMessage(); } if (count($error) == 0) { OC_Appconfig::setValue('core', 'installedat', microtime(true)); OC_Appconfig::setValue('core', 'lastupdatedat', microtime(true)); OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php'); OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php'); OC_Group::createGroup('admin'); OC_Group::addToGroup($username, 'admin'); OC_User::login($username, $password); //guess what this does OC_Installer::installShippedApps(); // create empty file in data dir, so we can later find // out that this is indeed an ownCloud data directory file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT . '/data') . '/.ocdata', ''); //create htaccess files for apache hosts if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { self::createHtaccess(); } //and we are done OC_Config::setValue('installed', true); } return $error; }
function testStreamSetBlocking() { $filename = '/tmp-' . $this->getUniqueID(); $view = new \OC\Files\View('/' . $this->userId . '/files'); // Save short data as encrypted file using stream wrapper $cryptedFile = $view->file_put_contents($filename, $this->dataShort); // Test that data was successfully written $this->assertTrue(is_int($cryptedFile)); $handle = $view->fopen($filename, 'r'); if (\OC_Util::runningOnWindows()) { fclose($handle); $view->unlink($filename); $this->markTestSkipped('[Windows] stream_set_blocking() does not work as expected on Windows.'); } // set stream options $this->assertTrue(stream_set_blocking($handle, 1)); fclose($handle); // tear down $view->unlink($filename); }
/** * Try to find a program * Note: currently windows is not supported * * @param string $program * @return null|string */ public static function findBinaryPath($program) { $memcache = \OC::$server->getMemCacheFactory()->create('findBinaryPath'); if ($memcache->hasKey($program)) { return $memcache->get($program); } $result = null; if (!\OC_Util::runningOnWindows() && self::is_function_enabled('exec')) { $exeSniffer = new ExecutableFinder(); // Returns null if nothing is found $result = $exeSniffer->find($program); if (empty($result)) { $paths = getenv('PATH'); if (empty($paths)) { $paths = '/usr/local/bin /usr/bin /opt/bin /bin'; } else { $paths = str_replace(':', ' ', getenv('PATH')); } $command = 'find ' . $paths . ' -name ' . escapeshellarg($program) . ' 2> /dev/null'; exec($command, $output, $returnCode); if (count($output) > 0) { $result = escapeshellcmd($output[0]); } } } $memcache->set($program, $result, 3600); return $result; }
/** * @param $options * @return array */ public function install($options) { $l = $this->l10n; $error = array(); $dbType = $options['dbtype']; if (empty($options['adminlogin'])) { $error[] = $l->t('Set an admin username.'); } if (empty($options['adminpass'])) { $error[] = $l->t('Set an admin password.'); } if (empty($options['directory'])) { $options['directory'] = \OC::$SERVERROOT . "/data"; } if (!isset(self::$dbSetupClasses[$dbType])) { $dbType = 'sqlite'; } $username = htmlspecialchars_decode($options['adminlogin']); $password = htmlspecialchars_decode($options['adminpass']); $dataDir = htmlspecialchars_decode($options['directory']); $class = self::$dbSetupClasses[$dbType]; /** @var \OC\Setup\AbstractDatabase $dbSetup */ $dbSetup = new $class($l, 'db_structure.xml', $this->config, $this->logger, $this->random); $error = array_merge($error, $dbSetup->validate($options)); // validate the data directory if (!is_dir($dataDir) and !mkdir($dataDir) or !is_writable($dataDir)) { $error[] = $l->t("Can't create or write into the data directory %s", array($dataDir)); } if (count($error) != 0) { return $error; } $request = \OC::$server->getRequest(); //no errors, good if (isset($options['trusted_domains']) && is_array($options['trusted_domains'])) { $trustedDomains = $options['trusted_domains']; } else { $trustedDomains = [$request->getInsecureServerHost()]; } if (\OC_Util::runningOnWindows()) { $dataDir = rtrim(realpath($dataDir), '\\'); } //use sqlite3 when available, otherwise sqlite2 will be used. if ($dbType == 'sqlite' and class_exists('SQLite3')) { $dbType = 'sqlite3'; } //generate a random salt that is used to salt the local user passwords $salt = $this->random->generate(30); // generate a secret $secret = $this->random->generate(48); //write the config file $this->config->setSystemValues(['passwordsalt' => $salt, 'secret' => $secret, 'trusted_domains' => $trustedDomains, 'datadirectory' => $dataDir, 'overwrite.cli.url' => $request->getServerProtocol() . '://' . $request->getInsecureServerHost() . \OC::$WEBROOT, 'dbtype' => $dbType, 'version' => implode('.', \OCP\Util::getVersion())]); try { $dbSetup->initialize($options); $dbSetup->setupDatabase($username); } catch (\OC\DatabaseSetupException $e) { $error[] = array('error' => $e->getMessage(), 'hint' => $e->getHint()); return $error; } catch (Exception $e) { $error[] = array('error' => 'Error while trying to create admin user: '******'hint' => ''); return $error; } //create the user and group $user = null; try { $user = \OC::$server->getUserManager()->createUser($username, $password); if (!$user) { $error[] = "User <{$username}> could not be created."; } } catch (Exception $exception) { $error[] = $exception->getMessage(); } if (count($error) == 0) { $config = \OC::$server->getConfig(); $config->setAppValue('core', 'installedat', microtime(true)); $config->setAppValue('core', 'lastupdatedat', microtime(true)); $group = \OC::$server->getGroupManager()->createGroup('admin'); $group->addUser($user); \OC_User::login($username, $password); //guess what this does \OC_Installer::installShippedApps(); // create empty file in data dir, so we can later find // out that this is indeed an ownCloud data directory file_put_contents($config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); // Update .htaccess files Setup::updateHtaccess(); Setup::protectDataDirectory(); //try to write logtimezone if (date_default_timezone_get()) { $config->setSystemValue('logtimezone', date_default_timezone_get()); } //and we are done $config->setSystemValue('installed', true); } return $error; }
/** * Try to find a program * Note: currently windows is not supported * * @param string $program * @return null|string */ public static function findBinaryPath($program) { $memcache = \OC::$server->getMemCacheFactory()->create('findBinaryPath'); if ($memcache->hasKey($program)) { return $memcache->get($program); } $result = null; if (!\OC_Util::runningOnWindows() && self::is_function_enabled('exec')) { exec('command -v ' . escapeshellarg($program) . ' 2> /dev/null', $output, $returnCode); if ($returnCode === 0 && count($output) > 0) { $result = escapeshellcmd($output[0]); } } $memcache->set($program, $result, 3600); return $result; }
/** * @dataProvider normalizePathWindowsAbsolutePathData */ public function testNormalizePathWindowsAbsolutePath($expected, $path, $stripTrailingSlash = true) { if (!\OC_Util::runningOnWindows()) { $this->markTestSkipped('This test is Windows only'); } $this->assertEquals($expected, \OC\Files\Filesystem::normalizePath($path, $stripTrailingSlash, true)); }
public function testLogCantCreateFolder() { if (\OC_Util::runningOnWindows()) { $this->markTestSkipped('[Windows] chmod() does not work as intended on Windows.'); } $logger = $this->getMock('\\Test\\NullLogger'); $manager = $this->getManager($logger); chmod($this->baseDir, 0500); $logger->expects($this->once())->method('warning')->with($this->stringContains('Can not create a temporary folder in directory')); $this->assertFalse($manager->getTemporaryFolder()); }
/** * Check if the setlocal call does not work. This can happen if the right * local packages are not available on the server. * * @return bool */ public static function isSetLocaleWorking() { // setlocale test is pointless on Windows if (OC_Util::runningOnWindows()) { return true; } \Patchwork\Utf8\Bootup::initLocale(); if ('' === basename('§')) { return false; } return true; }
protected static function registerCoreProviders() { self::registerProvider('OC\\Preview\\TXT'); self::registerProvider('OC\\Preview\\MarkDown'); self::registerProvider('OC\\Preview\\Image'); self::registerProvider('OC\\Preview\\MP3'); // SVG, Office and Bitmap require imagick if (extension_loaded('imagick')) { $checkImagick = new \Imagick(); $imagickProviders = array('SVG' => 'OC\\Preview\\SVG', 'TIFF' => 'OC\\Preview\\TIFF', 'PDF' => 'OC\\Preview\\PDF', 'AI' => 'OC\\Preview\\Illustrator', 'PSD' => 'OC\\Preview\\Photoshop', 'EPS' => 'OC\\Preview\\Postscript'); foreach ($imagickProviders as $queryFormat => $provider) { if (count($checkImagick->queryFormats($queryFormat)) === 1) { self::registerProvider($provider); } } if (count($checkImagick->queryFormats('PDF')) === 1) { // Office previews are currently not supported on Windows if (!\OC_Util::runningOnWindows() && \OC_Helper::is_function_enabled('shell_exec')) { $officeFound = is_string(\OC::$server->getConfig()->getSystemValue('preview_libreoffice_path', null)); if (!$officeFound) { //let's see if there is libreoffice or openoffice on this machine $whichLibreOffice = shell_exec('command -v libreoffice'); $officeFound = !empty($whichLibreOffice); if (!$officeFound) { $whichOpenOffice = shell_exec('command -v openoffice'); $officeFound = !empty($whichOpenOffice); } } if ($officeFound) { self::registerProvider('OC\\Preview\\MSOfficeDoc'); self::registerProvider('OC\\Preview\\MSOffice2003'); self::registerProvider('OC\\Preview\\MSOffice2007'); self::registerProvider('OC\\Preview\\OpenDocument'); self::registerProvider('OC\\Preview\\StarOffice'); } } } } // Video requires avconv or ffmpeg and is therefor // currently not supported on Windows. if (!\OC_Util::runningOnWindows()) { $avconvBinary = \OC_Helper::findBinaryPath('avconv'); $ffmpegBinary = $avconvBinary ? null : \OC_Helper::findBinaryPath('ffmpeg'); if ($avconvBinary || $ffmpegBinary) { // FIXME // a bit hacky but didn't want to use subclasses \OC\Preview\Movie::$avconvBinary = $avconvBinary; \OC\Preview\Movie::$ffmpegBinary = $ffmpegBinary; self::registerProvider('OC\\Preview\\Movie'); } } }
* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License, version 3, * along with this program. If not, see <http://www.gnu.org/licenses/> * */ \OCP\JSON::checkAppEnabled('files_external_listing'); \OCP\JSON::checkLoggedIn(); \OCP\JSON::callCheck(); \OC_JSON::checkAdminUser(); $defaultDir = '/home'; if (\OC_Util::runningOnWindows()) { $defaultDir = 'C:\\'; } $localroot = OCP\Config::getAppValue('files_external_listing', 'starting_dir', $defaultDir); if (isset($_POST['path'])) { $path = realpath($_POST['path']); if (strpos($path, $localroot) === 0 or empty($_POST['path'])) { if (empty($_POST['path'])) { $path = $localroot; } if (!is_dir($path)) { //path is incorrect or is a file. Nothing to do, we work only with dirs OCP\JSON::error(array('data' => array('message' => 'Incorrect path: ' . $_POST['path']))); } elseif (isset($_POST['isnotempty']) && $_POST['isnotempty']) { //we only check if the dir has subdirs $dirs = glob($path . '/*', GLOB_ONLYDIR);
/** * Fix common problems with a file path * * @param string $path * @param bool $stripTrailingSlash * @param bool $isAbsolutePath * @return string */ public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false) { /** * FIXME: This is a workaround for existing classes and files which call * this function with another type than a valid string. This * conversion should get removed as soon as all existing * function calls have been fixed. */ $path = (string) $path; $cacheKey = json_encode([$path, $stripTrailingSlash, $isAbsolutePath]); if (isset(self::$normalizedPathCache[$cacheKey])) { return self::$normalizedPathCache[$cacheKey]; } if ($path == '') { return '/'; } //normalize unicode if possible $path = \OC_Util::normalizeUnicode($path); //no windows style slashes $path = str_replace('\\', '/', $path); // When normalizing an absolute path, we need to ensure that the drive-letter // is still at the beginning on windows $windows_drive_letter = ''; if ($isAbsolutePath && \OC_Util::runningOnWindows() && preg_match('#^([a-zA-Z])$#', $path[0]) && $path[1] == ':' && $path[2] == '/') { $windows_drive_letter = substr($path, 0, 2); $path = substr($path, 2); } //add leading slash if ($path[0] !== '/') { $path = '/' . $path; } // remove '/./' // ugly, but str_replace() can't replace them all in one go // as the replacement itself is part of the search string // which will only be found during the next iteration while (strpos($path, '/./') !== false) { $path = str_replace('/./', '/', $path); } // remove sequences of slashes $path = preg_replace('#/{2,}#', '/', $path); //remove trailing slash if ($stripTrailingSlash and strlen($path) > 1 and substr($path, -1, 1) === '/') { $path = substr($path, 0, -1); } // remove trailing '/.' if (substr($path, -2) == '/.') { $path = substr($path, 0, -2); } $normalizedPath = $windows_drive_letter . $path; self::$normalizedPathCache[$cacheKey] = $normalizedPath; return $normalizedPath; }
public function xtestLongPath() { $storage = new \OC\Files\Storage\Temporary(array()); \OC\Files\Filesystem::mount($storage, array(), '/'); $rootView = new \OC\Files\View(''); $longPath = ''; $ds = DIRECTORY_SEPARATOR; /* * 4096 is the maximum path length in file_cache.path in *nix * 1024 is the max path length in mac * 228 is the max path length in windows */ $folderName = 'abcdefghijklmnopqrstuvwxyz012345678901234567890123456789'; $tmpdirLength = strlen(\OC_Helper::tmpFolder()); if (\OC_Util::runningOnWindows()) { $this->markTestSkipped('[Windows] '); $depth = (260 - $tmpdirLength) / 57; } elseif (\OC_Util::runningOnMac()) { $depth = (1024 - $tmpdirLength) / 57; } else { $depth = (4000 - $tmpdirLength) / 57; } foreach (range(0, $depth - 1) as $i) { $longPath .= $ds . $folderName; $result = $rootView->mkdir($longPath); $this->assertTrue($result, "mkdir failed on {$i} - path length: " . strlen($longPath)); $result = $rootView->file_put_contents($longPath . "{$ds}test.txt", 'lorem'); $this->assertEquals(5, $result, "file_put_contents failed on {$i}"); $this->assertTrue($rootView->file_exists($longPath)); $this->assertTrue($rootView->file_exists($longPath . "{$ds}test.txt")); } $cache = $storage->getCache(); $scanner = $storage->getScanner(); $scanner->scan(''); $longPath = $folderName; foreach (range(0, $depth - 1) as $i) { $cachedFolder = $cache->get($longPath); $this->assertTrue(is_array($cachedFolder), "No cache entry for folder at {$i}"); $this->assertEquals($folderName, $cachedFolder['name'], "Wrong cache entry for folder at {$i}"); $cachedFile = $cache->get($longPath . '/test.txt'); $this->assertTrue(is_array($cachedFile), "No cache entry for file at {$i}"); $this->assertEquals('test.txt', $cachedFile['name'], "Wrong cache entry for file at {$i}"); $longPath .= $ds . $folderName; } }
/** * check dependencies */ public static function checkDependencies() { $l = new OC_L10N('files_external'); $txt = ''; if (!OC_Util::runningOnWindows()) { if (!OC_Mount_Config::checksmbclient()) { $txt .= $l->t('<b>Warning:</b> "smbclient" is not installed. Mounting of CIFS/SMB shares is not possible. Please ask your system administrator to install it.') . '<br />'; } } if (!OC_Mount_Config::checkphpftp()) { $txt .= $l->t('<b>Warning:</b> The FTP support in PHP is not enabled or installed. Mounting of FTP shares is not possible. Please ask your system administrator to install it.') . '<br />'; } if (!OC_Mount_Config::checkcurl()) { $txt .= $l->t('<b>Warning:</b> The Curl support in PHP is not enabled or installed. Mounting of ownCloud / WebDAV or GoogleDrive is not possible. Please ask your system administrator to install it.') . '<br />'; } return $txt; }