Skip to content

Commit

Permalink
Merge pull request #74 from ONLYOFFICE/develop
Browse files Browse the repository at this point in the history
Release/2.4.0
  • Loading branch information
LinneyS committed Mar 5, 2022
2 parents 76677dc + c91a7ae commit c177603
Show file tree
Hide file tree
Showing 47 changed files with 407 additions and 134 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,16 @@
# Change Log

## 2.4.0
## Added
- certificate verification setting
- check unsaved changes before closing
- Turkish and Galician empty file templates

## Changed
- document server v6.0 and earlier is no longer supported
- Fixed opening file when maintenance mode
- Added Versioning Support (HumHub v1.10+)

## 2.3.0
## Added
- support docxf and oform formats
Expand Down
5 changes: 5 additions & 0 deletions Events.php
Expand Up @@ -6,6 +6,11 @@
* @license https://www.humhub.com/licences
*/

/**
* Copyright (c) Ascensio System SIA 2022. All rights reserved.
* http://www.onlyoffice.com
*/

namespace humhub\modules\onlyoffice;

use humhub\modules\file\handler\FileHandlerCollection;
Expand Down
105 changes: 73 additions & 32 deletions Module.php
Expand Up @@ -6,6 +6,11 @@
* @license https://www.humhub.com/licences
*/

/**
* Copyright (c) Ascensio System SIA 2022. All rights reserved.
* http://www.onlyoffice.com
*/

namespace humhub\modules\onlyoffice;

use Yii;
Expand Down Expand Up @@ -34,9 +39,9 @@ class Module extends \humhub\components\Module
/**
* Only document types
*/
const DOCUMENT_TYPE_TEXT = 'text';
const DOCUMENT_TYPE_PRESENTATION = 'presentation';
const DOCUMENT_TYPE_SPREADSHEET = 'spreadsheet';
const DOCUMENT_TYPE_TEXT = 'word';
const DOCUMENT_TYPE_PRESENTATION = 'slide';
const DOCUMENT_TYPE_SPREADSHEET = 'cell';

/**
* @var string[] allowed spreadsheet extensions
Expand Down Expand Up @@ -101,6 +106,11 @@ public function getStorageUrl()
return $this->settings->get('storageUrl');
}

public function getVerifyPeerOff()
{
return $this->settings->get('verifyPeerOff');
}

/**
*
* @return type
Expand All @@ -112,7 +122,7 @@ public function getServerApiUrl()

public function getDocumentType($file)
{
$fileExtension = FileHelper::getExtension($file);
$fileExtension = strtolower(FileHelper::getExtension($file));

if (in_array($fileExtension, $this->spreadsheetExtensions)) {
return self::DOCUMENT_TYPE_SPREADSHEET;
Expand All @@ -127,13 +137,13 @@ public function getDocumentType($file)

public function canEdit($file)
{
$fileExtension = FileHelper::getExtension($file);
$fileExtension = strtolower(FileHelper::getExtension($file));
return in_array($fileExtension, $this->editableExtensions);
}

public function canConvert($file)
{
$fileExtension = FileHelper::getExtension($file);
$fileExtension = strtolower(FileHelper::getExtension($file));
return in_array($fileExtension, $this->convertableExtensions);
}

Expand Down Expand Up @@ -173,23 +183,19 @@ public function commandService($data)
$url = $this->getInternalServerUrl() . '/coauthoring/CommandService.ashx';

try {
$http = new \Zend\Http\Client($url, [
'adapter' => '\Zend\Http\Client\Adapter\Curl',
'curloptions' => CURLHelper::getOptions(),
'timeout' => 10
]);
$http->setMethod('POST');
$headers = $http->getRequest()->getHeaders();

$headers = [];
$headers['Accept'] = 'application/json';
if ($this->isJwtEnabled()) {
$data['token'] = JWT::encode($data, $this->getJwtSecret());
$headers->addHeaderLine('Authorization', 'Bearer ' . JWT::encode(['payload' => $data], $this->getJwtSecret()));
$headers['Authorization'] = 'Bearer ' . JWT::encode(['payload' => $data], $this->getJwtSecret());
}

$http->setRawBody(Json::encode($data));
$headers->addHeaderLine('Accept', 'application/json');
$options = array(
'headers' => $headers,
'body' => $data
);

$response = $http->send();
$response = $this->request($url, 'POST', $options);
$json = $response->getBody();
} catch (\Exception $ex) {
Yii::error('Could not get document server response! ' . $ex->getMessage());
Expand All @@ -209,34 +215,38 @@ public function convertService($file, $ts)
$url = $this->getInternalServerUrl() . '/ConvertService.ashx';
$key = $this->generateDocumentKey($file);

$ext = FileHelper::getExtension($file);
$user = Yii::$app->user->getIdentity();
$userGuid = null;
if (isset($user->guid)) {
$userGuid = $user->guid;
}

$docHash = $this->generateHash($key, $userGuid);

$ext = strtolower(FileHelper::getExtension($file));
$data = [
'async' => true,
'embeddedfonts' => true,
'filetype' => $ext,
'outputtype' => $this->convertsTo[$ext],
'key' => $key . $ts,
'url' => Url::to(['/onlyoffice/backend/download', 'key' => $key], true),
'url' => Url::to(['/onlyoffice/backend/download', 'doc' => $docHash], true),
];

try {
$http = new \Zend\Http\Client($url, [
'adapter' => '\Zend\Http\Client\Adapter\Curl',
'curloptions' => CURLHelper::getOptions(),
'timeout' => 10
]);
$http->setMethod('POST');
$headers = $http->getRequest()->getHeaders();

$headers = [];
$headers['Accept'] = 'application/json';
if ($this->isJwtEnabled()) {
$data['token'] = JWT::encode($data, $this->getJwtSecret());
$headers->addHeaderLine('Authorization', 'Bearer ' . JWT::encode(['payload' => $data], $this->getJwtSecret()));
$headers['Authorization'] = 'Bearer ' . JWT::encode(['payload' => $data], $this->getJwtSecret());
}

$http->setRawBody(Json::encode($data));
$headers->addHeaderLine('Accept', 'application/json');
$options = array(
'headers' => $headers,
'body' => $data
);

$response = $http->send();
$response = $this->request($url, 'POST', $options);
$json = $response->getBody();
} catch (\Exception $ex) {
$error = 'Could not get document server response! ' . $ex->getMessage();
Expand Down Expand Up @@ -267,6 +277,37 @@ public function getPermissions($contentContainer = null)
return [];
}

/**
* @inheritdoc
*/
public function generateHash($key, $userGuid)
{
$data = [
'key' => $key
];

if (!empty($userGuid)) {
$data['userGuid'] = $userGuid;
}

return JWT::encode($data, Yii::$app->settings->get('secret'));
}

/**
* @inheritdoc
*/
public function readHash($hash)
{
try {
$data = JWT::decode($hash, Yii::$app->settings->get('secret'), array('HS256'));
} catch (\Exception $ex) {
$error = 'Invalid hash ' . $ex->getMessage();
Yii::error($error);
return [null, $error];
}

return [$data, null];
}
/**
* @inheritdoc
*/
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -22,9 +22,9 @@ You will need an instance of ONLYOFFICE Docs (Document Server) that is resolvabl

You can install free Community version of ONLYOFFICE Docs or scalable Enterprise Edition with pro features.

To install free Community version, use [Docker](https://github.com/onlyoffice/Docker-DocumentServer) (recommended) or follow [these instructions](https://helpcenter.onlyoffice.com/server/linux/document/linux-installation.aspx) for Debian, Ubuntu, or derivatives.
To install free Community version, use [Docker](https://github.com/onlyoffice/Docker-DocumentServer) (recommended) or follow [these instructions](https://helpcenter.onlyoffice.com/installation/docs-community-install-ubuntu.aspx) for Debian, Ubuntu, or derivatives.

To install Enterprise Edition, follow instructions [here](https://helpcenter.onlyoffice.com/server/integration-edition/index.aspx).
To install Enterprise Edition, follow instructions [here](https://helpcenter.onlyoffice.com/installation/docs-enterprise-index.aspx).

Community Edition vs Enterprise Edition comparison can be found [here](#onlyoffice-docs-editions).

Expand Down
5 changes: 5 additions & 0 deletions assets/Assets.php
Expand Up @@ -6,6 +6,11 @@
* @license https://www.humhub.com/licences
*/

/**
* Copyright (c) Ascensio System SIA 2022. All rights reserved.
* http://www.onlyoffice.com
*/

namespace humhub\modules\onlyoffice\assets;

use Yii;
Expand Down
5 changes: 5 additions & 0 deletions components/BaseFileController.php
Expand Up @@ -6,6 +6,11 @@
* @license https://www.humhub.com/licences
*/

/**
* Copyright (c) Ascensio System SIA 2022. All rights reserved.
* http://www.onlyoffice.com
*/

namespace humhub\modules\onlyoffice\components;

use Yii;
Expand Down
5 changes: 5 additions & 0 deletions controllers/AdminController.php
Expand Up @@ -6,6 +6,11 @@
* @license https://www.humhub.com/licences
*/

/**
* Copyright (c) Ascensio System SIA 2022. All rights reserved.
* http://www.onlyoffice.com
*/

namespace humhub\modules\onlyoffice\controllers;

use Yii;
Expand Down
5 changes: 5 additions & 0 deletions controllers/ApiController.php
Expand Up @@ -6,6 +6,11 @@
* @license https://www.humhub.com/licences
*/

/**
* Copyright (c) Ascensio System SIA 2022. All rights reserved.
* http://www.onlyoffice.com
*/

namespace humhub\modules\onlyoffice\controllers;

use Yii;
Expand Down
45 changes: 39 additions & 6 deletions controllers/BackendController.php
Expand Up @@ -6,13 +6,19 @@
* @license https://www.humhub.com/licences
*/

/**
* Copyright (c) Ascensio System SIA 2022. All rights reserved.
* http://www.onlyoffice.com
*/

namespace humhub\modules\onlyoffice\controllers;

use Yii;
use yii\web\HttpException;
use humhub\modules\file\models\File;
use humhub\modules\user\models\User;
use humhub\components\Controller;
use \humhub\components\Module;
use \Firebase\JWT\JWT;

class BackendController extends Controller
Expand All @@ -28,16 +34,37 @@ class BackendController extends Controller
*/
public $file;

/**
* @var Module
*/
public $module;

/**
* @inheritdoc
*/
public function beforeAction($action)
{
$this->module = Yii::$app->getModule('onlyoffice');
$this->enableCsrfValidation = false;

$key = Yii::$app->request->get('key');
$hash = Yii::$app->request->get('doc');
list ($hashData, $error) = $this->module->readHash($hash);
if (!empty($error)) {
throw new HttpException(404, 'Backend action with empty or invalid hash');
}

$key = $hashData->key;
$userGuid = isset($hashData->userGuid) ? $hashData->userGuid : null;

$this->file = File::findOne(['onlyoffice_key' => $key]);

if (Yii::$app->settings->get('maintenanceMode')) {
$user = User::findOne(['guid' => $userGuid]);
if (!empty($user) && $user->isSystemAdmin()) {
Yii::$app->user->login($user);
}
}

if ($this->file == null) {
throw new HttpException(404, Yii::t('OnlyofficeModule.base', 'Could not find requested file!'));
}
Expand Down Expand Up @@ -79,8 +106,7 @@ public function actionTrack()
throw new \Exception('Could not parse json');
}

$module = Yii::$app->getModule('onlyoffice');
if ($module->isJwtEnabled()) {
if ($this->module->isJwtEnabled()) {
$token = null;
if (!empty($data["token"])) {
$token = $data["token"];
Expand All @@ -96,7 +122,7 @@ public function actionTrack()
}

try {
$ds = JWT::decode($token, $module->getJwtSecret(), array('HS256'));
$ds = JWT::decode($token, $this->module->getJwtSecret(), array('HS256'));
$data = isset($ds->payload) ? (array)$ds->payload : (array)$ds;
} catch (\Exception $ex) {
throw new \Exception('Invalid JWT signature');
Expand All @@ -117,10 +143,17 @@ public function actionTrack()
case "Corrupted":
case "ForceSave":

$newData = file_get_contents($data["url"]);
$newData = $this->module->request($data["url"])->getBody();

if (!empty($newData)) {
$this->file->getStore()->setContent($newData);

if (version_compare(Yii::$app->version, '1.10', '>=')) {
// For HumHub from version 1.10 with versioning support
$this->file->setStoredFileContent($newData);
} else {
// Older HumHub versions
$this->file->getStore()->setContent($newData);
}

if ($status != 'ForceSave') {
$newAttr = [
Expand Down

0 comments on commit c177603

Please sign in to comment.