multiwan.lua 4.9 KB

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