2 LuCI - Lua Configuration Interface
4 Copyright 2014 Nikos Mavrogiannopoulos <nmav@gnutls.org>
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
13 local map, section, net = ...
15 local server, username, password, cert, ca
16 local oc_cert_file, oc_key_file, oc_ca_file
18 local ifc = net:get_interface():name()
20 oc_cert_file = "/etc/openconnect/user-cert-" .. ifc .. ".pem"
21 oc_key_file = "/etc/openconnect/user-key-" .. ifc .. ".pem"
22 oc_ca_file = "/etc/openconnect/ca-" .. ifc .. ".pem"
24 server = section:taboption("general", Value, "server", translate("VPN Server"))
25 server.datatype = "host"
27 port = section:taboption("general", Value, "port", translate("VPN Server port"))
28 port.placeholder = "443"
29 port.datatype = "port"
31 section:taboption("general", Value, "serverhash", translate("VPN Server's certificate SHA1 hash"))
33 section:taboption("general", Value, "authgroup", translate("AuthGroup"))
35 username = section:taboption("general", Value, "username", translate("Username"))
36 password = section:taboption("general", Value, "password", translate("Password"))
37 password.password = true
40 cert = section:taboption("advanced", Value, "usercert", translate("User certificate (PEM encoded)"))
41 cert.template = "cbi/tvalue"
44 function cert.cfgvalue(self, section)
45 return nixio.fs.readfile(oc_cert_file)
48 function cert.write(self, section, value)
49 value = value:gsub("\r\n?", "\n")
50 nixio.fs.writefile(oc_cert_file, value)
53 cert = section:taboption("advanced", Value, "userkey", translate("User key (PEM encoded)"))
54 cert.template = "cbi/tvalue"
57 function cert.cfgvalue(self, section)
58 return nixio.fs.readfile(oc_key_file)
61 function cert.write(self, section, value)
62 value = value:gsub("\r\n?", "\n")
63 nixio.fs.writefile(oc_key_file, value)
67 ca = section:taboption("advanced", Value, "ca", translate("CA certificate; if empty it will be saved after the first connection."))
68 ca.template = "cbi/tvalue"
71 function ca.cfgvalue(self, section)
72 return nixio.fs.readfile(oc_ca_file)
75 function ca.write(self, section, value)
76 value = value:gsub("\r\n?", "\n")
77 nixio.fs.writefile(oc_ca_file, value)