2026-11-21 12:35:24 +01:00
|
|
|
import uuid
|
|
|
|
|
|
2026-11-19 22:16:29 +01:00
|
|
|
from django.conf import settings
|
2026-11-21 15:32:02 +01:00
|
|
|
from django.core.exceptions import ValidationError
|
2026-11-21 13:02:06 +01:00
|
|
|
from django.core.validators import (
|
|
|
|
|
MaxValueValidator,
|
|
|
|
|
MinValueValidator,
|
|
|
|
|
RegexValidator,
|
|
|
|
|
)
|
2026-11-21 15:32:02 +01:00
|
|
|
from django.db import models, router, transaction
|
2026-11-19 21:30:25 +01:00
|
|
|
from django.urls import reverse
|
2026-11-21 01:17:01 +01:00
|
|
|
from django.utils import timezone
|
2026-11-19 21:08:13 +01:00
|
|
|
|
2026-11-21 12:35:24 +01:00
|
|
|
from coulobre.account_backup_request import backup_archive
|
2026-11-21 15:08:48 +01:00
|
|
|
from coulobre.account_backup_retention import MAX_RETAINED_BACKUPS
|
2026-11-21 14:42:38 +01:00
|
|
|
from coulobre.account_restore_request import MAX_RESTORE_PATH_BYTES
|
2026-11-21 02:12:32 +01:00
|
|
|
from coulobre.database_node import (
|
|
|
|
|
DATABASE_SUFFIX_PATTERN,
|
|
|
|
|
INVALID_SUFFIX,
|
|
|
|
|
DatabaseSpec,
|
|
|
|
|
)
|
2026-11-20 19:46:11 +01:00
|
|
|
from coulobre.dns_node import (
|
|
|
|
|
MAX_SOA_SERIAL,
|
|
|
|
|
AddressRecord,
|
|
|
|
|
DnsZone,
|
|
|
|
|
MxRecord,
|
|
|
|
|
TxtRecord,
|
|
|
|
|
)
|
2026-11-21 13:02:06 +01:00
|
|
|
from coulobre.mail_node import (
|
|
|
|
|
LOCAL_PART_MAX_LENGTH,
|
|
|
|
|
MAX_MAILBOX_QUOTA_MIB,
|
|
|
|
|
MailboxSpec,
|
|
|
|
|
)
|
2026-11-21 16:04:33 +01:00
|
|
|
from coulobre.php_pool_settings import (
|
|
|
|
|
PHP_SETTING_BOUNDS,
|
|
|
|
|
PhpPoolSettings,
|
|
|
|
|
PhpPoolSettingsError,
|
|
|
|
|
)
|
2026-11-21 14:10:34 +01:00
|
|
|
from coulobre.web_node import MAX_STORAGE_LIMIT_MIB
|
2026-11-19 22:40:47 +01:00
|
|
|
|
2026-11-19 21:08:13 +01:00
|
|
|
from .fields import DomainNameField
|
|
|
|
|
|
|
|
|
|
|
2026-11-19 22:16:29 +01:00
|
|
|
class Reseller(models.Model):
|
|
|
|
|
user = models.OneToOneField(
|
|
|
|
|
settings.AUTH_USER_MODEL,
|
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
|
related_name="hosting_reseller",
|
2026-11-21 02:12:32 +01:00
|
|
|
limit_choices_to={
|
|
|
|
|
"is_superuser": False,
|
|
|
|
|
"hosting_customer__isnull": True,
|
|
|
|
|
},
|
2026-11-19 22:16:29 +01:00
|
|
|
)
|
2026-11-19 22:32:19 +01:00
|
|
|
account_limit = models.PositiveIntegerField(default=0)
|
|
|
|
|
hosting_plans = models.ManyToManyField("HostingPlan", blank=True)
|
|
|
|
|
|
2026-11-19 22:16:29 +01:00
|
|
|
def __str__(self):
|
|
|
|
|
return self.user.get_username()
|
|
|
|
|
|
2026-11-21 19:08:45 +01:00
|
|
|
def get_absolute_url(self):
|
|
|
|
|
return reverse("panel:reseller", kwargs={"pk": self.pk})
|
|
|
|
|
|
2026-11-21 02:12:32 +01:00
|
|
|
def may_create_accounts(self):
|
|
|
|
|
return self.account_limit > 0 and self.hosting_plans.exists()
|
|
|
|
|
|
2026-11-19 22:16:29 +01:00
|
|
|
|
2026-11-21 19:08:45 +01:00
|
|
|
class ResellerAuditEvent(models.Model):
|
|
|
|
|
class Action(models.TextChoices):
|
|
|
|
|
CREATE = "create", "Created reseller"
|
|
|
|
|
UPDATE = "update", "Updated reseller"
|
|
|
|
|
ASSIGN = "assign", "Assigned hosting account"
|
|
|
|
|
UNASSIGN = "unassign", "Unassigned hosting account"
|
|
|
|
|
PLAN = "plan", "Changed hosting account plan"
|
|
|
|
|
|
|
|
|
|
reseller = models.ForeignKey(
|
|
|
|
|
Reseller,
|
|
|
|
|
on_delete=models.SET_NULL,
|
|
|
|
|
null=True,
|
|
|
|
|
related_name="audit_events",
|
|
|
|
|
)
|
|
|
|
|
reseller_username = models.CharField(max_length=150)
|
|
|
|
|
actor_username = models.CharField(max_length=150)
|
|
|
|
|
action = models.CharField(max_length=8, choices=Action)
|
|
|
|
|
account_domain = DomainNameField(max_length=253, blank=True)
|
|
|
|
|
changes = models.JSONField()
|
|
|
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
ordering = ("-pk",)
|
|
|
|
|
|
|
|
|
|
|
2026-11-21 00:23:52 +01:00
|
|
|
class Customer(models.Model):
|
|
|
|
|
user = models.OneToOneField(
|
|
|
|
|
settings.AUTH_USER_MODEL,
|
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
|
related_name="hosting_customer",
|
|
|
|
|
limit_choices_to={
|
|
|
|
|
"is_staff": False,
|
|
|
|
|
"is_superuser": False,
|
|
|
|
|
"hosting_reseller__isnull": True,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
|
return self.user.get_username()
|
|
|
|
|
|
2026-11-21 02:24:04 +01:00
|
|
|
@property
|
|
|
|
|
def may_be_impersonated(self):
|
|
|
|
|
user = self.user
|
|
|
|
|
return (
|
|
|
|
|
user.is_active
|
|
|
|
|
and not user.is_staff
|
|
|
|
|
and not user.is_superuser
|
|
|
|
|
and not hasattr(user, "hosting_reseller")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CustomerImpersonation(models.Model):
|
|
|
|
|
class EndReason(models.TextChoices):
|
|
|
|
|
STOPPED = "stopped", "Ended by administrator"
|
|
|
|
|
SIGNED_OUT = "signed_out", "Signed out"
|
|
|
|
|
EXPIRED = "expired", "Expired"
|
|
|
|
|
ACCESS_REVOKED = "access_revoked", "Access revoked"
|
|
|
|
|
|
|
|
|
|
operator = models.ForeignKey(
|
|
|
|
|
settings.AUTH_USER_MODEL,
|
|
|
|
|
on_delete=models.SET_NULL,
|
|
|
|
|
null=True,
|
|
|
|
|
related_name="+",
|
|
|
|
|
)
|
|
|
|
|
customer = models.ForeignKey(
|
|
|
|
|
Customer,
|
|
|
|
|
on_delete=models.SET_NULL,
|
|
|
|
|
null=True,
|
|
|
|
|
related_name="+",
|
|
|
|
|
)
|
|
|
|
|
operator_username = models.CharField(max_length=150)
|
|
|
|
|
customer_username = models.CharField(max_length=150)
|
|
|
|
|
started_at = models.DateTimeField(default=timezone.now)
|
|
|
|
|
expires_at = models.DateTimeField()
|
|
|
|
|
ended_at = models.DateTimeField(null=True, blank=True)
|
|
|
|
|
end_reason = models.CharField(
|
|
|
|
|
max_length=16, choices=EndReason.choices, blank=True
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
ordering = ("-started_at", "-pk")
|
|
|
|
|
default_permissions = ("view",)
|
|
|
|
|
verbose_name = "customer impersonation session"
|
|
|
|
|
permissions = (
|
|
|
|
|
("impersonate_customer", "Can view the panel as a customer"),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
|
return f"{self.operator_username} viewing as {self.customer_username}"
|
|
|
|
|
|
2026-11-21 00:23:52 +01:00
|
|
|
|
2026-11-21 16:27:07 +01:00
|
|
|
class ServiceCredentialAccess(models.Model):
|
|
|
|
|
class Kind(models.TextChoices):
|
|
|
|
|
DATABASE = "database", "MariaDB database"
|
|
|
|
|
MAILBOX = "mailbox", "Mailbox"
|
|
|
|
|
|
|
|
|
|
class Outcome(models.TextChoices):
|
|
|
|
|
REQUESTED = "requested", "Requested"
|
|
|
|
|
REJECTED = "rejected", "Password confirmation failed"
|
|
|
|
|
UNAVAILABLE = "unavailable", "Credentials unavailable"
|
|
|
|
|
REVEALED = "revealed", "Credentials revealed"
|
2026-11-21 19:23:01 +01:00
|
|
|
ROTATED = "rotated", "Password changed"
|
|
|
|
|
BLOCKED = "blocked", "Password change was blocked"
|
2026-11-21 16:27:07 +01:00
|
|
|
|
|
|
|
|
class Method(models.TextChoices):
|
|
|
|
|
REVEAL = "reveal", "Show connection details"
|
|
|
|
|
PHPMYADMIN = "phpmyadmin", "phpMyAdmin"
|
2026-11-21 20:18:05 +01:00
|
|
|
WEBMAIL = "webmail", "Roundcube"
|
2026-11-21 19:23:01 +01:00
|
|
|
ROTATE = "rotate", "Rotate password"
|
2026-11-21 16:27:07 +01:00
|
|
|
|
|
|
|
|
method = models.CharField(
|
|
|
|
|
max_length=10, choices=Method, default=Method.REVEAL
|
|
|
|
|
)
|
|
|
|
|
actor = models.ForeignKey(
|
|
|
|
|
settings.AUTH_USER_MODEL, null=True, on_delete=models.SET_NULL
|
|
|
|
|
)
|
|
|
|
|
actor_username = models.CharField(max_length=150)
|
|
|
|
|
hosting_account_id = models.PositiveBigIntegerField()
|
2026-11-21 19:23:01 +01:00
|
|
|
rotation_id = models.UUIDField(null=True)
|
|
|
|
|
previous_rotation_id = models.UUIDField(null=True)
|
2026-11-21 16:27:07 +01:00
|
|
|
kind = models.CharField(max_length=8, choices=Kind)
|
|
|
|
|
resource = models.CharField(max_length=254)
|
|
|
|
|
requested_at = models.DateTimeField(default=timezone.now)
|
|
|
|
|
outcome = models.CharField(max_length=11, choices=Outcome)
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
ordering = ("-requested_at", "-pk")
|
|
|
|
|
indexes = [models.Index(fields=("actor", "outcome", "requested_at"))]
|
|
|
|
|
default_permissions = ("view",)
|
|
|
|
|
permissions = [
|
|
|
|
|
("reveal_database_credentials", "Can reveal database credentials"),
|
|
|
|
|
("reveal_mailbox_credentials", "Can reveal mailbox credentials"),
|
2026-11-21 19:23:01 +01:00
|
|
|
("rotate_database_credentials", "Can rotate database credentials"),
|
|
|
|
|
("rotate_mailbox_credentials", "Can rotate mailbox credentials"),
|
2026-11-21 16:27:07 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
2026-11-21 16:04:33 +01:00
|
|
|
def php_plan_field(option, label):
|
|
|
|
|
minimum, maximum = PHP_SETTING_BOUNDS[option]
|
|
|
|
|
return models.PositiveIntegerField(
|
|
|
|
|
label,
|
|
|
|
|
blank=True,
|
|
|
|
|
null=True,
|
|
|
|
|
validators=[MinValueValidator(minimum), MaxValueValidator(maximum)],
|
|
|
|
|
help_text="Leave blank to use the web node default.",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2026-11-19 22:09:10 +01:00
|
|
|
class HostingPlan(models.Model):
|
|
|
|
|
name = models.CharField(max_length=120, unique=True)
|
|
|
|
|
description = models.CharField(max_length=240, blank=True)
|
2026-11-21 00:34:37 +01:00
|
|
|
database_limit = models.PositiveIntegerField(
|
|
|
|
|
blank=True,
|
|
|
|
|
null=True,
|
2026-11-21 02:12:32 +01:00
|
|
|
help_text=(
|
|
|
|
|
"Leave blank for unlimited. "
|
|
|
|
|
"Enter 0 to block new database requests."
|
|
|
|
|
),
|
2026-11-21 00:34:37 +01:00
|
|
|
)
|
|
|
|
|
mailbox_limit = models.PositiveIntegerField(
|
|
|
|
|
blank=True,
|
|
|
|
|
null=True,
|
2026-11-21 02:12:32 +01:00
|
|
|
help_text=(
|
|
|
|
|
"Leave blank for unlimited. Enter 0 to block new mailbox requests."
|
|
|
|
|
),
|
2026-11-21 00:34:37 +01:00
|
|
|
)
|
2026-11-21 13:02:06 +01:00
|
|
|
mailbox_quota_mib = models.PositiveIntegerField(
|
|
|
|
|
"mailbox storage limit (MiB)",
|
|
|
|
|
blank=True,
|
|
|
|
|
null=True,
|
|
|
|
|
validators=[
|
|
|
|
|
MinValueValidator(1),
|
|
|
|
|
MaxValueValidator(MAX_MAILBOX_QUOTA_MIB),
|
|
|
|
|
],
|
|
|
|
|
help_text=(
|
|
|
|
|
"Applies to new mailbox requests. Leave blank for unlimited."
|
|
|
|
|
),
|
|
|
|
|
)
|
2026-11-21 14:10:34 +01:00
|
|
|
website_storage_limit_mib = models.PositiveIntegerField(
|
|
|
|
|
"website storage limit (MiB)",
|
|
|
|
|
blank=True,
|
|
|
|
|
null=True,
|
|
|
|
|
validators=[
|
|
|
|
|
MinValueValidator(1),
|
|
|
|
|
MaxValueValidator(MAX_STORAGE_LIMIT_MIB),
|
|
|
|
|
],
|
|
|
|
|
help_text="Default when applying a website storage limit.",
|
|
|
|
|
)
|
2026-11-19 22:09:10 +01:00
|
|
|
|
2026-11-21 16:04:33 +01:00
|
|
|
php_memory_limit_mib = php_plan_field(
|
|
|
|
|
"memory_limit_mib", "PHP memory limit (MiB)"
|
|
|
|
|
)
|
|
|
|
|
php_upload_limit_mib = php_plan_field(
|
|
|
|
|
"upload_limit_mib", "PHP upload limit (MiB)"
|
|
|
|
|
)
|
|
|
|
|
php_request_timeout_seconds = php_plan_field(
|
|
|
|
|
"request_timeout_seconds", "PHP request timeout (seconds)"
|
|
|
|
|
)
|
|
|
|
|
php_max_children = php_plan_field(
|
|
|
|
|
"max_children", "Maximum PHP-FPM workers"
|
|
|
|
|
)
|
|
|
|
|
|
2026-11-19 22:09:10 +01:00
|
|
|
class Meta:
|
|
|
|
|
ordering = ("name", "pk")
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
|
return self.name
|
|
|
|
|
|
2026-11-21 16:04:33 +01:00
|
|
|
def clean(self):
|
|
|
|
|
super().clean()
|
|
|
|
|
try:
|
|
|
|
|
self.get_php_settings()
|
|
|
|
|
except PhpPoolSettingsError as error:
|
|
|
|
|
raise ValidationError(
|
|
|
|
|
{f"php_{error.field}": str(error)}
|
|
|
|
|
) from error
|
|
|
|
|
|
|
|
|
|
def get_php_settings(self):
|
|
|
|
|
return PhpPoolSettings(
|
|
|
|
|
**{
|
|
|
|
|
option: getattr(self, f"php_{option}")
|
|
|
|
|
for option in PHP_SETTING_BOUNDS
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
2026-11-19 22:09:10 +01:00
|
|
|
|
2026-11-19 21:08:13 +01:00
|
|
|
class HostingAccount(models.Model):
|
|
|
|
|
name = models.CharField(max_length=120)
|
2026-11-21 19:40:19 +01:00
|
|
|
primary_domain = DomainNameField(max_length=253, unique=True, null=True)
|
|
|
|
|
retired_at = models.DateTimeField(null=True, blank=True)
|
2026-11-19 22:09:10 +01:00
|
|
|
hosting_plan = models.ForeignKey(
|
|
|
|
|
HostingPlan, on_delete=models.PROTECT, null=True, blank=True
|
|
|
|
|
)
|
2026-11-19 22:16:29 +01:00
|
|
|
reseller = models.ForeignKey(
|
|
|
|
|
Reseller, on_delete=models.PROTECT, null=True, blank=True
|
|
|
|
|
)
|
2026-11-21 00:23:52 +01:00
|
|
|
customer = models.ForeignKey(
|
|
|
|
|
Customer, on_delete=models.PROTECT, null=True, blank=True
|
|
|
|
|
)
|
2026-11-21 18:55:41 +01:00
|
|
|
services_suspended = models.BooleanField(default=False)
|
2026-11-21 15:08:48 +01:00
|
|
|
scheduled_backups_to_keep = models.PositiveSmallIntegerField(
|
|
|
|
|
null=True,
|
|
|
|
|
blank=True,
|
|
|
|
|
validators=[
|
|
|
|
|
MinValueValidator(1),
|
|
|
|
|
MaxValueValidator(MAX_RETAINED_BACKUPS),
|
|
|
|
|
],
|
|
|
|
|
)
|
2026-11-19 21:08:13 +01:00
|
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
|
|
2026-11-21 15:08:48 +01:00
|
|
|
class Meta:
|
|
|
|
|
constraints = [
|
|
|
|
|
models.CheckConstraint(
|
|
|
|
|
condition=models.Q(scheduled_backups_to_keep__isnull=True)
|
|
|
|
|
| models.Q(
|
|
|
|
|
scheduled_backups_to_keep__gte=1,
|
|
|
|
|
scheduled_backups_to_keep__lte=MAX_RETAINED_BACKUPS,
|
|
|
|
|
),
|
|
|
|
|
name="hosting_account_valid_backup_retention",
|
2026-11-21 19:40:19 +01:00
|
|
|
),
|
|
|
|
|
models.CheckConstraint(
|
|
|
|
|
condition=models.Q(primary_domain__isnull=False)
|
|
|
|
|
| models.Q(retired_at__isnull=False),
|
|
|
|
|
name="hosting_account_active_domain_required",
|
|
|
|
|
),
|
2026-11-21 15:08:48 +01:00
|
|
|
]
|
|
|
|
|
|
2026-11-19 21:08:13 +01:00
|
|
|
def __str__(self):
|
|
|
|
|
return str(self.primary_domain)
|
2026-11-19 21:18:37 +01:00
|
|
|
|
2026-11-21 15:32:02 +01:00
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
|
update_fields = kwargs.get("update_fields")
|
|
|
|
|
if update_fields is not None and "primary_domain" not in update_fields:
|
|
|
|
|
return super().save(*args, **kwargs)
|
|
|
|
|
|
2026-11-21 19:40:19 +01:00
|
|
|
if self.primary_domain is None and self.retired_at is not None:
|
|
|
|
|
return super().save(*args, **kwargs)
|
|
|
|
|
|
2026-11-21 15:32:02 +01:00
|
|
|
self.primary_domain = self._meta.get_field("primary_domain").to_python(
|
|
|
|
|
self.primary_domain
|
|
|
|
|
)
|
|
|
|
|
using = kwargs.get("using") or router.db_for_write(
|
|
|
|
|
type(self), instance=self
|
|
|
|
|
)
|
|
|
|
|
with transaction.atomic(using=using):
|
|
|
|
|
super().save(*args, **kwargs)
|
|
|
|
|
claims = WebsiteDomain.objects.using(using).filter(account=self)
|
|
|
|
|
primary = claims.filter(is_primary=True).first()
|
|
|
|
|
if primary is None:
|
|
|
|
|
claims.create(
|
|
|
|
|
domain=self.primary_domain, account=self, is_primary=True
|
|
|
|
|
)
|
|
|
|
|
elif primary.domain != self.primary_domain:
|
|
|
|
|
if claims.filter(is_primary=False).exists():
|
|
|
|
|
raise ValidationError(
|
|
|
|
|
{
|
|
|
|
|
"primary_domain": (
|
|
|
|
|
"Remove website aliases before changing the "
|
|
|
|
|
"primary domain."
|
|
|
|
|
),
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
primary.domain = self.primary_domain
|
|
|
|
|
primary.save(update_fields=["domain"], using=using)
|
|
|
|
|
|
2026-11-21 02:12:32 +01:00
|
|
|
def get_absolute_url(self):
|
|
|
|
|
return reverse("panel:account", kwargs={"pk": self.pk})
|
|
|
|
|
|
2026-11-21 15:32:02 +01:00
|
|
|
def clean(self):
|
|
|
|
|
super().clean()
|
|
|
|
|
if not self.primary_domain:
|
|
|
|
|
return
|
|
|
|
|
if WebsiteDomain.objects.filter(
|
|
|
|
|
domain=self.primary_domain, is_primary=False
|
|
|
|
|
).exists():
|
|
|
|
|
raise ValidationError(
|
|
|
|
|
{"primary_domain": "This domain is unavailable."}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if self.pk:
|
|
|
|
|
claims = self.website_domains
|
|
|
|
|
if (
|
|
|
|
|
claims.filter(is_primary=False).exists()
|
|
|
|
|
and claims.filter(is_primary=True)
|
|
|
|
|
.exclude(domain=self.primary_domain)
|
|
|
|
|
.exists()
|
|
|
|
|
):
|
|
|
|
|
raise ValidationError(
|
|
|
|
|
{
|
|
|
|
|
"primary_domain": (
|
|
|
|
|
"Remove website aliases before changing the "
|
|
|
|
|
"primary domain."
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WebsiteDomain(models.Model):
|
|
|
|
|
account = models.ForeignKey(
|
|
|
|
|
HostingAccount,
|
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
|
related_name="website_domains",
|
|
|
|
|
)
|
|
|
|
|
domain = DomainNameField(max_length=253, unique=True)
|
|
|
|
|
is_primary = models.BooleanField(default=False)
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
|
return self.domain
|
|
|
|
|
|
2026-11-19 21:18:37 +01:00
|
|
|
|
2026-11-19 22:40:47 +01:00
|
|
|
class HostingDatabase(models.Model):
|
|
|
|
|
account = models.ForeignKey(
|
|
|
|
|
HostingAccount, on_delete=models.PROTECT, related_name="databases"
|
|
|
|
|
)
|
|
|
|
|
suffix = models.CharField(
|
|
|
|
|
"database suffix",
|
|
|
|
|
max_length=24,
|
|
|
|
|
validators=[RegexValidator(DATABASE_SUFFIX_PATTERN, INVALID_SUFFIX)],
|
|
|
|
|
help_text=INVALID_SUFFIX,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
ordering = ("suffix",)
|
|
|
|
|
constraints = [
|
|
|
|
|
models.UniqueConstraint(
|
|
|
|
|
fields=("account", "suffix"),
|
|
|
|
|
name="hosting_database_account_suffix_unique",
|
|
|
|
|
)
|
|
|
|
|
]
|
|
|
|
|
|
2026-11-21 02:12:32 +01:00
|
|
|
def __str__(self):
|
|
|
|
|
return self.spec.name
|
|
|
|
|
|
2026-11-19 22:40:47 +01:00
|
|
|
@property
|
|
|
|
|
def spec(self):
|
|
|
|
|
return DatabaseSpec(self.account_id, self.suffix)
|
|
|
|
|
|
|
|
|
|
|
2026-11-21 20:18:05 +01:00
|
|
|
class ServiceSignOnGrant(models.Model):
|
2026-11-21 16:27:07 +01:00
|
|
|
token_digest = models.CharField(max_length=64, primary_key=True)
|
|
|
|
|
actor = models.ForeignKey(
|
|
|
|
|
settings.AUTH_USER_MODEL, on_delete=models.CASCADE
|
|
|
|
|
)
|
|
|
|
|
expires_at = models.DateTimeField(db_index=True)
|
|
|
|
|
redeemed_at = models.DateTimeField(null=True, blank=True)
|
|
|
|
|
|
2026-11-21 20:18:05 +01:00
|
|
|
class Meta:
|
|
|
|
|
abstract = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PhpMyAdminGrant(ServiceSignOnGrant):
|
|
|
|
|
database = models.ForeignKey(HostingDatabase, on_delete=models.CASCADE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RoundcubeGrant(ServiceSignOnGrant):
|
|
|
|
|
mailbox = models.ForeignKey("HostingMailbox", on_delete=models.CASCADE)
|
|
|
|
|
address = models.CharField(max_length=254)
|
|
|
|
|
|
2026-11-21 16:27:07 +01:00
|
|
|
|
2026-11-21 00:03:04 +01:00
|
|
|
class DirectAdminImport(models.Model):
|
|
|
|
|
account = models.OneToOneField(
|
2026-11-21 02:12:32 +01:00
|
|
|
HostingAccount,
|
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
|
related_name="directadmin_import",
|
2026-11-21 00:03:04 +01:00
|
|
|
)
|
|
|
|
|
fingerprint = models.CharField(max_length=64, unique=True)
|
|
|
|
|
|
|
|
|
|
|
2026-11-19 23:11:39 +01:00
|
|
|
class HostingDnsZone(models.Model):
|
|
|
|
|
account = models.ForeignKey(
|
|
|
|
|
HostingAccount, on_delete=models.PROTECT, related_name="dns_zones"
|
|
|
|
|
)
|
|
|
|
|
domain = DomainNameField(max_length=253, unique=True)
|
|
|
|
|
serial = models.PositiveBigIntegerField(default=1)
|
|
|
|
|
nameservers = models.JSONField()
|
|
|
|
|
responsible_name = DomainNameField(max_length=253)
|
|
|
|
|
addresses = models.JSONField(default=list)
|
2026-11-20 19:46:11 +01:00
|
|
|
mx_records = models.JSONField(default=list)
|
|
|
|
|
txt_records = models.JSONField(default=list)
|
2026-11-19 23:11:39 +01:00
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
ordering = ("domain",)
|
|
|
|
|
constraints = [
|
|
|
|
|
models.CheckConstraint(
|
|
|
|
|
condition=models.Q(serial__lte=MAX_SOA_SERIAL),
|
|
|
|
|
name="hosting_dns_zone_valid_serial",
|
|
|
|
|
)
|
|
|
|
|
]
|
|
|
|
|
|
2026-11-21 02:12:32 +01:00
|
|
|
def __str__(self):
|
|
|
|
|
return str(self.domain)
|
|
|
|
|
|
2026-11-19 23:11:39 +01:00
|
|
|
@property
|
|
|
|
|
def spec(self):
|
|
|
|
|
return DnsZone(
|
|
|
|
|
domain=self.domain,
|
|
|
|
|
serial=self.serial,
|
|
|
|
|
nameservers=tuple(self.nameservers),
|
|
|
|
|
responsible_name=self.responsible_name,
|
|
|
|
|
addresses=tuple(
|
|
|
|
|
AddressRecord.from_manifest(item) for item in self.addresses
|
|
|
|
|
),
|
2026-11-21 02:12:32 +01:00
|
|
|
mx_records=tuple(
|
|
|
|
|
MxRecord.from_manifest(item) for item in self.mx_records
|
|
|
|
|
),
|
2026-11-20 19:46:11 +01:00
|
|
|
txt_records=tuple(
|
|
|
|
|
TxtRecord.from_manifest(item) for item in self.txt_records
|
|
|
|
|
),
|
2026-11-19 23:11:39 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2026-11-19 23:24:40 +01:00
|
|
|
class HostingMailDomain(models.Model):
|
|
|
|
|
account = models.ForeignKey(
|
|
|
|
|
HostingAccount, on_delete=models.PROTECT, related_name="mail_domains"
|
|
|
|
|
)
|
|
|
|
|
domain = DomainNameField(max_length=253, unique=True)
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
|
return str(self.domain)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HostingMailbox(models.Model):
|
|
|
|
|
mail_domain = models.ForeignKey(
|
|
|
|
|
HostingMailDomain, on_delete=models.PROTECT, related_name="mailboxes"
|
|
|
|
|
)
|
|
|
|
|
local_part = models.CharField(max_length=LOCAL_PART_MAX_LENGTH)
|
2026-11-21 13:02:06 +01:00
|
|
|
quota_mib = models.PositiveIntegerField(
|
|
|
|
|
"storage limit (MiB)",
|
|
|
|
|
blank=True,
|
|
|
|
|
null=True,
|
|
|
|
|
validators=[
|
|
|
|
|
MinValueValidator(1),
|
|
|
|
|
MaxValueValidator(MAX_MAILBOX_QUOTA_MIB),
|
|
|
|
|
],
|
|
|
|
|
)
|
2026-11-19 23:24:40 +01:00
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
ordering = ("mail_domain__domain", "local_part")
|
|
|
|
|
constraints = [
|
|
|
|
|
models.UniqueConstraint(
|
|
|
|
|
fields=("mail_domain", "local_part"),
|
|
|
|
|
name="hosting_mailbox_domain_local_part_unique",
|
|
|
|
|
)
|
|
|
|
|
]
|
|
|
|
|
|
2026-11-21 02:12:32 +01:00
|
|
|
def __str__(self):
|
|
|
|
|
return self.spec.address
|
|
|
|
|
|
2026-11-19 23:24:40 +01:00
|
|
|
@property
|
|
|
|
|
def spec(self):
|
2026-11-21 13:02:06 +01:00
|
|
|
return MailboxSpec(
|
|
|
|
|
self.mail_domain.domain, self.local_part, self.quota_mib
|
|
|
|
|
)
|
2026-11-19 23:24:40 +01:00
|
|
|
|
|
|
|
|
|
2026-11-19 21:18:37 +01:00
|
|
|
class WebProvisioningPlan(models.Model):
|
|
|
|
|
account = models.ForeignKey(HostingAccount, on_delete=models.CASCADE)
|
|
|
|
|
primary_domain = DomainNameField(max_length=253)
|
|
|
|
|
requested_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
|
last_dispatched_at = models.DateTimeField(null=True, blank=True)
|
|
|
|
|
completed_at = models.DateTimeField(null=True, blank=True)
|
|
|
|
|
apache_config = models.TextField(blank=True)
|
|
|
|
|
|
2026-11-21 02:12:32 +01:00
|
|
|
def __str__(self):
|
|
|
|
|
return str(self.primary_domain)
|
|
|
|
|
|
2026-11-19 21:30:25 +01:00
|
|
|
@classmethod
|
|
|
|
|
def for_account(cls, account):
|
|
|
|
|
return cls(account=account, primary_domain=account.primary_domain)
|
|
|
|
|
|
2026-11-19 21:35:59 +01:00
|
|
|
@property
|
|
|
|
|
def can_export(self):
|
|
|
|
|
return (
|
|
|
|
|
self.completed_at is not None
|
|
|
|
|
and bool(self.apache_config)
|
|
|
|
|
and self.primary_domain == self.account.primary_domain
|
|
|
|
|
)
|
|
|
|
|
|
2026-11-21 10:31:32 +01:00
|
|
|
@property
|
|
|
|
|
def can_enable_https(self):
|
|
|
|
|
activation = getattr(self, "activation", None)
|
|
|
|
|
return (
|
|
|
|
|
self.can_export
|
|
|
|
|
and activation is not None
|
|
|
|
|
and activation.state == "configured"
|
|
|
|
|
)
|
|
|
|
|
|
2026-11-21 01:17:01 +01:00
|
|
|
|
2026-11-21 01:26:10 +01:00
|
|
|
class ProvisioningJobManager(models.Manager):
|
|
|
|
|
def queue(self, **target):
|
|
|
|
|
job, created = self.get_or_create(**target)
|
|
|
|
|
if not created:
|
2026-11-21 01:41:06 +01:00
|
|
|
self.requeue(self.filter(pk=job.pk).exclude(problem=""))
|
|
|
|
|
|
|
|
|
|
def requeue(self, jobs, **updates):
|
|
|
|
|
jobs.filter(finished_at__isnull=False).update(
|
|
|
|
|
requested_at=timezone.now(),
|
|
|
|
|
last_dispatched_at=None,
|
|
|
|
|
started_at=None,
|
|
|
|
|
finished_at=None,
|
|
|
|
|
problem="",
|
|
|
|
|
**updates,
|
|
|
|
|
)
|
2026-11-21 01:26:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProvisioningJob(models.Model):
|
2026-11-21 01:17:01 +01:00
|
|
|
requested_at = models.DateTimeField(default=timezone.now)
|
|
|
|
|
last_dispatched_at = models.DateTimeField(null=True, blank=True)
|
|
|
|
|
started_at = models.DateTimeField(null=True, blank=True)
|
|
|
|
|
finished_at = models.DateTimeField(null=True, blank=True)
|
|
|
|
|
problem = models.TextField(blank=True)
|
2026-11-21 01:26:10 +01:00
|
|
|
objects = ProvisioningJobManager()
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
abstract = True
|
2026-11-21 01:17:01 +01:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def state(self):
|
|
|
|
|
if self.finished_at is not None:
|
|
|
|
|
return "failed" if self.problem else "configured"
|
|
|
|
|
return "running" if self.started_at else "queued"
|
2026-11-21 01:26:10 +01:00
|
|
|
|
|
|
|
|
|
2026-11-21 19:40:19 +01:00
|
|
|
class AccountRetirement(models.Model):
|
|
|
|
|
class Policy(models.TextChoices):
|
|
|
|
|
HOLD = "hold", "Keep names reserved"
|
|
|
|
|
RELEASE = "release", "Release names and retain data"
|
|
|
|
|
|
|
|
|
|
account = models.OneToOneField(
|
|
|
|
|
HostingAccount, on_delete=models.PROTECT, related_name="retirement"
|
|
|
|
|
)
|
|
|
|
|
primary_domain = DomainNameField(max_length=253)
|
|
|
|
|
policy = models.CharField(max_length=8, choices=Policy)
|
|
|
|
|
inventory = models.JSONField()
|
|
|
|
|
history = models.JSONField(default=list)
|
|
|
|
|
requested_at = models.DateTimeField(default=timezone.now)
|
|
|
|
|
released_at = models.DateTimeField(null=True, blank=True)
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
ordering = ("-pk",)
|
|
|
|
|
permissions = [
|
|
|
|
|
("retire_hosting_account", "Can retire hosting accounts")
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AccountRetirementJob(ProvisioningJob):
|
|
|
|
|
class Kind(models.TextChoices):
|
|
|
|
|
ALIAS = "alias", "Website alias"
|
|
|
|
|
WEB = "web", "Website and SFTP"
|
|
|
|
|
DATABASE = "database", "Database"
|
|
|
|
|
MAILBOX = "mailbox", "Mailbox"
|
|
|
|
|
DNS = "dns", "DNS zone"
|
|
|
|
|
|
|
|
|
|
retirement = models.ForeignKey(
|
|
|
|
|
AccountRetirement, on_delete=models.CASCADE, related_name="jobs"
|
|
|
|
|
)
|
|
|
|
|
operation_id = models.UUIDField(default=uuid.uuid4, unique=True)
|
|
|
|
|
kind = models.CharField(max_length=8, choices=Kind)
|
|
|
|
|
target = models.CharField(max_length=254)
|
|
|
|
|
manifest = models.JSONField()
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
ordering = ("kind", "target")
|
|
|
|
|
indexes = [
|
|
|
|
|
models.Index(fields=("kind", "finished_at", "requested_at"))
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
2026-11-21 18:55:41 +01:00
|
|
|
class AccountServiceChange(models.Model):
|
|
|
|
|
account = models.ForeignKey(
|
|
|
|
|
HostingAccount,
|
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
|
related_name="service_changes",
|
|
|
|
|
)
|
|
|
|
|
suspended = models.BooleanField()
|
|
|
|
|
is_retry = models.BooleanField(default=False)
|
|
|
|
|
operator_username = models.CharField(max_length=150)
|
|
|
|
|
requested_at = models.DateTimeField(default=timezone.now)
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
ordering = ("-pk",)
|
|
|
|
|
permissions = [
|
|
|
|
|
(
|
|
|
|
|
"suspend_hosting_services",
|
|
|
|
|
"Can suspend and resume hosting services",
|
|
|
|
|
)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AccountServiceJob(ProvisioningJob):
|
|
|
|
|
class Kind(models.TextChoices):
|
|
|
|
|
WEB = "web", "Website"
|
|
|
|
|
SFTP = "sftp", "SFTP"
|
|
|
|
|
DATABASE = "database", "Database"
|
|
|
|
|
MAILBOX = "mailbox", "Mailbox"
|
|
|
|
|
|
|
|
|
|
change = models.ForeignKey(
|
|
|
|
|
AccountServiceChange, on_delete=models.CASCADE, related_name="jobs"
|
|
|
|
|
)
|
|
|
|
|
kind = models.CharField(max_length=8, choices=Kind)
|
|
|
|
|
target = models.CharField(max_length=254)
|
|
|
|
|
manifest = models.JSONField()
|
|
|
|
|
applied_suspended = models.BooleanField(default=False)
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
ordering = ("kind", "target")
|
|
|
|
|
indexes = [
|
|
|
|
|
models.Index(fields=("kind", "finished_at", "requested_at"))
|
|
|
|
|
]
|
|
|
|
|
constraints = [
|
|
|
|
|
models.UniqueConstraint(
|
|
|
|
|
fields=("change", "kind", "target"),
|
|
|
|
|
name="hosting_service_change_unique_target",
|
|
|
|
|
)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
2026-11-21 01:26:10 +01:00
|
|
|
class WebActivation(ProvisioningJob):
|
|
|
|
|
plan = models.OneToOneField(
|
2026-11-21 02:12:32 +01:00
|
|
|
WebProvisioningPlan,
|
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
|
related_name="activation",
|
2026-11-21 01:26:10 +01:00
|
|
|
)
|
|
|
|
|
|
2026-11-21 16:04:33 +01:00
|
|
|
php_settings = models.JSONField(null=True, blank=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SitePhpSettings(ProvisioningJob):
|
|
|
|
|
account = models.OneToOneField(
|
|
|
|
|
HostingAccount,
|
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
|
related_name="php_settings_job",
|
|
|
|
|
)
|
|
|
|
|
domain = DomainNameField(max_length=253)
|
|
|
|
|
requested_settings = models.JSONField()
|
|
|
|
|
applied_settings = models.JSONField(null=True, blank=True)
|
|
|
|
|
applied_at = models.DateTimeField(null=True, blank=True)
|
|
|
|
|
|
2026-11-21 01:26:10 +01:00
|
|
|
|
2026-11-21 13:40:50 +01:00
|
|
|
class SiteStorageUsage(ProvisioningJob):
|
|
|
|
|
account = models.OneToOneField(
|
|
|
|
|
HostingAccount, on_delete=models.CASCADE, related_name="storage_usage"
|
|
|
|
|
)
|
|
|
|
|
domain = DomainNameField(max_length=253)
|
|
|
|
|
used_bytes = models.PositiveBigIntegerField(null=True, blank=True)
|
|
|
|
|
measured_at = models.DateTimeField(null=True, blank=True)
|
|
|
|
|
|
|
|
|
|
|
2026-11-21 14:10:34 +01:00
|
|
|
class SiteStorageLimit(ProvisioningJob):
|
|
|
|
|
account = models.OneToOneField(
|
|
|
|
|
HostingAccount, on_delete=models.CASCADE, related_name="storage_limit"
|
|
|
|
|
)
|
|
|
|
|
domain = DomainNameField(max_length=253)
|
|
|
|
|
limit_mib = models.PositiveIntegerField(null=True)
|
|
|
|
|
applied_mib = models.PositiveIntegerField(null=True)
|
|
|
|
|
applied_at = models.DateTimeField(null=True)
|
|
|
|
|
|
|
|
|
|
|
2026-11-21 10:31:32 +01:00
|
|
|
class WebHTTPS(ProvisioningJob):
|
|
|
|
|
plan = models.OneToOneField(
|
|
|
|
|
WebProvisioningPlan, on_delete=models.CASCADE, related_name="https"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
verbose_name = "website HTTPS request"
|
|
|
|
|
|
|
|
|
|
|
2026-11-21 15:32:02 +01:00
|
|
|
class WebsiteAlias(ProvisioningJob):
|
|
|
|
|
class Operation(models.TextChoices):
|
|
|
|
|
ACTIVATE = "activate", "Activate alias"
|
|
|
|
|
HTTPS = "https", "Enable HTTPS"
|
|
|
|
|
REMOVE = "remove", "Remove alias"
|
|
|
|
|
|
|
|
|
|
reservation = models.OneToOneField(
|
|
|
|
|
WebsiteDomain, on_delete=models.PROTECT, related_name="alias"
|
|
|
|
|
)
|
|
|
|
|
primary_domain = DomainNameField(max_length=253)
|
|
|
|
|
operation = models.CharField(
|
|
|
|
|
max_length=8, choices=Operation, default=Operation.ACTIVATE
|
|
|
|
|
)
|
|
|
|
|
http_active = models.BooleanField(default=False)
|
|
|
|
|
https_active = models.BooleanField(default=False)
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
indexes = [
|
|
|
|
|
models.Index(fields=("operation", "finished_at", "requested_at"))
|
|
|
|
|
]
|
|
|
|
|
permissions = [
|
|
|
|
|
("manage_website_aliases", "Can manage website aliases")
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
2026-11-21 10:56:47 +01:00
|
|
|
class SiteSFTP(ProvisioningJob):
|
|
|
|
|
account = models.OneToOneField(
|
|
|
|
|
HostingAccount, on_delete=models.CASCADE, related_name="sftp"
|
|
|
|
|
)
|
|
|
|
|
domain = DomainNameField(max_length=253)
|
|
|
|
|
public_keys = models.TextField(blank=True)
|
|
|
|
|
requested_customer_id = models.PositiveBigIntegerField(
|
|
|
|
|
null=True, blank=True
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
verbose_name = "site SFTP access"
|
|
|
|
|
verbose_name_plural = "site SFTP access"
|
|
|
|
|
|
|
|
|
|
|
2026-11-21 01:26:10 +01:00
|
|
|
class DatabaseProvisioning(ProvisioningJob):
|
|
|
|
|
database = models.OneToOneField(
|
|
|
|
|
HostingDatabase, on_delete=models.CASCADE, related_name="provisioning"
|
|
|
|
|
)
|
2026-11-21 01:41:06 +01:00
|
|
|
|
|
|
|
|
|
2026-11-21 12:35:24 +01:00
|
|
|
class AccountBackupJob(ProvisioningJob):
|
|
|
|
|
account = models.ForeignKey(
|
|
|
|
|
HostingAccount, on_delete=models.CASCADE, related_name="backup_jobs"
|
|
|
|
|
)
|
|
|
|
|
backup_id = models.UUIDField(
|
|
|
|
|
default=uuid.uuid4, unique=True, editable=False
|
|
|
|
|
)
|
|
|
|
|
manifest = models.JSONField()
|
2026-11-21 14:26:38 +01:00
|
|
|
scheduled_for = models.DateTimeField(null=True, blank=True)
|
2026-11-21 15:08:48 +01:00
|
|
|
archive_bytes = models.PositiveBigIntegerField(null=True, blank=True)
|
|
|
|
|
retention_protected = models.BooleanField(default=False)
|
|
|
|
|
expired_at = models.DateTimeField(null=True, blank=True)
|
2026-11-21 12:35:24 +01:00
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
indexes = [models.Index(fields=("finished_at", "requested_at"))]
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def archive(self):
|
|
|
|
|
return str(backup_archive(self.account_id, self.backup_id))
|
|
|
|
|
|
2026-11-21 12:48:55 +01:00
|
|
|
@property
|
|
|
|
|
def includes_mailboxes(self):
|
|
|
|
|
return "mailboxes" in self.manifest
|
|
|
|
|
|
2026-11-21 15:08:48 +01:00
|
|
|
@property
|
|
|
|
|
def archive_is_restorable(self):
|
|
|
|
|
if self.state != "configured" or self.expired_at is not None:
|
|
|
|
|
return False
|
|
|
|
|
expiration = getattr(self, "expiration", None)
|
|
|
|
|
return expiration is None or expiration.finished_at is not None
|
|
|
|
|
|
2026-11-21 14:42:38 +01:00
|
|
|
def can_restore_website(self, site):
|
|
|
|
|
return (
|
2026-11-21 15:08:48 +01:00
|
|
|
self.archive_is_restorable
|
2026-11-21 14:42:38 +01:00
|
|
|
and self.manifest.get("website") == site.manifest()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2026-11-21 15:08:48 +01:00
|
|
|
class AccountBackupExpiration(ProvisioningJob):
|
|
|
|
|
backup = models.OneToOneField(
|
|
|
|
|
AccountBackupJob, on_delete=models.CASCADE, related_name="expiration"
|
|
|
|
|
)
|
|
|
|
|
keeper_ids = models.JSONField()
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
indexes = [models.Index(fields=("finished_at", "requested_at"))]
|
|
|
|
|
permissions = [
|
|
|
|
|
("manage_backup_retention", "Can manage account backup retention"),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
2026-11-21 14:42:38 +01:00
|
|
|
class WebsiteRestoreJob(ProvisioningJob):
|
|
|
|
|
backup = models.ForeignKey(
|
|
|
|
|
AccountBackupJob,
|
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
|
related_name="website_restores",
|
|
|
|
|
)
|
|
|
|
|
restore_id = models.UUIDField(unique=True, editable=False)
|
|
|
|
|
filename = models.CharField(max_length=MAX_RESTORE_PATH_BYTES, blank=True)
|
|
|
|
|
replace = models.BooleanField(default=False)
|
|
|
|
|
operator_username = models.CharField(max_length=150)
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
indexes = [models.Index(fields=("finished_at", "requested_at"))]
|
|
|
|
|
|
2026-11-21 12:35:24 +01:00
|
|
|
|
2026-11-21 14:54:51 +01:00
|
|
|
class ComponentRestoreJob(ProvisioningJob):
|
|
|
|
|
class Kind(models.TextChoices):
|
|
|
|
|
DATABASE = "database", "Database"
|
|
|
|
|
MAILBOX = "mailbox", "Mailbox"
|
|
|
|
|
|
|
|
|
|
backup = models.ForeignKey(
|
|
|
|
|
AccountBackupJob,
|
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
|
related_name="component_restores",
|
|
|
|
|
)
|
|
|
|
|
restore_id = models.UUIDField(unique=True, editable=False)
|
|
|
|
|
kind = models.CharField(max_length=8, choices=Kind)
|
|
|
|
|
resource = models.CharField(max_length=254)
|
|
|
|
|
operator_username = models.CharField(max_length=150)
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
indexes = [models.Index(fields=("finished_at", "requested_at"))]
|
|
|
|
|
permissions = [
|
|
|
|
|
("restore_account_database", "Can restore an account database"),
|
|
|
|
|
("restore_account_mailbox", "Can restore an account mailbox"),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def target_name(self):
|
|
|
|
|
if self.kind == self.Kind.DATABASE:
|
|
|
|
|
return DatabaseSpec(self.backup.account_id, self.resource).name
|
|
|
|
|
return self.resource
|
|
|
|
|
|
|
|
|
|
|
2026-11-21 14:26:38 +01:00
|
|
|
class AccountBackupSchedule(models.Model):
|
|
|
|
|
class Frequency(models.TextChoices):
|
|
|
|
|
DAILY = "daily", "Daily"
|
|
|
|
|
WEEKLY = "weekly", "Weekly"
|
|
|
|
|
|
|
|
|
|
class Weekday(models.IntegerChoices):
|
|
|
|
|
MONDAY = 0, "Monday"
|
|
|
|
|
TUESDAY = 1, "Tuesday"
|
|
|
|
|
WEDNESDAY = 2, "Wednesday"
|
|
|
|
|
THURSDAY = 3, "Thursday"
|
|
|
|
|
FRIDAY = 4, "Friday"
|
|
|
|
|
SATURDAY = 5, "Saturday"
|
|
|
|
|
SUNDAY = 6, "Sunday"
|
|
|
|
|
|
|
|
|
|
account = models.OneToOneField(
|
|
|
|
|
HostingAccount,
|
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
|
related_name="backup_schedule",
|
|
|
|
|
)
|
|
|
|
|
enabled = models.BooleanField(default=True)
|
|
|
|
|
frequency = models.CharField(
|
|
|
|
|
max_length=6, choices=Frequency, default=Frequency.DAILY
|
|
|
|
|
)
|
|
|
|
|
weekday = models.PositiveSmallIntegerField(
|
|
|
|
|
choices=Weekday, null=True, blank=True
|
|
|
|
|
)
|
|
|
|
|
time = models.TimeField("time (UTC)")
|
|
|
|
|
include_mailboxes = models.BooleanField(default=False)
|
|
|
|
|
next_run_at = models.DateTimeField(null=True, blank=True)
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
indexes = [models.Index(fields=("enabled", "next_run_at"))]
|
|
|
|
|
|
|
|
|
|
|
2026-11-21 01:41:06 +01:00
|
|
|
class DnsPublication(ProvisioningJob):
|
|
|
|
|
zone = models.OneToOneField(
|
|
|
|
|
HostingDnsZone, on_delete=models.CASCADE, related_name="publication"
|
|
|
|
|
)
|
|
|
|
|
manifest = models.JSONField()
|
|
|
|
|
serial = models.PositiveBigIntegerField()
|
|
|
|
|
published_serial = models.PositiveBigIntegerField(null=True, blank=True)
|
2026-11-21 01:51:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class MailboxProvisioning(ProvisioningJob):
|
|
|
|
|
mailbox = models.OneToOneField(
|
|
|
|
|
HostingMailbox, on_delete=models.CASCADE, related_name="provisioning"
|
|
|
|
|
)
|
2026-11-21 13:32:08 +01:00
|
|
|
quota_update = models.BooleanField(default=False)
|
2026-11-21 17:43:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ServiceHealth(models.Model):
|
|
|
|
|
node = models.CharField(max_length=63)
|
|
|
|
|
service = models.CharField(max_length=24)
|
|
|
|
|
result = models.CharField(max_length=24)
|
|
|
|
|
observed_at = models.DateTimeField()
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
default_permissions = ("view",)
|
|
|
|
|
constraints = [
|
|
|
|
|
models.UniqueConstraint(
|
|
|
|
|
fields=("node", "service"),
|
|
|
|
|
name="hosting_service_health_identity",
|
|
|
|
|
)
|
|
|
|
|
]
|