main.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. local o_pki = s:taboption("general", DummyValue, "pkid", translate("Server's Public Key ID"),
  15. translate("The value to be communicated to the client to verify the server's certificate; this value only depends on the public key"))
  16. local fd = io.popen("/usr/bin/certtool --hash sha256 --key-id --infile /etc/ocserv/server-cert.pem", "r")
  17. if fd then local ln
  18. local ln = fd:read("*l")
  19. if ln then
  20. o_pki.default = "sha256:" .. ln
  21. end
  22. fd:close()
  23. end
  24. function m.on_commit(map)
  25. luci.sys.call("/usr/bin/occtl reload >/dev/null 2>&1")
  26. end
  27. function e.write(self, section, value)
  28. if value == "0" then
  29. luci.sys.call("/etc/init.d/ocserv stop >/dev/null 2>&1")
  30. luci.sys.call("/etc/init.d/ocserv disable >/dev/null 2>&1")
  31. else
  32. luci.sys.call("/etc/init.d/ocserv enable >/dev/null 2>&1")
  33. luci.sys.call("/etc/init.d/ocserv restart >/dev/null 2>&1")
  34. end
  35. Flag.write(self, section, value)
  36. end
  37. local o
  38. o = s:taboption("general", ListValue, "auth", translate("User Authentication"),
  39. 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)."))
  40. o.rmempty = false
  41. o.default = "plain"
  42. o:value("plain")
  43. o:value("PAM")
  44. s:taboption("general", Value, "port", translate("Port"),
  45. translate("The same UDP and TCP ports will be used"))
  46. s:taboption("general", Value, "max_clients", translate("Max clients"))
  47. s:taboption("general", Value, "max_same", translate("Max same clients"))
  48. s:taboption("general", Value, "dpd", translate("Dead peer detection time (secs)"))
  49. local pip = s:taboption("general", Flag, "predictable_ips", translate("Predictable IPs"),
  50. translate("The assigned IPs will be selected deterministically"))
  51. pip.default = "1"
  52. local compr = s:taboption("general", Flag, "compression", translate("Enable compression"),
  53. translate("Enable compression"))
  54. compr.default = "0"
  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. tmpl = s:taboption("template", Value, "_tmpl",
  62. translate("Edit the template that is used for generating the ocserv configuration."))
  63. tmpl.template = "cbi/tvalue"
  64. tmpl.rows = 20
  65. function tmpl.cfgvalue(self, section)
  66. return nixio.fs.readfile("/etc/ocserv/ocserv.conf.template")
  67. end
  68. function tmpl.write(self, section, value)
  69. value = value:gsub("\r\n?", "\n")
  70. nixio.fs.writefile("/etc/ocserv/ocserv.conf.template", value)
  71. end
  72. ca = s:taboption("ca", Value, "_ca",
  73. translate("View the CA certificate used by this server. You will need to save it as 'ca.pem' and import it into the clients."))
  74. ca.template = "cbi/tvalue"
  75. ca.rows = 20
  76. function ca.cfgvalue(self, section)
  77. return nixio.fs.readfile("/etc/ocserv/ca.pem")
  78. end
  79. --[[Networking options]]--
  80. local parp = s:taboption("general", Flag, "proxy_arp", translate("Enable proxy arp"),
  81. translate("Provide addresses to clients from a subnet of LAN; if enabled the network below must be a subnet of LAN. Note that the first address of the specified subnet will be reserved by ocserv, so it should not be in use. If you have a network in LAN covering 192.168.1.0/24 use 192.168.1.192/26 to reserve the upper 62 addresses."))
  82. parp.default = "0"
  83. ipaddr = s:taboption("general", Value, "ipaddr", translate("VPN <abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Network-Address"),
  84. translate("The IPv4 subnet address to provide to clients; this should be some private network different than the LAN addresses unless proxy ARP is enabled. Leave empty to attempt auto-configuration."))
  85. ipaddr.datatype = "ip4addr"
  86. ipaddr.default = "192.168.100.1"
  87. nm = s:taboption("general", Value, "netmask", translate("VPN <abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask"),
  88. translate("The mask of the subnet above."))
  89. nm.datatype = "ip4addr"
  90. nm.default = "255.255.255.0"
  91. nm:value("255.255.255.0")
  92. nm:value("255.255.0.0")
  93. nm:value("255.0.0.0")
  94. if has_ipv6 then
  95. 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"),
  96. translate("The IPv6 subnet address to provide to clients; leave empty to attempt auto-configuration."))
  97. ip6addr.datatype = "ip6addr"
  98. end
  99. --[[DNS]]--
  100. s = m:section(TypedSection, "dns", translate("DNS servers"),
  101. translate("The DNS servers to be provided to clients; can be either IPv6 or IPv4. Typically you should include the address of this device"))
  102. s.anonymous = true
  103. s.addremove = true
  104. s.template = "cbi/tblsection"
  105. s:option(Value, "ip", translate("IP Address")).rmempty = true
  106. s.datatype = "ipaddr"
  107. --[[Routes]]--
  108. s = m:section(TypedSection, "routes", translate("Routing table"),
  109. 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"))
  110. s.anonymous = true
  111. s.addremove = true
  112. s.template = "cbi/tblsection"
  113. s:option(Value, "ip", translate("IP Address")).rmempty = true
  114. o = s:option(Value, "netmask", translate("Netmask (or IPv6-prefix)"))
  115. o.default = "255.255.255.0"
  116. o:value("255.255.255.0")
  117. o:value("255.255.0.0")
  118. o:value("255.0.0.0")
  119. return m