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