diff --git a/controller/documentcontroller.php b/controller/documentcontroller.php index e8e0c404..6a138ae1 100644 --- a/controller/documentcontroller.php +++ b/controller/documentcontroller.php @@ -61,9 +61,8 @@ class DocumentController extends Controller{ ]); $policy = new ContentSecurityPolicy(); - //$policy->addAllowedChildSrcDomain('\'self\' http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js http://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.12/jquery.mousewheel.min.js \'unsafe-eval\''); - $policy->addAllowedScriptDomain('\'self\' http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js http://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.12/jquery.mousewheel.min.js \'unsafe-eval\''); - $policy->addAllowedFrameDomain('\'self\' http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js http://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.12/jquery.mousewheel.min.js \'unsafe-eval\''); ++ $policy->addAllowedScriptDomain('\'self\' http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js http://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.12/jquery.mousewheel.min.js \'unsafe-eval\' ' . $this->settings->getAppValue('documents', 'wopi_url', $_SERVER['SERVER_NAME'])); ++ $policy->addAllowedFrameDomain('\'self\' http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js http://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.12/jquery.mousewheel.min.js \'unsafe-eval\' ' . $this->settings->getAppValue('documents', 'wopi_url', $_SERVER['SERVER_NAME'])); $policy->addAllowedConnectDomain('ws://' . $_SERVER['SERVER_NAME'] . ':9980'); $policy->addAllowedImageDomain('*'); $policy->allowInlineScript(true); diff --git a/controller/settingscontroller.php b/controller/settingscontroller.php index 3e008a7b..7fbed840 100644 --- a/controller/settingscontroller.php +++ b/controller/settingscontroller.php @@ -22,18 +22,18 @@ use OCA\Richdocuments\Converter; use OCA\Richdocuments\Filter; class SettingsController extends Controller{ - + private $userId; private $l10n; private $appConfig; - + public function __construct($appName, IRequest $request, IL10N $l10n, AppConfig $appConfig, $userId){ parent::__construct($appName, $request); $this->userId = $userId; $this->l10n = $l10n; $this->appConfig = $appConfig; } - + /** * @NoAdminRequired */ @@ -43,47 +43,48 @@ class SettingsController extends Controller{ 'mimes' => Filter::getAll() ); } - + /** * @NoAdminRequired * @NoCSRFRequired */ public function personalIndex(){ return new TemplateResponse( - $this->appName, + $this->appName, 'personal', [ 'save_path' => $this->appConfig->getUserValue($this->userId, 'save_path') ], 'blank' ); } - + /** * @NoCSRFRequired */ public function settingsIndex(){ return new TemplateResponse( - $this->appName, + $this->appName, 'settings', [ 'unstable' => $this->appConfig->getAppValue('unstable') ], 'blank' ); } - + /** * @NoCSRFRequired */ public function adminIndex(){ return new TemplateResponse( - $this->appName, + $this->appName, 'admin', [ 'converter' => $this->appConfig->getAppValue('converter'), + 'wopi_url' => $this->appConfig->getAppValue('wopi_url'), 'converter_url' => $this->appConfig->getAppValue('converter_url'), ], 'blank' ); } - + /** * @NoAdminRequired */ @@ -95,7 +96,7 @@ class SettingsController extends Controller{ if (\OC\Files\Filesystem::file_exists($savePath) === false ){ $status = \OC\Files\Filesystem::mkdir($savePath); } - + if ($status){ $this->appConfig->setUserValue($this->userId, 'save_path', $savePath); $response = array( @@ -112,33 +113,37 @@ class SettingsController extends Controller{ } return $response; } - + public function setUnstable($unstable){ if (!is_null($unstable)){ $this->appConfig->setAppValue('unstable', $unstable); } return array('status' => 'success'); } - - public function setConverter($converter, $url){ + + public function setConverter($converter, $wopi_url, $url){ if (!is_null($converter)){ $this->appConfig->setAppValue('converter', $converter); } - + + if (!is_null($wopi_url)){ + $this->appConfig->setAppValue('wopi_url', $wopi_url); + } + if (!is_null($url)){ $this->appConfig->setAppValue('converter_url', $url); } - + $response = array( 'status' => 'success', 'data' => array('message' => (string) $this->l10n->t('Saved')) ); - + $currentConverter = $this->appConfig->getAppValue('converter'); if ($currentConverter == 'external'){ if (!Converter::checkConnection()){ \OC::$server->getLogger()->warning( - 'Bad response from Format Filter Server', + 'Bad response from Format Filter Server', ['app' => $this->appName] ); $response = array( @@ -150,7 +155,7 @@ class SettingsController extends Controller{ } elseif ($currentConverter === 'local') { try { if (!Converter::testConversion()){ - $response = array( + $response = array( 'status' => 'error', 'data'=> array('message' => (string) $this->l10n->t('Conversion failed. Check log for details.') ) @@ -163,7 +168,7 @@ class SettingsController extends Controller{ ); } } - + return $response; } } diff --git a/js/admin.js b/js/admin.js index f2da6bdc..e0f78ded 100644 --- a/js/admin.js +++ b/js/admin.js @@ -1,32 +1,33 @@ /*global OC, $ */ $(document).ready(function(){ - + var documentsSettings = { save : function() { $('#docs_apply').attr('disabled', true); var data = { - converter : $('[name="docs_converter"]:checked').val() - }; - + converter : $('[name="docs_converter"]:checked').val(), + wopi_url : $('#wopi_url').val() + }; + if (data.converter === 'external'){ data.url = $('#docs_url').val(); } - + OC.msg.startAction('#documents-admin-msg', t('richdocuments', 'Saving...')); $.post( - OC.filePath('richdocuments', 'ajax', 'admin.php'), + OC.filePath('richdocuments', 'ajax', 'admin.php'), data, documentsSettings.afterSave ); }, - + afterSave : function(response){ $('#docs_apply').attr('disabled', false); OC.msg.finishedAction('#documents-admin-msg', response); } }; - + $('#docs_converter_external, #docs_converter_local, #docs_converter_off').on('click', function(){ $('#docs_extra').toggle($('[name="docs_converter"]:checked').val() === 'external'); }); diff --git a/lib/appconfig.php b/lib/appconfig.php index a83ceae3..490c7eb2 100644 --- a/lib/appconfig.php +++ b/lib/appconfig.php @@ -8,7 +8,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. */ - + namespace OCA\Richdocuments; use \OCP\IConfig; @@ -18,15 +18,16 @@ use \OCP\IConfig; private $defaults = [ 'converter' => 'off', 'converter_url' => 'http://localhost:16080', - 'unstable' => 'false' + 'unstable' => 'false', + 'wopi_url' => 'htpp://localhost' ]; - + private $config; - + public function __construct(IConfig $config) { $this->config = $config; } - + /** * Can we convert anything to odt? * @return bool @@ -34,7 +35,7 @@ use \OCP\IConfig; public function isConverterEnabled(){ return $this->getAppValue('converter') !== 'off'; } - + /** * Get a value by key * @param string $key @@ -57,7 +58,7 @@ use \OCP\IConfig; public function setAppValue($key, $value) { return $this->config->setAppValue($this->appName, $key, $value); } - + /** * Get a value by key for a user * @param string $userId @@ -83,4 +84,4 @@ use \OCP\IConfig; return $this->config->setAppValue($userId, $this->appName, $key, $value); } } - \ No newline at end of file + diff --git a/templates/admin.php b/templates/admin.php index 2d391d30..59cf7584 100644 --- a/templates/admin.php +++ b/templates/admin.php @@ -5,34 +5,39 @@ script('richdocuments', 'admin');

t('Documents')) ?>

t('MS Word support (requires openOffice/libreOffice)')) ?>

- + />
t('openOffice/libreOffice is installed on this server. Path to binary is provided via preview_libreoffice_path in config.php')) ?>

+ />
t('openOffice/libreOffice is installed on external server running a format filter server')) ?>

+ />
t('No MS Word support')) ?>

> -
t('Server URL')) ?>
+
+
+ +
t('WOPI Client')) ?> +