1269 lines
43 KiB
Python
1269 lines
43 KiB
Python
from django.conf import settings
|
|
from django.contrib.auth import get_user_model
|
|
from django.contrib.auth.forms import UserCreationForm
|
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
|
from django.core.exceptions import PermissionDenied, ValidationError
|
|
from django.db import IntegrityError, transaction
|
|
from django.db.models import Q
|
|
from django.http import (
|
|
Http404,
|
|
HttpResponse,
|
|
HttpResponseBadRequest,
|
|
JsonResponse,
|
|
)
|
|
from django.shortcuts import get_object_or_404, redirect
|
|
from django.urls import reverse, reverse_lazy
|
|
from django.utils.decorators import method_decorator
|
|
from django.utils.functional import cached_property
|
|
from django.views import View
|
|
from django.views.decorators.debug import sensitive_post_parameters
|
|
from django.views.generic import (
|
|
CreateView,
|
|
DetailView,
|
|
FormView,
|
|
ListView,
|
|
UpdateView,
|
|
)
|
|
from django.views.generic.detail import SingleObjectMixin
|
|
|
|
from coulobre.dns_node import MAX_SOA_SERIAL
|
|
from coulobre.mail_node import INVALID_LOCAL_PART
|
|
from coulobre.sftp_keys import public_key_fingerprint
|
|
from coulobre.web_node import WebSite
|
|
|
|
from .access import (
|
|
OperatorOnlyMixin,
|
|
TenantScopeMixin,
|
|
customer_for_user,
|
|
is_tenant,
|
|
reseller_for_user,
|
|
)
|
|
from .account_backup_forms import (
|
|
SCHEDULE_FIELDS,
|
|
AccountBackupScheduleForm,
|
|
WebsiteRestoreForm,
|
|
)
|
|
from .account_backups import (
|
|
account_backup_manifest,
|
|
queue_account_backup,
|
|
queue_website_restore,
|
|
save_backup_schedule,
|
|
)
|
|
from .dns_forms import DnsZoneEditForm, DnsZoneForm, format_txt_record
|
|
from .dns_publication import queue_dns_publication
|
|
from .impersonation import (
|
|
EndReason,
|
|
can_impersonate_customer,
|
|
end_impersonation,
|
|
start_impersonation,
|
|
)
|
|
from .models import (
|
|
AccountBackupJob,
|
|
AccountBackupSchedule,
|
|
Customer,
|
|
DatabaseProvisioning,
|
|
HostingAccount,
|
|
HostingDatabase,
|
|
HostingDnsZone,
|
|
HostingMailbox,
|
|
HostingPlan,
|
|
Reseller,
|
|
WebActivation,
|
|
WebHTTPS,
|
|
WebProvisioningPlan,
|
|
WebsiteRestoreJob,
|
|
)
|
|
from .reseller_accounts import create_reseller_account
|
|
from .resource_requests import (
|
|
change_mailbox_quota,
|
|
create_database_request,
|
|
create_mailbox_request,
|
|
queue_mailbox_provisioning,
|
|
queue_site_storage_limit,
|
|
queue_site_storage_measurement,
|
|
)
|
|
from .sftp import (
|
|
SFTPKeyUploadForm,
|
|
can_manage_sftp,
|
|
queue_sftp_keys,
|
|
site_is_active,
|
|
)
|
|
from .web_node import (
|
|
SiteStorageLimitForm,
|
|
build_web_smoke_bundle,
|
|
serialize_deployment_manifest,
|
|
)
|
|
|
|
VIEW_ACCOUNTS = "hosting.view_hostingaccount"
|
|
CHANGE_ACCOUNTS = "hosting.change_hostingaccount"
|
|
VIEW_PLANS = "hosting.view_webprovisioningplan"
|
|
VIEW_HOSTING_PLANS = "hosting.view_hostingplan"
|
|
VIEW_RESELLERS = "hosting.view_reseller"
|
|
VIEW_CUSTOMERS = "hosting.view_customer"
|
|
VIEW_DATABASES = "hosting.view_hostingdatabase"
|
|
VIEW_DNS_ZONES = "hosting.view_hostingdnszone"
|
|
VIEW_MAILBOXES = "hosting.view_hostingmailbox"
|
|
MEASURE_SITE_STORAGE = (VIEW_ACCOUNTS, "hosting.add_sitestorageusage")
|
|
CHANGE_SITE_STORAGE_LIMIT = (VIEW_ACCOUNTS, "hosting.change_sitestoragelimit")
|
|
EXPORT_BACKUP_MANIFEST = (VIEW_ACCOUNTS, VIEW_PLANS, VIEW_DATABASES)
|
|
EXPORT_MAIL_BACKUP_MANIFEST = (*EXPORT_BACKUP_MANIFEST, VIEW_MAILBOXES)
|
|
MANAGE_ACCOUNT_BACKUPS = (
|
|
*EXPORT_BACKUP_MANIFEST,
|
|
"hosting.add_accountbackupjob",
|
|
)
|
|
MANAGE_BACKUP_SCHEDULE = (
|
|
*MANAGE_ACCOUNT_BACKUPS,
|
|
"hosting.change_accountbackupschedule",
|
|
)
|
|
RESTORE_WEBSITE = (*MANAGE_ACCOUNT_BACKUPS, "hosting.add_websiterestorejob")
|
|
ACTIVATE_WEB = (VIEW_ACCOUNTS, VIEW_PLANS, "hosting.add_webactivation")
|
|
ENABLE_WEB_HTTPS = (VIEW_ACCOUNTS, VIEW_PLANS, "hosting.add_webhttps")
|
|
PROVISION_DATABASE = (
|
|
VIEW_ACCOUNTS,
|
|
VIEW_DATABASES,
|
|
"hosting.add_databaseprovisioning",
|
|
)
|
|
PUBLISH_DNS = (VIEW_ACCOUNTS, VIEW_DNS_ZONES, "hosting.add_dnspublication")
|
|
PROVISION_MAILBOX = (
|
|
VIEW_ACCOUNTS,
|
|
VIEW_MAILBOXES,
|
|
"hosting.add_mailboxprovisioning",
|
|
)
|
|
CHANGE_MAILBOX_QUOTA = (*PROVISION_MAILBOX, "hosting.change_hostingmailbox")
|
|
|
|
|
|
class AccountList(TenantScopeMixin, PermissionRequiredMixin, ListView):
|
|
queryset = HostingAccount.objects.select_related("hosting_plan").order_by(
|
|
"primary_domain"
|
|
)
|
|
permission_required = VIEW_ACCOUNTS
|
|
template_name = "hosting/account_list.html"
|
|
context_object_name = "accounts"
|
|
paginate_by = 20
|
|
customer_relation = "customer"
|
|
|
|
def get_queryset(self):
|
|
self.search = self.request.GET.get("q", "").strip()[:253]
|
|
accounts = super().get_queryset()
|
|
if self.search:
|
|
accounts = accounts.filter(
|
|
Q(name__icontains=self.search)
|
|
| Q(primary_domain__icontains=self.search)
|
|
)
|
|
return accounts
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(search=self.search, **kwargs)
|
|
reseller = reseller_for_user(self.request.user)
|
|
if reseller is not None and reseller.may_create_accounts():
|
|
context["account_allowance"] = {
|
|
"used": reseller.hostingaccount_set.count(),
|
|
"limit": reseller.account_limit,
|
|
}
|
|
return context
|
|
|
|
|
|
class AccountEditor:
|
|
model = HostingAccount
|
|
template_name = "hosting/account_form.html"
|
|
|
|
def get_form_class(self):
|
|
self.fields = ("name", "primary_domain")
|
|
reseller = reseller_for_user(self.request.user)
|
|
if reseller is not None or self.request.user.has_perm(
|
|
VIEW_HOSTING_PLANS
|
|
):
|
|
self.fields += ("hosting_plan",)
|
|
if reseller is None and self.request.user.has_perm(VIEW_RESELLERS):
|
|
self.fields += ("reseller",)
|
|
if reseller is None and self.request.user.has_perm(VIEW_CUSTOMERS):
|
|
self.fields += ("customer",)
|
|
return super().get_form_class()
|
|
|
|
def get_form(self, form_class=None):
|
|
form = super().get_form(form_class)
|
|
if "hosting_plan" in form.fields:
|
|
field = form.fields["hosting_plan"]
|
|
reseller = reseller_for_user(self.request.user)
|
|
if reseller is None:
|
|
field.empty_label = "Unassigned"
|
|
else:
|
|
field.queryset = reseller.hosting_plans.all()
|
|
field.required = True
|
|
field.empty_label = "Select a hosting plan"
|
|
for name in ("reseller", "customer"):
|
|
if name in form.fields:
|
|
field = form.fields[name]
|
|
field.empty_label = "Unassigned"
|
|
field.queryset = field.queryset.select_related(
|
|
"user"
|
|
).order_by("user__username")
|
|
return form
|
|
|
|
|
|
class AccountCreate(PermissionRequiredMixin, AccountEditor, CreateView):
|
|
permission_required = (VIEW_ACCOUNTS, "hosting.add_hostingaccount")
|
|
extra_context = {
|
|
"page_title": "Add hosting account",
|
|
"submit_label": "Add account",
|
|
}
|
|
|
|
def has_permission(self):
|
|
if customer_for_user(self.request.user) is not None:
|
|
return False
|
|
reseller = reseller_for_user(self.request.user)
|
|
if reseller is not None:
|
|
return reseller.may_create_accounts()
|
|
return super().has_permission()
|
|
|
|
def form_valid(self, form):
|
|
reseller = reseller_for_user(self.request.user)
|
|
if reseller is None:
|
|
return super().form_valid(form)
|
|
|
|
self.object = form.save(commit=False)
|
|
try:
|
|
create_reseller_account(reseller, self.object)
|
|
except ValidationError as error:
|
|
form.add_error(None, error)
|
|
return self.form_invalid(form)
|
|
except IntegrityError:
|
|
if not HostingAccount.objects.filter(
|
|
primary_domain=self.object.primary_domain
|
|
).exists():
|
|
raise
|
|
form.add_error("primary_domain", "This domain is unavailable.")
|
|
return self.form_invalid(form)
|
|
return redirect(self.object)
|
|
|
|
|
|
class AccountEdit(
|
|
OperatorOnlyMixin, PermissionRequiredMixin, AccountEditor, UpdateView
|
|
):
|
|
permission_required = (VIEW_ACCOUNTS, CHANGE_ACCOUNTS)
|
|
context_object_name = "account"
|
|
extra_context = {
|
|
"page_title": "Edit hosting account",
|
|
"submit_label": "Save changes",
|
|
}
|
|
|
|
def form_valid(self, form):
|
|
self.object = form.save(commit=False)
|
|
self.object.save(update_fields=form.changed_data)
|
|
return redirect(self.object)
|
|
|
|
|
|
class AccountDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView):
|
|
queryset = HostingAccount.objects.select_related(
|
|
"hosting_plan", "reseller__user", "customer__user"
|
|
)
|
|
permission_required = VIEW_ACCOUNTS
|
|
template_name = "hosting/account_detail.html"
|
|
context_object_name = "account"
|
|
customer_relation = "customer"
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
user = self.request.user
|
|
reseller = reseller_for_user(user)
|
|
customer = customer_for_user(user)
|
|
tenant = reseller is not None or customer is not None
|
|
storage = getattr(self.object, "storage_usage", None)
|
|
if (
|
|
storage is not None
|
|
and storage.domain == self.object.primary_domain
|
|
):
|
|
context["website_storage"] = storage
|
|
context["can_measure_site_storage"] = (
|
|
settings.LOCAL_WEB_ACTIVATION
|
|
and not tenant
|
|
and user.has_perms(MEASURE_SITE_STORAGE)
|
|
)
|
|
context["website_storage_pending"] = (
|
|
storage is not None and storage.finished_at is None
|
|
)
|
|
quota = getattr(self.object, "storage_limit", None)
|
|
if quota is not None and quota.domain == self.object.primary_domain:
|
|
context["website_limit"] = quota
|
|
context["can_change_site_storage_limit"] = (
|
|
settings.LOCAL_WEB_ACTIVATION
|
|
and not tenant
|
|
and user.has_perms(CHANGE_SITE_STORAGE_LIMIT)
|
|
)
|
|
context["website_limit_pending"] = (
|
|
quota is not None and quota.finished_at is None
|
|
)
|
|
context["export_backup_manifest"] = not tenant and user.has_perms(
|
|
EXPORT_BACKUP_MANIFEST
|
|
)
|
|
context["export_mail_backup_manifest"] = context[
|
|
"export_backup_manifest"
|
|
] and user.has_perm(VIEW_MAILBOXES)
|
|
if (
|
|
settings.LOCAL_ACCOUNT_BACKUPS
|
|
and not tenant
|
|
and user.has_perms(MANAGE_ACCOUNT_BACKUPS)
|
|
):
|
|
jobs = list(
|
|
self.object.backup_jobs.order_by("-requested_at", "-pk")[:10]
|
|
)
|
|
can_view_mailboxes = user.has_perm(VIEW_MAILBOXES)
|
|
context["show_account_backups"] = True
|
|
visible_jobs = (
|
|
jobs
|
|
if can_view_mailboxes
|
|
else [job for job in jobs if not job.includes_mailboxes]
|
|
)
|
|
context["account_backup_jobs"] = visible_jobs
|
|
if user.has_perm("hosting.add_websiterestorejob"):
|
|
if settings.LOCAL_WEBSITE_RESTORE:
|
|
site = WebSite(self.object.pk, self.object.primary_domain)
|
|
context["website_restore_sources"] = {
|
|
job.pk
|
|
for job in visible_jobs
|
|
if job.can_restore_website(site)
|
|
}
|
|
restores = WebsiteRestoreJob.objects.filter(
|
|
backup__account=self.object
|
|
).select_related("backup")
|
|
if not can_view_mailboxes:
|
|
restores = restores.exclude(
|
|
backup__manifest__has_key="mailboxes"
|
|
)
|
|
context["website_restore_jobs"] = restores.order_by(
|
|
"-requested_at", "-pk"
|
|
)[:10]
|
|
pending = next(
|
|
(job for job in jobs if job.finished_at is None), None
|
|
)
|
|
context["account_backup_pending"] = pending is not None
|
|
context["account_backup_pending_hidden"] = (
|
|
pending is not None and pending not in visible_jobs
|
|
)
|
|
context["account_backup_allow_mail"] = (
|
|
settings.LOCAL_ACCOUNT_BACKUP_MAIL and can_view_mailboxes
|
|
)
|
|
schedule = getattr(self.object, "backup_schedule", None)
|
|
if (
|
|
schedule is None
|
|
or not schedule.include_mailboxes
|
|
or can_view_mailboxes
|
|
):
|
|
context["account_backup_schedule"] = schedule
|
|
context["edit_account_backup_schedule"] = user.has_perms(
|
|
MANAGE_BACKUP_SCHEDULE
|
|
)
|
|
context["manage_sftp"] = (
|
|
settings.LOCAL_WEB_SFTP
|
|
and can_manage_sftp(user)
|
|
and (site_is_active(self.object) or hasattr(self.object, "sftp"))
|
|
)
|
|
if reseller is not None or (
|
|
customer is None and user.has_perm(VIEW_PLANS)
|
|
):
|
|
context["plans"] = self.object.webprovisioningplan_set.order_by(
|
|
"-requested_at", "-pk"
|
|
)[:10]
|
|
if tenant or user.has_perm(VIEW_DATABASES):
|
|
databases = self.object.databases.all()
|
|
if not tenant and user.has_perms(PROVISION_DATABASE):
|
|
databases = databases.select_related("provisioning")
|
|
context["manage_database_provisioning"] = True
|
|
context["local_database_enabled"] = (
|
|
settings.LOCAL_DATABASE_PROVISIONING
|
|
)
|
|
context["databases"] = databases
|
|
if tenant or user.has_perm(VIEW_DNS_ZONES):
|
|
zone_list = self.object.dns_zones.all()
|
|
if not tenant and user.has_perms(PUBLISH_DNS):
|
|
zone_list = zone_list.select_related("publication").defer(
|
|
"publication__manifest"
|
|
)
|
|
context["manage_dns_publishing"] = True
|
|
context["local_dns_enabled"] = settings.LOCAL_DNS_PUBLISHING
|
|
zones = list(zone_list)
|
|
context["dns_zones"] = zones
|
|
context["has_primary_zone"] = any(
|
|
zone.domain == self.object.primary_domain for zone in zones
|
|
)
|
|
if tenant or user.has_perm(VIEW_MAILBOXES):
|
|
mailboxes = HostingMailbox.objects.filter(
|
|
mail_domain__account=self.object
|
|
).select_related("mail_domain")
|
|
if not tenant and user.has_perms(PROVISION_MAILBOX):
|
|
mailboxes = mailboxes.select_related("provisioning")
|
|
context["manage_mailbox_provisioning"] = True
|
|
context["local_mailbox_enabled"] = (
|
|
settings.LOCAL_MAILBOX_PROVISIONING
|
|
)
|
|
context["change_mailbox_quota"] = user.has_perms(
|
|
CHANGE_MAILBOX_QUOTA
|
|
)
|
|
context["mailboxes"] = mailboxes
|
|
return context
|
|
|
|
|
|
class SiteStorageLimitEdit(
|
|
OperatorOnlyMixin, PermissionRequiredMixin, FormView
|
|
):
|
|
permission_required = CHANGE_SITE_STORAGE_LIMIT
|
|
form_class = SiteStorageLimitForm
|
|
template_name = "hosting/site_storage_limit_form.html"
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
if not settings.LOCAL_WEB_ACTIVATION:
|
|
raise Http404
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
@cached_property
|
|
def account(self):
|
|
return get_object_or_404(
|
|
HostingAccount.objects.select_related(
|
|
"hosting_plan", "storage_limit"
|
|
),
|
|
pk=self.kwargs["pk"],
|
|
)
|
|
|
|
def get_initial(self):
|
|
initial = super().get_initial()
|
|
current = getattr(self.account, "storage_limit", None)
|
|
if (
|
|
current is not None
|
|
and current.domain == self.account.primary_domain
|
|
):
|
|
initial["limit_mib"] = current.limit_mib
|
|
elif self.account.hosting_plan is not None:
|
|
initial["limit_mib"] = (
|
|
self.account.hosting_plan.website_storage_limit_mib
|
|
)
|
|
return initial
|
|
|
|
def get_context_data(self, **kwargs):
|
|
return super().get_context_data(account=self.account, **kwargs)
|
|
|
|
def form_valid(self, form):
|
|
try:
|
|
queue_site_storage_limit(
|
|
self.account.pk, form.cleaned_data["limit_mib"]
|
|
)
|
|
except ValidationError as error:
|
|
form.add_error(None, error)
|
|
return self.form_invalid(form)
|
|
return redirect(self.account)
|
|
|
|
|
|
class RequestSiteStorageMeasurement(
|
|
OperatorOnlyMixin, PermissionRequiredMixin, View
|
|
):
|
|
permission_required = MEASURE_SITE_STORAGE
|
|
|
|
def post(self, request, pk):
|
|
if not settings.LOCAL_WEB_ACTIVATION:
|
|
raise Http404
|
|
try:
|
|
queue_site_storage_measurement(pk)
|
|
except HostingAccount.DoesNotExist:
|
|
raise Http404 from None
|
|
return redirect("panel:account", pk=pk)
|
|
|
|
|
|
class DownloadAccountBackupManifest(
|
|
OperatorOnlyMixin, PermissionRequiredMixin, View
|
|
):
|
|
permission_required = EXPORT_BACKUP_MANIFEST
|
|
|
|
@property
|
|
def include_mailboxes(self):
|
|
return self.request.GET.get("include_mail") == "1"
|
|
|
|
def get_permission_required(self):
|
|
if self.include_mailboxes:
|
|
return EXPORT_MAIL_BACKUP_MANIFEST
|
|
return super().get_permission_required()
|
|
|
|
def get(self, request, pk):
|
|
account = get_object_or_404(HostingAccount, pk=pk)
|
|
suffix = "backup-with-mail" if self.include_mailboxes else "backup"
|
|
return JsonResponse(
|
|
account_backup_manifest(
|
|
account, include_mailboxes=self.include_mailboxes
|
|
),
|
|
headers={
|
|
"Cache-Control": "private, no-store",
|
|
"Content-Disposition": (
|
|
"attachment; "
|
|
f'filename="coulobre-account-{account.pk}-{suffix}.json"'
|
|
),
|
|
},
|
|
)
|
|
|
|
|
|
class RequestAccountBackup(OperatorOnlyMixin, PermissionRequiredMixin, View):
|
|
permission_required = MANAGE_ACCOUNT_BACKUPS
|
|
|
|
def post(self, request, pk):
|
|
if not settings.LOCAL_ACCOUNT_BACKUPS:
|
|
raise Http404
|
|
include_mailboxes = request.POST.get("include_mail") == "1"
|
|
if include_mailboxes:
|
|
if not settings.LOCAL_ACCOUNT_BACKUP_MAIL:
|
|
raise Http404
|
|
if not request.user.has_perm(VIEW_MAILBOXES):
|
|
return self.handle_no_permission()
|
|
try:
|
|
queue_account_backup(pk, include_mailboxes=include_mailboxes)
|
|
except HostingAccount.DoesNotExist:
|
|
raise Http404 from None
|
|
return redirect("panel:account", pk=pk)
|
|
|
|
|
|
class RequestWebsiteRestore(
|
|
OperatorOnlyMixin, PermissionRequiredMixin, FormView
|
|
):
|
|
permission_required = RESTORE_WEBSITE
|
|
form_class = WebsiteRestoreForm
|
|
template_name = "hosting/website_restore.html"
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
if not (
|
|
settings.LOCAL_ACCOUNT_BACKUPS and settings.LOCAL_WEBSITE_RESTORE
|
|
):
|
|
raise Http404
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
@cached_property
|
|
def backup(self):
|
|
backup = get_object_or_404(
|
|
AccountBackupJob.objects.select_related("account"),
|
|
pk=self.kwargs["backup_pk"],
|
|
account_id=self.kwargs["pk"],
|
|
)
|
|
site = WebSite(backup.account_id, backup.account.primary_domain)
|
|
if not backup.can_restore_website(site):
|
|
raise Http404
|
|
if backup.includes_mailboxes and not self.request.user.has_perm(
|
|
VIEW_MAILBOXES
|
|
):
|
|
raise Http404
|
|
return backup
|
|
|
|
def get_context_data(self, **kwargs):
|
|
return super().get_context_data(
|
|
account=self.backup.account, backup=self.backup, **kwargs
|
|
)
|
|
|
|
def form_valid(self, form):
|
|
try:
|
|
queue_website_restore(
|
|
self.backup,
|
|
restore_id=form.cleaned_data["restore_id"],
|
|
filename=form.cleaned_data["filename"],
|
|
replace=form.cleaned_data["replace"],
|
|
operator_username=self.request.user.get_username(),
|
|
)
|
|
except HostingAccount.DoesNotExist:
|
|
raise Http404 from None
|
|
except ValidationError as error:
|
|
form.add_error(None, error)
|
|
return self.form_invalid(form)
|
|
return redirect(self.backup.account)
|
|
|
|
|
|
class EditAccountBackupSchedule(
|
|
OperatorOnlyMixin, PermissionRequiredMixin, FormView
|
|
):
|
|
permission_required = MANAGE_BACKUP_SCHEDULE
|
|
form_class = AccountBackupScheduleForm
|
|
template_name = "hosting/account_backup_schedule.html"
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
if not settings.LOCAL_ACCOUNT_BACKUPS:
|
|
raise Http404
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
@cached_property
|
|
def account(self):
|
|
return get_object_or_404(HostingAccount, pk=self.kwargs["pk"])
|
|
|
|
def get_initial(self):
|
|
schedule = getattr(self.account, "backup_schedule", None)
|
|
if schedule is None:
|
|
return {
|
|
"enabled": True,
|
|
"frequency": AccountBackupSchedule.Frequency.DAILY,
|
|
}
|
|
if schedule.include_mailboxes and not self.request.user.has_perm(
|
|
VIEW_MAILBOXES
|
|
):
|
|
raise PermissionDenied
|
|
return {field: getattr(schedule, field) for field in SCHEDULE_FIELDS}
|
|
|
|
def get_form_kwargs(self):
|
|
kwargs = super().get_form_kwargs()
|
|
kwargs["allow_mail"] = (
|
|
settings.LOCAL_ACCOUNT_BACKUP_MAIL
|
|
and self.request.user.has_perm(VIEW_MAILBOXES)
|
|
)
|
|
return kwargs
|
|
|
|
def get_context_data(self, **kwargs):
|
|
return super().get_context_data(account=self.account, **kwargs)
|
|
|
|
def form_valid(self, form):
|
|
try:
|
|
save_backup_schedule(
|
|
self.account.pk,
|
|
can_manage_mail=self.request.user.has_perm(VIEW_MAILBOXES),
|
|
schedule_fields=form.cleaned_data,
|
|
)
|
|
except HostingAccount.DoesNotExist:
|
|
raise Http404 from None
|
|
return super().form_valid(form)
|
|
|
|
def get_success_url(self):
|
|
return self.account.get_absolute_url()
|
|
|
|
|
|
class SiteSFTPKeys(PermissionRequiredMixin, FormView):
|
|
form_class = SFTPKeyUploadForm
|
|
template_name = "hosting/sftp_keys.html"
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
if not settings.LOCAL_WEB_SFTP:
|
|
raise Http404
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
def has_permission(self):
|
|
return can_manage_sftp(self.request.user)
|
|
|
|
@cached_property
|
|
def account(self):
|
|
accounts = HostingAccount.objects.select_related("sftp")
|
|
customer = customer_for_user(self.request.user)
|
|
if customer is not None:
|
|
accounts = accounts.filter(customer=customer)
|
|
return get_object_or_404(accounts, pk=self.kwargs["pk"])
|
|
|
|
def get_context_data(self, **kwargs):
|
|
status = getattr(self.account, "sftp", None)
|
|
editable = getattr(self.request, "impersonation", None) is None
|
|
idle = status is None or status.finished_at is not None
|
|
keys = () if status is None else status.public_keys.splitlines()
|
|
return super().get_context_data(
|
|
account=self.account,
|
|
ssh_keys=[
|
|
(key.split(" ", 1)[0], public_key_fingerprint(key))
|
|
for key in keys
|
|
],
|
|
can_edit_keys=editable and idle and site_is_active(self.account),
|
|
can_revoke_keys=editable
|
|
and idle
|
|
and status is not None
|
|
and bool(status.public_keys or status.problem),
|
|
**kwargs,
|
|
)
|
|
|
|
def get_success_url(self):
|
|
return reverse("panel:sftp_keys", args=[self.account.pk])
|
|
|
|
def form_valid(self, form):
|
|
customer = customer_for_user(self.request.user)
|
|
try:
|
|
queue_sftp_keys(
|
|
self.account.pk,
|
|
form.cleaned_data["operation"],
|
|
public_keys=form.cleaned_data["public_keys"],
|
|
fingerprint=form.cleaned_data["fingerprint"],
|
|
customer_id=customer.pk if customer is not None else None,
|
|
)
|
|
except HostingAccount.DoesNotExist as error:
|
|
raise Http404 from error
|
|
except ValidationError as error:
|
|
form.add_error(None, error)
|
|
return self.render_to_response(
|
|
self.get_context_data(form=form), status=409
|
|
)
|
|
return super().form_valid(form)
|
|
|
|
|
|
class CustomerList(OperatorOnlyMixin, PermissionRequiredMixin, ListView):
|
|
queryset = Customer.objects.select_related(
|
|
"user__hosting_reseller"
|
|
).order_by("user__username")
|
|
permission_required = VIEW_CUSTOMERS
|
|
template_name = "hosting/customer_list.html"
|
|
context_object_name = "customers"
|
|
paginate_by = 20
|
|
|
|
def get_queryset(self):
|
|
self.search = self.request.GET.get("q", "").strip()[:150]
|
|
queryset = super().get_queryset()
|
|
if self.search:
|
|
queryset = queryset.filter(user__username__icontains=self.search)
|
|
return queryset
|
|
|
|
def get_context_data(self, **kwargs):
|
|
return super().get_context_data(
|
|
search=self.search,
|
|
can_impersonate=can_impersonate_customer(self.request.user),
|
|
**kwargs,
|
|
)
|
|
|
|
|
|
@method_decorator(
|
|
sensitive_post_parameters("password1", "password2"), name="dispatch"
|
|
)
|
|
class CustomerCreate(OperatorOnlyMixin, PermissionRequiredMixin, FormView):
|
|
permission_required = (VIEW_CUSTOMERS, "hosting.add_customer")
|
|
form_class = UserCreationForm
|
|
template_name = "hosting/customer_form.html"
|
|
success_url = reverse_lazy("panel:customers")
|
|
|
|
def form_valid(self, form):
|
|
try:
|
|
with transaction.atomic():
|
|
Customer.objects.create(user=form.save())
|
|
except IntegrityError:
|
|
user = form.instance
|
|
users = get_user_model().objects
|
|
if not users.filter(username__iexact=user.username).exists():
|
|
raise
|
|
form.add_error(
|
|
"username", user.unique_error_message(type(user), ["username"])
|
|
)
|
|
return self.form_invalid(form)
|
|
return super().form_valid(form)
|
|
|
|
|
|
class CustomerAccess(OperatorOnlyMixin, PermissionRequiredMixin, View):
|
|
permission_required = (VIEW_CUSTOMERS, "hosting.change_customer")
|
|
|
|
def post(self, request, pk):
|
|
access = request.POST.get("access")
|
|
if access not in ("restore", "suspend"):
|
|
return HttpResponseBadRequest(
|
|
"Choose whether to restore or suspend sign-in."
|
|
)
|
|
customer = Customer.objects.filter(pk=pk).values("user_id")
|
|
resellers = Reseller.objects.values("user_id")
|
|
users = (
|
|
get_user_model()
|
|
.objects.filter(
|
|
pk__in=customer, is_staff=False, is_superuser=False
|
|
)
|
|
.exclude(pk__in=resellers)
|
|
)
|
|
if not users.update(is_active=access == "restore"):
|
|
raise Http404
|
|
return redirect(reverse("panel:customers", query=request.GET))
|
|
|
|
|
|
class CustomerImpersonationStart(PermissionRequiredMixin, View):
|
|
def has_permission(self):
|
|
return can_impersonate_customer(self.request.user)
|
|
|
|
def post(self, request, pk):
|
|
customers = Customer.objects.select_related("user__hosting_reseller")
|
|
customer = get_object_or_404(customers, pk=pk)
|
|
if not customer.may_be_impersonated:
|
|
raise Http404
|
|
start_impersonation(request, customer)
|
|
return redirect("panel:accounts")
|
|
|
|
|
|
class CustomerImpersonationStop(View):
|
|
def post(self, request):
|
|
session = getattr(request, "impersonation", None)
|
|
if session is not None:
|
|
end_impersonation(request, session, EndReason.STOPPED)
|
|
return redirect("panel:customers")
|
|
return redirect("panel:accounts")
|
|
|
|
|
|
class ResourceRequestCreate(PermissionRequiredMixin, CreateView):
|
|
@cached_property
|
|
def customer(self):
|
|
return customer_for_user(self.request.user)
|
|
|
|
def has_permission(self):
|
|
return self.customer is not None or (
|
|
reseller_for_user(self.request.user) is None
|
|
and super().has_permission()
|
|
)
|
|
|
|
@cached_property
|
|
def account(self):
|
|
accounts = HostingAccount.objects.all()
|
|
if self.customer is not None:
|
|
accounts = accounts.filter(customer=self.customer)
|
|
return get_object_or_404(accounts, pk=self.kwargs["pk"])
|
|
|
|
def get_context_data(self, **kwargs):
|
|
return super().get_context_data(account=self.account, **kwargs)
|
|
|
|
def get_form(self, form_class=None):
|
|
form = super().get_form(form_class)
|
|
if getattr(self.request, "impersonation", None) is not None:
|
|
for field in form.fields.values():
|
|
field.disabled = True
|
|
return form
|
|
|
|
def form_valid(self, form):
|
|
try:
|
|
self.object = self.create_request(
|
|
self.account.pk,
|
|
**form.cleaned_data,
|
|
customer_id=self.customer.pk
|
|
if self.customer is not None
|
|
else None,
|
|
)
|
|
except HostingAccount.DoesNotExist as error:
|
|
raise Http404 from error
|
|
except ValidationError as error:
|
|
form.add_error(None, error)
|
|
return self.form_invalid(form)
|
|
return redirect(self.account)
|
|
|
|
|
|
class DatabaseCreate(ResourceRequestCreate):
|
|
model = HostingDatabase
|
|
fields = ("suffix",)
|
|
template_name = "hosting/database_form.html"
|
|
permission_required = (
|
|
VIEW_ACCOUNTS,
|
|
VIEW_DATABASES,
|
|
"hosting.add_hostingdatabase",
|
|
)
|
|
create_request = staticmethod(create_database_request)
|
|
|
|
|
|
class DownloadDatabaseManifest(
|
|
OperatorOnlyMixin, PermissionRequiredMixin, View
|
|
):
|
|
permission_required = (VIEW_ACCOUNTS, VIEW_DATABASES)
|
|
|
|
def get(self, request, pk):
|
|
database = get_object_or_404(HostingDatabase, pk=pk)
|
|
return JsonResponse(
|
|
database.spec.manifest(),
|
|
headers={
|
|
"Cache-Control": "private, no-store",
|
|
"Content-Disposition": (
|
|
"attachment; "
|
|
f'filename="coulobre-database-{database.pk}.json"'
|
|
),
|
|
},
|
|
)
|
|
|
|
|
|
class RequestDatabaseProvisioning(
|
|
OperatorOnlyMixin, PermissionRequiredMixin, View
|
|
):
|
|
permission_required = PROVISION_DATABASE
|
|
|
|
def post(self, request, pk):
|
|
if not settings.LOCAL_DATABASE_PROVISIONING:
|
|
raise Http404
|
|
database = get_object_or_404(
|
|
HostingDatabase.objects.select_related("account"), pk=pk
|
|
)
|
|
DatabaseProvisioning.objects.queue(database=database)
|
|
return redirect(database.account)
|
|
|
|
|
|
class DnsZoneEditor(OperatorOnlyMixin, PermissionRequiredMixin, FormView):
|
|
template_name = "hosting/dns_zone_form.html"
|
|
|
|
def get_form_kwargs(self):
|
|
return {**super().get_form_kwargs(), "domain": self.domain}
|
|
|
|
def get_context_data(self, **kwargs):
|
|
return super().get_context_data(
|
|
account=self.account, domain=self.domain, **kwargs
|
|
)
|
|
|
|
def get_success_url(self):
|
|
return self.account.get_absolute_url()
|
|
|
|
|
|
class DnsZoneCreate(DnsZoneEditor):
|
|
form_class = DnsZoneForm
|
|
permission_required = (
|
|
VIEW_ACCOUNTS,
|
|
VIEW_DNS_ZONES,
|
|
"hosting.add_hostingdnszone",
|
|
)
|
|
extra_context = {"page_title": "Add DNS zone"}
|
|
|
|
@cached_property
|
|
def account(self):
|
|
return get_object_or_404(HostingAccount, pk=self.kwargs["pk"])
|
|
|
|
@property
|
|
def domain(self):
|
|
return self.account.primary_domain
|
|
|
|
def get_initial(self):
|
|
return {"responsible_name": f"hostmaster.{self.domain}"}
|
|
|
|
def form_valid(self, form):
|
|
try:
|
|
with transaction.atomic():
|
|
HostingDnsZone.objects.create(
|
|
account=self.account,
|
|
domain=self.domain,
|
|
**form.cleaned_data,
|
|
)
|
|
except IntegrityError:
|
|
if not HostingDnsZone.objects.filter(domain=self.domain).exists():
|
|
raise
|
|
form.add_error(None, "A DNS zone already exists for this domain.")
|
|
return self.form_invalid(form)
|
|
return super().form_valid(form)
|
|
|
|
|
|
class DnsZoneEdit(DnsZoneEditor):
|
|
form_class = DnsZoneEditForm
|
|
permission_required = (
|
|
VIEW_ACCOUNTS,
|
|
VIEW_DNS_ZONES,
|
|
"hosting.change_hostingdnszone",
|
|
)
|
|
extra_context = {"page_title": "Edit DNS zone"}
|
|
|
|
@cached_property
|
|
def zone(self):
|
|
return get_object_or_404(
|
|
HostingDnsZone.objects.select_related("account"),
|
|
pk=self.kwargs["pk"],
|
|
)
|
|
|
|
@property
|
|
def account(self):
|
|
return self.zone.account
|
|
|
|
@property
|
|
def domain(self):
|
|
return self.zone.domain
|
|
|
|
def get_initial(self):
|
|
return {
|
|
"serial": self.zone.serial,
|
|
"nameservers": "\n".join(self.zone.nameservers),
|
|
"responsible_name": self.zone.responsible_name,
|
|
"addresses": "\n".join(
|
|
f"{record['name']} {record['address']}"
|
|
for record in self.zone.addresses
|
|
),
|
|
"mx_records": "\n".join(
|
|
f"{record['name']} {record['priority']} {record['exchange']}"
|
|
for record in self.zone.mx_records
|
|
),
|
|
"txt_records": "\n".join(
|
|
format_txt_record(record) for record in self.zone.txt_records
|
|
),
|
|
}
|
|
|
|
def form_valid(self, form):
|
|
values = form.cleaned_data
|
|
serial = values["serial"]
|
|
if all(
|
|
getattr(self.zone, field) == value
|
|
for field, value in values.items()
|
|
):
|
|
return super().form_valid(form)
|
|
|
|
next_serial = (serial + 1) % (MAX_SOA_SERIAL + 1)
|
|
updated = HostingDnsZone.objects.filter(
|
|
pk=self.zone.pk, serial=serial
|
|
).update(**(values | {"serial": next_serial}))
|
|
if not updated:
|
|
form.add_error(
|
|
None,
|
|
"This DNS zone changed while you were editing it. "
|
|
"Reopen the form and try again.",
|
|
)
|
|
return self.form_invalid(form)
|
|
return super().form_valid(form)
|
|
|
|
|
|
class DownloadDnsZoneManifest(
|
|
OperatorOnlyMixin, PermissionRequiredMixin, View
|
|
):
|
|
permission_required = (VIEW_ACCOUNTS, VIEW_DNS_ZONES)
|
|
|
|
def get(self, request, pk):
|
|
zone = get_object_or_404(HostingDnsZone, pk=pk)
|
|
return JsonResponse(
|
|
zone.spec.manifest(),
|
|
headers={
|
|
"Cache-Control": "private, no-store",
|
|
"Content-Disposition": (
|
|
f'attachment; filename="coulobre-zone-{zone.pk}.json"'
|
|
),
|
|
},
|
|
)
|
|
|
|
|
|
class RequestDnsPublication(OperatorOnlyMixin, PermissionRequiredMixin, View):
|
|
permission_required = PUBLISH_DNS
|
|
|
|
def post(self, request, pk):
|
|
if not settings.LOCAL_DNS_PUBLISHING:
|
|
raise Http404
|
|
try:
|
|
zone = queue_dns_publication(pk, request.POST.get("serial"))
|
|
except HostingDnsZone.DoesNotExist as error:
|
|
raise Http404 from error
|
|
except ValueError as error:
|
|
return HttpResponse(
|
|
str(error), status=409, content_type="text/plain"
|
|
)
|
|
return redirect(zone.account)
|
|
|
|
|
|
class MailboxCreate(ResourceRequestCreate):
|
|
model = HostingMailbox
|
|
fields = ("local_part",)
|
|
template_name = "hosting/mailbox_form.html"
|
|
permission_required = (
|
|
VIEW_ACCOUNTS,
|
|
VIEW_MAILBOXES,
|
|
"hosting.add_hostingmailbox",
|
|
)
|
|
create_request = staticmethod(create_mailbox_request)
|
|
|
|
def get_form(self, form_class=None):
|
|
form = super().get_form(form_class)
|
|
form.fields["local_part"].help_text = INVALID_LOCAL_PART
|
|
return form
|
|
|
|
|
|
class DownloadMailboxManifest(
|
|
OperatorOnlyMixin, PermissionRequiredMixin, View
|
|
):
|
|
permission_required = (VIEW_ACCOUNTS, VIEW_MAILBOXES)
|
|
|
|
def get(self, request, pk):
|
|
mailbox = get_object_or_404(
|
|
HostingMailbox.objects.select_related("mail_domain"), pk=pk
|
|
)
|
|
return JsonResponse(
|
|
mailbox.spec.manifest(),
|
|
headers={
|
|
"Cache-Control": "private, no-store",
|
|
"Content-Disposition": (
|
|
"attachment; "
|
|
f'filename="coulobre-mailbox-{mailbox.pk}.json"'
|
|
),
|
|
},
|
|
)
|
|
|
|
|
|
class MailboxQuotaEdit(OperatorOnlyMixin, PermissionRequiredMixin, UpdateView):
|
|
queryset = HostingMailbox.objects.select_related("mail_domain__account")
|
|
permission_required = CHANGE_MAILBOX_QUOTA
|
|
fields = ("quota_mib",)
|
|
template_name = "hosting/mailbox_quota_form.html"
|
|
context_object_name = "mailbox"
|
|
|
|
def get_form(self, form_class=None):
|
|
form = super().get_form(form_class)
|
|
form.fields[
|
|
"quota_mib"
|
|
].help_text = "Leave blank for unlimited storage."
|
|
return form
|
|
|
|
def form_valid(self, form):
|
|
try:
|
|
change_mailbox_quota(self.object, form.cleaned_data["quota_mib"])
|
|
except ValidationError as error:
|
|
form.add_error(None, error)
|
|
return self.form_invalid(form)
|
|
return redirect(self.object.mail_domain.account)
|
|
|
|
|
|
class RequestMailboxProvisioning(
|
|
OperatorOnlyMixin, PermissionRequiredMixin, View
|
|
):
|
|
permission_required = PROVISION_MAILBOX
|
|
|
|
def post(self, request, pk):
|
|
if not settings.LOCAL_MAILBOX_PROVISIONING:
|
|
raise Http404
|
|
mailbox = get_object_or_404(
|
|
HostingMailbox.objects.select_related("mail_domain__account"),
|
|
pk=pk,
|
|
)
|
|
queue_mailbox_provisioning(mailbox)
|
|
return redirect(mailbox.mail_domain.account)
|
|
|
|
|
|
class HostingPlanList(OperatorOnlyMixin, PermissionRequiredMixin, ListView):
|
|
model = HostingPlan
|
|
permission_required = VIEW_HOSTING_PLANS
|
|
template_name = "hosting/hosting_plan_list.html"
|
|
context_object_name = "hosting_plans"
|
|
paginate_by = 20
|
|
|
|
|
|
class HostingPlanEditor:
|
|
model = HostingPlan
|
|
fields = (
|
|
"name",
|
|
"description",
|
|
"database_limit",
|
|
"mailbox_limit",
|
|
"mailbox_quota_mib",
|
|
"website_storage_limit_mib",
|
|
)
|
|
template_name = "hosting/hosting_plan_form.html"
|
|
success_url = reverse_lazy("panel:hosting_plans")
|
|
|
|
|
|
class HostingPlanCreate(
|
|
OperatorOnlyMixin, PermissionRequiredMixin, HostingPlanEditor, CreateView
|
|
):
|
|
permission_required = (VIEW_HOSTING_PLANS, "hosting.add_hostingplan")
|
|
extra_context = {
|
|
"page_title": "Add hosting plan",
|
|
"submit_label": "Add plan",
|
|
}
|
|
|
|
|
|
class HostingPlanEdit(
|
|
OperatorOnlyMixin, PermissionRequiredMixin, HostingPlanEditor, UpdateView
|
|
):
|
|
permission_required = (VIEW_HOSTING_PLANS, "hosting.change_hostingplan")
|
|
extra_context = {
|
|
"page_title": "Edit hosting plan",
|
|
"submit_label": "Save changes",
|
|
}
|
|
|
|
def form_valid(self, form):
|
|
self.object = form.save(commit=False)
|
|
self.object.save(update_fields=form.changed_data)
|
|
return redirect(self.get_success_url())
|
|
|
|
|
|
class RequestWebPlan(
|
|
OperatorOnlyMixin, PermissionRequiredMixin, SingleObjectMixin, View
|
|
):
|
|
model = HostingAccount
|
|
permission_required = (VIEW_ACCOUNTS, CHANGE_ACCOUNTS, VIEW_PLANS)
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
plan = WebProvisioningPlan.for_account(self.get_object())
|
|
plan.save()
|
|
return redirect("panel:plan", pk=plan.pk)
|
|
|
|
|
|
class PlanList(TenantScopeMixin, PermissionRequiredMixin, ListView):
|
|
queryset = WebProvisioningPlan.objects.select_related("account").order_by(
|
|
"-requested_at", "-pk"
|
|
)
|
|
permission_required = VIEW_PLANS
|
|
reseller_relation = "account__reseller"
|
|
template_name = "hosting/plan_list.html"
|
|
context_object_name = "plans"
|
|
paginate_by = 20
|
|
|
|
|
|
class PlanDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView):
|
|
queryset = WebProvisioningPlan.objects.select_related(
|
|
"account", "activation", "https"
|
|
)
|
|
permission_required = VIEW_PLANS
|
|
reseller_relation = "account__reseller"
|
|
template_name = "hosting/plan_detail.html"
|
|
context_object_name = "plan"
|
|
|
|
def get_context_data(self, **kwargs):
|
|
user = self.request.user
|
|
return super().get_context_data(
|
|
manage_activation=not is_tenant(user)
|
|
and user.has_perms(ACTIVATE_WEB),
|
|
local_activation_enabled=settings.LOCAL_WEB_ACTIVATION,
|
|
manage_https=not is_tenant(user)
|
|
and user.has_perms(ENABLE_WEB_HTTPS),
|
|
local_https_enabled=settings.LOCAL_WEB_HTTPS,
|
|
**kwargs,
|
|
)
|
|
|
|
|
|
class RequestWebActivation(
|
|
OperatorOnlyMixin, PermissionRequiredMixin, SingleObjectMixin, View
|
|
):
|
|
queryset = WebProvisioningPlan.objects.select_related("account")
|
|
permission_required = ACTIVATE_WEB
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
if not settings.LOCAL_WEB_ACTIVATION:
|
|
raise Http404
|
|
plan = self.get_object()
|
|
if not plan.can_export:
|
|
return HttpResponse(
|
|
"Request a completed Apache preview for the current "
|
|
"account domain.",
|
|
status=409,
|
|
content_type="text/plain",
|
|
)
|
|
WebActivation.objects.queue(plan=plan)
|
|
return redirect("panel:plan", pk=plan.pk)
|
|
|
|
|
|
class RequestWebHTTPS(
|
|
OperatorOnlyMixin, PermissionRequiredMixin, SingleObjectMixin, View
|
|
):
|
|
queryset = WebProvisioningPlan.objects.select_related(
|
|
"account", "activation"
|
|
)
|
|
permission_required = ENABLE_WEB_HTTPS
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
if not settings.LOCAL_WEB_HTTPS:
|
|
raise Http404
|
|
plan = self.get_object()
|
|
if not plan.can_enable_https:
|
|
return HttpResponse(
|
|
"Activate the site for the current domain first.",
|
|
status=409,
|
|
content_type="text/plain",
|
|
)
|
|
WebHTTPS.objects.queue(plan=plan)
|
|
return redirect("panel:plan", pk=plan.pk)
|
|
|
|
|
|
class DownloadWebPlan(OperatorOnlyMixin, PlanDetail):
|
|
manifest = False
|
|
|
|
def render_to_response(self, context, **response_kwargs):
|
|
plan = self.object
|
|
if not plan.can_export:
|
|
return HttpResponse(
|
|
"Request a completed Apache preview for the current "
|
|
"account domain.",
|
|
status=409,
|
|
content_type="text/plain",
|
|
)
|
|
|
|
if self.manifest:
|
|
content = serialize_deployment_manifest(plan)
|
|
extension = "json"
|
|
content_type = "application/json"
|
|
else:
|
|
content = build_web_smoke_bundle(plan)
|
|
extension = "tar"
|
|
content_type = "application/x-tar"
|
|
return HttpResponse(
|
|
content,
|
|
content_type=content_type,
|
|
headers={
|
|
"Cache-Control": "private, no-store",
|
|
"Content-Disposition": (
|
|
"attachment; "
|
|
f'filename="coulobre-web-plan-{plan.pk}.{extension}"'
|
|
),
|
|
},
|
|
)
|