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 section:taboption("general", Value, "serverhash", translate("VPN Server's certificate SHA1 hash"))
24 section:taboption("general", Value, "authgroup", translate("AuthGroup"))
26 username = section:taboption("general", Value, "username", translate("Username"))
27 password = section:taboption("general", Value, "password", translate("Password"))
28 password.password = true
31 cert = section:taboption("advanced", Value, "usercert", translate("User certificate (PEM encoded)"))
32 cert.template = "cbi/tvalue"
35 function cert.cfgvalue(self, section)
36 return nixio.fs.readfile(oc_cert_file)
39 function cert.write(self, section, value)
40 value = value:gsub("\r\n?", "\n")
41 nixio.fs.writefile(oc_cert_file, value)
44 cert = section:taboption("advanced", Value, "userkey", translate("User key (PEM encoded)"))
45 cert.template = "cbi/tvalue"
48 function cert.cfgvalue(self, section)
49 return nixio.fs.readfile(oc_key_file)
52 function cert.write(self, section, value)
53 value = value:gsub("\r\n?", "\n")
54 nixio.fs.writefile(oc_key_file, value)
58 ca = section:taboption("advanced", Value, "ca", translate("CA certificate; if empty it will be saved after the first connection."))
59 ca.template = "cbi/tvalue"
62 function ca.cfgvalue(self, section)
63 return nixio.fs.readfile(oc_ca_file)
66 function ca.write(self, section, value)
67 value = value:gsub("\r\n?", "\n")
68 nixio.fs.writefile(oc_ca_file, value)