Random fixes
This commit is contained in:
parent
0a522884a7
commit
b5fbba012f
3
TODO.md
3
TODO.md
|
@ -160,6 +160,3 @@ Remember that, as always with QuerySets, any subsequent chained methods which im
|
||||||
* prevent adding local email addresses on account.contacts account.email
|
* prevent adding local email addresses on account.contacts account.email
|
||||||
|
|
||||||
* Resource monitoring without ROUTE alert or explicit error
|
* Resource monitoring without ROUTE alert or explicit error
|
||||||
|
|
||||||
|
|
||||||
* account.full_name account.short_name
|
|
||||||
|
|
|
@ -167,7 +167,7 @@ class MailmanTraffic(ServiceMonitor):
|
||||||
def monitor(self, mail_list):
|
def monitor(self, mail_list):
|
||||||
context = self.get_context(mail_list)
|
context = self.get_context(mail_list)
|
||||||
self.append(
|
self.append(
|
||||||
'monitor %(object_id)i %(last_date)s "%(list_name)s" "%(log_file)s"' % context)
|
'monitor %(object_id)i %(last_date)s "%(list_name)s" "%(log_file)s{,.1}"' % context)
|
||||||
|
|
||||||
def get_context(self, mail_list):
|
def get_context(self, mail_list):
|
||||||
last_date = timezone.localtime(self.get_last_date(mail_list.pk))
|
last_date = timezone.localtime(self.get_last_date(mail_list.pk))
|
||||||
|
|
|
@ -103,7 +103,7 @@ class PasswdVirtualUserBackend(ServiceController):
|
||||||
'group': self.DEFAULT_GROUP,
|
'group': self.DEFAULT_GROUP,
|
||||||
'quota': self.get_quota(mailbox),
|
'quota': self.get_quota(mailbox),
|
||||||
'passwd_path': settings.MAILBOXES_PASSWD_PATH,
|
'passwd_path': settings.MAILBOXES_PASSWD_PATH,
|
||||||
'home': mailbox.get_home(),
|
'home': mailbox.get_home().rstrip('/'),
|
||||||
'banner': self.get_banner(),
|
'banner': self.get_banner(),
|
||||||
'virtual_mailbox_maps': settings.MAILBOXES_VIRTUAL_MAILBOX_MAPS_PATH,
|
'virtual_mailbox_maps': settings.MAILBOXES_VIRTUAL_MAILBOX_MAPS_PATH,
|
||||||
'mailbox_domain': settings.MAILBOXES_VIRTUAL_MAILBOX_DEFAULT_DOMAIN,
|
'mailbox_domain': settings.MAILBOXES_VIRTUAL_MAILBOX_DEFAULT_DOMAIN,
|
||||||
|
|
|
@ -50,8 +50,7 @@ class Mailbox(models.Model):
|
||||||
'name': self.name,
|
'name': self.name,
|
||||||
'username': self.name,
|
'username': self.name,
|
||||||
}
|
}
|
||||||
home = settings.MAILBOXES_HOME % context
|
return settings.MAILBOXES_HOME % context
|
||||||
return home.rstrip('/')
|
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
if self.custom_filtering and self.filtering != self.CUSTOM:
|
if self.custom_filtering and self.filtering != self.CUSTOM:
|
||||||
|
|
|
@ -8,7 +8,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||||
MAILBOXES_DOMAIN_MODEL = getattr(settings, 'MAILBOXES_DOMAIN_MODEL', 'domains.Domain')
|
MAILBOXES_DOMAIN_MODEL = getattr(settings, 'MAILBOXES_DOMAIN_MODEL', 'domains.Domain')
|
||||||
|
|
||||||
|
|
||||||
MAILBOXES_HOME = getattr(settings, 'MAILBOXES_HOME', '/home/%(name)s/')
|
MAILBOXES_HOME = getattr(settings, 'MAILBOXES_HOME', '/home/./%(name)s/')
|
||||||
|
|
||||||
|
|
||||||
MAILBOXES_SIEVE_PATH = getattr(settings, 'MAILBOXES_SIEVE_PATH',
|
MAILBOXES_SIEVE_PATH = getattr(settings, 'MAILBOXES_SIEVE_PATH',
|
||||||
|
|
|
@ -55,7 +55,7 @@ class Resource(models.Model):
|
||||||
help_text=_("Default allocation value used when this is not an "
|
help_text=_("Default allocation value used when this is not an "
|
||||||
"on demand resource"))
|
"on demand resource"))
|
||||||
unit = models.CharField(_("unit"), max_length=16,
|
unit = models.CharField(_("unit"), max_length=16,
|
||||||
help_text=_("The unit in which this resource is measured. "
|
help_text=_("The unit in which this resource is represented. "
|
||||||
"For example GB, KB or subscribers"))
|
"For example GB, KB or subscribers"))
|
||||||
scale = models.CharField(_("scale"), max_length=32, validators=[validate_scale],
|
scale = models.CharField(_("scale"), max_length=32, validators=[validate_scale],
|
||||||
help_text=_("Scale in which this resource monitoring resoults should "
|
help_text=_("Scale in which this resource monitoring resoults should "
|
||||||
|
@ -171,7 +171,7 @@ class MonitorData(models.Model):
|
||||||
choices=ServiceMonitor.get_plugin_choices())
|
choices=ServiceMonitor.get_plugin_choices())
|
||||||
content_type = models.ForeignKey(ContentType, verbose_name=_("content type"))
|
content_type = models.ForeignKey(ContentType, verbose_name=_("content type"))
|
||||||
object_id = models.PositiveIntegerField(_("object id"))
|
object_id = models.PositiveIntegerField(_("object id"))
|
||||||
created_at = models.DateTimeField(_("created"))
|
created_at = models.DateTimeField(_("created"), default=timezone.now)
|
||||||
value = models.DecimalField(_("value"), max_digits=16, decimal_places=2)
|
value = models.DecimalField(_("value"), max_digits=16, decimal_places=2)
|
||||||
|
|
||||||
content_object = GenericForeignKey()
|
content_object = GenericForeignKey()
|
||||||
|
|
|
@ -8,6 +8,7 @@ from django.utils import timezone
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from orchestra.utils import plugins
|
from orchestra.utils import plugins
|
||||||
|
from orchestra.utils.humanize import text2int
|
||||||
from orchestra.utils.python import AttrDict
|
from orchestra.utils.python import AttrDict
|
||||||
|
|
||||||
from . import settings, helpers
|
from . import settings, helpers
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
from django.utils import timezone
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from orchestra.apps.orchestration import ServiceController
|
from orchestra.apps.orchestration import ServiceController
|
||||||
|
@ -82,9 +81,8 @@ class FTPTraffic(ServiceMonitor):
|
||||||
verbose_name = _('Main FTP traffic')
|
verbose_name = _('Main FTP traffic')
|
||||||
|
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
current_date = timezone.localtime(self.current_date)
|
current_date = self.current_date.strftime("%Y-%m-%d %H:%M:%S %Z")
|
||||||
current_date = current_date.strftime("%Y%m%d%H%M%S")
|
self.append(textwrap.dedent("""\
|
||||||
self.append(textwrap.dedent("""
|
|
||||||
function monitor () {
|
function monitor () {
|
||||||
OBJECT_ID=$1
|
OBJECT_ID=$1
|
||||||
INI_DATE=$2
|
INI_DATE=$2
|
||||||
|
@ -92,9 +90,8 @@ class FTPTraffic(ServiceMonitor):
|
||||||
LOG_FILE="$4"
|
LOG_FILE="$4"
|
||||||
grep "UPLOAD\|DOWNLOAD" "${LOG_FILE}" \\
|
grep "UPLOAD\|DOWNLOAD" "${LOG_FILE}" \\
|
||||||
| grep " \\[${USERNAME}\\] " \\
|
| grep " \\[${USERNAME}\\] " \\
|
||||||
| awk -v ini="${INI_DATE}" '
|
| awk -v ini="${INI_DATE}" end="$(date '+%%Y%%m%%d%%H%%M%%S' -d '%s')" '
|
||||||
BEGIN {
|
BEGIN {
|
||||||
end = "%s"
|
|
||||||
sum = 0
|
sum = 0
|
||||||
months["Jan"] = "01"
|
months["Jan"] = "01"
|
||||||
months["Feb"] = "02"
|
months["Feb"] = "02"
|
||||||
|
@ -126,13 +123,13 @@ class FTPTraffic(ServiceMonitor):
|
||||||
def monitor(self, user):
|
def monitor(self, user):
|
||||||
context = self.get_context(user)
|
context = self.get_context(user)
|
||||||
self.append(
|
self.append(
|
||||||
'monitor %(object_id)i %(last_date)s "%(username)s" "%(log_file)s"' % context)
|
'monitor %{object_id} $(date "+%Y%m%d%H%M%S" -d "{last_date}") "{username}" "{log_file}"'.format(**context)
|
||||||
|
)
|
||||||
|
|
||||||
def get_context(self, user):
|
def get_context(self, user):
|
||||||
last_date = timezone.localtime(self.get_last_date(user.pk))
|
|
||||||
return {
|
return {
|
||||||
'log_file': settings.SYSTEMUSERS_FTP_LOG_PATH,
|
'log_file': '%s{,.1}' % settings.SYSTEMUSERS_FTP_LOG_PATH,
|
||||||
'last_date': last_date.strftime("%Y%m%d%H%M%S"),
|
'last_date': self.get_last_date(site.pk).strftime("%Y-%m-%d %H:%M:%S %Z"),
|
||||||
'object_id': user.pk,
|
'object_id': user.pk,
|
||||||
'username': user.username,
|
'username': user.username,
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ class SystemUser(models.Model):
|
||||||
help_text=_("Home directory relative to account's ~main_user"))
|
help_text=_("Home directory relative to account's ~main_user"))
|
||||||
shell = models.CharField(_("shell"), max_length=32,
|
shell = models.CharField(_("shell"), max_length=32,
|
||||||
choices=settings.SYSTEMUSERS_SHELLS, default=settings.SYSTEMUSERS_DEFAULT_SHELL)
|
choices=settings.SYSTEMUSERS_SHELLS, default=settings.SYSTEMUSERS_DEFAULT_SHELL)
|
||||||
groups = models.ManyToManyField('self', blank=True,
|
groups = models.ManyToManyField('self', blank=True, symmetrical=False,
|
||||||
help_text=_("A new group will be created for the user. "
|
help_text=_("A new group will be created for the user. "
|
||||||
"Which additional groups would you like them to be a member of?"))
|
"Which additional groups would you like them to be a member of?"))
|
||||||
# is_main = models.BooleanField(_("is main"), default=False)
|
# is_main = models.BooleanField(_("is main"), default=False)
|
||||||
|
@ -72,26 +72,7 @@ class SystemUser(models.Model):
|
||||||
basehome = settings.SYSTEMUSERS_HOME % context
|
basehome = settings.SYSTEMUSERS_HOME % context
|
||||||
else:
|
else:
|
||||||
basehome = self.account.main_systemuser.get_home()
|
basehome = self.account.main_systemuser.get_home()
|
||||||
basehome = basehome.replace('/./', '/')
|
return os.path.join(basehome, self.home)
|
||||||
home = os.path.join(basehome, self.home)
|
|
||||||
# Chrooting
|
|
||||||
# TODO option for disabling chrooting
|
|
||||||
home = home.split('/')
|
|
||||||
home.insert(-2, '.')
|
|
||||||
return '/'.join(home)
|
|
||||||
|
|
||||||
|
|
||||||
## TODO user deletion and group handling.
|
|
||||||
#class SystemGroup(models.Model):
|
|
||||||
# name = models.CharField(_("name"), max_length=64, unique=True,
|
|
||||||
# help_text=_("Required. 30 characters or fewer. Letters, digits and ./-/_ only."),
|
|
||||||
# validators=[validators.RegexValidator(r'^[\w.-]+$',
|
|
||||||
# _("Enter a valid group name."), 'invalid')])
|
|
||||||
# account = models.ForeignKey('accounts.Account', verbose_name=_("Account"),
|
|
||||||
# related_name='systemgroups')
|
|
||||||
#
|
|
||||||
# def __unicode__(self):
|
|
||||||
# return self.name
|
|
||||||
|
|
||||||
|
|
||||||
services.register(SystemUser)
|
services.register(SystemUser)
|
||||||
|
|
|
@ -13,7 +13,7 @@ SYSTEMUSERS_SHELLS = getattr(settings, 'SYSTEMUSERS_SHELLS', (
|
||||||
SYSTEMUSERS_DEFAULT_SHELL = getattr(settings, 'SYSTEMUSERS_DEFAULT_SHELL', '/dev/null')
|
SYSTEMUSERS_DEFAULT_SHELL = getattr(settings, 'SYSTEMUSERS_DEFAULT_SHELL', '/dev/null')
|
||||||
|
|
||||||
|
|
||||||
SYSTEMUSERS_HOME = getattr(settings, 'SYSTEMUSERS_HOME', '/home/%(username)s')
|
SYSTEMUSERS_HOME = getattr(settings, 'SYSTEMUSERS_HOME', '/home/./%(username)s')
|
||||||
|
|
||||||
|
|
||||||
SYSTEMUSERS_FTP_LOG_PATH = getattr(settings, 'SYSTEMUSERS_FTP_LOG_PATH', '/var/log/vsftpd.log')
|
SYSTEMUSERS_FTP_LOG_PATH = getattr(settings, 'SYSTEMUSERS_FTP_LOG_PATH', '/var/log/vsftpd.log')
|
||||||
|
|
|
@ -235,9 +235,8 @@ class Apache2Traffic(ServiceMonitor):
|
||||||
self.append('monitor {object_id} $(date "+%Y%m%d%H%M%S" -d "{last_date}") "{log_file}"'.format(**context))
|
self.append('monitor {object_id} $(date "+%Y%m%d%H%M%S" -d "{last_date}") "{log_file}"'.format(**context))
|
||||||
|
|
||||||
def get_context(self, site):
|
def get_context(self, site):
|
||||||
last_date = self.get_last_date(site.pk)
|
|
||||||
return {
|
return {
|
||||||
'log_file': '%s{,.1}' % site.get_www_log_path(),
|
'log_file': '%s{,.1}' % site.get_www_log_path(),
|
||||||
'last_date': last_date.strftime("%Y-%m-%d %H:%M:%S %Z"),
|
'last_date': self.get_last_date(site.pk).strftime("%Y-%m-%d %H:%M:%S %Z"),
|
||||||
'object_id': site.pk,
|
'object_id': site.pk,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue