django-orchestra/orchestra/contrib/saas/backends/dokuwikimu.py

67 lines
2.3 KiB
Python
Raw Normal View History

2015-06-09 11:16:36 +00:00
import crypt
2014-09-26 15:05:20 +00:00
import os
2015-06-09 11:16:36 +00:00
import textwrap
2014-09-26 15:05:20 +00:00
2014-05-08 16:59:35 +00:00
from django.utils.translation import ugettext_lazy as _
2015-06-09 11:16:36 +00:00
from orchestra.contrib.orchestration import ServiceController
from orchestra.utils.python import random_ascii
2014-05-08 16:59:35 +00:00
from .. import settings
2014-07-09 16:17:43 +00:00
2014-11-27 19:17:26 +00:00
class DokuWikiMuBackend(ServiceController):
2015-04-24 11:39:20 +00:00
"""
Creates a DokuWiki site on a DokuWiki multisite installation.
"""
2015-06-09 11:16:36 +00:00
name = 'dokuwiki'
2014-05-08 16:59:35 +00:00
verbose_name = _("DokuWiki multisite")
2015-06-09 11:16:36 +00:00
model = 'saas.SaaS'
default_route_match = "saas.service == 'dokuwiki'"
doc_settings = (settings, (
'SAAS_DOKUWIKI_TEMPLATE_PATH',
'SAAS_DOKUWIKI_FARM_PATH',
'SAAS_DOKUWIKI_USER',
'SAAS_DOKUWIKI_GROUP',
))
2014-05-08 16:59:35 +00:00
2015-06-09 11:16:36 +00:00
def save(self, saas):
context = self.get_context(saas)
self.append(textwrap.dedent("""
if [[ ! -e %(app_path)s ]]; then
mkdir %(app_path)s
tar xfz %(template)s -C %(app_path)s
chown -R %(user)s:%(group)s %(app_path)s
fi""") % context
)
if context['password']:
self.append(textwrap.dedent("""\
if [[ $(grep '^admin:' %(users_path)s) ]]; then
sed -i 's#^admin:.*$#admin:%(password)s:admin:%(email)s:admin,user#' %(users_path)s
else
echo 'admin:%(password)s:admin:%(email)s:admin,user' >> %(users_path)s
fi""") % context
)
2014-05-08 16:59:35 +00:00
2015-06-09 11:16:36 +00:00
def delete(self, saas):
context = self.get_context(saas)
2014-05-08 16:59:35 +00:00
self.append("rm -fr %(app_path)s" % context)
2015-06-09 11:16:36 +00:00
def get_context(self, saas):
context = super(DokuWikiMuBackend, self).get_context(saas)
2014-05-08 16:59:35 +00:00
context.update({
2015-04-24 11:39:20 +00:00
'template': settings.SAAS_DOKUWIKI_TEMPLATE_PATH,
2015-06-09 11:16:36 +00:00
'farm_path': settings.SAAS_DOKUWIKI_FARM_PATH,
'app_path': os.path.join(settings.SAAS_DOKUWIKI_FARM_PATH, saas.get_site_domain()),
'user': settings.SAAS_DOKUWIKI_USER,
'group': settings.SAAS_DOKUWIKI_GROUP,
'email': saas.account.email,
2014-05-08 16:59:35 +00:00
})
2015-06-09 11:16:36 +00:00
password = getattr(saas, 'password', None)
salt = random_ascii(8)
context.update({
'password': crypt.crypt(password, '$1$'+salt) if password else None,
'users_path': os.path.join(context['app_path'], 'conf/users.auth.php'),
})
return context