Globally reduce copyright headers
[project/luci.git] / protocols / luci-proto-openconnect / luasrc / model / cbi / admin_network / proto_openconnect.lua
1 -- Copyright 2014 Nikos Mavrogiannopoulos <nmav@gnutls.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local map, section, net = ...
5
6 local server, username, password, cert, ca
7 local oc_cert_file, oc_key_file, oc_ca_file
8
9 local ifc = net:get_interface():name()
10
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"
14
15 server = section:taboption("general", Value, "server", translate("VPN Server"))
16 server.datatype = "host"
17
18 port = section:taboption("general", Value, "port", translate("VPN Server port"))
19 port.placeholder = "443"
20 port.datatype    = "port"
21
22 section:taboption("general", Value, "serverhash", translate("VPN Server's certificate SHA1 hash"))
23
24 section:taboption("general", Value, "authgroup", translate("AuthGroup"))
25
26 username = section:taboption("general", Value, "username", translate("Username"))
27 password = section:taboption("general", Value, "password", translate("Password"))
28 password.password = true
29
30
31 cert = section:taboption("advanced", Value, "usercert", translate("User certificate (PEM encoded)"))
32 cert.template = "cbi/tvalue"
33 cert.rows = 10
34
35 function cert.cfgvalue(self, section)
36         return nixio.fs.readfile(oc_cert_file)
37 end
38
39 function cert.write(self, section, value)
40         value = value:gsub("\r\n?", "\n")
41         nixio.fs.writefile(oc_cert_file, value)
42 end
43
44 cert = section:taboption("advanced", Value, "userkey", translate("User key (PEM encoded)"))
45 cert.template = "cbi/tvalue"
46 cert.rows = 10
47
48 function cert.cfgvalue(self, section)
49         return nixio.fs.readfile(oc_key_file)
50 end
51
52 function cert.write(self, section, value)
53         value = value:gsub("\r\n?", "\n")
54         nixio.fs.writefile(oc_key_file, value)
55 end
56
57
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"
60 ca.rows = 10
61
62 function ca.cfgvalue(self, section)
63         return nixio.fs.readfile(oc_ca_file)
64 end
65
66 function ca.write(self, section, value)
67         value = value:gsub("\r\n?", "\n")
68         nixio.fs.writefile(oc_ca_file, value)
69 end