1 module("luci.controller.multiwan", package.seeall)
4 local fs = luci.fs or nixio.fs
5 if not fs.access("/etc/config/multiwan") then
11 page = entry({"admin", "network", "multiwan"}, cbi("multiwan/multiwan"), _("Multi-WAN"))
14 entry({"admin", "network", "multiwan", "status"}, call("multiwan_status"))
16 page = entry({"mini", "network", "multiwan"}, cbi("multiwan/multiwanmini", {autoapply=true}), _("Multi-WAN"))
19 function multiwan_status()
20 local nfs = require "nixio.fs"
21 local cachefile = "/tmp/.mwan/cache"
25 cachefile = nfs.readfile(cachefile)
27 local ntm = require "luci.model.network".init()
28 _, _, wan_if_map = string.find(cachefile, "wan_if_map=\"([^\"]*)\"")
29 _, _, wan_fail_map = string.find(cachefile, "wan_fail_map=\"([^\"]*)\"")
30 _, _, wan_recovery_map = string.find(cachefile, "wan_recovery_map=\"([^\"]*)\"")
35 for wanname, wanifname in string.gfind(wan_if_map, "([^%[]+)%[([^%]]+)%]") do
36 local wanlink = ntm:get_interface(wanifname)
37 wanlink = wanlink and wanlink:get_network()
38 wanlink = wanlink and wanlink:adminlink() or "#"
39 wansid[wanname] = #rv.wans + 1
40 rv.wans[wansid[wanname]] = { name = wanname, link = wanlink, ifname = wanifname, status = "ok", count = 0 }
43 for wanname, failcount in string.gfind(wan_fail_map, "([^%[]+)%[([^%]]+)%]") do
44 if failcount == "x" then
45 rv.wans[wansid[wanname]].status = "ko"
47 rv.wans[wansid[wanname]].status = "failing"
48 rv.wans[wansid[wanname]].count = failcount
52 for wanname, recoverycount in string.gfind(wan_recovery_map, "([^%[]+)%[([^%]]+)%]") do
53 rv.wans[wansid[wanname]].status = "recovering"
54 rv.wans[wansid[wanname]].count = recoverycount
58 luci.http.prepare_content("application/json")
59 luci.http.write_json(rv)