applications/luci-multiwan: use new uci disable option instead of disabling the init...
[project/luci.git] / applications / luci-multiwan / luasrc / model / cbi / multiwan / multiwan.lua
1 require("luci.tools.webadmin")
2
3 m = Map("multiwan", translate("Multi-WAN"),
4 translate("Multi-WAN allows for the use of multiple uplinks for load balancing and failover."))
5
6 s = m:section(NamedSection, "config", "multiwan", "")
7
8 e = s:option(Flag, "enabled", translate("Enable"))
9 e.rmempty = false
10 e.default = e.enabled
11
12 function e.write(self, section, value)
13 if value == "0" then
14 os.execute("/etc/init.d/multiwan stop")
15 else
16 os.execute("/etc/init.d/multiwan enable")
17 end
18 Flag.write(self, section, value)
19 end
20
21 s = m:section(TypedSection, "interface", translate("WAN Interfaces"),
22 translate("Health Monitor detects and corrects network changes and failed connections."))
23 s.addremove = true
24
25 weight = s:option(ListValue, "weight", translate("Load Balancer Distribution"))
26 weight:value("10", "10")
27 weight:value("9", "9")
28 weight:value("8", "8")
29 weight:value("7", "7")
30 weight:value("6", "6")
31 weight:value("5", "5")
32 weight:value("4", "4")
33 weight:value("3", "3")
34 weight:value("2", "2")
35 weight:value("1", "1")
36 weight:value("disable", translate("None"))
37 weight.default = "10"
38 weight.optional = false
39 weight.rmempty = false
40
41 interval = s:option(ListValue, "health_interval", translate("Health Monitor Interval"))
42 interval:value("disable", translate("Disable"))
43 interval:value("5", "5 sec.")
44 interval:value("10", "10 sec.")
45 interval:value("20", "20 sec.")
46 interval:value("30", "30 sec.")
47 interval:value("60", "60 sec.")
48 interval:value("120", "120 sec.")
49 interval.default = "10"
50 interval.optional = false
51 interval.rmempty = false
52
53 icmp_hosts = s:option(Value, "icmp_hosts", translate("Health Monitor ICMP Host(s)"))
54 icmp_hosts:value("disable", translate("Disable"))
55 icmp_hosts:value("dns", "DNS Server(s)")
56 icmp_hosts:value("gateway", "WAN Gateway")
57 icmp_hosts.default = "dns"
58 icmp_hosts.optional = false
59 icmp_hosts.rmempty = false
60
61 timeout = s:option(ListValue, "timeout", translate("Health Monitor ICMP Timeout"))
62 timeout:value("1", "1 sec.")
63 timeout:value("2", "2 sec.")
64 timeout:value("3", "3 sec.")
65 timeout:value("4", "4 sec.")
66 timeout:value("5", "5 sec.")
67 timeout:value("10", "10 sec.")
68 timeout.default = "3"
69 timeout.optional = false
70 timeout.rmempty = false
71
72 fail = s:option(ListValue, "health_fail_retries", translate("Attempts Before WAN Failover"))
73 fail:value("1", "1")
74 fail:value("3", "3")
75 fail:value("5", "5")
76 fail:value("10", "10")
77 fail:value("15", "15")
78 fail:value("20", "20")
79 fail.default = "3"
80 fail.optional = false
81 fail.rmempty = false
82
83 recovery = s:option(ListValue, "health_recovery_retries", translate("Attempts Before WAN Recovery"))
84 recovery:value("1", "1")
85 recovery:value("3", "3")
86 recovery:value("5", "5")
87 recovery:value("10", "10")
88 recovery:value("15", "15")
89 recovery:value("20", "20")
90 recovery.default = "5"
91 recovery.optional = false
92 recovery.rmempty = false
93
94 failover_to = s:option(ListValue, "failover_to", translate("Failover Traffic Destination"))
95 failover_to:value("disable", translate("None"))
96 luci.tools.webadmin.cbi_add_networks(failover_to)
97 failover_to:value("fastbalancer", translate("Load Balancer(Performance)"))
98 failover_to:value("balancer", translate("Load Balancer(Compatibility)"))
99 failover_to.default = "balancer"
100 failover_to.optional = false
101 failover_to.rmempty = false
102
103 dns = s:option(Value, "dns", translate("DNS Server(s)"))
104 dns:value("auto", translate("Auto"))
105 dns.default = "auto"
106 dns.optional = false
107 dns.rmempty = true
108
109 s = m:section(TypedSection, "mwanfw", translate("Multi-WAN Traffic Rules"),
110 translate("Configure rules for directing outbound traffic through specified WAN Uplinks."))
111 s.template = "cbi/tblsection"
112 s.anonymous = true
113 s.addremove = true
114
115 src = s:option(Value, "src", translate("Source Address"))
116 src.rmempty = true
117 src:value("", translate("all"))
118 luci.tools.webadmin.cbi_add_knownips(src)
119
120 dst = s:option(Value, "dst", translate("Destination Address"))
121 dst.rmempty = true
122 dst:value("", translate("all"))
123 luci.tools.webadmin.cbi_add_knownips(dst)
124
125 proto = s:option(Value, "proto", translate("Protocol"))
126 proto:value("", translate("all"))
127 proto:value("tcp", "TCP")
128 proto:value("udp", "UDP")
129 proto:value("icmp", "ICMP")
130 proto.rmempty = true
131
132 ports = s:option(Value, "ports", translate("Ports"))
133 ports.rmempty = true
134 ports:value("", translate("all", translate("all")))
135
136 wanrule = s:option(ListValue, "wanrule", translate("WAN Uplink"))
137 luci.tools.webadmin.cbi_add_networks(wanrule)
138 wanrule:value("fastbalancer", translate("Load Balancer(Performance)"))
139 wanrule:value("balancer", translate("Load Balancer(Compatibility)"))
140 wanrule.default = "fastbalancer"
141 wanrule.optional = false
142 wanrule.rmempty = false
143
144 s = m:section(NamedSection, "config", "", "")
145 s.addremove = false
146
147 default_route = s:option(ListValue, "default_route", translate("Default Route"))
148 luci.tools.webadmin.cbi_add_networks(default_route)
149 default_route:value("fastbalancer", translate("Load Balancer(Performance)"))
150 default_route:value("balancer", translate("Load Balancer(Compatibility)"))
151 default_route.default = "balancer"
152 default_route.optional = false
153 default_route.rmempty = false
154
155 return m