From 9740e28234f26fa92354a888aced833ee8b0fc9b Mon Sep 17 00:00:00 2001 From: suyuan <175338101@qq.com> Date: Thu, 12 Nov 2020 21:13:58 +0800 Subject: [PATCH] fixbug --- .../resources/status/css/wanstatus.css | 2 +- luci-app-status/luasrc/controller/status.lua | 153 ++++++++++++++---- .../luasrc/view/status/wanstatus.htm | 121 +++++++++----- 3 files changed, 202 insertions(+), 74 deletions(-) diff --git a/luci-app-status/htdocs/luci-static/resources/status/css/wanstatus.css b/luci-app-status/htdocs/luci-static/resources/status/css/wanstatus.css index cc056af3f..81aa8dfcf 100644 --- a/luci-app-status/htdocs/luci-static/resources/status/css/wanstatus.css +++ b/luci-app-status/htdocs/luci-static/resources/status/css/wanstatus.css @@ -296,7 +296,7 @@ Thanks :)*/ .network-node .info .title i { font-weight: lighter; - font-size: 0.8em; + font-size: 1em; text-transform: uppercase; } diff --git a/luci-app-status/luasrc/controller/status.lua b/luci-app-status/luasrc/controller/status.lua index 551385277..02cdbbebc 100644 --- a/luci-app-status/luasrc/controller/status.lua +++ b/luci-app-status/luasrc/controller/status.lua @@ -269,40 +269,131 @@ function interface_bandwidth(iface) end end -function multipath_bandwidth() - local result = { }; - local uci = luci.model.uci.cursor() - - uci:foreach("network", "interface", function(s) - local intname = s[".name"] - local dev = get_device(intname) - if dev == "" then - dev = get_device(s["ifname"]) +function string.split(input, delimiter) + input = tostring(input) + delimiter = tostring(delimiter) + if (delimiter=='') then return false end + local pos,arr = 0, {} + -- for each divider found + for st,sp in function() return string.find(input, delimiter, pos, true) end do + table.insert(arr, string.sub(input, pos, st - 1)) + pos = sp + 1 end - local multipath = s["multipath"] or "" - if dev ~= "lo" and dev ~= "" then - if multipath == "" then - multipath = uci:get("openmptcprouter", intname, "multipath") or "" - end - if multipath == "" then - multipath = "off" - end - if multipath == "on" or multipath == "master" or multipath == "backup" or multipath == "handover" then - local bwc = luci.sys.exec("luci-bwc -i %q 2>/dev/null" % dev) or "" - if bwc ~= nil then - --result[dev] = "[" .. string.gsub(bwc, '[\r\n]', '') .. "]" - result[intname] = "[" .. string.gsub(bwc, '[\r\n]', '') .. "]" - else - result[dev] = "[]" - end - end - end - end) - - luci.http.prepare_content("application/json") - luci.http.write_json(result) + table.insert(arr, string.sub(input, pos)) + return arr end +function multipath_bandwidth() + local result = { }; + local uci = luci.model.uci.cursor() + local res={ }; + local str=""; + local tmpstr=""; + + uci:foreach("network", "interface", function(s) + local intname = s[".name"] + local label = s["label"] + local dev = get_device(intname) + if dev == "" then + dev = get_device(s["ifname"]) + end + local multipath = s["multipath"] or "" + if dev ~= "lo" and dev ~= "" then + if multipath == "" then + multipath = uci:get("openmptcprouter", intname, "multipath") or "" + end + if multipath == "" then + multipath = "off" + end + if multipath == "on" or multipath == "master" or multipath == "backup" or multipath == "handover" then + local bwc = luci.sys.exec("luci-bwc -i %q 2>/dev/null" % dev) or "" + local bwc = luci.sys.exec("luci-bwc -i %q 2>/dev/null" % dev) or "" + if bwc ~= nil then + --result[dev] = "[" .. string.gsub(bwc, '[\r\n]', '') .. "]" + if label ~= nil then + result[intname .. " (" .. label .. ")" ] = "[" .. string.gsub(bwc, '[\r\n]', '') .. "]" + else + result[intname] = "[" .. string.gsub(bwc, '[\r\n]', '') .. "]" + end + else + if label ~= nil then + result[intname .. " (" .. label .. ")" ] = "[]" + else + result[intname] = "[]" + end + end + end + end + end) + + res["total"]={ }; + for i=1,60 do + res["total"][i]={} + for j=1,5 do + res["total"][i][j]=0 + end + end + + for key,value in pairs(result) do + res[key]={} + value=(string.gsub(value, "^%[%[", "")) + value=(string.gsub(value, "%]%]", "")) + local temp1 = string.split(value, "],") + if temp1[2] ~= nil then + res[key][1]=temp1[1] + for i=2,60 do + res[key][i]={} + if temp1[i] ~= nil then + res[key][i]=(string.gsub(temp1[i], "%[", " ")) + end + end + for i=1,60 do + res[key][i] = string.split(res[key][i], ",") + for j=1,5 do + if "string"== type(res[key][i][j]) then + res[key][i][j]= tonumber(res[key][i][j]) + end + if "string"==type(res["total"][i][j]) then + res["total"][i][j]= tonumber(res["total"][i][j]) + end + if j ==1 then + if res[key][i][j] ~= nil then + res["total"][i][j] = res[key][i][j] + else + res["total"][i][j] = 0 + end + else + if res[key][i][j] ~= nil then + res["total"][i][j] = res["total"][i][j] + res[key][i][j] + end + end + end + end + end + end + for i=1,60 do + for j=1,5 do + if "number"== type(res["total"][i][j]) then + res["total"][i][j]= tostring(res["total"][i][j]) + end + end + end + for i=1,60 do + if i == 60 then + tmpstr = "["..table.concat(res["total"][i], ",") + else + tmpstr = "["..table.concat(res["total"][i], ",").."]," + end + str = str..tmpstr + end + str = "["..str.."]]" + result["total"]=str + + luci.http.prepare_content("application/json") + luci.http.write_json(result) +end + + function get_device(interface) local dump = require("luci.util").ubus("network.interface.%s" % interface, "status", {}) if dump ~= nil then diff --git a/luci-app-status/luasrc/view/status/wanstatus.htm b/luci-app-status/luasrc/view/status/wanstatus.htm index e1403e2a1..492b9a6f6 100644 --- a/luci-app-status/luasrc/view/status/wanstatus.htm +++ b/luci-app-status/luasrc/view/status/wanstatus.htm @@ -1,5 +1,5 @@ <% --- Copyright 2015 OVH1 (OverTheBox@ovh.net) +-- Copyright 2015 OVH (OverTheBox@ovh.net) -- Simon Lelievre (simon.lelievre@corp.ovh.com) -- Sebastien Duponcheel (sebastien.duponcheel@ovh.net) -- @@ -19,7 +19,7 @@ -- along with OverTheBox. If not, see (http://www.gnu.org/licenses/) -%> <% --- Copyright 2018 Ycarus (Yannick Chabanois) ycarus@zugaina.org +-- Copyright 2018-2020 Ycarus (Yannick Chabanois) ycarus@zugaina.org -- -- Small changes to make this work with OpenMPTCProuter -- New features: @@ -55,6 +55,8 @@ end local curifname = luci.http.formvalue("dev") or "all" + local bandwidthtotalurl = "admin/system/status/multipath_bandwidth" + local bandwidthintfurl = "admin/system/status/interface_bandwidth" -%> <%+header%> @@ -789,21 +791,23 @@