2008-04-05 20:48:33 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2007-02-12 22:39:14 +01:00
|
|
|
#
|
2008-04-05 20:48:33 +02:00
|
|
|
# Copyright (C) 2007, 2008 by Jan Dittberner.
|
2007-02-12 22:39:14 +01:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
# USA.
|
|
|
|
#
|
2008-06-06 21:20:18 +02:00
|
|
|
# Version: $Id$
|
2008-06-07 23:25:35 +02:00
|
|
|
"""This module defines the code for handling domains."""
|
2007-02-12 22:39:14 +01:00
|
|
|
|
2008-06-06 21:20:18 +02:00
|
|
|
import datetime
|
|
|
|
import os
|
2007-02-12 22:39:14 +01:00
|
|
|
|
2008-06-07 23:25:35 +02:00
|
|
|
from gnuviechadmin.exceptions import ValidationFailedError
|
|
|
|
from gnuviechadmin.backend.settings import config, get_template, \
|
|
|
|
get_template_dir, get_template_string
|
|
|
|
from gnuviechadmin.backend.BackendTo import Record, Domain
|
|
|
|
from gnuviechadmin.backend.BackendEntity import BackendEntity
|
|
|
|
from gnuviechadmin.backend.BackendEntityHandler import BackendEntityHandler
|
2007-02-12 22:39:14 +01:00
|
|
|
|
2008-06-06 21:20:18 +02:00
|
|
|
|
2007-07-09 08:46:36 +02:00
|
|
|
class DomainEntity(BackendEntity):
|
2007-07-02 11:14:47 +02:00
|
|
|
"""Entity class for DNS domains."""
|
|
|
|
|
2008-06-07 23:25:35 +02:00
|
|
|
# the valid domain types
|
2007-07-05 11:00:34 +02:00
|
|
|
_valid_domain_types = ("MASTER", "SLAVE")
|
2007-07-02 11:14:47 +02:00
|
|
|
|
2007-07-09 08:46:36 +02:00
|
|
|
def __init__(self, delegate, verbose = False, **kwargs):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Initializes the DomainEntity instance.
|
|
|
|
|
|
|
|
`delegate` is the corresponding database object.
|
|
|
|
If `verbose` is `True` verbose logging is turned on.
|
|
|
|
"""
|
2007-07-09 08:46:36 +02:00
|
|
|
BackendEntity.__init__(self, delegate, verbose)
|
2007-07-05 11:00:34 +02:00
|
|
|
self.ns1 = None
|
|
|
|
self.ns2 = None
|
2008-06-07 23:25:35 +02:00
|
|
|
self.mxrr = None
|
2007-07-05 11:00:34 +02:00
|
|
|
self.ipaddr = None
|
|
|
|
for (key, value) in kwargs.items():
|
|
|
|
self.__setattr__(key, value)
|
2007-07-09 08:46:36 +02:00
|
|
|
if not self.delegateto.type:
|
|
|
|
self.delegateto.type = self.getdefaultdomaintype()
|
2007-07-05 11:00:34 +02:00
|
|
|
if not self.ns1:
|
|
|
|
self.ns1 = config.get('domain', 'defaultns1')
|
|
|
|
if not self.ns2:
|
|
|
|
self.ns2 = config.get('domain', 'defaultns2')
|
2008-06-07 23:25:35 +02:00
|
|
|
if not self.mxrr:
|
|
|
|
self.mxrr = config.get('domain', 'defaultmx')
|
2007-07-05 11:00:34 +02:00
|
|
|
if not self.ipaddr:
|
|
|
|
self.ipaddr = config.get('domain', 'defaultip')
|
2007-07-09 08:46:36 +02:00
|
|
|
self.delegateto.type = self.delegateto.type.upper()
|
2007-07-02 11:14:47 +02:00
|
|
|
self.validate()
|
|
|
|
|
2007-07-05 11:00:34 +02:00
|
|
|
def getdefaultdomaintype(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Returns the default domain type."""
|
2007-07-05 11:00:34 +02:00
|
|
|
return self._valid_domain_types[0]
|
|
|
|
|
|
|
|
def validate(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Validates the consistency if the entity instance and
|
|
|
|
dependent entities."""
|
2007-07-05 11:00:34 +02:00
|
|
|
BackendEntity.validate(self)
|
2007-07-09 08:46:36 +02:00
|
|
|
if not self.delegateto.type in self._valid_domain_types:
|
2007-07-05 11:00:34 +02:00
|
|
|
raise ValidationFailedError(
|
2007-07-09 08:46:36 +02:00
|
|
|
self, "invalid domain type %s" % (self.delegateto.type))
|
|
|
|
if self.delegateto.type == 'SLAVE' and not self.delegateto.master:
|
2007-07-05 11:00:34 +02:00
|
|
|
raise ValidationFailedError(
|
|
|
|
self, "you have to specify a master for slave domains.")
|
2007-07-09 08:46:36 +02:00
|
|
|
if self.delegateto.type == 'MASTER':
|
2007-07-05 11:00:34 +02:00
|
|
|
if not self.ns1 or not self.ns2:
|
|
|
|
raise ValidationFailedError(
|
|
|
|
self, "two nameservers must be specified.")
|
2008-06-07 23:25:35 +02:00
|
|
|
if not self.mxrr:
|
2007-07-05 11:00:34 +02:00
|
|
|
raise ValidationFailedError(
|
|
|
|
self, "a primary mx host must be specified.")
|
|
|
|
|
2007-07-09 08:46:36 +02:00
|
|
|
def _getnewserial(self, oldserial = None):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Gets a new zone serial number for the DNS domain entity."""
|
2007-07-05 11:00:34 +02:00
|
|
|
current = datetime.datetime.now()
|
2007-07-09 08:46:36 +02:00
|
|
|
datepart = "%04d%02d%02d" % \
|
|
|
|
(current.year, current.month, current.day)
|
|
|
|
retval = None
|
|
|
|
if oldserial:
|
|
|
|
if str(oldserial)[:len(datepart)] == datepart:
|
|
|
|
retval = oldserial + 1
|
|
|
|
if not retval:
|
|
|
|
retval = int("%s01" % (datepart))
|
|
|
|
return retval
|
2007-07-05 11:00:34 +02:00
|
|
|
|
|
|
|
def _getnewsoa(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Gets a new SOA record for the DNS domain entity."""
|
2007-07-05 11:00:34 +02:00
|
|
|
return '%s %s %d %d %d %d %d' % \
|
|
|
|
(self.ns1,
|
|
|
|
config.get('domain', 'defaulthostmaster'),
|
|
|
|
self._getnewserial(),
|
|
|
|
config.getint('domain', 'defaultrefresh'),
|
|
|
|
config.getint('domain', 'defaultretry'),
|
|
|
|
config.getint('domain', 'defaultexpire'),
|
|
|
|
config.getint('domain', 'defaultminimumttl'))
|
|
|
|
|
2007-07-09 08:46:36 +02:00
|
|
|
def update_serial(self, session):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Updates the serial of the domain."""
|
2007-07-09 08:46:36 +02:00
|
|
|
query = session.query(Record)
|
|
|
|
soarecord = query.get_by(Record.c.type == 'SOA',
|
|
|
|
Record.c.domainid == self.delegateto.domainid)
|
|
|
|
parts = soarecord.content.split(" ")
|
|
|
|
parts[2] = str(self._getnewserial(int(parts[2])))
|
|
|
|
soarecord.content = " ".join(parts)
|
|
|
|
session.save(soarecord)
|
|
|
|
session.flush()
|
|
|
|
|
|
|
|
def _get_vhost_dir(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Gets the directory name for the Apache VirtualHost of the
|
|
|
|
domain."""
|
2007-07-09 08:46:36 +02:00
|
|
|
return os.path.join(self.delegateto.sysuser.home,
|
|
|
|
self.delegateto.name,
|
|
|
|
config.get('domain', 'htdir'))
|
|
|
|
|
|
|
|
def _get_log_dir(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Gets the Apache log file directory for the domain."""
|
2007-07-09 08:46:36 +02:00
|
|
|
return os.path.join(config.get('domain', 'logpath'),
|
|
|
|
self.delegateto.name)
|
|
|
|
|
|
|
|
def _get_stats_dir(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Gets the statistics dir for the domain."""
|
2007-07-09 08:46:36 +02:00
|
|
|
return os.path.join(config.get('domain', 'statspath'),
|
|
|
|
self.delegateto.name)
|
|
|
|
|
|
|
|
def _create_vhost_dir(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Creates the Apache VirtualHost directory for the domain."""
|
2007-07-09 08:46:36 +02:00
|
|
|
vhostdir = self._get_vhost_dir()
|
2008-04-05 20:48:46 +02:00
|
|
|
self.logger.debug("creating virtual host dir %s" % (vhostdir))
|
2007-07-09 08:46:36 +02:00
|
|
|
cmd = 'mkdir -p "%s"' % (vhostdir)
|
|
|
|
self.sucommand(cmd)
|
|
|
|
for tpl in [tpl for tpl in os.listdir(
|
|
|
|
get_template_dir(config.get('domain', 'htdocstemplate'))) \
|
|
|
|
if not tpl.startswith('.')]:
|
2008-04-05 20:48:46 +02:00
|
|
|
self.logger.debug("processing template %s" % (tpl))
|
2007-07-09 08:46:36 +02:00
|
|
|
template = get_template(config.get('domain', 'htdocstemplate'),
|
|
|
|
tpl)
|
|
|
|
template = template.substitute({
|
2008-06-06 21:20:18 +02:00
|
|
|
'domain': self.delegateto.name})
|
2007-07-09 08:46:36 +02:00
|
|
|
self.write_to_file(os.path.join(vhostdir, tpl), template)
|
|
|
|
cmd = 'chown -R %(username)s:%(group)s "%(dir)s"' % {
|
2008-06-06 21:20:18 +02:00
|
|
|
'username': self.delegateto.sysuser.username,
|
|
|
|
'group': config.get('sysuser', 'defaultgroup'),
|
|
|
|
'dir': vhostdir}
|
2007-07-09 08:46:36 +02:00
|
|
|
self.sucommand(cmd)
|
|
|
|
|
|
|
|
def _create_log_dir(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Creates the Apache log file directory for the domain."""
|
2007-07-09 08:46:36 +02:00
|
|
|
cmd = 'mkdir -p "%s"' % (self._get_log_dir())
|
|
|
|
self.sucommand(cmd)
|
|
|
|
|
|
|
|
def _get_auth_userfile(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Gets the file name of the password file for statistic
|
|
|
|
logins for the domain."""
|
2007-07-09 08:46:36 +02:00
|
|
|
authdir = config.get('domain', 'authdir')
|
|
|
|
if not os.path.isdir(authdir):
|
|
|
|
cmd = 'mkdir -p "%s"' % (authdir)
|
|
|
|
self.sucommand(cmd)
|
|
|
|
return os.path.join(authdir, '%s.passwd' % (self.delegateto.name))
|
|
|
|
|
|
|
|
def _create_stats_dir(self):
|
|
|
|
"""Creates the statistics directory for the domain and sets
|
|
|
|
Apache .htaccess password protection."""
|
|
|
|
statsdir = self._get_stats_dir()
|
|
|
|
authfile = self._get_auth_userfile()
|
|
|
|
cmd = 'htpasswd -m -c -b "%s" "%s" "%s"' % (
|
|
|
|
authfile,
|
|
|
|
self.delegateto.sysuser.username,
|
|
|
|
self.delegateto.sysuser.clearpass)
|
|
|
|
self.sucommand(cmd)
|
|
|
|
cmd = 'mkdir -p "%s"' % (statsdir)
|
|
|
|
self.sucommand(cmd)
|
|
|
|
template = get_template(config.get('domain', 'conftemplates'),
|
|
|
|
config.get('domain', 'statshtaccesstemplate'))
|
|
|
|
template = template.substitute({
|
2008-06-06 21:20:18 +02:00
|
|
|
'domain': self.delegateto.name,
|
|
|
|
'userfile': authfile})
|
2007-07-09 08:46:36 +02:00
|
|
|
self.write_to_file(os.path.join(self._get_stats_dir(),
|
|
|
|
'.htaccess'), template)
|
|
|
|
|
|
|
|
def _create_stats_conf(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Creates the modlogan statistics configuration for the
|
|
|
|
domain."""
|
2007-07-09 08:46:36 +02:00
|
|
|
modlogandir = os.path.join(config.get('domain',
|
|
|
|
'modlogandir'),
|
|
|
|
self.delegateto.sysuser.username)
|
|
|
|
cmd = 'mkdir -p "%s"' % (modlogandir)
|
|
|
|
self.sucommand(cmd)
|
|
|
|
template = get_template(config.get('domain', 'conftemplates'),
|
|
|
|
config.get('domain', 'modlogantemplate'))
|
|
|
|
template = template.substitute({
|
2008-06-06 21:20:18 +02:00
|
|
|
'statsdir': self._get_stats_dir(),
|
|
|
|
'logdir': self._get_log_dir(),
|
|
|
|
'domain': self.delegateto.name,
|
|
|
|
'domainesc': self.delegateto.name.replace('.', '\.')})
|
2007-07-09 08:46:36 +02:00
|
|
|
self.write_to_file(os.path.join(modlogandir,
|
|
|
|
self.delegateto.name + '.conf'),
|
|
|
|
template)
|
|
|
|
|
|
|
|
def _create_apache_conf(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Creates the Apache configuration file for the domain."""
|
2007-07-09 08:46:36 +02:00
|
|
|
template = get_template(config.get('domain', 'conftemplates'),
|
|
|
|
config.get('domain', 'apachetemplate'))
|
|
|
|
template = template.substitute({
|
2008-06-06 21:20:18 +02:00
|
|
|
'ipaddr': self.ipaddr,
|
|
|
|
'statsdir': self._get_stats_dir(),
|
|
|
|
'logdir': self._get_log_dir(),
|
|
|
|
'domain': self.delegateto.name,
|
|
|
|
'docroot': self._get_vhost_dir()})
|
2007-07-09 08:46:36 +02:00
|
|
|
self.write_to_file(os.path.join(config.get('domain', 'sitesdir'),
|
|
|
|
self.delegateto.name), template)
|
|
|
|
|
|
|
|
def _mail_domain(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Mail a summary of the domain data."""
|
2007-07-09 08:46:36 +02:00
|
|
|
template = get_template(config.get('common', 'mailtemplates'),
|
|
|
|
config.get('domain', 'create.mail'))
|
|
|
|
text = template.substitute({
|
2008-06-06 21:20:18 +02:00
|
|
|
'sysuser': self.delegateto.sysuser.username,
|
|
|
|
'domain': self.delegateto.name,
|
|
|
|
'docroot': self._get_vhost_dir(),
|
|
|
|
'statspass': self.delegateto.sysuser.clearpass})
|
2007-07-09 08:46:36 +02:00
|
|
|
template = get_template_string(config.get('domain', 'create_subject'))
|
|
|
|
subject = template.substitute({
|
2008-06-06 21:20:18 +02:00
|
|
|
'domain': self.delegateto.name})
|
|
|
|
self.send_mail(subject, text)
|
2007-07-09 08:46:36 +02:00
|
|
|
|
|
|
|
def create_hook(self, session):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Hook for the creation of the domain.
|
|
|
|
|
|
|
|
This method is called by
|
|
|
|
`gnuviechadmin.backend.BackendEntityHandler.create()`.
|
|
|
|
"""
|
2007-07-09 08:46:36 +02:00
|
|
|
self.delegateto.records.append(Record(
|
|
|
|
name = self.delegateto.name, type = 'SOA',
|
2007-07-05 11:00:34 +02:00
|
|
|
content = self._getnewsoa(),
|
|
|
|
ttl = config.getint('domain', 'defaultttl')))
|
2007-07-09 08:46:36 +02:00
|
|
|
self.delegateto.records.append(Record(
|
|
|
|
name = self.delegateto.name, type = 'NS', content = self.ns1,
|
2007-07-05 11:00:34 +02:00
|
|
|
ttl = config.getint('domain', 'defaultttl')))
|
2007-07-09 08:46:36 +02:00
|
|
|
self.delegateto.records.append(Record(
|
|
|
|
name = self.delegateto.name, type = 'NS', content = self.ns2,
|
2007-07-05 11:00:34 +02:00
|
|
|
ttl = config.getint('domain', 'defaultttl')))
|
2007-07-09 08:46:36 +02:00
|
|
|
self.delegateto.records.append(Record(
|
2008-06-07 23:25:35 +02:00
|
|
|
name = self.delegateto.name, type = 'MX', content = self.mxrr,
|
2007-07-05 11:00:34 +02:00
|
|
|
ttl = config.getint('domain', 'defaultttl'),
|
|
|
|
prio = config.getint('domain', 'defaultmxprio')))
|
2007-07-09 08:46:36 +02:00
|
|
|
self.delegateto.records.append(Record(
|
|
|
|
name = self.delegateto.name, type = 'A', content = self.ipaddr,
|
2007-07-05 11:00:34 +02:00
|
|
|
ttl = config.getint('domain', 'defaultttl')))
|
2007-07-09 08:46:36 +02:00
|
|
|
self.delegateto.records.append(Record(
|
|
|
|
name = "www.%s" % (self.delegateto.name), type = 'A',
|
|
|
|
content = self.ipaddr,
|
2007-07-05 11:00:34 +02:00
|
|
|
ttl = config.getint('domain', 'defaultttl')))
|
2008-04-05 20:48:33 +02:00
|
|
|
session.save_or_update(self.delegateto)
|
2007-07-09 08:46:36 +02:00
|
|
|
session.flush()
|
|
|
|
self._create_vhost_dir()
|
|
|
|
self._create_log_dir()
|
|
|
|
self._create_stats_dir()
|
|
|
|
self._create_stats_conf()
|
|
|
|
self._create_apache_conf()
|
|
|
|
self._mail_domain()
|
|
|
|
|
|
|
|
def _delete_apache_conf(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Deletes the Apache configuration file for the domain."""
|
2007-07-09 08:46:36 +02:00
|
|
|
cmd = 'a2dissite %s' % (self.delegateto.name)
|
|
|
|
self.sucommand(cmd)
|
|
|
|
cmd = 'rm "%s"' % (os.path.join(config.get('domain', 'sitesdir'),
|
|
|
|
self.delegateto.name))
|
|
|
|
self.sucommand(cmd)
|
|
|
|
|
|
|
|
def _delete_stats_conf(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Deletes the modlogan stastics configuration for the
|
|
|
|
domain."""
|
2007-07-09 08:46:36 +02:00
|
|
|
cmd = 'rm "%s"' % (os.path.join(config.get('domain', 'modlogandir'),
|
|
|
|
self.delegateto.sysuser.username,
|
|
|
|
self.delegateto.name + '.conf'))
|
|
|
|
self.sucommand(cmd)
|
|
|
|
|
|
|
|
def _archive_stats_dir(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Archives the statistics directory for the domain."""
|
2007-07-09 08:46:36 +02:00
|
|
|
archive = os.path.join(self.delegateto.sysuser.home,
|
|
|
|
'%(domain)s-stats.tar.gz' % {
|
2008-06-06 21:20:18 +02:00
|
|
|
'domain': self.delegateto.name})
|
|
|
|
cmd = 'tar czf "%(archive)s" --directory="%(statsbase)s" ' + \
|
|
|
|
'"%(statsdir)s"' % {
|
|
|
|
'archive': archive,
|
|
|
|
'statsbase': config.get('domain', 'statspath'),
|
|
|
|
'statsdir': self.delegateto.name}
|
2007-07-09 08:46:36 +02:00
|
|
|
self.sucommand(cmd)
|
|
|
|
cmd = 'rm -r "%(statsdir)s"' % {
|
2008-06-06 21:20:18 +02:00
|
|
|
'statsdir': self._get_stats_dir()}
|
2007-07-09 08:46:36 +02:00
|
|
|
self.sucommand(cmd)
|
|
|
|
cmd = 'chown "%(username)s:%(group)s" "%(archive)s"' % {
|
2008-06-06 21:20:18 +02:00
|
|
|
'username': self.delegateto.sysuser.username,
|
|
|
|
'group': config.get('sysuser', 'defaultgroup'),
|
|
|
|
'archive': archive}
|
2007-07-09 08:46:36 +02:00
|
|
|
self.sucommand(cmd)
|
|
|
|
|
|
|
|
def _archive_log_dir(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Archives the Apache log file directory for the domain."""
|
2007-07-09 08:46:36 +02:00
|
|
|
archive = os.path.join(self.delegateto.sysuser.home,
|
|
|
|
'%(domain)s-logs.tar.gz' % {
|
2008-06-06 21:20:18 +02:00
|
|
|
'domain': self.delegateto.name})
|
|
|
|
cmd = 'tar czf "%(archive)s" --directory="%(logbase)s" ' + \
|
|
|
|
'"%(logdir)s"' % {
|
|
|
|
'archive': archive,
|
|
|
|
'logbase': config.get('domain', 'logpath'),
|
|
|
|
'logdir': self.delegateto.name}
|
2007-07-09 08:46:36 +02:00
|
|
|
self.sucommand(cmd)
|
|
|
|
cmd = 'rm -r "%(logdir)s"' % {
|
2008-06-06 21:20:18 +02:00
|
|
|
'logdir': self._get_log_dir()}
|
2007-07-09 08:46:36 +02:00
|
|
|
self.sucommand(cmd)
|
|
|
|
cmd = 'chown "%(username)s:%(group)s" "%(archive)s"' % {
|
2008-06-06 21:20:18 +02:00
|
|
|
'username': self.delegateto.sysuser.username,
|
|
|
|
'group': config.get('sysuser', 'defaultgroup'),
|
|
|
|
'archive': archive}
|
2007-07-09 08:46:36 +02:00
|
|
|
self.sucommand(cmd)
|
2007-07-05 11:00:34 +02:00
|
|
|
|
2007-07-09 08:46:36 +02:00
|
|
|
def _archive_vhost_dir(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Archives the Apache VirtualHost directory for the domain."""
|
2007-07-09 08:46:36 +02:00
|
|
|
archive = os.path.join(self.delegateto.sysuser.home,
|
|
|
|
'%(domain)s-vhost.tar.gz' % {
|
2008-06-06 21:20:18 +02:00
|
|
|
'domain': self.delegateto.name})
|
|
|
|
cmd = 'tar czf "%(archive)s" --directory="%(vhostbase)s" ' + \
|
|
|
|
'"%(vhostdir)s"' % {
|
|
|
|
'archive': archive,
|
|
|
|
'vhostbase': self.delegateto.sysuser.home,
|
|
|
|
'vhostdir': self.delegateto.name}
|
2007-07-09 08:46:36 +02:00
|
|
|
self.sucommand(cmd)
|
|
|
|
cmd = 'rm -r "%(vhostdir)s"' % {
|
2008-06-06 21:20:18 +02:00
|
|
|
'vhostdir': os.path.join(self.delegateto.sysuser.home,
|
2007-07-09 08:46:36 +02:00
|
|
|
self.delegateto.name)}
|
|
|
|
self.sucommand(cmd)
|
|
|
|
cmd = 'chown "%(username)s:%(group)s" "%(archive)s"' % {
|
2008-06-06 21:20:18 +02:00
|
|
|
'username': self.delegateto.sysuser.username,
|
|
|
|
'group': config.get('sysuser', 'defaultgroup'),
|
|
|
|
'archive': archive}
|
2007-07-09 08:46:36 +02:00
|
|
|
self.sucommand(cmd)
|
2007-07-05 11:00:34 +02:00
|
|
|
|
2008-06-06 21:20:18 +02:00
|
|
|
def delete_hook(self, session):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Deletes domain related files and directories.
|
|
|
|
|
|
|
|
This method is called by `BackendEntityHandler.delete()`.
|
|
|
|
"""
|
2007-07-09 08:46:36 +02:00
|
|
|
self._delete_apache_conf()
|
|
|
|
self._delete_stats_conf()
|
|
|
|
self._archive_stats_dir()
|
|
|
|
self._archive_log_dir()
|
|
|
|
self._archive_vhost_dir()
|
2007-07-02 11:14:47 +02:00
|
|
|
|
2008-06-06 21:20:18 +02:00
|
|
|
|
2007-07-02 11:14:47 +02:00
|
|
|
class DomainHandler(BackendEntityHandler):
|
|
|
|
"""BackendEntityHandler for Domain entities."""
|
|
|
|
|
|
|
|
def __init__(self, verbose = False):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Initialize the DomainHandler."""
|
2007-07-09 08:46:36 +02:00
|
|
|
BackendEntityHandler.__init__(self, DomainEntity, Domain, verbose)
|