コード例 #1
0
ファイル: updater.php プロジェクト: farukuzun/core-1
 /**
  * Fix for https://github.com/owncloud/core/issues/20769
  *
  * The owner is allowed to move their files (if they are shared) into a receiving folder
  * In this case we need to update the parent of the moved share. Since they are
  * effectively handing over ownership of the file the rest of the code needs to know
  * they need to build up the reshare tree.
  *
  * @param string $path
  */
 private static function moveShareToShare($path)
 {
     $userFolder = \OC::$server->getUserFolder();
     // If the user folder can't be constructed (e.g. link share) just return.
     if ($userFolder === null) {
         return;
     }
     $src = $userFolder->get($path);
     $type = $src instanceof \OCP\Files\File ? 'file' : 'folder';
     $shares = \OCP\Share::getItemShared($type, $src->getId());
     // If the path we move is not a share we don't care
     if (empty($shares)) {
         return;
     }
     // Check if the destination is inside a share
     $mountManager = \OC::$server->getMountManager();
     $dstMount = $mountManager->find($src->getPath());
     if (!$dstMount instanceof \OCA\Files_Sharing\SharedMount) {
         return;
     }
     $parenShare = $dstMount->getShare();
     foreach ($shares as $share) {
         $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
         $qb->update('share')->set('parent', $qb->createNamedParameter($parenShare['id']))->where($qb->expr()->eq('id', $qb->createNamedParameter($share['id'])))->execute();
     }
 }
コード例 #2
0
	/**
	 * @NoAdminRequired
	 */
	public function getGroups() {
		$tags = $this->tags->getTags();

		foreach ($tags as &$tag) {
			try {
				$ids = $this->tags->getIdsForTag($tag['id']);
				$tag['contacts'] = $ids;
				$tag['displayname'] = $this->displayName($tag);
			} catch(\Exception $e) {
				\OCP\Util::writeLog('contacts', __METHOD__ . ', ' . $e->getMessage(), \OCP\Util::ERROR);
			}
		}

		$favorites = $this->tags->getFavorites();

		$shares = \OCP\Share::getItemsSharedWith('addressbook', \OCA\Contacts\Share\Addressbook::FORMAT_ADDRESSBOOKS);
		$addressbookShare = new \OCA\Contacts\Share\Addressbook();
		foreach ($shares as $key => $share) {
			$children = $addressbookShare->getChildren($share['id']); // FIXME: This should be cheaper!
			$shares[$key]['length'] = count($children);
		}

		$groups = array(
			'categories' => $tags,
			'favorites' => $favorites,
			'shared' => $shares,
			'lastgroup' => \OCP\Config::getUserValue(\OCP\User::getUser(), 'contacts', 'lastgroup', 'all'),
			'sortorder' => \OCP\Config::getUserValue(\OCP\User::getUser(), 'contacts', 'groupsort', ''),
			);

		return new JSONResponse($groups);
	}
コード例 #3
0
ファイル: addressbook.php プロジェクト: sahne123/contactsplus
 /**
  * Returns a list of ACE's for this node.
  *
  * Each ACE has the following properties:
  *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
  *     currently the only supported privileges
  *   * 'principal', a url to the principal who owns the node
  *   * 'protected' (optional), indicating that this ACE is not allowed to
  *      be updated.
  *
  * @return array
  */
 public function getACL()
 {
     $readprincipal = $this->getOwner();
     $writeprincipal = $this->getOwner();
     $createprincipal = $this->getOwner();
     $deleteprincipal = $this->getOwner();
     $uid = AddrBook::extractUserID($this->getOwner());
     //\OCP\Config::setUserValue($uid, 'contactsplus', 'syncaddrbook', $this->addressBookInfo['uri']);
     $readWriteACL = array(array('privilege' => '{DAV:}read', 'principal' => 'principals/' . \OCP\User::getUser(), 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => 'principals/' . \OCP\User::getUser(), 'protected' => true));
     if ($uid !== \OCP\USER::getUser()) {
         $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(ContactsApp::SHAREADDRESSBOOK, ContactsApp::SHAREADDRESSBOOKPREFIX . $this->addressBookInfo['id']);
         if ($sharedAddressbook) {
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE && $sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE && $sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) {
                 return $readWriteACL;
             }
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE) {
                 $createprincipal = 'principals/' . \OCP\USER::getUser();
             }
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ) {
                 $readprincipal = 'principals/' . \OCP\USER::getUser();
             }
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE) {
                 $writeprincipal = 'principals/' . \OCP\USER::getUser();
             }
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) {
                 $deleteprincipal = 'principals/' . \OCP\USER::getUser();
             }
         }
     } else {
         return parent::getACL();
     }
     return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write-content', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}bind', 'principal' => $createprincipal, 'protected' => true), array('privilege' => '{DAV:}unbind', 'principal' => $deleteprincipal, 'protected' => true));
 }
コード例 #4
0
ファイル: backend.php プロジェクト: BacLuc/newGryfiPage
 /**
  * Returns a list of calendars for a principal.
  *
  * Every project is an array with the following keys:
  *  * id, a unique id that will be used by other functions to modify the
  *	calendar. This can be the same as the uri or a database key.
  *  * uri, which the basename of the uri with which the calendar is
  *	accessed.
  *  * principalUri. The owner of the calendar. Almost always the same as
  *	principalUri passed to this method.
  *
  * Furthermore it can contain webdav properties in clark notation. A very
  * common one is '{DAV:}displayname'.
  *
  * @param string $principalUri
  * @return array
  */
 public function getCalendarsForUser($principalUri)
 {
     $raw = \OC_Calendar_Calendar::allCalendarsWherePrincipalURIIs($principalUri);
     $calendars = array();
     foreach ($raw as $row) {
         $components = explode(',', $row['components']);
         $sharedCalendar = \OCP\Share::getItemSharedWithBySource('calendar', $row['id']);
         if ($row['userid'] !== User::getUser() && empty($sharedCalendar)) {
             continue;
         }
         if ($row['userid'] != User::getUser()) {
             $row['uri'] = $row['uri'] . '_shared_by_' . $row['userid'];
         }
         $calendar = array('id' => $row['id'], 'uri' => $row['uri'], 'principaluri' => 'principals/' . \OCP\User::getUser(), '{' . \Sabre\CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => $row['ctag'] ? $row['ctag'] : '0', '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => new \Sabre\CalDAV\Property\SupportedCalendarComponentSet($components));
         foreach ($this->propertyMap as $xmlName => $dbName) {
             $calendar[$xmlName] = isset($row[$dbName]) ? $row[$dbName] : '';
         }
         $calendars[] = $calendar;
     }
     if (\OCP\App::isEnabled('contacts')) {
         $ctag = 0;
         $app = new \OCA\Contacts\App();
         $addressBooks = $app->getAddressBooksForUser();
         foreach ($addressBooks as $addressBook) {
             $tmp = $addressBook->lastModified();
             if (!is_null($tmp)) {
                 $ctag = max($ctag, $tmp);
             }
         }
         $ctag++;
         $calendars[] = array('id' => 'contact_birthdays', 'uri' => 'contact_birthdays', '{DAV:}displayname' => (string) \OC_Calendar_App::$l10n->t('Contact birthdays'), 'principaluri' => 'principals/' . \OCP\User::getUser(), '{' . \Sabre\CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => $ctag, '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => new \Sabre\CalDAV\Property\SupportedCalendarComponentSet(array('VEVENT')), '{http://apple.com/ns/ical/}calendar-color' => '#CCCCCC');
     }
     return $calendars;
 }
コード例 #5
0
ファイル: removefile.php プロジェクト: arun-TK/chat
 /**
  * @param $fileId the fileId of the file
  * @param $shareWIth the ownCloud user to share the file with
  */
 private function unShare($fileId, $shareWIth)
 {
     try {
         \OCP\Share::unshare('file', $fileId, \OCP\Share::SHARE_TYPE_USER, $shareWIth);
     } catch (\Exception $e) {
     }
 }
コード例 #6
0
ファイル: file.php プロジェクト: adolfo2103/hcloudfilem
 /**
  * get list of users with access to the file
  *
  * @param string $path to the file
  * @return array
  */
 public function getAccessList($path)
 {
     // Make sure that a share key is generated for the owner too
     list($owner, $ownerPath) = $this->util->getUidAndFilename($path);
     // always add owner to the list of users with access to the file
     $userIds = array($owner);
     if (!$this->util->isFile($ownerPath)) {
         return array('users' => $userIds, 'public' => false);
     }
     $ownerPath = substr($ownerPath, strlen('/files'));
     $ownerPath = $this->util->stripPartialFileExtension($ownerPath);
     // Find out who, if anyone, is sharing the file
     $result = \OCP\Share::getUsersSharingFile($ownerPath, $owner);
     $userIds = \array_merge($userIds, $result['users']);
     $public = $result['public'] || $result['remote'];
     // check if it is a group mount
     if (\OCP\App::isEnabled("files_external")) {
         $mounts = \OC_Mount_Config::getSystemMountPoints();
         foreach ($mounts as $mount) {
             if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) {
                 $mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']);
                 $userIds = array_merge($userIds, $mountedFor);
             }
         }
     }
     // Remove duplicate UIDs
     $uniqueUserIds = array_unique($userIds);
     return array('users' => $uniqueUserIds, 'public' => $public);
 }
コード例 #7
0
ファイル: backend.php プロジェクト: Romua1d/core
 function testGetParents()
 {
     $fileinfo1 = $this->view->getFileInfo($this->folder);
     $fileinfo2 = $this->view->getFileInfo($this->folder . $this->subfolder . $this->subsubfolder);
     $fileinfo3 = $this->view->getFileInfo($this->folder . $this->subfolder . $this->subsubfolder . $this->filename);
     $this->assertTrue(\OCP\Share::shareItem('folder', $fileinfo1['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31));
     $this->assertTrue(\OCP\Share::shareItem('folder', $fileinfo2['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER3, 31));
     $backend = new \OC_Share_Backend_Folder();
     $result = $backend->getParents($fileinfo3['fileid']);
     $this->assertSame(2, count($result));
     $count1 = 0;
     $count2 = 0;
     foreach ($result as $r) {
         if ($r['path'] === 'files' . $this->folder) {
             $this->assertSame(ltrim($this->folder, '/'), $r['collection']['path']);
             $count1++;
         } elseif ($r['path'] === 'files' . $this->folder . $this->subfolder . $this->subsubfolder) {
             $this->assertSame(ltrim($this->subsubfolder, '/'), $r['collection']['path']);
             $count2++;
         } else {
             $this->assertTrue(false, 'unexpected result');
         }
     }
     $this->assertSame(1, $count1);
     $this->assertSame(1, $count2);
     $result1 = $backend->getParents($fileinfo3['fileid'], self::TEST_FILES_SHARING_API_USER3);
     $this->assertSame(1, count($result1));
     $elemet = reset($result1);
     $this->assertSame('files' . $this->folder . $this->subfolder . $this->subsubfolder, $elemet['path']);
     $this->assertSame(ltrim($this->subsubfolder, '/'), $elemet['collection']['path']);
 }
コード例 #8
0
ファイル: backend.php プロジェクト: Romua1d/core
 public function generateTarget($itemSource, $shareWith, $exclude = null)
 {
     // Always make target be test.txt to cause conflicts
     if (substr($itemSource, 0, strlen('test')) !== 'test') {
         $target = "test.txt";
     } else {
         $target = $itemSource;
     }
     $shares = \OCP\Share::getItemsSharedWithUser('test', $shareWith);
     $knownTargets = array();
     foreach ($shares as $share) {
         $knownTargets[] = $share['item_target'];
     }
     if (in_array($target, $knownTargets)) {
         $pos = strrpos($target, '.');
         $name = substr($target, 0, $pos);
         $ext = substr($target, $pos);
         $append = '';
         $i = 1;
         while (in_array($name . $append . $ext, $knownTargets)) {
             $append = $i;
             $i++;
         }
         $target = $name . $append . $ext;
     }
     return $target;
 }
コード例 #9
0
ファイル: alarm.php プロジェクト: Rotzbua/calendarplus
 public function __construct()
 {
     $timeNow = time();
     //test
     $checkOffset = new \DateTime(date('d.m.Y', $timeNow), new \DateTimeZone(self::$tz));
     $calcSumWin = $checkOffset->getOffset();
     $this->nowTime = strtotime(date('d.m.Y H:i', $timeNow)) + $calcSumWin;
     if (\OC::$server->getSession()->get('public_link_token')) {
         $linkItem = \OCP\Share::getShareByToken(\OC::$server->getSession()->get('public_link_token', false));
         if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
             if ($linkItem['item_type'] === App::SHARECALENDAR) {
                 $sPrefix = App::SHARECALENDARPREFIX;
             }
             if ($linkItem['item_type'] === App::SHAREEVENT) {
                 $sPrefix = App::SHAREEVENTPREFIX;
             }
             if ($linkItem['item_type'] === App::SHARETODO) {
                 $sPrefix = App::SHARETODOPREFIX;
             }
             $itemSource = App::validateItemSource($linkItem['item_source'], $sPrefix);
             $rootLinkItem = Calendar::find($itemSource);
             $this->aCalendars[] = $rootLinkItem;
         }
     } else {
         if (\OCP\User::isLoggedIn()) {
             $this->aCalendars = Calendar::allCalendars(\OCP\User::getUser());
             $this->checkAlarm();
         }
     }
 }
コード例 #10
0
 /**
  * Returns a list of ACE's for this node.
  *
  * Each ACE has the following properties:
  *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
  *     currently the only supported privileges
  *   * 'principal', a url to the principal who owns the node
  *   * 'protected' (optional), indicating that this ACE is not allowed to
  *      be updated.
  *
  * @return array
  */
 public function getACL()
 {
     $readprincipal = $this->getOwner();
     $writeprincipal = $this->getOwner();
     $createprincipal = $this->getOwner();
     $deleteprincipal = $this->getOwner();
     $uid = $this->carddavBackend->userIDByPrincipal($this->getOwner());
     $readWriteACL = array(array('privilege' => '{DAV:}read', 'principal' => 'principals/' . \OCP\User::getUser(), 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => 'principals/' . \OCP\User::getUser(), 'protected' => true));
     if ($uid !== \OCP\User::getUser()) {
         list($backendName, $id) = explode('::', $this->addressBookInfo['id']);
         $sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $id);
         if ($sharedAddressbook) {
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE && $sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE && $sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) {
                 return $readWriteACL;
             }
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE) {
                 $createprincipal = 'principals/' . \OCP\User::getUser();
             }
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ) {
                 $readprincipal = 'principals/' . \OCP\User::getUser();
             }
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE) {
                 $writeprincipal = 'principals/' . \OCP\User::getUser();
             }
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) {
                 $deleteprincipal = 'principals/' . \OCP\User::getUser();
             }
         }
     } else {
         return parent::getACL();
     }
     return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write-content', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}bind', 'principal' => $createprincipal, 'protected' => true), array('privilege' => '{DAV:}unbind', 'principal' => $deleteprincipal, 'protected' => true));
 }
コード例 #11
0
 /**
  *@PublicPage
  * @NoCSRFRequired
  * 
  */
 public function exportEvents()
 {
     $token = $this->params('t');
     $calid = null;
     $eventid = null;
     if (isset($token)) {
         $linkItem = \OCP\Share::getShareByToken($token, false);
         if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
             $rootLinkItem = \OCP\Share::resolveReShare($linkItem);
             if (isset($rootLinkItem['uid_owner'])) {
                 \OCP\JSON::checkUserExists($rootLinkItem['uid_owner']);
                 if ($linkItem['item_type'] === CalendarApp::SHARECALENDAR) {
                     $sPrefix = CalendarApp::SHARECALENDARPREFIX;
                 }
                 if ($linkItem['item_type'] === CalendarApp::SHAREEVENT) {
                     $sPrefix = CalendarApp::SHAREEVENTPREFIX;
                 }
                 if ($linkItem['item_type'] === CalendarApp::SHARETODO) {
                     $sPrefix = CalendarApp::SHARETODOPREFIX;
                 }
                 $itemSource = CalendarApp::validateItemSource($linkItem['item_source'], $sPrefix);
                 if ($linkItem['item_type'] === CalendarApp::SHARECALENDAR) {
                     $calid = $itemSource;
                 }
                 if ($linkItem['item_type'] === CalendarApp::SHAREEVENT || $linkItem['item_type'] === CalendarApp::SHARETODO) {
                     $eventid = $itemSource;
                 }
             }
         }
     } else {
         if (\OCP\User::isLoggedIn()) {
             $calid = $this->params('calid');
             $eventid = $this->params('eventid');
         }
     }
     if (!is_null($calid)) {
         $calendar = CalendarApp::getCalendar($calid, true);
         if (!$calendar) {
             $params = ['status' => 'error'];
             $response = new JSONResponse($params);
             return $response;
         }
         $name = str_replace(' ', '_', $calendar['displayname']) . '.ics';
         $calendarEvents = Export::export($calid, Export::CALENDAR);
         $response = new DataDownloadResponse($calendarEvents, $name, 'text/calendar');
         return $response;
     }
     if (!is_null($eventid)) {
         $data = CalendarApp::getEventObject($eventid, false);
         if (!$data) {
             $params = ['status' => 'error'];
             $response = new JSONResponse($params);
             return $response;
         }
         $name = str_replace(' ', '_', $data['summary']) . '.ics';
         $singleEvent = Export::export($eventid, Export::EVENT);
         $response = new DataDownloadResponse($singleEvent, $name, 'text/calendar');
         return $response;
     }
 }
コード例 #12
0
ファイル: publicauth.php プロジェクト: olucao/owncloud-core
 /**
  * Validates a username and password
  *
  * This method should return true or false depending on if login
  * succeeded.
  *
  * @param string $username
  * @param string $password
  *
  * @return bool
  */
 protected function validateUserPass($username, $password)
 {
     $linkItem = \OCP\Share::getShareByToken($username, false);
     \OC_User::setIncognitoMode(true);
     $this->share = $linkItem;
     if (!$linkItem) {
         return false;
     }
     // check if the share is password protected
     if (isset($linkItem['share_with'])) {
         if ($linkItem['share_type'] == \OCP\Share::SHARE_TYPE_LINK) {
             // Check Password
             $forcePortable = CRYPT_BLOWFISH != 1;
             $hasher = new \PasswordHash(8, $forcePortable);
             if (!$hasher->CheckPassword($password . $this->config->getSystemValue('passwordsalt', ''), $linkItem['share_with'])) {
                 return false;
             } else {
                 return true;
             }
         } else {
             return false;
         }
     } else {
         return true;
     }
 }
コード例 #13
0
ファイル: sizepropagation.php プロジェクト: evanjt/core
 public function testSizePropagationWhenRecipientChangesFile()
 {
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $recipientView = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $ownerView = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     $ownerView->mkdir('/sharedfolder/subfolder');
     $ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar');
     $sharedFolderInfo = $ownerView->getFileInfo('/sharedfolder', false);
     $this->assertInstanceOf('\\OC\\Files\\FileInfo', $sharedFolderInfo);
     \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER1, 31);
     $ownerRootInfo = $ownerView->getFileInfo('', false);
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $this->assertTrue($recipientView->file_exists('/sharedfolder/subfolder/foo.txt'));
     $recipientRootInfo = $recipientView->getFileInfo('', false);
     // when file changed as recipient
     $recipientView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'foobar');
     // size of recipient's root stays the same
     $newRecipientRootInfo = $recipientView->getFileInfo('', false);
     $this->assertEquals($recipientRootInfo->getSize(), $newRecipientRootInfo->getSize());
     // size of owner's root increases
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $newOwnerRootInfo = $ownerView->getFileInfo('', false);
     $this->assertEquals($ownerRootInfo->getSize() + 3, $newOwnerRootInfo->getSize());
 }
コード例 #14
0
ファイル: calendar.php プロジェクト: Bullnados/calendarplus
 /**
  * Returns a list of ACE's for this node.
  *
  * Each ACE has the following properties:
  *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
  *     currently the only supported privileges
  *   * 'principal', a url to the principal who owns the node
  *   * 'protected' (optional), indicating that this ACE is not allowed to
  *      be updated.
  *
  * @return array
  */
 public function getACL()
 {
     $readprincipal = $this->getOwner();
     $writeprincipal = $this->getOwner();
     $uid = CalendarCalendar::extractUserID($this->getOwner());
     $calendar = CalendarApp::getCalendar($this->calendarInfo['id'], false, false);
     if ($uid === \OCP\USER::getUser() && (bool) $calendar['issubscribe'] === true) {
         $readprincipal = 'principals/' . \OCP\USER::getUser();
         $writeprincipal = '';
     }
     if ($uid !== \OCP\USER::getUser()) {
         $sharedCalendar = \OCP\Share::getItemSharedWithBySource(CalendarApp::SHARECALENDAR, CalendarApp::SHARECALENDARPREFIX . $this->calendarInfo['id']);
         if ($sharedCalendar && $sharedCalendar['permissions'] & \OCP\PERMISSION_READ) {
             $readprincipal = 'principals/' . \OCP\USER::getUser();
             $writeprincipal = '';
         }
         if ($sharedCalendar && $sharedCalendar['permissions'] & \OCP\PERMISSION_UPDATE) {
             $readprincipal = 'principals/' . \OCP\USER::getUser();
             $writeprincipal = 'principals/' . \OCP\USER::getUser();
         }
     }
     $acl = array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-read', 'protected' => true), array('privilege' => '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}read-free-busy', 'principal' => '{DAV:}authenticated', 'protected' => true));
     if (empty($this->calendarInfo['{http://sabredav.org/ns}read-only'])) {
         $acl[] = ['privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true];
         $acl[] = ['privilege' => '{DAV:}write', 'principal' => $writeprincipal . '/calendar-proxy-write', 'protected' => true];
     }
     return $acl;
 }
コード例 #15
0
ファイル: shared.php プロジェクト: omusico/isle-web-framework
 /**
  * Returns a specific address book.
  *
  * @param string $addressbookid
  * @param mixed $id Contact ID
  * @return mixed
  */
 public function getAddressBook($addressbookid, array $options = array())
 {
     $addressBook = \OCP\Share::getItemSharedWithBySource('addressbook', $addressbookid, Contacts\Share\Addressbook::FORMAT_ADDRESSBOOKS);
     // Not sure if I'm doing it wrongly, or if its supposed to return
     // the info in an array?
     $addressBook = isset($addressBook['permissions']) ? $addressBook : $addressBook[0];
     $addressBook['backend'] = $this->name;
     return $addressBook;
 }
コード例 #16
0
ファイル: watcher.php プロジェクト: Romua1d/core
 function tearDown()
 {
     $this->sharedCache->clear();
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $fileinfo = $this->view->getFileInfo('container/shareddir');
     \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
     $this->view->deleteAll('container');
     $this->ownerCache->clear();
     parent::tearDown();
 }
コード例 #17
0
ファイル: mountprovider.php プロジェクト: evanjt/core
 /**
  * Get all mountpoints applicable for the user and check for shares where we need to update the etags
  *
  * @param \OCP\IUser $user
  * @param \OCP\Files\Storage\IStorageFactory $storageFactory
  * @return \OCP\Files\Mount\IMountPoint[]
  */
 public function getMountsForUser(IUser $user, IStorageFactory $storageFactory)
 {
     $shares = \OCP\Share::getItemsSharedWithUser('file', $user->getUID());
     $shares = array_filter($shares, function ($share) {
         return $share['permissions'] > 0;
     });
     $shares = array_map(function ($share) use($user, $storageFactory) {
         return new SharedMount('\\OC\\Files\\Storage\\Shared', '/' . $user->getUID() . '/' . $share['file_target'], array('share' => $share, 'user' => $user->getUID()), $storageFactory);
     }, $shares);
     // array_filter removes the null values from the array
     return array_filter($shares);
 }
コード例 #18
0
ファイル: hooks.php プロジェクト: untitaker/contacts
 /**
  * Delete any registred address books (Future)
  */
 public static function addressBookDeletion($parameters)
 {
     // Clean up sharing
     \OCP\Share::unshareAll('addressbook', $parameters['addressbookid']);
     if (count($parameters['contactids'])) {
         // Remove contacts from groups
         $tagMgr = \OC::$server->getTagManager()->load('contact');
         $tagMgr->purgeObjects($parameters['contactids']);
         // Purge property indexes
         Utils\Properties::purgeIndexes($parameters['contactids']);
     }
 }
コード例 #19
0
 /**
  * inform users if a file was shared with them
  *
  * @param array $recipientList list of recipients
  * @param string $itemSource shared item source
  * @param string $itemType shared item type
  * @return array list of user to whom the mail send operation failed
  */
 public function sendInternalShareMail($recipientList, $itemSource, $itemType)
 {
     $noMail = [];
     foreach ($recipientList as $recipient) {
         $recipientDisplayName = \OCP\User::getDisplayName($recipient);
         $to = $this->config->getUserValue($recipient, 'settings', 'email', '');
         if ($to === '') {
             $noMail[] = $recipientDisplayName;
             continue;
         }
         $items = \OCP\Share::getItemSharedWithUser($itemType, $itemSource, $recipient);
         $filename = trim($items[0]['file_target'], '/');
         $subject = (string) $this->l->t('%s shared »%s« with you', array($this->senderDisplayName, $filename));
         $expiration = null;
         if (isset($items[0]['expiration'])) {
             try {
                 $date = new DateTime($items[0]['expiration']);
                 $expiration = $date->getTimestamp();
             } catch (\Exception $e) {
                 $this->logger->error("Couldn't read date: " . $e->getMessage(), ['app' => 'sharing']);
             }
         }
         // Link to folder, or root folder if a file
         if ($itemType === 'folder') {
             $args = array('dir' => $filename);
         } else {
             if (strpos($filename, '/')) {
                 $args = array('dir' => '/' . dirname($filename), 'scrollto' => basename($filename));
             } else {
                 $args = array('dir' => '/', 'scrollto' => $filename);
             }
         }
         $link = \OCP\Util::linkToAbsolute('files', 'index.php', $args);
         list($htmlBody, $textBody) = $this->createMailBody($filename, $link, $expiration);
         // send it out now
         try {
             $message = $this->mailer->createMessage();
             $message->setSubject($subject);
             $message->setTo([$to => $recipientDisplayName]);
             $message->setHtmlBody($htmlBody);
             $message->setPlainBody($textBody);
             $message->setFrom([\OCP\Util::getDefaultEmailAddress('sharing-noreply') => (string) $this->l->t('%s via %s', [$this->senderDisplayName, $this->defaults->getName()])]);
             if (!is_null($this->replyTo)) {
                 $message->setReplyTo([$this->replyTo]);
             }
             $this->mailer->send($message);
         } catch (\Exception $e) {
             $this->logger->error("Can't send mail to inform the user about an internal share: " . $e->getMessage(), ['app' => 'sharing']);
             $noMail[] = $recipientDisplayName;
         }
     }
     return $noMail;
 }
コード例 #20
0
ファイル: server2server.php プロジェクト: riso/owncloud-core
 protected function setUp()
 {
     parent::setUp();
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     \OCP\Share::registerBackend('test', 'Test_Share_Backend');
     $config = $this->getMockBuilder('\\OCP\\IConfig')->disableOriginalConstructor()->getMock();
     $certificateManager = $this->getMock('\\OCP\\ICertificateManager');
     $httpHelperMock = $this->getMockBuilder('\\OC\\HTTPHelper')->setConstructorArgs(array($config, $certificateManager))->getMock();
     $httpHelperMock->expects($this->any())->method('post')->with($this->anything())->will($this->returnValue(true));
     $this->registerHttpHelper($httpHelperMock);
     $this->s2s = new \OCA\Files_Sharing\API\Server2Server();
 }
コード例 #21
0
ファイル: versions.php プロジェクト: ryanshoover/core
 private static function getUidAndFilename($filename)
 {
     if (\OCP\App::isEnabled('files_sharing') && substr($filename, 0, 7) == '/Shared' && ($source = \OCP\Share::getItemSharedWith('file', substr($filename, 7), \OC_Share_Backend_File::FORMAT_SHARED_STORAGE))) {
         $filename = $source['path'];
         $pos = strpos($filename, '/files', 1);
         $uid = substr($filename, 1, $pos - 1);
         $filename = substr($filename, $pos + 6);
     } else {
         $uid = \OCP\User::getUser();
     }
     return array($uid, $filename);
 }
コード例 #22
0
ファイル: server2server.php プロジェクト: hyb148/core
 protected function setUp()
 {
     parent::setUp();
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     \OCP\Share::registerBackend('test', 'Test_Share_Backend');
     $config = $this->getMockBuilder('\\OCP\\IConfig')->disableOriginalConstructor()->getMock();
     $clientService = $this->getMock('\\OCP\\Http\\Client\\IClientService');
     $httpHelperMock = $this->getMockBuilder('\\OC\\HTTPHelper')->setConstructorArgs([$config, $clientService])->getMock();
     $httpHelperMock->expects($this->any())->method('post')->with($this->anything())->will($this->returnValue(true));
     $this->registerHttpHelper($httpHelperMock);
     $this->s2s = new \OCA\Files_Sharing\API\Server2Server();
     $this->connection = \OC::$server->getDatabaseConnection();
 }
コード例 #23
0
ファイル: etagtest.php プロジェクト: adolfo2103/hcloudfilem
 protected function setUp()
 {
     parent::setUp();
     \OC_Hook::clear('OC_Filesystem', 'setup');
     \OCP\Util::connectHook('OC_Filesystem', 'setup', '\\OC\\Files\\Storage\\Shared', 'setup');
     \OCP\Share::registerBackend('file', 'OC_Share_Backend_File');
     \OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file');
     $this->datadir = \OC_Config::getValue('datadirectory');
     $this->tmpDir = \OC_Helper::tmpFolder();
     \OC_Config::setValue('datadirectory', $this->tmpDir);
     $this->userBackend = new \OC_User_Dummy();
     \OC_User::useBackend($this->userBackend);
 }
コード例 #24
0
ファイル: etagtest.php プロジェクト: DaubaKao/owncloud-core
 protected function setUp()
 {
     parent::setUp();
     \OC_Hook::clear('OC_Filesystem', 'setup');
     $application = new \OCA\Files_Sharing\AppInfo\Application();
     $application->registerMountProviders();
     \OCP\Share::registerBackend('file', 'OC_Share_Backend_File');
     \OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file');
     $this->datadir = \OC_Config::getValue('datadirectory');
     $this->tmpDir = \OC_Helper::tmpFolder();
     \OC_Config::setValue('datadirectory', $this->tmpDir);
     $this->userBackend = new \Test\Util\User\Dummy();
     \OC_User::useBackend($this->userBackend);
 }
コード例 #25
0
 /**
  * get the permissions for all files in a folder
  *
  * @param int $parentId
  * @param string $user
  * @return int[]
  */
 public function getDirectoryPermissions($parentId, $user)
 {
     // Root of the Shared folder
     if ($parentId === -1) {
         return \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_PERMISSIONS);
     }
     $permissions = $this->get($parentId, $user);
     $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `parent` = ?');
     $result = $query->execute(array($parentId));
     $filePermissions = array();
     while ($row = $result->fetchRow()) {
         $filePermissions[$row['fileid']] = $permissions;
     }
     return $filePermissions;
 }
コード例 #26
0
ファイル: etagtest.php プロジェクト: TechArea/core
 protected function setUp()
 {
     parent::setUp();
     \OC_Hook::clear('OC_Filesystem', 'setup');
     $application = new \OCA\Files_Sharing\AppInfo\Application();
     $application->registerMountProviders();
     \OCP\Share::registerBackend('file', 'OC_Share_Backend_File');
     \OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file');
     $config = \OC::$server->getConfig();
     $this->datadir = $config->getSystemValue('datadirectory');
     $this->tmpDir = \OC::$server->getTempManager()->getTemporaryFolder();
     $config->setSystemValue('datadirectory', $this->tmpDir);
     $this->userBackend = new \Test\Util\User\Dummy();
     \OC_User::useBackend($this->userBackend);
 }
コード例 #27
0
 /**
  * @NoAdminRequired
  */
 public function getGroups()
 {
     $tags = $this->tags->getTags();
     foreach ($tags as &$tag) {
         try {
             $ids = $this->tags->getIdsForTag($tag['name']);
             $tag['contacts'] = $ids;
         } catch (\Exception $e) {
             $this->api->log(__METHOD__ . ' ' . $e->getMessage());
         }
     }
     $favorites = $this->tags->getFavorites();
     $groups = array('categories' => $tags, 'favorites' => $favorites, 'shared' => \OCP\Share::getItemsSharedWith('addressbook', \OCA\Contacts\Share\Addressbook::FORMAT_ADDRESSBOOKS), 'lastgroup' => \OCP\Config::getUserValue(\OCP\User::getUser(), 'contacts', 'lastgroup', 'all'), 'sortorder' => \OCP\Config::getUserValue(\OCP\User::getUser(), 'contacts', 'groupsort', ''));
     return new JSONResponse($groups);
 }
コード例 #28
0
ファイル: file.php プロジェクト: owncloud/richdocuments
 public static function getByShareToken($token)
 {
     $linkItem = \OCP\Share::getShareByToken($token, false);
     if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
         // seems to be a valid share
         $rootLinkItem = \OCP\Share::resolveReShare($linkItem);
     } else {
         throw new \Exception('This file was probably unshared');
     }
     $file = new File($rootLinkItem['file_source'], $rootLinkItem, $token);
     if (isset($linkItem['share_with']) && !empty($linkItem['share_with'])) {
         $file->setPasswordProtected(true);
     }
     return $file;
 }
コード例 #29
0
ファイル: Helper.php プロジェクト: drognisep/Portfolio-Site
 /**
  * Sets up the filesystem and user for public sharing
  * @param string $token string share token
  * @param string $relativePath optional path relative to the share
  * @param string $password optional password
  * @return array
  */
 public static function setupFromToken($token, $relativePath = null, $password = null)
 {
     \OC_User::setIncognitoMode(true);
     $linkItem = \OCP\Share::getShareByToken($token, !$password);
     if ($linkItem === false || $linkItem['item_type'] !== 'file' && $linkItem['item_type'] !== 'folder') {
         \OC_Response::setStatus(404);
         \OCP\Util::writeLog('core-preview', 'Passed token parameter is not valid', \OCP\Util::DEBUG);
         exit;
     }
     if (!isset($linkItem['uid_owner']) || !isset($linkItem['file_source'])) {
         \OC_Response::setStatus(500);
         \OCP\Util::writeLog('core-preview', 'Passed token seems to be valid, but it does not contain all necessary information . ("' . $token . '")', \OCP\Util::WARN);
         exit;
     }
     $rootLinkItem = \OCP\Share::resolveReShare($linkItem);
     $path = null;
     if (isset($rootLinkItem['uid_owner'])) {
         \OCP\JSON::checkUserExists($rootLinkItem['uid_owner']);
         \OC_Util::tearDownFS();
         \OC_Util::setupFS($rootLinkItem['uid_owner']);
     }
     try {
         $path = Filesystem::getPath($linkItem['file_source']);
     } catch (NotFoundException $e) {
         \OCP\Util::writeLog('share', 'could not resolve linkItem', \OCP\Util::DEBUG);
         \OC_Response::setStatus(404);
         \OCP\JSON::error(array('success' => false));
         exit;
     }
     if (!isset($linkItem['item_type'])) {
         \OCP\Util::writeLog('share', 'No item type set for share id: ' . $linkItem['id'], \OCP\Util::ERROR);
         \OC_Response::setStatus(404);
         \OCP\JSON::error(array('success' => false));
         exit;
     }
     if (isset($linkItem['share_with']) && (int) $linkItem['share_type'] === \OCP\Share::SHARE_TYPE_LINK) {
         if (!self::authenticate($linkItem, $password)) {
             \OC_Response::setStatus(403);
             \OCP\JSON::error(array('success' => false));
             exit;
         }
     }
     $basePath = $path;
     if ($relativePath !== null && Filesystem::isReadable($basePath . $relativePath)) {
         $path .= Filesystem::normalizePath($relativePath);
     }
     return array('linkItem' => $linkItem, 'basePath' => $basePath, 'realPath' => $path);
 }
コード例 #30
0
ファイル: server2server.php プロジェクト: Kevin-ZK/vaneDisk
 /**
  * decline server-to-server share
  *
  * @param array $params
  * @return \OC_OCS_Result
  */
 public function declineShare($params)
 {
     if (!$this->isS2SEnabled()) {
         return new \OC_OCS_Result(null, 503, 'Server does not support federated cloud sharing');
     }
     $id = $params['id'];
     $token = isset($_POST['token']) ? $_POST['token'] : null;
     $share = $this->getShare($id, $token);
     if ($share) {
         // userId must be set to the user who unshares
         \OCP\Share::unshare($share['item_type'], $share['item_source'], $share['share_type'], null, $share['uid_owner']);
         list($file, $link) = $this->getFile($share['uid_owner'], $share['file_source']);
         \OC::$server->getActivityManager()->publishActivity('files_sharing', \OCA\Files_Sharing\Activity::SUBJECT_REMOTE_SHARE_DECLINED, array($share['share_with'], basename($file)), '', array(), $file, $link, $share['uid_owner'], \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::PRIORITY_LOW);
     }
     return new \OC_OCS_Result();
 }