b7351ff19bfbcedacd157ebdb2cbf360ee5fe489
[project/luci.git] / modules / niu / luasrc / model / cbi / niu / network / wan.lua
1 local cursor = require "luci.model.uci".cursor()
2
3 if not cursor:get("network", "wan") then
4         cursor:section("network", "interface", "wan", {proto = "none"})
5         cursor:save("network")
6 end
7
8 local function deviceroute(self)
9         cursor:unload("network")
10         local wd = cursor:get("network", "wan", "_wandev") or ""
11         
12         if wd == "none" then
13                 cursor:set("network", "wan", "proto", "none")
14         end
15         
16         if wd:find("ethernet:") == 1 then
17                 cursor:set("network", "wan", "defaultroute", "1")
18                 cursor:set("network", "wan", "ifname", wd:sub(10))
19                 self:set_route("etherwan")
20         else
21                 cursor:delete("network", "wan", "ifname")
22         end
23         
24         if wd:find("wlan:") == 1 then
25         
26         else
27                 cursor:delete_all("wireless", "wifi-iface", {network = "wan"}) 
28         end
29         
30         cursor:save("wireless")
31         cursor:save("network")
32 end
33
34
35 local d = Delegator()
36 d.allow_finish = true
37 d.allow_back = true
38 d.allow_cancel = true
39
40 d:add("device", load("niu/network/wandevice"))
41 d:add("deviceroute", deviceroute)
42 d:set("etherwan", load("niu/network/etherwan"))
43
44 function d.on_cancel()
45         cursor:revert("network")
46         cursor:revert("wireless")
47 end
48
49 function d.on_done()
50         cursor:commit("network")
51         cursor:commit("wireless")
52 end
53
54 return d