-- Copyright 2008 Steven Barth -- Copyright 2011 Jo-Philipp Wich -- Copyright 2018 Ycarus (Yannick Chabanois) -- Licensed to the public under the Apache License 2.0. module("luci.controller.mptcp", package.seeall) function index() entry({"admin", "network", "mptcp"}, alias("admin", "network", "mptcp", "settings"), _("MPTCP")) entry({"admin", "network", "mptcp", "settings"}, cbi("mptcp"), _("Settings"),2) entry({"admin", "network", "mptcp", "bandwidth"}, template("multipath"), _("Bandwidth"), 3).leaf = true entry({"admin", "network", "mptcp", "multipath_bandwidth"}, call("multipath_bandwidth")).leaf = true entry({"admin", "network", "mptcp", "interface_bandwidth"}, call("interface_bandwidth")).leaf = true end function interface_bandwidth(iface) luci.http.prepare_content("application/json") local bwc = io.popen("luci-bwc -i %q 2>/dev/null" % iface) if bwc then luci.http.write("[") while true do local ln = bwc:read("*l") if not ln then break end luci.http.write(ln) end luci.http.write("]") bwc:close() end end function multipath_bandwidth() local result = { }; local uci = luci.model.uci.cursor() for _, dev in luci.util.vspairs(luci.sys.net.devices()) do if dev ~= "lo" then local multipath = uci:get("network", dev, "multipath") if multipath == "on" or multipath == "master" or multipath == "backup" or multipath == "handover" then result[dev] = "[" .. string.gsub((luci.sys.exec("luci-bwc -i %q 2>/dev/null" % dev)), '[\r\n]', '') .. "]" end end end luci.http.prepare_content("application/json") luci.http.write_json(result) end