Ejemplo n.º 1
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);
     $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;
 }
Ejemplo n.º 2
0
 /**
  * create a new share
  *
  * @param array $params
  * @return \OC_OCS_Result
  */
 public function createShare($params)
 {
     if (!$this->isS2SEnabled(true)) {
         return new \OC_OCS_Result(null, 503, 'Server does not support server-to-server sharing');
     }
     $remote = isset($_POST['remote']) ? $_POST['remote'] : null;
     $token = isset($_POST['token']) ? $_POST['token'] : null;
     $name = isset($_POST['name']) ? $_POST['name'] : null;
     $owner = isset($_POST['owner']) ? $_POST['owner'] : null;
     $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null;
     $remoteId = isset($_POST['remoteId']) ? (int) $_POST['remoteId'] : null;
     if ($remote && $token && $name && $owner && $remoteId && $shareWith) {
         if (!\OCP\Util::isValidFileName($name)) {
             return new \OC_OCS_Result(null, 400, 'The mountpoint name contains invalid characters.');
         }
         if (!\OCP\User::userExists($shareWith)) {
             return new \OC_OCS_Result(null, 400, 'User does not exists');
         }
         \OC_Util::setupFS($shareWith);
         $externalManager = new \OCA\Files_Sharing\External\Manager(\OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), \OC::$server->getUserSession(), \OC::$server->getHTTPHelper());
         $name = \OCP\Files::buildNotExistingFileName('/', $name);
         try {
             $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId);
             $user = $owner . '@' . $this->cleanupRemote($remote);
             \OC::$server->getActivityManager()->publishActivity('files_sharing', \OCA\Files_Sharing\Activity::SUBJECT_REMOTE_SHARE_RECEIVED, array($user), '', array(), '', '', $shareWith, \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::PRIORITY_LOW);
             return new \OC_OCS_Result();
         } catch (\Exception $e) {
             \OCP\Util::writeLog('files_sharing', 'server can not add remote share, ' . $e->getMessage(), \OCP\Util::ERROR);
             return new \OC_OCS_Result(null, 500, 'internal server error, was not able to add share from ' . $remote);
         }
     }
     return new \OC_OCS_Result(null, 400, 'server can not add remote share, missing parameter');
 }
Ejemplo n.º 3
0
 protected function tearDown()
 {
     if ($this->instance) {
         \OCP\Files::rmdirr($this->instance->constructUrl(''));
     }
     parent::tearDown();
 }
Ejemplo n.º 4
0
 /**
  * Get the template for a specific activity-event in the activities
  *
  * @param array $activity An array with all the activity data in it
  * @return string
  */
 public function show($activity)
 {
     $tmpl = new Template('activity', 'stream.item');
     $tmpl->assign('formattedDate', $this->dateTimeFormatter->formatDateTime($activity['timestamp']));
     $tmpl->assign('formattedTimestamp', Template::relative_modified_date($activity['timestamp']));
     if (strpos($activity['subjectformatted']['markup']['trimmed'], '<a ') !== false) {
         // We do not link the subject as we create links for the parameters instead
         $activity['link'] = '';
     }
     $tmpl->assign('event', $activity);
     if ($activity['file']) {
         $this->view->chroot('/' . $activity['affecteduser'] . '/files');
         $exist = $this->view->file_exists($activity['file']);
         $is_dir = $this->view->is_dir($activity['file']);
         $tmpl->assign('previewLink', $this->getPreviewLink($activity['file'], $is_dir));
         // show a preview image if the file still exists
         $mimeType = Files::getMimeType($activity['file']);
         if ($mimeType && !$is_dir && $this->preview->isMimeSupported($mimeType) && $exist) {
             $tmpl->assign('previewImageLink', $this->urlGenerator->linkToRoute('core_ajax_preview', array('file' => $activity['file'], 'x' => 150, 'y' => 150)));
         } else {
             $mimeTypeIcon = Template::mimetype_icon($is_dir ? 'dir' : $mimeType);
             $mimeTypeIcon = substr($mimeTypeIcon, -4) === '.png' ? substr($mimeTypeIcon, 0, -4) . '.svg' : $mimeTypeIcon;
             $tmpl->assign('previewImageLink', $mimeTypeIcon);
             $tmpl->assign('previewLinkIsDir', true);
         }
     }
     return $tmpl->fetchPage();
 }
Ejemplo n.º 5
0
 public function __construct($params)
 {
     $host = $params['host'];
     //remove leading http[s], will be generated in createBaseUri()
     if (substr($host, 0, 8) == "https://") {
         $host = substr($host, 8);
     } else {
         if (substr($host, 0, 7) == "http://") {
             $host = substr($host, 7);
         }
     }
     $this->host = $host;
     $this->user = $params['user'];
     $this->password = $params['password'];
     $this->secure = isset($params['secure']) && $params['secure'] == 'true' ? true : false;
     $this->root = isset($params['root']) ? $params['root'] : '/';
     if (!$this->root || $this->root[0] != '/') {
         $this->root = '/' . $this->root;
     }
     if (substr($this->root, -1, 1) != '/') {
         $this->root .= '/';
     }
     $settings = array('baseUri' => $this->createBaseUri(), 'userName' => $this->user, 'password' => $this->password);
     $this->client = new OC_Connector_Sabre_Client($settings);
     if ($caview = \OCP\Files::getStorage('files_external')) {
         $certPath = \OCP\Config::getSystemValue('datadirectory') . $caview->getAbsolutePath("") . 'rootcerts.crt';
         if (file_exists($certPath)) {
             $this->client->addTrustedCertificates($certPath);
         }
     }
     //create the root folder if necesary
     $this->mkdir('');
 }
Ejemplo n.º 6
0
 protected static function searchDocuments()
 {
     $documents = array();
     foreach (self::getSupportedMimetypes() as $mime) {
         $documents = array_merge($documents, \OCP\Files::searchByMime($mime));
     }
     return $documents;
 }
Ejemplo n.º 7
0
 private function hostKeysPath()
 {
     try {
         $storage_view = \OCP\Files::getStorage('files_external');
         if ($storage_view) {
             return \OCP\Config::getSystemValue('datadirectory') . $storage_view->getAbsolutePath('') . 'ssh_hostKeys';
         }
     } catch (\Exception $e) {
     }
     return false;
 }
Ejemplo n.º 8
0
 public function download($filename)
 {
     $file = basename($filename);
     $filename = $this->config->getBackupBase() . $file;
     // Prevent directory traversal
     if (strlen($file) < 3 || !@file_exists($filename)) {
         exit;
     }
     $mime = \OCP\Files::getMimeType($filename);
     return new DataDownloadResponse(file_get_contents($filename), $file, $mime);
 }
Ejemplo n.º 9
0
 public static function getDocuments()
 {
     $list = array_filter(\OCP\Files::searchByMime('application/vnd.oasis.opendocument.text'), function ($item) {
         //filter Deleted
         if (strpos($item['path'], '_trashbin') === 0) {
             return false;
         }
         return true;
     });
     return $list;
 }
Ejemplo n.º 10
0
 /**
  * convert via openOffice hosted on the same server
  * @param string $input
  * @param string $targetFilter
  * @param string $targetExtension
  * @return string
  */
 protected static function convertLocal($input, $targetFilter, $targetExtension)
 {
     $infile = \OCP\Files::tmpFile();
     $outdir = \OCP\Files::tmpFolder();
     $cmd = Helper::findOpenOffice();
     $params = ' --headless --convert-to ' . $targetFilter . ' --outdir ' . escapeshellarg($outdir) . ' --writer ' . escapeshellarg($infile) . ' -env:UserInstallation=file://' . escapeshellarg(get_temp_dir() . '/owncloud-' . \OC_Util::getInstanceId() . '/');
     file_put_contents($infile, $input);
     shell_exec($cmd . $params);
     $output = file_get_contents($outdir . '/' . basename($infile) . '.' . $targetExtension);
     return $output;
 }
Ejemplo n.º 11
0
 public static function getPresentations()
 {
     $presentations = array();
     $list = \OCP\Files::searchByMime('text/impress');
     foreach ($list as $l) {
         $size = \OC\Files\Filesystem::filesize($l["path"]);
         if ($size > 0) {
             $info = pathinfo($l["path"]);
             $mtime = \OC\Files\Filesystem::filemtime($l["path"]);
             $entry = array('url' => $l["path"], 'name' => $info['filename'], 'size' => $size, 'mtime' => $mtime);
             $presentations[] = $entry;
         }
     }
     return $presentations;
 }
Ejemplo n.º 12
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;
 }
Ejemplo n.º 13
0
 /**
  * @brief rename/move versions of renamed/moved files
  * @param array with oldpath and newpath
  *
  * This function is connected to the rename signal of OC_Filesystem and adjust the name and location
  * of the stored versions along the actual file
  */
 public static function rename_hook($params)
 {
     $versions_fileview = \OCP\Files::getStorage('files_versions');
     $rel_oldpath = $params['oldpath'];
     $abs_oldpath = \OCP\Config::getSystemValue('datadirectory') . $versions_fileview->getAbsolutePath('') . $rel_oldpath . '.v';
     $abs_newpath = \OCP\Config::getSystemValue('datadirectory') . $versions_fileview->getAbsolutePath('') . $params['newpath'] . '.v';
     if (Storage::isversioned($rel_oldpath)) {
         $info = pathinfo($abs_newpath);
         if (!file_exists($info['dirname'])) {
             mkdir($info['dirname'], 0750, true);
         }
         $versions = Storage::getVersions($rel_oldpath);
         foreach ($versions as $v) {
             rename($abs_oldpath . $v['version'], $abs_newpath . $v['version']);
         }
     }
 }
Ejemplo n.º 14
0
 public static function av_scan($path)
 {
     $path = $path[\OC\Files\Filesystem::signal_param_path];
     if ($path != '') {
         if (isset($_POST['dirToken'])) {
             //Public upload case
             $filesView = \OC\Files\Filesystem::getView();
         } else {
             $filesView = \OCP\Files::getStorage("files");
         }
         if (!is_object($filesView)) {
             \OCP\Util::writeLog('files_antivirus', 'Can\'t init filesystem view', \OCP\Util::WARN);
             return;
         }
         // check if path is a directory
         if ($filesView->is_dir($path)) {
             return;
         }
         // we should have a file to work with, and the file shouldn't
         // be empty
         $fileExists = $filesView->file_exists($path);
         if ($fileExists && $filesView->filesize($path) > 0) {
             $fileStatus = self::scanFile($filesView, $path);
             $result = $fileStatus->getNumericStatus();
             switch ($result) {
                 case Status::SCANRESULT_UNCHECKED:
                     //TODO: Show warning to the user: The file can not be checked
                     break;
                 case Status::SCANRESULT_INFECTED:
                     //remove file
                     $filesView->unlink($path);
                     Notification::sendMail($path);
                     $message = \OCP\Util::getL10N('files_antivirus')->t("Virus detected! Can't upload the file %s", array(basename($path)));
                     \OCP\JSON::error(array("data" => array("message" => $message)));
                     exit;
                     break;
                 case Status::SCANRESULT_CLEAN:
                     //do nothing
                     break;
             }
         }
     }
 }
Ejemplo n.º 15
0
 public static function getPackage($url, $version)
 {
     self::$package = \OCP\Files::tmpFile();
     if (!self::$package) {
         throw new \Exception('Unable to create a temporary file');
     }
     try {
         if (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]);
 }
Ejemplo n.º 16
0
 public static function testConversion()
 {
     $targetFilter = 'odt:writer8';
     $targetExtension = 'odt';
     $input = file_get_contents(dirname(__DIR__) . self::TEST_DOC_PATH);
     $infile = \OCP\Files::tmpFile();
     $outdir = \OCP\Files::tmpFolder();
     $outfile = $outdir . '/' . basename($infile) . '.' . $targetExtension;
     $cmd = Helper::findOpenOffice();
     $params = ' --headless --convert-to ' . escapeshellarg($targetFilter) . ' --outdir ' . escapeshellarg($outdir) . ' --writer ' . escapeshellarg($infile) . ' -env:UserInstallation=file://' . escapeshellarg(get_temp_dir() . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' 2>&1';
     file_put_contents($infile, $input);
     $result = shell_exec($cmd . $params);
     $exists = file_exists($outfile);
     if (!$exists) {
         Helper::warnLog('Conversion test failed. Raw output:' . $result);
         return false;
     } else {
         unlink($outfile);
     }
     return true;
 }
Ejemplo n.º 17
0
 public static function av_scan($path)
 {
     $path = $path[\OC\Files\Filesystem::signal_param_path];
     if ($path != '') {
         $files_view = \OCP\Files::getStorage("files");
         if ($files_view->file_exists($path)) {
             $root = OC_User::getHome(OC_User::getUser()) . '/files';
             $file = $root . $path;
             $result = self::clamav_scan($file);
             switch ($result) {
                 case CLAMAV_SCANRESULT_UNCHECKED:
                     //TODO: Show warning to the user: The file can not be checked
                     break;
                 case CLAMAV_SCANRESULT_INFECTED:
                     //remove file
                     $files_view->unlink($path);
                     OCP\JSON::error(array("data" => array("message" => "Virus detected! Can't upload the file.")));
                     $email = OC_Preferences::getValue(OC_User::getUser(), 'settings', 'email', '');
                     \OCP\Util::writeLog('files_antivirus', 'Email: ' . $email, \OCP\Util::DEBUG);
                     if (!empty($email)) {
                         $tmpl = new OC_Template('files_antivirus', 'notification');
                         $tmpl->assign('file', $path);
                         $tmpl->assign('host', OCP\Util::getServerHost());
                         $tmpl->assign('user', OC_User::getUser());
                         $msg = $tmpl->fetchPage();
                         $from = OCP\Util::getDefaultEmailAddress('security-noreply');
                         OCP\Util::sendMail($email, OC_User::getUser(), 'Malware detected', $msg, $from, 'ownCloud', 1);
                     }
                     exit;
                     break;
                 case CLAMAV_SCANRESULT_CLEAN:
                     //do nothing
                     break;
             }
         }
     }
 }
Ejemplo n.º 18
0
 public function fopen($path, $mode)
 {
     switch ($mode) {
         case 'r':
         case 'rb':
         case 'w':
         case 'wb':
         case 'a':
         case 'ab':
             //these are supported by the wrapper
             $context = stream_context_create(array('ftp' => array('overwrite' => true)));
             return fopen($this->constructUrl($path), $mode, false, $context);
         case 'r+':
         case 'w+':
         case 'wb+':
         case 'a+':
         case 'x':
         case 'x+':
         case 'c':
         case 'c+':
             //emulate these
             if (strrpos($path, '.') !== false) {
                 $ext = substr($path, strrpos($path, '.'));
             } else {
                 $ext = '';
             }
             $tmpFile = \OCP\Files::tmpFile($ext);
             \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
             if ($this->file_exists($path)) {
                 $this->getFile($path, $tmpFile);
             }
             self::$tempFiles[$tmpFile] = $path;
             return fopen('close://' . $tmpFile, $mode);
     }
     return false;
 }
Ejemplo n.º 19
0
Archivo: smb.php Proyecto: evanjt/core
 /**
  * @param string $path
  * @param string $mode
  * @return resource
  */
 public function fopen($path, $mode)
 {
     $fullPath = $this->buildPath($path);
     try {
         switch ($mode) {
             case 'r':
             case 'rb':
                 if (!$this->file_exists($path)) {
                     return false;
                 }
                 return $this->share->read($fullPath);
             case 'w':
             case 'wb':
                 return $this->share->write($fullPath);
             case 'a':
             case 'ab':
             case 'r+':
             case 'w+':
             case 'wb+':
             case 'a+':
             case 'x':
             case 'x+':
             case 'c':
             case 'c+':
                 //emulate these
                 if (strrpos($path, '.') !== false) {
                     $ext = substr($path, strrpos($path, '.'));
                 } else {
                     $ext = '';
                 }
                 if ($this->file_exists($path)) {
                     if (!$this->isUpdatable($path)) {
                         return false;
                     }
                     $tmpFile = $this->getCachedFile($path);
                 } else {
                     if (!$this->isCreatable(dirname($path))) {
                         return false;
                     }
                     $tmpFile = \OCP\Files::tmpFile($ext);
                 }
                 $source = fopen($tmpFile, $mode);
                 $share = $this->share;
                 return CallBackWrapper::wrap($source, null, null, function () use($tmpFile, $fullPath, $share) {
                     $share->put($tmpFile, $fullPath);
                     unlink($tmpFile);
                 });
         }
         return false;
     } catch (NotFoundException $e) {
         return false;
     }
 }
Ejemplo n.º 20
0
 private function toTmpFile($path)
 {
     $tmpFile = \OCP\Files::tmpFile();
     $this->archive->extractFile($path, $tmpFile);
     return $tmpFile;
 }
Ejemplo n.º 21
0
 protected function getNew()
 {
     return new ZIP(\OCP\Files::tmpFile('.zip'));
 }
Ejemplo n.º 22
0
 /**
  * get a file handler
  *
  * @param string $path
  * @param string $mode
  * @return resource
  */
 function getStream($path, $mode)
 {
     if (strrpos($path, '.') !== false) {
         $ext = substr($path, strrpos($path, '.'));
     } else {
         $ext = '';
     }
     $tmpFile = \OCP\Files::tmpFile($ext);
     if ($this->fileExists($path)) {
         $this->extractFile($path, $tmpFile);
     } elseif ($mode == 'r' or $mode == 'rb') {
         return false;
     }
     if ($mode == 'r' or $mode == 'rb') {
         return fopen($tmpFile, $mode);
     } else {
         \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
         self::$tempFiles[$tmpFile] = $path;
         return fopen('close://' . $tmpFile, $mode);
     }
 }
Ejemplo n.º 23
0
        // The token defines the target directory (security reasons)
        $path = \OC\Files\Filesystem::getPath($linkItem['file_source']);
        $view = new \OC\Files\View(\OC\Files\Filesystem::getView()->getAbsolutePath($path));
        $images = $view->searchByMime('image');
        $result = array();
        foreach ($images as $image) {
            $result[] = $token . $image['path'];
        }
        OCP\JSON::setContentTypeHeader();
        echo json_encode(array('images' => $result, 'users' => array(), 'displayNames' => array()));
        exit;
    }
}
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('gallery');
$images = \OCP\Files::searchByMime('image');
$user = \OCP\User::getUser();
$users = array();
$result = array();
foreach ($images as &$image) {
    // we show shared images another way
    if ($image->getStorage() instanceof \OC\Files\Storage\Shared) {
        $owner = $image['uid_owner'];
        $users[$owner] = $owner;
    } else {
        $owner = $user;
    }
    $path = $image['path'];
    if (strpos($path, DIRECTORY_SEPARATOR . ".")) {
        continue;
    }
Ejemplo n.º 24
0
 public function fopen($path, $mode)
 {
     $path = $this->normalizePath($path);
     switch ($mode) {
         case 'r':
         case 'rb':
             try {
                 $c = $this->getContainer();
                 $streamFactory = new \Guzzle\Stream\PhpStreamRequestFactory();
                 $streamInterface = $streamFactory->fromRequest($c->getClient()->get($c->getUrl($path)));
                 $streamInterface->rewind();
                 $stream = $streamInterface->getStream();
                 stream_context_set_option($stream, 'swift', 'content', $streamInterface);
                 if (!strrpos($streamInterface->getMetaData('wrapper_data')[0], '404 Not Found')) {
                     return $stream;
                 }
                 return false;
             } catch (\Guzzle\Http\Exception\BadResponseException $e) {
                 \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
                 return false;
             }
         case 'w':
         case 'wb':
         case 'a':
         case 'ab':
         case 'r+':
         case 'w+':
         case 'wb+':
         case 'a+':
         case 'x':
         case 'x+':
         case 'c':
         case 'c+':
             if (strrpos($path, '.') !== false) {
                 $ext = substr($path, strrpos($path, '.'));
             } else {
                 $ext = '';
             }
             $tmpFile = \OCP\Files::tmpFile($ext);
             \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
             // Fetch existing file if required
             if ($mode[0] !== 'w' && $this->file_exists($path)) {
                 if ($mode[0] === 'x') {
                     // File cannot already exist
                     return false;
                 }
                 $source = $this->fopen($path, 'r');
                 file_put_contents($tmpFile, $source);
                 // Seek to end if required
                 if ($mode[0] === 'a') {
                     fseek($tmpFile, 0, SEEK_END);
                 }
             }
             self::$tmpFiles[$tmpFile] = $path;
             return fopen('close://' . $tmpFile, $mode);
     }
 }
Ejemplo n.º 25
0
    /**
     * accept server-to-server share
     *
     * @param int $id
     * @return bool True if the share could be accepted, false otherwise
     */
    public function acceptShare($id)
    {
        $share = $this->getShare($id);
        if ($share) {
            $mountPoint = Files::buildNotExistingFileName('/', $share['name']);
            $mountPoint = Filesystem::normalizePath('/' . $mountPoint);
            $hash = md5($mountPoint);
            $acceptShare = $this->connection->prepare('
				UPDATE `*PREFIX*share_external`
				SET `accepted` = ?,
					`mountpoint` = ?,
					`mountpoint_hash` = ?
				WHERE `id` = ? AND `user` = ?');
            $acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid));
            $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept');
            //FIXME $this->scrapNotification($share['remote_id']);
            return true;
        }
        return false;
    }
Ejemplo n.º 26
0
 public function fopen($path, $mode)
 {
     $path = $this->root . $path;
     switch ($mode) {
         case 'r':
         case 'rb':
             $tmpFile = \OCP\Files::tmpFile();
             try {
                 $data = $this->dropbox->getFile($path);
                 file_put_contents($tmpFile, $data);
                 return fopen($tmpFile, 'r');
             } catch (\Exception $exception) {
                 \OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
                 return false;
             }
         case 'w':
         case 'wb':
         case 'a':
         case 'ab':
         case 'r+':
         case 'w+':
         case 'wb+':
         case 'a+':
         case 'x':
         case 'x+':
         case 'c':
         case 'c+':
             if (strrpos($path, '.') !== false) {
                 $ext = substr($path, strrpos($path, '.'));
             } else {
                 $ext = '';
             }
             $tmpFile = \OCP\Files::tmpFile($ext);
             \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
             if ($this->file_exists($path)) {
                 $source = $this->fopen($path, 'r');
                 file_put_contents($tmpFile, $source);
             }
             self::$tempFiles[$tmpFile] = $path;
             return fopen('close://' . $tmpFile, $mode);
     }
     return false;
 }
Ejemplo n.º 27
0
 /** {@inheritdoc} */
 public function fopen($path, $mode)
 {
     $this->init();
     $path = $this->cleanPath($path);
     switch ($mode) {
         case 'r':
         case 'rb':
             if (!$this->file_exists($path)) {
                 return false;
             }
             //straight up curl instead of sabredav here, sabredav put's the entire get result in memory
             $curl = curl_init();
             $fp = fopen('php://temp', 'r+');
             curl_setopt($curl, CURLOPT_USERPWD, $this->user . ':' . $this->password);
             curl_setopt($curl, CURLOPT_URL, $this->createBaseUri() . $this->encodePath($path));
             curl_setopt($curl, CURLOPT_FILE, $fp);
             curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
             if (defined('CURLOPT_PROTOCOLS')) {
                 curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
             }
             if (defined('CURLOPT_REDIR_PROTOCOLS')) {
                 curl_setopt($curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
             }
             if ($this->secure === true) {
                 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
                 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
                 if ($this->certPath) {
                     curl_setopt($curl, CURLOPT_CAINFO, $this->certPath);
                 }
             }
             curl_exec($curl);
             $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
             if ($statusCode !== 200) {
                 Util::writeLog("webdav client", 'curl GET ' . curl_getinfo($curl, CURLINFO_EFFECTIVE_URL) . ' returned status code ' . $statusCode, Util::ERROR);
             }
             curl_close($curl);
             rewind($fp);
             return $fp;
         case 'w':
         case 'wb':
         case 'a':
         case 'ab':
         case 'r+':
         case 'w+':
         case 'wb+':
         case 'a+':
         case 'x':
         case 'x+':
         case 'c':
         case 'c+':
             //emulate these
             if (strrpos($path, '.') !== false) {
                 $ext = substr($path, strrpos($path, '.'));
             } else {
                 $ext = '';
             }
             if ($this->file_exists($path)) {
                 if (!$this->isUpdatable($path)) {
                     return false;
                 }
                 $tmpFile = $this->getCachedFile($path);
             } else {
                 if (!$this->isCreatable(dirname($path))) {
                     return false;
                 }
                 $tmpFile = Files::tmpFile($ext);
             }
             Close::registerCallback($tmpFile, array($this, 'writeBack'));
             self::$tempFiles[$tmpFile] = $path;
             return fopen('close://' . $tmpFile, $mode);
     }
 }
Ejemplo n.º 28
0
<?php

OCP\JSON::checkAppEnabled('files_external');
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
$view = \OCP\Files::getStorage("files_external");
$file = 'uploads/' . ltrim($_POST['cert'], "/\\.");
if ($view->file_exists($file)) {
    $view->unlink($file);
    OC_Mount_Config::createCertificateBundle();
}
Ejemplo n.º 29
0
 private function getTmpFile($path)
 {
     $this->init();
     $obj = $this->getObject($path);
     if (!is_null($obj)) {
         $tmpFile = \OCP\Files::tmpFile();
         $obj->save_to_filename($tmpFile);
         return $tmpFile;
     } else {
         return \OCP\Files::tmpFile();
     }
 }
Ejemplo n.º 30
0
 public function tearDown()
 {
     if ($this->instance) {
         \OCP\Files::rmdirr($this->instance->constructUrl(''));
     }
 }