1 -- Copyright 2014 Nikos Mavrogiannopoulos <nmav@gnutls.org>
2 -- Licensed to the public under the Apache License 2.0.
4 local map, section, net = ...
6 local server, username, password, cert, ca
7 local oc_cert_file, oc_key_file, oc_ca_file
9 local ifc = net:get_interface():name()
11 oc_cert_file = "/etc/openconnect/user-cert-" .. ifc .. ".pem"
12 oc_key_file = "/etc/openconnect/user-key-" .. ifc .. ".pem"
13 oc_ca_file = "/etc/openconnect/ca-" .. ifc .. ".pem"
15 server = section:taboption("general", Value, "server", translate("VPN Server"))
16 server.datatype = "host"
18 port = section:taboption("general", Value, "port", translate("VPN Server port"))
19 port.placeholder = "443"
20 port.datatype = "port"
22 ifname = section:taboption("general", Value, "interface", translate("Output Interface"))
23 ifname.template = "cbi/network_netlist"
25 section:taboption("general", Value, "serverhash", translate("VPN Server's certificate SHA1 hash"))
27 section:taboption("general", Value, "authgroup", translate("AuthGroup"))
29 username = section:taboption("general", Value, "username", translate("Username"))
30 password = section:taboption("general", Value, "password", translate("Password"))
31 password.password = true
34 cert = section:taboption("advanced", Value, "usercert", translate("User certificate (PEM encoded)"))
35 cert.template = "cbi/tvalue"
38 function cert.cfgvalue(self, section)
39 return nixio.fs.readfile(oc_cert_file)
42 function cert.write(self, section, value)
43 value = value:gsub("\r\n?", "\n")
44 nixio.fs.writefile(oc_cert_file, value)
47 cert = section:taboption("advanced", Value, "userkey", translate("User key (PEM encoded)"))
48 cert.template = "cbi/tvalue"
51 function cert.cfgvalue(self, section)
52 return nixio.fs.readfile(oc_key_file)
55 function cert.write(self, section, value)
56 value = value:gsub("\r\n?", "\n")
57 nixio.fs.writefile(oc_key_file, value)
61 ca = section:taboption("advanced", Value, "ca", translate("CA certificate; if empty it will be saved after the first connection."))
62 ca.template = "cbi/tvalue"
65 function ca.cfgvalue(self, section)
66 return nixio.fs.readfile(oc_ca_file)
69 function ca.write(self, section, value)
70 value = value:gsub("\r\n?", "\n")
71 nixio.fs.writefile(oc_ca_file, value)