1. 参考网址:https://forum.openmediavault....
  2. 创建应用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
    ```

  3. 创建shell脚本
    生成配置信息的脚本postinst 命令执行:/bin/sh postinst configure

    ```

    #!/bin/sh

    set -e

    . /etc/default/openmediavault
    . /usr/share/openmediavault/scripts/helper-functions

    case "$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-functions

    SERVICE_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
    ```

  4. 创建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

  5. 创建shell脚本获取配置信息
    创建执行脚本 example 执行命令:omv-mkconf example

    ```

    #!/bin/sh

    set -e

    . /etc/default/openmediavault
    . /usr/share/openmediavault/scripts/helper-functions

    OMV_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")
    EOF

    exit 0
    ```

    为了监听触发执行脚本,将脚本放在/usr/share/openmediavault/mkconf目录下
    脚本权限改为 chmod 755 example

  6. 配置保存事件监听

    /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

  7. 创建deb包 https://blog.csdn.net/gatieme...

原文地址:https://segmentfault.com/a/1190000016716780

最新文章

  1. Java设计模式之策略模式(Strategy)
  2. Web AppBuilder Widget使用共享类库的方式
  3. SQL Server 2012 The report server cannot open a connection to the report server database
  4. Mysql使用workbench迁移数据
  5. Oracle在dos命令下导出导入
  6. 开源.net 混淆器ConfuserEx介绍
  7. css颜色大全-转载
  8. 1.表单中 get与post提交方法的区别?
  9. Leetcode: Length of Last Word in python
  10. Delphi 调试WEBService程序(ISAPI或CGI) 把Web App Debugger executable转换成 ISAPI/NSAPI
  11. FreeMarker---数据类型
  12. JS面向对象使用面向对象进行开发
  13. 我的Windows日常——Excel 打开.xls .xlsx 文件格式或文件扩展名无效
  14. 20175204 张湲祯 2018-2019-2《Java程序设计》2
  15. vue vue-route 传参 $route.params
  16. 20145326蔡馨熠《网络对抗》shellcode注入&amp;Return-to-libc攻击深入
  17. (转)SQL Server 列转行
  18. FAQ:枚举和常规的值,到底哪种更符合程序使用?
  19. Date 日期格式化
  20. LintCode-88.最近公共祖先

热门文章

  1. PAT团体程序设计天梯赛 - 模拟赛
  2. IOCP编程之基本原理
  3. 与Cookie相比,Web Storage存在的优势
  4. python正则表达式多次提取数据(一个规则提取多组数据)
  5. C. Arpa&#39;s loud Owf and Mehrdad&#39;s evil plan DFS + LCM
  6. canvas 平移&amp;缩放
  7. 代码文件导到word里
  8. ES6学习笔记(4)----正则的扩展
  9. git diff查看修改,出现^M换行问题
  10. XSS漏洞扫描经验分享