diff --git a/solid/lib/Controller/CalendarController.php b/solid/lib/Controller/CalendarController.php index c06bab02..57efbd2b 100644 --- a/solid/lib/Controller/CalendarController.php +++ b/solid/lib/Controller/CalendarController.php @@ -26,7 +26,7 @@ class CalendarController extends Controller { /* @var ISession */ private $session; - + public function __construct( $AppName, IRequest $request, @@ -50,7 +50,7 @@ public function __construct( private function getFileSystem($userId) { // Make sure the root folder has an acl file, as is required by the spec; - // Generate a default file granting the owner full access. + // Generate a default file granting the owner full access. $defaultAcl = $this->generateDefaultAcl($userId); // Create the Nextcloud Calendar Adapter @@ -61,7 +61,11 @@ private function getFileSystem($userId) { // Create Formats objects $formats = new \Pdsinterop\Rdf\Formats(); - $serverUri = "https://" . $this->rawRequest->getServerParams()["SERVER_NAME"] . $this->rawRequest->getServerParams()["REQUEST_URI"]; // FIXME: doublecheck that this is the correct url; + $serverParams = $this->rawRequest->getServerParams(); + $scheme = $serverParams['REQUEST_SCHEME']; + $domain = $serverParams['SERVER_NAME']; + $path = $serverParams['REQUEST_URI']; + $serverUri = "{$scheme}://{$domain}{$path}"; // FIXME: doublecheck that this is the correct url; // Create the RDF Adapter $rdfAdapter = new \Pdsinterop\Rdf\Flysystem\Adapter\Rdf( @@ -74,7 +78,7 @@ private function getFileSystem($userId) { $filesystem = new \League\Flysystem\Filesystem($rdfAdapter); $filesystem->addPlugin(new \Pdsinterop\Rdf\Flysystem\Plugin\AsMime($formats)); - + $plugin = new \Pdsinterop\Rdf\Flysystem\Plugin\ReadRdf($graph); $filesystem->addPlugin($plugin); @@ -122,18 +126,18 @@ private function getCalendarUrl($userId) { * @NoCSRFRequired */ public function handleRequest($userId, $path) { - $this->calendarUserId = $userId; - + $this->calendarUserId = $userId; + $this->rawRequest = \Laminas\Diactoros\ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); $this->response = new \Laminas\Diactoros\Response(); $this->filesystem = $this->getFileSystem($userId); - $this->resourceServer = new ResourceServer($this->filesystem, $this->response); + $this->resourceServer = new ResourceServer($this->filesystem, $this->response); $this->WAC = new WAC($this->filesystem); $request = $this->rawRequest; - $baseUrl = $this->getCalendarUrl($userId); + $baseUrl = $this->getCalendarUrl($userId); $this->resourceServer->setBaseUrl($baseUrl); $this->WAC->setBaseUrl($baseUrl); $notifications = new SolidNotifications(); @@ -148,26 +152,26 @@ public function handleRequest($userId, $path) { ->withStatus(Http::STATUS_CONFLICT, "Invalid token " . $e->getMessage()); return $this->respond($response); } - + if (!$this->WAC->isAllowed($request, $webId)) { $response = $this->resourceServer->getResponse()->withStatus(403, "Access denied"); return $this->respond($response); } - $response = $this->resourceServer->respondToRequest($request); + $response = $this->resourceServer->respondToRequest($request); $response = $this->WAC->addWACHeaders($request, $response, $webId); return $this->respond($response); } - + /** * @PublicPage * @NoAdminRequired * @NoCSRFRequired */ - public function handleGet($userId, $path) { + public function handleGet($userId, $path) { return $this->handleRequest($userId, $path); } - + /** * @PublicPage * @NoAdminRequired @@ -184,7 +188,7 @@ public function handlePost($userId, $path) { public function handlePut() { // $userId, $path) { // FIXME: Adding the correct variables in the function name will make nextcloud // throw an error about accessing put twice, so we will find out the userId and path from $_SERVER instead; - + // because we got here, the request uri should look like: // /index.php/apps/solid/@{userId}/storage{path} $pathInfo = explode("@", $_SERVER['REQUEST_URI']); @@ -192,7 +196,7 @@ public function handlePut() { // $userId, $path) { $userId = $pathInfo[0]; $path = $pathInfo[1]; $path = preg_replace("/^calendar/", "", $path); - + return $this->handleRequest($userId, $path); } /** @@ -239,7 +243,7 @@ private function respond($response) { $result->addHeader($header, $value); } } - + $result->setStatus($statusCode); return $result; } diff --git a/solid/lib/Controller/ContactsController.php b/solid/lib/Controller/ContactsController.php index ff07c425..daf72d52 100644 --- a/solid/lib/Controller/ContactsController.php +++ b/solid/lib/Controller/ContactsController.php @@ -27,7 +27,7 @@ class ContactsController extends Controller /* @var ISession */ private $session; - + public function __construct( $AppName, IRequest $request, @@ -51,7 +51,7 @@ public function __construct( private function getFileSystem($userId) { // Make sure the root folder has an acl file, as is required by the spec; - // Generate a default file granting the owner full access. + // Generate a default file granting the owner full access. $defaultAcl = $this->generateDefaultAcl($userId); // Create the Nextcloud Contacts Adapter @@ -62,7 +62,11 @@ private function getFileSystem($userId) { // Create Formats objects $formats = new \Pdsinterop\Rdf\Formats(); - $serverUri = "https://" . $this->rawRequest->getServerParams()["SERVER_NAME"] . $this->rawRequest->getServerParams()["REQUEST_URI"]; // FIXME: doublecheck that this is the correct url; + $serverParams = $this->rawRequest->getServerParams(); + $scheme = $serverParams['REQUEST_SCHEME']; + $domain = $serverParams['SERVER_NAME']; + $path = $serverParams['REQUEST_URI']; + $serverUri = "{$scheme}://{$domain}{$path}"; // FIXME: doublecheck that this is the correct url; // Create the RDF Adapter $rdfAdapter = new \Pdsinterop\Rdf\Flysystem\Adapter\Rdf( @@ -75,7 +79,7 @@ private function getFileSystem($userId) { $filesystem = new \League\Flysystem\Filesystem($rdfAdapter); $filesystem->addPlugin(new \Pdsinterop\Rdf\Flysystem\Plugin\AsMime($formats)); - + $plugin = new \Pdsinterop\Rdf\Flysystem\Plugin\ReadRdf($graph); $filesystem->addPlugin($plugin); @@ -123,18 +127,18 @@ private function getContactsUrl($userId) { * @NoCSRFRequired */ public function handleRequest($userId, $path) { - $this->contactsUserId = $userId; - + $this->contactsUserId = $userId; + $this->rawRequest = \Laminas\Diactoros\ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); $this->response = new \Laminas\Diactoros\Response(); $this->filesystem = $this->getFileSystem($userId); - $this->resourceServer = new ResourceServer($this->filesystem, $this->response); + $this->resourceServer = new ResourceServer($this->filesystem, $this->response); $this->WAC = new WAC($this->filesystem); $request = $this->rawRequest; - $baseUrl = $this->getContactsUrl($userId); + $baseUrl = $this->getContactsUrl($userId); $this->resourceServer->setBaseUrl($baseUrl); $this->WAC->setBaseUrl($baseUrl); $notifications = new SolidNotifications(); @@ -149,26 +153,26 @@ public function handleRequest($userId, $path) { ->withStatus(Http::STATUS_CONFLICT, "Invalid token " . $e->getMessage()); return $this->respond($response); } - + if (!$this->WAC->isAllowed($request, $webId)) { $response = $this->resourceServer->getResponse()->withStatus(403, "Access denied"); return $this->respond($response); } - $response = $this->resourceServer->respondToRequest($request); + $response = $this->resourceServer->respondToRequest($request); $response = $this->WAC->addWACHeaders($request, $response, $webId); return $this->respond($response); } - + /** * @PublicPage * @NoAdminRequired * @NoCSRFRequired */ - public function handleGet($userId, $path) { + public function handleGet($userId, $path) { return $this->handleRequest($userId, $path); } - + /** * @PublicPage * @NoAdminRequired @@ -185,7 +189,7 @@ public function handlePost($userId, $path) { public function handlePut() { // $userId, $path) { // FIXME: Adding the correct variables in the function name will make nextcloud // throw an error about accessing put twice, so we will find out the userId and path from $_SERVER instead; - + // because we got here, the request uri should look like: // /index.php/apps/solid/@{userId}/storage{path} $pathInfo = explode("@", $_SERVER['REQUEST_URI']); @@ -193,7 +197,7 @@ public function handlePut() { // $userId, $path) { $userId = $pathInfo[0]; $path = $pathInfo[1]; $path = preg_replace("/^contacts/", "", $path); - + return $this->handleRequest($userId, $path); } /** diff --git a/solid/lib/Controller/ProfileController.php b/solid/lib/Controller/ProfileController.php index 67cfc7da..a1ef6bba 100644 --- a/solid/lib/Controller/ProfileController.php +++ b/solid/lib/Controller/ProfileController.php @@ -27,7 +27,7 @@ class ProfileController extends Controller { /* @var ISession */ private $session; - + public function __construct( $AppName, IRequest $request, @@ -54,7 +54,7 @@ public function __construct( private function getFileSystem($userId) { // Make sure the root folder has an acl file, as is required by the spec; - // Generate a default file granting the owner full access. + // Generate a default file granting the owner full access. $defaultAcl = $this->generateDefaultAcl($userId); $profile = $this->generateTurtleProfile($userId); @@ -65,7 +65,11 @@ private function getFileSystem($userId) { // Create Formats objects $formats = new \Pdsinterop\Rdf\Formats(); - $serverUri = "https://" . $this->rawRequest->getServerParams()["SERVER_NAME"] . $this->rawRequest->getServerParams()["REQUEST_URI"]; // FIXME: doublecheck that this is the correct url; + $serverParams = $this->rawRequest->getServerParams(); + $scheme = $serverParams['REQUEST_SCHEME']; + $domain = $serverParams['SERVER_NAME']; + $path = $serverParams['REQUEST_URI']; + $serverUri = "{$scheme}://{$domain}{$path}"; // FIXME: doublecheck that this is the correct url; // Create the RDF Adapter $rdfAdapter = new \Pdsinterop\Rdf\Flysystem\Adapter\Rdf( @@ -78,7 +82,7 @@ private function getFileSystem($userId) { $filesystem = new \League\Flysystem\Filesystem($rdfAdapter); $filesystem->addPlugin(new \Pdsinterop\Rdf\Flysystem\Plugin\AsMime($formats)); - + $plugin = new \Pdsinterop\Rdf\Flysystem\Plugin\ReadRdf($graph); $filesystem->addPlugin($plugin); @@ -93,12 +97,12 @@ private function generateDefaultAcl($userId) { # The profile is readable by the public <#public> - a acl:Authorization; - acl:agentClass foaf:Agent; + a acl:Authorization; + acl:agentClass foaf:Agent; acl:accessTo <./>; acl:default <./>; acl:mode acl:Read. - + # The owner has full access to every resource in their pod. # Other agents have no access rights, # unless specifically authorized in other .acl resources. @@ -139,18 +143,18 @@ private function getStorageUrl($userId) { * @NoCSRFRequired */ public function handleRequest($userId, $path) { - $this->userId = $userId; - + $this->userId = $userId; + $this->rawRequest = \Laminas\Diactoros\ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); $this->response = new \Laminas\Diactoros\Response(); $this->filesystem = $this->getFileSystem($userId); - $this->resourceServer = new ResourceServer($this->filesystem, $this->response); + $this->resourceServer = new ResourceServer($this->filesystem, $this->response); $this->WAC = new WAC($this->filesystem); $request = $this->rawRequest; - $baseUrl = $this->getProfileUrl($userId); + $baseUrl = $this->getProfileUrl($userId); $this->resourceServer->setBaseUrl($baseUrl); $this->WAC->setBaseUrl($baseUrl); $notifications = new SolidNotifications(); @@ -175,20 +179,20 @@ public function handleRequest($userId, $path) { return $this->respond($response); } - $response = $this->resourceServer->respondToRequest($request); + $response = $this->resourceServer->respondToRequest($request); $response = $this->WAC->addWACHeaders($request, $response, $webId); return $this->respond($response); } - + /** * @PublicPage * @NoAdminRequired * @NoCSRFRequired */ - public function handleGet($userId, $path) { + public function handleGet($userId, $path) { return $this->handleRequest($userId, $path); } - + /** * @PublicPage * @NoAdminRequired @@ -205,7 +209,7 @@ public function handlePost($userId, $path) { public function handlePut() { // $userId, $path) { // FIXME: Adding the correct variables in the function name will make nextcloud // throw an error about accessing put twice, so we will find out the userId and path from $_SERVER instead; - + // because we got here, the request uri should look like: // /index.php/apps/solid/@{userId}/storage{path} $pathInfo = explode("@", $_SERVER['REQUEST_URI']); @@ -213,7 +217,7 @@ public function handlePut() { // $userId, $path) { $userId = $pathInfo[0]; $path = $pathInfo[1]; $path = preg_replace("/^profile/", "", $path); - + return $this->handleRequest($userId, $path); } /** @@ -318,9 +322,9 @@ private function generateTurtleProfile($userId) { @prefix inbox: <>. @prefix sp: . @prefix ser: <>. - + pro:card a foaf:PersonalProfileDocument; foaf:maker :me; foaf:primaryTopic :me. - + :me a schem:Person, foaf:Person; ldp:inbox inbox:; diff --git a/solid/lib/Controller/StorageController.php b/solid/lib/Controller/StorageController.php index 36f68513..a16ff5ac 100644 --- a/solid/lib/Controller/StorageController.php +++ b/solid/lib/Controller/StorageController.php @@ -63,7 +63,11 @@ private function getFileSystem() { // Create Formats objects $formats = new \Pdsinterop\Rdf\Formats(); - $serverUri = "https://" . $this->rawRequest->getServerParams()["SERVER_NAME"] . $this->rawRequest->getServerParams()["REQUEST_URI"]; // FIXME: doublecheck that this is the correct url; + $serverParams = $this->rawRequest->getServerParams(); + $scheme = $serverParams['REQUEST_SCHEME']; + $domain = $serverParams['SERVER_NAME']; + $path = $serverParams['REQUEST_URI']; + $serverUri = "{$scheme}://{$domain}{$path}"; // FIXME: doublecheck that this is the correct url; // Create the RDF Adapter $rdfAdapter = new \Pdsinterop\Rdf\Flysystem\Adapter\Rdf( @@ -76,7 +80,7 @@ private function getFileSystem() { $filesystem = new \League\Flysystem\Filesystem($rdfAdapter); $filesystem->addPlugin(new \Pdsinterop\Rdf\Flysystem\Plugin\AsMime($formats)); - + $plugin = new \Pdsinterop\Rdf\Flysystem\Plugin\ReadRdf($graph); $filesystem->addPlugin($plugin); @@ -131,11 +135,11 @@ private function generatePublicAppendAcl($userId) { @prefix foaf: . <#public> - a acl:Authorization; - acl:agentClass foaf:Agent; - acl:accessTo <./>; - acl:default <./>; - acl:mode + a acl:Authorization; + acl:agentClass foaf:Agent; + acl:accessTo <./>; + acl:default <./>; + acl:mode acl:Append. <#owner> @@ -299,7 +303,7 @@ public function handleRequest($userId, $path) { $this->WAC = new WAC($this->filesystem); $request = $this->rawRequest; - $baseUrl = $this->getStorageUrl($userId); + $baseUrl = $this->getStorageUrl($userId); $this->resourceServer->setBaseUrl($baseUrl); $this->WAC->setBaseUrl($baseUrl); @@ -347,20 +351,20 @@ public function handleRequest($userId, $path) { ->withStatus(403, "Access denied"); return $this->respond($response); } - $response = $this->resourceServer->respondToRequest($request); + $response = $this->resourceServer->respondToRequest($request); $response = $this->WAC->addWACHeaders($request, $response, $webId); return $this->respond($response); } - + /** * @PublicPage * @NoAdminRequired * @NoCSRFRequired */ - public function handleGet($userId, $path) { + public function handleGet($userId, $path) { return $this->handleRequest($userId, $path); } - + /** * @PublicPage * @NoAdminRequired @@ -377,7 +381,7 @@ public function handlePost($userId, $path) { public function handlePut() { // $userId, $path) { // FIXME: Adding the correct variables in the function name will make nextcloud // throw an error about accessing put twice, so we will find out the userId and path from $_SERVER instead; - + // because we got here, the request uri should look like: // /index.php/apps/solid/@{userId}/storage{path} $pathInfo = explode("@", $_SERVER['REQUEST_URI']); @@ -385,7 +389,7 @@ public function handlePut() { // $userId, $path) { $userId = $pathInfo[0]; $path = $pathInfo[1]; $path = preg_replace("/^storage/", "", $path); - + return $this->handleRequest($userId, $path); } /** @@ -430,20 +434,20 @@ private function respond($response) { // $result->addHeader('Access-Control-Allow-Credentials', 'true'); // $result->addHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization'); // $result->addHeader('Access-Control-Allow-Origin', $origin); - - $policy = new EmptyContentSecurityPolicy(); - $policy->addAllowedStyleDomain("*"); - $policy->addAllowedStyleDomain("data:"); - $policy->addAllowedScriptDomain("*"); - $policy->addAllowedImageDomain("*"); - $policy->addAllowedFontDomain("*"); - $policy->addAllowedConnectDomain("*"); - $policy->allowInlineStyle(true); - // $policy->allowInlineScript(true); - removed, this function no longer exists in NC28 - $policy->allowEvalScript(true); - $result->setContentSecurityPolicy($policy); - - $result->setStatus($statusCode); + + $policy = new EmptyContentSecurityPolicy(); + $policy->addAllowedStyleDomain("*"); + $policy->addAllowedStyleDomain("data:"); + $policy->addAllowedScriptDomain("*"); + $policy->addAllowedImageDomain("*"); + $policy->addAllowedFontDomain("*"); + $policy->addAllowedConnectDomain("*"); + $policy->allowInlineStyle(true); + // $policy->allowInlineScript(true); - removed, this function no longer exists in NC28 + $policy->allowEvalScript(true); + $result->setContentSecurityPolicy($policy); + + $result->setStatus($statusCode); return $result; } }