Added wordpressurlbackend
This commit is contained in:
parent
6715f2ee2b
commit
6d8ce2bbc1
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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 &
|
||||
|
|
|
@ -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, '<IfModule mod_security2.c>')
|
||||
remove_rules.append('</IfModule>')
|
||||
security.append(('', '\n'.join(remove_rules)))
|
||||
rules.append('SecRuleRemoveById %i' % int(rule))
|
||||
for location in directives.get('sec-engine', []):
|
||||
sec_rule = textwrap.dedent("""\
|
||||
<IfModule mod_security2.c>
|
||||
if location == '/':
|
||||
rules.append('SecRuleEngine Off')
|
||||
else:
|
||||
rules.append(textwrap.dedent("""\
|
||||
<Location %s>
|
||||
SecRuleEngine Off
|
||||
</Location>
|
||||
</IfModule>""") % location
|
||||
security.append((location, sec_rule))
|
||||
</Location>""") % location
|
||||
)
|
||||
security = []
|
||||
if rules:
|
||||
rules = textwrap.dedent("""\
|
||||
<IfModule mod_security2.c>
|
||||
%s
|
||||
</IfModule>""") % '\n '.join(rules)
|
||||
security.append((location, rules))
|
||||
return security
|
||||
|
||||
def get_redirects(self, directives):
|
||||
|
|
|
@ -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'),
|
||||
}
|
|
@ -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.")
|
||||
|
|
|
@ -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 = '/'
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue