You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.3 KiB

  1. --[[
  2. LuCI - Lua Configuration Interface
  3. Copyright 2014 Nikos Mavrogiannopoulos <nmav@gnutls.org>
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. ]]--
  9. local map, section, net = ...
  10. local server, username, password, cert, ca
  11. local oc_cert_file, oc_key_file, oc_ca_file
  12. local ifc = net:get_interface():name()
  13. oc_cert_file = "/etc/openconnect/user-cert-" .. ifc .. ".pem"
  14. oc_key_file = "/etc/openconnect/user-key-" .. ifc .. ".pem"
  15. oc_ca_file = "/etc/openconnect/ca-" .. ifc .. ".pem"
  16. server = section:taboption("general", Value, "server", translate("VPN Server"))
  17. server.datatype = "host"
  18. port = section:taboption("general", Value, "port", translate("VPN Server port"))
  19. port.placeholder = "443"
  20. port.datatype = "port"
  21. section:taboption("general", Value, "serverhash", translate("VPN Server's certificate SHA1 hash"))
  22. section:taboption("general", Value, "authgroup", translate("AuthGroup"))
  23. username = section:taboption("general", Value, "username", translate("Username"))
  24. password = section:taboption("general", Value, "password", translate("Password"))
  25. password.password = true
  26. cert = section:taboption("advanced", Value, "usercert", translate("User certificate (PEM encoded)"))
  27. cert.template = "cbi/tvalue"
  28. cert.rows = 10
  29. function cert.cfgvalue(self, section)
  30. return nixio.fs.readfile(oc_cert_file)
  31. end
  32. function cert.write(self, section, value)
  33. value = value:gsub("\r\n?", "\n")
  34. nixio.fs.writefile(oc_cert_file, value)
  35. end
  36. cert = section:taboption("advanced", Value, "userkey", translate("User key (PEM encoded)"))
  37. cert.template = "cbi/tvalue"
  38. cert.rows = 10
  39. function cert.cfgvalue(self, section)
  40. return nixio.fs.readfile(oc_key_file)
  41. end
  42. function cert.write(self, section, value)
  43. value = value:gsub("\r\n?", "\n")
  44. nixio.fs.writefile(oc_key_file, value)
  45. end
  46. ca = section:taboption("advanced", Value, "ca", translate("CA certificate; if empty it will be saved after the first connection."))
  47. ca.template = "cbi/tvalue"
  48. ca.rows = 10
  49. function ca.cfgvalue(self, section)
  50. return nixio.fs.readfile(oc_ca_file)
  51. end
  52. function ca.write(self, section, value)
  53. value = value:gsub("\r\n?", "\n")
  54. nixio.fs.writefile(oc_ca_file, value)
  55. end