summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2016-01-18 11:47:42 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2016-01-18 11:47:42 +0100
commit623f10b8447b87246192f750b5ea41cb4326c897 (patch)
tree73b2a8e16377e16c2d43eb1dee122171607b3ab2
parentf34e0b4a33d0bbe32726fffd44f174341f795924 (diff)
downloadpykolab-623f10b8447b87246192f750b5ea41cb4326c897.tar.gz
Add routines to set up manticore
-rw-r--r--pykolab/setup/setup_manticore.py101
-rw-r--r--share/templates/manticore.js.tpl31
2 files changed, 132 insertions, 0 deletions
diff --git a/pykolab/setup/setup_manticore.py b/pykolab/setup/setup_manticore.py
new file mode 100644
index 0000000..2f17244
--- /dev/null
+++ b/pykolab/setup/setup_manticore.py
@@ -0,0 +1,101 @@
+# -*- coding: utf-8 -*-
+# Copyright 2010-2016 Kolab Systems AG (http://www.kolabsys.com)
+#
+# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+from Cheetah.Template import Template
+import hashlib
+import os
+import random
+import re
+import subprocess
+import sys
+import time
+
+import components
+
+import pykolab
+
+from pykolab import utils
+from pykolab.constants import *
+from pykolab.translate import _
+
+log = pykolab.getLogger('pykolab.setup')
+conf = pykolab.getConf()
+
+def __init__():
+ components.register('manticore', execute, description=description(), after=['ldap','roundcube'])
+
+def description():
+ return _("Setup Manticore.")
+
+def execute(*args, **kw):
+ if not os.path.isfile('/etc/manticore/local.env.js'):
+ log.error(_("Manticore is not installed on this system"))
+ return
+
+ manticore_settings = {
+ 'fqdn': hostname + '.' + domainname,
+ 'secret': re.sub(
+ r'[^a-zA-Z0-9]',
+ "",
+ "%s%s" % (
+ hashlib.md5("%s" % random.random()).digest().encode("base64"),
+ hashlib.md5("%s" % random.random()).digest().encode("base64")
+ )
+ )[:24],
+ 'server_host': utils.parse_ldap_uri(conf.get('ldap', 'ldap_uri'))[1],
+ 'auth_key': re.sub(
+ r'[^a-zA-Z0-9]',
+ "",
+ "%s%s" % (
+ hashlib.md5("%s" % random.random()).digest().encode("base64"),
+ hashlib.md5("%s" % random.random()).digest().encode("base64")
+ )
+ )[:24],
+ 'service_bind_dn': conf.get('ldap', 'service_bind_dn'),
+ 'service_bind_pw': conf.get('ldap', 'service_bind_pw'),
+ 'user_base_dn': conf.get('ldap', 'user_base_dn')
+ }
+
+ if os.path.isfile('/etc/kolab/templates/manticore.js.tpl'):
+ fp = open('/etc/kolab/templates/manticore.js.tpl','r')
+ else:
+ fp = open('/usr/share/kolab/templates/manticore.js.tpl', 'r')
+
+ template_definition = fp.read()
+ fp.close()
+
+ t = Template(template_definition, searchList=[manticore_settings])
+
+ fp = open('/etc/manticore/local.env.js', 'w')
+ fp.write(t.__str__())
+ fp.close()
+
+ if os.path.isfile('/bin/systemctl'):
+ subprocess.call(['/bin/systemctl', 'restart', 'mongod'])
+ time.sleep(5)
+ subprocess.call(['/bin/systemctl', 'restart', 'manticore'])
+ else:
+ log.error(_("Could not start the manticore service."))
+
+ if os.path.isfile('/bin/systemctl'):
+ subprocess.call(['/bin/systemctl', 'enable', 'mongod'])
+ subprocess.call(['/bin/systemctl', 'enable', 'manticore'])
+ else:
+ log.error(_("Could not configure the manticore service to start on boot"))
+
diff --git a/share/templates/manticore.js.tpl b/share/templates/manticore.js.tpl
new file mode 100644
index 0000000..2a8a913
--- /dev/null
+++ b/share/templates/manticore.js.tpl
@@ -0,0 +1,31 @@
+'use strict';
+
+// Use local.env.js for environment variables that grunt will set when the server starts locally.
+// Use for your api keys, secrets, etc. This file should not be tracked by git.
+//
+// You will need to set these on the server you deploy to.
+
+module.exports = {
+ DOMAIN: 'http://$fqdn:8080',
+ SESSION_SECRET: 'manticore-secret',
+
+ // Control debug level for modules using visionmedia/debug
+ DEBUG: '',
+
+ DEFAULT_ACCESS: 'deny',
+
+ AUTH: 'ldap',
+ STORAGE: 'chwala',
+
+ CHWALA_SERVER: 'http://$fqdn/chwala/api/document',
+ ROUNDCUBE_SERVER: 'http://$fqdn/roundcubemail',
+
+ AUTH_ENCRYPTION_KEY: 'suchauth123muchkey456',
+
+ LDAP_SERVER: 'ldap://$server_host:389',
+ LDAP_BASE: '$user_base_dn',
+ LDAP_FILTER: '(&(objectclass=kolabinetorgperson)(|(uid={{username}})(mail={{username}})))',
+ LDAP_BIND_DN: '$service_bind_dn',
+ LDAP_BIND_PW: '$service_bind_pw'
+
+};