Skip to content

Commit

Permalink
Merge pull request #61 from ONLYOFFICE/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
LinneyS authored May 11, 2017
2 parents c7aeefe + ac14548 commit 92ad85c
Show file tree
Hide file tree
Showing 45 changed files with 479 additions and 45 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log

## 1.0.4
### Added
- advanced server settings for specifying internal addresses
- opening file editor in a same tab

### Changed
- setting default aplication for editable formats
- new file on user language
- compatible with Nextcloud 12

## 1.0.3
- compatible with ownCloud 10

Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@ git clone https://github.com/ONLYOFFICE/onlyoffice-owncloud.git onlyoffice

## Configuring ownCloud/Nextcloud ONLYOFFICE integration app

In ownCloud/Nextcloud open the `~/index.php/settings/admin#onlyoffice` page with administrative settings for **ONLYOFFICE** section and enter the address
In ownCloud/Nextcloud open the `~/index.php/settings/admin#onlyoffice` page with administrative settings for **ONLYOFFICE** section. Enter the following address to connect ONLYOFFICE Document Server:

```
https://<documentserver>
```

Where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed.
Where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed. The address must be accessible for the user browser and from the ownCloud/Nextcloud server. The ownCloud/Nextcloud server address must also be accessible from ONLYOFFICE Document Server for correct work.

Sometimes your network configuration might not allow the requests between installed ownCloud/Nextcloud and ONLYOFFICE Document Server using the public addresses. The _Advanced server settings_ allows to set the ONLYOFFICE Document Server address for internal requests from ownCloud/Nextcloud server and the returning ownCloud/Nextcloud address for the internal requests from ONLYOFFICE Document Server. You need to enter them in the appropriate fields.

To restrict the access to ONLYOFFICE Document Server and for security reasons and data integrity the encrypted signature is used. Specify the _Secret key_ in the ownCloud/Nextcloud administrative configuration. In the ONLYOFFICE Document Server [config file](https://api.onlyoffice.com/editors/signature/) specify the same secret key and enable the validation.

Enable or disable the _Open file in the same tab_ setting.

The **Open in ONLYOFFICE** action will be added to the file context menu. You can specify this action as default and it will be used when the file name is clicked for the selected file types.



Expand Down
10 changes: 8 additions & 2 deletions appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,21 @@ public function __construct(array $urlParams = []) {
return $c->query("ServerContainer")->getLogger();
});

$container->registerService("URLGenerator", function($c) {
return $c->query("ServerContainer")->getURLGenerator();
});


// Controllers
$container->registerService("SettingsController", function($c) {
return new SettingsController(
$c->query("AppName"),
$c->query("Request"),
$c->query("URLGenerator"),
$c->query("L10N"),
$c->query("Logger"),
$this->appConfig
$this->appConfig,
$this->crypt
);
});

Expand All @@ -111,7 +117,7 @@ public function __construct(array $urlParams = []) {
$c->query("Request"),
$c->query("RootStorage"),
$c->query("UserSession"),
$c->query("ServerContainer")->getURLGenerator(),
$c->query("URLGenerator"),
$c->query("L10N"),
$c->query("Logger"),
$this->appConfig,
Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<screenshot>https://raw.githubusercontent.com/ONLYOFFICE/onlyoffice-owncloud/master/screenshots/settings.png</screenshot>
<dependencies>
<owncloud min-version="9.0" max-version="10.0" />
<nextcloud min-version="11" max-version="11"/>
<nextcloud min-version="11" max-version="12"/>
</dependencies>
<settings>
<admin>OCA\Onlyoffice\AdminSettings</admin>
Expand Down
5 changes: 3 additions & 2 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
return [
"routes" => [
["name" => "callback#download", "url" => "/download", "verb" => "GET"],
["name" => "callback#emptyfile", "url" => "/empty", "verb" => "GET"],
["name" => "callback#track", "url" => "/track", "verb" => "POST"],
["name" => "editor#index", "url" => "/{fileId}", "verb" => "GET"],
["name" => "editor#config", "url" => "/ajax/config/{fileId}", "verb" => "GET"],
["name" => "editor#create", "url" => "/ajax/new", "verb" => "POST"],
["name" => "editor#convert", "url" => "/ajax/convert", "verb" => "POST"],
["name" => "settings#settings", "url" => "/ajax/settings", "verb" => "PUT"],
["name" => "settings#formats", "url" => "/ajax/settings", "verb" => "GET"],
["name" => "settings#save_settings", "url" => "/ajax/settings", "verb" => "PUT"],
["name" => "settings#get_settings", "url" => "/ajax/settings", "verb" => "GET"],
]
];
Binary file added assets/az/new.docx
Binary file not shown.
File renamed without changes.
Binary file added assets/az/new.xlsx
Binary file not shown.
Binary file added assets/de/new.docx
Binary file not shown.
Binary file added assets/de/new.pptx
Binary file not shown.
Binary file added assets/de/new.xlsx
Binary file not shown.
File renamed without changes.
Binary file added assets/en/new.pptx
Binary file not shown.
File renamed without changes.
Binary file added assets/es/new.docx
Binary file not shown.
Binary file added assets/es/new.pptx
Binary file not shown.
Binary file added assets/es/new.xlsx
Binary file not shown.
Binary file added assets/fr/new.docx
Binary file not shown.
Binary file added assets/fr/new.pptx
Binary file not shown.
Binary file added assets/fr/new.xlsx
Binary file not shown.
Binary file added assets/it/new.docx
Binary file not shown.
Binary file added assets/it/new.pptx
Binary file not shown.
Binary file added assets/it/new.xlsx
Binary file not shown.
Binary file added assets/lv/new.docx
Binary file not shown.
Binary file added assets/lv/new.pptx
Binary file not shown.
Binary file added assets/lv/new.xlsx
Binary file not shown.
Binary file added assets/pl/new.docx
Binary file not shown.
Binary file added assets/pl/new.pptx
Binary file not shown.
Binary file added assets/pl/new.xlsx
Binary file not shown.
Binary file added assets/pt/new.docx
Binary file not shown.
Binary file added assets/pt/new.pptx
Binary file not shown.
Binary file added assets/pt/new.xlsx
Binary file not shown.
Binary file added assets/ru/new.docx
Binary file not shown.
Binary file added assets/ru/new.pptx
Binary file not shown.
Binary file added assets/ru/new.xlsx
Binary file not shown.
53 changes: 53 additions & 0 deletions controller/callbackcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,47 @@ public function download($doc) {
return new JSONResponse(["message" => $this->trans->t("Download failed")], Http::STATUS_INTERNAL_SERVER_ERROR);
}

/**
* Downloading empty file by the document service
*
* @param string $doc - verification token with the file identifier
*
* @return OCA\Onlyoffice\DownloadResponse
*
* @NoAdminRequired
* @NoCSRFRequired
* @PublicPage
* @CORS
*/
public function emptyfile($doc) {

list ($hashData, $error) = $this->crypt->ReadHash($doc);
if ($hashData === NULL) {
$this->logger->info("Download empty with empty or not correct hash: " . $error, array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("Access deny")], Http::STATUS_FORBIDDEN);
}
if ($hashData->action !== "empty") {
$this->logger->info("Download empty with other action", array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("Invalid request")], Http::STATUS_BAD_REQUEST);
}

$templatePath = dirname(__DIR__) . DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . "en" . DIRECTORY_SEPARATOR . "new.docx";

$template = file_get_contents($templatePath);
if (!$template) {
$this->logger->info("Template for download empty not found: " . $templatePath, array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("File not found")], Http::STATUS_NOT_FOUND);
}

try {
return new DataDownloadResponse($template, "new.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
} catch(\OCP\Files\NotPermittedException $e) {
$this->logger->info("Download Not permitted: " . $fileId . " " . $e->getMessage(), array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("Not permitted")], Http::STATUS_FORBIDDEN);
}
return new JSONResponse(["message" => $this->trans->t("Download failed")], Http::STATUS_INTERNAL_SERVER_ERROR);
}

/**
* Handle request from the document server with the document status information
*
Expand Down Expand Up @@ -259,6 +300,18 @@ public function track($doc, $users, $key, $status, $url) {
}
}

if (!empty($this->config->GetDocumentServerInternalUrl(true))) {
$from = $this->config->GetDocumentServerUrl();

if (!preg_match("/^https?:\/\//i", $from)) {
$parsedUrl = parse_url($url);
$from = $parsedUrl["scheme"] . "://" . $parsedUrl["host"] . (array_key_exists("port", $parsedUrl) ? (":" . $parsedUrl["port"]) : "") . "/";
}

$this->logger->debug("Replace in track from " . $from . " to " . $this->config->GetDocumentServerInternalUrl(true));
$url = str_replace($from, $this->config->GetDocumentServerInternalUrl(true), $url);
}

if (($newData = file_get_contents($url))) {

$this->userSession->setUser($this->userManager->get($users[0]));
Expand Down
45 changes: 41 additions & 4 deletions controller/editorcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,14 @@ public function create($name, $dir) {
$name = $userFolder->getNonExistingName($name);
$filePath = $dir . DIRECTORY_SEPARATOR . $name;
$ext = strtolower("." . pathinfo($filePath, PATHINFO_EXTENSION));
$templatePath = dirname(__DIR__) . DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . "new" . $ext;

$lang = \OC::$server->getL10NFactory("")->get("")->getLanguageCode();

$templatePath = $this->getTemplatePath($lang, $ext);
if (!file_exists($templatePath)) {
$lang = "en";
$templatePath = $this->getTemplatePath($lang, $ext);
}

$template = file_get_contents($templatePath);
if (!$template) {
Expand All @@ -189,6 +196,10 @@ public function create($name, $dir) {
return $result;
}

private function getTemplatePath($lang, $ext) {
return dirname(__DIR__) . DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . $lang . DIRECTORY_SEPARATOR . "new" . $ext;
}

/**
* Conversion file to Office Open XML format
*
Expand Down Expand Up @@ -253,7 +264,7 @@ public function convert($fileId) {

$newFilePath = $newFolderPath . DIRECTORY_SEPARATOR . $newFileName;

if (($newData = file_get_contents($newFileUri)) === FALSE){
if (($newData = file_get_contents($newFileUri)) === FALSE) {
$this->logger->error("Failed download converted file: " . $newFileUri, array("app" => $this->appName));
return ["error" => $this->trans->t("Failed download converted file")];
}
Expand Down Expand Up @@ -303,9 +314,11 @@ public function index($fileId) {
$csp = new ContentSecurityPolicy();
$csp->allowInlineScript(true);

if (isset($documentServerUrl) && !empty($documentServerUrl)) {
if (preg_match("/^https?:\/\//i", $documentServerUrl)) {
$csp->addAllowedScriptDomain($documentServerUrl);
$csp->addAllowedFrameDomain($documentServerUrl);
} else {
$csp->addAllowedFrameDomain($this->urlGenerator->getAbsoluteURL("/"));
}
$response->setContentSecurityPolicy($csp);

Expand Down Expand Up @@ -339,8 +352,10 @@ public function config($fileId) {

$userId = $this->userSession->getUser()->getUID();
$ownerId = $file->getOwner()->getUID();
$folderPath = NULL;
try {
$this->root->getUserFolder($ownerId);
$userFolder = $this->root->getUserFolder($ownerId);
$folderPath = $userFolder->getRelativePath($file->getParent()->getPath());
} catch (NoUserException $e) {
$ownerId = $userId;
}
Expand All @@ -353,6 +368,10 @@ public function config($fileId) {
$canEdit = isset($format["edit"]) && $format["edit"];
$callback = ($file->isUpdateable() && $canEdit ? $this->urlGenerator->linkToRouteAbsolute($this->appName . ".callback.track", ["doc" => $hashCallback]) : NULL);

if (!empty($this->config->GetStorageUrl())) {
$callback = str_replace($this->urlGenerator->getAbsoluteURL("/"), $this->config->GetStorageUrl(), $callback);
}

$params = [
"document" => [
"fileType" => pathinfo($fileName, PATHINFO_EXTENSION),
Expand All @@ -372,6 +391,19 @@ public function config($fileId) {
]
];

if (!empty($folderPath)) {
$args = [
"dir" => $folderPath,
"scrollto" => $file->getName()
];

$params["editorConfig"]["customization"] = [
"goback" => [
"url" => $this->urlGenerator->linkToRouteAbsolute("files.view.index", $args)
]
];
}

if (!empty($this->config->GetDocumentServerSecret())) {
$token = \Firebase\JWT\JWT::encode($params, $this->config->GetDocumentServerSecret());
$params["token"] = $token;
Expand Down Expand Up @@ -457,6 +489,11 @@ private function getUrl($file) {
$hashUrl = $this->crypt->GetHash(["fileId" => $fileId, "ownerId" => $ownerId, "action" => "download"]);

$fileUrl = $this->urlGenerator->linkToRouteAbsolute($this->appName . ".callback.download", ["doc" => $hashUrl]);

if (!empty($this->config->GetStorageUrl())) {
$fileUrl = str_replace($this->urlGenerator->getAbsoluteURL("/"), $this->config->GetStorageUrl(), $fileUrl);
}

return $fileUrl;
}
}
Loading

0 comments on commit 92ad85c

Please sign in to comment.