From 354455f09acdfaf0dcf49e5b512fc80a45428d30 Mon Sep 17 00:00:00 2001 From: ling <1042585959@qq.com> Date: Fri, 19 Apr 2024 15:59:34 +0800 Subject: [PATCH] log --- applications/luci-app-modem/Makefile | 2 +- .../luasrc/controller/modem.lua | 47 +++- .../luasrc/view/modem/modem_debug.htm | 122 +++----- .../luasrc/view/modem/modem_dial_log.htm | 263 +++++++++++++++++- applications/luci-app-modem/po/zh-cn/modem.po | 6 + applications/luci-app-modem/po/zh_Hans | 1 + 6 files changed, 351 insertions(+), 90 deletions(-) create mode 100644 applications/luci-app-modem/po/zh_Hans diff --git a/applications/luci-app-modem/Makefile b/applications/luci-app-modem/Makefile index 8e7e8d0..8a5b1fd 100644 --- a/applications/luci-app-modem/Makefile +++ b/applications/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.3.0 +PKG_VERSION:=1.4.0 PKG_LICENSE:=GPLv3 PKG_LINCESE_FILES:=LICENSE PKF_MAINTAINER:=siriling diff --git a/applications/luci-app-modem/luasrc/controller/modem.lua b/applications/luci-app-modem/luasrc/controller/modem.lua index 1807d70..3e57a65 100644 --- a/applications/luci-app-modem/luasrc/controller/modem.lua +++ b/applications/luci-app-modem/luasrc/controller/modem.lua @@ -24,6 +24,7 @@ function index() entry({"admin", "network", "modem", "config"}, cbi("modem/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 entry({"admin", "network", "modem", "status"}, call("act_status")).leaf = true --模块调试 @@ -365,9 +366,32 @@ function getDialLogInfo() local command="find "..run_path.." -name \"modem*_dial.cache\"" local result=shell(command) + local log_paths=string.split(result, "\n") + + local logs={} + for i = #log_paths, 1, -1 do --倒序遍历 + + local log_path=log_paths[i] + + if log_path ~= "" then + --获取模组 + local tmp=string.gsub(log_path, run_path, "") + local modem=string.gsub(tmp, "_dial.cache", "") + + --获取日志内容 + local command="cat "..log_path + log=shell(command) + + --排序插入 + modem_log={} + modem_log[modem]=log + table.insert(logs, modem_log) + end + end + -- 设置值 local data={} - data["dial_log_info"]=result + data["dial_log_info"]=logs -- data["translation"]=translation -- 写入Web界面 @@ -375,6 +399,27 @@ function getDialLogInfo() luci.http.write_json(data) end +--[[ +@Description 清空拨号日志 +]] +function cleanDialLog() + + -- 获取拨号日志路径 + local dial_log_path = http.formvalue("path") + + -- 清空拨号日志 + local command=": > "..dial_log_path + shell(command) + + -- 设置值 + local data={} + data["clean_result"]="clean dial log" + + -- 写入Web界面 + luci.http.prepare_content("application/json") + luci.http.write_json(data) +end + --[[ @Description 模块列表状态函数 ]] diff --git a/applications/luci-app-modem/luasrc/view/modem/modem_debug.htm b/applications/luci-app-modem/luasrc/view/modem/modem_debug.htm index b4d0f25..03b4e52 100644 --- a/applications/luci-app-modem/luasrc/view/modem/modem_debug.htm +++ b/applications/luci-app-modem/luasrc/view/modem/modem_debug.htm @@ -15,7 +15,7 @@ get_modem_debug_info(debug_params); }); - //获取tab菜单 + //获取标签菜单 var tab_menu = document.getElementsByClassName('cbi-tabmenu')[0]; set_tab_event(tab_menu); @@ -69,7 +69,7 @@ }); } - //设置tab菜单事件 + //设置标签菜单事件 function set_tab_event(parent_element) { //获取子元素 @@ -78,7 +78,7 @@ for (var i = 0; i < childElements.length; i++) { // childElements[i].addEventListener('click', function(event) { - // var debug_params={first_cache:true}; + // var debug_params={first_cache:true}; // get_modem_debug_info(debug_params); // }); @@ -123,7 +123,8 @@ function(x, data) { responseElement=document.getElementById("response"); - if ("response" in data) { + if ("response" in data) + { //显示当前时间 responseElement.value+=data["time"]+" "; //显示返回值 @@ -233,7 +234,7 @@ return disenable_element; } - // 设置tab显示 + // 设置标签显示 function set_tab_view(disenable_element,enable_element) { //获取tab内容父元素 @@ -282,17 +283,6 @@ document.getElementById("tab_context").style.display="none"; } - // 有模组界面 - function modems_view() - { - //显示模组选择界面 - document.getElementById("cbi-modem").style.display="block"; - //显示AT命令标题 - // document.getElementById("at_command_title").style.display="block"; - //隐藏提示信息 - // document.getElementById("cbi-info").style.display="none"; - } - // 未适配模组界面 function not_adapted_modems_view() { @@ -300,26 +290,30 @@ document.getElementById("info_message").innerHTML="<%:Not adapted to this modem%>"; //显示提示信息 document.getElementById("cbi-info").style.display="block"; - //显示tab内容界面 + //显示模组选择界面 + document.getElementById("cbi-modem").style.display="block"; + //显示标签内容界面 document.getElementById("tab_context").style.display="block"; //显示AT命令标题 document.getElementById("at_command_title").style.display="block"; - //隐藏tab菜单界面 + //隐藏标签菜单界面 document.getElementsByClassName("cbi-tabmenu")[0].style.display="none"; - //在tab菜单选中AT命令 + //在标签菜单选中AT命令 var data_tab="at_command_tab" var at_command_tab_element = document.querySelector('li[data-tab="'+data_tab+'"]'); tab_event(at_command_tab_element); - //隐藏tab内容界面 - // document.getElementById("tab_context").style.display="none"; } // 全功能界面 function all_function_view() { - //显示tab菜单界面 + //更新提示信息 + document.getElementById("info_message").innerHTML='<%:Loading%><%:Loading modem%>...'; + //显示模组选择界面 + document.getElementById("cbi-modem").style.display="block"; + //显示标签菜单界面 document.getElementsByClassName("cbi-tabmenu")[0].style.display="block"; - //显示tab内容界面 + //显示标签内容界面 document.getElementById("tab_context").style.display="block"; //隐藏AT命令标题 document.getElementById("at_command_title").style.display="none"; @@ -390,9 +384,6 @@ var command_select = document.getElementById('command_select'); //更新选项 update_option(command_select,data["quick_commands"],true); - - //显示有模组界面 - modems_view(); } ); } @@ -733,8 +724,6 @@ var mode_info=data["mode_info"]; if (Object.keys(mode_info).length==0) { - //显示未适配模组界面 - not_adapted_modems_view(); return false } @@ -743,9 +732,6 @@ //设置第一次获取数据标志 debug_params.first_cache=false; - - //显示全功能界面 - all_function_view(); } ); } @@ -757,8 +743,6 @@ var network_prefer_info=data["network_prefer_info"]; if (Object.keys(network_prefer_info).length==0) { - //显示未适配模组界面 - not_adapted_modems_view(); return false } @@ -767,9 +751,6 @@ //设置第一次获取数据标志 debug_params.first_cache=false; - - //显示全功能界面 - all_function_view(); } ); } @@ -781,8 +762,6 @@ var self_test_info=data["self_test_info"]; if (Object.keys(self_test_info).length==0) { - //显示未适配模组界面 - not_adapted_modems_view(); return false } @@ -791,43 +770,9 @@ //设置第一次获取数据标志 // debug_params.first_cache=false; - - //显示全功能界面 - all_function_view(); } ); } - - //获取调试信息 - // XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "get_modem_debug_info")%>', {"port":at_port}, - // function(x, data) - // { - // var mode_info=data["mode_info"]; - // var network_prefer_info=data["network_prefer_info"]; - // var self_test_info=data["self_test_info"]; - // if (Object.keys(mode_info).length==0||Object.keys(network_prefer_info).length==0) { - // //显示未适配模组界面 - // not_adapted_modems_view(); - // return false - // } - - // //设置模式信息 - // set_mode_info(mode_info,debug_params.first_cache); - - // //设置网络偏好信息 - // set_network_prefer_info(network_prefer_info,debug_params.first_cache); - - // //设置模组自检信息 - // set_modem_self_test_info(self_test_info); - - // //设置第一次获取数据标志 - // debug_params.first_cache=false; - - // //显示全功能界面 - // all_function_view(); - // } - // ); - } // 定时触发更新AT串口 @@ -836,7 +781,7 @@ { //缓存当前选择的模组 var modem_select_cache=""; - var debug_params={first_cache:true}; + var debug_params={first_cache:true,view:0}; return function(x, data) { var at_ports=data["at_ports"]; @@ -848,8 +793,7 @@ //获取快捷命令 if (Object.keys(at_ports).length==0) { - //显示无模组界面 - no_modems_view(); + debug_params.view=0; } else { @@ -857,6 +801,15 @@ var modem_select_element = document.getElementById('modem_select'); var select_modem_name = modem_select_element.options[modem_select_element.selectedIndex].text; + if (select_modem_name.includes("ttyUSB")||select_modem_name.includes("at")||select_modem_name.includes("DUN")) + { + debug_params.view=2; + } + else + { + debug_params.view=1; + } + if (select_modem_name != modem_select_cache) { //获取快捷选项 @@ -864,6 +817,7 @@ if (quick_option=="auto") { get_quick_commands(); } + //缓存当前选中的模组 modem_select_cache=select_modem_name; //设置第一次获取数据标志 @@ -873,6 +827,20 @@ //获取模组调试信息 get_modem_debug_info(debug_params); } + + //设置界面 + if (debug_params.view==0) { + //显示无模组界面 + no_modems_view(); + } + else if (debug_params.view==1) { + //显示全功能界面 + all_function_view(); + } + else if (debug_params.view==2) { + //显示未适配模组界面 + not_adapted_modems_view(); + } }; })() ); @@ -1150,8 +1118,8 @@
<%:Response%>

- - + +
diff --git a/applications/luci-app-modem/luasrc/view/modem/modem_dial_log.htm b/applications/luci-app-modem/luasrc/view/modem/modem_dial_log.htm index efaf5ed..7cc2710 100644 --- a/applications/luci-app-modem/luasrc/view/modem/modem_dial_log.htm +++ b/applications/luci-app-modem/luasrc/view/modem/modem_dial_log.htm @@ -1,12 +1,236 @@ @@ -17,20 +241,37 @@ border:none; color:#FFF; width: 100%; + + + border-top-width: 2px; + + padding-top: 12px; + } -
- +

<%:Dial Log%>

- -
-
- - - -
+ + + + + + + +
+
    +
    + +
    +
    + + +
    +
    diff --git a/applications/luci-app-modem/po/zh-cn/modem.po b/applications/luci-app-modem/po/zh-cn/modem.po index e7eddc6..3c2b2ed 100644 --- a/applications/luci-app-modem/po/zh-cn/modem.po +++ b/applications/luci-app-modem/po/zh-cn/modem.po @@ -1,3 +1,6 @@ +msgid "" +msgstr "Content-Type: text/plain; charset=UTF-8\n" + msgid "Base Setting" msgstr "基本设置" @@ -43,6 +46,9 @@ msgstr "在此页面给所有模组添加拨号配置" msgid "Global Config" msgstr "全局配置" +msgid "Dial Log" +msgstr "拨号日志" + msgid "connect" msgstr "已连接" diff --git a/applications/luci-app-modem/po/zh_Hans b/applications/luci-app-modem/po/zh_Hans new file mode 100644 index 0000000..41451e4 --- /dev/null +++ b/applications/luci-app-modem/po/zh_Hans @@ -0,0 +1 @@ +zh-cn \ No newline at end of file