diff --git a/orchestra/contrib/saas/backends/bscw.py b/orchestra/contrib/saas/backends/bscw.py
index 351f5276..ab21e0e6 100644
--- a/orchestra/contrib/saas/backends/bscw.py
+++ b/orchestra/contrib/saas/backends/bscw.py
@@ -19,10 +19,10 @@ class BSCWBackend(ServiceController):
def validate_creation(self, saas):
context = self.get_context(saas)
self.append(textwrap.dedent("""\
- if %(bsadmin)s register %(email)s > /dev/null; then
+ if [[ $(%(bsadmin)s register %(email)s) ]]; then
echo 'ValidationError: email-exists'
fi
- if %(bsadmin)s users -n %(username)s > /dev/null; then
+ if [[ $(%(bsadmin)s users -n %(username)s) ]]; then
echo 'ValidationError: user-exists'
fi""") % context
)
diff --git a/orchestra/contrib/webapps/backends/__init__.py b/orchestra/contrib/webapps/backends/__init__.py
index dfd60f34..da79b48d 100644
--- a/orchestra/contrib/webapps/backends/__init__.py
+++ b/orchestra/contrib/webapps/backends/__init__.py
@@ -28,11 +28,11 @@ class WebAppServiceMixin(object):
if context['under_construction_path']:
self.append(textwrap.dedent("""
# 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
nohup bash -c '
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
chown -R %(user)s:%(group)s %(app_path)s
fi' &> /dev/null &
diff --git a/orchestra/contrib/websites/backends/apache.py b/orchestra/contrib/websites/backends/apache.py
index 301013fc..01d8ee7e 100644
--- a/orchestra/contrib/websites/backends/apache.py
+++ b/orchestra/contrib/websites/backends/apache.py
@@ -291,24 +291,26 @@ class Apache2Backend(ServiceController):
]
def get_security(self, directives):
- remove_rules = []
+ rules = []
for values in directives.get('sec-rule-remove', []):
for rule in values.split():
- sec_rule = " SecRuleRemoveById %i" % int(rule)
- remove_rules.append(sec_rule)
- security = []
- if remove_rules:
- remove_rules.insert(0, '')
- remove_rules.append('')
- security.append(('', '\n'.join(remove_rules)))
+ rules.append('SecRuleRemoveById %i' % int(rule))
for location in directives.get('sec-engine', []):
- sec_rule = textwrap.dedent("""\
-
+ if location == '/':
+ rules.append('SecRuleEngine Off')
+ else:
+ rules.append(textwrap.dedent("""\
SecRuleEngine Off
-
- """) % location
- security.append((location, sec_rule))
+ """) % location
+ )
+ security = []
+ if rules:
+ rules = textwrap.dedent("""\
+
+ %s
+ """) % '\n '.join(rules)
+ security.append((location, rules))
return security
def get_redirects(self, directives):
diff --git a/orchestra/contrib/websites/backends/wordpress.py b/orchestra/contrib/websites/backends/wordpress.py
new file mode 100644
index 00000000..1a98d86b
--- /dev/null
+++ b/orchestra/contrib/websites/backends/wordpress.py
@@ -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'),
+ }
diff --git a/orchestra/contrib/websites/directives.py b/orchestra/contrib/websites/directives.py
index a017f251..475c5a15 100644
--- a/orchestra/contrib/websites/directives.py
+++ b/orchestra/contrib/websites/directives.py
@@ -106,7 +106,7 @@ class Redirect(SiteDirective):
unique_location = True
def validate(self, directive):
- """ inserts default url path if not provided """
+ """ inserts default url-path if not provided """
values = directive.value.strip().split()
if len(values) == 1:
values.insert(0, '/')
@@ -167,7 +167,7 @@ class SecRuleRemove(SiteDirective):
class SecEngine(SecRuleRemove):
name = 'sec-engine'
verbose_name = _("SecRuleEngine Off")
- help_text = _("URL path with disabled modsecurity engine.")
+ help_text = _("URL-path with disabled modsecurity engine.")
regex = r'^/[^ ]*$'
unique_location = False
@@ -175,7 +175,7 @@ class SecEngine(SecRuleRemove):
class WordPressSaaS(SiteDirective):
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
regex = r'^/[^ ]*$'
unique_value = True
@@ -185,10 +185,10 @@ class WordPressSaaS(SiteDirective):
class DokuWikiSaaS(WordPressSaaS):
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):
name = 'drupal-saas'
verbose_name = "Drupdal SaaS"
- help_text = _("URL path for mounting wordpress multisite.")
+ help_text = _("URL-path for mounting wordpress multisite.")
diff --git a/orchestra/contrib/websites/models.py b/orchestra/contrib/websites/models.py
index 62d660b9..7e3b57b7 100644
--- a/orchestra/contrib/websites/models.py
+++ b/orchestra/contrib/websites/models.py
@@ -148,6 +148,10 @@ class Content(models.Model):
except Website.DoesNotExist:
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):
if not self.path:
self.path = '/'
diff --git a/orchestra/core/validators.py b/orchestra/core/validators.py
index ae8906ef..e13ad0c6 100644
--- a/orchestra/core/validators.py
+++ b/orchestra/core/validators.py
@@ -118,7 +118,7 @@ def validate_password(value):
def validate_url_path(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):