diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-12-04 19:51:04 +0100 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-12-19 15:20:24 +0100 |
commit | 24993280edcf66f9daa5a5e82428fefef4a3ab56 (patch) | |
tree | ede7ca0417af874185588a845fe5f7f754076f60 /lib/private/httphelper.php | |
parent | f671b232cc122cdb8e993c8b35bd5419b32a9ae4 (diff) | |
download | nextcloud-server-24993280edcf66f9daa5a5e82428fefef4a3ab56.tar.gz nextcloud-server-24993280edcf66f9daa5a5e82428fefef4a3ab56.zip |
Next step in server-to-server sharing next generation, see #12285
Beside some small improvements and bug fixes this will probably the final state for OC8.
To test this you need to set up two ownCloud instances. Let's say:
URL: myPC/firstOwnCloud user: user1
URL: myPC/secondOwnCloud user: user2
Now user1 can share a file with user2 by entering the username and the URL to the second ownCloud to the share-drop-down, in this case "user2@myPC/secondOwnCloud".
The next time user2 login he will get a notification that he received a server-to-server share with the option to accept/decline it. If he accept it the share will be mounted. In both cases a event will be send back to user1 and add a notification to the activity stream that the share was accepted/declined.
If user1 decides to unshare the file again from user2 the share will automatically be removed from the second ownCloud server and user2 will see a notification in his activity stream that user1@myPC/firstOwnCloud has unshared the file/folder from him.
Diffstat (limited to 'lib/private/httphelper.php')
-rw-r--r-- | lib/private/httphelper.php | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/lib/private/httphelper.php b/lib/private/httphelper.php index 846825dee8d..1f3482b3514 100644 --- a/lib/private/httphelper.php +++ b/lib/private/httphelper.php @@ -8,7 +8,8 @@ namespace OC; -use \OCP\IConfig; +use OCP\IConfig; +use OCP\ICertificateManager; class HTTPHelper { const USER_AGENT = 'ownCloud Server Crawler'; @@ -16,11 +17,15 @@ class HTTPHelper { /** @var \OCP\IConfig */ private $config; + /** @var \OC\Security\CertificateManager */ + private $certificateManager; + /** * @param \OCP\IConfig $config */ - public function __construct(IConfig $config) { + public function __construct(IConfig $config, ICertificateManager $certificateManager) { $this->config = $config; + $this->certificateManager = $certificateManager; } /** @@ -176,4 +181,50 @@ class HTTPHelper { return $location; } + /** + * create string of parameters for post request + * + * @param array $parameters + * @return string + */ + private function assemblePostParameters(array $parameters) { + $parameterString = ''; + foreach ($parameters as $key => $value) { + $parameterString .= $key . '=' . urlencode($value) . '&'; + } + + return rtrim($parameterString, '&'); + } + + /** + * send http post request + * + * @param string $url + * @param array $fields data send by the request + * @return bool + */ + public function post($url, array $fields) { + + $fieldsString = $this->assemblePostParameters($fields); + + $certBundle = $this->certificateManager->getCertificateBundle(); + + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_POST, count($fields)); + curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsString); + if (is_readable($certBundle)) { + curl_setopt($ch, CURLOPT_CAINFO, $certBundle); + } + + $result = curl_exec($ch); + $success = $result ? true : false; + + curl_close($ch); + + return array('success' => $success, 'result' => $result); + } + } |