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

Set up a php oc10 controller for reading the config.json from the config folder #4537

Merged
merged 17 commits into from
Jan 5, 2021
Merged
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
6 changes: 4 additions & 2 deletions Makefile.release
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ copy-configs: copy-web-config copy-htaccess

.PHONY: copy-web-config
copy-web-config:
cp config.json.dist $(dist_dir)/config.json
cp config.json.dist $(dist_dir)/

.Phony: copy-htaccess
copy-htaccess:
cp .htaccess $(dist_dir)
cp .htaccess $(dist_dir)/

.PHONY: package
package: create-release-folder create-packages
Expand Down Expand Up @@ -78,6 +78,8 @@ endif
ocx-app-config:
cp -R appinfo $(dist_dir)
cp -R img $(dist_dir)
cp -R lib $(dist_dir)
rm $(dist_dir)/.htaccess # .htaccess is not needed/read in ocx app deployment scenarios

.PHONY: ocx-app-bundle
ocx-app-bundle:
Expand Down
22 changes: 22 additions & 0 deletions appinfo/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* @author Benedikt Kulmann <[email protected]>
*
* @copyright Copyright (c) 2020, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

$app = new OCA\Web\Application();
39 changes: 39 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* @author Benedikt Kulmann <[email protected]>
*
* @copyright Copyright (c) 2020, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

use OCA\Web\Application;

$app = new Application();
$app->registerRoutes(
$this,
[
'routes' => [
['name' => 'Config#getConfig', 'url' => '/config.json', 'verb' => 'GET'],
[
'name' => 'Files#getFile',
'url' => '/{path}',
'verb' => 'GET',
'requirements' => ['path' => '.+'],
'defaults' => ['path' => 'index.html']
]
]
]
);
6 changes: 6 additions & 0 deletions changelog/unreleased/oc10-app-controllers
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Change: Add controllers for oc10 app deployment

We added a config endpoint for when ownCloud Web is deployed as ownCloud 10 app. The config.json file must not be placed in the apps folder because it would cause the app integrity check to fail.
In addition to the config endpoint we added a wildcard endpoint for serving static assets (js bundles, css, etc) of the ownCloud Web javascript application by their paths.

https://github.com/owncloud/web/pull/4537
40 changes: 25 additions & 15 deletions docs/deployments/oc10-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ geekdocFilePath: oc10-app.md
{{< toc >}}

The ownCloud Web is being deployed as an app to [ownCloud marketplace](https://market.owncloud.com) to enable easy early integration into existing ownCloud 10 instances.
After completing this setup, ownCloud Web will be available on `https://<your-owncloud-server>/apps-external/web`.

{{< hint info >}}
Depending on your setup, the name of `apps-external` folder can vary. It is important to use the correct name in all of the mentioned URLs.
{{< /hint >}}
After completing this setup, ownCloud Web will be available on `https://<your-owncloud-server>/index.php/apps/web`.

## Prerequisites
- Running [ownCloud 10 server](https://owncloud.com/download-server/) with version 10.6
Expand All @@ -24,34 +20,34 @@ Depending on your setup, the name of `apps-external` folder can vary. It is impo
Download [ownCloud Web app](https://marketplace.owncloud.com/apps/web) from the marketplace and enable it.

## Configure oauth2
In the `Admin` of ownCloud 10, head into `User Authentication` and add a new client with arbitrary name and redirection URL `https://<your-owncloud-server>/apps-external/web/oidc-callback.html`.
Within the `Admin` page of ownCloud 10, head into `User Authentication` and add a new client with arbitrary name (e.g. `ownCloud Web`) and redirection URL `https://<your-owncloud-server>/index.php/apps/web/oidc-callback.html`.

{{< figure src="/clients/web/static/oauth2.jpg" alt="Example OAuth2 entry" >}}

## Configure ownCloud 10
To display ownCloud Web in the app switcher and to redirect all private and public links to the new WebUI, add the following config into `config/config.php`:

```php
'web.baseUrl' => 'https://<your-owncloud-server>/apps-external/web',
'web.baseUrl' => 'https://<your-owncloud-server>/index.php/apps/web',
```
## Configure ownCloud Web
There are a few config values which need to be set in order for ownCloud Web to work correctly. Navigate into `apps-external/web` and adjust `config.json` according to the following example:
There are a few config values which need to be set in order for ownCloud Web to work correctly. Please copy `config.json.dist` from the web app directory into `config/config.json` and adjust it according to the following example:

```json
{
"server" : "https://<your-owncloud-server>", // ownCloud 10 server address
"theme": "owncloud", // Theme to be used in ownCloud Web pointing to a json file inside of `themes` folder
"server" : "https://<your-owncloud-server>",
"theme": "owncloud",
"auth": {
"clientId": "<client-id-from-oauth2>", // Client ID received when adding ownCloud Web in the `User Authentication` section in `Admin`
"clientId": "<client-id-from-oauth2>",
"url": "https://<your-owncloud-server>/index.php/apps/oauth2/api/v1/token",
"authUrl": "https://<your-owncloud-server>/index.php/apps/oauth2/authorize"
},
"apps" : [ // List of extensions to be loaded
"apps" : [
"files"
],
"applications" : [ // Apps to be displayed in the application switcher or in the user menu
"applications" : [
{
"title": { // Item in apps switcher pointing to the old ownCloud UI
"title": {
"en": "Classic Design",
"de": "Dateien",
"fr": "Fichiers",
Expand All @@ -60,7 +56,7 @@ There are a few config values which need to be set in order for ownCloud Web to
"icon": "switch_ui",
"url": "http://<your-owncloud-server>/index.php/apps/files"
},
{ // Item in user menu pointing to user settings in the old ownCloud UI
{
"icon": "application",
"menu": "user",
"target": "_self",
Expand All @@ -74,6 +70,20 @@ There are a few config values which need to be set in order for ownCloud Web to
}
```

|config parameter|explanation|
|---|---|
|server|ownCloud 10 server address|
|theme|Theme to be used in ownCloud Web pointing to a json file inside of `themes` folder|
|auth.clientId|Client ID received when adding ownCloud Web in the `User Authentication` section in `Admin`|
|apps|List of internal extensions to be loaded|
|applications|Additional apps and links to be displayed in the application switcher or in the user menu|
|applications[0].title|Visible title in the application switcher or user menu, localizable|
|applications[1].menu|Use `user` to move the menu item into the user menu. Defaults to app switcher|

{{< hint info >}}
It is important that you don't edit or place the `config.json` within the app folder. If you do, the integrity check of the app will fail and raise warnings.
{{< /hint >}}

## Accessing ownCloud Web
After following all the steps, you should see a new entry in the application switcher called `New Design` which points to the ownCloud web.

Expand Down
36 changes: 36 additions & 0 deletions lib/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* @author Benedikt Kulmann <[email protected]>
*
* @copyright Copyright (c) 2020, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\Web;

use OCP\AppFramework\App;

class Application extends App {

const APPID = 'web';

/**
* @param array $urlParams
*/
public function __construct(array $urlParams = []) {
parent::__construct(Application::APPID, $urlParams);
}
}
78 changes: 78 additions & 0 deletions lib/Controller/ConfigController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* @author Benedikt Kulmann <[email protected]>
*
* @copyright Copyright (c) 2020, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\Web\Controller;

use OC\AppFramework\Http;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\ILogger;
use OCP\IRequest;

/**
* Class ConfigController
*
* @package OCA\Web\Controller
*/
class ConfigController extends Controller {

/**
* @var ILogger
*/
private $logger;

/**
* ConfigController constructor.
*
* @param string $appName
* @param IRequest $request
* @param ILogger $logger
*/
public function __construct(string $appName, IRequest $request, ILogger $logger) {
parent::__construct($appName, $request);
$this->logger = $logger;
}

/**
* Loads the config json file for ownCloud Web
*
* @PublicPage
* @NoCSRFRequired
*
* @return JSONResponse
*/
public function getConfig(): JSONResponse {
try {
$configFile = \OC::$SERVERROOT . '/config/config.json';
$configContent = \file_get_contents($configFile);
$configAssoc = \json_decode($configContent, true);
$response = new JSONResponse($configAssoc);
$response->addHeader('Cache-Control', 'max-age=0, no-cache, no-store, must-revalidate');
$response->addHeader('Pragma', 'no-cache');
$response->addHeader('Expires', 'Wed, 11 Jan 1984 05:00:00 GMT');
$response->addHeader('X-Frame-Options', 'DENY');
return $response;
} catch(\Exception $e) {
$this->logger->logException($e, ['app' => 'web']);
return new JSONResponse(["message" => $e->getMessage()], Http::STATUS_NOT_FOUND);
}
}
}
Loading