From b5fbba012f76b3ba7eea6b767c9400b9cc6df2fe Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Mon, 27 Oct 2014 17:34:14 +0000 Subject: [PATCH] Random fixes --- TODO.md | 3 --- orchestra/apps/lists/backends.py | 2 +- orchestra/apps/mailboxes/backends.py | 2 +- orchestra/apps/mailboxes/models.py | 3 +-- orchestra/apps/mailboxes/settings.py | 2 +- orchestra/apps/resources/models.py | 4 ++-- orchestra/apps/services/handlers.py | 1 + orchestra/apps/systemusers/backends.py | 17 +++++++--------- orchestra/apps/systemusers/models.py | 23 ++-------------------- orchestra/apps/systemusers/settings.py | 2 +- orchestra/apps/websites/backends/apache.py | 3 +-- 11 files changed, 18 insertions(+), 44 deletions(-) diff --git a/TODO.md b/TODO.md index 92c4c39d..6ebea6af 100644 --- a/TODO.md +++ b/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 * Resource monitoring without ROUTE alert or explicit error - - -* account.full_name account.short_name diff --git a/orchestra/apps/lists/backends.py b/orchestra/apps/lists/backends.py index 97aa2ccc..cdb9fb7a 100644 --- a/orchestra/apps/lists/backends.py +++ b/orchestra/apps/lists/backends.py @@ -167,7 +167,7 @@ class MailmanTraffic(ServiceMonitor): def monitor(self, mail_list): context = self.get_context(mail_list) 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): last_date = timezone.localtime(self.get_last_date(mail_list.pk)) diff --git a/orchestra/apps/mailboxes/backends.py b/orchestra/apps/mailboxes/backends.py index 46ecbbeb..5150bd50 100644 --- a/orchestra/apps/mailboxes/backends.py +++ b/orchestra/apps/mailboxes/backends.py @@ -103,7 +103,7 @@ class PasswdVirtualUserBackend(ServiceController): 'group': self.DEFAULT_GROUP, 'quota': self.get_quota(mailbox), 'passwd_path': settings.MAILBOXES_PASSWD_PATH, - 'home': mailbox.get_home(), + 'home': mailbox.get_home().rstrip('/'), 'banner': self.get_banner(), 'virtual_mailbox_maps': settings.MAILBOXES_VIRTUAL_MAILBOX_MAPS_PATH, 'mailbox_domain': settings.MAILBOXES_VIRTUAL_MAILBOX_DEFAULT_DOMAIN, diff --git a/orchestra/apps/mailboxes/models.py b/orchestra/apps/mailboxes/models.py index 88e16284..05b42be1 100644 --- a/orchestra/apps/mailboxes/models.py +++ b/orchestra/apps/mailboxes/models.py @@ -50,8 +50,7 @@ class Mailbox(models.Model): 'name': self.name, 'username': self.name, } - home = settings.MAILBOXES_HOME % context - return home.rstrip('/') + return settings.MAILBOXES_HOME % context def clean(self): if self.custom_filtering and self.filtering != self.CUSTOM: diff --git a/orchestra/apps/mailboxes/settings.py b/orchestra/apps/mailboxes/settings.py index 138649c0..750c99b1 100644 --- a/orchestra/apps/mailboxes/settings.py +++ b/orchestra/apps/mailboxes/settings.py @@ -8,7 +8,7 @@ from django.utils.translation import ugettext_lazy as _ 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', diff --git a/orchestra/apps/resources/models.py b/orchestra/apps/resources/models.py index 5d55fb62..b6a2f642 100644 --- a/orchestra/apps/resources/models.py +++ b/orchestra/apps/resources/models.py @@ -55,7 +55,7 @@ class Resource(models.Model): help_text=_("Default allocation value used when this is not an " "on demand resource")) 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")) scale = models.CharField(_("scale"), max_length=32, validators=[validate_scale], help_text=_("Scale in which this resource monitoring resoults should " @@ -171,7 +171,7 @@ class MonitorData(models.Model): choices=ServiceMonitor.get_plugin_choices()) content_type = models.ForeignKey(ContentType, verbose_name=_("content type")) 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) content_object = GenericForeignKey() diff --git a/orchestra/apps/services/handlers.py b/orchestra/apps/services/handlers.py index d555375a..3bb375bd 100644 --- a/orchestra/apps/services/handlers.py +++ b/orchestra/apps/services/handlers.py @@ -8,6 +8,7 @@ from django.utils import timezone from django.utils.translation import ugettext_lazy as _ from orchestra.utils import plugins +from orchestra.utils.humanize import text2int from orchestra.utils.python import AttrDict from . import settings, helpers diff --git a/orchestra/apps/systemusers/backends.py b/orchestra/apps/systemusers/backends.py index 4874d8db..89b9c561 100644 --- a/orchestra/apps/systemusers/backends.py +++ b/orchestra/apps/systemusers/backends.py @@ -1,7 +1,6 @@ import os import textwrap -from django.utils import timezone from django.utils.translation import ugettext_lazy as _ from orchestra.apps.orchestration import ServiceController @@ -82,9 +81,8 @@ class FTPTraffic(ServiceMonitor): verbose_name = _('Main FTP traffic') def prepare(self): - current_date = timezone.localtime(self.current_date) - current_date = current_date.strftime("%Y%m%d%H%M%S") - self.append(textwrap.dedent(""" + current_date = self.current_date.strftime("%Y-%m-%d %H:%M:%S %Z") + self.append(textwrap.dedent("""\ function monitor () { OBJECT_ID=$1 INI_DATE=$2 @@ -92,9 +90,8 @@ class FTPTraffic(ServiceMonitor): LOG_FILE="$4" grep "UPLOAD\|DOWNLOAD" "${LOG_FILE}" \\ | grep " \\[${USERNAME}\\] " \\ - | awk -v ini="${INI_DATE}" ' + | awk -v ini="${INI_DATE}" end="$(date '+%%Y%%m%%d%%H%%M%%S' -d '%s')" ' BEGIN { - end = "%s" sum = 0 months["Jan"] = "01" months["Feb"] = "02" @@ -126,13 +123,13 @@ class FTPTraffic(ServiceMonitor): def monitor(self, user): context = self.get_context(user) 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): - last_date = timezone.localtime(self.get_last_date(user.pk)) return { - 'log_file': settings.SYSTEMUSERS_FTP_LOG_PATH, - 'last_date': last_date.strftime("%Y%m%d%H%M%S"), + 'log_file': '%s{,.1}' % settings.SYSTEMUSERS_FTP_LOG_PATH, + 'last_date': self.get_last_date(site.pk).strftime("%Y-%m-%d %H:%M:%S %Z"), 'object_id': user.pk, 'username': user.username, } diff --git a/orchestra/apps/systemusers/models.py b/orchestra/apps/systemusers/models.py index aa4f4bd7..63e1a362 100644 --- a/orchestra/apps/systemusers/models.py +++ b/orchestra/apps/systemusers/models.py @@ -33,7 +33,7 @@ class SystemUser(models.Model): help_text=_("Home directory relative to account's ~main_user")) shell = models.CharField(_("shell"), max_length=32, 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. " "Which additional groups would you like them to be a member of?")) # is_main = models.BooleanField(_("is main"), default=False) @@ -72,26 +72,7 @@ class SystemUser(models.Model): basehome = settings.SYSTEMUSERS_HOME % context else: basehome = self.account.main_systemuser.get_home() - basehome = basehome.replace('/./', '/') - 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 + return os.path.join(basehome, self.home) services.register(SystemUser) diff --git a/orchestra/apps/systemusers/settings.py b/orchestra/apps/systemusers/settings.py index bc6f6e80..5f228058 100644 --- a/orchestra/apps/systemusers/settings.py +++ b/orchestra/apps/systemusers/settings.py @@ -13,7 +13,7 @@ SYSTEMUSERS_SHELLS = getattr(settings, 'SYSTEMUSERS_SHELLS', ( 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') diff --git a/orchestra/apps/websites/backends/apache.py b/orchestra/apps/websites/backends/apache.py index 24bceaf2..88e3b3ad 100644 --- a/orchestra/apps/websites/backends/apache.py +++ b/orchestra/apps/websites/backends/apache.py @@ -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)) def get_context(self, site): - last_date = self.get_last_date(site.pk) return { '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, }