From c8be607e09c2fbd471bc90156c2cad7de9284ead Mon Sep 17 00:00:00 2001 From: "Ycarus (Yannick Chabanois)" Date: Wed, 11 Mar 2020 19:55:16 +0100 Subject: [PATCH] Convert luci-app-macvlan to client side rendering --- luci-app-macvlan/Makefile | 74 ++----------------- .../files/luci/controller/macvlan.lua | 10 --- .../files/luci/i18n/macvlan.zh-cn.po | 14 ---- .../files/luci/model/cbi/macvlan/macvlan.lua | 22 ------ .../resources/view/network/macvlan.js | 35 +++++++++ .../{files => }/root/etc/config/macvlan | 0 .../{files => }/root/etc/init.d/macvlan | 10 ++- .../root/etc/uci-defaults/40_luci-app-macvlan | 0 .../share/luci/menu.d/luci-app-macvlan.json | 10 +++ 9 files changed, 60 insertions(+), 115 deletions(-) delete mode 100644 luci-app-macvlan/files/luci/controller/macvlan.lua delete mode 100644 luci-app-macvlan/files/luci/i18n/macvlan.zh-cn.po delete mode 100644 luci-app-macvlan/files/luci/model/cbi/macvlan/macvlan.lua create mode 100644 luci-app-macvlan/htdocs/luci-static/resources/view/network/macvlan.js rename luci-app-macvlan/{files => }/root/etc/config/macvlan (100%) rename luci-app-macvlan/{files => }/root/etc/init.d/macvlan (95%) rename luci-app-macvlan/{files => }/root/etc/uci-defaults/40_luci-app-macvlan (100%) create mode 100644 luci-app-macvlan/root/usr/share/luci/menu.d/luci-app-macvlan.json diff --git a/luci-app-macvlan/Makefile b/luci-app-macvlan/Makefile index 8414d239a..5ad2647f5 100644 --- a/luci-app-macvlan/Makefile +++ b/luci-app-macvlan/Makefile @@ -1,5 +1,5 @@ # -# Copyright (C) 2017-2019 Chen Minqiang +# Copyright (C) 2020 Ycarus (Yannick Chabanois) for OpeenMPTCProuter # # This is free software, licensed under the GNU General Public License v3. # See /LICENSE for more information. @@ -7,72 +7,10 @@ include $(TOPDIR)/rules.mk -PKG_NAME:=luci-app-macvlan -PKG_VERSION:=1.0.0 -PKG_RELEASE:=1 +LUCI_TITLE:=LuCI Support for macvlan +LUC_PKGARCH:=all +LUCI_DEPENDS:=+kmod-macvlan +busybox +@BUSYBOX_CUSTOM +@BUSYBOX_CONFIG_VCONFIG -PKG_LICENSE:=GPLv3 -PKG_LICENSE_FILES:=LICENSE -PKG_MAINTAINER:=Chen Minqiang +include $(TOPDIR)/feeds/luci/luci.mk -PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) - -include $(INCLUDE_DIR)/package.mk - -define Package/luci-app-macvlan - CATEGORY:=OpenMPTCProuter - SUBMENU:=Macvlan - TITLE:=LuCI Support for macvlan - PKGARCH:=all - DEPENDS:=+kmod-macvlan +busybox +@BUSYBOX_CUSTOM +@BUSYBOX_CONFIG_VCONFIG -endef - -define Package/luci-app-macvlan/description - LuCI Support for macvlan. -endef - -define Build/Prepare - $(foreach po,$(wildcard ${CURDIR}/files/luci/i18n/*.po), \ - po2lmo $(po) $(PKG_BUILD_DIR)/$(patsubst %.po,%.lmo,$(notdir $(po)));) -endef - -define Build/Configure -endef - -define Build/Compile -endef - -define Package/luci-app-macvlan/postinst -#!/bin/sh -if [ -z "$${IPKG_INSTROOT}" ]; then - rm -rf /tmp/luci-indexcache /tmp/luci-modulecache -fi - -if [ -z "$$IPKG_INSTROOT" ]; then - ( . /etc/uci-defaults/40_luci-app-macvlan ) - rm -f /etc/uci-defaults/40_luci-app-macvlan -fi - -exit 0 -endef - -define Package/luci-app-macvlan/conffiles -/etc/config/macvlan -endef - -define Package/luci-app-macvlan/install - $(INSTALL_DIR) $(1)/usr/lib/lua/luci/i18n - $(INSTALL_DATA) $(PKG_BUILD_DIR)/macvlan.*.lmo $(1)/usr/lib/lua/luci/i18n/ - $(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller - $(INSTALL_DATA) ./files/luci/controller/*.lua $(1)/usr/lib/lua/luci/controller/ - $(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi/macvlan - $(INSTALL_DATA) ./files/luci/model/cbi/macvlan/*.lua $(1)/usr/lib/lua/luci/model/cbi/macvlan/ - $(INSTALL_DIR) $(1)/etc/config - $(INSTALL_DATA) ./files/root/etc/config/macvlan $(1)/etc/config/macvlan - $(INSTALL_DIR) $(1)/etc/init.d - $(INSTALL_BIN) ./files/root/etc/init.d/macvlan $(1)/etc/init.d/macvlan - $(INSTALL_DIR) $(1)/etc/uci-defaults - $(INSTALL_DATA) ./files/root/etc/uci-defaults/40_luci-app-macvlan $(1)/etc/uci-defaults/40_luci-app-macvlan -endef - -$(eval $(call BuildPackage,luci-app-macvlan)) +# call BuildPackage - OpenWrt buildroot signature \ No newline at end of file diff --git a/luci-app-macvlan/files/luci/controller/macvlan.lua b/luci-app-macvlan/files/luci/controller/macvlan.lua deleted file mode 100644 index 3207db1b8..000000000 --- a/luci-app-macvlan/files/luci/controller/macvlan.lua +++ /dev/null @@ -1,10 +0,0 @@ --- Copyright (C) 2019 X-WRT - -module("luci.controller.macvlan", package.seeall) - -function index() - local page - - page = entry({"admin", "network", "macvlan"}, cbi("macvlan/macvlan"), _("Macvlan")) - page.leaf = true -end diff --git a/luci-app-macvlan/files/luci/i18n/macvlan.zh-cn.po b/luci-app-macvlan/files/luci/i18n/macvlan.zh-cn.po deleted file mode 100644 index a06710760..000000000 --- a/luci-app-macvlan/files/luci/i18n/macvlan.zh-cn.po +++ /dev/null @@ -1,14 +0,0 @@ -msgid "" -msgstr "Content-Type: text/plain; charset=UTF-8\n" - -msgid "Macvlan" -msgstr "Macvlan" - -msgid "Macvlan Settings" -msgstr "Macvlan设置" - -msgid "Interface" -msgstr "网络接口" - -msgid "Index" -msgstr "序号" diff --git a/luci-app-macvlan/files/luci/model/cbi/macvlan/macvlan.lua b/luci-app-macvlan/files/luci/model/cbi/macvlan/macvlan.lua deleted file mode 100644 index 2bcba5f18..000000000 --- a/luci-app-macvlan/files/luci/model/cbi/macvlan/macvlan.lua +++ /dev/null @@ -1,22 +0,0 @@ --- Copyright (C) 2019 X-WRT - -local net = require "luci.model.network".init() -local ifaces = net:get_interfaces() or { net:get_interface() } - -m = Map("macvlan", translate("Macvlan"), translate("You can configure Macvlan virtual interfaces base on the real itnerface you want.")) - -s = m:section(TypedSection, "macvlan", translate("Macvlan Settings")) -s.addremove = true -s.anonymous = false -s.template = "cbi/tblsection" - -hn = s:option(Value, "ifname", translate("Interface")) -hn.rmempty = false - -for _, iface in ipairs(ifaces) do - if iface:type() ~= "macvlan" then - hn:value(iface:name(),"%s" % iface:name()) - end -end - -return m diff --git a/luci-app-macvlan/htdocs/luci-static/resources/view/network/macvlan.js b/luci-app-macvlan/htdocs/luci-static/resources/view/network/macvlan.js new file mode 100644 index 000000000..ffdf4514a --- /dev/null +++ b/luci-app-macvlan/htdocs/luci-static/resources/view/network/macvlan.js @@ -0,0 +1,35 @@ +'use strict'; +'require rpc'; +'require form'; +'require tools.widgets as widgets'; + +return L.view.extend({ + callHostHints: rpc.declare({ + object: 'luci-rpc', + method: 'getHostHints', + expect: { '': {} } + }), + + load: function() { + return this.callHostHints(); + }, + + render: function(hosts) { + var m, s, o; + + m = new form.Map('macvlan', _('Macvlan')); + + s = m.section(form.GridSection, 'macvlan', _('Interfaces')); + s.addremove = true; + s.anonymous = true; + + o = s.option(form.Value, 'name', _('Name')); + o.datatype = 'uciname'; + o.rmempty = false; + + o = s.option(widgets.DeviceSelect, 'ifname', _('Interface')); + o.rmempty = false; + + return m.render(); + } +}); diff --git a/luci-app-macvlan/files/root/etc/config/macvlan b/luci-app-macvlan/root/etc/config/macvlan similarity index 100% rename from luci-app-macvlan/files/root/etc/config/macvlan rename to luci-app-macvlan/root/etc/config/macvlan diff --git a/luci-app-macvlan/files/root/etc/init.d/macvlan b/luci-app-macvlan/root/etc/init.d/macvlan similarity index 95% rename from luci-app-macvlan/files/root/etc/init.d/macvlan rename to luci-app-macvlan/root/etc/init.d/macvlan index fcecf3ac8..eb51d3808 100755 --- a/luci-app-macvlan/files/root/etc/init.d/macvlan +++ b/luci-app-macvlan/root/etc/init.d/macvlan @@ -36,7 +36,15 @@ _save_macaddr() { _create_interface() { local _masterifname - local _ifname=$1 + config_get _ifname "$1" name + # Convert from old config without name defined + [ -z "$_ifname" ] && { + uci batch <<-EOF + set macvlan.$1.name=$1 + commit macvlan + EOF + _ifname=$1 + } config_get _masterifname "$1" ifname uci batch <<-EOF set network.$_ifname=interface diff --git a/luci-app-macvlan/files/root/etc/uci-defaults/40_luci-app-macvlan b/luci-app-macvlan/root/etc/uci-defaults/40_luci-app-macvlan similarity index 100% rename from luci-app-macvlan/files/root/etc/uci-defaults/40_luci-app-macvlan rename to luci-app-macvlan/root/etc/uci-defaults/40_luci-app-macvlan diff --git a/luci-app-macvlan/root/usr/share/luci/menu.d/luci-app-macvlan.json b/luci-app-macvlan/root/usr/share/luci/menu.d/luci-app-macvlan.json new file mode 100644 index 000000000..01c2164ee --- /dev/null +++ b/luci-app-macvlan/root/usr/share/luci/menu.d/luci-app-macvlan.json @@ -0,0 +1,10 @@ +{ + "admin/network/macvlan": { + "title": "Macvlan", + "order": 60, + "action": { + "type": "view", + "path": "network/macvlan" + } + } +}