Added wordpressurlbackend

This commit is contained in:
Marc Aymerich 2015-09-28 10:51:03 +00:00
parent 6715f2ee2b
commit 6d8ce2bbc1
7 changed files with 69 additions and 23 deletions

View file

@ -19,10 +19,10 @@ class BSCWBackend(ServiceController):
def validate_creation(self, saas): def validate_creation(self, saas):
context = self.get_context(saas) context = self.get_context(saas)
self.append(textwrap.dedent("""\ self.append(textwrap.dedent("""\
if %(bsadmin)s register %(email)s > /dev/null; then if [[ $(%(bsadmin)s register %(email)s) ]]; then
echo 'ValidationError: email-exists' echo 'ValidationError: email-exists'
fi fi
if %(bsadmin)s users -n %(username)s > /dev/null; then if [[ $(%(bsadmin)s users -n %(username)s) ]]; then
echo 'ValidationError: user-exists' echo 'ValidationError: user-exists'
fi""") % context fi""") % context
) )

View file

@ -28,11 +28,11 @@ class WebAppServiceMixin(object):
if context['under_construction_path']: if context['under_construction_path']:
self.append(textwrap.dedent(""" self.append(textwrap.dedent("""
# Set under construction if needed # Set under construction if needed
if [[ $CREATED == 1 ]] && ! ls -A %(app_path)s > /dev/null; then if [[ $CREATED == 1 && ! $(ls -A %(app_path)s) ]]; then
# Async wait 2 more seconds for other backends to lock app_path or cp under construction # Async wait 2 more seconds for other backends to lock app_path or cp under construction
nohup bash -c ' nohup bash -c '
sleep 2 sleep 2
if ! ls -A %(app_path)s > /dev/null; then if [[ ! $(ls -A %(app_path)s) ]]; then
cp -r %(under_construction_path)s %(app_path)s cp -r %(under_construction_path)s %(app_path)s
chown -R %(user)s:%(group)s %(app_path)s chown -R %(user)s:%(group)s %(app_path)s
fi' &> /dev/null & fi' &> /dev/null &

View file

@ -291,24 +291,26 @@ class Apache2Backend(ServiceController):
] ]
def get_security(self, directives): def get_security(self, directives):
remove_rules = [] rules = []
for values in directives.get('sec-rule-remove', []): for values in directives.get('sec-rule-remove', []):
for rule in values.split(): for rule in values.split():
sec_rule = " SecRuleRemoveById %i" % int(rule) rules.append('SecRuleRemoveById %i' % int(rule))
remove_rules.append(sec_rule)
security = []
if remove_rules:
remove_rules.insert(0, '<IfModule mod_security2.c>')
remove_rules.append('</IfModule>')
security.append(('', '\n'.join(remove_rules)))
for location in directives.get('sec-engine', []): for location in directives.get('sec-engine', []):
sec_rule = textwrap.dedent("""\ if location == '/':
<IfModule mod_security2.c> rules.append('SecRuleEngine Off')
else:
rules.append(textwrap.dedent("""\
<Location %s> <Location %s>
SecRuleEngine Off SecRuleEngine Off
</Location> </Location>""") % location
</IfModule>""") % location )
security.append((location, sec_rule)) security = []
if rules:
rules = textwrap.dedent("""\
<IfModule mod_security2.c>
%s
</IfModule>""") % '\n '.join(rules)
security.append((location, rules))
return security return security
def get_redirects(self, directives): def get_redirects(self, directives):

View file

@ -0,0 +1,40 @@
import os
import textwrap
from django.utils.translation import ugettext_lazy as _
from orchestra.contrib.orchestration import ServiceController
class WordPressURLBackend(ServiceController):
"""
Configures WordPress site URL with associated website domain.
"""
verbose_name = _("WordPress URL")
model = 'websites.Content'
default_route_match = "content.webapp.type == 'wordpress-php'"
def save(self, content):
context = self.get_context(content)
if context['url']:
self.append(textwrap.dedent("""\
mysql %(db_name)s -e 'UPDATE wp_options
SET option_value="%(url)s"
WHERE option_id IN (1, 2) AND option_value="http:";'
""") % context
)
def delete(self, content):
context = self.get_context(content)
self.append(textwrap.dedent("""\
mysql %(db_name)s -e 'UPDATE wp_options
SET option_value="http:"
WHERE option_id IN (1, 2);'
""") % context
)
def get_context(self, content):
return {
'url': content.get_absolute_url(),
'db_name': content.webapp.data.get('db_name'),
}

View file

@ -106,7 +106,7 @@ class Redirect(SiteDirective):
unique_location = True unique_location = True
def validate(self, directive): def validate(self, directive):
""" inserts default url path if not provided """ """ inserts default url-path if not provided """
values = directive.value.strip().split() values = directive.value.strip().split()
if len(values) == 1: if len(values) == 1:
values.insert(0, '/') values.insert(0, '/')
@ -167,7 +167,7 @@ class SecRuleRemove(SiteDirective):
class SecEngine(SecRuleRemove): class SecEngine(SecRuleRemove):
name = 'sec-engine' name = 'sec-engine'
verbose_name = _("SecRuleEngine Off") verbose_name = _("SecRuleEngine Off")
help_text = _("URL path with disabled modsecurity engine.") help_text = _("URL-path with disabled modsecurity engine.")
regex = r'^/[^ ]*$' regex = r'^/[^ ]*$'
unique_location = False unique_location = False
@ -175,7 +175,7 @@ class SecEngine(SecRuleRemove):
class WordPressSaaS(SiteDirective): class WordPressSaaS(SiteDirective):
name = 'wordpress-saas' name = 'wordpress-saas'
verbose_name = "WordPress SaaS" verbose_name = "WordPress SaaS"
help_text = _("URL path for mounting wordpress multisite.") help_text = _("URL-path for mounting wordpress multisite.")
group = SiteDirective.SAAS group = SiteDirective.SAAS
regex = r'^/[^ ]*$' regex = r'^/[^ ]*$'
unique_value = True unique_value = True
@ -185,10 +185,10 @@ class WordPressSaaS(SiteDirective):
class DokuWikiSaaS(WordPressSaaS): class DokuWikiSaaS(WordPressSaaS):
name = 'dokuwiki-saas' name = 'dokuwiki-saas'
verbose_name = "DokuWiki SaaS" verbose_name = "DokuWiki SaaS"
help_text = _("URL path for mounting wordpress multisite.") help_text = _("URL-path for mounting wordpress multisite.")
class DrupalSaaS(WordPressSaaS): class DrupalSaaS(WordPressSaaS):
name = 'drupal-saas' name = 'drupal-saas'
verbose_name = "Drupdal SaaS" verbose_name = "Drupdal SaaS"
help_text = _("URL path for mounting wordpress multisite.") help_text = _("URL-path for mounting wordpress multisite.")

View file

@ -148,6 +148,10 @@ class Content(models.Model):
except Website.DoesNotExist: except Website.DoesNotExist:
return self.path return self.path
def clean_fields(self, *args, **kwargs):
self.path = self.path.strip()
return super(Content, self).clean_fields(*args, **kwargs)
def clean(self): def clean(self):
if not self.path: if not self.path:
self.path = '/' self.path = '/'

View file

@ -118,7 +118,7 @@ def validate_password(value):
def validate_url_path(value): def validate_url_path(value):
if not re.match(r'^\/[/.a-zA-Z0-9-_]*$', value): if not re.match(r'^\/[/.a-zA-Z0-9-_]*$', value):
raise ValidationError(_('"%s" is not a valid URL path.') % value) raise ValidationError(_('"%s" is not a valid URL-path.') % value)
def validate_vat(vat, country): def validate_vat(vat, country):