Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More generic #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# wopiviewer
# wopiviewer

Don't forget to to set the following in config.php
'wopi.secret'
'wopi.baseurl'
'wopi.oos'
'wopi.cabundle'

39 changes: 5 additions & 34 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,11 @@
* @copyright Hugo Gonzalez Labrador (CERN) 2017
*/

namespace OCA\WopiViewer\AppInfo;

use OCP\AppFramework\App;

require_once __DIR__ . '/autoload.php';

$app = new App('wopiviewer');
$container = $app->getContainer();
if (\OCP\Util::getVersion()[0] >= 10) {
$policy = new OCP\AppFramework\Http\EmptyContentSecurityPolicy();
$policy->addAllowedFrameDomain(\OC::$server->getConfig()->getSystemValue('wopi.oos','self'));
\OC::$server->getContentSecurityPolicyManager()->addDefaultPolicy($policy);
}

\OCP\Util::addScript('wopiviewer', 'script');
\OCP\Util::addStyle('wopiviewer', 'style');

/*
$container->query('OCP\INavigationManager')->add(function () use ($container) {
$urlGenerator = $container->query('OCP\IURLGenerator');
$l10n = $container->query('OCP\IL10N');
return [
// the string under which your app will be referenced in owncloud
'id' => 'wopiviewer',

// sorting weight for the navigation. The higher the number, the higher
// will it be listed in the navigation
'order' => 10,

// the route that will be shown on startup
'href' => $urlGenerator->linkToRoute('wopiviewer.page.index'),

// the icon that will be shown in the navigation
// this file needs to exist in img/
'icon' => $urlGenerator->imagePath('wopiviewer', 'app.svg'),

// the title of your application. This will be used in the
// navigation or on the settings page of your app
'name' => $l10n->t('Wopi Viewer'),
];
});
*/
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
<namespace>WopiViewer</namespace>
<category>other</category>
<dependencies>
<owncloud min-version="8.2.2" />
<owncloud min-version="8.2.2" max-version="20.0" />
</dependencies>
</info>
6 changes: 3 additions & 3 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
return [
'routes' => [
['name' => 'page#do_open', 'url' => '/open', 'verb' => 'POST'],
['name' => 'page#do_public_open', 'url' => '/publicopen', 'verb' => 'POST'],
['name' => 'page#do_open', 'url' => '/open', 'verb' => 'POST'],
['name' => 'page#do_public_open', 'url' => '/publicopen', 'verb' => 'POST'],
]
];
];
33 changes: 24 additions & 9 deletions controller/pagecontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,36 @@
namespace OCA\WopiViewer\Controller;

use Guzzle\Http\Client;
use OC\Files\ObjectStore\EosProxy;
use OC\Files\ObjectStore\EosUtil;
//use OC\Files\ObjectStore\EosProxy;
//use OC\Files\ObjectStore\EosUtil;
use OCP\IRequest;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Controller;
use Punic\Data;
use OC\Files\Filesystem;
use OC\Files\View;

class PageController extends Controller {


private $userId;
private $wopiBaseUrl;
private $wopiSecret;
private $wopiOOS;

public function __construct($AppName, IRequest $request, $UserId) {
parent::__construct($AppName, $request);
$this->userId = $UserId;
$this->wopiSecret = \OC::$server->getConfig()->getSystemValue("wopi.secret", "please change me");
$this->wopiBaseUrl = \OC::$server->getConfig()->getSystemValue("wopi.baseurl", "http://wopiserver-test:8080");
$this->wopiCABundle = \OC::$server->getConfig()->getSystemValue("wopi.cabundle", true);
$this->wopiOOS = \OC::$server->getConfig()->getSystemValue("wopi.oos", "https://oos-test");

$view = new \OC\Files\View('/' . $UserId);
if (!$view->is_dir('wopi')) {
$view->mkdir('wopi');
}
}

/**
Expand All @@ -56,25 +65,29 @@ public function index() {
* @NoAdminRequired
*/
public function doOpen($filename, $folderurl) {
$username = \OC::$server->getUserSession()->getUser()->getUID();
/*
$username = \OC::$server->getUserSession()->getLoginName();
$uidAndGid = EosUtil::getUidAndGid($username);
if($uidAndGid === null) {
return new DataResponse(['error' => 'username does not have a valid uid and gid']); }
list($uid, $gid) = $uidAndGid;
if(!$uid || !$gid) {
return new DataResponse(['error' => 'username does not have a valid uid and gid']);
}

}*/
$node = \OC::$server->getUserFolder($username)->get($filename);
$info = $node->stat();
$eosPath = $info['eospath'];
//$eosPath = $info['eospath'];
$eosPath = $node->getPath();
$uid = $info['uid'];
$gid = $info['gid'];
$canedit = "false"; // we send boolean as strings to wopi
if ($node->isReadable()) {
if($node->isUpdateable()) {
$canedit = "true";
}
$client = new Client();
$request = $client->createRequest("GET", sprintf("%s/cbox/open", $this->wopiBaseUrl), null, null, ['verify' => $this->wopiCABundle]);
$request = $client->createRequest("GET", sprintf("%s/wopi/cbox/open", $this->wopiBaseUrl), null, null, ['verify' => $this->wopiCABundle]);
$request->addHeader("Authorization", "Bearer " . $this->wopiSecret);
$request->getQuery()->add("ruid", $uid);
$request->getQuery()->add("rgid", $gid);
Expand All @@ -92,7 +105,7 @@ public function doOpen($filename, $folderurl) {
if ($response->getStatusCode() == 200) {
$body = $response->getBody(true);
$body = urldecode($body);
return new DataResponse(['wopi_src' => $body]);
return new DataResponse(['wopi_src' => $body, 'oos' => $this->wopiOOS]);
} else {
return new DataResponse(['error' => 'error opening file in wopi server']);
}
Expand Down Expand Up @@ -121,6 +134,7 @@ public function doPublicOpen($filename, $canedit, $token, $folderurl) {

$owner = $row['uid_owner'];
$fileID = $row['item_source'];
/*
$uidAndGid = EosUtil::getUidAndGid($owner);
if($uidAndGid === null) {
return new DataResponse(['error' => 'username does not have a valid uid and gid']);
Expand All @@ -129,6 +143,7 @@ public function doPublicOpen($filename, $canedit, $token, $folderurl) {
if(!$uid || !$gid) {
return new DataResponse(['error' => 'username does not have a valid uid and gid']);
}
*/

$canedit="false";
if((int)($row['permissions']) > 1) {
Expand All @@ -142,7 +157,7 @@ public function doPublicOpen($filename, $canedit, $token, $folderurl) {
$eosPath = $info['eospath'];
if ($node->isReadable()) {
$client = new Client();
$request = $client->createRequest("GET", sprintf("%s/cbox/open", $this->wopiBaseUrl), null, null, ['verify' => $this->wopiCABundle]);
$request = $client->createRequest("GET", sprintf("%s/wopi/cbox/open", $this->wopiBaseUrl), null, null, ['verify' => $this->wopiCABundle]);
$request->addHeader("Authorization", "Bearer " . $this->wopiSecret);
$request->getQuery()->add("ruid", $uid);
$request->getQuery()->add("rgid", $gid);
Expand All @@ -154,7 +169,7 @@ public function doPublicOpen($filename, $canedit, $token, $folderurl) {
if ($response->getStatusCode() == 200) {
$body = $response->getBody(true);
$body = urldecode($body);
return new DataResponse(['wopi_src' => $body]);
return new DataResponse(['wopi_src' => $body, 'oos' => $this->wopiOOS]);
} else {
return new DataResponse(['error' => 'error opening file in wopi server']);
}
Expand Down
Loading