openmediavault 4.1.3 插件开发
- 参考网址:https://forum.openmediavault....
创建应用GUI
创建应用目录:/var/www/openmediavault/js/omv/module/admin/service/example
创建菜单节点: Node.js```
// require("js/omv/WorkspaceManager.js")
OMV.WorkspaceManager.registerNode({
id: 'example',
path: '/service',
text: _('Example'),
icon16: 'images/example.png',
iconSvg: 'images/example.svg'
});
```设置菜单节点图标
var/www/openmediavault/images 内创建对应Node.js内的2张图片创建设置面板: Settings.js
```
// require("js/omv/WorkspaceManager.js")
// require("js/omv/workspace/form/Panel.js")
Ext.define('OMV.module.admin.service.example.Settings', {
extend: 'OMV.workspace.form.Panel',rpcService: 'Example',
rpcGetMethod: 'getSettings',
rpcSetMethod: 'setSettings',getFormItems: function() {
return [{
xtype: 'fieldset',
title: _('General'),
fieldDefaults: {
labelSeparator: ''
},
items: [{
xtype: 'checkbox',
name: 'enable',
fieldLabel: _('Enable'),
checked: false
},
{
xtype: 'numberfield',
name: 'max_value',
fieldLabel: _('Max value'),
minValue: 0,
maxValue: 100,
allowDecimals: false,
allowBlank: true
}]
}];
}
});OMV.WorkspaceManager.registerPanel({
id: 'settings',
path: '/service/example',
text: _('Settings'),
position: 10,
className: 'OMV.module.admin.service.example.Settings'
});
```刷新js缓存:
```
source /usr/share/openmediavault/scripts/helper-functions && omv_purge_internal_cache
```创建shell脚本
生成配置信息的脚本postinst 命令执行:/bin/sh postinst configure```
#!/bin/sh
set -e
. /etc/default/openmediavault
. /usr/share/openmediavault/scripts/helper-functionscase "$1" in
configure)
SERVICE_XPATH_NAME="example"
SERVICE_XPATH="/config/services/${SERVICE_XPATH_NAME}"# 添加默认配置
if ! omv_config_exists "${SERVICE_XPATH}"; then
omv_config_add_element "/config/services" "${SERVICE_XPATH_NAME}"
omv_config_add_element "${SERVICE_XPATH}" "enable" "0"
omv_config_add_element "${SERVICE_XPATH}" "max_value" "0"
fi# 以下2条命令用于安装包安装 直接执行可注释掉
dpkg-trigger update-fixperms
dpkg-trigger update-locale
;;abort-upgrade|abort-remove|abort-deconfigure)
;;*)
echo "postinst called with unknown argument" >&2
exit 1
;;
esac#DEBHELPER#
exit 0
```创建删除配置信息的shell脚本 postrm 执行命令:/bin/sh postrm purge
```
#!/bin/sh
set -e
. /etc/default/openmediavault
. /usr/share/openmediavault/scripts/helper-functionsSERVICE_XPATH_NAME="example"
SERVICE_XPATH="/config/services/${SERVICE_XPATH_NAME}"case "$1" in
purge)
if omv_config_exists ${SERVICE_XPATH}; then
omv_config_delete ${SERVICE_XPATH}
fi
;;remove)
;;upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
;;*)
echo "postrm called with unknown argument \\`$1'" >&2
exit 1
;;
esac#DEBHELPER#
exit 0
```创建rpc
在目录/usr/share/openmediavault/engined/rpc创建example.inc```
<?php
class OMVRpcServiceExample extends \OMV\Rpc\ServiceAbstract {public function getName() {
return "EXAMPLE";
}public function initialize() {
$this->registerMethod("getSettings");
$this->registerMethod("setSettings");
}public function getSettings($params, $context) {
// Validate the RPC caller context.
$this->validateMethodContext($context, [
"role" => OMV_ROLE_ADMINISTRATOR
]);
// Get the configuration object.
$db = \\OMV\\Config\\Database::getInstance();
$object = $db->get("conf.service.example");
// Remove useless properties from the object.
return $object->getAssoc();
}public function setSettings($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.example.setsettings");
// Get the existing configuration object.
$db = \\OMV\\Config\\Database::getInstance();
$object = $db->get("conf.service.example");
$object->setAssoc($params);
$db->set($object);
// Return the configuration object.
return $object->getAssoc();
}
}
```创建对应的配置文件
在usr\share\openmediavault\datamodels创建conf.service.example.json```
{
"type": "config",
"id": "conf.service.example",
"title": "EXAMPLE",
"queryinfo": {
"xpath": "//services/example",
"iterable": false
},
"properties": {
"enable": {
"type": "boolean",
"default": false
},
"max_value": {
"type": "integer",
"minimum": 1,
"maximum": 100,
"default": 0
}
}
}
```在usr\share\openmediavault\datamodels创建rpc.example.json
```
[{
"type": "rpc",
"id": "rpc.example.setsettings",
"params": {
"type": "object",
"properties": {
"enable": {
"type": "boolean",
"required": true
},
"max_value": {
"type": "integer",
"minimum": 1,
"maximum": 100,
"required": true
}
}
}
}]
```运行命令重启omv服务:service openmediavault-engined restart
创建shell脚本获取配置信息
创建执行脚本 example 执行命令:omv-mkconf example```
#!/bin/sh
set -e
. /etc/default/openmediavault
. /usr/share/openmediavault/scripts/helper-functionsOMV_EXAMPLE_XPATH="/config/services/example"
OMV_EXAMPLE_CONF="/tmp/example.conf"cat <<EOF > ${OMV_EXAMPLE_CONF}
enable = $(omv_config_get "${OMV_EXAMPLE_XPATH}/enable")
max_value = $(omv_config_get "${OMV_EXAMPLE_XPATH}/max_value")
EOFexit 0
```为了监听触发执行脚本,将脚本放在/usr/share/openmediavault/mkconf目录下
脚本权限改为 chmod 755 example配置保存事件监听
/usr/share/openmediavault/engined/module创建监听的example.inc
```
<?php
class OMVModuleExample extends \OMV\Engine\Module\ServiceAbstract
implements \OMV\Engine\Notify\IListener {
public function getName() {
return "EXAMPLE";
}public function applyConfig() {
// 触发对应执行脚本
$cmd = new \\OMV\\System\\Process("omv-mkconf", "example");
$cmd->setRedirect2to1();
$cmd->execute();
}function bindListeners(\\OMV\\Engine\\Notify\\Dispatcher $dispatcher) {
$dispatcher->addListener(OMV_NOTIFY_MODIFY,
"org.openmediavault.conf.service.example", // 和rpc内的配置文件一致conf.service.example
[ $this, "setDirty" ]);
}
}
```运行命令重启omv服务:service openmediavault-engined restart
- 创建deb包 https://blog.csdn.net/gatieme...
原文地址:https://segmentfault.com/a/1190000016716780
最新文章
- Java设计模式之策略模式(Strategy)
- Web AppBuilder Widget使用共享类库的方式
- SQL Server 2012 The report server cannot open a connection to the report server database
- Mysql使用workbench迁移数据
- Oracle在dos命令下导出导入
- 开源.net 混淆器ConfuserEx介绍
- css颜色大全-转载
- 1.表单中 get与post提交方法的区别?
- Leetcode: Length of Last Word in python
- Delphi 调试WEBService程序(ISAPI或CGI) 把Web App Debugger executable转换成 ISAPI/NSAPI
- FreeMarker---数据类型
- JS面向对象使用面向对象进行开发
- 我的Windows日常——Excel 打开.xls .xlsx 文件格式或文件扩展名无效
- 20175204 张湲祯 2018-2019-2《Java程序设计》2
- vue vue-route 传参 $route.params
- 20145326蔡馨熠《网络对抗》shellcode注入&;Return-to-libc攻击深入
- (转)SQL Server 列转行
- FAQ:枚举和常规的值,到底哪种更符合程序使用?
- Date 日期格式化
- LintCode-88.最近公共祖先