Git based wiki inspired by Gollum
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.

230 lines
6.1KB

  1. from __future__ import absolute_import
  2. import json
  3. import os
  4. import sys
  5. # noinspection PyUnresolvedReferences
  6. from six.moves.urllib.parse import urlparse
  7. from realms.lib.util import in_vagrant
  8. class Config(object):
  9. urlparse = urlparse
  10. APP_PATH = os.path.abspath(os.path.dirname(__file__) + "/../..")
  11. USER_HOME = os.path.abspath(os.path.expanduser("~"))
  12. # Best to change to /var/run
  13. PIDFILE = "/tmp/realms-wiki.pid"
  14. ENV = 'DEV'
  15. HOST = "0.0.0.0"
  16. PORT = 5000
  17. BASE_URL = 'http://localhost'
  18. SITE_TITLE = "Realms"
  19. # http://flask-sqlalchemy.pocoo.org/config/#connection-uri-format
  20. DB_URI = 'sqlite:////tmp/wiki.db'
  21. # DB_URI = 'mysql://scott:tiger@localhost/mydatabase'
  22. # DB_URI = 'postgresql://scott:tiger@localhost/mydatabase'
  23. # DB_URI = 'oracle://scott:tiger@127.0.0.1:1521/sidname'
  24. # DB_URI = 'crate://'
  25. # LDAP = {
  26. # 'URI': '',
  27. #
  28. # # This BIND_DN/BIND_PASSWORD default to '', this is shown here for demonstrative purposes
  29. # # The values '' perform an anonymous bind so we may use search/bind method
  30. # 'BIND_DN': '',
  31. # 'BIND_AUTH': '',
  32. #
  33. # # Adding the USER_SEARCH field tells the flask-ldap-login that we are using
  34. # # the search/bind method
  35. # 'USER_SEARCH': {'base': 'dc=example,dc=com', 'filter': 'uid=%(username)s'},
  36. #
  37. # # Map ldap keys into application specific keys
  38. # 'KEY_MAP': {
  39. # 'name': 'cn',
  40. # 'company': 'o',
  41. # 'location': 'l',
  42. # 'email': 'mail',
  43. # }
  44. # }
  45. # OAUTH = {
  46. # 'twitter': {
  47. # 'key': '',
  48. # 'secret': ''
  49. # },
  50. # 'github': {
  51. # 'key': '',
  52. # 'secret': ''
  53. # }
  54. # }
  55. # Valid options: simple, redis, memcached
  56. CACHE_TYPE = 'simple'
  57. CACHE_REDIS_HOST = '127.0.0.1'
  58. CACHE_REDIS_PORT = 6379
  59. CACHE_REDIS_DB = '0'
  60. CACHE_MEMCACHED_SERVERS = ['127.0.0.1:11211']
  61. # Valid options: simple, elasticsearch, whoosh
  62. SEARCH_TYPE = 'simple'
  63. ELASTICSEARCH_URL = 'http://127.0.0.1:9200'
  64. ELASTICSEARCH_FIELDS = ["name"]
  65. WHOOSH_INDEX = '/tmp/whoosh'
  66. WHOOSH_LANGUAGE = 'en'
  67. # Get ReCaptcha Keys for your domain here:
  68. # https://www.google.com/recaptcha/admin#whyrecaptcha
  69. RECAPTCHA_ENABLE = False
  70. RECAPTCHA_USE_SSL = False
  71. RECAPTCHA_PUBLIC_KEY = "6LfYbPkSAAAAAB4a2lG2Y_Yjik7MG9l4TDzyKUao"
  72. RECAPTCHA_PRIVATE_KEY = "6LfYbPkSAAAAAG-KlkwjZ8JLWgwc9T0ytkN7lWRE"
  73. RECAPTCHA_OPTIONS = {}
  74. SECRET_KEY = 'CHANGE_ME'
  75. # Path on file system where wiki data will reside
  76. WIKI_PATH = '/tmp/wiki'
  77. # Name of page that will act as home
  78. WIKI_HOME = 'home'
  79. # Should we trust authentication set by a proxy
  80. AUTH_PROXY = False
  81. AUTH_PROXY_HEADER_NAME = "REMOTE_USER"
  82. AUTH_LOCAL_ENABLE = True
  83. ALLOW_ANON = True
  84. REGISTRATION_ENABLED = True
  85. PRIVATE_WIKI = False
  86. # None, firepad, and/or togetherjs
  87. COLLABORATION = 'togetherjs'
  88. # Required for firepad
  89. FIREBASE_HOSTNAME = None
  90. # Page names that can't be modified
  91. WIKI_LOCKED_PAGES = []
  92. ROOT_ENDPOINT = 'wiki.page'
  93. # Used by Flask-Login
  94. @property
  95. def LOGIN_DISABLED(self):
  96. return self.ALLOW_ANON
  97. # Depreciated variable name
  98. @property
  99. def LOCKED(self):
  100. return self.WIKI_LOCKED_PAGES[:]
  101. @property
  102. def SQLALCHEMY_DATABASE_URI(self):
  103. return self.DB_URI
  104. @property
  105. def _url(self):
  106. return urlparse(self.BASE_URL)
  107. @property
  108. def RELATIVE_PATH(self):
  109. return self._url.path
  110. USE_X_SENDFILE = False
  111. DEBUG = False
  112. ASSETS_DEBUG = False
  113. SQLALCHEMY_ECHO = False
  114. SQLALCHEMY_TRACK_MODIFICATIONS = False
  115. MODULES = ['wiki', 'search', 'auth']
  116. def __init__(self):
  117. for k, v in self.read().iteritems():
  118. setattr(self, k, v)
  119. if getattr(self, 'AUTH_LOCAL_ENABLE', True):
  120. self.MODULES.append('auth.local')
  121. if hasattr(self, 'OAUTH'):
  122. self.MODULES.append('auth.oauth')
  123. if hasattr(self, 'LDAP'):
  124. self.MODULES.append('auth.ldap')
  125. if hasattr(self, "AUTH_PROXY"):
  126. self.MODULES.append('auth.proxy')
  127. if in_vagrant():
  128. self.USE_X_SENDFILE = False
  129. if self.ENV == "DEV":
  130. self.DEBUG = True
  131. self.ASSETS_DEBUG = True
  132. self.SQLALCHEMY_ECHO = True
  133. self.USE_X_SENDFILE = False
  134. def update(self, data):
  135. conf = self.read()
  136. conf.update(data)
  137. return self.save(data)
  138. def read(self):
  139. conf = dict()
  140. for k, v in os.environ.items():
  141. if k.startswith('REALMS_'):
  142. conf[k[7:]] = v
  143. loc = self.get_path()
  144. if loc:
  145. with open(loc) as f:
  146. conf.update(json.load(f))
  147. if 'BASE_URL' in conf and conf['BASE_URL'].endswith('/'):
  148. conf['BASE_URL'] = conf['BASE_URL'][:-1]
  149. for k in ['APP_PATH', 'USER_HOME']:
  150. if k in conf:
  151. del conf[k]
  152. return conf
  153. def save(self, conf):
  154. loc = self.get_path(check_write=True)
  155. with open(loc, 'w') as f:
  156. f.write(json.dumps(conf, sort_keys=True, indent=4, separators=(',', ': ')).strip() + '\n')
  157. return loc
  158. def get_path(self, check_write=False):
  159. """Find config path
  160. """
  161. for loc in os.curdir, os.path.expanduser("~"), "/etc/realms-wiki":
  162. if not loc:
  163. continue
  164. path = os.path.join(loc, "realms-wiki.json")
  165. if os.path.isfile(path):
  166. # file exists
  167. if not check_write:
  168. # Don't care if I can write
  169. return path
  170. if os.access(path, os.W_OK):
  171. # Has write access, ok!
  172. return path
  173. elif os.path.isdir(loc) and check_write:
  174. # dir exists file doesn't
  175. if os.access(loc, os.W_OK):
  176. # can write file
  177. return path
  178. return None
  179. conf = Config()