You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
4.9 KiB

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