Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ryecoaaron committed May 26, 2016
0 parents commit 2c2a222
Show file tree
Hide file tree
Showing 16 changed files with 552 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
openmediavault-symlinks
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
openmediavault-symlinks (3.0) stable; urgency=low

* Initial release after separation from downloader plugin

-- OpenMediaVault Plugin Developers <plugins@omv-extras.org> Mon, 31 Aug 2015 07:00:14 -0500
1 change: 1 addition & 0 deletions debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9
16 changes: 16 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Source: openmediavault-symlinks
Section: net
XB-Plugin-Section: filesystems
Priority: optional
Maintainer: OpenMediaVault Plugin Developers <plugins@omv-extras.org>
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.
9 changes: 9 additions & 0 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Format: http://dep.debian.net/deps/dep5
Upstream-Contact: OpenMediaVault Plugin Developers <plugins@omv-extras.org>
Copyright: 2013-2016 OpenMediaVault Plugin Developers <plugins@omv-extras.org>
License: GPL-3

Files: /var/www/openmediavault/images/link.png
/var/www/openmediavault/images/link.svg
Copyright: IcoMoon <http://www.icomoon.io>
IcoMoon <http://www.icomoon.io>
2 changes: 2 additions & 0 deletions debian/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
usr/share/openmediavault/* usr/share/openmediavault
var/www/openmediavault/* var/www/openmediavault
1 change: 1 addition & 0 deletions debian/lintian-overrides
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dir-or-file-in-var-www
51 changes: 51 additions & 0 deletions debian/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/sh
#
# @license http://www.gnu.org/licenses/gpl.html GPL Version 3
# @author Volker Theile <volker.theile@openmediavault.org>
# @author OpenMediaVault Plugin Developers <plugins@omv-extras.org>
# @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 <http://www.gnu.org/licenses/>.

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
45 changes: 45 additions & 0 deletions debian/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh
#
# @license http://www.gnu.org/licenses/gpl.html GPL Version 3
# @author Volker Theile <volker.theile@openmediavault.org>
# @author OpenMediaVault Plugin Developers <plugins@omv-extras.org>
# @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 <http://www.gnu.org/licenses/>.

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
4 changes: 4 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/make -f

%:
dh $@
1 change: 1 addition & 0 deletions debian/source/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0 (native)
1 change: 1 addition & 0 deletions debian/triggers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
activate restart-engined
Original file line number Diff line number Diff line change
@@ -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": ""
}
}
}
26 changes: 26 additions & 0 deletions usr/share/openmediavault/datamodels/rpc.symlinks.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}]
130 changes: 130 additions & 0 deletions usr/share/openmediavault/engined/rpc/symlinks.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php
/**
* @license http://www.gnu.org/licenses/gpl.html GPL Version 3
* @author Volker Theile <volker.theile@openmediavault.org>
* @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 <http://www.gnu.org/licenses/>.
*/
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"
);
}
}
Loading

0 comments on commit 2c2a222

Please sign in to comment.