Beispiel #1
0
 public function getMimeType($path)
 {
     $path = $this->cleanPath($path);
     try {
         $response = $this->client->propfind($path, array('{DAV:}getcontenttype', '{DAV:}resourcetype'));
         $responseType = $response["{DAV:}resourcetype"]->resourceType;
         $type = (count($responseType) > 0 and $responseType[0] == "{DAV:}collection") ? 'dir' : 'file';
         if ($type == 'dir') {
             return 'httpd/unix-directory';
         } elseif (isset($response['{DAV:}getcontenttype'])) {
             return $response['{DAV:}getcontenttype'];
         } else {
             return false;
         }
     } catch (Exception $e) {
         return false;
     }
 }
Beispiel #2
0
 /**
  * we test if webDAV is working properly
  *
  * The basic assumption is that if the server returns 401/Not Authenticated for an unauthenticated PROPFIND
  * the web server it self is setup properly.
  *
  * Why not an authenticated PROFIND and other verbs?
  *  - We don't have the password available
  *  - We have no idea about other auth methods implemented (e.g. OAuth with Bearer header)
  *
  */
 public static function isWebDAVWorking()
 {
     if (!function_exists('curl_init')) {
         return true;
     }
     $settings = array('baseUri' => OC_Helper::linkToRemote('webdav'));
     // save the old timeout so that we can restore it later
     $old_timeout = ini_get("default_socket_timeout");
     // use a 5 sec timeout for the check. Should be enough for local requests.
     ini_set("default_socket_timeout", 5);
     $client = new \Sabre_DAV_Client($settings);
     // for this self test we don't care if the ssl certificate is self signed and the peer cannot be verified.
     $client->setVerifyPeer(false);
     $return = true;
     try {
         // test PROPFIND
         $client->propfind('', array('{DAV:}resourcetype'));
     } catch (\Sabre_DAV_Exception_NotAuthenticated $e) {
         $return = true;
     } catch (\Exception $e) {
         OC_Log::write('core', 'isWebDAVWorking: NO - Reason: ' . $e, OC_Log::WARN);
         $return = false;
     }
     // restore the original timeout
     ini_set("default_socket_timeout", $old_timeout);
     return $return;
 }