예제 #1
0
 /**
  * create a new share
  *
  * @param array $params
  * @return \OC_OCS_Result
  */
 public function createShare($params)
 {
     if (!$this->isS2SEnabled(true)) {
         return new \OC_OCS_Result(null, 503, 'Server does not support federated cloud sharing');
     }
     $remote = isset($_POST['remote']) ? $_POST['remote'] : null;
     $token = isset($_POST['token']) ? $_POST['token'] : null;
     $name = isset($_POST['name']) ? $_POST['name'] : null;
     $owner = isset($_POST['owner']) ? $_POST['owner'] : null;
     $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null;
     $remoteId = isset($_POST['remoteId']) ? (int) $_POST['remoteId'] : null;
     if ($remote && $token && $name && $owner && $remoteId && $shareWith) {
         if (!\OCP\Util::isValidFileName($name)) {
             return new \OC_OCS_Result(null, 400, 'The mountpoint name contains invalid characters.');
         }
         if (!\OCP\User::userExists($shareWith)) {
             return new \OC_OCS_Result(null, 400, 'User does not exists');
         }
         \OC_Util::setupFS($shareWith);
         $externalManager = new \OCA\Files_Sharing\External\Manager(\OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), \OC::$server->getHTTPHelper(), $shareWith);
         try {
             $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId);
             $user = $owner . '@' . $this->cleanupRemote($remote);
             \OC::$server->getActivityManager()->publishActivity('files_sharing', \OCA\Files_Sharing\Activity::SUBJECT_REMOTE_SHARE_RECEIVED, array($user), '', array(), '', '', $shareWith, \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::PRIORITY_LOW);
             return new \OC_OCS_Result();
         } catch (\Exception $e) {
             \OCP\Util::writeLog('files_sharing', 'server can not add remote share, ' . $e->getMessage(), \OCP\Util::ERROR);
             return new \OC_OCS_Result(null, 500, 'internal server error, was not able to add share from ' . $remote);
         }
     }
     return new \OC_OCS_Result(null, 400, 'server can not add remote share, missing parameter');
 }
예제 #2
0
 /**
  * create a new share
  *
  * @param array $params
  * @return \OC_OCS_Result
  */
 public function createShare($params)
 {
     if (!$this->isS2SEnabled(true)) {
         return new \OC_OCS_Result(null, 503, 'Server does not support federated cloud sharing');
     }
     $remote = isset($_POST['remote']) ? $_POST['remote'] : null;
     $token = isset($_POST['token']) ? $_POST['token'] : null;
     $name = isset($_POST['name']) ? $_POST['name'] : null;
     $owner = isset($_POST['owner']) ? $_POST['owner'] : null;
     $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null;
     $remoteId = isset($_POST['remoteId']) ? (int) $_POST['remoteId'] : null;
     if ($remote && $token && $name && $owner && $remoteId && $shareWith) {
         if (!\OCP\Util::isValidFileName($name)) {
             return new \OC_OCS_Result(null, 400, 'The mountpoint name contains invalid characters.');
         }
         // FIXME this should be a method in the user management instead
         \OCP\Util::writeLog('files_sharing', 'shareWith before, ' . $shareWith, \OCP\Util::DEBUG);
         \OCP\Util::emitHook('\\OCA\\Files_Sharing\\API\\Server2Server', 'preLoginNameUsedAsUserName', array('uid' => &$shareWith));
         \OCP\Util::writeLog('files_sharing', 'shareWith after, ' . $shareWith, \OCP\Util::DEBUG);
         if (!\OCP\User::userExists($shareWith)) {
             return new \OC_OCS_Result(null, 400, 'User does not exists');
         }
         \OC_Util::setupFS($shareWith);
         $externalManager = new \OCA\Files_Sharing\External\Manager(\OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), \OC::$server->getHTTPHelper(), \OC::$server->getNotificationManager(), $shareWith);
         try {
             $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId);
             $user = $owner . '@' . $this->cleanupRemote($remote);
             \OC::$server->getActivityManager()->publishActivity(Activity::FILES_SHARING_APP, Activity::SUBJECT_REMOTE_SHARE_RECEIVED, array($user, trim($name, '/')), '', array(), '', '', $shareWith, Activity::TYPE_REMOTE_SHARE, Activity::PRIORITY_LOW);
             /**
             * FIXME
             				$urlGenerator = \OC::$server->getURLGenerator();
             
             				$notificationManager = \OC::$server->getNotificationManager();
             				$notification = $notificationManager->createNotification();
             				$notification->setApp('files_sharing')
             					->setUser($shareWith)
             					->setTimestamp(time())
             					->setObject('remote_share', $remoteId)
             					->setSubject('remote_share', [$user, trim($name, '/')]);
             
             				$declineAction = $notification->createAction();
             				$declineAction->setLabel('decline')
             					->setLink($urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/remote_shares/' . $remoteId), 'DELETE');
             				$notification->addAction($declineAction);
             
             				$acceptAction = $notification->createAction();
             				$acceptAction->setLabel('accept')
             					->setLink($urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/remote_shares/' . $remoteId), 'POST');
             				$notification->addAction($acceptAction);
             
             				$notificationManager->notify($notification);
             */
             return new \OC_OCS_Result();
         } catch (\Exception $e) {
             \OCP\Util::writeLog('files_sharing', 'server can not add remote share, ' . $e->getMessage(), \OCP\Util::ERROR);
             return new \OC_OCS_Result(null, 500, 'internal server error, was not able to add share from ' . $remote);
         }
     }
     return new \OC_OCS_Result(null, 400, 'server can not add remote share, missing parameter');
 }
예제 #3
0
// Check for invalid name
if (!\OCP\Util::isValidFileName($name)) {
    \OCP\JSON::error(array('data' => array('message' => $l->t('The mountpoint name contains invalid characters.'))));
    exit;
}
$externalManager = new \OCA\Files_Sharing\External\Manager(\OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), \OC::$server->getHTTPHelper(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession()->getUser()->getUID());
// check for ssl cert
if (substr($remote, 0, 5) === 'https') {
    try {
        \OC::$server->getHTTPClientService()->newClient()->get($remote)->getBody();
    } catch (\Exception $e) {
        \OCP\JSON::error(array('data' => array('message' => $l->t('Invalid or untrusted SSL certificate'))));
        exit;
    }
}
$mount = $externalManager->addShare($remote, $token, $password, $name, $owner, true);
/**
 * @var \OCA\Files_Sharing\External\Storage $storage
 */
$storage = $mount->getStorage();
try {
    // check if storage exists
    $storage->checkStorageAvailability();
} catch (\OCP\Files\StorageInvalidException $e) {
    // note: checkStorageAvailability will already remove the invalid share
    \OCP\Util::writeLog('files_sharing', 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), \OCP\Util::DEBUG);
    \OCP\JSON::error(array('data' => array('message' => $l->t('Could not authenticate to remote share, password might be wrong'))));
    exit;
} catch (\Exception $e) {
    \OCP\Util::writeLog('files_sharing', 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), \OCP\Util::DEBUG);
    $externalManager->removeShare($mount->getMountPoint());