Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use request scheme in server url #121

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions solid/lib/Controller/CalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CalendarController extends Controller {

/* @var ISession */
private $session;

public function __construct(
$AppName,
IRequest $request,
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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);

Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -184,15 +188,15 @@ 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']);
$pathInfo = explode("/", $pathInfo[1], 2);
$userId = $pathInfo[0];
$path = $pathInfo[1];
$path = preg_replace("/^calendar/", "", $path);

return $this->handleRequest($userId, $path);
}
/**
Expand Down Expand Up @@ -239,7 +243,7 @@ private function respond($response) {
$result->addHeader($header, $value);
}
}

$result->setStatus($statusCode);
return $result;
}
Expand Down
34 changes: 19 additions & 15 deletions solid/lib/Controller/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ContactsController extends Controller

/* @var ISession */
private $session;

public function __construct(
$AppName,
IRequest $request,
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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);

Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -185,15 +189,15 @@ 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']);
$pathInfo = explode("/", $pathInfo[1], 2);
$userId = $pathInfo[0];
$path = $pathInfo[1];
$path = preg_replace("/^contacts/", "", $path);

return $this->handleRequest($userId, $path);
}
/**
Expand Down
42 changes: 23 additions & 19 deletions solid/lib/Controller/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ProfileController extends Controller {

/* @var ISession */
private $session;

public function __construct(
$AppName,
IRequest $request,
Expand All @@ -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);

Expand All @@ -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(
Expand All @@ -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);

Expand All @@ -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.
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -205,15 +209,15 @@ 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']);
$pathInfo = explode("/", $pathInfo[1], 2);
$userId = $pathInfo[0];
$path = $pathInfo[1];
$path = preg_replace("/^profile/", "", $path);

return $this->handleRequest($userId, $path);
}
/**
Expand Down Expand Up @@ -318,9 +322,9 @@ private function generateTurtleProfile($userId) {
@prefix inbox: <<?php echo $profile['inbox']; ?>>.
@prefix sp: <http://www.w3.org/ns/pim/space#>.
@prefix ser: <<?php echo $profile['storage']; ?>>.

pro:card a foaf:PersonalProfileDocument; foaf:maker :me; foaf:primaryTopic :me.

:me
a schem:Person, foaf:Person;
ldp:inbox inbox:;
Expand Down
Loading
Loading