From 71981ffa05f164d06180cb5337ffe844691c0367 Mon Sep 17 00:00:00 2001 From: Deus Ex Machina Date: Tue, 1 Dec 2015 18:11:53 +0200 Subject: [PATCH] Add v0.1 --- appinfo/app.php | 7 ++ appinfo/info.xml | 15 ++++ appinfo/routes.php | 10 +++ appinfo/version | 1 + controller/apicontroller.php | 65 ++++++++++++++ controller/displaycontroller.php | 58 +++++++++++++ js/viewer.js | 142 +++++++++++++++++++++++++++++++ templates/online.php | 142 +++++++++++++++++++++++++++++++ tmp/index.php | 0 9 files changed, 440 insertions(+) create mode 100644 appinfo/app.php create mode 100644 appinfo/info.xml create mode 100644 appinfo/routes.php create mode 100644 appinfo/version create mode 100644 controller/apicontroller.php create mode 100644 controller/displaycontroller.php create mode 100644 js/viewer.js create mode 100644 templates/online.php create mode 100644 tmp/index.php diff --git a/appinfo/app.php b/appinfo/app.php new file mode 100644 index 0000000..cc3c2e9 --- /dev/null +++ b/appinfo/app.php @@ -0,0 +1,7 @@ + + + libreonline + LibreOnline + + LibreOffice Online app for ownCloud + + MPLv2/LGPLv3+ + 8.0 + Ozcan Esen, Faruk Uzun + true + + + + diff --git a/appinfo/routes.php b/appinfo/routes.php new file mode 100644 index 0000000..84150db --- /dev/null +++ b/appinfo/routes.php @@ -0,0 +1,10 @@ + [ + ['name' => 'api#saveFile', 'url' => '/save/', 'verb' => 'GET'], + ['name' => 'api#generateFileURL', 'url' => '/generateFileURL/', 'verb' => 'GET'], + ['name' => 'display#showLibreOnline', 'url' => '/', 'verb' => 'GET'] + +]]; diff --git a/appinfo/version b/appinfo/version new file mode 100644 index 0000000..49d5957 --- /dev/null +++ b/appinfo/version @@ -0,0 +1 @@ +0.1 diff --git a/controller/apicontroller.php b/controller/apicontroller.php new file mode 100644 index 0000000..0ef202d --- /dev/null +++ b/controller/apicontroller.php @@ -0,0 +1,65 @@ +urlGenerator = $urlGenerator; + $this->userId = $userId; + $this->rootFolder = $rootFolder; + } + + /** + * @PublicPage + * @NoCSRFRequired + * + * @return TemplateResponse + */ + public function saveFile($ip, $port, $jail, $dir, $name, $target) { + + $url = "http://$ip:$port/$jail/$dir/$name"; + //FIXME: We should use owncloud api here. + file_put_contents("/var/www/owncloud/data/" . $this->userId . "/files$target", file_get_contents($url)); + } + + + /** + * @PublicPage + * @NoCSRFRequired + * + * @return TemplateResponse + */ + public function generateFileURL($file) { + $url = sha1($file . mt_rand()); + $app_path = \OC_App::getAppPath("libreonline"); + $tmp_path = $app_path . '/tmp'; + //FIXME: We should use owncloud api here. + copy("/var/www/owncloud/data/" . $this->userId . "/files$file", "$tmp_path/$url"); + $uri = \OC_App::getAppWebPath('libreonline') . "/tmp/$url"; + return $uri; + } +} diff --git a/controller/displaycontroller.php b/controller/displaycontroller.php new file mode 100644 index 0000000..415dda1 --- /dev/null +++ b/controller/displaycontroller.php @@ -0,0 +1,58 @@ +urlGenerator = $urlGenerator; + } + + /** + * @PublicPage + * @NoCSRFRequired + * + * @return TemplateResponse + */ + public function showLibreOnline() { + $params = [ + 'urlGenerator' => $this->urlGenerator + ]; + $response = new TemplateResponse($this->appName, 'online', $params, 'blank'); + + $policy = new ContentSecurityPolicy(); + $policy->addAllowedChildSrcDomain('*'); + $policy->addAllowedScriptDomain("*"); + $policy->addAllowedConnectDomain("*"); + $policy->addAllowedStyleDomain("*"); + $policy->addAllowedMediaDomain("*"); + $policy->addAllowedFontDomain('*'); + $policy->addAllowedImageDomain('*'); + $policy->addAllowedFrameDomain('*'); + $policy->addAllowedObjectDomain('*'); + $policy->allowInlineScript(True); + $policy->allowInlineStyle(True); + $policy->allowEvalScript(True); + $response->setContentSecurityPolicy($policy); + + return $response; + } + +} diff --git a/js/viewer.js b/js/viewer.js new file mode 100644 index 0000000..f77f17e --- /dev/null +++ b/js/viewer.js @@ -0,0 +1,142 @@ +(function(OCA) { + + OCA.LibreOnline = OCA.LibreOnline || {}; + OCA.LibreOnline.Viewer = { + + + attach: function(fileList) { + this._extendFileActions(fileList.fileActions); + }, + + hide: function() { + $('#loframe').remove(); + if ($('#isPublic').val() && $('#filesApp').val()){ + $('#controls').removeClass('hidden'); + } + + FileList.setViewerMode(false); + + $('#app-content #controls').removeClass('hidden'); + }, + + + show: function(downloadUrl, isFileList) { + var self = this; + var $iframe; + var viewer = OC.generateUrl('/apps/libreonline/?file={file}', {file: downloadUrl}); + $iframe = $('