config.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. # This file is part of Radicale Server - Calendar Server
  2. # Copyright © 2008-2016 Guillaume Ayoub
  3. # Copyright © 2008 Nicolas Kandel
  4. # Copyright © 2008 Pascal Halter
  5. #
  6. # This library is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This library is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. Radicale configuration module.
  20. Give a configparser-like interface to read and write configuration.
  21. """
  22. import os
  23. from collections import OrderedDict
  24. from configparser import RawConfigParser as ConfigParser
  25. # Default configuration
  26. INITIAL_CONFIG = OrderedDict([
  27. ("server", OrderedDict([
  28. ("hosts", {
  29. "value": "127.0.0.1:5232",
  30. "help": "set server hostnames including ports",
  31. "aliases": ["-H", "--hosts"]}),
  32. ("daemon", {
  33. "value": "False",
  34. "help": "launch as daemon",
  35. "aliases": ["-d", "--daemon"],
  36. "opposite": ["-f", "--foreground"]}),
  37. ("pid", {
  38. "value": "",
  39. "help": "set PID filename for daemon mode",
  40. "aliases": ["-p", "--pid"]}),
  41. ("max_connections", {
  42. "value": "20",
  43. "help": "maximum number of parallel connections"}),
  44. ("max_content_length", {
  45. "value": "10000000",
  46. "help": "maximum size of request body in bytes"}),
  47. ("timeout", {
  48. "value": "10",
  49. "help": "socket timeout"}),
  50. ("ssl", {
  51. "value": "False",
  52. "help": "use SSL connection",
  53. "aliases": ["-s", "--ssl"],
  54. "opposite": ["-S", "--no-ssl"]}),
  55. ("certificate", {
  56. "value": "/etc/ssl/radicale.cert.pem",
  57. "help": "set certificate file",
  58. "aliases": ["-c", "--certificate"]}),
  59. ("key", {
  60. "value": "/etc/ssl/radicale.key.pem",
  61. "help": "set private key file",
  62. "aliases": ["-k", "--key"]}),
  63. ("protocol", {
  64. "value": "PROTOCOL_TLSv1_2",
  65. "help": "SSL protocol used"}),
  66. ("ciphers", {
  67. "value": "",
  68. "help": "available ciphers"}),
  69. ("dns_lookup", {
  70. "value": "True",
  71. "help": "use reverse DNS to resolve client address in logs"}),
  72. ("realm", {
  73. "value": "Radicale - Password Required",
  74. "help": "message displayed when a password is needed"})])),
  75. ("encoding", OrderedDict([
  76. ("request", {
  77. "value": "utf-8",
  78. "help": "encoding for responding requests"}),
  79. ("stock", {
  80. "value": "utf-8",
  81. "help": "encoding for storing local collections"})])),
  82. ("auth", OrderedDict([
  83. ("type", {
  84. "value": "None",
  85. "help": "authentication method"}),
  86. ("htpasswd_filename", {
  87. "value": "/etc/radicale/users",
  88. "help": "htpasswd filename"}),
  89. ("htpasswd_encryption", {
  90. "value": "bcrypt",
  91. "help": "htpasswd encryption method"})])),
  92. ("rights", OrderedDict([
  93. ("type", {
  94. "value": "owner_only",
  95. "help": "rights backend"}),
  96. ("file", {
  97. "value": "/etc/radicale/rights",
  98. "help": "file for rights management from_file"})])),
  99. ("storage", OrderedDict([
  100. ("type", {
  101. "value": "multifilesystem",
  102. "help": "storage backend"}),
  103. ("filesystem_folder", {
  104. "value": os.path.expanduser(
  105. "/var/lib/radicale/collections"),
  106. "help": "file for rights management from_file"}),
  107. ("filesystem_fsync", {
  108. "value": "True",
  109. "help": "sync all changes to filesystem during requests"}),
  110. ("filesystem_close_lock_file", {
  111. "value": "False",
  112. "help": "close the lock file when no more clients are waiting"}),
  113. ("hook", {
  114. "value": "",
  115. "help": "command that is run after changes to storage"})])),
  116. ("logging", OrderedDict([
  117. ("config", {
  118. "value": "/etc/radicale/logging",
  119. "help": "logging configuration file"}),
  120. ("debug", {
  121. "value": "False",
  122. "help": "print debug information",
  123. "aliases": ["-D", "--debug"]}),
  124. ("full_environment", {
  125. "value": "False",
  126. "help": "store all environment variables"}),
  127. ("mask_passwords", {
  128. "value": "True",
  129. "help": "mask passwords in logs"})]))])
  130. def load(paths=(), extra_config=None):
  131. config = ConfigParser()
  132. for section, values in INITIAL_CONFIG.items():
  133. config.add_section(section)
  134. for key, data in values.items():
  135. config.set(section, key, data["value"])
  136. if extra_config:
  137. for section, values in extra_config.items():
  138. for key, value in values.items():
  139. config.set(section, key, value)
  140. for path in paths:
  141. if path:
  142. config.read(path)
  143. return config