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

Fixed Keeweb application for NC 28.x.x #231

Merged
merged 2 commits into from
Jan 4, 2024
Merged
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ keeweb-source/
keeweb/build/
keeweb/templates/keeweb.php
keeweb/templates/service-worker.js
keeweb/js/viewer.js
keeweb/js/viewer.js.map
keeweb/js/viewer.js.LICENSE.txt
keeweb/node_modules/
.idea/
13 changes: 11 additions & 2 deletions keeweb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ endif
.PHONY: npm
npm:
ifeq (,$(wildcard $(CURDIR)/package.json))
cd js && $(npm) run build
cd js && $(npm) install && $(npm) run build
else
npm run build
$(npm) install && $(npm) run build
endif

# Removes the appstore build
Expand All @@ -107,6 +107,7 @@ distclean: clean
# Builds the source and appstore package
.PHONY: dist
dist:
make build
make source
make appstore

Expand All @@ -118,6 +119,10 @@ source:
tar --exclude-vcs \
--exclude="../$(app_name)/build" \
--exclude="../$(app_name)/js/node_modules" \
--exclude="../$(app_name)/js/viewer.js.LICENSE.txt" \
--exclude="../$(app_name)/js/viewer.js.map" \
--exclude="../$(app_name)/package.json" \
--exclude="../$(app_name)/package-lock.json" \
--exclude="../$(app_name)/node_modules" \
--exclude="../$(app_name)/*.log" \
--exclude="../$(app_name)/js/*.log" \
Expand All @@ -138,6 +143,10 @@ appstore:
--exclude="../$(app_name)/js/node_modules" \
--exclude="../$(app_name)/js/tests" \
--exclude="../$(app_name)/js/test" \
--exclude="../$(app_name)/js/viewer.js.LICENSE.txt" \
--exclude="../$(app_name)/js/viewer.js.map" \
--exclude="../$(app_name)/package-lock.json" \
--exclude="../$(app_name)/node_modules" \
--exclude="../$(app_name)/js/*.log" \
--exclude="../$(app_name)/js/package.json" \
--exclude="../$(app_name)/js/bower.json" \
Expand Down
13 changes: 8 additions & 5 deletions keeweb/appinfo/info.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?xml version="1.0"?>
<info xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
<info xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
<id>keeweb</id>
<name>Keeweb</name>
<summary>Open Keepass stores</summary>
<description>Open Keepass stores inside Nextcloud with Keeweb just by clicking on an *.kdbx file in your Nextcloud.</description>
<version>0.6.13</version>
<description>Open Keepass stores inside Nextcloud with Keeweb just by clicking on an *.kdbx file in your
Nextcloud.
</description>
<version>0.6.14</version>
<licence>agpl</licence>
<author>Jonne Haß, Arno Welzel</author>
<author>Jonne Haß, Arno Welzel, Florian Forestier</author>
<namespace>Keeweb</namespace>
<category>tools</category>
<category>integration</category>
Expand All @@ -15,7 +18,7 @@
<repository>https://github.com/jhass/nextcloud-keeweb</repository>
<screenshot>https://arnowelzel.de/download/nextcloud-keeweb.gif</screenshot>
<dependencies>
<nextcloud min-version="16" max-version="27" />
<nextcloud min-version="28" max-version="28"/>
</dependencies>
<repair-steps>
<install>
Expand Down
10 changes: 5 additions & 5 deletions keeweb/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
*/
return [
'routes' => [
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'page#keeweb', 'url' => '/keeweb', 'verb' => 'GET'],
['name' => 'page#manifest', 'url' => '/manifest.appcache', 'verb' => 'GET'],
['name' => 'page#config', 'url' => '/config', 'verb' => 'GET'],
['name' => 'page#serviceworker', 'url' => '/service-worker.js', 'verb' => 'GET']
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'page#keeweb', 'url' => '/keeweb', 'verb' => 'GET'],
['name' => 'page#manifest', 'url' => '/manifest.appcache', 'verb' => 'GET'],
['name' => 'page#config', 'url' => '/config', 'verb' => 'GET'],
['name' => 'page#serviceworker', 'url' => '/service-worker.js', 'verb' => 'GET']
]
];
41 changes: 3 additions & 38 deletions keeweb/js/viewer.js

Large diffs are not rendered by default.

43 changes: 23 additions & 20 deletions keeweb/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,30 @@
*/

namespace OCA\Keeweb\AppInfo;

use OCA\Keeweb\Controller\PageController;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Util;
use Psr\Container\ContainerInterface;
use OCP\Files\IMimeTypeDetector;

class Application extends App implements IBootstrap {
class Application extends App {
public function __construct(){
parent::__construct('keeweb');
}
$appName = "keeweb";

parent::__construct($appName);

public function register(IRegistrationContext $context): void {
if (array_key_exists("REQUEST_URI", \OC::$server->getRequest()->server))
{
$url = \OC::$server->getRequest()->server["REQUEST_URI"];
if (isset($url)) {
if (preg_match("%/apps/files(/.*)?%", $url) || str_contains($url, "/s/")) // Files app and file sharing
{
Util::addScript($appName, "viewer");
}
}
}

$context = $this->getContainer();
$context->registerService('PageController', function (ContainerInterface $c) {
return new PageController(
$c->query('AppName'),
Expand All @@ -34,16 +42,11 @@ public function register(IRegistrationContext $context): void {
$c->query('Config')
);
});
}

public function boot(IBootContext $context): void {
$context->injectFn(function (IEventDispatcher $eventDispatcher) {
$eventDispatcher->addListener(
'OCA\Files::loadAdditionalScripts',
function() {
Util::addScript('keeweb', 'viewer');
}
);
});
$detector = $context->query(IMimeTypeDetector::class);
$detector->getAllMappings();
$detector->registerType("kdbx", "application/x-kdbx");

}
}

}
8 changes: 3 additions & 5 deletions keeweb/lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,10 @@ private function getCSP() {
$csp->addAllowedConnectDomain("'self'");
$csp->addAllowedConnectDomain('https://services.keeweb.info');
$csp->addAllowedScriptDomain('https://plugins.keeweb.info');
$csp->addAllowedScriptDomain("'unsafe-inline'");
$csp->addAllowedConnectDomain('https://plugins.keeweb.info');
$csp->addAllowedChildSrcDomain("blob:");
$csp->addAllowedChildSrcDomain("'self'");
$csp->allowEvalScript(true);
$csp->allowInlineScript(true);
$csp->allowInlineStyle(true);
$csp->allowEvalScript(true);
$csp->allowInlineStyle();
return $csp;
}
}
3 changes: 2 additions & 1 deletion keeweb/lib/Migration/MimeTypeMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace OCA\Keeweb\Migration;

use OCP\Files\IMimeTypeLoader;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;

abstract class MimeTypeMigration implements IRepairStep
{
const CUSTOM_MIMETYPEMAPPING = 'mimetypemapping.json';
const CUSTOM_MIMETYPEALIASES = 'mimetypealiases.json';

protected $mimeTypeLoader;
protected $updateJS;

public function __construct(IMimeTypeLoader $mimeTypeLoader)
{
Expand Down
34 changes: 21 additions & 13 deletions keeweb/lib/Migration/RegisterMimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace OCA\Keeweb\Migration;

use OCP\Files\IMimeTypeLoader;
require \OC::$SERVERROOT . "/3rdparty/autoload.php";

use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;

class RegisterMimeType extends MimeTypeMigration
{
Expand All @@ -21,19 +21,15 @@ private function registerForExistingFiles()

private function registerForNewFiles()
{
$mapping = ['kdbx' => ['application/x-kdbx']];
$mappingFile = \OC::$configDir . self::CUSTOM_MIMETYPEMAPPING;

if (file_exists($mappingFile)) {
$existingMapping = json_decode(file_get_contents($mappingFile), true);
if (json_last_error() === JSON_ERROR_NONE && is_array($existingMapping)) {
$mapping = array_merge($existingMapping, $mapping);
}
}
$configDir = \OC::$configDir;
$mimetypealiasesFile = $configDir . self::CUSTOM_MIMETYPEALIASES;
$mimetypemappingFile = $configDir . self::CUSTOM_MIMETYPEMAPPING;

file_put_contents($mappingFile, json_encode($mapping, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
$this->appendToFile($mimetypealiasesFile, ['application/x-kdbx' => 'kdbx']);
$this->appendToFile($mimetypemappingFile, ['kdbx' => ['application/x-kdbx']]);
}


public function run(IOutput $output)
{
$output->info('Registering the mimetype...');
Expand All @@ -46,4 +42,16 @@ public function run(IOutput $output)

$output->info('The mimetype was successfully registered.');
}
}

private function appendToFile(string $filename, array $data) {
$obj = [];
if (file_exists($filename)) {
$content = file_get_contents($filename);
$obj = json_decode($content, true);
}
foreach ($data as $key => $value) {
$obj[$key] = $value;
}
file_put_contents($filename, json_encode($obj, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
}
}
32 changes: 19 additions & 13 deletions keeweb/lib/Migration/UnregisterMimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace OCA\Keeweb\Migration;

use OCP\Files\IMimeTypeLoader;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;

class UnregisterMimeType extends MimeTypeMigration
{
Expand All @@ -21,17 +19,12 @@ private function unregisterForExistingFiles()

private function unregisterForNewFiles()
{
$mappingFile = \OC::$configDir . self::CUSTOM_MIMETYPEMAPPING;

if (file_exists($mappingFile)) {
$mapping = json_decode(file_get_contents($mappingFile), true);
if (json_last_error() === JSON_ERROR_NONE && is_array($mapping)) {
unset($mapping['kdbx']);
} else {
$mapping = [];
}
file_put_contents($mappingFile, json_encode($mapping, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
}
$configDir = \OC::$configDir;
$mimetypealiasesFile = $configDir . self::CUSTOM_MIMETYPEALIASES;
$mimetypemappingFile = $configDir . self::CUSTOM_MIMETYPEMAPPING;

$this->removeFromFile($mimetypealiasesFile, ['application/x-kdbx' => 'kdbx']);
$this->removeFromFile($mimetypemappingFile, ['kdbx' => ['application/x-kdbx']]);
}

public function run(IOutput $output)
Expand All @@ -46,4 +39,17 @@ public function run(IOutput $output)

$output->info('The mimetype was successfully unregistered.');
}


private function removeFromFile(string $filename, array $data) {
$obj = [];
if (file_exists($filename)) {
$content = file_get_contents($filename);
$obj = json_decode($content, true);
}
foreach ($data as $key => $value) {
unset($obj[$key]);
}
file_put_contents($filename, json_encode($obj, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
}
}
Loading