Exemplo n.º 1
0
 /**
  * Authenticates the user based on the current request.
  *
  * If authentication is successful, true must be returned.
  * If authentication fails, an exception must be thrown.
  *
  * @param DAV\Server $server
  * @param string $realm
  * @throws DAV\Exception\NotAuthenticated
  * @return bool
  */
 public function authenticate(DAV\Server $server, $realm)
 {
     $auth = new BasicAuthNoPass();
     $auth->setHTTPRequest($server->httpRequest);
     $auth->setHTTPResponse($server->httpResponse);
     $auth->setRealm($realm);
     $userpass = $auth->getUserPass();
     if (!$userpass) {
         $auth->requireLogin();
         throw new DAV\Exception\NotAuthenticated('No basic authentication headers were found');
     }
     // Authenticates the user
     $token = $userpass[0];
     $shareStore = new \ShareStore(\ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER"));
     $shareData = $shareStore->loadShare($token);
     if (is_array($shareData)) {
         $this->shareData = $shareData;
     } else {
         $auth->requireLogin();
         throw new DAV\Exception\NotAuthenticated('Username or password does not match');
     }
     if (!$this->validateUserPass($userpass[0], $userpass[1])) {
         $auth->requireLogin();
         throw new DAV\Exception\NotAuthenticated('Username or password does not match');
     }
     $repositoryId = $this->shareData["REPOSITORY"];
     $repository = \ConfService::getRepositoryById($repositoryId);
     if ($repository == null) {
         $repository = \ConfService::getRepositoryByAlias($repositoryId);
     }
     if ($repository == null) {
         throw new DAV\Exception\NotAuthenticated('Username cannot access any repository');
     } else {
         $this->rootCollection->updateRepository($repository);
     }
     $this->currentUser = $userpass[0];
     return true;
 }
Exemplo n.º 2
0
 /**
  * Not used for the moment
  * This will expose folder as /dav/FolderName and file as /dav/FileName.txt
  *
  * @param $baseUri
  * @return \AJXP_Sabre_Collection|SharingCollection
  * @throws \Exception
  */
 protected function initCollectionForFileOrFolderAsUniqueItem(&$baseUri)
 {
     try {
         $testBackend = new BasicAuthNoPass();
         $userPass = $testBackend->getUserPass();
         if (isset($userPass[0])) {
             $shareStore = new \ShareStore(\ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER"));
             $shareData = $shareStore->loadShare($userPass[0]);
             if (isset($shareData) && isset($shareData["REPOSITORY"])) {
                 $repo = \ConfService::getRepositoryById($shareData["REPOSITORY"]);
                 if (!empty($repo) && !$repo->hasContentFilter()) {
                     $baseDir = basename($repo->getOption("PATH"));
                 }
             }
         }
     } catch (\Exception $e) {
     }
     $rootCollection = new \AJXP_Sabre_Collection("/", null, null);
     if (isset($baseDir)) {
         $currentPath = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
         if ($currentPath == $baseUri || $currentPath == $baseUri . "/") {
             $rootCollection = new SharingCollection("/", null, null);
         } else {
             $baseUri .= "/{$baseDir}";
         }
     }
     return $rootCollection;
 }