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
openmediavault 4.1.3 插件开发的更多相关文章
- JavaScript学习笔记(四)——jQuery插件开发与发布
jQuery插件就是以jQuery库为基础衍生出来的库,jQuery插件的好处是封装功能,提高了代码的复用性,加快了开发速度,现在网络上开源的jQuery插件非常多,随着版本的不停迭代越来越稳定好用, ...
- jira的插件开发流程实践
怎么开头呢,由于自己比较懒,博客一直不怎么弄,以后克己一点,多传点自己遇到的问题和经历上来,供自己以后记忆,也供需要的小伙伴少走点弯路吧 最近公司项目需要竞标一个运维项目,甲方给予了既定的几种比较常用 ...
- Vue插件开发入门
相对组件来说,Vue 的插件开发受到的关注要少一点.但是插件的功能是十分强大的,能够完成许多 Vue 框架本身不具备的功能. 大家一般习惯直接调用现成的插件,比如官方推荐的 vue-router.vu ...
- 【原创】记一次Project插件开发
一.开发背景 最近在使用微软的Office Project 2010 进行项目管理,看到排的满满的计划任务,一个个地被执行完毕,还是很有成就感的.其实,不光是在工作中可以使用Project进行项目进度 ...
- JavaScript学习总结(四)——jQuery插件开发与发布
jQuery插件就是以jQuery库为基础衍生出来的库,jQuery插件的好处是封装功能,提高了代码的复用性,加快了开发速度,现在网络上开源的jQuery插件非常多,随着版本的不停迭代越来越稳定好用, ...
- [Tool] Open Live Writer插件开发
一 前言 Windows Live Writer(简称 WLW)开源之后变成 Open Live Writer(简称 OLW),原先 WLW 的插件在 OLW 下都不能用了,原因很简单,WLW 插件开 ...
- VS插件开发 - 登录身份验证
[附加] 很多朋友问那个VS背景怎么弄的,我刚刚已经抽时间把制作步骤发出来了: 请参见<VS插件开发 - 个性化VS IDE编辑器,瞬间 高 大 上>. 最近一直在忙着一些事情,一直没有发 ...
- jQuery插件开发精品教程,让你的jQuery提升一个台阶
要说jQuery 最成功的地方,我认为是它的可扩展性吸引了众多开发者为其开发插件,从而建立起了一个生态系统.这好比大公司们争相做平台一样,得平台者得天下.苹果,微软,谷歌等巨头,都有各自的平台及生态圈 ...
- 开源遥感平台opticks插件开发指南
Opticks是一款开源的遥感数据处理平台,与其同类开源软件OSSIM一样,支持种类丰富的数据文件格式,但其最大特点为设计精巧的插件开发模式,在设计技巧上,系统提供了良好的封装特性,即使插件开发者对框 ...
随机推荐
- 强连通分量再探 By cellur925
我真的好喜欢图论啊. (虽然可能理解的并不深hhh) 上一次(暑假)我们初探了强联通分量,这一次我们再探.(特别感谢pku-lyc老师的课件.有很多引用) 上次我们忘记讨论复杂度了.tarjan老爷爷 ...
- Educational Codeforces Round 19 A
Description Given a positive integer n, find k integers (not necessary distinct) such that all these ...
- 18.3.2从Class上获取信息(内部类接口等)
内部类 接口.枚举.注释类型
- 使用kubeadm安装kubernetes v1.14.1
使用kubeadm安装kubernetes v1.14.1 一.环境准备 操作系统:Centos 7.5 ⼀ 一台或多台运⾏行行着下列列系统的机器器: Ubuntu 16.04+ Debi ...
- 修改他人电脑的Windows登录密码
在别人电脑已登录Windows的情况下: 打开控制面板 -> 管理工具 -> 计算机管理 或者 对Win图标单击右键 -> 计算机管理 -> 本地用户和组 -> 用 ...
- T4312 最大出栈顺序
题目描述 给你一个栈和n个数,按照n个数的顺序入栈,你可以选择在任何时候将数 出栈,使得出栈的序列的字典序最大. 输入输出格式 输入格式: 输入共2行. 第一行个整数n,表示入栈序列长度. 第二行包含 ...
- new操作符具体干了什么
function Func(){ }; var newFunc=new Func (); new共经过了4个阶段 1.创建一个空对象 var obj=new Object(); 2.设置原型链 把 o ...
- iOS圆形图片裁剪,原型图片外面加一个圆环
/** * 在圆形外面加一个圆环 */ - (void)yuanHuan{ //0.加载图片 UIImage *image = [UIImage imageNamed:@"AppIcon1 ...
- redis集群架构(含面试题解析)
老规矩,我还是以循序渐进的方式来讲,我一共经历过三套集群架构的演进! Replication+Sentinel 这套架构使用的是社区版本推出的原生高可用解决方案,其架构图如下! 这里Sentinel的 ...
- Data Center Manager Leveraging OpenStack
这是去年的一个基于OpenStack的数据中心管理软件的想法. Abstract OpenStack facilates users to provision and manage cloud ser ...