From 1bb9b83c5ac8713fe0d1172152eed6254844a60c Mon Sep 17 00:00:00 2001 From: lean Date: Sun, 20 Jun 2021 13:51:09 +0800 Subject: [PATCH] luci-app-easymesh: add package from ntlf9t --- package/lean/luci-app-easymesh/Makefile | 13 +++ .../luasrc/controller/easymesh.lua | 15 +++ .../luasrc/model/cbi/easymesh.lua | 70 ++++++++++++ .../luci-app-easymesh/po/zh-cn/easymesh.po | 47 ++++++++ package/lean/luci-app-easymesh/po/zh_Hans | 1 + .../root/etc/config/easymesh | 3 + .../root/etc/init.d/easymesh | 107 ++++++++++++++++++ .../root/etc/uci-defaults/luci-easymesh | 11 ++ .../share/rpcd/acl.d/luci-app-easymesh.json | 11 ++ 9 files changed, 278 insertions(+) create mode 100755 package/lean/luci-app-easymesh/Makefile create mode 100755 package/lean/luci-app-easymesh/luasrc/controller/easymesh.lua create mode 100755 package/lean/luci-app-easymesh/luasrc/model/cbi/easymesh.lua create mode 100755 package/lean/luci-app-easymesh/po/zh-cn/easymesh.po create mode 120000 package/lean/luci-app-easymesh/po/zh_Hans create mode 100755 package/lean/luci-app-easymesh/root/etc/config/easymesh create mode 100755 package/lean/luci-app-easymesh/root/etc/init.d/easymesh create mode 100755 package/lean/luci-app-easymesh/root/etc/uci-defaults/luci-easymesh create mode 100644 package/lean/luci-app-easymesh/root/usr/share/rpcd/acl.d/luci-app-easymesh.json diff --git a/package/lean/luci-app-easymesh/Makefile b/package/lean/luci-app-easymesh/Makefile new file mode 100755 index 000000000..a1da04bbf --- /dev/null +++ b/package/lean/luci-app-easymesh/Makefile @@ -0,0 +1,13 @@ +# +#-- Copyright (C) 2021 dz +# + +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=LuCI Support for easymesh +LUCI_DEPENDS:= +kmod-cfg80211 +batctl-default +kmod-batman-adv +wpad-openssl +PKG_VERSION:=1.6 + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/package/lean/luci-app-easymesh/luasrc/controller/easymesh.lua b/package/lean/luci-app-easymesh/luasrc/controller/easymesh.lua new file mode 100755 index 000000000..19e24ac82 --- /dev/null +++ b/package/lean/luci-app-easymesh/luasrc/controller/easymesh.lua @@ -0,0 +1,15 @@ +#-- Copyright (C) 2021 dz + +module("luci.controller.easymesh", package.seeall) + +function index() + if not nixio.fs.access("/etc/config/easymesh") then + return + end + + local page + + page = entry({"admin", "network", "easymesh"}, cbi("easymesh"), _("EASY MESH"), 60) + page.dependent = true + page.acl_depends = { "luci-app-easymesh" } +end diff --git a/package/lean/luci-app-easymesh/luasrc/model/cbi/easymesh.lua b/package/lean/luci-app-easymesh/luasrc/model/cbi/easymesh.lua new file mode 100755 index 000000000..de8222e12 --- /dev/null +++ b/package/lean/luci-app-easymesh/luasrc/model/cbi/easymesh.lua @@ -0,0 +1,70 @@ +-- Copyright (C) 2021 dz + +local m,s,o +local sys = require "luci.sys" +local uci = require "luci.model.uci".cursor() + +m = Map("easymesh") + +function detect_Node() + local data = {} + local lps = luci.util.execi(" batctl n 2>/dev/null | tail +2 | sed 's/^[ ][ ]*//g' | sed 's/[ ][ ]*/ /g' | sed 's/$/ /g' ") + for value in lps do + local row = {} + local pos = string.find(value, " ") + local IFA = string.sub(value, 1, pos - 1) + local value = string.sub(value, pos + 1, string.len(value)) + pos = string.find(value, " ") + local pos = string.find(value, " ") + local Neighbora = string.sub(value, 1, pos - 1) + local value = string.sub(value, pos + 1, string.len(value)) + pos = string.find(value, " ") + local pos = string.find(value, " ") + local lastseena = string.sub(value, 1, pos - 1) + local value = string.sub(value, pos + 1, string.len(value)) + pos = string.find(value, " ") + row["IF"] = IFA + row["Neighbor"] = Neighbora + row["lastseen"] = lastseena + table.insert(data, row) + end + return data +end +local Nodes = luci.sys.exec("batctl n 2>/dev/null| tail +3 | wc -l") +local Node = detect_Node() +v = m:section(Table, Node, "" ,translate("Active node:" .. Nodes .. "")) +v:option(DummyValue, "IF") +v:option(DummyValue, "Neighbor") +v:option(DummyValue, "lastseen") + +-- Basic +s = m:section(TypedSection, "easymesh", translate("Settings"), translate("General Settings")) +s.anonymous = true + +---- Eanble +o = s:option(Flag, "enabled", translate("Enable"), translate("Enable or disable EASY MESH")) +o.default = 0 +o.rmempty = false + +apRadio = s:option(ListValue, "apRadio", translate("MESH Radio device"), translate("The radio device which MESH use")) +uci:foreach("wireless", "wifi-device", + function(s) + apRadio:value(s['.name']) + end) +o.default = "radio0" +o.rmempty = false + +---- mesh +o = s:option(Value, "mesh_id", translate("MESH ID")) +o.default = "easymesh" +o.description = translate("MESH ID") + +enable = s:option(Flag, "encryption", translate("Encryption"), translate("")) +enable.default = 0 +enable.rmempty = false + +o = s:option(Value, "key", translate("Key")) +o.default = "easymesh" +o:depends("encryption", 1) + +return m diff --git a/package/lean/luci-app-easymesh/po/zh-cn/easymesh.po b/package/lean/luci-app-easymesh/po/zh-cn/easymesh.po new file mode 100755 index 000000000..ade62b5ea --- /dev/null +++ b/package/lean/luci-app-easymesh/po/zh-cn/easymesh.po @@ -0,0 +1,47 @@ +msgid "" +msgstr "Content-Type: text/plain; charset=UTF-8\n" + +msgid "easymesh" +msgstr "easymesh" + +msgid "Active node:" .. Nodes .. "" +msgstr "活动节点:" .. Nodes .. "" + +msgid "IF" +msgstr "IF" + +msgid "Neighbor" +msgstr "节点邻居设备" + +msgid "lastseen" +msgstr "上次连接延时" + +msgid "EASY MESH" +msgstr "简单MESH" + +msgid "Settings" +msgstr "设置" + +msgid "General Settings" +msgstr "基本设置" + +msgid "Enable" +msgstr "启用" + +msgid "MESH Radio device" +msgstr "MESH无线设备" + +msgid "The radio device which MESH use" +msgstr "使用MESH组网的无线设备" + +msgid "AUTO" +msgstr "自动" + +msgid "Enable or disable EASY MESH" +msgstr "启用或禁用简单MESH" + +msgid "Encryption" +msgstr "加密" + +msgid "Key" +msgstr "密码" diff --git a/package/lean/luci-app-easymesh/po/zh_Hans b/package/lean/luci-app-easymesh/po/zh_Hans new file mode 120000 index 000000000..41451e4a1 --- /dev/null +++ b/package/lean/luci-app-easymesh/po/zh_Hans @@ -0,0 +1 @@ +zh-cn \ No newline at end of file diff --git a/package/lean/luci-app-easymesh/root/etc/config/easymesh b/package/lean/luci-app-easymesh/root/etc/config/easymesh new file mode 100755 index 000000000..3446d21c1 --- /dev/null +++ b/package/lean/luci-app-easymesh/root/etc/config/easymesh @@ -0,0 +1,3 @@ + +config easymesh 'config' + option enabled '0' diff --git a/package/lean/luci-app-easymesh/root/etc/init.d/easymesh b/package/lean/luci-app-easymesh/root/etc/init.d/easymesh new file mode 100755 index 000000000..975e69f68 --- /dev/null +++ b/package/lean/luci-app-easymesh/root/etc/init.d/easymesh @@ -0,0 +1,107 @@ +#!/bin/sh /etc/rc.common +START=99 +STOP=10 + +enable=$(uci get easymesh.config.enabled 2>/dev/null) +mesh_bat0=$(uci get network.bat0 2>/dev/null) +mesh_nwi_mesh0=$(uci get network.nwi_mesh0 2>/dev/null) +mesh_mesh0=$(uci get wireless.mesh0 2>/dev/null) +lan=$(uci get network.lan.ifname 2>/dev/null) +mesh_id=$(uci get easymesh.config.mesh_id 2>/dev/null) +apRadio=$(uci get easymesh.config.apRadio 2>/dev/null) +mesh0_apRadio=$(uci get wireless.mesh0.device 2>/dev/null) +encryption=$(uci get easymesh.config.encryption 2>/dev/null) +key=$(uci get easymesh.config.key 2>/dev/null) + +start(){ + if [ "$enable" == 1 ]; then + if [ "$mesh_bat0" != "interface" ]; then + uci set network.bat0=interface + uci set network.bat0.proto='batadv' + uci set network.bat0.routing_algo='BATMAN_IV' + uci set network.bat0.aggregated_ogms='1' + #uci set network.bat0.gw_bandwidth='10000/2000' + uci set network.bat0.ap_isolation='0' + uci set network.bat0.bonding='0' + uci set network.bat0.fragmentation='1' + uci set network.bat0.gw_mode='off' + #uci set network.bat0.gw_sel_class='20' + uci set network.bat0.log_level='0' + uci set network.bat0.orig_interval='1000' + uci set network.bat0.bridge_loop_avoidance='1' + uci set network.bat0.distributed_arp_table='1' + uci set network.bat0.multicast_mode='1' + uci set network.bat0.network_coding='0' + uci set network.bat0.hop_penalty='30' + uci set network.bat0.isolation_mark='0x00000000/0x00000000' + + uci add_list network.lan.ifname='bat0' + uci commit network + fi + + if [ "$mesh_nwi_mesh0" != "interface" ]; then + uci set network.nwi_mesh0=interface + uci set network.nwi_mesh0.proto='batadv_hardif' + uci set network.nwi_mesh0.mtu='2304' + uci set network.nwi_mesh0.master='bat0' + uci commit network + fi + + if [ "$mesh_mesh0" != "wifi-iface" ]; then + uci set wireless.mesh0=wifi-iface + uci set wireless.mesh0.device=$apRadio + uci set wireless.mesh0.ifname='mesh0' + uci set wireless.mesh0.network='nwi_mesh0' + uci set wireless.mesh0.mode='mesh' + uci set wireless.mesh0.mesh_fwding='0' + uci set wireless.mesh0.mesh_id=$mesh_id + uci commit wireless + fi + + if [ "$mesh_mesh0" = "wifi-iface" ]; then + if [ "$mesh0_apRadio" != "$apRadio" ]; then + uci set wireless.mesh0.device=$apRadio + uci commit wireless + fi + fi + + if [ "$encryption" != 1 ]; then + uci set wireless.mesh0.encryption='none' + uci commit wireless + else + uci set wireless.mesh0.encryption='sae' + uci set wireless.mesh0.key=$key + uci commit wireless + fi + + /etc/init.d/network restart + else + stop + fi +} + +stop(){ + if [ "$enable" != 1 ]; then + if [ "$mesh_bat0" = "interface" ]; then + uci delete network.bat0 + uci del_list network.lan.ifname='bat0' + uci commit network + fi + + if [ "$mesh_nwi_mesh0" = "interface" ]; then + uci delete network.nwi_mesh0 + uci commit network + fi + + if [ "$mesh_mesh0" = "wifi-iface" ]; then + uci delete wireless.mesh0 + uci commit wireless + fi + + /etc/init.d/network restart + fi +} + +restart() { + start +} diff --git a/package/lean/luci-app-easymesh/root/etc/uci-defaults/luci-easymesh b/package/lean/luci-app-easymesh/root/etc/uci-defaults/luci-easymesh new file mode 100755 index 000000000..92b07747e --- /dev/null +++ b/package/lean/luci-app-easymesh/root/etc/uci-defaults/luci-easymesh @@ -0,0 +1,11 @@ +#!/bin/sh + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@easymesh[-1] + add ucitrack easymesh + set ucitrack.@easymesh[-1].init=easymesh + commit ucitrack +EOF + +rm -f /tmp/luci-indexcache +exit 0 diff --git a/package/lean/luci-app-easymesh/root/usr/share/rpcd/acl.d/luci-app-easymesh.json b/package/lean/luci-app-easymesh/root/usr/share/rpcd/acl.d/luci-app-easymesh.json new file mode 100644 index 000000000..4d435948a --- /dev/null +++ b/package/lean/luci-app-easymesh/root/usr/share/rpcd/acl.d/luci-app-easymesh.json @@ -0,0 +1,11 @@ +{ + "luci-app-easymesh": { + "description": "Grant UCI access for luci-app-easymesh", + "read": { + "uci": [ "easymesh" ] + }, + "write": { + "uci": [ "easymesh" ] + } + } +} \ No newline at end of file