Fixes on apache2 backend

This commit is contained in:
Marc 2014-10-17 14:59:06 +00:00
parent 21af6d5ee1
commit 8a818ecb87
1 changed files with 11 additions and 7 deletions

View File

@ -43,10 +43,14 @@ class Apache2Backend(ServiceController):
apache_conf += self.get_protections(site) apache_conf += self.get_protections(site)
context['apache_conf'] = apache_conf context['apache_conf'] = apache_conf
self.append( self.append(textwrap.dedent("""\
"{ echo -e '%(apache_conf)s' | diff -N -I'^\s*#' %(sites_available)s - ; } ||" {
" { echo -e '%(apache_conf)s' > %(sites_available)s; UPDATED=1; }" % context echo -e '%(apache_conf)s' | diff -N -I'^\s*#' %(sites_available)s -
) } || {
echo -e '%(apache_conf)s' > %(sites_available)s
UPDATED=1
}""" % context
))
self.enable_or_disable(site) self.enable_or_disable(site)
def delete(self, site): def delete(self, site):
@ -108,8 +112,8 @@ class Apache2Backend(ServiceController):
def get_security(self, site): def get_security(self, site):
directives = '' directives = ''
for rules in site.options.filter(name='sec_rule_remove'): for rules in site.options.filter(name='sec_rule_remove'):
for rule in rules.split(): for rule in rules.value.split():
directives += "SecRuleRemoveById %d" % rule directives += "SecRuleRemoveById %i" % int(rule)
for modsecurity in site.options.filter(name='sec_rule_off'): for modsecurity in site.options.filter(name='sec_rule_off'):
directives += textwrap.dedent("""\ directives += textwrap.dedent("""\
@ -143,7 +147,7 @@ class Apache2Backend(ServiceController):
def enable_or_disable(self, site): def enable_or_disable(self, site):
context = self.get_context(site) context = self.get_context(site)
self.append("ls -l %(sites_enabled)s; DISABLED=$?" % context) self.append("ls -l %(sites_enabled)s > /dev/null; DISABLED=$?" % context)
if site.is_active: if site.is_active:
self.append("if [[ $DISABLED ]]; then a2ensite %(site_unique_name)s.conf;\n" self.append("if [[ $DISABLED ]]; then a2ensite %(site_unique_name)s.conf;\n"
"else UPDATED=0; fi" % context) "else UPDATED=0; fi" % context)