user-config.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. -- Copyright 2014 Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local fs = require "nixio.fs"
  4. local has_ipv6 = fs.access("/proc/net/ipv6_route")
  5. m = Map("ocserv", translate("OpenConnect VPN"))
  6. s = m:section(TypedSection, "ocserv", "OpenConnect")
  7. s.anonymous = true
  8. s:tab("general", translate("General Settings"))
  9. s:tab("ca", translate("CA certificate"))
  10. s:tab("template", translate("Edit Template"))
  11. local e = s:taboption("general", Flag, "enable", translate("Enable server"))
  12. e.rmempty = false
  13. e.default = "1"
  14. function m.on_commit(map)
  15. luci.sys.call("/usr/bin/occtl reload >/dev/null 2>&1")
  16. end
  17. function e.write(self, section, value)
  18. if value == "0" then
  19. luci.sys.call("/etc/init.d/ocserv stop >/dev/null 2>&1")
  20. luci.sys.call("/etc/init.d/ocserv disable >/dev/null 2>&1")
  21. else
  22. luci.sys.call("/etc/init.d/ocserv enable >/dev/null 2>&1")
  23. luci.sys.call("/etc/init.d/ocserv restart >/dev/null 2>&1")
  24. end
  25. Flag.write(self, section, value)
  26. end
  27. local o
  28. o = s:taboption("general", ListValue, "auth", translate("User Authentication"),
  29. translate("The authentication method for the users. The simplest is plain with a single username-password pair. Use PAM modules to authenticate using another server (e.g., LDAP, Radius)."))
  30. o.rmempty = false
  31. o.default = "plain"
  32. o:value("plain")
  33. o:value("PAM")
  34. o = s:taboption("general", Value, "zone", translate("Firewall Zone"),
  35. translate("The firewall zone that the VPN clients will be set to"))
  36. o.nocreate = true
  37. o.default = "lan"
  38. o.template = "cbi/firewall_zonelist"
  39. s:taboption("general", Value, "port", translate("Port"),
  40. translate("The same UDP and TCP ports will be used"))
  41. s:taboption("general", Value, "max_clients", translate("Max clients"))
  42. s:taboption("general", Value, "max_same", translate("Max same clients"))
  43. s:taboption("general", Value, "dpd", translate("Dead peer detection time (secs)"))
  44. local pip = s:taboption("general", Flag, "predictable_ips", translate("Predictable IPs"),
  45. translate("The assigned IPs will be selected deterministically"))
  46. pip.default = "1"
  47. local udp = s:taboption("general", Flag, "udp", translate("Enable UDP"),
  48. translate("Enable UDP channel support; this must be enabled unless you know what you are doing"))
  49. udp.default = "1"
  50. local cisco = s:taboption("general", Flag, "cisco_compat", translate("AnyConnect client compatibility"),
  51. translate("Enable support for CISCO AnyConnect clients"))
  52. cisco.default = "1"
  53. ipaddr = s:taboption("general", Value, "ipaddr", translate("VPN <abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Network-Address"))
  54. ipaddr.default = "192.168.100.1"
  55. ipaddr.datatype = "ip4addr"
  56. nm = s:taboption("general", Value, "netmask", translate("VPN <abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask"))
  57. nm.default = "255.255.255.0"
  58. nm.datatype = "ip4addr"
  59. nm:value("255.255.255.0")
  60. nm:value("255.255.0.0")
  61. nm:value("255.0.0.0")
  62. if has_ipv6 then
  63. ip6addr = s:taboption("general", Value, "ip6addr", translate("VPN <abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Network-Address"), translate("<abbr title=\"Classless Inter-Domain Routing\">CIDR</abbr>-Notation: address/prefix"))
  64. end
  65. tmpl = s:taboption("template", Value, "_tmpl",
  66. translate("Edit the template that is used for generating the ocserv configuration."))
  67. tmpl.template = "cbi/tvalue"
  68. tmpl.rows = 20
  69. function tmpl.cfgvalue(self, section)
  70. return nixio.fs.readfile("/etc/ocserv/ocserv.conf.template")
  71. end
  72. function tmpl.write(self, section, value)
  73. value = value:gsub("\r\n?", "\n")
  74. nixio.fs.writefile("/etc/ocserv/ocserv.conf.template", value)
  75. end
  76. ca = s:taboption("ca", Value, "_ca",
  77. translate("View the CA certificate used by this server. You will need to save it as 'ca.pem' and import it into the clients."))
  78. ca.template = "cbi/tvalue"
  79. ca.rows = 20
  80. function ca.cfgvalue(self, section)
  81. return nixio.fs.readfile("/etc/ocserv/ca.pem")
  82. end
  83. --[[DNS]]--
  84. s = m:section(TypedSection, "dns", translate("DNS servers"),
  85. translate("The DNS servers to be provided to clients; can be either IPv6 or IPv4"))
  86. s.anonymous = true
  87. s.addremove = true
  88. s.template = "cbi/tblsection"
  89. s:option(Value, "ip", translate("IP Address")).rmempty = true
  90. s.datatype = "ipaddr"
  91. --[[Routes]]--
  92. s = m:section(TypedSection, "routes", translate("Routing table"),
  93. translate("The routing table to be provided to clients; you can mix IPv4 and IPv6 routes, the server will send only the appropriate. Leave empty to set a default route"))
  94. s.anonymous = true
  95. s.addremove = true
  96. s.template = "cbi/tblsection"
  97. s:option(Value, "ip", translate("IP Address")).rmempty = true
  98. s.datatype = "ipaddr"
  99. o = s:option(Value, "netmask", translate("Netmask (or IPv6-prefix)"))
  100. o.default = "255.255.255.0"
  101. o:value("255.255.255.0")
  102. o:value("255.255.0.0")
  103. o:value("255.0.0.0")
  104. return m