2015-03-10 21:51:10 +00:00
|
|
|
import re
|
|
|
|
|
2015-03-10 11:46:48 +00:00
|
|
|
from django.core.exceptions import ValidationError
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
|
|
from orchestra.plugins import Plugin
|
|
|
|
from orchestra.utils.functional import cached
|
|
|
|
from orchestra.utils.python import import_class
|
|
|
|
|
|
|
|
from . import settings
|
|
|
|
|
|
|
|
|
|
|
|
# TODO multiple and unique validation support in the formset
|
|
|
|
class SiteDirective(Plugin):
|
2015-03-10 16:57:23 +00:00
|
|
|
HTTPD = 'HTTPD'
|
|
|
|
SEC = 'ModSecurity'
|
|
|
|
SSL = 'SSL'
|
2015-03-23 15:36:51 +00:00
|
|
|
SAAS = 'SaaS'
|
2015-03-10 11:46:48 +00:00
|
|
|
|
|
|
|
help_text = ""
|
2015-03-25 15:45:04 +00:00
|
|
|
unique_name = False
|
|
|
|
unique_value = False
|
2015-03-10 11:46:48 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@cached
|
|
|
|
def get_plugins(cls):
|
|
|
|
plugins = []
|
|
|
|
for cls in settings.WEBSITES_ENABLED_DIRECTIVES:
|
|
|
|
plugins.append(import_class(cls))
|
|
|
|
return plugins
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@cached
|
|
|
|
def get_option_groups(cls):
|
|
|
|
groups = {}
|
|
|
|
for opt in cls.get_plugins():
|
|
|
|
try:
|
|
|
|
groups[opt.group].append(opt)
|
|
|
|
except KeyError:
|
|
|
|
groups[opt.group] = [opt]
|
|
|
|
return groups
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_plugin_choices(cls):
|
|
|
|
""" Generates grouped choices ready to use in Field.choices """
|
|
|
|
# generators can not be @cached
|
|
|
|
yield (None, '-------')
|
|
|
|
options = cls.get_option_groups()
|
|
|
|
for option in options.pop(None, ()):
|
|
|
|
yield (option.name, option.verbose_name)
|
|
|
|
for group, options in options.iteritems():
|
|
|
|
yield (group, [(op.name, op.verbose_name) for op in options])
|
|
|
|
|
|
|
|
def validate(self, website):
|
|
|
|
if self.regex and not re.match(self.regex, website.value):
|
|
|
|
raise ValidationError({
|
|
|
|
'value': ValidationError(_("'%(value)s' does not match %(regex)s."),
|
|
|
|
params={
|
|
|
|
'value': website.value,
|
|
|
|
'regex': self.regex
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
class Redirect(SiteDirective):
|
|
|
|
name = 'redirect'
|
2015-03-10 21:51:10 +00:00
|
|
|
verbose_name = _("Redirection")
|
2015-03-10 11:46:48 +00:00
|
|
|
help_text = _("<tt><website path> <destination URL></tt>")
|
|
|
|
regex = r'^[^ ]+\s[^ ]+$'
|
|
|
|
group = SiteDirective.HTTPD
|
2015-03-25 15:45:04 +00:00
|
|
|
unique_value = True
|
2015-03-10 11:46:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Proxy(SiteDirective):
|
|
|
|
name = 'proxy'
|
2015-03-10 21:51:10 +00:00
|
|
|
verbose_name = _("Proxy")
|
2015-03-10 11:46:48 +00:00
|
|
|
help_text = _("<tt><website path> <target URL></tt>")
|
|
|
|
regex = r'^[^ ]+\shttp[^ ]+(timeout=[0-9]{1,3}|retry=[0-9]|\s)*$'
|
|
|
|
group = SiteDirective.HTTPD
|
2015-03-25 15:45:04 +00:00
|
|
|
unique_value = True
|
2015-03-10 11:46:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ErrorDocument(SiteDirective):
|
|
|
|
name = 'error_document'
|
2015-03-10 21:51:10 +00:00
|
|
|
verbose_name = _("ErrorDocumentRoot")
|
2015-03-10 11:46:48 +00:00
|
|
|
help_text = _("<error code> <URL/path/message><br>"
|
|
|
|
"<tt> 500 http://foo.example.com/cgi-bin/tester</tt><br>"
|
|
|
|
"<tt> 404 /cgi-bin/bad_urls.pl</tt><br>"
|
|
|
|
"<tt> 401 /subscription_info.html</tt><br>"
|
|
|
|
"<tt> 403 \"Sorry can't allow you access today\"</tt>")
|
|
|
|
regex = r'[45]0[0-9]\s.*'
|
|
|
|
group = SiteDirective.HTTPD
|
2015-03-25 15:45:04 +00:00
|
|
|
unique_value = True
|
2015-03-10 11:46:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SSLCA(SiteDirective):
|
|
|
|
name = 'ssl_ca'
|
2015-03-10 21:51:10 +00:00
|
|
|
verbose_name = _("SSL CA")
|
2015-03-10 11:46:48 +00:00
|
|
|
help_text = _("Filesystem path of the CA certificate file.")
|
|
|
|
regex = r'^[^ ]+$'
|
|
|
|
group = SiteDirective.SSL
|
2015-03-25 15:45:04 +00:00
|
|
|
unique_name = True
|
2015-03-10 11:46:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SSLCert(SiteDirective):
|
|
|
|
name = 'ssl_cert'
|
2015-03-10 21:51:10 +00:00
|
|
|
verbose_name = _("SSL cert")
|
2015-03-10 11:46:48 +00:00
|
|
|
help_text = _("Filesystem path of the certificate file.")
|
|
|
|
regex = r'^[^ ]+$'
|
|
|
|
group = SiteDirective.SSL
|
2015-03-25 15:45:04 +00:00
|
|
|
unique_name = True
|
2015-03-10 11:46:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SSLKey(SiteDirective):
|
|
|
|
name = 'ssl_key'
|
2015-03-10 21:51:10 +00:00
|
|
|
verbose_name = _("SSL key")
|
2015-03-10 11:46:48 +00:00
|
|
|
help_text = _("Filesystem path of the key file.")
|
|
|
|
regex = r'^[^ ]+$'
|
|
|
|
group = SiteDirective.SSL
|
2015-03-25 15:45:04 +00:00
|
|
|
unique_name = True
|
2015-03-10 11:46:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SecRuleRemove(SiteDirective):
|
|
|
|
name = 'sec_rule_remove'
|
2015-03-10 21:51:10 +00:00
|
|
|
verbose_name = _("SecRuleRemoveById")
|
2015-03-10 11:46:48 +00:00
|
|
|
help_text = _("Space separated ModSecurity rule IDs.")
|
|
|
|
regex = r'^[0-9\s]+$'
|
|
|
|
group = SiteDirective.SEC
|
|
|
|
|
|
|
|
|
|
|
|
class SecEngine(SiteDirective):
|
|
|
|
name = 'sec_engine'
|
2015-03-25 15:45:04 +00:00
|
|
|
verbose_name = _("SecRuleEngine Off")
|
|
|
|
help_text = _("URL path with disabled modsecurity engine.")
|
2015-03-12 14:05:23 +00:00
|
|
|
regex = r'^/[^ ]*$'
|
2015-03-10 11:46:48 +00:00
|
|
|
group = SiteDirective.SEC
|
2015-03-25 15:45:04 +00:00
|
|
|
unique_value = True
|
2015-03-23 15:36:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
class WordPressSaaS(SiteDirective):
|
|
|
|
name = 'wordpress-saas'
|
2015-03-25 15:45:04 +00:00
|
|
|
verbose_name = "WordPress SaaS"
|
|
|
|
help_text = _("URL path for mounting wordpress multisite.")
|
2015-03-23 15:36:51 +00:00
|
|
|
# fpm_listen = settings.WEBAPPS_WORDPRESSMU_LISTEN
|
|
|
|
group = SiteDirective.SAAS
|
|
|
|
regex = r'^/[^ ]*$'
|
2015-03-25 15:45:04 +00:00
|
|
|
unique_value = True
|
2015-03-23 15:36:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DokuWikiSaaS(SiteDirective):
|
|
|
|
name = 'dokuwiki-saas'
|
2015-03-25 15:45:04 +00:00
|
|
|
verbose_name = "DokuWiki SaaS"
|
|
|
|
help_text = _("URL path for mounting wordpress multisite.")
|
2015-03-23 15:36:51 +00:00
|
|
|
# fpm_listen = settings.WEBAPPS_DOKUWIKIMU_LISTEN
|
|
|
|
group = SiteDirective.SAAS
|
|
|
|
regex = r'^/[^ ]*$'
|
2015-03-25 15:45:04 +00:00
|
|
|
unique_value = True
|
2015-03-23 15:36:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DrupalSaaS(SiteDirective):
|
|
|
|
name = 'drupal-saas'
|
2015-03-25 15:45:04 +00:00
|
|
|
verbose_name = "Drupdal SaaS"
|
|
|
|
help_text = _("URL path for mounting wordpress multisite.")
|
2015-03-23 15:36:51 +00:00
|
|
|
# fpm_listen = settings.WEBAPPS_DRUPALMU_LISTEN
|
|
|
|
group = SiteDirective.SAAS
|
|
|
|
regex = r'^/[^ ]*$'
|
2015-03-25 15:45:04 +00:00
|
|
|
unique_value = True
|