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