Exemplo n.º 1
0
 def ready(self):
     from .management import create_initial_superuser
     from .models import Account
     services.register(Account, menu=False, dashboard=False)
     accounts.register(Account, icon='Face-monkey.png')
     post_migrate.connect(create_initial_superuser,
         dispatch_uid="orchestra.contrib.accounts.management.createsuperuser")
Exemplo n.º 2
0
 def ready(self):
     from .models import SystemUser
     services.register(SystemUser, icon='roleplaying.png')
     if 'migrate' in sys.argv and 'accounts' not in sys.argv:
         post_migrate.connect(
             self.create_initial_systemuser,
             dispatch_uid=
             "orchestra.contrib.systemusers.apps.create_initial_systemuser")
Exemplo n.º 3
0
 def ready(self):
     from .management import create_initial_superuser
     from .models import Account
     services.register(Account, menu=False, dashboard=False)
     accounts.register(Account, icon='Face-monkey.png')
     post_migrate.connect(
         create_initial_superuser,
         dispatch_uid="orchestra.contrib.accounts.management.createsuperuser"
     )
Exemplo n.º 4
0
    def ready(self):
        if database_ready():
#            from django.contrib.contenttypes.models import ContentType
#            from .models import Content, Website
#            qset = Content.content_type.field.get_limit_choices_to()
#            for ct in ContentType.objects.filter(qset):
#                relation = GenericRelation('websites.Content')
#                ct.model_class().add_to_class('content_set', relation)
            from .models import Website
            services.register(Website, icon='Applications-internet.png')
Exemplo n.º 5
0
 def ready(self):
     from .models import MiscService, Miscellaneous
     services.register(Miscellaneous, icon='applications-other.png')
     administration.register(MiscService, icon='Misc-Misc-Box-icon.png')
     ModelTranslation.register(MiscService, ('verbose_name',))
Exemplo n.º 6
0
    def ready(self):
        from .models import Mailbox, Address

        services.register(Mailbox, icon="email.png")
        services.register(Address, icon="X-office-address-book.png")
        from . import signals
Exemplo n.º 7
0
        return self.name
    
    @cached_property
    def option_class(self):
        return AppOption.get(self.name)
    
    @cached_property
    def option_instance(self):
        """ Per request lived option instance """
        return self.option_class(self)
    
    def clean(self):
        self.option_instance.validate()


services.register(WebApp)


# Admin bulk deletion doesn't call model.delete()
# So, signals are used instead of model method overriding

@receiver(pre_save, sender=WebApp, dispatch_uid='webapps.type.save')
def type_save(sender, *args, **kwargs):
    instance = kwargs['instance']
    instance.type_instance.save()

@receiver(pre_delete, sender=WebApp, dispatch_uid='webapps.type.delete')
def type_delete(sender, *args, **kwargs):
    instance = kwargs['instance']
    try:
        instance.type_instance.delete()
Exemplo n.º 8
0
            validators=[validators.validate_forward])
    account = models.ForeignKey('accounts.Account', verbose_name=_("Account"),
            related_name='addresses')
    
    class Meta:
        verbose_name_plural = _("addresses")
        unique_together = ('name', 'domain')
    
    def __unicode__(self):
        return self.email
    
    @property
    def email(self):
        return "%s@%s" % (self.name, self.domain)


class Autoresponse(models.Model):
    address = models.OneToOneField(Address, verbose_name=_("address"),
            related_name='autoresponse')
    # TODO initial_date
    subject = models.CharField(_("subject"), max_length=256)
    message = models.TextField(_("message"))
    enabled = models.BooleanField(_("enabled"), default=False)
    
    def __unicode__(self):
        return self.address


services.register(Mailbox)
services.register(Address)
Exemplo n.º 9
0
        """
        # Active superusers have all permissions.
        if self.is_active and self.is_superuser:
            return True
        # Otherwise we need to check the backends.
        return auth._user_has_perm(self, perm, obj)
    
    def has_perms(self, perm_list, obj=None):
        """
        Returns True if the user has each of the specified permissions. If
        object is passed, it checks if the user has all required perms for this
        object.
        """
        for perm in perm_list:
            if not self.has_perm(perm, obj):
                return False
        return True
    
    def has_module_perms(self, app_label):
        """
        Returns True if the user has any permissions in the given app label.
        Uses pretty much the same logic as has_perm, above.
        """
        # Active superusers have all permissions.
        if self.is_active and self.is_superuser:
            return True
        return auth._user_has_module_perms(self, app_label)


services.register(User, menu=False)
Exemplo n.º 10
0
        """
        Returns True if the user has any permissions in the given app label.
        Uses pretty much the same logic as has_perm, above.
        """
        # Active superusers have all permissions.
        if self.is_active and self.is_superuser:
            return True
        return auth._user_has_module_perms(self, app_label)
    
    def get_related_passwords(self):
        related = [
            self.main_systemuser,
        ]
        for model, key, related_kwargs, __ in settings.ACCOUNTS_CREATE_RELATED:
            if 'password' not in related_kwargs:
                continue
            model = apps.get_model(model)
            kwargs = {
                key: eval(related_kwargs[key], {'account': self})
            }
            try:
                rel = model.objects.get(account=self, **kwargs)
            except model.DoesNotExist:
                continue
            related.append(rel)
        return related


services.register(Account, menu=False)
accounts.register(Account)
Exemplo n.º 11
0
 def ready(self):
     from .models import Domain
     services.register(Domain, icon='domain.png')
Exemplo n.º 12
0
    has_amount = models.BooleanField(default=False,
            help_text=_("Designates whether this service has <tt>amount</tt> "
                        "property or not."))
    is_active = models.BooleanField(default=True,
            help_text=_("Whether new instances of this service can be created "
                        "or not. Unselect this instead of deleting services."))
    
    def __unicode__(self):
        return self.name


class Miscellaneous(models.Model):
    service = models.ForeignKey(MiscService, verbose_name=_("service"),
            related_name='instances')
    account = models.ForeignKey('accounts.Account', verbose_name=_("account"),
            related_name='miscellaneous')
    description = models.TextField(_("description"), blank=True)
    amount = models.PositiveIntegerField(_("amount"), default=1)
    is_active = models.BooleanField(default=True,
            help_text=_("Designates whether this service should be treated as "
                        "active. Unselect this instead of deleting services."))
    
    class Meta:
        verbose_name_plural = _("miscellaneous")
    
    def __unicode__(self):
        return "{0}-{1}".format(str(self.service), str(self.account))


services.register(Miscellaneous)
Exemplo n.º 13
0
 def ready(self):
     from . import signals
     from .models import SaaS
     services.register(SaaS, icon='saas.png')
Exemplo n.º 14
0
        self.directive_instance.validate(self)


class Content(models.Model):
    # related_name is content_set to differentiate between website.content -> webapp
    webapp = models.ForeignKey('webapps.WebApp', verbose_name=_("web application"))
    website = models.ForeignKey('websites.Website', verbose_name=_("web site"))
    path = models.CharField(_("path"), max_length=256, blank=True,
        validators=[validators.validate_url_path])
    
    class Meta:
        unique_together = ('website', 'path')
    
    def __str__(self):
        try:
            return self.website.name + self.path
        except Website.DoesNotExist:
            return self.path
    
    def clean(self):
        if not self.path:
            self.path = '/'
    
    def get_absolute_url(self):
        domain = self.website.domains.first()
        if domain:
            return '%s://%s%s' % (self.website.get_protocol(), domain, self.path)


services.register(Website)
Exemplo n.º 15
0
    type = models.CharField(_("type"), max_length=32, choices=TYPE_CHOICES)
    value = models.CharField(_("value"), max_length=256)
    
    def __str__(self):
        return "%s %s IN %s %s" % (self.domain, self.get_ttl(), self.type, self.value)
    
    def clean(self):
        """ validates record value based on its type """
        # validate value
        self.value = self.value.lower().strip()
        choices = {
            self.MX: validators.validate_mx_record,
            self.NS: validators.validate_zone_label,
            self.A: validate_ipv4_address,
            self.AAAA: validate_ipv6_address,
            self.CNAME: validators.validate_zone_label,
            self.TXT: validate_ascii,
            self.SRV: validators.validate_srv_record,
            self.SOA: validators.validate_soa_record,
        }
        try:
            choices[self.type](self.value)
        except ValidationError as error:
            raise ValidationError({'value': error})
    
    def get_ttl(self):
        return self.ttl or settings.DOMAINS_DEFAULT_TTL


services.register(Domain)
Exemplo n.º 16
0
 def ready(self):
     from .models import Plan, ContractedPlan
     accounts.register(ContractedPlan, icon='ContractedPack.png')
     services.register(ContractedPlan, menu=False, dashboard=False)
     administration.register(Plan, icon='Pack.png')
     ModelTranslation.register(Plan, ('verbose_name',))
Exemplo n.º 17
0
 def ready(self):
     from .models import WebApp
     services.register(WebApp, icon='Applications-other.png')
     from . import signals
Exemplo n.º 18
0
from . import settings


class VPS(models.Model):
    hostname = models.CharField(_("hostname"), max_length=256, unique=True,
        validators=[validate_hostname])
    type = models.CharField(_("type"), max_length=64, choices=settings.VPS_TYPES,
        default=settings.VPS_DEFAULT_TYPE)
    template = models.CharField(_("template"), max_length=64,
        choices=settings.VPS_TEMPLATES, default=settings.VPS_DEFAULT_TEMPLATE)
    password = models.CharField(_('password'), max_length=128,
        help_text=_("<TT>root</TT> password of this virtual machine"))
    account = models.ForeignKey('accounts.Account', verbose_name=_("Account"),
        related_name='vpss')
    
    class Meta:
        verbose_name = "VPS"
        verbose_name_plural = "VPSs"
    
    def __str__(self):
        return self.hostname
    
    def set_password(self, raw_password):
        self.password = make_password(raw_password)
    
    def get_username(self):
        return self.hostname


services.register(VPS)
Exemplo n.º 19
0
 def ready(self):
     from .models import Database, DatabaseUser
     services.register(Database, icon='database.png')
     services.register(DatabaseUser, icon='postgresql.png', verbose_name_plural=_("Database users"))
Exemplo n.º 20
0
 def ready(self):
     from .models import WebApp
     services.register(WebApp, icon='Applications-other.png')
     from . import signals
Exemplo n.º 21
0
from . import settings


class List(models.Model):
    name = models.CharField(_("name"), max_length=128, unique=True,
            validators=[validate_name])
    address_name = models.CharField(_("address name"), max_length=128,
            validators=[validate_name], blank=True)
    address_domain = models.ForeignKey(settings.LISTS_DOMAIN_MODEL,
            verbose_name=_("address domain"), blank=True, null=True)
    admin_email = models.EmailField(_("admin email"),
            help_text=_("Administration email address"))
    account = models.ForeignKey('accounts.Account', verbose_name=_("Account"),
            related_name='lists')
    
    class Meta:
        unique_together = ('address_name', 'address_domain')
    
    def __unicode__(self):
        return "%s@%s" % (self.address_name, self.address_domain)
    
    def get_username(self):
        return self.name
    
    def set_password(self, password):
        self.password = password


services.register(List)
Exemplo n.º 22
0
 def ready(self):
     from .models import List
     services.register(List, icon='email-alter.png')
     from . import signals
Exemplo n.º 23
0
 def ready(self):
     from .models import SystemUser
     services.register(SystemUser, icon='roleplaying.png')
     if 'migrate' in sys.argv and 'accounts' not in sys.argv:
         post_migrate.connect(self.create_initial_systemuser,
             dispatch_uid="orchestra.contrib.systemusers.apps.create_initial_systemuser")
Exemplo n.º 24
0
            if self.has_shell:
                directory_error = _("Directory with shell users can not be specified.")
            elif self.account_id and self.is_main:
                directory_error = _("Directory with main system users can not be specified.")
            elif self.home == self.get_base_home():
                directory_error = _("Directory on the user's base home is not allowed.")
            if directory_error:
                raise ValidationError({
                    'directory': directory_error,
                })
        if self.has_shell and self.home and self.home != self.get_base_home():
            raise ValidationError({
                'home': _("Shell users should use their own home."),
            })
    
    def set_password(self, raw_password):
        self.password = make_password(raw_password)
    
    def get_base_home(self):
        context = {
            'user': self.username,
            'username': self.username,
        }
        return os.path.normpath(settings.SYSTEMUSERS_HOME % context)
    
    def get_home(self):
        return os.path.normpath(os.path.join(self.home, self.directory))


services.register(SystemUser)
Exemplo n.º 25
0
 def ready(self):
     from .models import VPS
     services.register(VPS, icon='TuxBox.png')
Exemplo n.º 26
0
            validators=[validators.validate_forward])
    account = models.ForeignKey('accounts.Account', verbose_name=_("Account"),
            related_name='addresses')
    
    class Meta:
        verbose_name_plural = _("addresses")
        unique_together = ('name', 'domain')
    
    def __unicode__(self):
        return self.email
    
    @property
    def email(self):
        return "%s@%s" % (self.name, self.domain)


class Autoresponse(models.Model):
    address = models.OneToOneField(Address, verbose_name=_("address"),
            related_name='autoresponse')
    # TODO initial_date
    subject = models.CharField(_("subject"), max_length=256)
    message = models.TextField(_("message"))
    enabled = models.BooleanField(_("enabled"), default=False)
    
    def __unicode__(self):
        return self.address


services.register(Address)
roles.register('mailbox', Mailbox)
Exemplo n.º 27
0
 def ready(self):
     from .models import Database, DatabaseUser
     services.register(Database, icon='database.png')
     services.register(DatabaseUser,
                       icon='postgresql.png',
                       verbose_name_plural=_("Database users"))
Exemplo n.º 28
0
    service = models.ForeignKey('services.Service', verbose_name=_("service"),
        related_name='rates')
    plan = models.ForeignKey(Plan, verbose_name=_("plan"), related_name='rates')
    quantity = models.PositiveIntegerField(_("quantity"), null=True, blank=True)
    price = models.DecimalField(_("price"), max_digits=12, decimal_places=2)
    
    objects = RateQuerySet.as_manager()
    
    class Meta:
        unique_together = ('service', 'plan', 'quantity')
    
    def __str__(self):
        return "{}-{}".format(str(self.price), self.quantity)
    
    @classmethod
    def get_methods(cls):
        return cls.RATE_METHODS
    
    @classmethod
    def get_choices(cls):
        choices = []
        for name, method in cls.RATE_METHODS.items():
            choices.append((name, method.verbose_name))
        return choices


accounts.register(ContractedPlan)
services.register(ContractedPlan, menu=False)

ModelTranslation.register(Plan, ('verbose_name',))
Exemplo n.º 29
0
 def ready(self):
     from .models import Mailbox, Address
     services.register(Mailbox, icon='email.png')
     services.register(Address, icon='X-office-address-book.png')
Exemplo n.º 30
0
 def ready(self):
     from .models import Plan, ContractedPlan
     accounts.register(ContractedPlan, icon='ContractedPack.png')
     services.register(ContractedPlan, menu=False, dashboard=False)
     administration.register(Plan, icon='Pack.png')
     ModelTranslation.register(Plan, ('verbose_name', ))
Exemplo n.º 31
0
 def ready(self):
     from .models import List
     services.register(List, icon='email-alter.png')
Exemplo n.º 32
0
 def ready(self):
     from .models import Mailbox, Address
     services.register(Mailbox, icon='email.png')
     services.register(Address, icon='X-office-address-book.png')
     from . import signals
Exemplo n.º 33
0
    password = models.CharField(_("password"), max_length=128)
    type = models.CharField(_("type"), max_length=32,
            choices=settings.DATABASES_TYPE_CHOICES,
            default=settings.DATABASES_DEFAULT_TYPE)
    account = models.ForeignKey('accounts.Account', verbose_name=_("Account"),
            related_name='databaseusers')
    
    class Meta:
        verbose_name_plural = _("DB users")
        unique_together = ('username', 'type')
    
    def __unicode__(self):
        return self.username
    
    def get_username(self):
        return self.username
    
    def set_password(self, password):
        if self.type == self.MYSQL:
            # MySQL stores sha1(sha1(password).binary).hex
            binary = hashlib.sha1(password).digest()
            hexdigest = hashlib.sha1(binary).hexdigest()
            password = '******' % hexdigest.upper()
            self.password = password
        else:
            raise TypeError("Database type '%s' not supported" % self.type)


services.register(Database)
services.register(DatabaseUser, verbose_name_plural=_("Database users"))
Exemplo n.º 34
0
 def ready(self):
     from .models import Domain
     services.register(Domain, icon='domain.png')
Exemplo n.º 35
0
            return 0


@receiver(pre_delete, dispatch_uid="orders.cancel_orders")
def cancel_orders(sender, **kwargs):
    if sender in services:
        instance = kwargs['instance']
        for order in Order.objects.by_object(instance).active():
            order.cancel()


@receiver(post_save, dispatch_uid="orders.update_orders")
@receiver(post_delete, dispatch_uid="orders.update_orders_post_delete")
def update_orders(sender, **kwargs):
    exclude = (
        MetricStorage, LogEntry, Order, Service, ContentType, MigrationRecorder.Migration
    )
    if sender not in exclude:
        instance = kwargs['instance']
        if instance.pk:
            # post_save
            Order.update_orders(instance)
        related = helpers.get_related_objects(instance)
        if related:
            Order.update_orders(related)


accounts.register(Order)
accounts.register(Plan)
services.register(Plan, menu=False)