diff --git a/.gitignore b/.gitignore
index d16515a..a3b83a9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,3 +19,4 @@ dist/
*.sqlite3-journal
*.sqlite3-shm
*.sqlite3-wal
+celerybeat-schedule*
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 7167387..d00ab45 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -2,6 +2,8 @@
- Use Gitea issues for work items and milestones for release planning.
- Start changes on a dedicated branch from the default branch, named main.
+- Keep related commits on the same branch and open one pull request when they
+ form a coherent change that can be reviewed and verified together.
- Reference the relevant issue in the pull request and describe what changed and
how it was verified.
- Submit changes for review before merging into main.
diff --git a/README.md b/README.md
index 4e86aa1..97c6f63 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,8 @@
Coulobre Panel is an open-source web hosting control panel for hosting providers
and resellers. The project is in early development.
-The development panel lets an administrator register and find hosting accounts.
+The development panel lets an administrator register hosting accounts and request
+Apache configuration previews through a background worker.
See [Local development](docs/development.md) to run it.
## Planned scope
diff --git a/docs/development.md b/docs/development.md
index a2be3d2..0414b6f 100644
--- a/docs/development.md
+++ b/docs/development.md
@@ -17,12 +17,36 @@ python manage.py runserver
Open
{}", obj.apache_config)
+ return None
+
+ def has_add_permission(self, request):
+ return False
+
+ def has_change_permission(self, request, obj=None):
+ return False
+
+ def has_delete_permission(self, request, obj=None):
+ return False
diff --git a/src/coulobre/hosting/migrations/0002_webprovisioningplan.py b/src/coulobre/hosting/migrations/0002_webprovisioningplan.py
new file mode 100644
index 0000000..f2b218a
--- /dev/null
+++ b/src/coulobre/hosting/migrations/0002_webprovisioningplan.py
@@ -0,0 +1,44 @@
+# Generated by Django 5.2.19 on 2026-11-19 20:12
+
+import django.db.models.deletion
+from django.db import migrations, models
+
+import coulobre.hosting.fields
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("hosting", "0001_initial"),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name="WebProvisioningPlan",
+ fields=[
+ (
+ "id",
+ models.BigAutoField(
+ auto_created=True,
+ primary_key=True,
+ serialize=False,
+ verbose_name="ID",
+ ),
+ ),
+ (
+ "primary_domain",
+ coulobre.hosting.fields.DomainNameField(max_length=253),
+ ),
+ ("requested_at", models.DateTimeField(auto_now_add=True)),
+ ("last_dispatched_at", models.DateTimeField(blank=True, null=True)),
+ ("completed_at", models.DateTimeField(blank=True, null=True)),
+ ("apache_config", models.TextField(blank=True)),
+ (
+ "account",
+ models.ForeignKey(
+ on_delete=django.db.models.deletion.CASCADE,
+ to="hosting.hostingaccount",
+ ),
+ ),
+ ],
+ ),
+ ]
diff --git a/src/coulobre/hosting/models.py b/src/coulobre/hosting/models.py
index a8390cc..6634f7c 100644
--- a/src/coulobre/hosting/models.py
+++ b/src/coulobre/hosting/models.py
@@ -10,3 +10,15 @@ class HostingAccount(models.Model):
def __str__(self):
return str(self.primary_domain)
+
+
+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)
+
+ def __str__(self):
+ return str(self.primary_domain)
diff --git a/src/coulobre/hosting/tasks.py b/src/coulobre/hosting/tasks.py
new file mode 100644
index 0000000..9d902c0
--- /dev/null
+++ b/src/coulobre/hosting/tasks.py
@@ -0,0 +1,43 @@
+from datetime import timedelta
+
+from celery import shared_task
+from django.db.models import Q
+from django.template.loader import render_to_string
+from django.utils import timezone
+
+from .models import WebProvisioningPlan
+
+REDISPATCH_AFTER = timedelta(minutes=5)
+
+
+@shared_task
+def dispatch_web_plans():
+ stale_before = timezone.now() - REDISPATCH_AFTER
+ pending_ids = (
+ WebProvisioningPlan.objects.filter(completed_at__isnull=True)
+ .filter(
+ Q(last_dispatched_at__isnull=True) | Q(last_dispatched_at__lte=stale_before)
+ )
+ .order_by("requested_at", "pk")
+ .values_list("pk", flat=True)[:100]
+ )
+
+ for plan_id in list(pending_ids):
+ render_web_plan.apply_async(args=[plan_id], retry=False)
+ WebProvisioningPlan.objects.filter(
+ pk=plan_id, completed_at__isnull=True
+ ).update(last_dispatched_at=timezone.now())
+
+
+@shared_task(acks_late=True, reject_on_worker_lost=True)
+def render_web_plan(plan_id):
+ pending = WebProvisioningPlan.objects.filter(pk=plan_id, completed_at__isnull=True)
+ plan = pending.first()
+ if plan is None:
+ return
+
+ apache_config = render_to_string(
+ "hosting/apache-vhost.conf",
+ {"account_id": str(plan.account_id), "domain": plan.primary_domain},
+ )
+ pending.update(apache_config=apache_config, completed_at=timezone.now())
diff --git a/src/coulobre/hosting/templates/hosting/apache-vhost.conf b/src/coulobre/hosting/templates/hosting/apache-vhost.conf
new file mode 100644
index 0000000..720a0c1
--- /dev/null
+++ b/src/coulobre/hosting/templates/hosting/apache-vhost.conf
@@ -0,0 +1,14 @@
+<VirtualHost")
+ self.assertContains(response, "ServerName example.org")
+ self.assertEqual(self.client.post(plan_url).status_code, 403)
+
+ @patch("coulobre.hosting.tasks.render_web_plan.apply_async")
+ def test_broker_failure_leaves_request_available_for_dispatch(self, publish):
+ plan = self.create_plan()
+ publish.side_effect = OperationalError("Broker unavailable")
+ with self.assertRaises(OperationalError):
+ dispatch_web_plans.run()
+ plan.refresh_from_db()
+ self.assertIsNone(plan.last_dispatched_at)
+
+ publish.side_effect = None
+ publish.reset_mock()
+ dispatch_web_plans.run()
+ publish.assert_called_once_with(args=[plan.pk], retry=False)
+ plan.refresh_from_db()
+ self.assertIsNotNone(plan.last_dispatched_at)
+
+ @patch("coulobre.hosting.tasks.render_web_plan.apply_async")
+ def test_only_incomplete_stale_deliveries_are_republished(self, publish):
+ now = timezone.now()
+ stale_at = now - REDISPATCH_AFTER - timedelta(seconds=1)
+ stale_plan = self.create_plan()
+ recent_plan = self.create_plan()
+ completed_plan = self.create_plan()
+ WebProvisioningPlan.objects.filter(pk=stale_plan.pk).update(
+ last_dispatched_at=stale_at
+ )
+ WebProvisioningPlan.objects.filter(pk=recent_plan.pk).update(
+ last_dispatched_at=now
+ )
+ WebProvisioningPlan.objects.filter(pk=completed_plan.pk).update(
+ last_dispatched_at=stale_at, completed_at=now
+ )
+
+ dispatch_web_plans.run()
+
+ publish.assert_called_once_with(args=[stale_plan.pk], retry=False)
+
+ def test_duplicate_delivery_preserves_the_completed_preview(self):
+ plan = self.create_plan()
+ render_web_plan.run(plan.pk)
+ plan.refresh_from_db()
+ original = (plan.completed_at, plan.apache_config)
+
+ render_web_plan.run(plan.pk)
+ plan.refresh_from_db()
+
+ self.assertEqual((plan.completed_at, plan.apache_config), original)
diff --git a/src/coulobre/settings.py b/src/coulobre/settings.py
index 7f2bff3..3ed8298 100644
--- a/src/coulobre/settings.py
+++ b/src/coulobre/settings.py
@@ -85,3 +85,17 @@ AUTH_PASSWORD_VALIDATORS = [
TIME_ZONE = "UTC"
STATIC_URL = "/static/"
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
+
+CELERY_BROKER_URL = os.environ.get(
+ "COULOBRE_BROKER_URL", "amqp://guest:guest@127.0.0.1:5672//"
+)
+CELERY_BROKER_TRANSPORT_OPTIONS = {"confirm_publish": True}
+CELERY_TASK_DEFAULT_QUEUE = "coulobre"
+CELERY_TASK_IGNORE_RESULT = True
+CELERY_BEAT_SCHEDULE = {
+ "dispatch-web-provisioning-plans": {
+ "task": "coulobre.hosting.tasks.dispatch_web_plans",
+ "schedule": 5.0,
+ "options": {"expires": 5.0},
+ },
+}