Exemple #1
0
 public function GetPrincipalUrl(CDavRequest $request)
 {
     if (strlen($this->principalURL) > 0) {
         return $this->principalURL;
     }
     if (strpos($request->GetBaseUri(), 'http') === 0) {
         $this->principalURL = CDav::CheckIfRightSlashAdded($request->GetBaseUri());
     } else {
         $this->principalURL = ($request->GetParameter("HTTPS") === "on" ? "https" : "http") . '://' . $request->GetParameter('HTTP_HOST') . $request->GetParameter('SCRIPT_NAME') . '/';
     }
     $this->principalURL .= 'principals/user/' . $this->Login() . '/';
     if (!$request->IsUrlRequired()) {
         $this->principalURL = parse_url($this->principalURL, PHP_URL_PATH);
     }
     return $this->principalURL;
 }
 public function Propfind(&$arResources, $siteId, $account, $arPath, $id = null)
 {
     $calendarId = $this->GetCalendarId($siteId, $account, $arPath);
     if ($calendarId == null) {
         return '404 Not Found';
     }
     $request = $this->groupdav->GetRequest();
     $currentPrincipal = $request->GetPrincipal();
     if (!$this->CheckPrivileges('urn:ietf:params:xml:ns:caldav:read-free-busy', $currentPrincipal, $calendarId)) {
         return '403 Forbidden';
     }
     $requestDocument = $request->GetXmlDocument();
     $path = CDav::CheckIfRightSlashAdded($request->GetPath());
     if (!isset($calendarId[0], $calendarId[1])) {
         $arCalendarList = CCalendar::GetCalendarList($calendarId, array('skipExchange' => true));
         foreach ($arCalendarList as $calendar) {
             $resource = new CDavResource($path . $calendar["ID"] . "/");
             $this->GetCalendarProperties($resource, $siteId, $account, array($calendar["ID"]), 0);
             $arResources[] = $resource;
         }
         return true;
     }
     $bCalendarData = count($requestDocument->GetPath('/*/DAV::allprop')) > 0;
     if (!$bCalendarData || $requestDocument->GetRoot()->GetXmlns() != CDavGroupDav::CALDAV) {
         $arProp = $requestDocument->GetPath('/*/DAV::prop/*');
         foreach ($arProp as $prop) {
             if ($prop->GetTag() == 'calendar-data') {
                 $bCalendarData = true;
                 break;
             }
         }
     }
     $arFilter = array('DATE_START' => ConvertTimeStamp(time() - 93 * 24 * 3600, "FULL"), 'DATE_END' => ConvertTimeStamp(time() + 365 * 24 * 3600, "FULL"));
     if (($id || $requestDocument->GetRoot() && $requestDocument->GetRoot()->GetTag() != 'propfind') && !$this->PrepareFilters($arFilter, $requestDocument, $id)) {
         return false;
     }
     if ($calendarId[0] > 0) {
         $arEvents = CCalendar::GetDavCalendarEventsList($calendarId, $arFilter);
         foreach ($arEvents as $event) {
             if (!$this->CheckPrivileges('DAV::read', $currentPrincipal, $calendarId)) {
                 $this->ClearPrivateData($event);
             }
             $resource = new CDavResource($path . $this->GetPath($event));
             $resource->AddProperty('getetag', $this->GetETag($calendarId, $event));
             $resource->AddProperty('getcontenttype', $request->GetAgent() != 'kde' ? 'text/calendar; charset=utf-8; component=VEVENT' : 'text/calendar');
             $resource->AddProperty('getlastmodified', MakeTimeStamp($event['TIMESTAMP_X']));
             $resource->AddProperty('resourcetype', '');
             if ($bCalendarData) {
                 $content = $this->GetICalContent($event, $siteId);
                 $resource->AddProperty('getcontentlength', strlen($content));
                 $resource->AddProperty('calendar-data', $content, CDavGroupDav::CALDAV);
             } else {
                 $resource->AddProperty('getcontentlength', "");
             }
             $arResources[] = $resource;
         }
     }
     return true;
 }
 public function Propfind(&$arResources, $siteId, $account, $arPath, $id = null)
 {
     $collectionId = $this->GetCollectionId($siteId, $account, $arPath);
     if ($collectionId == null) {
         return '404 Not Found';
     }
     $request = $this->groupdav->GetRequest();
     $currentPrincipal = $request->GetPrincipal();
     if (!$this->CheckPrivileges('DAV:read', $currentPrincipal, $collectionId)) {
         return '403 Forbidden';
     }
     $requestDocument = $request->GetXmlDocument();
     $path = CDav::CheckIfRightSlashAdded($request->GetPath());
     $bAddressData = count($requestDocument->GetPath('/*/DAV::allprop')) > 0;
     if (!$bAddressData || $requestDocument->GetRoot()->GetXmlns() != CDavGroupDav::CARDDAV) {
         $arProp = $requestDocument->GetPath('/*/DAV::prop/*');
         foreach ($arProp as $prop) {
             if ($prop->GetTag() == 'address-data') {
                 $bAddressData = true;
                 break;
             }
         }
     }
     $arFilter = array();
     if (($id || $requestDocument->GetRoot() && $requestDocument->GetRoot()->GetTag() != 'propfind') && !$this->PrepareFilters($arFilter, $requestDocument, $id)) {
         return false;
     }
     $arContacts = CDavAccount::GetAddressbookContactsList($collectionId, $arFilter);
     foreach ($arContacts as $contact) {
         $resource = new CDavResource($path . $this->GetPath($contact));
         $resource->AddProperty('getetag', $this->GetETag($collectionId, $contact));
         $resource->AddProperty('getcontenttype', 'text/vcard');
         $resource->AddProperty('getlastmodified', MakeTimeStamp($contact['TIMESTAMP_X']));
         $resource->AddProperty('resourcetype', '');
         if ($bAddressData) {
             $content = $this->GetVCardContent($contact);
             $resource->AddProperty('getcontentlength', strlen($content));
             $resource->AddProperty('address-data', $content, CDavGroupDav::CARDDAV);
         } else {
             $resource->AddProperty('getcontentlength', "");
         }
         $arResources[] = $resource;
     }
     return true;
 }
Exemple #4
0
 protected function PROPFIND(&$arResources, $method = 'PROPFIND')
 {
     $arResources = array();
     $arRequestPath = self::ParsePath($this->request->GetPath());
     $accountPrefixPath = CDav::CheckIfRightSlashAdded($arRequestPath["accountPrefix"]);
     $requestDocument = $this->request->GetXmlDocument();
     $application = $arRequestPath["application"];
     if (!$application) {
         if (!$arRequestPath["account"]) {
             $arRequestPath["account"] = array("user", $this->request->GetPrincipal()->Id());
         }
         $arAccount = CDavAccount::GetAccountById($arRequestPath["account"]);
         $resource = new CDavResource($accountPrefixPath);
         $resource->AddProperty('resourcetype', array('collection', ''));
         $this->GetCollectionProperties($resource, $arRequestPath["site"], $arRequestPath["account"], $arRequestPath["path"]);
         foreach ($this->arApplications as $app) {
             if (($handler = $this->GetApplicationHandler($app)) && method_exists($handler, 'GetCollectionProperties')) {
                 $handler->GetCollectionProperties($resource, $arRequestPath["site"], $arRequestPath["account"], null, $arRequestPath["path"], 0);
             }
         }
         $arResources[] = $resource;
         if ($this->request->GetDepth()) {
             if (strlen($accountPrefixPath) == 1) {
                 $resource = new CDavResource('/principals/');
                 $resource->AddProperty('displayname', GetMessage("DAV_PRINCIPALS"));
                 $resource->AddProperty('resourcetype', array('principals', ''));
                 $resource->AddProperty('current-user-principal', array('href', $this->request->GetPrincipalUrl()));
                 $arResources[] = $resource;
             }
             foreach ($this->arApplications as $app) {
                 if (($handler = $this->GetApplicationHandler($app)) && method_exists($handler, 'GetHomeCollectionUrl')) {
                     $resourcePath = $handler->GetHomeCollectionUrl($arRequestPath["site"], $arRequestPath["account"], $arRequestPath["path"]);
                 } else {
                     $resourcePath = $accountPrefixPath . $app;
                 }
                 $resource = new CDavResource($resourcePath);
                 $this->GetCollectionProperties($resource, $arRequestPath["site"], $arRequestPath["account"], $arRequestPath["path"]);
                 if (method_exists($handler, 'GetCollectionProperties')) {
                     $handler->GetCollectionProperties($resource, $arRequestPath["site"], $arRequestPath["account"], $app, $arRequestPath["path"], 0);
                 }
                 $resource->AddProperty('getetag', $app);
                 $arResources[] = $resource;
             }
         }
         return true;
     }
     if ($handler = $this->GetApplicationHandler($application)) {
         if ($application != "principals" && $method != 'REPORT' && $arRequestPath["id"] == null) {
             $resource = new CDavResource($this->request->GetPath());
             $this->GetCollectionProperties($resource, $arRequestPath["site"], $arRequestPath["account"], $arRequestPath["path"]);
             if (method_exists($handler, 'GetCollectionProperties')) {
                 $handler->GetCollectionProperties($resource, $arRequestPath["site"], $arRequestPath["account"], $application, $arRequestPath["path"], $application == 'addressbook' && $this->request->GetAgent() == 'kde' ? BX_GW_SKIP_EXTRA_TYPES : 0);
             }
             $arResources[] = $resource;
             if ($this->request->GetDepth() == 0) {
                 return true;
             }
         }
         return $handler->Propfind($arResources, $arRequestPath["site"], $arRequestPath["account"], $arRequestPath["path"], $arRequestPath["id"]);
     }
     return '501 Not Implemented';
 }
Exemple #5
0
 public function ExtractFromLock($path, $arLock)
 {
     $this->path = CDav::CheckIfRightSlashAdded($path);
     $this->arProperties = array(self::MakeProp("displayname", $path), self::MakeProp("creationdate", $arLock['CREATED']), self::MakeProp("getlastmodified", $arLock['MODIFIED']), self::MakeProp("resourcetype", ""), self::MakeProp("getcontenttype", ""), self::MakeProp("getcontentlength", 0));
 }