コード例 #1
0
ファイル: file.php プロジェクト: Combustible/core
 /**
  * create unique target
  * @param string $filePath
  * @param string $shareWith
  * @param string $exclude
  * @return string
  */
 public function generateTarget($filePath, $shareWith, $exclude = null)
 {
     $shareFolder = \OCA\Files_Sharing\Helper::getShareFolder();
     $target = \OC\Files\Filesystem::normalizePath($shareFolder . '/' . basename($filePath));
     // for group shares we return the target right away
     if ($shareWith === false) {
         return $target;
     }
     \OC\Files\Filesystem::initMountPoints($shareWith);
     $view = new \OC\Files\View('/' . $shareWith . '/files');
     if (!$view->is_dir($shareFolder)) {
         $dir = '';
         $subdirs = explode('/', $shareFolder);
         foreach ($subdirs as $subdir) {
             $dir = $dir . '/' . $subdir;
             if (!$view->is_dir($dir)) {
                 $view->mkdir($dir);
             }
         }
     }
     $excludeList = \OCP\Share::getItemsSharedWithUser('file', $shareWith, self::FORMAT_TARGET_NAMES);
     if (is_array($exclude)) {
         $excludeList = array_merge($excludeList, $exclude);
     }
     return \OCA\Files_Sharing\Helper::generateUniqueTarget($target, $excludeList, $view);
 }
コード例 #2
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     // reset backend
     \OC_User::clearBackends();
     \OC_User::useBackend('database');
     \OC_Hook::clear('OC_Filesystem');
     \OC_Hook::clear('OC_User');
     \OC_Hook::clear('OCP\\Share');
     // trashbin hooks
     \OCA\Files_Trashbin\Trashbin::registerHooks();
     // Filesystem related hooks
     \OCA\Encryption\Helper::registerFilesystemHooks();
     // register share hooks
     \OC::registerShareHooks();
     \OCA\Files_Sharing\Helper::registerHooks();
     // Sharing related hooks
     \OCA\Encryption\Helper::registerShareHooks();
     // Filesystem related hooks
     \OCA\Encryption\Helper::registerFilesystemHooks();
     // clear and register hooks
     \OC_FileProxy::clearProxies();
     \OC_FileProxy::register(new OCA\Files\Share\Proxy());
     \OC_FileProxy::register(new OCA\Encryption\Proxy());
     // create test user
     self::loginHelper(self::TEST_ENCRYPTION_TRASHBIN_USER2, true);
     self::loginHelper(self::TEST_ENCRYPTION_TRASHBIN_USER1, true);
 }
コード例 #3
0
ファイル: application.php プロジェクト: hyb148/core
 public function __construct(array $urlParams = array())
 {
     parent::__construct('files_sharing', $urlParams);
     $container = $this->getContainer();
     $server = $container->getServer();
     /**
      * Controllers
      */
     $container->registerService('ShareController', function (SimpleContainer $c) use($server) {
         return new ShareController($c->query('AppName'), $c->query('Request'), $c->query('UserSession'), $server->getAppConfig(), $server->getConfig(), $c->query('URLGenerator'), $c->query('UserManager'), $server->getLogger(), $server->getActivityManager());
     });
     $container->registerService('ExternalSharesController', function (SimpleContainer $c) {
         return new ExternalSharesController($c->query('AppName'), $c->query('Request'), $c->query('IsIncomingShareEnabled'), $c->query('ExternalManager'), $c->query('HttpClientService'));
     });
     /**
      * Core class wrappers
      */
     $container->registerService('UserSession', function (SimpleContainer $c) use($server) {
         return $server->getUserSession();
     });
     $container->registerService('URLGenerator', function (SimpleContainer $c) use($server) {
         return $server->getUrlGenerator();
     });
     $container->registerService('UserManager', function (SimpleContainer $c) use($server) {
         return $server->getUserManager();
     });
     $container->registerService('HttpClientService', function (SimpleContainer $c) use($server) {
         return $server->getHTTPClientService();
     });
     $container->registerService('IsIncomingShareEnabled', function (SimpleContainer $c) {
         return Helper::isIncomingServer2serverShareEnabled();
     });
     $container->registerService('ExternalManager', function (SimpleContainer $c) use($server) {
         $user = $server->getUserSession()->getUser();
         $uid = $user ? $user->getUID() : null;
         return new \OCA\Files_Sharing\External\Manager($server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), $server->getHTTPHelper(), $server->getNotificationManager(), $uid);
     });
     /**
      * Middleware
      */
     $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use($server) {
         return new SharingCheckMiddleware($c->query('AppName'), $server->getConfig(), $server->getAppManager());
     });
     // Execute middlewares
     $container->registerMiddleware('SharingCheckMiddleware');
     $container->registerService('MountProvider', function (IContainer $c) {
         /** @var \OCP\IServerContainer $server */
         $server = $c->query('ServerContainer');
         return new MountProvider($server->getConfig(), $c->query('PropagationManager'));
     });
     $container->registerService('PropagationManager', function (IContainer $c) {
         /** @var \OCP\IServerContainer $server */
         $server = $c->query('ServerContainer');
         return new PropagationManager($server->getUserSession(), $server->getConfig());
     });
     /*
      * Register capabilities
      */
     $container->registerCapability('OCA\\Files_Sharing\\Capabilities');
 }
コード例 #4
0
ファイル: share.php プロジェクト: Romua1d/core
 public static function setUpBeforeClass()
 {
     // reset backend
     \OC_User::clearBackends();
     \OC_User::useBackend('database');
     // enable resharing
     \OC::$server->getAppConfig()->setValue('core', 'shareapi_allow_resharing', 'yes');
     // clear share hooks
     \OC_Hook::clear('OCP\\Share');
     // register share hooks
     \OC::registerShareHooks();
     \OCA\Files_Sharing\Helper::registerHooks();
     // Sharing related hooks
     \OCA\Encryption\Helper::registerShareHooks();
     // Filesystem related hooks
     \OCA\Encryption\Helper::registerFilesystemHooks();
     // clear and register hooks
     \OC_FileProxy::clearProxies();
     \OC_FileProxy::register(new OCA\Files\Share\Proxy());
     \OC_FileProxy::register(new OCA\Encryption\Proxy());
     // create users
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1, true);
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, true);
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, true);
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, true);
     // create group and assign users
     \OC_Group::createGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
     \OC_Group::addToGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
     \OC_Group::addToGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
 }
コード例 #5
0
ファイル: helper.php プロジェクト: Romua1d/core
 /**
  * test set and get share folder
  */
 function testSetGetShareFolder()
 {
     $this->assertSame('/', \OCA\Files_Sharing\Helper::getShareFolder());
     \OCA\Files_Sharing\Helper::setShareFolder('/Shared');
     $this->assertSame('/Shared', \OCA\Files_Sharing\Helper::getShareFolder());
     // cleanup
     \OCP\Config::deleteSystemValue('share_folder');
 }
コード例 #6
0
ファイル: helper.php プロジェクト: droiter/openwrt-on-android
 /**
  * test set and get share folder
  */
 function testSetGetShareFolder()
 {
     $this->assertSame('/', \OCA\Files_Sharing\Helper::getShareFolder());
     \OCA\Files_Sharing\Helper::setShareFolder('/Shared/Folder');
     $sharedFolder = \OCA\Files_Sharing\Helper::getShareFolder();
     $this->assertSame('/Shared/Folder', \OCA\Files_Sharing\Helper::getShareFolder());
     $this->assertTrue(\OC\Files\Filesystem::is_dir($sharedFolder));
     // cleanup
     \OCP\Config::deleteSystemValue('share_folder');
 }
コード例 #7
0
 private function getCloudId()
 {
     $this->requireLogin();
     if (!method_exists($this->user, 'getCloudId')) {
         $uid = \OC::$server->getUserSession()->getUser()->getUID();
         $server = \OC::$server->getURLGenerator()->getAbsoluteURL('/');
         return $uid . '@' . rtrim(\OCA\Files_Sharing\Helper::removeProtocolFromUrl($server), '/');
     }
     // Nextcloud 9
     return $this->user->getCloudId();
 }
コード例 #8
0
ファイル: sharedmount.php プロジェクト: stweil/owncloud-core
 /**
  * check if the parent folder exists otherwise move the mount point up
  *
  * @param \OCP\Share\IShare $share
  * @param SharedMount[] $mountpoints
  * @return string
  */
 private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints)
 {
     $mountPoint = basename($share->getTarget());
     $parent = dirname($share->getTarget());
     if (!$this->recipientView->is_dir($parent)) {
         $parent = Helper::getShareFolder();
     }
     $newMountPoint = $this->generateUniqueTarget(\OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), $this->recipientView, $mountpoints);
     if ($newMountPoint !== $share->getTarget()) {
         $this->updateFileTarget($newMountPoint, $share);
     }
     return $newMountPoint;
 }
コード例 #9
0
ファイル: file.php プロジェクト: olucao/owncloud-core
 /**
  * create unique target
  * @param string $filePath
  * @param string $shareWith
  * @param string $exclude
  * @return string
  */
 public function generateTarget($filePath, $shareWith, $exclude = null)
 {
     $target = '/' . basename($filePath);
     // for group shares we return the target right away
     if ($shareWith === false) {
         return $target;
     }
     \OC\Files\Filesystem::initMountPoints($shareWith);
     $view = new \OC\Files\View('/' . $shareWith . '/files');
     $excludeList = \OCP\Share::getItemsSharedWithUser('file', $shareWith, self::FORMAT_TARGET_NAMES);
     if (is_array($exclude)) {
         $excludeList = array_merge($excludeList, $exclude);
     }
     return \OCA\Files_Sharing\Helper::generateUniqueTarget($target, $excludeList, $view);
 }
コード例 #10
0
 /**
  * check if the parent folder exists otherwise move the mount point up
  */
 private function verifyMountPoint(&$share, $user)
 {
     $mountPoint = basename($share['file_target']);
     $parent = dirname($share['file_target']);
     if (!\OC\Files\Filesystem::is_dir($parent)) {
         $parent = Helper::getShareFolder();
     }
     $newMountPoint = \OCA\Files_Sharing\Helper::generateUniqueTarget(\OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), array(), new \OC\Files\View('/' . $user . '/files'));
     if ($newMountPoint !== $share['file_target']) {
         self::updateFileTarget($newMountPoint, $share);
         $share['file_target'] = $newMountPoint;
         $share['unique_name'] = true;
     }
     return $newMountPoint;
 }
コード例 #11
0
 /**
  * check if the parent folder exists otherwise move the mount point up
  *
  * @param array $share
  * @return string
  */
 private function verifyMountPoint(&$share)
 {
     $mountPoint = basename($share['file_target']);
     $parent = dirname($share['file_target']);
     if (!$this->recipientView->is_dir($parent)) {
         $parent = Helper::getShareFolder();
     }
     $newMountPoint = \OCA\Files_Sharing\Helper::generateUniqueTarget(\OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), [], $this->recipientView);
     if ($newMountPoint !== $share['file_target']) {
         $this->updateFileTarget($newMountPoint, $share);
         $share['file_target'] = $newMountPoint;
         $share['unique_name'] = true;
     }
     return $newMountPoint;
 }
コード例 #12
0
ファイル: share.php プロジェクト: yheric455042/owncloud82
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     // enable resharing
     \OC::$server->getAppConfig()->setValue('core', 'shareapi_allow_resharing', 'yes');
     // register share hooks
     \OC::registerShareHooks();
     \OCA\Files_Sharing\Helper::registerHooks();
     // clear and register hooks
     \OC_FileProxy::register(new \OCA\Files\Share\Proxy());
     // create users
     self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1, true);
     self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2, true);
     self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER3, true);
     self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER4, true);
     // create group and assign users
     \OC_Group::createGroup(self::TEST_ENCRYPTION_SHARE_GROUP1);
     \OC_Group::addToGroup(self::TEST_ENCRYPTION_SHARE_USER3, self::TEST_ENCRYPTION_SHARE_GROUP1);
     \OC_Group::addToGroup(self::TEST_ENCRYPTION_SHARE_USER4, self::TEST_ENCRYPTION_SHARE_GROUP1);
 }
コード例 #13
0
    private function setupMounts()
    {
        // don't setup server-to-server shares if the admin disabled it
        if (\OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled() === false) {
            return false;
        }
        if ($this->uid) {
            $query = $this->connection->prepare('
				SELECT `remote`, `share_token`, `password`, `mountpoint`, `owner`
				FROM `*PREFIX*share_external`
				WHERE `user` = ?
			');
            $query->execute(array($this->uid));
            while ($row = $query->fetch()) {
                $row['manager'] = $this;
                $row['token'] = $row['share_token'];
                $this->mountShare($row);
            }
        }
    }
コード例 #14
0
 /**
  * Correct the parent folders' ETags for all users shared the file at $target
  *
  * @param string $target
  */
 public static function correctFolders($target)
 {
     // ignore part files
     if (pathinfo($target, PATHINFO_EXTENSION) === 'part') {
         return false;
     }
     // Correct Shared folders of other users shared with
     $shares = \OCA\Files_Sharing\Helper::getSharesFromItem($target);
     foreach ($shares as $share) {
         if ((int) $share['share_type'] === \OCP\Share::SHARE_TYPE_USER) {
             self::correctUsersFolder($share['share_with'], $share['file_target']);
         } elseif ((int) $share['share_type'] === \OCP\Share::SHARE_TYPE_GROUP) {
             $users = \OC_Group::usersInGroup($share['share_with']);
             foreach ($users as $user) {
                 self::correctUsersFolder($user, $share['file_target']);
             }
         } else {
             //unique name for group share
             self::correctUsersFolder($share['share_with'], $share['file_target']);
         }
     }
 }
コード例 #15
0
ファイル: application.php プロジェクト: riso/owncloud-core
 /**
  * @param array $urlParams
  */
 public function __construct(array $urlParams = array())
 {
     parent::__construct('files_sharing', $urlParams);
     $container = $this->getContainer();
     /**
      * Controllers
      */
     $container->registerService('ShareController', function (SimpleContainer $c) {
         return new ShareController($c->query('AppName'), $c->query('Request'), $c->query('UserSession'), $c->query('ServerContainer')->getAppConfig(), $c->query('ServerContainer')->getConfig(), $c->query('URLGenerator'), $c->query('ServerContainer')->getUserManager(), $c->query('ServerContainer')->getLogger(), $c->query('ServerContainer')->getActivityManager());
     });
     $container->registerService('ExternalSharesController', function (SimpleContainer $c) {
         return new ExternalSharesController($c->query('AppName'), $c->query('Request'), $c->query('IsIncomingShareEnabled'), $c->query('ExternalManager'));
     });
     /**
      * Core class wrappers
      */
     $container->registerService('UserSession', function (SimpleContainer $c) {
         return $c->query('ServerContainer')->getUserSession();
     });
     $container->registerService('URLGenerator', function (SimpleContainer $c) {
         return $c->query('ServerContainer')->getUrlGenerator();
     });
     $container->registerService('IsIncomingShareEnabled', function (SimpleContainer $c) {
         return Helper::isIncomingServer2serverShareEnabled();
     });
     $container->registerService('ExternalManager', function (SimpleContainer $c) {
         return new \OCA\Files_Sharing\External\Manager(\OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), \OC::$server->getUserSession(), \OC::$server->getHTTPHelper());
     });
     /**
      * Middleware
      */
     $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) {
         return new SharingCheckMiddleware($c->query('AppName'), $c->query('ServerContainer')->getAppConfig(), $c->getCoreApi());
     });
     // Execute middlewares
     $container->registerMiddleware('SharingCheckMiddleware');
 }
コード例 #16
0
ファイル: app.php プロジェクト: rchicoli/owncloud-core
 * 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/>
 *
 */
$l = \OC::$server->getL10N('files_sharing');
\OC::$CLASSPATH['OC_Share_Backend_File'] = 'files_sharing/lib/share/file.php';
\OC::$CLASSPATH['OC_Share_Backend_Folder'] = 'files_sharing/lib/share/folder.php';
\OC::$CLASSPATH['OC\\Files\\Storage\\Shared'] = 'files_sharing/lib/sharedstorage.php';
$application = new \OCA\Files_Sharing\AppInfo\Application();
$application->registerMountProviders();
\OCA\Files_Sharing\Helper::registerHooks();
\OCP\Share::registerBackend('file', 'OC_Share_Backend_File');
\OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file');
$eventDispatcher = \OC::$server->getEventDispatcher();
$eventDispatcher->addListener('OCA\\Files::loadAdditionalScripts', function () {
    \OCP\Util::addScript('files_sharing', 'share');
    \OCP\Util::addScript('files_sharing', 'sharetabview');
    if (\OC::$server->getConfig()->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes') {
        \OCP\Util::addScript('files_sharing', 'external');
    }
    \OCP\Util::addStyle('files_sharing', 'sharetabview');
});
// \OCP\Util::addStyle('files_sharing', 'sharetabview');
\OC::$server->getActivityManager()->registerExtension(function () {
    return new \OCA\Files_Sharing\Activity(\OC::$server->query('L10NFactory'), \OC::$server->getURLGenerator(), \OC::$server->getActivityManager());
});
コード例 #17
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     \OCA\Files_Sharing\Helper::registerHooks();
 }
コード例 #18
0
ファイル: file.php プロジェクト: Ebimedia/owncloud
 /**
  * check if server2server share is enabled
  *
  * @param int $shareType
  * @return boolean
  */
 public function isShareTypeAllowed($shareType)
 {
     if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
         return \OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled();
     }
     return true;
 }
コード例 #19
0
 public function rename($path1, $path2)
 {
     // we need the paths relative to data/user/files
     $relPath1 = $this->getMountPoint() . '/' . $path1;
     $relPath2 = $this->getMountPoint() . '/' . $path2;
     // check for update permissions on the share
     if ($this->isUpdatable('')) {
         $pathinfo = pathinfo($relPath1);
         // for part files we need to ask for the owner and path from the parent directory because
         // the file cache doesn't return any results for part files
         if ($pathinfo['extension'] === 'part') {
             list($user1, $path1) = \OCA\Files_Sharing\Helper::getUidAndFilename($pathinfo['dirname']);
             $path1 = $path1 . '/' . $pathinfo['basename'];
         } else {
             list($user1, $path1) = \OCA\Files_Sharing\Helper::getUidAndFilename($relPath1);
         }
         $targetFilename = basename($relPath2);
         list($user2, $path2) = \OCA\Files_Sharing\Helper::getUidAndFilename(dirname($relPath2));
         $rootView = new \OC\Files\View('');
         return $rootView->rename('/' . $user1 . '/files/' . $path1, '/' . $user2 . '/files/' . $path2 . '/' . $targetFilename);
     }
     return false;
 }
コード例 #20
0
ファイル: share.php プロジェクト: evanjt/core
 public function testShareWithDifferentShareFolder()
 {
     $fileinfo = $this->view->getFileInfo($this->filename);
     $folderinfo = $this->view->getFileInfo($this->folder);
     $fileShare = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $this->assertTrue($fileShare);
     \OCA\Files_Sharing\Helper::setShareFolder('/Shared/subfolder');
     $folderShare = \OCP\Share::shareItem('folder', $folderinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $this->assertTrue($folderShare);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertTrue(\OC\Files\Filesystem::file_exists('/Shared/subfolder/' . $this->folder));
     //cleanup
     \OC::$server->getConfig()->deleteSystemValue('share_folder');
 }
コード例 #21
0
ファイル: ShareTest.php プロジェクト: GitHubUser4234/core
 public function testShareWithDifferentShareFolder()
 {
     $fileinfo = $this->view->getFileInfo($this->filename);
     $folderinfo = $this->view->getFileInfo($this->folder);
     $share = $this->share(\OCP\Share::SHARE_TYPE_USER, $this->filename, self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
     \OCA\Files_Sharing\Helper::setShareFolder('/Shared/subfolder');
     $share = $this->share(\OCP\Share::SHARE_TYPE_USER, $this->folder, self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertTrue(\OC\Files\Filesystem::file_exists('/Shared/subfolder/' . $this->folder));
     //cleanup
     \OC::$server->getConfig()->deleteSystemValue('share_folder');
 }
コード例 #22
0
ファイル: server2server.php プロジェクト: nougad/core
 /**
  * check if server-to-server sharing is enabled
  *
  * @param bool $incoming
  * @return bool
  */
 private function isS2SEnabled($incoming = false)
 {
     $result = \OCP\App::isEnabled('files_sharing');
     if ($incoming) {
         $result = $result && \OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled();
     } else {
         $result = $result && \OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled();
     }
     return $result;
 }
コード例 #23
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @param string $token
  * @param string $files
  * @param string $path
  * @return void|RedirectResponse
  */
 public function downloadShare($token, $files = null, $path = '')
 {
     \OC_User::setIncognitoMode(true);
     $linkItem = OCP\Share::getShareByToken($token, false);
     // Share is password protected - check whether the user is permitted to access the share
     if (isset($linkItem['share_with'])) {
         if (!Helper::authenticate($linkItem)) {
             return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', array('token' => $token)));
         }
     }
     $files_list = null;
     if (!is_null($files)) {
         // download selected files
         $files_list = json_decode($files);
         // in case we get only a single file
         if ($files_list === null) {
             $files_list = array($files);
         }
     }
     $originalSharePath = self::getPath($token);
     // Create the activities
     if (isset($originalSharePath) && Filesystem::isReadable($originalSharePath . $path)) {
         $originalSharePath = Filesystem::normalizePath($originalSharePath . $path);
         $isDir = \OC\Files\Filesystem::is_dir($originalSharePath);
         $activities = [];
         if (!$isDir) {
             // Single file public share
             $activities[$originalSharePath] = Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED;
         } else {
             if (!empty($files_list)) {
                 // Only some files are downloaded
                 foreach ($files_list as $file) {
                     $filePath = Filesystem::normalizePath($originalSharePath . '/' . $file);
                     $isDir = \OC\Files\Filesystem::is_dir($filePath);
                     $activities[$filePath] = $isDir ? Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED : Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED;
                 }
             } else {
                 // The folder is downloaded
                 $activities[$originalSharePath] = Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED;
             }
         }
         foreach ($activities as $filePath => $subject) {
             $this->activityManager->publishActivity('files_sharing', $subject, array($filePath), '', array(), $filePath, '', $linkItem['uid_owner'], Activity::TYPE_PUBLIC_LINKS, Activity::PRIORITY_MEDIUM);
         }
     }
     // download selected files
     if (!is_null($files)) {
         // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
         // after dispatching the request which results in a "Cannot modify header information" notice.
         OC_Files::get($originalSharePath, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD');
         exit;
     } else {
         // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
         // after dispatching the request which results in a "Cannot modify header information" notice.
         OC_Files::get(dirname($originalSharePath), basename($originalSharePath), $_SERVER['REQUEST_METHOD'] == 'HEAD');
         exit;
     }
 }
コード例 #24
0
 public function rename($path1, $path2)
 {
     // we need the paths relative to data/user/files
     $relPath1 = $this->getMountPoint() . '/' . $path1;
     $relPath2 = $this->getMountPoint() . '/' . $path2;
     $pathinfo = pathinfo($relPath1);
     $isPartFile = isset($pathinfo['extension']) && $pathinfo['extension'] === 'part';
     $targetExists = $this->file_exists($path2);
     $sameFolder = dirname($relPath1) === dirname($relPath2);
     if ($targetExists || $sameFolder && !$isPartFile) {
         // note that renaming a share mount point is always allowed
         if (!$this->isUpdatable('')) {
             return false;
         }
     } else {
         if (!$this->isCreatable('')) {
             return false;
         }
     }
     // for part files we need to ask for the owner and path from the parent directory because
     // the file cache doesn't return any results for part files
     if ($isPartFile) {
         list($user1, $path1) = \OCA\Files_Sharing\Helper::getUidAndFilename($pathinfo['dirname']);
         $path1 = $path1 . '/' . $pathinfo['basename'];
     } else {
         list($user1, $path1) = \OCA\Files_Sharing\Helper::getUidAndFilename($relPath1);
     }
     $targetFilename = basename($relPath2);
     list($user2, $path2) = \OCA\Files_Sharing\Helper::getUidAndFilename(dirname($relPath2));
     $rootView = new \OC\Files\View('');
     return $rootView->rename('/' . $user1 . '/files/' . $path1, '/' . $user2 . '/files/' . $path2 . '/' . $targetFilename);
 }
コード例 #25
0
ファイル: public.php プロジェクト: Combustible/core
 OCP\Util::addScript('files', 'file-upload');
 OCP\Util::addStyle('files_sharing', 'public');
 OCP\Util::addStyle('files_sharing', 'mobile');
 OCP\Util::addScript('files_sharing', 'public');
 OCP\Util::addScript('files', 'fileactions');
 OCP\Util::addScript('files', 'jquery.iframe-transport');
 OCP\Util::addScript('files', 'jquery.fileupload');
 $maxUploadFilesize = OCP\Util::maxUploadFilesize($path);
 $tmpl = new OCP\Template('files_sharing', 'public', 'base');
 $tmpl->assign('displayName', \OCP\User::getDisplayName($shareOwner));
 $tmpl->assign('filename', $file);
 $tmpl->assign('directory_path', $linkItem['file_target']);
 $tmpl->assign('mimetype', \OC\Files\Filesystem::getMimeType($path));
 $tmpl->assign('dirToken', $linkItem['token']);
 $tmpl->assign('sharingToken', $token);
 $tmpl->assign('server2serversharing', Helper::isOutgoingServer2serverShareEnabled());
 $tmpl->assign('protected', isset($linkItem['share_with']) ? 'true' : 'false');
 $urlLinkIdentifiers = (isset($token) ? '&t=' . $token : '') . (isset($_GET['dir']) ? '&dir=' . $_GET['dir'] : '') . (isset($_GET['file']) ? '&file=' . $_GET['file'] : '');
 // Show file list
 if (\OC\Files\Filesystem::is_dir($path)) {
     $tmpl->assign('dir', $getPath);
     OCP\Util::addStyle('files', 'files');
     OCP\Util::addStyle('files', 'upload');
     OCP\Util::addScript('files', 'filesummary');
     OCP\Util::addScript('files', 'breadcrumb');
     OCP\Util::addScript('files', 'files');
     OCP\Util::addScript('files', 'filelist');
     OCP\Util::addscript('files', 'keyboardshortcuts');
     $files = array();
     $rootLength = strlen($basePath) + 1;
     $maxUploadFilesize = OCP\Util::maxUploadFilesize($path);
コード例 #26
0
ファイル: update.php プロジェクト: WYSAC/oregon-owncloud
/**
 * 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');
    }
}
コード例 #27
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @param string $token
  * @param string $files
  * @param string $path
  * @return void|RedirectResponse
  */
 public function downloadShare($token, $files = null, $path = '')
 {
     \OC_User::setIncognitoMode(true);
     $linkItem = OCP\Share::getShareByToken($token, false);
     // Share is password protected - check whether the user is permitted to access the share
     if (isset($linkItem['share_with'])) {
         if (!Helper::authenticate($linkItem)) {
             return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', array('token' => $token)));
         }
     }
     $originalSharePath = self::getPath($token);
     if (isset($originalSharePath) && Filesystem::isReadable($originalSharePath . $path)) {
         $originalSharePath = Filesystem::normalizePath($originalSharePath . $path);
         $type = \OC\Files\Filesystem::is_dir($originalSharePath) ? 'folder' : 'file';
         $args = $type === 'folder' ? array('dir' => $originalSharePath) : array('dir' => dirname($originalSharePath), 'scrollto' => basename($originalSharePath));
         $linkToFile = \OCP\Util::linkToAbsolute('files', 'index.php', $args);
         $subject = $type === 'folder' ? Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED : Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED;
         $this->activityManager->publishActivity('files_sharing', $subject, array($originalSharePath), '', array(), $originalSharePath, $linkToFile, $linkItem['uid_owner'], Activity::TYPE_PUBLIC_LINKS, Activity::PRIORITY_MEDIUM);
     }
     if (!is_null($files)) {
         // download selected files
         $files_list = json_decode($files);
         // in case we get only a single file
         if ($files_list === NULL) {
             $files_list = array($files);
         }
         // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
         // after dispatching the request which results in a "Cannot modify header information" notice.
         OC_Files::get($originalSharePath, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD');
         exit;
     } else {
         // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
         // after dispatching the request which results in a "Cannot modify header information" notice.
         OC_Files::get(dirname($originalSharePath), basename($originalSharePath), $_SERVER['REQUEST_METHOD'] == 'HEAD');
         exit;
     }
 }
コード例 #28
0
ファイル: sharecontroller.php プロジェクト: Pookay/core
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @param string $token
  * @param string $path
  * @return TemplateResponse|RedirectResponse
  * @throws NotFoundException
  */
 public function showShare($token, $path = '')
 {
     \OC_User::setIncognitoMode(true);
     // Check whether share exists
     try {
         $share = $this->shareManager->getShareByToken($token);
     } catch (\OC\Share20\Exception\ShareNotFound $e) {
         return new NotFoundResponse();
     }
     // Share is password protected - check whether the user is permitted to access the share
     if ($share->getPassword() !== null && !$this->linkShareAuth($share)) {
         return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', array('token' => $token)));
     }
     // We can't get the path of a file share
     if ($share->getNode() instanceof \OCP\Files\File && $path !== '') {
         throw new NotFoundException();
     }
     $rootFolder = null;
     if ($share->getNode() instanceof \OCP\Files\Folder) {
         /** @var \OCP\Files\Folder $rootFolder */
         $rootFolder = $share->getNode();
         try {
             $path = $rootFolder->get($path);
         } catch (\OCP\Files\NotFoundException $e) {
             throw new NotFoundException();
         }
     }
     $shareTmpl = [];
     $shareTmpl['displayName'] = $share->getShareOwner()->getDisplayName();
     $shareTmpl['owner'] = $share->getShareOwner()->getUID();
     $shareTmpl['filename'] = $share->getNode()->getName();
     $shareTmpl['directory_path'] = $share->getTarget();
     $shareTmpl['mimetype'] = $share->getNode()->getMimetype();
     $shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getNode()->getMimetype());
     $shareTmpl['dirToken'] = $token;
     $shareTmpl['sharingToken'] = $token;
     $shareTmpl['server2serversharing'] = Helper::isOutgoingServer2serverShareEnabled();
     $shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false';
     $shareTmpl['dir'] = '';
     $shareTmpl['nonHumanFileSize'] = $share->getNode()->getSize();
     $shareTmpl['fileSize'] = \OCP\Util::humanFileSize($share->getNode()->getSize());
     // Show file list
     if ($share->getNode() instanceof \OCP\Files\Folder) {
         $shareTmpl['dir'] = $rootFolder->getRelativePath($path->getPath());
         /*
          * The OC_Util methods require a view. This just uses the node API
          */
         $freeSpace = $share->getNode()->getStorage()->free_space($share->getNode()->getInternalPath());
         if ($freeSpace !== \OCP\Files\FileInfo::SPACE_UNKNOWN) {
             $freeSpace = max($freeSpace, 0);
         } else {
             $freeSpace = INF > 0 ? INF : PHP_INT_MAX;
             // work around https://bugs.php.net/bug.php?id=69188
         }
         $uploadLimit = Util::uploadLimit();
         $maxUploadFilesize = min($freeSpace, $uploadLimit);
         $folder = new Template('files', 'list', '');
         $folder->assign('dir', $rootFolder->getRelativePath($path->getPath()));
         $folder->assign('dirToken', $token);
         $folder->assign('permissions', \OCP\Constants::PERMISSION_READ);
         $folder->assign('isPublic', true);
         $folder->assign('publicUploadEnabled', 'no');
         $folder->assign('uploadMaxFilesize', $maxUploadFilesize);
         $folder->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
         $folder->assign('freeSpace', $freeSpace);
         $folder->assign('uploadLimit', $uploadLimit);
         // PHP upload limit
         $folder->assign('usedSpacePercent', 0);
         $folder->assign('trash', false);
         $shareTmpl['folder'] = $folder->fetchPage();
     }
     $shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', array('token' => $token));
     $shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
     $shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
     $csp = new OCP\AppFramework\Http\ContentSecurityPolicy();
     $csp->addAllowedFrameDomain('\'self\'');
     $response = new TemplateResponse($this->appName, 'public', $shareTmpl, 'base');
     $response->setContentSecurityPolicy($csp);
     return $response;
 }
コード例 #29
0
ファイル: list.php プロジェクト: olucao/owncloud-core
    \OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST);
    \OC_Log::write('core-preview', 'No token parameter was passed', \OC_Log::DEBUG);
    exit;
}
$token = $_GET['t'];
$password = null;
if (isset($_POST['password'])) {
    $password = $_POST['password'];
}
$relativePath = null;
if (isset($_GET['dir'])) {
    $relativePath = $_GET['dir'];
}
$sortAttribute = isset($_GET['sort']) ? $_GET['sort'] : 'name';
$sortDirection = isset($_GET['sortdirection']) ? $_GET['sortdirection'] === 'desc' : false;
$data = \OCA\Files_Sharing\Helper::setupFromToken($token, $relativePath, $password);
$linkItem = $data['linkItem'];
// Load the files
$dir = $data['realPath'];
$dir = \OC\Files\Filesystem::normalizePath($dir);
if (!\OC\Files\Filesystem::is_dir($dir . '/')) {
    \OC_Response::setStatus(\OC_Response::STATUS_NOT_FOUND);
    \OCP\JSON::error(array('success' => false));
    exit;
}
$data = array();
// make filelist
$files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection);
$formattedFiles = array();
foreach ($files as $file) {
    $entry = \OCA\Files\Helper::formatFileInfo($file);
コード例 #30
0
ファイル: settings-personal.php プロジェクト: alfrescoo/core
 * @copyright Copyright (c) 2015, ownCloud, Inc.
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * 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/>
 *
 */
\OC_Util::checkLoggedIn();
$l = \OC::$server->getL10N('files_sharing');
$uid = \OC::$server->getUserSession()->getUser()->getUID();
$server = \OC::$server->getURLGenerator()->getAbsoluteURL('/');
$cloudID = $uid . '@' . rtrim(\OCA\Files_Sharing\Helper::removeProtocolFromUrl($server), '/');
$url = 'https://owncloud.org/federation#' . $cloudID;
$ownCloudLogoPath = \OC::$server->getURLGenerator()->imagePath('core', 'logo-icon.svg');
$tmpl = new OCP\Template('files_sharing', 'settings-personal');
$tmpl->assign('outgoingServer2serverShareEnabled', \OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled());
$tmpl->assign('message_with_URL', $l->t('Share with me through my #ownCloud Federated Cloud ID, see %s', [$url]));
$tmpl->assign('message_without_URL', $l->t('Share with me through my #ownCloud Federated Cloud ID', [$cloudID]));
$tmpl->assign('owncloud_logo_path', $ownCloudLogoPath);
$tmpl->assign('reference', $url);
$tmpl->assign('cloudId', $cloudID);
return $tmpl->fetchPage();