a1696b57f1b14a4a96d2d27e8702102c3fd3ee6a
[project/luci.git] / applications / luci-multiwan / luasrc / model / cbi / multiwan / multiwan.lua
1 require("luci.tools.webadmin")
2 m = Map("multiwan")
3
4 s = m:section(NamedSection, "config", "multiwan", "")
5 e = s:option(Flag, "enabled", translate("enable"))
6 e.rmempty = false
7
8 function e.write(self, section, value)
9         local cmd = (value == "1") and "enable" or "disable"
10         if value ~= "1" then
11                 os.execute("/etc/init.d/multiwan stop")
12         end
13         os.execute("/etc/init.d/multiwan " .. cmd)
14 end
15
16 function e.cfgvalue(self, section)
17         return (os.execute("/etc/init.d/multiwan enabled") == 0) and "1" or "0"
18 end
19
20 default_route = s:option(ListValue, "default_route", translate("default_route"))
21 luci.tools.webadmin.cbi_add_networks(default_route)
22 default_route:value("balancer", translate("balancer"))
23 default_route.default = "balancer"
24 default_route.optional = false
25 default_route.rmempty = false
26
27 resolv_conf = s:option(Value, "resolv_conf", translate("resolv_conf"), translate("resolv_conf_desc"))
28 resolv_conf.default = "/tmp/resolv.conf.auto"
29 resolv_conf.optional = false
30 resolv_conf.rmempty = false
31
32 s = m:section(TypedSection, "interface", translate("interfaces"), translate("interfaces_desc"))
33 s.addremove = true
34
35 weight = s:option(ListValue, "weight", translate("weight"))
36 weight:value("10", "10")
37 weight:value("9", "9")
38 weight:value("8", "8")
39 weight:value("7", "7")
40 weight:value("6", "6")
41 weight:value("5", "5")
42 weight:value("4", "4")
43 weight:value("3", "3")
44 weight:value("2", "2")
45 weight:value("1", "1")
46 weight:value("disable", translate("none"))
47 weight.default = "5"
48 weight.optional = false
49 weight.rmempty = false
50
51 interval = s:option(ListValue, "health_interval", translate("health_interval"))
52 interval:value("disable", translate("disable"))
53 interval:value("5", "5 sec.")
54 interval:value("10", "10 sec.")
55 interval:value("20", "20 sec.")
56 interval:value("30", "30 sec.")
57 interval:value("60", "60 sec.")
58 interval:value("120", "120 sec.")
59 interval.default = "10"
60 interval.optional = false
61 interval.rmempty = false
62
63 icmp_hosts = s:option(Value, "icmp_hosts", translate("icmp_hosts"))
64 icmp_hosts:value("disable", translate("disable"))
65 icmp_hosts:value("dns", "DNS Server(s)")
66 icmp_hosts:value("gateway", "WAN Gateway")
67 icmp_hosts.default = "dns"
68 icmp_hosts.optional = false
69 icmp_hosts.rmempty = false
70
71 timeout = s:option(ListValue, "timeout", translate("timeout"))
72 timeout:value("1", "1 sec.")
73 timeout:value("2", "2 sec.")
74 timeout:value("3", "3 sec.")
75 timeout:value("4", "4 sec.")
76 timeout:value("5", "5 sec.")
77 timeout:value("10", "10 sec.")
78 timeout.default = "3"
79 timeout.optional = false
80 timeout.rmempty = false
81
82 fail = s:option(ListValue, "health_fail_retries", translate("health_fail_retries"))
83 fail:value("1", "1")
84 fail:value("3", "3")
85 fail:value("5", "5")
86 fail:value("10", "10")
87 fail:value("15", "15")
88 fail:value("20", "20")
89 fail.default = "3"
90 fail.optional = false
91 fail.rmempty = false
92
93 recovery = s:option(ListValue, "health_recovery_retries", translate("health_recovery_retries"))
94 recovery:value("1", "1")
95 recovery:value("3", "3")
96 recovery:value("5", "5")
97 recovery:value("10", "10")
98 recovery:value("15", "15")
99 recovery:value("20", "20")
100 recovery.default = "5"
101 recovery.optional = false
102 recovery.rmempty = false
103
104 failover_to = s:option(ListValue, "failover_to", translate("failover_to"))
105 failover_to:value("disable", translate("none"))
106 luci.tools.webadmin.cbi_add_networks(failover_to)
107 failover_to:value("balancer", translate("balancer"))
108 failover_to.default = "balancer"
109 failover_to.optional = false
110 failover_to.rmempty = false
111
112 s = m:section(TypedSection, "mwanfw", translate("mwanfw"), translate("mwanfw_desc"))
113 s.template = "cbi/tblsection"
114 s.anonymous = true
115 s.addremove = true
116
117 src = s:option(Value, "src", translate("src"))
118 src.rmempty = true
119 src:value("", translate("all"))
120 luci.tools.webadmin.cbi_add_knownips(src)
121
122 dst = s:option(Value, "dst", translate("dst"))
123 dst.rmempty = true
124 dst:value("", translate("all"))
125 luci.tools.webadmin.cbi_add_knownips(dst)
126
127 proto = s:option(ListValue, "proto", translate("protocol"))
128 proto:value("", translate("all"))
129 proto:value("tcp", "TCP")
130 proto:value("udp", "UDP")
131 proto:value("icmp", "ICMP")
132 proto.rmempty = true
133
134 ports = s:option(Value, "ports", translate("ports"))
135 ports.rmempty = true
136 ports:value("", translate("all", translate("all")))
137
138 wanrule = s:option(ListValue, "wanrule", translate("wanrule"))
139 luci.tools.webadmin.cbi_add_networks(wanrule)
140 wanrule:value("balancer", translate("balancer"))
141 wanrule.default = "balancer"
142 wanrule.optional = false
143 wanrule.rmempty = false
144
145 return m