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一样,支持种类丰富的数据文件格式,但其最大特点为设计精巧的插件开发模式,在设计技巧上,系统提供了良好的封装特性,即使插件开发者对框 ...
随机推荐
- YCOJ黑熊过河
Description 有一只黑熊想过河,但河很宽,黑熊不会游泳,只能借助河面上的石墩跳过去,他可以一次跳一墩,也可以一次跳两墩,但是每起跳一次都会耗费一定的能量,黑熊最终可能因能量不够而掉入水中,所 ...
- shell Syntax error: Bad fd number 错误解决
最近在玩spark , 需要看一下python的spark lib 是怎么加入环境变量的. 执行: sh -x bin/pyspark 报错 + dirname bin/pyspark + cd bi ...
- iOS WKWebView 加载进度条、导航栏返回&关闭 (Swift 4)
导航: 1.加载进度条 2.导航栏增加返回.关闭按钮 加载进度条 效果图 代码如下: self.progressView.trackTintColor = UIColor.white self.pro ...
- April Fools Contest 2017 A
Description Input The input contains a single integer a (1 ≤ a ≤ 30). Output Output a single integer ...
- Steps to Resolve the Database JAVAVM Component if it Becomes INVALID After Applying an OJVM Patch
11.2.0.2升级到11.2.0.4 memory_target 设置过小,只有800M. 导致jserver jave virtual machine 组件无法安装, 建议升级之前至少memory ...
- 166 Fraction to Recurring Decimal 分数到小数
给定两个整数,分别表示分数的分子和分母,返回字符串格式的小数.如果小数部分为循环小数,则将重复部分括在括号内.例如, 给出 分子 = 1, 分母 = 2,返回 "0.5". ...
- HDU 2828 Lamp 二分图的最大匹配 模型题
http://acm.hdu.edu.cn/showproblem.php?pid=2828 给定n个灯,m个开关,使得每栈灯亮,前提是控制这栈灯的开关的状态是其中一个.(题目应该都看得懂) 其实我想 ...
- 使用 Realm 和 Swift 创建 ToDo 应用
原文出处: HOSSAM GHAREEB 译文出处:Prayer’s blog(@EclipsePrayer) 智能手机的快速发展的同时,涌现出了很多对开发者友好的开发工具,这些工具不仅使得开发变 ...
- 导Excel数据表
需要把EXcel转换格式:
- ubuntu用户自定义的命令alias永久生效
cd ~ vi .bash_profile alias ll='ls -ltr' . .bash_profile ps:写在.bashrc终端断开就没了