proto_openconnect.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. -- Copyright 2014 Nikos Mavrogiannopoulos <nmav@gnutls.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local map, section, net = ...
  4. local server, username, password, cert, ca
  5. local oc_cert_file, oc_key_file, oc_ca_file
  6. local ifc = net:get_interface():name()
  7. oc_cert_file = "/etc/openconnect/user-cert-" .. ifc .. ".pem"
  8. oc_key_file = "/etc/openconnect/user-key-" .. ifc .. ".pem"
  9. oc_ca_file = "/etc/openconnect/ca-" .. ifc .. ".pem"
  10. server = section:taboption("general", Value, "server", translate("VPN Server"))
  11. server.datatype = "host"
  12. port = section:taboption("general", Value, "port", translate("VPN Server port"))
  13. port.placeholder = "443"
  14. port.datatype = "port"
  15. ifname = section:taboption("general", Value, "interface", translate("Output Interface"))
  16. ifname.template = "cbi/network_netlist"
  17. defaultroute = section:taboption("advanced", Flag, "defaultroute",
  18. translate("Use default gateway"),
  19. translate("If unchecked, no default route is configured"))
  20. defaultroute.default = defaultroute.enabled
  21. metric = section:taboption("advanced", Value, "metric",
  22. translate("Use gateway metric"))
  23. metric.placeholder = "0"
  24. metric.datatype = "uinteger"
  25. metric:depends("defaultroute", defaultroute.enabled)
  26. section:taboption("general", Value, "serverhash", translate("VPN Server's certificate SHA1 hash"))
  27. section:taboption("general", Value, "authgroup", translate("AuthGroup"))
  28. username = section:taboption("general", Value, "username", translate("Username"))
  29. password = section:taboption("general", Value, "password", translate("Password"))
  30. password.password = true
  31. cert = section:taboption("advanced", Value, "usercert", translate("User certificate (PEM encoded)"))
  32. cert.template = "cbi/tvalue"
  33. cert.rows = 10
  34. function cert.cfgvalue(self, section)
  35. return nixio.fs.readfile(oc_cert_file)
  36. end
  37. function cert.write(self, section, value)
  38. value = value:gsub("\r\n?", "\n")
  39. nixio.fs.writefile(oc_cert_file, value)
  40. end
  41. cert = section:taboption("advanced", Value, "userkey", translate("User key (PEM encoded)"))
  42. cert.template = "cbi/tvalue"
  43. cert.rows = 10
  44. function cert.cfgvalue(self, section)
  45. return nixio.fs.readfile(oc_key_file)
  46. end
  47. function cert.write(self, section, value)
  48. value = value:gsub("\r\n?", "\n")
  49. nixio.fs.writefile(oc_key_file, value)
  50. end
  51. ca = section:taboption("advanced", Value, "ca", translate("CA certificate; if empty it will be saved after the first connection."))
  52. ca.template = "cbi/tvalue"
  53. ca.rows = 10
  54. function ca.cfgvalue(self, section)
  55. return nixio.fs.readfile(oc_ca_file)
  56. end
  57. function ca.write(self, section, value)
  58. value = value:gsub("\r\n?", "\n")
  59. nixio.fs.writefile(oc_ca_file, value)
  60. end