Merge pull request #1818 from dibdot/lxc_fix
[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(0)"
17
18 port = section:taboption("general", Value, "port", translate("VPN Server port"))
19 port.placeholder = "443"
20 port.datatype    = "port"
21
22
23 defaultroute = section:taboption("advanced", Flag, "defaultroute",
24         translate("Use default gateway"),
25         translate("If unchecked, no default route is configured"))
26
27 defaultroute.default = defaultroute.enabled
28
29
30 metric = section:taboption("advanced", Value, "metric",
31         translate("Use gateway metric"))
32
33 metric.placeholder = "0"
34 metric.datatype    = "uinteger"
35 metric:depends("defaultroute", defaultroute.enabled)
36
37 section:taboption("general", Value, "serverhash", translate("VPN Server's certificate SHA1 hash"))
38
39 section:taboption("general", Value, "authgroup", translate("Auth Group"))
40
41 username = section:taboption("general", Value, "username", translate("Username"))
42 password = section:taboption("general", Value, "password", translate("Password"))
43 password.password = true
44 password2 = section:taboption("general", Value, "password2", translate("Password2"))
45 password2.password = true
46
47
48 cert = section:taboption("advanced", Value, "usercert", translate("User certificate (PEM encoded)"))
49 cert.template = "cbi/tvalue"
50 cert.rows = 10
51
52 function cert.cfgvalue(self, section)
53         return nixio.fs.readfile(oc_cert_file)
54 end
55
56 function cert.write(self, section, value)
57         value = value:gsub("\r\n?", "\n")
58         nixio.fs.writefile(oc_cert_file, value)
59 end
60
61 cert = section:taboption("advanced", Value, "userkey", translate("User key (PEM encoded)"))
62 cert.template = "cbi/tvalue"
63 cert.rows = 10
64
65 function cert.cfgvalue(self, section)
66         return nixio.fs.readfile(oc_key_file)
67 end
68
69 function cert.write(self, section, value)
70         value = value:gsub("\r\n?", "\n")
71         nixio.fs.writefile(oc_key_file, value)
72 end
73
74
75 ca = section:taboption("advanced", Value, "ca", translate("CA certificate; if empty it will be saved after the first connection."))
76 ca.template = "cbi/tvalue"
77 ca.rows = 10
78
79 function ca.cfgvalue(self, section)
80         return nixio.fs.readfile(oc_ca_file)
81 end
82
83 function ca.write(self, section, value)
84         value = value:gsub("\r\n?", "\n")
85         nixio.fs.writefile(oc_ca_file, value)
86 end
87
88 mtu = section:taboption("advanced", Value, "mtu", translate("Override MTU"))
89 mtu.placeholder = "1406"
90 mtu.datatype    = "max(9200)"