rules.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. -- Copyright 2017 Yousong Zhou <yszhou4tech@gmail.com>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local ss = require("luci.model.shadowsocks-libev")
  4. local m, s, o
  5. m = Map("shadowsocks-libev",
  6. translate("Redir Rules"),
  7. translate("On this page you can configure how traffics are to be \
  8. forwarded to ss-redir instances. \
  9. If enabled, packets will first have their src ip addresses checked \
  10. against <em>Src ip/net bypass</em>, <em>Src ip/net forward</em>, \
  11. <em>Src ip/net checkdst</em> and if none matches <em>Src default</em> \
  12. will give the default action to be taken. \
  13. If the prior check results in action <em>checkdst</em>, packets will continue \
  14. to have their dst addresses checked."))
  15. local sdata = m:get('ss_rules')
  16. if not sdata then
  17. m:set('ss_rules', nil, 'ss_rules')
  18. m:set('ss_rules', 'disabled', "1")
  19. end
  20. function src_dst_option(s, ...)
  21. local o = s:taboption(...)
  22. o.datatype = "or(ip4addr,cidr4)"
  23. end
  24. s = m:section(NamedSection, "ss_rules", "ss_rules")
  25. s:tab("general", translate("General Settings"))
  26. s:tab("src", translate("Source Settings"))
  27. s:tab("dst", translate("Destination Settings"))
  28. s:taboption('general', Flag, "disabled", translate("Disable"))
  29. ss.option_install_package(s, 'general')
  30. o = s:taboption('general', ListValue, "redir_tcp",
  31. translate("ss-redir for TCP"))
  32. ss.values_redir(o, 'tcp')
  33. o = s:taboption('general', ListValue, "redir_udp",
  34. translate("ss-redir for UDP"))
  35. ss.values_redir(o, 'udp')
  36. o = s:taboption('general', ListValue, "local_default",
  37. translate("Local-out default"),
  38. translate("Default action for locally generated TCP packets"))
  39. ss.values_actions(o)
  40. o = s:taboption('general', DynamicList, "ifnames",
  41. translate("Ingress interfaces"),
  42. translate("Only apply rules on packets from these network interfaces"))
  43. ss.values_ifnames(o)
  44. s:taboption('general', Value, "ipt_args",
  45. translate("Extra arguments"),
  46. translate("Passes additional arguments to iptables. Use with care!"))
  47. src_dst_option(s, 'src', DynamicList, "src_ips_bypass",
  48. translate("Src ip/net bypass"),
  49. translate("Bypass ss-redir for packets with src address in this list"))
  50. src_dst_option(s, 'src', DynamicList, "src_ips_forward",
  51. translate("Src ip/net forward"),
  52. translate("Forward through ss-redir for packets with src address in this list"))
  53. src_dst_option(s, 'src', DynamicList, "src_ips_checkdst",
  54. translate("Src ip/net checkdst"),
  55. translate("Continue to have dst address checked for packets with src address in this list"))
  56. o = s:taboption('src', ListValue, "src_default",
  57. translate("Src default"),
  58. translate("Default action for packets whose src address do not match any of the src ip/net list"))
  59. ss.values_actions(o)
  60. src_dst_option(s, 'dst', DynamicList, "dst_ips_bypass",
  61. translate("Dst ip/net bypass"),
  62. translate("Bypass ss-redir for packets with dst address in this list"))
  63. src_dst_option(s, 'dst', DynamicList, "dst_ips_forward",
  64. translate("Dst ip/net forward"),
  65. translate("Forward through ss-redir for packets with dst address in this list"))
  66. o = s:taboption('dst', FileBrowser, "dst_ips_bypass_file",
  67. translate("Dst ip/net bypass file"),
  68. translate("File containing ip/net for the purposes as with <em>Dst ip/net bypass</em>"))
  69. o.datatype = "file"
  70. s:taboption('dst', FileBrowser, "dst_ips_forward_file",
  71. translate("Dst ip/net forward file"),
  72. translate("File containing ip/net for the purposes as with <em>Dst ip/net forward</em>"))
  73. o.datatype = "file"
  74. o = s:taboption('dst', ListValue, "dst_default",
  75. translate("Dst default"),
  76. translate("Default action for packets whose dst address do not match any of the dst ip list"))
  77. ss.values_actions(o)
  78. local installed = os.execute("iptables -m recent -h &>/dev/null") == 0
  79. if installed then
  80. o = s:taboption('dst', Flag, "dst_forward_recentrst")
  81. else
  82. m:set('ss_rules', 'dst_forward_recentrst', "0")
  83. o = s:taboption("dst", Button, "_install")
  84. o.inputtitle = translate("Install package iptables-mod-conntrack-extra")
  85. o.inputstyle = "apply"
  86. o.write = function()
  87. return luci.http.redirect(
  88. luci.dispatcher.build_url("admin/system/packages") ..
  89. "?submit=1&install=iptables-mod-conntrack-extra"
  90. )
  91. end
  92. end
  93. o.title = translate("Forward recentrst")
  94. o.description = translate("Forward those packets whose dst have recently sent to us multiple tcp-rst")
  95. return m