Skip to content
Snippets Groups Projects
Commit c0e5c74e authored by Rasmus Fuhse's avatar Rasmus Fuhse
Browse files

fix OwnCloud apache problem

parent 4dd04817
No related branches found
No related tags found
No related merge requests found
...@@ -47,7 +47,7 @@ class OwnCloudPlugin extends StudIPPlugin implements FilesystemPlugin { ...@@ -47,7 +47,7 @@ class OwnCloudPlugin extends StudIPPlugin implements FilesystemPlugin {
$header = array(); $header = array();
$header[] = "Authorization: Bearer ".\Owncloud\OAuth::getAccessToken(); $header[] = OwnCloudFolder::getAuthHeader();
$r = curl_init(); $r = curl_init();
curl_setopt($r, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($r, CURLOPT_CUSTOMREQUEST, "GET");
...@@ -117,7 +117,7 @@ class OwnCloudPlugin extends StudIPPlugin implements FilesystemPlugin { ...@@ -117,7 +117,7 @@ class OwnCloudPlugin extends StudIPPlugin implements FilesystemPlugin {
$header = array(); $header = array();
$header[] = "Authorization: Bearer ".\Owncloud\OAuth::getAccessToken(); $header[] = OwnCloudFolder::getAuthHeader();
$r = curl_init(); $r = curl_init();
curl_setopt($r, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($r, CURLOPT_CUSTOMREQUEST, "GET");
...@@ -177,7 +177,7 @@ class OwnCloudPlugin extends StudIPPlugin implements FilesystemPlugin { ...@@ -177,7 +177,7 @@ class OwnCloudPlugin extends StudIPPlugin implements FilesystemPlugin {
} }
$webdav = $url . "remote.php/webdav/"; $webdav = $url . "remote.php/webdav/";
$header = array(); $header = array();
$header[] = "Authorization: Bearer ".\Owncloud\OAuth::getAccessToken(); $header[] = OwnCloudFolder::getAuthHeader();
$r = curl_init(); $r = curl_init();
curl_setopt($r, CURLOPT_CUSTOMREQUEST, "PROPFIND"); curl_setopt($r, CURLOPT_CUSTOMREQUEST, "PROPFIND");
curl_setopt($r, CURLOPT_URL, $webdav."/".$id); curl_setopt($r, CURLOPT_URL, $webdav."/".$id);
......
...@@ -13,7 +13,7 @@ class OAuth { ...@@ -13,7 +13,7 @@ class OAuth {
throw new Exception("No valid access token. Please refresh you connection to Owncloud."); throw new Exception("No valid access token. Please refresh you connection to Owncloud.");
} }
$header[] = "Authorization: Bearer ".$accessToken; $header[] = OwnCloudFolder::getAuthHeader();
$r = curl_init(); $r = curl_init();
curl_setopt($r, CURLOPT_URL, $url); curl_setopt($r, CURLOPT_URL, $url);
......
...@@ -48,7 +48,7 @@ class OwncloudFolder extends VirtualFolderType { ...@@ -48,7 +48,7 @@ class OwncloudFolder extends VirtualFolderType {
$webdav = $this->getWebDavURL(); $webdav = $this->getWebDavURL();
$header = array(); $header = array();
$header[] = "Authorization: Bearer ".\Owncloud\OAuth::getAccessToken(); $header[] = self::getAuthHeader();
$header[] = "Destination: ". $webdav . $this->id; $header[] = "Destination: ". $webdav . $this->id;
$r = curl_init(); $r = curl_init();
...@@ -76,7 +76,7 @@ class OwncloudFolder extends VirtualFolderType { ...@@ -76,7 +76,7 @@ class OwncloudFolder extends VirtualFolderType {
$webdav = $this->getWebDavURL(); $webdav = $this->getWebDavURL();
$header = array(); $header = array();
$header[] = "Authorization: Bearer ".\Owncloud\OAuth::getAccessToken(); $header[] = self::getAuthHeader();
$r = curl_init(); $r = curl_init();
curl_setopt($r, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_setopt($r, CURLOPT_CUSTOMREQUEST, "DELETE");
...@@ -111,7 +111,7 @@ class OwncloudFolder extends VirtualFolderType { ...@@ -111,7 +111,7 @@ class OwncloudFolder extends VirtualFolderType {
$file_ref_id = $this->id . (mb_strlen($this->id) ? '/' : '') . rawurlencode($filedata['name']); $file_ref_id = $this->id . (mb_strlen($this->id) ? '/' : '') . rawurlencode($filedata['name']);
$header = array(); $header = array();
$header[] = "Authorization: Bearer ".\Owncloud\OAuth::getAccessToken(); $header[] = self::getAuthHeader();
$url_template = "[InternetShortcut]\nURL=%s"; $url_template = "[InternetShortcut]\nURL=%s";
if (is_a($filedata, "File")) { if (is_a($filedata, "File")) {
...@@ -174,7 +174,7 @@ class OwncloudFolder extends VirtualFolderType { ...@@ -174,7 +174,7 @@ class OwncloudFolder extends VirtualFolderType {
$destination = $this->id . (mb_strlen($this->id) ? '/' : '') . rawurlencode($name); $destination = $this->id . (mb_strlen($this->id) ? '/' : '') . rawurlencode($name);
$header = array(); $header = array();
$header[] = "Authorization: Bearer ".\Owncloud\OAuth::getAccessToken(); $header[] = self::getAuthHeader();
$header[] = "Destination: ". $webdav . $destination; $header[] = "Destination: ". $webdav . $destination;
$r = curl_init(); $r = curl_init();
...@@ -215,7 +215,7 @@ class OwncloudFolder extends VirtualFolderType { ...@@ -215,7 +215,7 @@ class OwncloudFolder extends VirtualFolderType {
$destination = $this->id . (mb_strlen($this->id)?'/':'') . rawurlencode($name); $destination = $this->id . (mb_strlen($this->id)?'/':'') . rawurlencode($name);
$header = array(); $header = array();
$header[] = "Authorization: Bearer ".\Owncloud\OAuth::getAccessToken(); $header[] = self::getAuthHeader();
$header[] = "Destination: ". $webdav . $destination; $header[] = "Destination: ". $webdav . $destination;
$r = curl_init(); $r = curl_init();
...@@ -256,7 +256,7 @@ class OwncloudFolder extends VirtualFolderType { ...@@ -256,7 +256,7 @@ class OwncloudFolder extends VirtualFolderType {
$destination = $this->id . (mb_strlen($this->id)?'/':'') . rawurlencode($name); $destination = $this->id . (mb_strlen($this->id)?'/':'') . rawurlencode($name);
$header = array(); $header = array();
$header[] = "Authorization: Bearer ".\Owncloud\OAuth::getAccessToken(); $header[] = self::getAuthHeader();
$header[] = "Destination: ". $webdav . $destination; $header[] = "Destination: ". $webdav . $destination;
$r = curl_init(); $r = curl_init();
...@@ -295,7 +295,7 @@ class OwncloudFolder extends VirtualFolderType { ...@@ -295,7 +295,7 @@ class OwncloudFolder extends VirtualFolderType {
$destination = $this->id . (mb_strlen($this->id)?'/':'') . $name; $destination = $this->id . (mb_strlen($this->id)?'/':'') . $name;
$header = array(); $header = array();
$header[] = "Authorization: Bearer ".\Owncloud\OAuth::getAccessToken(); $header[] = self::getAuthHeader();
$r = curl_init(); $r = curl_init();
...@@ -332,7 +332,7 @@ class OwncloudFolder extends VirtualFolderType { ...@@ -332,7 +332,7 @@ class OwncloudFolder extends VirtualFolderType {
$header = array(); $header = array();
$header[] = "Authorization: Bearer ".\Owncloud\OAuth::getAccessToken(); $header[] = self::getAuthHeader();
$header[] = "Depth: 1"; $header[] = "Depth: 1";
$r = curl_init(); $r = curl_init();
...@@ -355,6 +355,14 @@ class OwncloudFolder extends VirtualFolderType { ...@@ -355,6 +355,14 @@ class OwncloudFolder extends VirtualFolderType {
$doc = new DOMDocument(); $doc = new DOMDocument();
$doc->loadXML($xml); $doc->loadXML($xml);
foreach ($doc->getElementsByTagNameNS("DAV:", "error") as $error) {
foreach ($error->childNodes as $node) {
if (strtolower($node->tagName) === "s:message") {
PageLayout::postError($node->nodeValue);
}
}
}
foreach ($doc->getElementsByTagNameNS("DAV:","response") as $file) { foreach ($doc->getElementsByTagNameNS("DAV:","response") as $file) {
//response //response
// -> href // -> href
...@@ -393,7 +401,7 @@ class OwncloudFolder extends VirtualFolderType { ...@@ -393,7 +401,7 @@ class OwncloudFolder extends VirtualFolderType {
if ($prop->childNodes) { if ($prop->childNodes) {
foreach ($prop->childNodes as $attr) { foreach ($prop->childNodes as $attr) {
if (strtolower($attr->tagName) === "d:resourcetype") { if (strtolower($attr->tagName) === "d:resourcetype") {
$file_attributes['type'] = $attr->childNodes[0] && strtolower($attr->childNodes[0]->tagName) === "d:collection" ? "folder" : "file"; $file_attributes['type'] = $attr->childNodes->item(0) && strtolower($attr->childNodes->item(0)->tagName) === "d:collection" ? "folder" : "file";
} }
if (strtolower($attr->tagName) === "d:getcontentlength") { if (strtolower($attr->tagName) === "d:getcontentlength") {
$file_attributes['size'] = $attr->nodeValue; $file_attributes['size'] = $attr->nodeValue;
...@@ -433,7 +441,7 @@ class OwncloudFolder extends VirtualFolderType { ...@@ -433,7 +441,7 @@ class OwncloudFolder extends VirtualFolderType {
'mime_type' => $content_type, 'mime_type' => $content_type,
'description' => "", 'description' => "",
'chdate' => $file_attributes['chdate'], 'chdate' => $file_attributes['chdate'],
'download_url' => URLHelper::getURL("plugins.php/owncloudplugin/download/" . ($this->id ? $this->id . "/" : "") . $file_attributes['name']) 'download_url' => URLHelper::getURL("plugins.php/owncloudplugin/download/" . ($this->id ? $this->id . "/" : "") . rawurlencode($file_attributes['name']))
); );
} }
} }
...@@ -466,7 +474,7 @@ class OwncloudFolder extends VirtualFolderType { ...@@ -466,7 +474,7 @@ class OwncloudFolder extends VirtualFolderType {
$this->folderdata['id'] = $request['name']; $this->folderdata['id'] = $request['name'];
} else { } else {
$this->folderdata['id'] = $request['parent_id'] . '/' . $request['name']; $this->folderdata['id'] = $request['parent_id'] . '/' . $request['name'];
} }
$this->folderdata['parent_id'] = $request['parent_id']; $this->folderdata['parent_id'] = $request['parent_id'];
$this->folderdata['range_type'] = $plugin->getPluginId(); $this->folderdata['range_type'] = $plugin->getPluginId();
$this->folderdata['range_id'] = $plugin->getPluginName(); $this->folderdata['range_id'] = $plugin->getPluginName();
...@@ -503,4 +511,8 @@ class OwncloudFolder extends VirtualFolderType { ...@@ -503,4 +511,8 @@ class OwncloudFolder extends VirtualFolderType {
return false; return false;
} }
static public function getAuthHeader() {
return "Authorization: Bearer " . \Owncloud\OAuth::getAccessToken();
}
} }
...@@ -6,7 +6,7 @@ class InitPlugin extends Migration { ...@@ -6,7 +6,7 @@ class InitPlugin extends Migration {
foreach ($configs as $config) { foreach ($configs as $config) {
Config::get()->create($config, array( Config::get()->create($config, array(
'value' => "", 'value' => "",
'type' => $config === "OWNCLOUD_ACTIVATED" ? "boolean" : "string", 'type' => in_array($config, ["OWNCLOUD_ACTIVATED"]) ? "boolean" : "string",
'range' => "user", 'range' => "user",
'section' => "Owncloud" 'section' => "Owncloud"
)); ));
......
...@@ -35,4 +35,7 @@ Die n ...@@ -35,4 +35,7 @@ Die n
5. Die OwnCloud fragt Sie, ob Stud.IP in Ihrem Namen Daten abrufen und verändern darf. Klicken Sie auf "Authorisieren". 5. Die OwnCloud fragt Sie, ob Stud.IP in Ihrem Namen Daten abrufen und verändern darf. Klicken Sie auf "Authorisieren".
6. Jetzt landen Sie wieder in Stud.IP und die Schnittstelle zwischen Stud.IP und OwnCloud sollte eingerichtet sein. 6. Jetzt landen Sie wieder in Stud.IP und die Schnittstelle zwischen Stud.IP und OwnCloud sollte eingerichtet sein.
Probleme?
* Manchmal scheint fast alles zu funktionieren. OAuth-Access-Token ist da, Refresh-Token ist da und der Refresh scheint auch zu klappen, aber es werden keine Dateien und Ordner angezeigt. Es erscheint stattdessen eine Fehlermeldung: "No 'Authorization: Basic' header found. Either the client didn't send one, or the server is misconfigured, No 'Authorization: Basic' header found. Either the client didn't send one, or the server is misconfigured, No 'Authorization: Bearer' header found. Either the client didn't send one, or the server is mis-configured". In dem Fall muss man vermutlich in die Datei .htacess die Zeile einbauen `SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1`
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment