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(); } } }
/** *@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; } }
public static function getByShareToken($token) { $linkItem = \OCP\Share::getShareByToken($token); if (is_array($linkItem) && isset($linkItem['uid_owner'])) { // seems to be a valid share $rootLinkItem = \OCP\Share::resolveReShare($linkItem); $fileOwner = $rootLinkItem['uid_owner']; } else { throw new \Exception('This file was probably unshared'); } if (!isset($rootLinkItem['path']) && isset($rootLinkItem['file_target'])) { $rootLinkItem['path'] = 'files/' . $rootLinkItem['file_target']; } $file = new File($rootLinkItem['file_source'], array($rootLinkItem)); if (isset($rootLinkItem['uid_owner'])) { \OC_Util::tearDownFS(); \OC_Util::setupFS($rootLinkItem['uid_owner']); $file->setOwner($rootLinkItem['uid_owner']); $file->setPath('/files' . \OC\Files\Filesystem::getPath($linkItem['file_source'])); } if (isset($linkItem['share_with']) && !empty($linkItem['share_with'])) { $file->setPasswordProtected(true); } return $file; }
/** * 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; } }
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; }
/** * 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); }
/** * 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 $newHash = ''; if (\OC::$server->getHasher()->verify($password, $linkItem['share_with'], $newHash)) { /** * FIXME: Migrate old hashes to new hash format * Due to the fact that there is no reasonable functionality to update the password * of an existing share no migration is yet performed there. * The only possibility is to update the existing share which will result in a new * share ID and is a major hack. * * In the future the migration should be performed once there is a proper method * to update the share's password. (for example `$share->updatePassword($password)` * * @link https://github.com/owncloud/core/issues/10671 */ if (!empty($newHash)) { } return true; } else { if (\OC::$server->getSession()->exists('public_link_authenticated') && \OC::$server->getSession()->get('public_link_authenticated') === $linkItem['id']) { return true; } else { return false; } } } else { if ($linkItem['share_type'] == \OCP\Share::SHARE_TYPE_REMOTE) { return true; } else { return false; } } } else { return true; } }
/** * @expectedException \Exception * @expectedExceptionMessage Owner of the share does not exist anymore */ public function testShowShareWithNotExistingUser() { $this->container['UserManager']->expects($this->once())->method('userExists')->with($this->user)->will($this->returnValue(false)); $linkItem = Share::getShareByToken($this->token, false); \OC::$server->getSession()->set('public_link_authenticated', $linkItem['id']); $this->shareController->showShare($this->token); }
<?php \OCP\JSON::checkAppEnabled('gallery'); OCP\Util::addStyle('gallery', 'styles'); OCP\Util::addStyle('gallery', 'mobile'); $token = isset($_GET['t']) ? (string) $_GET['t'] : ''; if ($token) { $linkItem = \OCP\Share::getShareByToken($token, false); 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']; $albumName = trim($linkItem['file_target'], '//'); $ownerDisplayName = \OC_User::getDisplayName($fileOwner); // stupid copy and paste job if (isset($linkItem['share_with'])) { // Authenticate share_with $url = OCP\Util::linkToPublic('gallery') . '&t=' . $token; if (isset($_GET['file'])) { $url .= '&file=' . urlencode($_GET['file']); } else { if (isset($_GET['dir'])) { $url .= '&dir=' . urlencode($_GET['dir']); } } if (isset($_POST['password'])) { $password = $_POST['password'];
/** * @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.'); }
<?php /** * 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'); $square = isset($_GET['square']) ? (bool) $_GET['square'] : false; $scale = isset($_GET['scale']) ? $_GET['scale'] : 1; $images = explode(';', $_GET['image']); if (!empty($_GET['token'])) { $linkItem = \OCP\Share::getShareByToken($_GET['token']); if (!(is_array($linkItem) && isset($linkItem['uid_owner']))) { exit; } // seems to be a valid share $rootLinkItem = \OCP\Share::resolveReShare($linkItem); $user = $rootLinkItem['uid_owner']; // Setup filesystem OCP\JSON::checkUserExists($user); OC_Util::tearDownFS(); OC_Util::setupFS($user); $root = \OC\Files\Filesystem::getPath($linkItem['file_source']) . '/'; $images = array_map(function ($image) use($root) { return $root . $image; }, $images); } else { $root = ''; OCP\JSON::checkLoggedIn();
$expiration = null; if (isset($_POST['expiration']) && $_POST['expiration'] !== '') { try { $date = new DateTime((string) $_POST['expiration']); $expiration = $date->getTimestamp(); } catch (Exception $e) { \OCP\Util::writeLog('sharing', "Couldn't read date: " . $e->getMessage(), \OCP\Util::ERROR); } } $result = $mailNotification->sendLinkShareMail($to_address, $file, $link, $expiration); if (empty($result)) { // Get the token from the link $linkParts = explode('/', $link); $token = array_pop($linkParts); // Get the share for the token $share = \OCP\Share::getShareByToken($token, false); if ($share !== false) { $currentUser = \OC::$server->getUserSession()->getUser()->getUID(); $file = '/' . ltrim($file, '/'); // Check whether share belongs to the user and whether the file is the same if ($share['file_target'] === $file && $share['uid_owner'] === $currentUser) { // Get the path for the user $view = new \OC\Files\View('/' . $currentUser . '/files'); $fileId = (int) $share['item_source']; $path = $view->getPath((int) $share['item_source']); if ($path !== null) { $event = \OC::$server->getActivityManager()->generateEvent(); $event->setApp(\OCA\Files_Sharing\Activity::FILES_SHARING_APP)->setType(\OCA\Files_Sharing\Activity::TYPE_SHARED)->setAuthor($currentUser)->setAffectedUser($currentUser)->setObject('files', $fileId, $path)->setSubject(\OCA\Files_Sharing\Activity::SUBJECT_SHARED_EMAIL, [$path, $to_address]); \OC::$server->getActivityManager()->publish($event); } }
/** * * @param string $token *@return array || null */ public function getShareByToken($token) { return Share::getShareByToken($token, false); }
<?php /** * 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'); list($owner, $img) = explode('/', $_GET['file'], 2); $linkItem = \OCP\Share::getShareByToken($owner); if (is_array($linkItem) && isset($linkItem['uid_owner'])) { // seems to be a valid share $rootLinkItem = \OCP\Share::resolveReShare($linkItem); $user = $rootLinkItem['uid_owner']; // Setup filesystem OCP\JSON::checkUserExists($user); OC_Util::tearDownFS(); OC_Util::setupFS($user); $fullPath = \OC\Files\Filesystem::getPath($linkItem['file_source']); if ($fullPath === null) { exit; } $img = trim($fullPath . '/' . $img); } else { OCP\JSON::checkLoggedIn(); $user = OCP\User::getUser(); } session_write_close(); $square = isset($_GET['square']) ? (bool) $_GET['square'] : false; $image = new \OCA\Gallery\Thumbnail('/' . $img, $user, $square);
/** * @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; } }
/** * Creates an environment based on a token * * @param string $token * * @return Environment */ protected function setTokenBasedEnv($token) { $linkItem = Share::getShareByToken($token, false); $environment = $this->instantiateEnvironment(); $environment->setTokenBasedEnv($linkItem); return $environment; }
public function testShareItemWithLink() { \OC_User::setUserId($this->user1); $token = \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ); $this->assertInternalType('string', $token, 'Failed asserting that user 1 successfully shared text.txt as link with token.'); // testGetShareByTokenNoExpiration $row = $this->getShareByValidToken($token); $this->assertEmpty($row['expiration'], 'Failed asserting that the returned row does not have an expiration date.'); // testGetShareByTokenExpirationValid $this->assertTrue(\OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture, ''), 'Failed asserting that user 1 successfully set a future expiration date for the test.txt share.'); $row = $this->getShareByValidToken($token); $this->assertNotEmpty($row['expiration'], 'Failed asserting that the returned row has an expiration date.'); // manipulate share table and set expire date to the past $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `item_type` = ? AND `item_source` = ? AND `uid_owner` = ? AND `share_type` = ?'); $query->bindValue(1, new \DateTime($this->dateInPast), 'datetime'); $query->bindValue(2, 'test'); $query->bindValue(3, 'test.txt'); $query->bindValue(4, $this->user1); $query->bindValue(5, \OCP\Share::SHARE_TYPE_LINK); $query->execute(); $this->assertFalse(\OCP\Share::getShareByToken($token), 'Failed asserting that an expired share could not be found.'); }
public function testShowShare() { // Test without a not existing token $response = $this->shareController->showShare('ThisTokenShouldHopefullyNeverExistSoThatTheUnitTestWillAlwaysPass :)'); $expectedResponse = new TemplateResponse('core', '404', array(), 'guest'); $this->assertEquals($expectedResponse, $response); // Test with a password protected share and no authentication $response = $this->shareController->showShare($this->token); $expectedResponse = new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', array('token' => $this->token))); $this->assertEquals($expectedResponse, $response); // Test with password protected share and authentication $linkItem = Share::getShareByToken($this->token, false); \OC::$server->getSession()->set('public_link_authenticated', $linkItem['id']); $response = $this->shareController->showShare($this->token); $sharedTmplParams = array('displayName' => $this->user, 'filename' => 'file1.txt', 'directory_path' => '/file1.txt', 'mimetype' => 'text/plain', 'dirToken' => $this->token, 'sharingToken' => $this->token, 'server2serversharing' => true, 'protected' => 'true', 'dir' => '', 'downloadURL' => null, 'fileSize' => '33 B', 'nonHumanFileSize' => 33, 'maxSizeAnimateGif' => 10); $expectedResponse = new TemplateResponse($this->container['AppName'], 'public', $sharedTmplParams, 'base'); $this->assertEquals($expectedResponse, $response); }
/** * @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; }
/** *@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(); }
/** * Validates a token to make sure its linked to a valid resource * * Logic mostly duplicated from @see \OCA\Files_Sharing\Helper * * @fixme setIncognitoMode in 8.1 https://github.com/owncloud/core/pull/12912 * * @param string $token * * @return array * * @throws CheckException */ private function getLinkItem($token) { // Allows a logged in user to access public links \OC_User::setIncognitoMode(true); $linkItem = Share::getShareByToken($token, false); $this->checkLinkItemExists($linkItem); $this->checkLinkItemIsValid($linkItem, $token); $this->checkItemType($linkItem); // Checks passed, let's store the linkItem return $linkItem; }
* */ OCP\JSON::checkAppEnabled('files_sharing'); \OC_User::setIncognitoMode(true); $file = array_key_exists('file', $_GET) ? (string) $_GET['file'] : ''; $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '32'; $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '32'; $scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; $token = array_key_exists('t', $_GET) ? (string) $_GET['t'] : ''; $keepAspect = array_key_exists('a', $_GET) ? true : false; if ($token === '') { \OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); \OCP\Util::writeLog('core-preview', 'No token parameter was passed', \OCP\Util::DEBUG); exit; } $linkedItem = \OCP\Share::getShareByToken($token); if ($linkedItem === false || $linkedItem['item_type'] !== 'file' && $linkedItem['item_type'] !== 'folder') { \OC_Response::setStatus(\OC_Response::STATUS_NOT_FOUND); \OCP\Util::writeLog('core-preview', 'Passed token parameter is not valid', \OCP\Util::DEBUG); exit; } if (!isset($linkedItem['uid_owner']) || !isset($linkedItem['file_source'])) { \OC_Response::setStatus(\OC_Response::STATUS_INTERNAL_SERVER_ERROR); \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($linkedItem); $userId = $rootLinkItem['uid_owner']; OCP\JSON::checkUserExists($rootLinkItem['uid_owner']); \OC_Util::setupFS($userId); \OC\Files\Filesystem::initMountPoints($userId);
/** * @PublicPage * * Because the method tested is static, we need to load our test environment \Helper\DataSetup */ public function testBeforeControllerWithPublicNotationAndToken() { $this->reflector->reflect(__CLASS__, __FUNCTION__); $this->mockGetTokenAndPasswordParams($this->sharedFolderToken, $this->passwordForFolderShare); $linkItem = Share::getShareByToken($this->sharedFolderToken, false); $this->mockHasherVerify($this->passwordForFolderShare, $linkItem['share_with'], true); $this->middleware->beforeController(__CLASS__, __FUNCTION__); }