1
0

openvpn-basic.lua 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. -- Copyright 2008 Steven Barth <steven@midlink.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. require("luci.ip")
  4. require("luci.model.uci")
  5. local basicParams = {
  6. --
  7. -- Widget, Name, Default(s), Description
  8. --
  9. { ListValue, "verb", { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }, translate("Set output verbosity") },
  10. { Value, "nice",0, translate("Change process priority") },
  11. { Value,"port",1194, translate("TCP/UDP port # for both local and remote") },
  12. { ListValue,"dev_type",{ "tun", "tap" }, translate("Type of used device") },
  13. { Flag,"tun_ipv6",0, translate("Make tun device IPv6 capable") },
  14. { Value,"ifconfig","10.200.200.3 10.200.200.1", translate("Set tun/tap adapter parameters") },
  15. { Value,"server","10.200.200.0 255.255.255.0", translate("Configure server mode") },
  16. { Value,"server_bridge","192.168.1.1 255.255.255.0 192.168.1.128 192.168.1.254", translate("Configure server bridge") },
  17. { Flag,"nobind",0, translate("Do not bind to local address and port") },
  18. { ListValue,"comp_lzo",{"yes","no","adaptive"}, translate("Use fast LZO compression") },
  19. { Value,"keepalive","10 60", translate("Helper directive to simplify the expression of --ping and --ping-restart in server mode configurations") },
  20. { ListValue,"proto",{ "udp", "tcp-client", "tcp-server" }, translate("Use protocol") },
  21. { Flag,"client",0, translate("Configure client mode") },
  22. { Flag,"client_to_client",0, translate("Allow client-to-client traffic") },
  23. { DynamicList,"remote","vpnserver.example.org", translate("Remote host name or ip address") },
  24. { FileUpload,"secret","/etc/openvpn/secret.key", translate("Enable Static Key encryption mode (non-TLS)") },
  25. { Value,"key_direction","1", translate("The key direction for 'tls-auth' and 'secret' options") },
  26. { FileUpload,"pkcs12","/etc/easy-rsa/keys/some-client.pk12", translate("PKCS#12 file containing keys") },
  27. { FileUpload,"ca","/etc/easy-rsa/keys/ca.crt", translate("Certificate authority") },
  28. { FileUpload,"dh","/etc/easy-rsa/keys/dh1024.pem", translate("Diffie Hellman parameters") },
  29. { FileUpload,"cert","/etc/easy-rsa/keys/some-client.crt", translate("Local certificate") },
  30. { FileUpload,"key","/etc/easy-rsa/keys/some-client.key", translate("Local private key") },
  31. }
  32. local m = Map("openvpn")
  33. local p = m:section( SimpleSection )
  34. p.template = "openvpn/pageswitch"
  35. p.mode = "basic"
  36. p.instance = arg[1]
  37. local s = m:section( NamedSection, arg[1], "openvpn" )
  38. for _, option in ipairs(basicParams) do
  39. local o = s:option(
  40. option[1], option[2],
  41. option[2], option[4]
  42. )
  43. o.optional = true
  44. if option[1] == DummyValue then
  45. o.value = option[3]
  46. else
  47. if option[1] == DynamicList then
  48. function o.cfgvalue(...)
  49. local val = AbstractValue.cfgvalue(...)
  50. return ( val and type(val) ~= "table" ) and { val } or val
  51. end
  52. end
  53. if type(option[3]) == "table" then
  54. if o.optional then o:value("", "-- remove --") end
  55. for _, v in ipairs(option[3]) do
  56. v = tostring(v)
  57. o:value(v)
  58. end
  59. o.default = tostring(option[3][1])
  60. else
  61. o.default = tostring(option[3])
  62. end
  63. end
  64. for i=5,#option do
  65. if type(option[i]) == "table" then
  66. o:depends(option[i])
  67. end
  68. end
  69. end
  70. return m