From 636317fdeb43dce76bd915b0245c14c59212f53c Mon Sep 17 00:00:00 2001 From: ling <1042585959@qq.com> Date: Wed, 24 Apr 2024 21:27:26 +0800 Subject: [PATCH] =?UTF-8?q?modem=E6=9B=B4=E6=96=B0V1.4.1=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=8F=92=E4=BB=B6=E9=A1=B5=E9=9D=A2=E9=80=89=E9=A1=B9?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=89=8B=E5=8A=A8=E6=A8=A1=E7=BB=84?= =?UTF-8?q?=E6=89=AB=E6=8F=8F=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=89=8B=E5=8A=A8=E9=85=8D=E7=BD=AE=E6=A8=A1=E7=BB=84=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- luci-app-modem/Makefile | 2 +- luci-app-modem/luasrc/controller/modem.lua | 26 +- .../cbi/modem/{config.lua => dial_config.lua} | 39 +- .../modem/{index.lua => dial_overview.lua} | 14 +- .../luasrc/model/cbi/modem/modem_config.lua | 130 ++++ .../luasrc/model/cbi/modem/plugin_config.lua | 76 +++ .../luasrc/view/modem/modem_info.htm | 2 +- .../luasrc/view/modem/modem_scan.htm | 46 ++ .../luasrc/view/modem/plugin_info.htm | 2 +- luci-app-modem/po/zh-cn/modem.po | 65 +- luci-app-modem/po/zh_Hans | 603 +++++++++++++++++- luci-app-modem/root/etc/config/modem | 3 +- luci-app-modem/root/etc/init.d/modem | 88 ++- .../root/etc/uci-defaults/luci-app-modem | 3 +- .../root/usr/share/modem/fibocom.sh | 2 +- .../root/usr/share/modem/modem_init.sh | 1 - .../usr/share/modem/modem_network_task.sh | 4 +- .../root/usr/share/modem/modem_scan.sh | 298 ++------- .../root/usr/share/modem/modem_task.sh | 4 +- .../root/usr/share/modem/modem_util.sh | 46 +- .../root/usr/share/modem/quectel.sh | 2 +- 21 files changed, 1133 insertions(+), 323 deletions(-) rename luci-app-modem/luasrc/model/cbi/modem/{config.lua => dial_config.lua} (81%) rename luci-app-modem/luasrc/model/cbi/modem/{index.lua => dial_overview.lua} (86%) create mode 100644 luci-app-modem/luasrc/model/cbi/modem/modem_config.lua create mode 100644 luci-app-modem/luasrc/model/cbi/modem/plugin_config.lua create mode 100644 luci-app-modem/luasrc/view/modem/modem_scan.htm diff --git a/luci-app-modem/Makefile b/luci-app-modem/Makefile index a5b8c81..113f298 100644 --- a/luci-app-modem/Makefile +++ b/luci-app-modem/Makefile @@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-modem LUCI_TITLE:=LuCI support for Modem LUCI_PKGARCH:=all -PKG_VERSION:=1.4.0 +PKG_VERSION:=1.4.1 PKG_LICENSE:=GPLv3 PKG_LINCESE_FILES:=LICENSE PKF_MAINTAINER:=siriling diff --git a/luci-app-modem/luasrc/controller/modem.lua b/luci-app-modem/luasrc/controller/modem.lua index eb418f0..ed41a5d 100644 --- a/luci-app-modem/luasrc/controller/modem.lua +++ b/luci-app-modem/luasrc/controller/modem.lua @@ -20,8 +20,8 @@ function index() entry({"admin", "network", "modem", "get_modem_info"}, call("getModemInfo")).leaf = true --拨号配置 - entry({"admin", "network", "modem", "index"},cbi("modem/index"),translate("Dial Config"),20).leaf = true - entry({"admin", "network", "modem", "config"}, cbi("modem/config")).leaf = true + entry({"admin", "network", "modem", "dial_overview"},cbi("modem/dial_overview"),translate("Dial Overview"),20).leaf = true + entry({"admin", "network", "modem", "dial_config"}, cbi("modem/dial_config")).leaf = true entry({"admin", "network", "modem", "get_modems"}, call("getModems"), nil).leaf = true entry({"admin", "network", "modem", "get_dial_log_info"}, call("getDialLogInfo"), nil).leaf = true entry({"admin", "network", "modem", "clean_dial_log"}, call("cleanDialLog"), nil).leaf = true @@ -39,8 +39,13 @@ function index() entry({"admin", "network", "modem", "send_at_command"}, call("sendATCommand"), nil).leaf = true -- entry({"admin", "network", "modem", "get_modem_debug_info"}, call("getModemDebugInfo"), nil).leaf = true + --插件设置 + entry({"admin", "network", "modem", "plugin_config"},cbi("modem/plugin_config"),translate("Plugin Config"),40).leaf = true + entry({"admin", "network", "modem", "modem_config"}, cbi("modem/modem_config")).leaf = true + entry({"admin", "network", "modem", "modem_scan"}, call("modemScan"), nil).leaf = true + --插件信息 - entry({"admin", "network", "modem", "plugin_info"},template("modem/plugin_info"),translate("Plugin Info"),40).leaf = true + entry({"admin", "network", "modem", "plugin_info"},template("modem/plugin_info"),translate("Plugin Info"),50).leaf = true entry({"admin", "network", "modem", "get_plugin_info"}, call("getPluginInfo"), nil).leaf = true --AT命令旧界面 @@ -452,7 +457,7 @@ end ]] function getModemRemarks(network) local remarks="" - uci:foreach("modem", "config", function (config) + uci:foreach("modem", "dial-config", function (config) ---配置启用,且备注存在 if network == config["network"] and config["enable"] == "1" then if config["remarks"] then @@ -748,6 +753,19 @@ end -- luci.http.write_json(modem_debug_info) -- end +--[[ +@Description 模组扫描 +]] +function modemScan() + + local command="source "..script_path.."modem_scan.sh && modem_scan" + local result=shell(command) + + -- 写入Web界面 + luci.http.prepare_content("application/json") + luci.http.write_json(result) +end + --[[ @Description 设置插件版本信息 @Params diff --git a/luci-app-modem/luasrc/model/cbi/modem/config.lua b/luci-app-modem/luasrc/model/cbi/modem/dial_config.lua similarity index 81% rename from luci-app-modem/luasrc/model/cbi/modem/config.lua rename to luci-app-modem/luasrc/model/cbi/modem/dial_config.lua index 4a33c5d..4970b60 100644 --- a/luci-app-modem/luasrc/model/cbi/modem/config.lua +++ b/luci-app-modem/luasrc/model/cbi/modem/dial_config.lua @@ -2,10 +2,10 @@ local dispatcher = require "luci.dispatcher" local uci = require "luci.model.uci".cursor() local http = require "luci.http" -m = Map("modem", translate("Modem Config")) -m.redirect = dispatcher.build_url("admin", "network", "modem","index") +m = Map("modem", translate("Dial Config")) +m.redirect = dispatcher.build_url("admin", "network", "modem","dial_overview") -s = m:section(NamedSection, arg[1], "config", "") +s = m:section(NamedSection, arg[1], "dial-config", "") s.addremove = false s.dynamic = false s:tab("general", translate("General Settings")) @@ -35,18 +35,29 @@ function getMobileNetwork() network:value("",translate("Mobile network not found")) end - for i=0,modem_number-1 do + -- for i=0,modem_number-1 do + -- --获取模块名 + -- local modem_name = uci:get('modem','modem'..i,'name') + -- if modem_name == nil then + -- modem_name = "unknown" + -- end + -- --设置网络 + -- modem_network = uci:get('modem','modem'..i,'network') + -- if modem_network ~= nil then + -- network:value(modem_network,modem_network.." ("..translate(modem_name:upper())..")") + -- end + -- end + + uci:foreach("modem", "modem-device", function (modem_device) + --获取模块名 - local modem_name = uci:get('modem','modem'..i,'name') - if modem_name == nil then - modem_name = "unknown" - end - --设置网络 - modem_network = uci:get('modem','modem'..i,'network') - if modem_network ~= nil then - network:value(modem_network,modem_network.." ("..translate(modem_name:upper())..")") - end - end + local modem_name=modem_device["name"] + --获取网络 + local modem_network=modem_device["network"] + + --设置网络值 + network:value(modem_network,modem_network.." ("..translate(modem_name:upper())..")") + end) end getMobileNetwork() diff --git a/luci-app-modem/luasrc/model/cbi/modem/index.lua b/luci-app-modem/luasrc/model/cbi/modem/dial_overview.lua similarity index 86% rename from luci-app-modem/luasrc/model/cbi/modem/index.lua rename to luci-app-modem/luasrc/model/cbi/modem/dial_overview.lua index b6746ec..daaee29 100644 --- a/luci-app-modem/luasrc/model/cbi/modem/index.lua +++ b/luci-app-modem/luasrc/model/cbi/modem/dial_overview.lua @@ -2,26 +2,26 @@ local d = require "luci.dispatcher" local uci = luci.model.uci.cursor() m = Map("modem") -m.title = translate("Dial Config") -m.description = translate("Add dialing configuration to all modules on this page") +m.title = translate("Dial Overview") +m.description = translate("Check and add modem dialing configurations") --全局配置 s = m:section(NamedSection, "global", "global", translate("Global Config")) s.anonymous = true s.addremove = false -o = s:option(Flag, "enable", translate("Enable")) +o = s:option(Flag, "enable_dial", translate("Enable")) o.rmempty = false -o.description = translate("Check to enable all configurations") +o.description = translate("Enable dial configurations") -- 添加模块状态 m:append(Template("modem/modem_status")) -s = m:section(TypedSection, "config", translate("Config List")) +s = m:section(TypedSection, "dial-config", translate("Config List")) s.anonymous = true s.addremove = true s.template = "modem/tblsection" -s.extedit = d.build_url("admin", "network", "modem", "config", "%s") +s.extedit = d.build_url("admin", "network", "modem", "dial_config", "%s") function s.create(uci, t) local uuid = string.gsub(luci.sys.exec("echo -n $(cat /proc/sys/kernel/random/uuid)"), "-", "") @@ -32,7 +32,7 @@ end function s.remove(uci, t) uci.map.proceed = true uci.map:del(t) - luci.http.redirect(d.build_url("admin", "network", "modem","index")) + luci.http.redirect(d.build_url("admin", "network", "modem","dial_overview")) end o = s:option(Flag, "enable", translate("Enable")) diff --git a/luci-app-modem/luasrc/model/cbi/modem/modem_config.lua b/luci-app-modem/luasrc/model/cbi/modem/modem_config.lua new file mode 100644 index 0000000..48c2261 --- /dev/null +++ b/luci-app-modem/luasrc/model/cbi/modem/modem_config.lua @@ -0,0 +1,130 @@ +local dispatcher = require "luci.dispatcher" +local uci = require "luci.model.uci".cursor() +local sys = require "luci.sys" +local json = require("luci.jsonc") +local script_path="/usr/share/modem/" + +--[[ +@Description 执行Shell脚本 +@Params + command sh命令 +]] +function shell(command) + local odpall = io.popen(command) + local odp = odpall:read("*a") + odpall:close() + return odp +end + +--[[ +@Description 获取支持的模组信息 +]] +function getSupportModems() + local command="cat "..script_path.."modem_support.json" + local result=json.parse(shell(command)) + return result["modem_support"]["usb"] +end + +--[[ +@Description 按照制造商给模组分类 +@Params + support_modem 支持的模组 +]] +function getManufacturers(support_modem) + + local manufacturers={} + + for modem in pairs(support_modem) do + + local manufacturer=support_modem[modem]["manufacturer"] + if manufacturers[manufacturer] then + -- 直接插入 + table.insert(manufacturers[manufacturer],modem) + else + -- 不存在先创建一个空表 + local tmp={} + table.insert(tmp,modem) + manufacturers[manufacturer]=tmp + end + end + + return manufacturers +end + +m = Map("modem", translate("Modem Config")) +m.redirect = dispatcher.build_url("admin", "network", "modem","plugin_config") + +s = m:section(NamedSection, arg[1], "modem-device", "") +s.addremove = false +s.dynamic = false + +-- 移动网络 +mobile_network = s:option(ListValue, "network", translate("Mobile Network")) +mobile_network.rmempty = true + +-- 获取移动网络 +function getMobileNetwork() + + --获取所有的网络接口 + local networks = sys.exec("ls -l /sys/class/net/ 2>/dev/null |awk '{print $9}' 2>/dev/null") + + --遍历所有网络接口 + for network in string.gmatch(networks, "%S+") do + + -- 只处理最上级的网络设备 + -- local count=$(echo "${network_path}" | grep -o "/net" | wc -l) + -- [ "$count" -ge "2" ] && return + + -- 判断路径是否带有usb(排除其他eth网络设备) + local command="readlink -f /sys/class/net/"..network + local network_path=shell(command) + local flag="0" + if network_path:find("eth") and not network_path:find("usb") then + flag="1" + end + + if flag=="0" then + if network:find("usb") or network:find("wwan") or network:find("eth") then + --设置USB移动网络 + mobile_network:value(network) + elseif network:find("mhi_hwip") or network:find("rmnet_mhi") then + --设置PCIE移动网络 + mobile_network:value(network) + end + end + + end +end + +getMobileNetwork() + +-- 模组名称 +name = s:option(ListValue, "name", translate("Modem Name")) +name.placeholder = translate("Not Null") +name.rmempty = false + +-- 获取支持的模组 +local support_modem=getSupportModems() +-- 按照制造商给模组分类 +local manufacturers=getManufacturers(support_modem) + +for key in pairs(manufacturers) do + local modems=manufacturers[key] + -- 排序 + table.sort(modems) + + for i in pairs(modems) do + -- 首字母大写 + local first_str=string.sub(key, 1, 1) + local manufacturer = string.upper(first_str)..string.sub(key, 2) + -- 设置值 + name:value(modems[i],manufacturer.." "..modems[i]:upper()) + end +end + +-- AT串口 +at_port = s:option(Value, "at_port", translate("AT Port")) +at_port.placeholder = translate("Not Null") +at_port.rmempty = false + +return m diff --git a/luci-app-modem/luasrc/model/cbi/modem/plugin_config.lua b/luci-app-modem/luasrc/model/cbi/modem/plugin_config.lua new file mode 100644 index 0000000..0dfce86 --- /dev/null +++ b/luci-app-modem/luasrc/model/cbi/modem/plugin_config.lua @@ -0,0 +1,76 @@ +local d = require "luci.dispatcher" +local uci = luci.model.uci.cursor() +local sys = require "luci.sys" +local script_path="/usr/share/modem/" + +m = Map("modem") +m.title = translate("Plugin Config") +m.description = translate("Check and modify the plugin configuration") + +font_red = [[]] +font_off = [[]] +bold_on = [[]] +bold_off = [[]] + +--全局配置 +s = m:section(TypedSection, "global", translate("Global Config")) +s.anonymous = true +s.addremove = false + +-- 模组扫描 +o = s:option(Button, "modem_scan", translate("Modem Scan")) +o.template = "modem/modem_scan" + +-- 启用手动配置 +o = s:option(Flag, "manual_configuration", font_red..bold_on..translate("Manual Configuration")..bold_off..font_off) +o.rmempty = false +o.description = translate("Enable the manual configuration of modem information").." "..font_red..bold_on.. translate("(After enable, the automatic scanning and configuration function for modem information will be disabled)")..bold_off..font_off + +-- 配置模组信息 +s = m:section(TypedSection, "modem-device", translate("Modem Config")) +s.anonymous = true +s.addremove = true +-- s.sortable = true +s.template = "modem/tblsection" +s.extedit = d.build_url("admin", "network", "modem", "modem_config", "%s") + +function s.create(uci, t) + -- 获取模组序号 + local modem_no=tonumber(uci.map:get("@global[0]","modem_number")) -- 将字符串转换为数字类型 + t="modem"..modem_no + TypedSection.create(uci, t) + -- 设置手动配置 + uci.map:set(t,"manual","1") + luci.http.redirect(uci.extedit:format(t)) +end + +function s.remove(uci, t) + uci.map.proceed = true + uci.map:del(t) + + -- 获取模组数量 + local modem_number=tonumber(uci.map:get("@global[0]","modem_number"))-1 + -- 设置模组数量 + uci.map:set("@global[0]","modem_number",modem_number) + + luci.http.redirect(d.build_url("admin", "network", "modem","plugin_config")) +end + +-- 移动网络 +o = s:option(DummyValue, "network", translate("Network")) + +-- 模组名称 +o = s:option(DummyValue, "name", translate("Modem Name")) +o.cfgvalue = function(t, n) + local name = (Value.cfgvalue(t, n) or "") + return name:upper() +end + +-- AT串口 +-- o = s:option(DummyValue, "at_port", translate("AT Port")) +o = s:option(Value, "at_port", translate("AT Port")) +o.placeholder = translate("Not Null") +o.rmempty = false +o.optional = false + +return m diff --git a/luci-app-modem/luasrc/view/modem/modem_info.htm b/luci-app-modem/luasrc/view/modem/modem_info.htm index 132fec1..d50bb24 100644 --- a/luci-app-modem/luasrc/view/modem/modem_info.htm +++ b/luci-app-modem/luasrc/view/modem/modem_info.htm @@ -516,7 +516,7 @@ end

<%:Modem Information%>

-
<%:Check information about adapted modem on this page%>
+
<%:Check the information of the adapted modem%>
diff --git a/luci-app-modem/luasrc/view/modem/modem_scan.htm b/luci-app-modem/luasrc/view/modem/modem_scan.htm new file mode 100644 index 0000000..a0ccc91 --- /dev/null +++ b/luci-app-modem/luasrc/view/modem/modem_scan.htm @@ -0,0 +1,46 @@ +<%+cbi/valueheader%> + + + + + +
+ <%:The automatic configuration modem is triggered only at startup, otherwise, manual scanning is necessary%> +
+<%+cbi/valuefooter%> diff --git a/luci-app-modem/luasrc/view/modem/plugin_info.htm b/luci-app-modem/luasrc/view/modem/plugin_info.htm index 0c54704..1a5c36f 100644 --- a/luci-app-modem/luasrc/view/modem/plugin_info.htm +++ b/luci-app-modem/luasrc/view/modem/plugin_info.htm @@ -79,7 +79,7 @@

<%:Plugin Info%>

-
<%:View the version information of the plugin%>
+
<%:Check the version information of the plugin%>