Fixes on mailman backend

This commit is contained in:
Marc 2014-10-27 15:15:22 +00:00
parent d85ada93e7
commit 0a522884a7
3 changed files with 15 additions and 11 deletions

View file

@ -40,7 +40,7 @@ class Bind9MasterDomainBackend(ServiceController):
self.append(textwrap.dedent("""\ self.append(textwrap.dedent("""\
sed '/zone "%(name)s".*/,/^\s*};\s*$/!d' %(conf_path)s | diff -B -I"^\s*//" - <(echo '%(conf)s') || { sed '/zone "%(name)s".*/,/^\s*};\s*$/!d' %(conf_path)s | diff -B -I"^\s*//" - <(echo '%(conf)s') || {
sed -i -e '/zone\s\s*"%(name)s".*/,/^\s*};/d' \\ sed -i -e '/zone\s\s*"%(name)s".*/,/^\s*};/d' \\
-e 'N; /^\\n$/d; P; D' %(conf_path)s -e 'N; /^\s*\\n\s*$/d; P; D' %(conf_path)s
echo '%(conf)s' >> %(conf_path)s echo '%(conf)s' >> %(conf_path)s
UPDATED=1 UPDATED=1
}""" % context }""" % context
@ -48,7 +48,7 @@ class Bind9MasterDomainBackend(ServiceController):
# Delete ex-top-domains that are now subdomains # Delete ex-top-domains that are now subdomains
self.append(textwrap.dedent("""\ self.append(textwrap.dedent("""\
sed -i -e '/zone\s\s*".*\.%(name)s".*/,/^\s*};\s*$/d' \\ sed -i -e '/zone\s\s*".*\.%(name)s".*/,/^\s*};\s*$/d' \\
-e 'N; /^\\n$/d; P; D' %(conf_path)s""" % context -e 'N; /^\s*\\n\s*$/d; P; D' %(conf_path)s""" % context
)) ))
if 'zone_path' in context: if 'zone_path' in context:
context['zone_subdomains_path'] = re.sub(r'^(.*/)', r'\1*.', context['zone_path']) context['zone_subdomains_path'] = re.sub(r'^(.*/)', r'\1*.', context['zone_path'])
@ -65,7 +65,7 @@ class Bind9MasterDomainBackend(ServiceController):
return return
self.append(textwrap.dedent("""\ self.append(textwrap.dedent("""\
sed -e '/zone\s\s*"%(name)s".*/,/^\s*};\s*$/d' \\ sed -e '/zone\s\s*"%(name)s".*/,/^\s*};\s*$/d' \\
-e 'N; /^\\n$/d; P; D' %(conf_path)s > %(conf_path)s.tmp""" % context -e 'N; /^\s*\\n\s*$/d; P; D' %(conf_path)s > %(conf_path)s.tmp""" % context
)) ))
self.append('diff -B -I"^\s*//" %(conf_path)s.tmp %(conf_path)s || UPDATED=1' % context) self.append('diff -B -I"^\s*//" %(conf_path)s.tmp %(conf_path)s || UPDATED=1' % context)
self.append('mv %(conf_path)s.tmp %(conf_path)s' % context) self.append('mv %(conf_path)s.tmp %(conf_path)s' % context)

View file

@ -72,7 +72,8 @@ class MailmanBackend(ServiceController):
UPDATED_VIRTUAL_ALIAS=1 UPDATED_VIRTUAL_ALIAS=1
else else
if [[ ! $(grep '^\s*%(address_name)s@%(address_domain)s\s\s*%(name)s\s*$' %(virtual_alias)s) ]]; then if [[ ! $(grep '^\s*%(address_name)s@%(address_domain)s\s\s*%(name)s\s*$' %(virtual_alias)s) ]]; then
sed -i "/^.*\s%(name)s\s*$/d" %(virtual_alias)s sed -i -e '/^.*\s%(name)s\(%(address_regex)s\)\s*$/d' \\
-e 'N; /^\s*\\n\s*$/d; P; D' %(virtual_alias)s
echo '# %(banner)s\n%(aliases)s echo '# %(banner)s\n%(aliases)s
' >> %(virtual_alias)s ' >> %(virtual_alias)s
UPDATED_VIRTUAL_ALIAS=1 UPDATED_VIRTUAL_ALIAS=1
@ -99,10 +100,10 @@ class MailmanBackend(ServiceController):
def delete(self, mail_list): def delete(self, mail_list):
context = self.get_context(mail_list) context = self.get_context(mail_list)
self.exclude_virtual_alias_domain(context) self.exclude_virtual_alias_domain(context)
self.append('sed -i "/^\s*Generated by.*%(name)s\s*$/d" %(virtual_alias)s' % context) self.append(textwrap.dedent("""\
for address in self.addresses: sed -i -e '/^.*\s%(name)s\(%(address_regex)s\)\s*$/d' \\
context['address'] = address -e 'N; /^\s*\\n\s*$/d; P; D' %(virtual_alias)s""" % context
self.append('sed -i "/^.*\s%(name)s%(address)s\s*$/d" %(virtual_alias)s' % context) ))
self.append("rmlist -a %(name)s" % context) self.append("rmlist -a %(name)s" % context)
def commit(self): def commit(self):
@ -126,12 +127,13 @@ class MailmanBackend(ServiceController):
def get_context(self, mail_list): def get_context(self, mail_list):
context = self.get_context_files() context = self.get_context_files()
context.update({ context.update({
'banner': self.get_banner(), 'banner': self.get_banner(mail_list),
'name': mail_list.name, 'name': mail_list.name,
'password': mail_list.password, 'password': mail_list.password,
'domain': mail_list.address_domain or settings.LISTS_DEFAULT_DOMAIN, 'domain': mail_list.address_domain or settings.LISTS_DEFAULT_DOMAIN,
'address_name': mail_list.get_address_name(), 'address_name': mail_list.get_address_name(),
'address_domain': mail_list.address_domain, 'address_domain': mail_list.address_domain,
'address_regex': '\|'.join(self.addresses),
'admin': mail_list.admin_email, 'admin': mail_list.admin_email,
'mailman_root': settings.LISTS_MAILMAN_ROOT_PATH, 'mailman_root': settings.LISTS_MAILMAN_ROOT_PATH,
}) })

View file

@ -8,6 +8,7 @@ import select
import paramiko import paramiko
from celery.datastructures import ExceptionInfo from celery.datastructures import ExceptionInfo
from django.conf import settings as djsettings
from . import settings from . import settings
@ -61,12 +62,13 @@ def BashSSH(backend, log, server, cmds):
# Execute it # Execute it
context = { context = {
'remote_path': remote_path, 'remote_path': remote_path,
'digest': digest 'digest': digest,
'remove': '' if djsettings.DEBUG else "rm -fr %(remote_path)s\n",
} }
cmd = ( cmd = (
"[[ $(md5sum %(remote_path)s|awk {'print $1'}) == %(digest)s ]] && bash %(remote_path)s\n" "[[ $(md5sum %(remote_path)s|awk {'print $1'}) == %(digest)s ]] && bash %(remote_path)s\n"
"RETURN_CODE=$?\n" "RETURN_CODE=$?\n"
"rm -fr %(remote_path)s\n" "%(remove)s"
"exit $RETURN_CODE" % context "exit $RETURN_CODE" % context
) )
channel = transport.open_session() channel = transport.open_session()