protected function curlRequest($url, $settings) { if ($this->requestTimeout > 0) { $settings[CURLOPT_TIMEOUT] = $this->requestTimeout; } return parent::curlRequest($url, $settings); }
private function simpleResponse($method, $path, $body, $expected) { $path = $this->cleanPath($path); try { $response = $this->client->request($method, $path, $body); return $response['statusCode'] == $expected; } catch (\Exception $e) { return false; } }
function testMultiGet() { $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/addressbooks/user1/book1')); $request->setBody('<?xml version="1.0"?> <c:addressbook-multiget xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav"> <d:prop> <d:getetag /> <c:address-data /> </d:prop> <d:href>/addressbooks/user1/book1/card1</d:href> </c:addressbook-multiget>'); $response = new Sabre_HTTP_ResponseMock(); $this->server->httpRequest = $request; $this->server->httpResponse = $response; $this->server->exec(); $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body); // using the client for parsing $client = new Sabre_DAV_Client(array('baseUri' => '/')); $result = $client->parseMultiStatus($response->body); $this->assertEquals(array('/addressbooks/user1/book1/card1' => array(200 => array('{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD"))), $result); }
/** * Just making this method public * * @param string $url * @return string */ public function getAbsoluteUrl($url) { return parent::getAbsoluteUrl($url); }
/** * 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; }
/** * Initialises the connection to the CDN * */ public function createConnection() { require_once CST_DIR . 'lib/pages/Options.php'; if ($this->connectionType == 'S3') { require_once CST_DIR . 'lib/api/S3.php'; $awsAccessKey = get_option('cst-s3-accesskey'); $awsSecretKey = get_option('cst-s3-secretkey'); $awsEndpoint = get_option('cst-s3-endpoint'); if (empty($awsEndpoint)) { $awsEndpoint = 's3.amazonaws.com'; } // default endpoint to AWS S3 $this->cdnConnection = new S3($awsAccessKey, $awsSecretKey, false, $awsEndpoint); if (@$this->cdnConnection->listBuckets() === false) { CST_page::$messages[] = 'S3 connection error, please check details'; } } else { if ($this->connectionType == 'FTP') { if (get_option('cst-ftp-sftp') == 'yes') { $connection = @ssh2_connect(get_option('cst-ftp-server'), get_option('cst-ftp-port')); if ($connection === false) { CST_Page::$messages[] = 'SFTP connection error, please check details.'; } else { if (@ssh2_auth_password($connection, get_option('cst-ftp-username'), get_option('cst-ftp-password'))) { $this->cdnConnection = $connection; } else { CST_Page::$messages[] = 'SFTP username/password authentication failed, please check details.'; } } } else { $this->cdnConnection = ftp_connect(get_option('cst-ftp-server'), get_option('cst-ftp-port'), 30); if ($this->cdnConnection === false) { CST_Page::$messages[] = 'FTP connection error, please check details.'; } else { if (ftp_login($this->cdnConnection, get_option('cst-ftp-username'), get_option('cst-ftp-password')) === false) { CST_Page::$messages[] = 'FTP login error, please check details.'; } $this->ftpHome = ftp_pwd($this->cdnConnection); } } } else { if ($this->connectionType == 'Cloudfiles') { require_once CST_DIR . '/lib/api/cloudfiles.php'; try { if (get_option('cst-cf-region') == 'uk') { $region = UK_AUTHURL; } else { $region = US_AUTHURL; } $cfAuth = new CF_Authentication(get_option('cst-cf-username'), get_option('cst-cf-api'), NULL, $region); $cfAuth->authenticate(); $this->cdnConnection = new CF_Connection($cfAuth); $this->cdnConnection = $this->cdnConnection->create_container(get_option('cst-cf-container')); } catch (Exception $e) { CST_Page::$messages[] = 'Cloudfiles connection error, please check details.'; } } else { if ($this->connectionType == 'WebDAV') { require_once CST_DIR . 'lib/api/webdav/Sabre/autoload.php'; $settings = array('baseUri' => get_option('cst-webdav-host'), 'userName' => get_option('cst-webdav-username'), 'password' => get_option('cst-webdav-password')); $client = new Sabre_DAV_Client($settings); $response = $client->request('GET'); if ($response['statusCode'] >= 400) { CST_Page::$messages[] = 'WebDAV connection error, server responded with code ' . $response['statusCode'] . '.'; } $this->cdnConnection = $client; } } } } }