/**
  *@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;
     }
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 /**
  * 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);
 }
Esempio n. 4
0
 /**
  * @param $token
  * @return null|string
  */
 private function getPath($token)
 {
     $linkItem = Share::getShareByToken($token, false);
     $path = null;
     if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
         // seems to be a valid share
         $rootLinkItem = Share::resolveReShare($linkItem);
         if (isset($rootLinkItem['uid_owner'])) {
             JSON::checkUserExists($rootLinkItem['uid_owner']);
             OC_Util::tearDownFS();
             OC_Util::setupFS($rootLinkItem['uid_owner']);
             $path = Filesystem::getPath($linkItem['file_source']);
         }
     }
     return $path;
 }
$server = new OC_Connector_Sabre_Server($objectTree);
$server->httpRequest = $requestBackend;
$server->setBaseUri($baseuri);
// Load plugins
$defaults = new OC_Defaults();
$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, $defaults->getName()));
$server->addPlugin(new \Sabre\DAV\Locks\Plugin($lockBackend));
$server->addPlugin(new \Sabre\DAV\Browser\Plugin(false));
// Show something in the Browser, but no upload
$server->addPlugin(new OC_Connector_Sabre_FilesPlugin());
$server->addPlugin(new OC_Connector_Sabre_MaintenancePlugin());
$server->addPlugin(new OC_Connector_Sabre_ExceptionLoggerPlugin('webdav'));
// wait with registering these until auth is handled and the filesystem is setup
$server->subscribeEvent('beforeMethod', function () use($server, $objectTree, $authBackend) {
    $share = $authBackend->getShare();
    $rootShare = \OCP\Share::resolveReShare($share);
    $owner = $rootShare['uid_owner'];
    $isWritable = $share['permissions'] & (\OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_CREATE);
    $fileId = $share['file_source'];
    if (!$isWritable) {
        \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, $storage) {
            return new \OCA\Files_Sharing\ReadOnlyWrapper(array('storage' => $storage));
        });
    }
    OC_Util::setupFS($owner);
    $ownerView = \OC\Files\Filesystem::getView();
    $path = $ownerView->getPath($fileId);
    $view = new \OC\Files\View($ownerView->getAbsolutePath($path));
    $rootInfo = $view->getFileInfo('');
    // Create ownCloud Dir
    if ($rootInfo->getType() === 'dir') {
Esempio n. 6
0
 * Copyright (c) 2012 Robin Appelman <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
OCP\JSON::checkAppEnabled('gallery');
if (isset($_GET['token'])) {
    $token = $_GET['token'];
    $linkItem = \OCP\Share::getShareByToken($token);
    if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
        // seems to be a valid share
        $type = $linkItem['item_type'];
        $fileSource = $linkItem['file_source'];
        $shareOwner = $linkItem['uid_owner'];
        $path = null;
        $rootLinkItem = \OCP\Share::resolveReShare($linkItem);
        $fileOwner = $rootLinkItem['uid_owner'];
        // Setup FS with owner
        OCP\JSON::checkUserExists($fileOwner);
        OC_Util::tearDownFS();
        OC_Util::setupFS($fileOwner);
        // 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()));
 /**
  * Creates the environment based on the linkItem the token links to
  *
  * @param array $linkItem
  */
 public function setTokenBasedEnv($linkItem)
 {
     // Resolves reshares down to the last real share
     $rootLinkItem = Share::resolveReShare($linkItem);
     $origShareOwner = $rootLinkItem['uid_owner'];
     $this->userFolder = $this->rootFolder->getUserFolder($origShareOwner);
     // This is actually the node ID
     $this->sharedNodeId = $linkItem['file_source'];
     $this->fromRootToFolder = $this->buildFromRootToFolder($this->sharedNodeId);
     $this->folderName = $linkItem['file_target'];
     $this->userId = $rootLinkItem['uid_owner'];
     $this->sharePassword = $linkItem['share_with'];
 }
Esempio n. 8
0
 protected function getSharingOps()
 {
     $where = 'AND `file_source`=?';
     $values = array($this->fileId);
     if (\OCP\User::isLoggedIn()) {
         $where .= ' AND ((`share_type`=' . \OCP\Share::SHARE_TYPE_USER . ' AND `share_with`=?) OR  `share_type`=' . \OCP\Share::SHARE_TYPE_LINK . ')';
         $values[] = \OCP\User::getUser();
     } else {
         $where .= ' AND (`share_type`=' . \OCP\Share::SHARE_TYPE_LINK . ')';
     }
     $query = \OC_DB::prepare('SELECT `*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `uid_owner`, ' . '`share_type`, `share_with`, `file_source`, `path`, `file_target`, ' . '`*PREFIX*share`.`permissions`, `expiration`, `storage`, `*PREFIX*filecache`.`parent` as `file_parent`, ' . '`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`' . 'FROM `*PREFIX*share` INNER JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid` WHERE `item_type` = \'file\' ' . $where);
     $result = $query->execute($values);
     $shares = $result->fetchAll();
     $origins = array();
     if (is_array($shares)) {
         foreach ($shares as $share) {
             $origin = \OCP\Share::resolveReShare($share);
             if (!isset($origin['path']) && isset($origin['file_target'])) {
                 $origin['path'] = 'files/' . $origin['file_target'];
             }
             $origins[] = $origin;
         }
     }
     return $origins;
 }
Esempio n. 9
0
 /**
  * @param string $token
  * @return string Resolved file path of the token
  * @throws \Exception In case share could not get properly resolved
  */
 private function getPath($token)
 {
     $linkItem = Share::getShareByToken($token, false);
     if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
         // seems to be a valid share
         $rootLinkItem = Share::resolveReShare($linkItem);
         if (isset($rootLinkItem['uid_owner'])) {
             if (!$this->userManager->userExists($rootLinkItem['uid_owner'])) {
                 throw new \Exception('Owner of the share does not exist anymore');
             }
             OC_Util::tearDownFS();
             OC_Util::setupFS($rootLinkItem['uid_owner']);
             $path = Filesystem::getPath($linkItem['file_source']);
             if (!empty($path) && Filesystem::isReadable($path)) {
                 return $path;
             }
         }
     }
     throw new \Exception('No file found belonging to file.');
 }
Esempio n. 10
0
 /**
  *
  * @param array $linkItem
  *@return array || null
  */
 public function resolveReShare($linkItem)
 {
     return Share::resolveReShare($linkItem);
 }
Esempio n. 11
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  */
 public function getGuestSettingsCalendar()
 {
     $token = $this->params('t');
     if (isset($token)) {
         $linkItem = \OCP\Share::getShareByToken($token, false);
         if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
             // seems to be a valid share
             if ($linkItem['item_type'] === CalendarApp::SHARECALENDAR) {
                 $sPrefix = CalendarApp::SHARECALENDARPREFIX;
             }
             if ($linkItem['item_type'] === CalendarApp::SHAREEVENT) {
                 $sPrefix = CalendarApp::SHAREEVENTPREFIX;
             }
             $itemSource = CalendarApp::validateItemSource($linkItem['item_source'], $sPrefix);
             $shareOwner = $linkItem['uid_owner'];
             $rootLinkItem = \OCP\Share::resolveReShare($linkItem);
             if (isset($rootLinkItem['uid_owner'])) {
                 \OCP\JSON::checkUserExists($rootLinkItem['uid_owner']);
                 $calendar = CalendarCalendar::find($itemSource);
                 if (!array_key_exists('active', $calendar)) {
                     $calendar['active'] = 1;
                 }
                 if ($calendar['active'] == 1) {
                     $eventSources[] = CalendarCalendar::getEventSourceInfo($calendar, true);
                     $eventSources[0]['url'] = \OC::$server->getURLGenerator()->linkToRoute($this->appName . '.public.getEventsPublic') . '?t=' . $token;
                     $calendarInfo[$calendar['id']] = array('bgcolor' => $calendar['calendarcolor'], 'color' => CalendarCalendar::generateTextColor($calendar['calendarcolor']));
                     $myRefreshChecker[$calendar['id']] = $calendar['ctag'];
                 }
             }
         }
         $defaultView = 'month';
         if ($this->session->get('public_currentView') != '') {
             $defaultView = (string) $this->session->get('public_currentView');
         }
         $params = ['status' => 'success', 'defaultView' => $defaultView, 'agendatime' => 'HH:mm { - HH:mm}', 'defaulttime' => 'HH:mm', 'firstDay' => '1', 'calendarId' => $calendar['id'], 'eventSources' => $eventSources, 'calendarcolors' => $calendarInfo, 'myRefreshChecker' => $myRefreshChecker];
         $response = new JSONResponse($params);
         return $response;
     }
 }
Esempio n. 12
0
 /**
  *@PublicPage
  * @NoCSRFRequired
  * @UseSession
  */
 public function index($token)
 {
     if ($token) {
         $linkItem = Share::getShareByToken($token, false);
         if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
             $type = $linkItem['item_type'];
             $itemSource = CalendarApp::validateItemSource($linkItem['item_source'], CalendarApp::SHARETODOPREFIX);
             $shareOwner = $linkItem['uid_owner'];
             $calendarName = $linkItem['item_target'];
             $rootLinkItem = \OCP\Share::resolveReShare($linkItem);
             // stupid copy and paste job
             if (isset($linkItem['share_with'])) {
                 // Authenticate share_with
                 $password = $this->params('password');
                 if (isset($password)) {
                     if ($linkItem['share_type'] === \OCP\Share::SHARE_TYPE_LINK) {
                         // Check Password
                         $newHash = '';
                         if (\OC::$server->getHasher()->verify($password, $linkItem['share_with'], $newHash)) {
                             $this->session->set('public_link_authenticated', $linkItem['id']);
                             if (!empty($newHash)) {
                             }
                         } else {
                             \OCP\Util::addStyle('files_sharing', 'authenticate');
                             $params = array('wrongpw' => true);
                             return new TemplateResponse('files_sharing', 'authenticate', $params, 'guest');
                         }
                     } else {
                         \OCP\Util::writeLog('share', 'Unknown share type ' . $linkItem['share_type'] . ' for share id ' . $linkItem['id'], \OCP\Util::ERROR);
                         return false;
                     }
                 } else {
                     // Check if item id is set in session
                     if (!$this->session->exists('public_link_authenticated') || $this->session->get('public_link_authenticated') !== $linkItem['id']) {
                         // Prompt for password
                         \OCP\Util::addStyle('files_sharing', 'authenticate');
                         $params = array();
                         return new TemplateResponse('files_sharing', 'authenticate', $params, 'guest');
                     }
                 }
             }
             \OCP\Util::addStyle(CalendarApp::$appname, '3rdparty/fontello/css/animation');
             \OCP\Util::addStyle(CalendarApp::$appname, '3rdparty/fontello/css/fontello');
             \OCP\Util::addStyle($this->appName, 'style');
             \OCP\Util::addStyle($this->appName, 'share');
             \OCP\Util::addScript($this->appName, 'share');
             $data = TasksApp::getEventObject($itemSource, false, false);
             $l = \OC::$server->getL10N($this->appName);
             $object = VObject::parse($data['calendardata']);
             $vTodo = $object->VTODO;
             $id = $data['id'];
             $object = Object::cleanByAccessClass($id, $object);
             $accessclass = $vTodo->getAsString('CLASS');
             $permissions = TasksApp::getPermissions($id, TasksApp::TODO, $accessclass);
             if ($accessclass === 'PRIVATE') {
                 header('HTTP/1.0 404 Not Found');
                 $response = new TemplateResponse('core', '404', '', 'guest');
                 return $response;
             }
             $categories = $vTodo->getAsArray('CATEGORIES');
             $summary = strtr($vTodo->getAsString('SUMMARY'), array('\\,' => ',', '\\;' => ';'));
             $location = strtr($vTodo->getAsString('LOCATION'), array('\\,' => ',', '\\;' => ';'));
             $description = strtr($vTodo->getAsString('DESCRIPTION'), array('\\,' => ',', '\\;' => ';'));
             $priorityOptionsArray = TasksApp::getPriorityOptionsFilterd();
             //$priorityOptions=$priorityOptionsArray[(string)$vTodo->priority];
             $priorityOptions = 0;
             $link = strtr($vTodo->getAsString('URL'), array('\\,' => ',', '\\;' => ';'));
             $TaskDate = '';
             $TaskTime = '';
             if ($vTodo->DUE) {
                 $dateDueType = $vTodo->DUE->getValueType();
                 if ($dateDueType == 'DATE') {
                     $TaskDate = $vTodo->DUE->getDateTime()->format('d.m.Y');
                     $TaskTime = '';
                 }
                 if ($dateDueType == 'DATE-TIME') {
                     $TaskDate = $vTodo->DUE->getDateTime()->format('d.m.Y');
                     $TaskTime = $vTodo->DUE->getDateTime()->format('H:i');
                 }
             }
             $TaskStartTime = '';
             $TaskStartDate = '';
             if ($vTodo->DTSTART) {
                 $dateStartType = $vTodo->DTSTART->getValueType();
                 if ($dateStartType === 'DATE') {
                     $TaskStartDate = $vTodo->DTSTART->getDateTime()->format('d.m.Y');
                     $TaskStartTime = '';
                 }
                 if ($dateStartType === 'DATE-TIME') {
                     $TaskStartDate = $vTodo->DTSTART->getDateTime()->format('d.m.Y');
                     $TaskStartTime = $vTodo->DTSTART->getDateTime()->format('H:i');
                 }
             }
             //PERCENT-COMPLETE
             $cptlStatus = (string) $this->l10n->t('needs action');
             $percentComplete = 0;
             if ($vTodo->{'PERCENT-COMPLETE'}) {
                 $percentComplete = $vTodo->{'PERCENT-COMPLETE'};
                 //$cptlStatus = (string)$this->l10n->t('in procress');
                 if ($percentComplete === '0') {
                     $cptlStatus = (string) $this->l10n->t('needs action');
                 }
                 if ($percentComplete > '0' && $percentComplete < '100') {
                     $cptlStatus = (string) $this->l10n->t('in procress');
                 }
             }
             if ($vTodo->{'COMPLETED'}) {
                 $cptlStatus = (string) $this->l10n->t('completed');
             }
             $timezone = \OC::$server->getSession()->get('public_link_timezone');
             $sCat = '';
             if (is_array($categories) && count($categories) > 0) {
                 $sCat = $categories;
             }
             $params = ['eventid' => $itemSource, 'permissions' => $permissions, 'priorityOptions' => $priorityOptions, 'percentComplete' => $percentComplete, 'cptlStatus' => $cptlStatus, 'TaskDate' => isset($TaskDate) ? $TaskDate : '', 'TaskTime' => isset($TaskTime) ? $TaskTime : '', 'TaskStartDate' => isset($TaskStartDate) ? $TaskStartDate : '', 'TaskStartTime' => isset($TaskStartTime) ? $TaskStartTime : '', 'title' => $summary, 'accessclass' => $accessclass, 'location' => $location, 'categories' => $sCat, 'calendar' => $data['calendarid'], 'aCalendar' => CalendarApp::getCalendar($data['calendarid'], false, false), 'calAppName' => CalendarApp::$appname, 'description' => $description, 'repeat_rules' => '', 'link' => $link, 'timezone' => $timezone, 'uidOwner' => $shareOwner, 'displayName' => \OCP\User::getDisplayName($shareOwner), 'sharingToken' => $token, 'token' => $token];
             $response = new TemplateResponse($this->appName, 'publicevent', $params, 'base');
             return $response;
         }
         //end isset
     }
     //end token
     $tmpl = new \OCP\Template('', '404', 'guest');
     $tmpl->printPage();
 }
Esempio n. 13
0
 /**
  * Creates the environment based on the linkItem the token links to
  *
  * @param array $linkItem
  */
 public function setTokenBasedEnv($linkItem)
 {
     // Resolves reshares down to the last real share
     $rootLinkItem = Share::resolveReShare($linkItem);
     $origShareOwner = $rootLinkItem['uid_owner'];
     $this->userFolder = $this->serverContainer->getUserFolder($origShareOwner);
     // TODO: Replace with this in 8.2 (https://github.com/owncloud/core/pull/16965)
     // You get root by calling getRootFolder() on the server container
     //$this->userFolder = $this->root->getUserFolder($origShareOwner);
     // This is actually the node ID
     $this->sharedNodeId = $linkItem['file_source'];
     $this->fromRootToFolder = $this->buildFromRootToFolder($this->sharedNodeId);
     $this->folderName = $linkItem['file_target'];
     $this->userId = $rootLinkItem['uid_owner'];
     $this->sharePassword = $linkItem['share_with'];
 }