From 2c2a222a22c86749efcb0fa3ad3d11a56f902c1f Mon Sep 17 00:00:00 2001 From: Aaron Murray Date: Wed, 25 May 2016 21:57:12 -0500 Subject: [PATCH] initial commit --- README.md | 1 + debian/changelog | 5 + debian/compat | 1 + debian/control | 16 ++ debian/copyright | 9 + debian/install | 2 + debian/lintian-overrides | 1 + debian/postinst | 51 ++++ debian/postrm | 45 ++++ debian/rules | 4 + debian/source/format | 1 + debian/triggers | 1 + .../conf.service.symlinks.symlink.json | 28 +++ .../datamodels/rpc.symlinks.json | 26 ++ .../openmediavault/engined/rpc/symlinks.inc | 130 ++++++++++ .../module/admin/service/symlinks/Symlinks.js | 231 ++++++++++++++++++ 16 files changed, 552 insertions(+) create mode 100755 README.md create mode 100755 debian/changelog create mode 100755 debian/compat create mode 100755 debian/control create mode 100755 debian/copyright create mode 100755 debian/install create mode 100755 debian/lintian-overrides create mode 100755 debian/postinst create mode 100755 debian/postrm create mode 100755 debian/rules create mode 100755 debian/source/format create mode 100755 debian/triggers create mode 100755 usr/share/openmediavault/datamodels/conf.service.symlinks.symlink.json create mode 100755 usr/share/openmediavault/datamodels/rpc.symlinks.json create mode 100755 usr/share/openmediavault/engined/rpc/symlinks.inc create mode 100755 var/www/openmediavault/js/omv/module/admin/service/symlinks/Symlinks.js diff --git a/README.md b/README.md new file mode 100755 index 0000000..cf119c1 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +openmediavault-symlinks \ No newline at end of file diff --git a/debian/changelog b/debian/changelog new file mode 100755 index 0000000..a5eadb6 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +openmediavault-symlinks (3.0) stable; urgency=low + + * Initial release after separation from downloader plugin + + -- OpenMediaVault Plugin Developers Mon, 31 Aug 2015 07:00:14 -0500 diff --git a/debian/compat b/debian/compat new file mode 100755 index 0000000..ec63514 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +9 diff --git a/debian/control b/debian/control new file mode 100755 index 0000000..fc6be17 --- /dev/null +++ b/debian/control @@ -0,0 +1,16 @@ +Source: openmediavault-symlinks +Section: net +XB-Plugin-Section: filesystems +Priority: optional +Maintainer: OpenMediaVault Plugin Developers +Build-Depends: debhelper (>= 9.0.0 ) +Standards-Version: 3.9.6 +Homepage: http://omv-extras.org/ + +Package: openmediavault-symlinks +Architecture: all +Depends: openmediavault (>= 3.0.19), + openmediavault-omvextrasorg (>= 3.2), + ${misc:Depends} +Description: OpenMediaVault symlinks plugin + Allow creation of symlinks. \ No newline at end of file diff --git a/debian/copyright b/debian/copyright new file mode 100755 index 0000000..52fb2be --- /dev/null +++ b/debian/copyright @@ -0,0 +1,9 @@ +Format: http://dep.debian.net/deps/dep5 +Upstream-Contact: OpenMediaVault Plugin Developers +Copyright: 2013-2016 OpenMediaVault Plugin Developers +License: GPL-3 + +Files: /var/www/openmediavault/images/link.png + /var/www/openmediavault/images/link.svg +Copyright: IcoMoon +IcoMoon diff --git a/debian/install b/debian/install new file mode 100755 index 0000000..46ca1cd --- /dev/null +++ b/debian/install @@ -0,0 +1,2 @@ +usr/share/openmediavault/* usr/share/openmediavault +var/www/openmediavault/* var/www/openmediavault diff --git a/debian/lintian-overrides b/debian/lintian-overrides new file mode 100755 index 0000000..c712afb --- /dev/null +++ b/debian/lintian-overrides @@ -0,0 +1 @@ +dir-or-file-in-var-www diff --git a/debian/postinst b/debian/postinst new file mode 100755 index 0000000..d42975c --- /dev/null +++ b/debian/postinst @@ -0,0 +1,51 @@ +#!/bin/sh +# +# @license http://www.gnu.org/licenses/gpl.html GPL Version 3 +# @author Volker Theile +# @author OpenMediaVault Plugin Developers +# @copyright Copyright (c) 2009-2013 Volker Theile +# @copyright Copyright (c) 2013-2016 OpenMediaVault Plugin Developers +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set -e + +. /etc/default/openmediavault +. /usr/share/openmediavault/scripts/helper-functions + +case "$1" in + configure) + SERVICE_XPATH_NAME="symlinks" + SERVICE_XPATH="/config/services/${SERVICE_XPATH_NAME}" + + if ! omv_config_exists "${SERVICE_XPATH}"; then + echo "Initialize configuration" + omv_config_add_element "/config/services" "${SERVICE_XPATH_NAME}" + omv_config_add_element "${SERVICE_XPATH}" "symlinks" "" + fi + + dpkg-trigger update-fixperms + dpkg-trigger update-locale + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument '$1'" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/debian/postrm b/debian/postrm new file mode 100755 index 0000000..9e00583 --- /dev/null +++ b/debian/postrm @@ -0,0 +1,45 @@ +#!/bin/sh +# +# @license http://www.gnu.org/licenses/gpl.html GPL Version 3 +# @author Volker Theile +# @author OpenMediaVault Plugin Developers +# @copyright Copyright (c) 2009-2013 Volker Theile +# @copyright Copyright (c) 2013-2016 OpenMediaVault Plugin Developers +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set -e + +. /etc/default/openmediavault +. /usr/share/openmediavault/scripts/helper-functions + +case "$1" in + remove) + ;; + + purge) + # Remove the configuration data + omv_config_delete "/config/services/symlinks" + ;; + + upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + ;; + + *) + echo "postrm called with unknown argument '$1'" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..2d33f6a --- /dev/null +++ b/debian/rules @@ -0,0 +1,4 @@ +#!/usr/bin/make -f + +%: + dh $@ diff --git a/debian/source/format b/debian/source/format new file mode 100755 index 0000000..89ae9db --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native) diff --git a/debian/triggers b/debian/triggers new file mode 100755 index 0000000..c182f8d --- /dev/null +++ b/debian/triggers @@ -0,0 +1 @@ +activate restart-engined diff --git a/usr/share/openmediavault/datamodels/conf.service.symlinks.symlink.json b/usr/share/openmediavault/datamodels/conf.service.symlinks.symlink.json new file mode 100755 index 0000000..3645236 --- /dev/null +++ b/usr/share/openmediavault/datamodels/conf.service.symlinks.symlink.json @@ -0,0 +1,28 @@ +{ + "type": "config", + "id": "conf.service.symlinks.symlink", + "title": "Symlinks symlink", + "queryinfo": { + "xpath": "//services/symlinks/symlinks/symlink", + "iterable": true, + "idproperty": "uuid" + }, + "properties": { + "uuid": { + "type": "string", + "format": "uuidv4" + }, + "enable: { + "type": "boolean", + "default": false + }, + "source": { + "type": "string", + "default": "" + }, + "destination": { + "type": "string", + "default": "" + } + } +} diff --git a/usr/share/openmediavault/datamodels/rpc.symlinks.json b/usr/share/openmediavault/datamodels/rpc.symlinks.json new file mode 100755 index 0000000..0fab56c --- /dev/null +++ b/usr/share/openmediavault/datamodels/rpc.symlinks.json @@ -0,0 +1,26 @@ +[{ + "type": "rpc", + "id": "rpc.symlinks.setsymlink", + "params": { + "type": "object", + "properties": { + "uuid": { + "type": "string", + "format": "uuidv4", + "required": true + }, + "enable: { + "type": "boolean", + "required": true + }, + "source": { + "type": "string", + "required": true + }, + "destination": { + "type": "string", + "required": true + } + } + } +}] diff --git a/usr/share/openmediavault/engined/rpc/symlinks.inc b/usr/share/openmediavault/engined/rpc/symlinks.inc new file mode 100755 index 0000000..aa5444d --- /dev/null +++ b/usr/share/openmediavault/engined/rpc/symlinks.inc @@ -0,0 +1,130 @@ + + * @copyright Copyright (c) 2009-2013 Volker Theile + * @copyright Copyright (c) 2013-2016 OpenMediaVault Plugin Developers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +require_once("openmediavault/object.inc"); +require_once("openmediavault/config.inc"); +require_once("openmediavault/error.inc"); +require_once("openmediavault/util.inc"); +require_once("openmediavault/rpcservice.inc"); +require_once("openmediavault/notify.inc"); + +class OMVRpcServiceSymlinks extends OMVRpcServiceAbstract +{ + public function getName() + { + return "Symlinks"; + } + + public function initialize() + { + $this->registerMethod("getSymlinkList"); + $this->registerMethod("getSymlink"); + $this->registerMethod("setSymlink"); + $this->registerMethod("deleteSymlink"); + } + + public function getSymlinkList($params, $context) + { + // Validate the RPC caller context. + $this->validateMethodContext($context, ["role" => OMV_ROLE_ADMINISTRATOR]); + // Validate the parameters of the RPC service method. + $this->validateMethodParams($params, "rpc.common.getlist"); + // Get the configuration object. + $db = \OMV\Config\Database::getInstance(); + $objects = $db->get("conf.service.symlinks.symlink"); + // Filter the result. + return $this->applyFilter($objects, $params['start'], $params['limit'], + $params['sortfield'], $params['sortdir']); + } + + public function getSymlink($params, $context) + { + // Validate the RPC caller context. + $this->validateMethodContext($context, ["role" => OMV_ROLE_ADMINISTRATOR]); + // Validate the parameters of the RPC service method. + $this->validateMethodParams($params, "rpc.common.objectuuid"); + // Get the configuration object. + $db = \OMV\Config\Database::getInstance(); + return $db->getAssoc("conf.service.symlinks.symlink", $params['uuid']); + } + + public function setSymlink($params, $context) + { + // Validate the RPC caller context. + $this->validateMethodContext($context, ["role" => OMV_ROLE_ADMINISTRATOR]); + // Validate the parameters of the RPC service method. + $this->validateMethodParams($params, "rpc.symlinks.setsymlink"); + // Prepare the configuration object. + $object = new \OMV\Config\ConfigObject("conf.service.symlinks.symlink"); + $object->setAssoc($params); + // Set the configuration object. + $isNew = $object->isNew(); + $db = \OMV\Config\Database::getInstance(); + // remove old symbolic link if modifying existing symlink + if ($isNew == OMV_NOTIFY_MODIFY) { + $oldObject = $db->getAssoc("conf.service.symlinks.symlink", $params['uuid']); + if (is_link($oldObject->get('destination'))) { + unlink($oldObject->get('destination')); + } + } + $db->set($object); + + if ($object->('enable') === true) { + // Create symbolic link + $success = false; + $success = symlink($object->get('source'), $object->('destination')); + if (false === $success) { + throw new \OMV\Exception( + sprintf( + "Failed to create symbolic link at %s", + $object->get('destination') + ) + ); + } + } + // Notify configuration changes. + $dispatcher = \OMV\Engine\Notify\Dispatcher::getInstance(); + $dispatcher->notify( + $isNew ? OMV_NOTIFY_CREATE : OMV_NOTIFY_MODIFY, + "org.openmediavault.services.symlinks.symlink", + $object->getAssoc() + ); + // Return the configuration object. + return $object->getAssoc(); + } + + public function deleteSymlink($params, $context) + { + // Validate the RPC caller context. + $this->validateMethodContext($context, ["role" => OMV_ROLE_ADMINISTRATOR]); + // Validate the parameters of the RPC service method. + $this->validateMethodParams($params, "rpc.common.objectuuid"); + // remove old symbolic link + if (is_link($params['destination'])) { + unlink($params['destination']); + } + // Delete the configuration object. + return $this->deleteConfigObjectByUuid( + "conf.service.symlinks.symlink", + $params['uuid'], + "org.openmediavault.services.symlinks.symlink" + ); + } +} diff --git a/var/www/openmediavault/js/omv/module/admin/service/symlinks/Symlinks.js b/var/www/openmediavault/js/omv/module/admin/service/symlinks/Symlinks.js new file mode 100755 index 0000000..f06f20b --- /dev/null +++ b/var/www/openmediavault/js/omv/module/admin/service/symlinks/Symlinks.js @@ -0,0 +1,231 @@ +/** + * @license http://www.gnu.org/licenses/gpl.html GPL Version 3 + * @author Volker Theile + * @author OpenMediaVault Plugin Developers + * @copyright Copyright (c) 2009-2013 Volker Theile + * @copyright Copyright (c) 2013-2016 OpenMediaVault Plugin Developers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ +// require("js/omv/WorkspaceManager.js") +// require("js/omv/workspace/grid/Panel.js") +// require("js/omv/workspace/window/Form.js") +// require("js/omv/workspace/window/plugin/ConfigObject.js") +// require("js/omv/util/Format.js") +// require("js/omv/Rpc.js") +// require("js/omv/data/Store.js") +// require("js/omv/data/Model.js") +// require("js/omv/data/proxy/Rpc.js") +// require("js/omv/window/RootFolderBrowser.js") + +Ext.define("OMV.module.admin.service.symlinks.Symlink", { + extend : "OMV.workspace.window.Form", + requires : [ + "OMV.workspace.window.plugin.ConfigObject" + ], + uses: [ + "OMV.data.Model", + "OMV.data.Store", + "OMV.window.RootFolderBrowser" + ], + + rpcService : "Symlinks", + rpcGetMethod : "getSymlink", + rpcSetMethod : "setSymlink", + plugins : [{ + ptype : "configobject" + }], + + width : 600, + + getFormItems : function() { + var me = this; + return [{ + xtype : "checkbox", + name : "enable", + fieldLabel : _("Enable"), + checked : true + },{ + xtype : "textfield", + name : "source", + fieldLabel : _("Source"), + allowBlank : false, + triggers : { + folder : { + cls : Ext.baseCSSPrefix + "form-folder-trigger", + handler : "onTriggerClick" + } + }, + onTriggerClick : function() { + Ext.create("OMV.window.RootFolderBrowser", { + listeners : { + scope : this, + select : function(wnd, node, path) { + // Set the selected path. + this.setValue(path); + } + } + }).show(); + } + },{ + xtype : "textfield", + name : "destination", + fieldLabel : _("Destination"), + allowBlank : false, + triggers : { + folder : { + cls : Ext.baseCSSPrefix + "form-folder-trigger", + handler : "onTriggerClick" + } + }, + onTriggerClick : function() { + Ext.create("OMV.window.RootFolderBrowser", { + listeners : { + scope : this, + select : function(wnd, node, path) { + // Set the selected path. + this.setValue(path); + } + } + }).show(); + } + }]; + } +}); + +Ext.define("OMV.module.admin.service.symlinks.Symlinks", { + extend : "OMV.workspace.grid.Panel", + requires : [ + "OMV.Rpc", + "OMV.data.Store", + "OMV.data.Model", + "OMV.data.proxy.Rpc", + "OMV.util.Format" + ], + uses : [ + "OMV.module.admin.service.symlinks.Symlink" + ], + + hidePagingToolbar : false, + stateful : true, + stateId : "a982a76d-6804-3637-b31b-8b48c0ea6dde", + columns : [{ + xtype : "booleaniconcolumn", + text : _("Enabled"), + sortable : true, + dataIndex : "enable", + stateId : "enable", + align : "center", + width : 80, + resizable : false, + trueIcon : "switch_on.png", + falseIcon : "switch_off.png" + },{ + text : _("Source"), + sortable : true, + dataIndex : "source", + stateId : "source" + },{ + text : _("Destination"), + sortable : true, + dataIndex : "destination", + stateId : "destination" + }], + + initComponent: function() { + var me = this; + Ext.apply(me, { + store : Ext.create("OMV.data.Store", { + autoLoad : true, + model : OMV.data.Model.createImplicit({ + idProperty : "uuid", + fields : [ + { name : "uuid", type: "string" }, + { name : "enable", type: "boolean" }, + { name : "source", type: "string" }, + { name : "destination", type: "string" } + ] + }), + proxy : { + type : "rpc", + rpcData : { + service : "Symlinks", + method : "getSymlinkList" + } + } + }) + }); + me.callParent(arguments); + }, + + onAddButton : function() { + var me = this; + Ext.create("OMV.module.admin.service.symlinks.Symlink", { + title : _("Add symlink"), + uuid : OMV.UUID_UNDEFINED, + listeners : { + scope : me, + submit : function() { + this.doReload(); + } + } + }).show(); + }, + + onEditButton : function() { + var me = this; + var record = me.getSelected(); + Ext.create("OMV.module.admin.service.symlinks.Symlink", { + title : _("Edit symlink"), + uuid : record.get("uuid"), + listeners : { + scope : me, + submit : function() { + this.doReload(); + } + } + }).show(); + }, + + doDeletion : function(record) { + var me = this; + OMV.Rpc.request({ + scope : me, + callback : me.onDeletion, + rpcData : { + service : "Symlinks", + method : "deleteSymlink", + params : { + uuid : record.get("uuid") + } + } + }); + } +}); + +OMV.WorkspaceManager.registerNode({ + id : "symlinks", + path : "/service", + text : _("Symlinks"), + icon16 : "images/downloader.png", + iconSvg : "images/downloader.svg" +}); + +OMV.WorkspaceManager.registerPanel({ + id : "symlinks", + path : "/service/symlinks", + text : _("Symlinks"), + position : 10, + className : "OMV.module.admin.service.symlinks.Symlinks" +});