Random fixes

This commit is contained in:
Marc Aymerich 2014-10-27 17:34:14 +00:00
parent 0a522884a7
commit b5fbba012f
11 changed files with 18 additions and 44 deletions

View File

@ -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

View File

@ -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))

View File

@ -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,

View File

@ -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:

View File

@ -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',

View File

@ -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()

View File

@ -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

View File

@ -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,
}

View File

@ -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)

View File

@ -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')

View File

@ -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,
}