Request discovery.xml from WOPI client

pull/1/head
Henry Castro 8 years ago
parent 2d2edffa80
commit 13692a5d3b

@ -49,7 +49,8 @@ class Application extends App {
$c->query('CoreConfig'), $c->query('CoreConfig'),
$c->query('L10N'), $c->query('L10N'),
$c->query('UserId'), $c->query('UserId'),
$c->query('ICacheFactory') $c->query('ICacheFactory'),
$c->query('Logger')
); );
}); });
$container->registerService('SettingsController', function($c) { $container->registerService('SettingsController', function($c) {

@ -28,6 +28,7 @@ use \OCA\Richdocuments\File;
use \OCA\Richdocuments\Genesis; use \OCA\Richdocuments\Genesis;
use \OC\Files\View; use \OC\Files\View;
use \OCP\ICacheFactory; use \OCP\ICacheFactory;
use \OCP\ILogger;
class DocumentController extends Controller{ class DocumentController extends Controller{
@ -35,16 +36,18 @@ class DocumentController extends Controller{
private $l10n; private $l10n;
private $settings; private $settings;
private $cache; private $cache;
private $logger;
const ODT_TEMPLATE_PATH = '/assets/odttemplate.odt'; const ODT_TEMPLATE_PATH = '/assets/odttemplate.odt';
const CLOUDSUITE_TMP_PATH = '/documents-tmp/'; const CLOUDSUITE_TMP_PATH = '/documents-tmp/';
public function __construct($appName, IRequest $request, IConfig $settings, IL10N $l10n, $uid, ICacheFactory $cache){ public function __construct($appName, IRequest $request, IConfig $settings, IL10N $l10n, $uid, ICacheFactory $cache, ILogger $logger){
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->uid = $uid; $this->uid = $uid;
$this->l10n = $l10n; $this->l10n = $l10n;
$this->settings = $settings; $this->settings = $settings;
$this->cache = $cache->create($appName); $this->cache = $cache->create($appName);
$this->logger = $logger;
} }
/** /**
@ -54,6 +57,7 @@ class DocumentController extends Controller{
public function index(){ public function index(){
\OC::$server->getNavigationManager()->setActiveEntry( 'richdocuments_index' ); \OC::$server->getNavigationManager()->setActiveEntry( 'richdocuments_index' );
$maxUploadFilesize = \OCP\Util::maxUploadFilesize("/"); $maxUploadFilesize = \OCP\Util::maxUploadFilesize("/");
$wopiRemote = $this->settings->getAppValue('richdocuments', 'wopi_url');
$response = new TemplateResponse('richdocuments', 'documents', [ $response = new TemplateResponse('richdocuments', 'documents', [
'enable_previews' => $this->settings->getSystemValue('enable_previews', true), 'enable_previews' => $this->settings->getSystemValue('enable_previews', true),
'useUnstable' => $this->settings->getAppValue('richdocuments', 'unstable', 'false'), 'useUnstable' => $this->settings->getAppValue('richdocuments', 'unstable', 'false'),
@ -61,20 +65,54 @@ class DocumentController extends Controller{
'uploadMaxFilesize' => $maxUploadFilesize, 'uploadMaxFilesize' => $maxUploadFilesize,
'uploadMaxHumanFilesize' => \OCP\Util::humanFileSize($maxUploadFilesize), 'uploadMaxHumanFilesize' => \OCP\Util::humanFileSize($maxUploadFilesize),
'allowShareWithLink' => $this->settings->getAppValue('core', 'shareapi_allow_links', 'yes'), 'allowShareWithLink' => $this->settings->getAppValue('core', 'shareapi_allow_links', 'yes'),
'wopi_url' => $this->settings->getAppValue('richdocuments', 'wopi_url'), 'wopi_url' => $wopiRemote,
]); ]);
$policy = new ContentSecurityPolicy(); $policy = new ContentSecurityPolicy();
$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('richdocuments', 'wopi_url')); $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\' ' . $wopiRemote);
$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('richdocuments', 'wopi_url')); $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\' ' . $wopiRemote);
$policy->addAllowedConnectDomain('ws://' . $_SERVER['SERVER_NAME'] . ':9980'); $policy->addAllowedConnectDomain('ws://' . $_SERVER['SERVER_NAME'] . ':9980');
$policy->addAllowedImageDomain('*'); $policy->addAllowedImageDomain('*');
$policy->allowInlineScript(true); $policy->allowInlineScript(true);
$policy->addAllowedFontDomain('data:'); $policy->addAllowedFontDomain('data:');
$response->setContentSecurityPolicy($policy); $response->setContentSecurityPolicy($policy);
$discovery = $this->cache->get('discovery.xml');
if(is_null($this->cache->get('discovery.xml'))) {
// TODO GET http://domain/hosting/discovery if(is_null($discovery)) {
if (($parts = parse_url($wopiRemote))) {
// Provides access to information about the capabilities of a WOPI client
// and the mechanisms for invoking those abilities through URIs.
// HTTP://server/hosting/discovery
$wopiDiscovery = sprintf(
"%s%s%s%s",
isset($parts['scheme']) ? $parts['scheme'] . "://" : '',
isset($parts['host']) ? $parts['host'] : '',
isset($parts['port']) ? ":" . $parts['port'] : '',
"/hosting/discovery" );
try {
$wopiClient = \OC::$server->getHTTPClientService()->newClient();
$xml = $wopiClient->get($wopiDiscovery)->getBody();
if ($xml) {
$loadEntities = libxml_disable_entity_loader(true);
$data = simplexml_load_string($xml);
libxml_disable_entity_loader($loadEntities);
if ($data !== false) {
// default ttl
$this->cache->set('discovery.xml', $xml);
}
else {
$this->logger->error('failure discovery.xml not well-formed XML string');
}
}
else {
$this->logger->error('failure response discovery.xml');
}
} catch (\Exception $e) {
$this->logger->error(
sprintf('Error getting discovery.xml: %s', $e->getMessage()));
}
}
} }
return $response; return $response;

@ -17,6 +17,7 @@ class DocumentControllerTest extends \PHPUnit_Framework_TestCase {
private $l10n; private $l10n;
private $settings; private $settings;
private $cache; private $cache;
private $logger;
private $uid = 'jack_the_documents_tester'; private $uid = 'jack_the_documents_tester';
private $password = 'password'; private $password = 'password';
private $controller; private $controller;
@ -34,17 +35,22 @@ class DocumentControllerTest extends \PHPUnit_Framework_TestCase {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock() ->getMock()
; ;
$this->cache = $this->getMockBuilder('\OCP\ICacheFactory') $this->cache = $this->getMockBuilder('\OCP\ICacheFactory')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock() ->getMock()
; ;
$this->logger = $this->getMockBuilder('\OCP\ILogger')
->disableOriginalConstructor()
->getMock()
;
$this->controller = new DocumentController( $this->controller = new DocumentController(
$this->appName, $this->appName,
$this->request, $this->request,
$this->settings, $this->settings,
$this->l10n, $this->l10n,
$this->uid, $this->uid,
$this->cache $this->cache,
$this->logger
); );
$userManager = \OC::$server->getUserManager(); $userManager = \OC::$server->getUserManager();

Loading…
Cancel
Save