2 LuCI - Lua Configuration Interface
4 Copyright 2014 Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
14 local fs = require "nixio.fs"
15 local has_ipv6 = fs.access("/proc/net/ipv6_route")
17 m = Map("ocserv", translate("OpenConnect VPN"))
19 s = m:section(TypedSection, "ocserv", "OpenConnect")
22 s:tab("general", translate("General Settings"))
23 s:tab("ca", translate("CA certificate"))
24 s:tab("template", translate("Edit Template"))
26 local e = s:taboption("general", Flag, "enable", translate("Enable server"))
30 function m.on_commit(map)
31 luci.sys.call("/usr/bin/occtl reload >/dev/null 2>&1")
34 function e.write(self, section, value)
36 luci.sys.call("/etc/init.d/ocserv stop >/dev/null 2>&1")
37 luci.sys.call("/etc/init.d/ocserv disable >/dev/null 2>&1")
39 luci.sys.call("/etc/init.d/ocserv enable >/dev/null 2>&1")
40 luci.sys.call("/etc/init.d/ocserv restart >/dev/null 2>&1")
42 Flag.write(self, section, value)
47 o = s:taboption("general", ListValue, "auth", translate("User Authentication"),
48 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)."))
54 o = s:taboption("general", Value, "zone", translate("Firewall Zone"),
55 translate("The firewall zone that the VPN clients will be set to"))
58 o.template = "cbi/firewall_zonelist"
60 s:taboption("general", Value, "port", translate("Port"),
61 translate("The same UDP and TCP ports will be used"))
62 s:taboption("general", Value, "max_clients", translate("Max clients"))
63 s:taboption("general", Value, "max_same", translate("Max same clients"))
64 s:taboption("general", Value, "dpd", translate("Dead peer detection time (secs)"))
66 local pip = s:taboption("general", Flag, "predictable_ips", translate("Predictable IPs"),
67 translate("The assigned IPs will be selected deterministically"))
70 local udp = s:taboption("general", Flag, "udp", translate("Enable UDP"),
71 translate("Enable UDP channel support; this must be enabled unless you know what you are doing"))
74 local cisco = s:taboption("general", Flag, "cisco_compat", translate("AnyConnect client compatibility"),
75 translate("Enable support for CISCO AnyConnect clients"))
78 ipaddr = s:taboption("general", Value, "ipaddr", translate("VPN <abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Network-Address"))
79 ipaddr.default = "192.168.100.1"
80 ipaddr.datatype = "ip4addr"
82 nm = s:taboption("general", Value, "netmask", translate("VPN <abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask"))
83 nm.default = "255.255.255.0"
84 nm.datatype = "ip4addr"
85 nm:value("255.255.255.0")
86 nm:value("255.255.0.0")
90 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"))
94 tmpl = s:taboption("template", Value, "_tmpl",
95 translate("Edit the template that is used for generating the ocserv configuration."))
97 tmpl.template = "cbi/tvalue"
100 function tmpl.cfgvalue(self, section)
101 return nixio.fs.readfile("/etc/ocserv/ocserv.conf.template")
104 function tmpl.write(self, section, value)
105 value = value:gsub("\r\n?", "\n")
106 nixio.fs.writefile("/etc/ocserv/ocserv.conf.template", value)
109 ca = s:taboption("ca", Value, "_ca",
110 translate("View the CA certificate used by this server. You will need to save it as 'ca.pem' and import it into the clients."))
112 ca.template = "cbi/tvalue"
115 function ca.cfgvalue(self, section)
116 return nixio.fs.readfile("/etc/ocserv/ca.pem")
121 s = m:section(TypedSection, "dns", translate("DNS servers"),
122 translate("The DNS servers to be provided to clients; can be either IPv6 or IPv4"))
125 s.template = "cbi/tblsection"
127 s:option(Value, "ip", translate("IP Address")).rmempty = true
128 s.datatype = "ipaddr"
132 s = m:section(TypedSection, "routes", translate("Routing table"),
133 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"))
136 s.template = "cbi/tblsection"
138 s:option(Value, "ip", translate("IP Address")).rmempty = true
139 s.datatype = "ipaddr"
141 o = s:option(Value, "netmask", translate("Netmask (or IPv6-prefix)"))
142 o.default = "255.255.255.0"
144 o:value("255.255.255.0")
145 o:value("255.255.0.0")