diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2011-10-02 10:23:32 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2011-10-02 10:23:32 +0000 |
commit | 31ea36f7ab8319313317f9420b47f29812977850 (patch) | |
tree | 3e468abd6432caa937225aabf6fc1ad82948799d /applications/luci-multiwan/luasrc/controller | |
parent | 86f63627b66a8ef73f079eda30db2d87772da9b6 (diff) |
applications/luci-multiwan: add status indicators, patch by Etienne Champetier <etienne.champetier@free.fr> (#260)
Diffstat (limited to 'applications/luci-multiwan/luasrc/controller')
-rw-r--r-- | applications/luci-multiwan/luasrc/controller/multiwan.lua | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/applications/luci-multiwan/luasrc/controller/multiwan.lua b/applications/luci-multiwan/luasrc/controller/multiwan.lua index 2a45c5f7bc..6aa4cf454a 100644 --- a/applications/luci-multiwan/luasrc/controller/multiwan.lua +++ b/applications/luci-multiwan/luasrc/controller/multiwan.lua @@ -11,8 +11,52 @@ function index() page = entry({"admin", "network", "multiwan"}, cbi("multiwan/multiwan"), _("Multi-WAN")) page.i18n = "multiwan" page.dependent = true + + entry({"admin", "network", "multiwan", "status"}, call("multiwan_status")) page = entry({"mini", "network", "multiwan"}, cbi("multiwan/multiwanmini", {autoapply=true}), _("Multi-WAN")) page.i18n = "multiwan" page.dependent = true end +function multiwan_status() + local nfs = require "nixio.fs" + local cachefile = "/tmp/.mwan/cache" + + local rv = { } + + cachefile = nfs.readfile(cachefile) + if cachefile then + local ntm = require "luci.model.network".init() + _, _, wan_if_map = string.find(cachefile, "wan_if_map=\"([^\"]*)\"") + _, _, wan_fail_map = string.find(cachefile, "wan_fail_map=\"([^\"]*)\"") + _, _, wan_recovery_map = string.find(cachefile, "wan_recovery_map=\"([^\"]*)\"") + + rv.wans = { } + wansid = {} + + for wanname, wanifname in string.gfind(wan_if_map, "([^%[]+)%[([^%]]+)%]") do + local wanlink = ntm:get_interface(wanifname) + wanlink = wanlink and wanlink:get_network() + wanlink = wanlink and wanlink:adminlink() or "#" + wansid[wanname] = #rv.wans + 1 + rv.wans[wansid[wanname]] = { name = wanname, link = wanlink, ifname = wanifname, status = "ok", count = 0 } + end + + for wanname, failcount in string.gfind(wan_fail_map, "([^%[]+)%[([^%]]+)%]") do + if failcount == "x" then + rv.wans[wansid[wanname]].status = "ko" + else + rv.wans[wansid[wanname]].status = "failing" + rv.wans[wansid[wanname]].count = failcount + end + end + + for wanname, recoverycount in string.gfind(wan_recovery_map, "([^%[]+)%[([^%]]+)%]") do + rv.wans[wansid[wanname]].status = "recovering" + rv.wans[wansid[wanname]].count = recoverycount + end + end + + luci.http.prepare_content("application/json") + luci.http.write_json(rv) +end |