server.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. -- Licensed to the public under the Apache License 2.0.
  2. local fs = require("nixio.fs")
  3. local rad2 = require "luci.controller.radicale2"
  4. local http = require("luci.http")
  5. local m = Map("radicale2", translate("Radicale 2.x"),
  6. translate("A lightweight CalDAV/CardDAV server"))
  7. s = m:section(SimpleSection, translate("Radicale v2 Web UI"))
  8. s.addremove = false
  9. s.anonymous = true
  10. o = s:option(DummyValue, "radicale2_webui_go", translate("Go to Radicale v2 Web UI"))
  11. o.template = "cbi/raduigo"
  12. o.section = "cbi-radicale2_webui"
  13. local s = m:section(NamedSection, "server", "section", translate("Server Settings"))
  14. s.addremove = true
  15. s.anonymous = false
  16. o.section = "cbi-radicale2_web_ui"
  17. local lhttp = nil
  18. local certificate_file = nil
  19. local key_file = nil
  20. local certificate_authority_file = nil
  21. s:tab("general", translate("General Settings"))
  22. s:tab("advanced", translate("Advanced Settings"))
  23. lhttp = s:taboption("general", DynamicList, "host", translate("HTTP(S) Listeners (address:port)"))
  24. lhttp.datatype = "list(ipaddrport(1))"
  25. lhttp.placeholder = "127.0.0.1:5232"
  26. o = s:taboption("advanced", Value, "max_connection", translate("Max Connections"), translate("Maximum number of simultaneous connections"))
  27. o.rmempty = true
  28. o.placeholder = 20
  29. o.datatype = "uinteger"
  30. o = s:taboption("advanced", Value, "max_content_length", translate("Max Content Length"), translate("Maximum size of request body (bytes)"))
  31. o.rmempty = true
  32. o.datatype = "uinteger"
  33. o.placeholder = 100000000
  34. o = s:taboption("advanced", Value, "timeout", translate("Timeout"), translate("Socket timeout (seconds)"))
  35. o.rmempty = true
  36. o.placeholder = 30
  37. o.datatype = "uinteger"
  38. sslon = s:taboption("general", Flag, "ssl", translate("SSL"), translate("Enable SSL connections"))
  39. sslon.rmempty = true
  40. sslon.default = o.disabled
  41. sslon.formvalue = function(self, section)
  42. if not rad2.pymodexists('ssl') then
  43. return false
  44. end
  45. return Flag.formvalue(self, section)
  46. end
  47. cert_file = s:taboption("general", FileUpload, "certificate", translate("Certificate"))
  48. cert_file.rmempty = true
  49. cert_file:depends("ssl", true)
  50. key_file = s:taboption("general", FileUpload, "key", translate("Private Key"))
  51. key_file.rmempty = true
  52. key_file:depends("ssl", true)
  53. ca_file = s:taboption("general", FileUpload, "certificate_authority", translate("Client Certificate Authority"), translate("For verifying client certificates"))
  54. ca_file.rmempty = true
  55. ca_file:depends("ssl", true)
  56. o = s:taboption("advanced", Value, "ciphers", translate("Allowed Ciphers"), translate("See python3-openssl documentation for available ciphers"))
  57. o.rmempty = true
  58. o:depends("ssl", true)
  59. o = s:taboption("advanced", Value, "protocol", translate("Use Protocol"), translate("See python3-openssl documentation for available protocols"))
  60. o.rmempty = true
  61. o:depends("ssl", true)
  62. o.placeholder = "PROTOCOL_TLSv1_2"
  63. o = s:taboption("general", Button, "remove_conf",
  64. translate("Remove configuration for certificate, key, and CA"),
  65. translate("This permanently deletes the cert, key, and configuration to use same."))
  66. o.inputstyle = "remove"
  67. o:depends("ssl", true)
  68. function o.write(self, section)
  69. if cert_file:cfgvalue(section) and fs.access(cert_file:cfgvalue(section)) then fs.unlink(cert_file:cfgvalue(section)) end
  70. if key_file:cfgvalue(section) and fs.access(key_file:cfgvalue(section)) then fs.unlink(key_file:cfgvalue(section)) end
  71. if ca_file:cfgvalue(section) and fs.access(key_file:cfgvalue(section)) then fs.unlink(ca_file:cfgvalue(section)) end
  72. self.map:del(section, "certificate")
  73. self.map:del(section, "key")
  74. self.map:del(section, "certificate_authority")
  75. self.map:del(section, "protocol")
  76. self.map:del(section, "ciphers")
  77. luci.http.redirect(luci.dispatcher.build_url("admin", "services", "radicale2", "server"))
  78. end
  79. if not rad2.pymodexists('ssl') then
  80. o = s:taboption("general", DummyValue, "sslnotpreset", translate("SSL not available"), translate("Install package python3-openssl to support SSL connections"))
  81. end
  82. o = s:taboption("advanced", Flag, "dns_lookup", translate("DNS Lookup"), translate("Lookup reverse DNS for clients for logging"))
  83. o.rmempty = true
  84. o.default = o.enabled
  85. o = s:taboption("advanced", Value, "realm", translate("Realm"), translate("HTTP(S) Basic Authentication Realm"))
  86. o.rmempty = true
  87. o.placeholder = "Radicale - Password Required"
  88. local s = m:section(NamedSection, "web", "section", translate("Web UI"))
  89. s.addremove = true
  90. s.anonymous = false
  91. o = s:option(ListValue, "type", translate("Web UI Type"))
  92. o:value("", "Default (Built-in)")
  93. o:value("internal", "Built-in")
  94. o:value("none", "None")
  95. o.default = ""
  96. o.rmempty = true
  97. local s = m:section(NamedSection, "headers", "section", translate("Headers"), translate("HTTP(S) Headers"))
  98. s.addremove = true
  99. s.anonymous = false
  100. o = s:option(Value, "cors", translate("CORS"), translate("Header: X-Access-Control-Allow-Origin"))
  101. o.rmempty = true
  102. o.placeholder = "*"
  103. local s = m:section(NamedSection, "encoding", "section", translate("Document Encoding"))
  104. s.addremove = true
  105. s.anonymous = false
  106. o = s:option(Value, "request", translate("Request"), translate("Encoding for responding to requests/events"))
  107. o.rmempty = true
  108. o.placeholder = "utf-8"
  109. o = s:option(Value, "stock", translate("Storage"), translate("Encoding for storing local collections"))
  110. o.rmempty = true
  111. o.placeholder = "utf-8"
  112. return m