Merge pull request 'Add the initial hosting account and web provisioning workflow' (#2) from feature/hosting-account-foundation into main
Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
commit
a12d428023
41 files changed
+1956
No files matched your search
@@ -19,3 +19,4 @@ dist/
|
|||||||
*.sqlite3-journal
|
*.sqlite3-journal
|
||||||
*.sqlite3-shm
|
*.sqlite3-shm
|
||||||
*.sqlite3-wal
|
*.sqlite3-wal
|
||||||
|
celerybeat-schedule*
|
||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
- Use Gitea issues for work items and milestones for release planning.
|
- Use Gitea issues for work items and milestones for release planning.
|
||||||
- Start changes on a dedicated branch from the default branch, named main.
|
- 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
|
- Reference the relevant issue in the pull request and describe what changed and
|
||||||
how it was verified.
|
how it was verified.
|
||||||
- Submit changes for review before merging into main.
|
- Submit changes for review before merging into main.
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
Coulobre Panel is an open-source web hosting control panel for hosting providers
|
Coulobre Panel is an open-source web hosting control panel for hosting providers
|
||||||
and resellers. The project is in early development.
|
and resellers. The project is in early development.
|
||||||
|
|
||||||
|
The web panel gives operators a workspace to manage hosting accounts, request
|
||||||
|
Apache configuration previews, and follow their progress.
|
||||||
|
See [Local development](docs/development.md) to run it.
|
||||||
|
|
||||||
## Planned scope
|
## Planned scope
|
||||||
|
|
||||||
- Self-hosted installation on a single Ubuntu server, with Debian support planned.
|
- Self-hosted installation on a single Ubuntu server, with Debian support planned.
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
# Local development
|
||||||
|
|
||||||
|
Use Python 3.12 or later. From the repository root, install the panel and its
|
||||||
|
development tools in a virtual environment.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
python3 -m venv .venv
|
||||||
|
. .venv/bin/activate
|
||||||
|
python -m pip install -e '.[dev]'
|
||||||
|
export COULOBRE_SECRET_KEY="$(python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())')"
|
||||||
|
export COULOBRE_DEBUG=1
|
||||||
|
python manage.py migrate
|
||||||
|
python manage.py createsuperuser
|
||||||
|
python manage.py runserver
|
||||||
|
```
|
||||||
|
|
||||||
|
Open <http://127.0.0.1:8000/> and sign in with the administrator account.
|
||||||
|
Select **Add hosting account** and enter a name and a primary domain such as
|
||||||
|
`example.org`. Open an account from the list to edit its details or request an
|
||||||
|
Apache preview. Manage users, groups, and permissions at `/admin/`.
|
||||||
|
|
||||||
|
The local database defaults to `db.sqlite3`. Set `COULOBRE_SQLITE_PATH` to use a
|
||||||
|
different file. Keep `COULOBRE_DEBUG` for local development.
|
||||||
|
|
||||||
|
## Request an Apache configuration preview
|
||||||
|
|
||||||
|
Start RabbitMQ and set `COULOBRE_BROKER_URL` to its AMQP URL. The development
|
||||||
|
default is `amqp://guest:guest@127.0.0.1:5672//`. Use the same database and
|
||||||
|
broker settings for the panel, worker, and scheduler.
|
||||||
|
|
||||||
|
In separate terminals with the virtual environment active, start a worker
|
||||||
|
and a scheduler. Use one worker process with SQLite.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
celery -A coulobre worker --pool=solo
|
||||||
|
celery -A coulobre beat
|
||||||
|
```
|
||||||
|
|
||||||
|
Open an account in **Hosting accounts** and select **Request Apache preview**.
|
||||||
|
The preview page shows the request status and the configuration once the worker
|
||||||
|
finishes. Use **Refresh status** for pending requests or **Web provisioning** to
|
||||||
|
find earlier previews. Each request captures the primary domain at queue time.
|
||||||
|
The preview references the future document root and PHP-FPM socket for the
|
||||||
|
account. Preview generation makes no changes to the hosting services.
|
||||||
|
|
||||||
|
The panel stores requests in its database before the scheduler publishes work
|
||||||
|
to RabbitMQ. After a broker outage, queued requests resume when the worker and
|
||||||
|
scheduler reconnect. Plans that remain incomplete five minutes after dispatch
|
||||||
|
are eligible for delivery again.
|
||||||
|
|
||||||
|
## Run an isolated PHP test site
|
||||||
|
|
||||||
|
Open a completed preview for the account's current domain and select **Download
|
||||||
|
test bundle**. The archive contains the exact Apache preview, a matching PHP-FPM
|
||||||
|
pool, site metadata, and a small PHP test page. It is intended for the isolated
|
||||||
|
Ubuntu check below.
|
||||||
|
|
||||||
|
Run the test with Docker from the repository root. Set the bundle path to the
|
||||||
|
downloaded tar archive.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker build -t coulobre-web-smoke tests/web-node
|
||||||
|
bundle="$PWD/coulobre-web-plan-1.tar"
|
||||||
|
docker run --rm --network none \
|
||||||
|
--mount "type=bind,src=$bundle,dst=/test/site.tar,readonly" \
|
||||||
|
coulobre-web-smoke
|
||||||
|
```
|
||||||
|
|
||||||
|
The Ubuntu container installs a system user for the site, checks the Apache and
|
||||||
|
PHP-FPM configurations, and makes an HTTP request with the account's primary
|
||||||
|
domain. A passing check confirms PHP execution through the generated socket.
|
||||||
|
The container uses its own filesystem and loopback interface.
|
||||||
|
|
||||||
|
## MariaDB
|
||||||
|
|
||||||
|
Create a dedicated MariaDB database and application user. Install the MariaDB or
|
||||||
|
MySQL client headers, Python headers, a C compiler, and `pkg-config`, then add
|
||||||
|
the database driver with `python -m pip install -e '.[dev,mariadb]'`.
|
||||||
|
|
||||||
|
Set `COULOBRE_DB_NAME`, `COULOBRE_DB_USER`, and `COULOBRE_DB_PASSWORD` for your
|
||||||
|
database and rerun `python manage.py migrate`. Set `COULOBRE_DB_HOST` and
|
||||||
|
`COULOBRE_DB_PORT` if the database uses a different address from `127.0.0.1:3306`.
|
||||||
|
|
||||||
|
## Checks
|
||||||
|
|
||||||
|
```sh
|
||||||
|
ruff check .
|
||||||
|
ruff format --check .
|
||||||
|
python manage.py check
|
||||||
|
python manage.py makemigrations --check --dry-run
|
||||||
|
python manage.py test coulobre
|
||||||
|
git diff --check
|
||||||
|
```
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from django.core.management import execute_from_command_line
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "coulobre.settings")
|
||||||
|
execute_from_command_line(sys.argv)
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
[build-system]
|
||||||
|
requires = ["setuptools>=77"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "coulobre-panel"
|
||||||
|
version = "0.1.0.dev0"
|
||||||
|
description = "A web hosting control panel for hosting providers and resellers."
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.12"
|
||||||
|
license = "Apache-2.0"
|
||||||
|
dependencies = [
|
||||||
|
"Django>=5.2.8,<5.3",
|
||||||
|
"celery>=5.6,<6",
|
||||||
|
"idna>=3,<4",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
dev = ["ruff>=0.11,<1"]
|
||||||
|
mariadb = ["mysqlclient>=2.2.1,<3"]
|
||||||
|
|
||||||
|
[tool.setuptools.package-data]
|
||||||
|
"coulobre.hosting" = [
|
||||||
|
"static/hosting/*.css",
|
||||||
|
"templates/*.html",
|
||||||
|
"templates/hosting/*.conf",
|
||||||
|
"templates/hosting/*.html",
|
||||||
|
"templates/hosting/*.php",
|
||||||
|
]
|
||||||
|
|
||||||
|
[tool.ruff]
|
||||||
|
target-version = "py312"
|
||||||
|
|
||||||
|
[tool.ruff.lint]
|
||||||
|
select = ["E4", "E7", "E9", "F", "I"]
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
from .celery import app as celery_app
|
||||||
|
|
||||||
|
__all__ = ("celery_app",)
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from celery import Celery
|
||||||
|
|
||||||
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "coulobre.settings")
|
||||||
|
|
||||||
|
app = Celery("coulobre")
|
||||||
|
app.config_from_object("django.conf:settings", namespace="CELERY")
|
||||||
|
app.autodiscover_tasks()
|
||||||
Whitespace-only changes.
@@ -0,0 +1,51 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from django.utils.html import format_html
|
||||||
|
|
||||||
|
from .models import HostingAccount, WebProvisioningPlan
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(HostingAccount)
|
||||||
|
class HostingAccountAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ("name", "primary_domain", "created_at")
|
||||||
|
search_fields = ("name", "primary_domain")
|
||||||
|
ordering = ("primary_domain",)
|
||||||
|
actions = ("request_web_plans",)
|
||||||
|
|
||||||
|
@admin.action(permissions=["change"], description="Request Apache plans")
|
||||||
|
def request_web_plans(self, request, queryset):
|
||||||
|
plans = WebProvisioningPlan.objects.bulk_create(
|
||||||
|
WebProvisioningPlan.for_account(account)
|
||||||
|
for account in queryset.only("primary_domain")
|
||||||
|
)
|
||||||
|
self.message_user(request, f"Queued {len(plans)} Apache plan(s).")
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(WebProvisioningPlan)
|
||||||
|
class WebProvisioningPlanAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ("primary_domain", "account", "requested_at", "completed_at")
|
||||||
|
list_select_related = ("account",)
|
||||||
|
ordering = ("-requested_at",)
|
||||||
|
fields = (
|
||||||
|
"account",
|
||||||
|
"primary_domain",
|
||||||
|
"requested_at",
|
||||||
|
"last_dispatched_at",
|
||||||
|
"completed_at",
|
||||||
|
"apache_preview",
|
||||||
|
)
|
||||||
|
readonly_fields = fields
|
||||||
|
|
||||||
|
@admin.display(description="Apache configuration", empty_value="Pending")
|
||||||
|
def apache_preview(self, obj):
|
||||||
|
if obj.apache_config:
|
||||||
|
return format_html("<pre>{}</pre>", 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
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import idna
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.core.validators import DomainNameValidator
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
validate_domain = DomainNameValidator(accept_idna=False)
|
||||||
|
|
||||||
|
|
||||||
|
class DomainNameField(models.CharField):
|
||||||
|
"""Store public hostnames in their canonical DNS representation."""
|
||||||
|
|
||||||
|
def to_python(self, value):
|
||||||
|
value = super().to_python(value)
|
||||||
|
if value in self.empty_values:
|
||||||
|
return value
|
||||||
|
|
||||||
|
try:
|
||||||
|
domain = idna.encode(value.strip(), uts46=True).decode("ascii")
|
||||||
|
except idna.IDNAError as error:
|
||||||
|
raise ValidationError(validate_domain.message, code="invalid") from error
|
||||||
|
|
||||||
|
domain = domain.removesuffix(".")
|
||||||
|
validate_domain(domain)
|
||||||
|
return domain
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
# Generated by Django 5.2.19 on 2026-11-19 20:03
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
import coulobre.hosting.fields
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = []
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="HostingAccount",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
models.BigAutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("name", models.CharField(max_length=120)),
|
||||||
|
(
|
||||||
|
"primary_domain",
|
||||||
|
coulobre.hosting.fields.DomainNameField(
|
||||||
|
max_length=253, unique=True
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("created_at", models.DateTimeField(auto_now_add=True)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -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",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
Whitespace-only changes.
@@ -0,0 +1,40 @@
|
|||||||
|
from django.db import models
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from .fields import DomainNameField
|
||||||
|
|
||||||
|
|
||||||
|
class HostingAccount(models.Model):
|
||||||
|
name = models.CharField(max_length=120)
|
||||||
|
primary_domain = DomainNameField(max_length=253, unique=True)
|
||||||
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return reverse("panel:account", kwargs={"pk": self.pk})
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def for_account(cls, account):
|
||||||
|
return cls(account=account, primary_domain=account.primary_domain)
|
||||||
|
|
||||||
|
@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
|
||||||
|
)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.primary_domain)
|
||||||
@@ -0,0 +1,567 @@
|
|||||||
|
:root {
|
||||||
|
color-scheme: light;
|
||||||
|
--page: #f4f5ef;
|
||||||
|
--surface: #fffefa;
|
||||||
|
--ink: #182923;
|
||||||
|
--muted: #516258;
|
||||||
|
--line: #dce3d9;
|
||||||
|
--sidebar: #142b26;
|
||||||
|
--sidebar-text: #e7f0e9;
|
||||||
|
--accent: #235440;
|
||||||
|
--accent-hover: #174332;
|
||||||
|
--focus: #8c4d2b;
|
||||||
|
--radius: 12px;
|
||||||
|
font: 100%/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
background: var(--page);
|
||||||
|
color: var(--ink);
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: var(--accent);
|
||||||
|
text-underline-offset: 0.2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
button, input {
|
||||||
|
font: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
:focus-visible {
|
||||||
|
outline: 3px solid var(--focus);
|
||||||
|
outline-offset: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar :focus-visible {
|
||||||
|
outline-color: #f1c68e;
|
||||||
|
}
|
||||||
|
|
||||||
|
.visually-hidden, .skip-link:not(:focus) {
|
||||||
|
position: absolute;
|
||||||
|
width: 1px;
|
||||||
|
height: 1px;
|
||||||
|
margin: -1px;
|
||||||
|
overflow: hidden;
|
||||||
|
clip-path: inset(50%);
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skip-link:focus {
|
||||||
|
position: fixed;
|
||||||
|
z-index: 1;
|
||||||
|
top: 1rem;
|
||||||
|
left: 1rem;
|
||||||
|
padding: 0.6rem 1rem;
|
||||||
|
background: var(--surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel {
|
||||||
|
display: grid;
|
||||||
|
min-height: 100vh;
|
||||||
|
grid-template-columns: 242px minmax(0, 1fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar {
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
display: flex;
|
||||||
|
height: 100dvh;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 1.65rem 1.1rem 1.1rem;
|
||||||
|
background: var(--sidebar);
|
||||||
|
color: var(--sidebar-text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.65rem;
|
||||||
|
padding: 0.25rem 0.45rem;
|
||||||
|
color: inherit;
|
||||||
|
font-size: 1.06rem;
|
||||||
|
font-weight: 750;
|
||||||
|
text-decoration: none;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-mark {
|
||||||
|
display: grid;
|
||||||
|
width: 2.15rem;
|
||||||
|
height: 2.15rem;
|
||||||
|
place-items: center;
|
||||||
|
border-radius: 0.55rem;
|
||||||
|
background: #d8e7bb;
|
||||||
|
color: #18372c;
|
||||||
|
font-size: 1.12rem;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-product {
|
||||||
|
color: #b8c9bd;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navigation {
|
||||||
|
display: grid;
|
||||||
|
gap: 0.35rem;
|
||||||
|
margin-top: 2.55rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navigation a {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.7rem;
|
||||||
|
padding: 0.65rem 0.75rem;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
border-radius: 8px;
|
||||||
|
color: #cad8ce;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navigation a:hover, .navigation a[aria-current="page"] {
|
||||||
|
border-color: #527369;
|
||||||
|
background: #28473e;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-icon {
|
||||||
|
display: inline-block;
|
||||||
|
width: 1rem;
|
||||||
|
height: 0.85rem;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
border: 1px solid currentColor;
|
||||||
|
border-radius: 2px;
|
||||||
|
color: #b9d5c3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-icon-accounts {
|
||||||
|
background: linear-gradient(currentColor, currentColor) center / 100% 1px no-repeat;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-icon-plans {
|
||||||
|
width: 0.8rem;
|
||||||
|
height: 1rem;
|
||||||
|
margin-inline: 0.1rem;
|
||||||
|
background:
|
||||||
|
linear-gradient(currentColor, currentColor) center 35% / 55% 1px no-repeat,
|
||||||
|
linear-gradient(currentColor, currentColor) center 65% / 55% 1px no-repeat;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-account {
|
||||||
|
display: grid;
|
||||||
|
gap: 0.3rem;
|
||||||
|
margin-top: auto;
|
||||||
|
padding: 0.85rem 0.55rem 0;
|
||||||
|
border-top: 1px solid #3c594e;
|
||||||
|
font-size: 0.88rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.operator {
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-account button {
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
|
color: #c1d4c7;
|
||||||
|
cursor: pointer;
|
||||||
|
text-decoration: underline;
|
||||||
|
text-underline-offset: 0.2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 1230px;
|
||||||
|
padding: clamp(1.25rem, 4.6vw, 4.5rem);
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-heading {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 1rem;
|
||||||
|
margin-bottom: 1.45rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-heading > div {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-heading > .button {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
margin-top: 0.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1, h2, p, dl {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
font-size: clamp(1.75rem, 4vw, 2.65rem);
|
||||||
|
font-weight: 750;
|
||||||
|
letter-spacing: -0.045em;
|
||||||
|
line-height: 1.12;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 1.06rem;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heading-meta {
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 0.92rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.surface {
|
||||||
|
min-width: 0;
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
background: var(--surface);
|
||||||
|
box-shadow: 0 2px 5px #1a2e2010;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
display: inline-flex;
|
||||||
|
min-height: 2.55rem;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 0.48rem 0.82rem;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
border-radius: 7px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
font-weight: 650;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.primary {
|
||||||
|
background: var(--accent);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.primary:hover {
|
||||||
|
background: var(--accent-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
.secondary {
|
||||||
|
border-color: #c5d1c7;
|
||||||
|
background: var(--surface);
|
||||||
|
color: var(--ink);
|
||||||
|
}
|
||||||
|
|
||||||
|
.secondary:hover {
|
||||||
|
background: #eaf0e9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar, .section-heading, .pagination, .form-actions {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.6rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar, .section-heading, .pagination {
|
||||||
|
padding: 1rem 1.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-heading {
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination {
|
||||||
|
justify-content: flex-end;
|
||||||
|
border-top: 1px solid var(--line);
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 0.88rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:not([type="hidden"]) {
|
||||||
|
min-width: 0;
|
||||||
|
height: 2.55rem;
|
||||||
|
padding: 0.48rem 0.68rem;
|
||||||
|
border: 1px solid #bbcbbf;
|
||||||
|
border-radius: 7px;
|
||||||
|
background: #fff;
|
||||||
|
color: var(--ink);
|
||||||
|
}
|
||||||
|
|
||||||
|
input::placeholder {
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar input {
|
||||||
|
width: min(100%, 20rem);
|
||||||
|
}
|
||||||
|
|
||||||
|
.quiet-link, .back-link {
|
||||||
|
font-size: 0.88rem;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.back-link {
|
||||||
|
display: inline-block;
|
||||||
|
margin-bottom: 1.1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-scroll {
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
th, td {
|
||||||
|
padding: 0.84rem 1.2rem;
|
||||||
|
border-top: 1px solid var(--line);
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
background: #edf1e9;
|
||||||
|
color: #40594b;
|
||||||
|
font-size: 0.78rem;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
font-size: 0.93rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
tbody tr:hover {
|
||||||
|
background: #f6f8f3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.surface > .table-scroll:first-child thead tr:first-child th {
|
||||||
|
border-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.surface > .table-scroll:first-child th:first-child {
|
||||||
|
border-top-left-radius: var(--radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
.surface > .table-scroll:first-child th:last-child {
|
||||||
|
border-top-right-radius: var(--radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
.cell-date, .status {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.record-link {
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
|
||||||
|
.domain, code {
|
||||||
|
font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
.domain {
|
||||||
|
font-size: 0.88rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.muted, .empty {
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty, .notice {
|
||||||
|
padding: 1.1rem 1.2rem;
|
||||||
|
font-size: 0.94rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.details {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 1.1rem 3rem;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
padding: 1.15rem 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.details > div {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
dt {
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 0.8rem;
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
|
||||||
|
dd {
|
||||||
|
margin: 0.28rem 0 0;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notice {
|
||||||
|
margin-bottom: 1.15rem;
|
||||||
|
border-left: 3px solid #8ca487;
|
||||||
|
border-radius: 0 6px 6px 0;
|
||||||
|
background: #e7eee5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0.18rem 0.55rem;
|
||||||
|
border-radius: 0.75rem;
|
||||||
|
font-size: 0.78rem;
|
||||||
|
font-weight: 680;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status.ready {
|
||||||
|
background: #dcebdc;
|
||||||
|
color: #205038;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status.pending {
|
||||||
|
background: #f5ead6;
|
||||||
|
color: #6b431b;
|
||||||
|
}
|
||||||
|
|
||||||
|
.configuration {
|
||||||
|
margin: 0;
|
||||||
|
overflow-x: auto;
|
||||||
|
padding: 1.2rem;
|
||||||
|
border-radius: 0 0 var(--radius) var(--radius);
|
||||||
|
background: #192e28;
|
||||||
|
color: #e6efe3;
|
||||||
|
font-size: 0.88rem;
|
||||||
|
line-height: 1.6;
|
||||||
|
tab-size: 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor-surface {
|
||||||
|
max-width: 600px;
|
||||||
|
padding: 1.35rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor {
|
||||||
|
display: grid;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 0.35rem;
|
||||||
|
font-size: 0.88rem;
|
||||||
|
font-weight: 680;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor input:not([type="hidden"]) {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor .errorlist {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0 0 0 1.1rem;
|
||||||
|
color: #902d29;
|
||||||
|
font-size: 0.87rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor [aria-invalid="true"] {
|
||||||
|
border-color: #902d29;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sign-in {
|
||||||
|
display: grid;
|
||||||
|
min-height: 100vh;
|
||||||
|
place-items: center;
|
||||||
|
padding: 1.5rem;
|
||||||
|
background: radial-gradient(ellipse at 25% 0%, #2b5343, var(--sidebar) 67%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sign-in-inner {
|
||||||
|
width: min(100%, 415px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sign-in-brand {
|
||||||
|
margin-bottom: 1.15rem;
|
||||||
|
color: var(--sidebar-text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sign-in-card {
|
||||||
|
padding: clamp(1.3rem, 4vw, 2rem);
|
||||||
|
border-radius: 14px;
|
||||||
|
background: var(--surface);
|
||||||
|
box-shadow: 0 16px 44px #08141045;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sign-in-card h1 {
|
||||||
|
margin-bottom: 1.25rem;
|
||||||
|
font-size: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 780px) {
|
||||||
|
.panel {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar {
|
||||||
|
position: static;
|
||||||
|
display: grid;
|
||||||
|
height: auto;
|
||||||
|
grid-template-columns: minmax(0, 1fr) auto;
|
||||||
|
gap: 0.65rem 0.3rem;
|
||||||
|
padding: 0.65rem 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand {
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navigation {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
grid-row: 2;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navigation a {
|
||||||
|
padding: 0.38rem 0.55rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-account {
|
||||||
|
max-width: 8.5rem;
|
||||||
|
justify-items: end;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0 0.35rem;
|
||||||
|
border-top: 0;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 520px) {
|
||||||
|
.page-heading {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar input {
|
||||||
|
width: auto;
|
||||||
|
flex: 1 1 45%;
|
||||||
|
}
|
||||||
|
|
||||||
|
th, td, .toolbar, .section-heading, .pagination {
|
||||||
|
padding-inline: 0.8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cell-date {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
from .web_node import web_site_configuration
|
||||||
|
|
||||||
|
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", web_site_configuration(plan)
|
||||||
|
)
|
||||||
|
pending.update(apache_config=apache_config, completed_at=timezone.now())
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{% extends "hosting/base.html" %}
|
||||||
|
{% block title %}Access restricted · Coulobre Panel{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<header class="page-heading">
|
||||||
|
<div>
|
||||||
|
<h1>Access restricted</h1>
|
||||||
|
<p class="heading-meta">Ask your panel administrator for access to this page.</p>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
{% extends "hosting/base.html" %}
|
||||||
|
{% block title %}{{ account.name }} · Coulobre Panel{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<a class="back-link" href="{% url 'panel:accounts' %}">← Hosting accounts</a>
|
||||||
|
<header class="page-heading">
|
||||||
|
<div>
|
||||||
|
<h1>{{ account.name }}</h1>
|
||||||
|
<p class="heading-meta domain">{{ account.primary_domain }}</p>
|
||||||
|
</div>
|
||||||
|
{% if perms.hosting.change_hostingaccount %}
|
||||||
|
<a class="button secondary" href="{% url 'panel:account_edit' account.pk %}">Edit account</a>
|
||||||
|
{% endif %}
|
||||||
|
</header>
|
||||||
|
<dl class="details surface">
|
||||||
|
<div><dt>Primary domain</dt><dd class="domain">{{ account.primary_domain }}</dd></div>
|
||||||
|
<div><dt>Added</dt><dd>{{ account.created_at|date:"j M Y, H:i" }} UTC</dd></div>
|
||||||
|
</dl>
|
||||||
|
{% if perms.hosting.view_webprovisioningplan %}
|
||||||
|
<section class="surface" aria-labelledby="previews-heading">
|
||||||
|
<header class="section-heading">
|
||||||
|
<h2 id="previews-heading">Recent Apache previews</h2>
|
||||||
|
{% if perms.hosting.change_hostingaccount %}
|
||||||
|
<form method="post" action="{% url 'panel:request_plan' account.pk %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button class="button primary" type="submit">Request Apache preview</button>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
</header>
|
||||||
|
{% include "hosting/plan_table.html" %}
|
||||||
|
</section>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
{% extends "hosting/base.html" %}
|
||||||
|
{% block title %}{{ page_title }} · Coulobre Panel{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<a class="back-link" href="{% if account %}{{ account.get_absolute_url }}{% else %}{% url 'panel:accounts' %}{% endif %}">← {% if account %}{{ account.name }}{% else %}Hosting accounts{% endif %}</a>
|
||||||
|
<header class="page-heading"><h1>{{ page_title }}</h1></header>
|
||||||
|
<section class="surface editor-surface">
|
||||||
|
<form method="post" class="editor">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_div }}
|
||||||
|
<div class="form-actions">
|
||||||
|
<button class="button primary" type="submit">{{ submit_label }}</button>
|
||||||
|
<a class="button secondary" href="{% if account %}{{ account.get_absolute_url }}{% else %}{% url 'panel:accounts' %}{% endif %}">Cancel</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
{% extends "hosting/base.html" %}
|
||||||
|
{% block title %}Hosting accounts · Coulobre Panel{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<header class="page-heading">
|
||||||
|
<div>
|
||||||
|
<h1>Hosting accounts</h1>
|
||||||
|
<p class="heading-meta">{{ paginator.count }} account{{ paginator.count|pluralize }}{% if search %} matching your search{% endif %}</p>
|
||||||
|
</div>
|
||||||
|
{% if perms.hosting.add_hostingaccount %}
|
||||||
|
<a class="button primary" href="{% url 'panel:account_create' %}">Add hosting account</a>
|
||||||
|
{% endif %}
|
||||||
|
</header>
|
||||||
|
<section class="surface" aria-label="Hosting account list">
|
||||||
|
<form class="toolbar" method="get" action="{% url 'panel:accounts' %}" role="search">
|
||||||
|
<label class="visually-hidden" for="account-search">Search by name or domain</label>
|
||||||
|
<input type="search" id="account-search" name="q" placeholder="Name or domain" value="{{ search }}">
|
||||||
|
<button class="button secondary" type="submit">Search</button>
|
||||||
|
{% if search %}<a class="quiet-link" href="{% url 'panel:accounts' %}">Clear</a>{% endif %}
|
||||||
|
</form>
|
||||||
|
{% if accounts %}
|
||||||
|
<div class="table-scroll">
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr><th scope="col">Account</th><th scope="col">Primary domain</th><th scope="col" class="cell-date">Added</th></tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for account in accounts %}
|
||||||
|
<tr>
|
||||||
|
<td><a class="record-link" href="{{ account.get_absolute_url }}">{{ account.name }}</a></td>
|
||||||
|
<td class="domain">{{ account.primary_domain }}</td>
|
||||||
|
<td class="cell-date muted">{{ account.created_at|date:"j M Y" }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% elif search %}
|
||||||
|
<p class="empty">No hosting accounts match this search.</p>
|
||||||
|
{% else %}
|
||||||
|
<p class="empty">No hosting accounts yet.</p>
|
||||||
|
{% endif %}
|
||||||
|
{% include "hosting/pagination.html" %}
|
||||||
|
</section>
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<VirtualHost *:80>
|
||||||
|
ServerName {{ domain }}
|
||||||
|
DocumentRoot "{{ document_root }}"
|
||||||
|
|
||||||
|
<Directory "{{ document_root }}">
|
||||||
|
AllowOverride None
|
||||||
|
Options None
|
||||||
|
Require all granted
|
||||||
|
</Directory>
|
||||||
|
|
||||||
|
<FilesMatch "\.php$">
|
||||||
|
SetHandler "proxy:unix:{{ socket_path }}|fcgi://localhost/"
|
||||||
|
</FilesMatch>
|
||||||
|
</VirtualHost>
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
{% load static %}<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>{% block title %}Coulobre Panel{% endblock %}</title>
|
||||||
|
<link rel="stylesheet" href="{% static 'hosting/panel.css' %}">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% if request.user.is_authenticated %}
|
||||||
|
<a class="skip-link" href="#main-content">Skip to content</a>
|
||||||
|
<div class="panel">
|
||||||
|
<aside class="sidebar">
|
||||||
|
<a class="brand" href="{% url 'panel:accounts' %}">
|
||||||
|
<span class="brand-mark" aria-hidden="true">C</span>
|
||||||
|
<span>Coulobre <span class="brand-product">Panel</span></span>
|
||||||
|
</a>
|
||||||
|
<nav class="navigation" aria-label="Main navigation">
|
||||||
|
{% with current=request.resolver_match.url_name %}
|
||||||
|
{% if perms.hosting.view_hostingaccount %}
|
||||||
|
<a href="{% url 'panel:accounts' %}"{% if current == 'accounts' or current == 'account' or current == 'account_create' or current == 'account_edit' %} aria-current="page"{% endif %}>
|
||||||
|
<span class="nav-icon nav-icon-accounts" aria-hidden="true"></span>
|
||||||
|
Hosting accounts
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if perms.hosting.view_webprovisioningplan %}
|
||||||
|
<a href="{% url 'panel:plans' %}"{% if current == 'plans' or current == 'plan' %} aria-current="page"{% endif %}>
|
||||||
|
<span class="nav-icon nav-icon-plans" aria-hidden="true"></span>
|
||||||
|
Web provisioning
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endwith %}
|
||||||
|
</nav>
|
||||||
|
<div class="sidebar-account">
|
||||||
|
<span class="operator">{{ request.user.get_username }}</span>
|
||||||
|
<form method="post" action="{% url 'panel:logout' %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button type="submit">Sign out</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
<main class="main" id="main-content">
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
{% block public_content %}{% endblock %}
|
||||||
|
{% endif %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
{% extends "hosting/base.html" %}
|
||||||
|
{% block title %}Sign in · Coulobre Panel{% endblock %}
|
||||||
|
{% block public_content %}
|
||||||
|
<main class="sign-in">
|
||||||
|
<div class="sign-in-inner">
|
||||||
|
<div class="brand sign-in-brand">
|
||||||
|
<span class="brand-mark" aria-hidden="true">C</span>
|
||||||
|
<span>Coulobre <span class="brand-product">Panel</span></span>
|
||||||
|
</div>
|
||||||
|
<section class="sign-in-card">
|
||||||
|
<h1>Sign in</h1>
|
||||||
|
<form method="post" class="editor">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_div }}
|
||||||
|
{% if next %}<input type="hidden" name="next" value="{{ next }}">{% endif %}
|
||||||
|
<button class="button primary" type="submit">Sign in</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{% if is_paginated %}
|
||||||
|
<nav class="pagination" aria-label="Pagination">
|
||||||
|
{% if page_obj.has_previous %}<a class="button secondary" href="{% querystring page=page_obj.previous_page_number %}">Previous</a>{% endif %}
|
||||||
|
<span>Page {{ page_obj.number }} of {{ paginator.num_pages }}</span>
|
||||||
|
{% if page_obj.has_next %}<a class="button secondary" href="{% querystring page=page_obj.next_page_number %}">Next</a>{% endif %}
|
||||||
|
</nav>
|
||||||
|
{% endif %}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[{{ service_user }}]
|
||||||
|
user = {{ service_user }}
|
||||||
|
group = {{ service_user }}
|
||||||
|
listen = {{ socket_path }}
|
||||||
|
listen.owner = www-data
|
||||||
|
listen.group = www-data
|
||||||
|
listen.mode = 0660
|
||||||
|
pm = ondemand
|
||||||
|
pm.max_children = 2
|
||||||
|
clear_env = yes
|
||||||
|
security.limit_extensions = .php
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
{% extends "hosting/base.html" %}
|
||||||
|
{% block title %}Apache preview · Coulobre Panel{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<a class="back-link" href="{% url 'panel:plans' %}">← Web provisioning</a>
|
||||||
|
<header class="page-heading">
|
||||||
|
<div>
|
||||||
|
<h1>Apache preview</h1>
|
||||||
|
<p class="heading-meta domain">{{ plan.primary_domain }}</p>
|
||||||
|
</div>
|
||||||
|
{% if not plan.completed_at %}
|
||||||
|
<a class="button secondary" href="{% url 'panel:plan' plan.pk %}">Refresh status</a>
|
||||||
|
{% endif %}
|
||||||
|
</header>
|
||||||
|
<dl class="details surface">
|
||||||
|
<div><dt>Status</dt><dd>{% include "hosting/plan_status.html" %}</dd></div>
|
||||||
|
<div><dt>Hosting account</dt><dd>{% if perms.hosting.view_hostingaccount %}<a class="record-link" href="{{ plan.account.get_absolute_url }}">{{ plan.account.name }}</a>{% else %}{{ plan.account.name }}{% endif %}</dd></div>
|
||||||
|
<div><dt>Requested</dt><dd>{{ plan.requested_at|date:"j M Y, H:i" }} UTC</dd></div>
|
||||||
|
</dl>
|
||||||
|
{% if plan.primary_domain != plan.account.primary_domain %}
|
||||||
|
<p class="notice">This preview captures the original domain. The hosting account now uses <strong>{{ plan.account.primary_domain }}</strong>.</p>
|
||||||
|
{% endif %}
|
||||||
|
{% if plan.completed_at %}
|
||||||
|
<section class="surface" aria-labelledby="configuration-heading">
|
||||||
|
<header class="section-heading">
|
||||||
|
<h2 id="configuration-heading">Virtual host configuration</h2>
|
||||||
|
{% if plan.can_export %}
|
||||||
|
<a class="button secondary" href="{% url 'panel:download_smoke_bundle' plan.pk %}">Download test bundle</a>
|
||||||
|
{% endif %}
|
||||||
|
</header>
|
||||||
|
<pre class="configuration"><code>{{ plan.apache_config }}</code></pre>
|
||||||
|
</section>
|
||||||
|
{% else %}
|
||||||
|
<p class="notice">The configuration will appear here after the worker completes the request.</p>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{% extends "hosting/base.html" %}
|
||||||
|
{% block title %}Web provisioning · Coulobre Panel{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<header class="page-heading">
|
||||||
|
<div>
|
||||||
|
<h1>Web provisioning</h1>
|
||||||
|
<p class="heading-meta">{{ paginator.count }} Apache preview{{ paginator.count|pluralize }}</p>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<section class="surface" aria-label="Apache previews">
|
||||||
|
{% include "hosting/plan_table.html" %}
|
||||||
|
{% include "hosting/pagination.html" %}
|
||||||
|
</section>
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{% if plan.completed_at %}
|
||||||
|
<span class="status ready">Ready</span>
|
||||||
|
{% elif plan.last_dispatched_at %}
|
||||||
|
<span class="status pending">Dispatched</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="status pending">Queued</span>
|
||||||
|
{% endif %}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
{% if plans %}
|
||||||
|
<div class="table-scroll">
|
||||||
|
<table>
|
||||||
|
<thead><tr><th scope="col">Primary domain</th><th scope="col" class="cell-date">Requested</th><th scope="col">Status</th></tr></thead>
|
||||||
|
<tbody>
|
||||||
|
{% for plan in plans %}
|
||||||
|
<tr>
|
||||||
|
<td><a class="record-link domain" href="{% url 'panel:plan' plan.pk %}">{{ plan.primary_domain }}</a></td>
|
||||||
|
<td class="cell-date muted">{{ plan.requested_at|date:"j M Y, H:i" }} UTC</td>
|
||||||
|
<td>{% include "hosting/plan_status.html" %}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<p class="empty">No Apache previews yet.</p>
|
||||||
|
{% endif %}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
header('Content-Type: text/plain; charset=UTF-8');
|
||||||
|
echo "Coulobre PHP-FPM smoke check passed.\n";
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.contrib.auth.models import Permission
|
||||||
|
from django.test import Client, TestCase
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from .models import HostingAccount, WebProvisioningPlan
|
||||||
|
from .tasks import render_web_plan
|
||||||
|
|
||||||
|
|
||||||
|
class PanelTests(TestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls):
|
||||||
|
users = get_user_model().objects
|
||||||
|
cls.login_password = "test-only-coulobre-password"
|
||||||
|
cls.operator = users.create_superuser("operator", password=cls.login_password)
|
||||||
|
cls.viewer = users.create_user("viewer")
|
||||||
|
cls.viewer.user_permissions.add(
|
||||||
|
Permission.objects.get(
|
||||||
|
content_type__app_label="hosting", codename="view_hostingaccount"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
cls.account = HostingAccount.objects.create(
|
||||||
|
name="Example hosting", primary_domain="example.org"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_login_returns_operator_to_panel_and_logout_ends_session(self):
|
||||||
|
account_url = self.account.get_absolute_url()
|
||||||
|
login_url = reverse("panel:login")
|
||||||
|
self.assertRedirects(
|
||||||
|
self.client.get(account_url), f"{login_url}?next={account_url}"
|
||||||
|
)
|
||||||
|
self.assertContains(self.client.get(login_url), "/static/hosting/panel.css")
|
||||||
|
|
||||||
|
response = self.client.post(
|
||||||
|
login_url,
|
||||||
|
{
|
||||||
|
"username": "operator",
|
||||||
|
"password": self.login_password,
|
||||||
|
"next": account_url,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
self.assertRedirects(response, account_url)
|
||||||
|
self.assertRedirects(self.client.post(reverse("panel:logout")), login_url)
|
||||||
|
self.assertRedirects(
|
||||||
|
self.client.get(account_url), f"{login_url}?next={account_url}"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_operator_can_add_find_and_edit_account(self):
|
||||||
|
self.client.force_login(self.operator)
|
||||||
|
response = self.client.post(
|
||||||
|
reverse("panel:account_create"),
|
||||||
|
{"name": "Test tenant", "primary_domain": "TEST-TENANT.example."},
|
||||||
|
)
|
||||||
|
account = HostingAccount.objects.get(name="Test tenant")
|
||||||
|
self.assertRedirects(response, account.get_absolute_url())
|
||||||
|
|
||||||
|
response = self.client.get(reverse("panel:accounts"), {"q": "test-tenant"})
|
||||||
|
self.assertContains(response, "test-tenant.example")
|
||||||
|
self.assertNotContains(response, "example.org")
|
||||||
|
|
||||||
|
response = self.client.post(
|
||||||
|
reverse("panel:account_edit", args=[account.pk]),
|
||||||
|
{"name": "Updated tenant", "primary_domain": "updated.example"},
|
||||||
|
)
|
||||||
|
self.assertRedirects(response, account.get_absolute_url())
|
||||||
|
account.refresh_from_db()
|
||||||
|
self.assertEqual(account.primary_domain, "updated.example")
|
||||||
|
|
||||||
|
def test_operator_can_queue_and_view_an_apache_preview(self):
|
||||||
|
self.client.force_login(self.operator)
|
||||||
|
request_url = reverse("panel:request_plan", args=[self.account.pk])
|
||||||
|
self.assertEqual(self.client.get(request_url).status_code, 405)
|
||||||
|
response = self.client.post(request_url)
|
||||||
|
plan = WebProvisioningPlan.objects.get()
|
||||||
|
preview_url = reverse("panel:plan", args=[plan.pk])
|
||||||
|
self.assertRedirects(response, preview_url)
|
||||||
|
self.assertContains(self.client.get(preview_url), "Queued")
|
||||||
|
|
||||||
|
render_web_plan.run(plan.pk)
|
||||||
|
|
||||||
|
self.assertContains(self.client.get(preview_url), "ServerName example.org")
|
||||||
|
self.assertContains(self.client.get(reverse("panel:plans")), "Ready")
|
||||||
|
|
||||||
|
def test_viewer_cannot_mutate_accounts_or_read_previews(self):
|
||||||
|
plan = WebProvisioningPlan.for_account(self.account)
|
||||||
|
plan.save()
|
||||||
|
self.client.force_login(self.viewer)
|
||||||
|
account = self.client.get(self.account.get_absolute_url())
|
||||||
|
self.assertContains(account, "Example hosting")
|
||||||
|
self.assertNotContains(account, "Request Apache preview")
|
||||||
|
self.assertEqual(
|
||||||
|
self.client.get(reverse("panel:account_create")).status_code, 403
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
self.client.post(
|
||||||
|
reverse("panel:account_edit", args=[self.account.pk])
|
||||||
|
).status_code,
|
||||||
|
403,
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
self.client.post(
|
||||||
|
reverse("panel:request_plan", args=[self.account.pk])
|
||||||
|
).status_code,
|
||||||
|
403,
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
self.client.get(reverse("panel:plan", args=[plan.pk])).status_code, 403
|
||||||
|
)
|
||||||
|
self.assertEqual(WebProvisioningPlan.objects.count(), 1)
|
||||||
|
|
||||||
|
def test_requesting_a_preview_requires_a_csrf_token(self):
|
||||||
|
browser = Client(enforce_csrf_checks=True)
|
||||||
|
browser.force_login(self.operator)
|
||||||
|
response = browser.post(reverse("panel:request_plan", args=[self.account.pk]))
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
self.assertFalse(WebProvisioningPlan.objects.exists())
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import json
|
||||||
|
import tarfile
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from .models import HostingAccount, WebProvisioningPlan
|
||||||
|
from .tasks import render_web_plan
|
||||||
|
|
||||||
|
|
||||||
|
class WebSmokeBundleTests(TestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls):
|
||||||
|
users = get_user_model().objects
|
||||||
|
cls.operator = users.create_superuser("operator")
|
||||||
|
cls.viewer = users.create_user("viewer")
|
||||||
|
cls.account = HostingAccount.objects.create(
|
||||||
|
name="Example hosting", primary_domain="example.org"
|
||||||
|
)
|
||||||
|
cls.plan = WebProvisioningPlan.for_account(cls.account)
|
||||||
|
cls.plan.save()
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.client.force_login(self.operator)
|
||||||
|
self.download = reverse("panel:download_smoke_bundle", args=[self.plan.pk])
|
||||||
|
|
||||||
|
def test_export_uses_the_reviewed_preview_and_matching_php_fpm_settings(self):
|
||||||
|
render_web_plan.run(self.plan.pk)
|
||||||
|
|
||||||
|
detail = self.client.get(reverse("panel:plan", args=[self.plan.pk]))
|
||||||
|
self.assertContains(detail, "Download test bundle")
|
||||||
|
response = self.client.get(self.download)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertEqual(response["Content-Type"], "application/x-tar")
|
||||||
|
self.assertIn("attachment", response["Content-Disposition"])
|
||||||
|
|
||||||
|
self.plan.refresh_from_db()
|
||||||
|
with tarfile.open(fileobj=BytesIO(response.content)) as bundle:
|
||||||
|
self.assertEqual(
|
||||||
|
set(bundle.getnames()),
|
||||||
|
{"site.json", "apache.conf", "php-fpm.conf", "public/index.php"},
|
||||||
|
)
|
||||||
|
config = json.load(bundle.extractfile("site.json"))
|
||||||
|
self.assertEqual(config["domain"], "example.org")
|
||||||
|
self.assertEqual(config["account_id"], self.account.pk)
|
||||||
|
|
||||||
|
apache = bundle.extractfile("apache.conf").read().decode()
|
||||||
|
fpm = bundle.extractfile("php-fpm.conf").read().decode()
|
||||||
|
self.assertEqual(apache, self.plan.apache_config)
|
||||||
|
self.assertIn(config["document_root"], apache)
|
||||||
|
self.assertIn(config["socket_path"], apache)
|
||||||
|
self.assertIn(f"listen = {config['socket_path']}", fpm)
|
||||||
|
self.assertIn(f"user = {config['service_user']}", fpm)
|
||||||
|
self.assertIn(b"<?php", bundle.extractfile("public/index.php").read())
|
||||||
|
|
||||||
|
def test_pending_and_stale_previews_cannot_be_exported(self):
|
||||||
|
self.assertEqual(self.client.get(self.download).status_code, 409)
|
||||||
|
render_web_plan.run(self.plan.pk)
|
||||||
|
HostingAccount.objects.filter(pk=self.account.pk).update(
|
||||||
|
primary_domain="updated.example"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(self.client.get(self.download).status_code, 409)
|
||||||
|
detail = self.client.get(reverse("panel:plan", args=[self.plan.pk]))
|
||||||
|
self.assertNotContains(detail, "Download test bundle")
|
||||||
|
|
||||||
|
def test_download_requires_plan_view_permission(self):
|
||||||
|
render_web_plan.run(self.plan.pk)
|
||||||
|
self.client.force_login(self.viewer)
|
||||||
|
|
||||||
|
self.assertEqual(self.client.get(self.download).status_code, 403)
|
||||||
@@ -0,0 +1,163 @@
|
|||||||
|
from datetime import timedelta
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.utils import timezone
|
||||||
|
from kombu.exceptions import OperationalError
|
||||||
|
|
||||||
|
from .models import HostingAccount, WebProvisioningPlan
|
||||||
|
from .tasks import REDISPATCH_AFTER, dispatch_web_plans, render_web_plan
|
||||||
|
|
||||||
|
|
||||||
|
class HostingAccountAdminTests(TestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls):
|
||||||
|
users = get_user_model().objects
|
||||||
|
cls.operator = users.create_superuser("operator")
|
||||||
|
cls.staff = users.create_user("staff", is_staff=True)
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.add_url = reverse("admin:hosting_hostingaccount_add")
|
||||||
|
self.client.force_login(self.operator)
|
||||||
|
|
||||||
|
def test_register_and_find_an_account(self):
|
||||||
|
response = self.client.post(
|
||||||
|
self.add_url,
|
||||||
|
{"name": "Example hosting", "primary_domain": "BÜCHER.example."},
|
||||||
|
follow=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertContains(response, "Example hosting")
|
||||||
|
self.assertContains(response, "xn--bcher-kva.example")
|
||||||
|
self.assertEqual(
|
||||||
|
HostingAccount.objects.get().primary_domain, "xn--bcher-kva.example"
|
||||||
|
)
|
||||||
|
|
||||||
|
list_url = reverse("admin:hosting_hostingaccount_changelist")
|
||||||
|
results = self.client.get(list_url, {"q": "xn--bcher"})
|
||||||
|
self.assertContains(results, "Example hosting")
|
||||||
|
|
||||||
|
def test_equivalent_domain_is_rejected(self):
|
||||||
|
HostingAccount.objects.create(
|
||||||
|
name="Existing account", primary_domain="bücher.example"
|
||||||
|
)
|
||||||
|
response = self.client.post(
|
||||||
|
self.add_url,
|
||||||
|
{"name": "Duplicate account", "primary_domain": "XN--BCHER-KVA.Example."},
|
||||||
|
)
|
||||||
|
|
||||||
|
form = response.context["adminform"].form
|
||||||
|
self.assertEqual(form.errors.as_data()["primary_domain"][0].code, "unique")
|
||||||
|
self.assertEqual(HostingAccount.objects.count(), 1)
|
||||||
|
|
||||||
|
def test_invalid_domain_is_rejected(self):
|
||||||
|
response = self.client.post(
|
||||||
|
self.add_url,
|
||||||
|
{"name": "Invalid account", "primary_domain": "https://example.org"},
|
||||||
|
)
|
||||||
|
|
||||||
|
form = response.context["adminform"].form
|
||||||
|
self.assertEqual(form.errors.as_data()["primary_domain"][0].code, "invalid")
|
||||||
|
self.assertFalse(HostingAccount.objects.exists())
|
||||||
|
|
||||||
|
def test_staff_without_add_permission_cannot_register_an_account(self):
|
||||||
|
self.client.force_login(self.staff)
|
||||||
|
response = self.client.post(
|
||||||
|
self.add_url,
|
||||||
|
{"name": "Example hosting", "primary_domain": "example.org"},
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
self.assertFalse(HostingAccount.objects.exists())
|
||||||
|
|
||||||
|
|
||||||
|
class WebProvisioningPlanTests(TestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls):
|
||||||
|
cls.account = HostingAccount.objects.create(
|
||||||
|
name="Example hosting", primary_domain="example.org"
|
||||||
|
)
|
||||||
|
|
||||||
|
def create_plan(self):
|
||||||
|
return WebProvisioningPlan.objects.create(
|
||||||
|
account=self.account, primary_domain=self.account.primary_domain
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_admin_request_preserves_domain_until_worker_finishes(self):
|
||||||
|
self.client.force_login(get_user_model().objects.create_superuser("operator"))
|
||||||
|
list_url = reverse("admin:hosting_hostingaccount_changelist")
|
||||||
|
response = self.client.post(
|
||||||
|
list_url,
|
||||||
|
{"action": "request_web_plans", "_selected_action": [self.account.pk]},
|
||||||
|
)
|
||||||
|
self.assertRedirects(response, list_url)
|
||||||
|
|
||||||
|
plan = WebProvisioningPlan.objects.get()
|
||||||
|
self.assertIsNone(plan.completed_at)
|
||||||
|
|
||||||
|
HostingAccount.objects.filter(pk=self.account.pk).update(
|
||||||
|
primary_domain="new.example.org"
|
||||||
|
)
|
||||||
|
render_web_plan.run(plan.pk)
|
||||||
|
plan.refresh_from_db()
|
||||||
|
|
||||||
|
self.assertIsNotNone(plan.completed_at)
|
||||||
|
self.assertIn("ServerName example.org", plan.apache_config)
|
||||||
|
self.assertIn(f"/srv/coulobre/web/{self.account.pk}/public", plan.apache_config)
|
||||||
|
self.assertIn(f"/run/php/coulobre-{self.account.pk}.sock", plan.apache_config)
|
||||||
|
|
||||||
|
plan_url = reverse("admin:hosting_webprovisioningplan_change", args=[plan.pk])
|
||||||
|
response = self.client.get(plan_url)
|
||||||
|
self.assertContains(response, "<pre><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)
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
from django.contrib.auth.views import LoginView, LogoutView
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
app_name = "panel"
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path("", views.AccountList.as_view(), name="accounts"),
|
||||||
|
path(
|
||||||
|
"sign-in/",
|
||||||
|
LoginView.as_view(
|
||||||
|
template_name="hosting/login.html",
|
||||||
|
redirect_authenticated_user=True,
|
||||||
|
),
|
||||||
|
name="login",
|
||||||
|
),
|
||||||
|
path("sign-out/", LogoutView.as_view(), name="logout"),
|
||||||
|
path("accounts/new/", views.AccountCreate.as_view(), name="account_create"),
|
||||||
|
path("accounts/<int:pk>/", views.AccountDetail.as_view(), name="account"),
|
||||||
|
path("accounts/<int:pk>/edit/", views.AccountEdit.as_view(), name="account_edit"),
|
||||||
|
path(
|
||||||
|
"accounts/<int:pk>/plans/", views.RequestWebPlan.as_view(), name="request_plan"
|
||||||
|
),
|
||||||
|
path("plans/", views.PlanList.as_view(), name="plans"),
|
||||||
|
path("plans/<int:pk>/", views.PlanDetail.as_view(), name="plan"),
|
||||||
|
path(
|
||||||
|
"plans/<int:pk>/smoke-bundle/",
|
||||||
|
views.DownloadWebSmokeBundle.as_view(),
|
||||||
|
name="download_smoke_bundle",
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||||
|
from django.db.models import Q
|
||||||
|
from django.http import HttpResponse
|
||||||
|
from django.shortcuts import redirect
|
||||||
|
from django.views import View
|
||||||
|
from django.views.generic import CreateView, DetailView, ListView, UpdateView
|
||||||
|
from django.views.generic.detail import SingleObjectMixin
|
||||||
|
|
||||||
|
from .models import HostingAccount, WebProvisioningPlan
|
||||||
|
from .web_node import build_web_smoke_bundle
|
||||||
|
|
||||||
|
VIEW_ACCOUNTS = "hosting.view_hostingaccount"
|
||||||
|
CHANGE_ACCOUNTS = "hosting.change_hostingaccount"
|
||||||
|
VIEW_PLANS = "hosting.view_webprovisioningplan"
|
||||||
|
|
||||||
|
|
||||||
|
class AccountList(PermissionRequiredMixin, ListView):
|
||||||
|
model = HostingAccount
|
||||||
|
permission_required = VIEW_ACCOUNTS
|
||||||
|
template_name = "hosting/account_list.html"
|
||||||
|
context_object_name = "accounts"
|
||||||
|
paginate_by = 20
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
self.search = self.request.GET.get("q", "").strip()[:253]
|
||||||
|
accounts = HostingAccount.objects.order_by("primary_domain")
|
||||||
|
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):
|
||||||
|
return super().get_context_data(search=self.search, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class AccountCreate(PermissionRequiredMixin, CreateView):
|
||||||
|
model = HostingAccount
|
||||||
|
permission_required = (VIEW_ACCOUNTS, "hosting.add_hostingaccount")
|
||||||
|
template_name = "hosting/account_form.html"
|
||||||
|
fields = ("name", "primary_domain")
|
||||||
|
extra_context = {"page_title": "Add hosting account", "submit_label": "Add account"}
|
||||||
|
|
||||||
|
|
||||||
|
class AccountEdit(PermissionRequiredMixin, UpdateView):
|
||||||
|
model = HostingAccount
|
||||||
|
permission_required = (VIEW_ACCOUNTS, CHANGE_ACCOUNTS)
|
||||||
|
template_name = "hosting/account_form.html"
|
||||||
|
context_object_name = "account"
|
||||||
|
fields = ("name", "primary_domain")
|
||||||
|
extra_context = {
|
||||||
|
"page_title": "Edit hosting account",
|
||||||
|
"submit_label": "Save changes",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class AccountDetail(PermissionRequiredMixin, DetailView):
|
||||||
|
model = HostingAccount
|
||||||
|
permission_required = VIEW_ACCOUNTS
|
||||||
|
template_name = "hosting/account_detail.html"
|
||||||
|
context_object_name = "account"
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
if self.request.user.has_perm(VIEW_PLANS):
|
||||||
|
context["plans"] = self.object.webprovisioningplan_set.order_by(
|
||||||
|
"-requested_at", "-pk"
|
||||||
|
)[:10]
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
class RequestWebPlan(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(PermissionRequiredMixin, ListView):
|
||||||
|
queryset = WebProvisioningPlan.objects.select_related("account").order_by(
|
||||||
|
"-requested_at", "-pk"
|
||||||
|
)
|
||||||
|
permission_required = VIEW_PLANS
|
||||||
|
template_name = "hosting/plan_list.html"
|
||||||
|
context_object_name = "plans"
|
||||||
|
paginate_by = 20
|
||||||
|
|
||||||
|
|
||||||
|
class PlanDetail(PermissionRequiredMixin, DetailView):
|
||||||
|
queryset = WebProvisioningPlan.objects.select_related("account")
|
||||||
|
permission_required = VIEW_PLANS
|
||||||
|
template_name = "hosting/plan_detail.html"
|
||||||
|
context_object_name = "plan"
|
||||||
|
|
||||||
|
|
||||||
|
class DownloadWebSmokeBundle(PlanDetail):
|
||||||
|
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",
|
||||||
|
)
|
||||||
|
|
||||||
|
return HttpResponse(
|
||||||
|
build_web_smoke_bundle(plan),
|
||||||
|
content_type="application/x-tar",
|
||||||
|
headers={
|
||||||
|
"Cache-Control": "private, no-store",
|
||||||
|
"Content-Disposition": f'attachment; filename="coulobre-web-plan-{plan.pk}.tar"',
|
||||||
|
},
|
||||||
|
)
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import json
|
||||||
|
import tarfile
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
|
from django.template.loader import render_to_string
|
||||||
|
|
||||||
|
|
||||||
|
def web_site_configuration(plan):
|
||||||
|
service_user = f"coulobre-{plan.account_id}"
|
||||||
|
return {
|
||||||
|
"account_id": plan.account_id,
|
||||||
|
"domain": plan.primary_domain,
|
||||||
|
"service_user": service_user,
|
||||||
|
"document_root": f"/srv/coulobre/web/{plan.account_id}/public",
|
||||||
|
"socket_path": f"/run/php/{service_user}.sock",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def build_web_smoke_bundle(plan):
|
||||||
|
configuration = web_site_configuration(plan)
|
||||||
|
files = {
|
||||||
|
"site.json": json.dumps(configuration, indent=2) + "\n",
|
||||||
|
"apache.conf": plan.apache_config,
|
||||||
|
"php-fpm.conf": render_to_string("hosting/php-fpm-pool.conf", configuration),
|
||||||
|
"public/index.php": render_to_string("hosting/smoke-index.php"),
|
||||||
|
}
|
||||||
|
|
||||||
|
archive = BytesIO()
|
||||||
|
with tarfile.open(fileobj=archive, mode="w") as bundle:
|
||||||
|
for name, text in files.items():
|
||||||
|
data = text.encode("utf-8")
|
||||||
|
member = tarfile.TarInfo(name)
|
||||||
|
member.size = len(data)
|
||||||
|
bundle.addfile(member, BytesIO(data))
|
||||||
|
return archive.getvalue()
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
|
|
||||||
|
|
||||||
|
def required_env(name):
|
||||||
|
value = os.environ.get(name)
|
||||||
|
if not value:
|
||||||
|
raise ImproperlyConfigured(f"Set the {name} environment variable.")
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
SECRET_KEY = required_env("COULOBRE_SECRET_KEY")
|
||||||
|
DEBUG = os.environ.get("COULOBRE_DEBUG") == "1"
|
||||||
|
ALLOWED_HOSTS = os.environ.get(
|
||||||
|
"COULOBRE_ALLOWED_HOSTS", "localhost,127.0.0.1,[::1]"
|
||||||
|
).split(",")
|
||||||
|
|
||||||
|
INSTALLED_APPS = [
|
||||||
|
"django.contrib.admin",
|
||||||
|
"django.contrib.auth",
|
||||||
|
"django.contrib.contenttypes",
|
||||||
|
"django.contrib.sessions",
|
||||||
|
"django.contrib.messages",
|
||||||
|
"django.contrib.staticfiles",
|
||||||
|
"coulobre.hosting",
|
||||||
|
]
|
||||||
|
|
||||||
|
MIDDLEWARE = [
|
||||||
|
"django.middleware.security.SecurityMiddleware",
|
||||||
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||||
|
"django.middleware.common.CommonMiddleware",
|
||||||
|
"django.middleware.csrf.CsrfViewMiddleware",
|
||||||
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||||
|
"django.contrib.messages.middleware.MessageMiddleware",
|
||||||
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||||
|
]
|
||||||
|
|
||||||
|
ROOT_URLCONF = "coulobre.urls"
|
||||||
|
TEMPLATES = [
|
||||||
|
{
|
||||||
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||||
|
"APP_DIRS": True,
|
||||||
|
"OPTIONS": {
|
||||||
|
"context_processors": [
|
||||||
|
"django.template.context_processors.request",
|
||||||
|
"django.contrib.auth.context_processors.auth",
|
||||||
|
"django.contrib.messages.context_processors.messages",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
database_name = os.environ.get("COULOBRE_DB_NAME")
|
||||||
|
if database_name:
|
||||||
|
DATABASES = {
|
||||||
|
"default": {
|
||||||
|
"ENGINE": "django.db.backends.mysql",
|
||||||
|
"NAME": database_name,
|
||||||
|
"USER": required_env("COULOBRE_DB_USER"),
|
||||||
|
"PASSWORD": os.environ.get("COULOBRE_DB_PASSWORD", ""),
|
||||||
|
"HOST": os.environ.get("COULOBRE_DB_HOST", "127.0.0.1"),
|
||||||
|
"PORT": os.environ.get("COULOBRE_DB_PORT", "3306"),
|
||||||
|
"OPTIONS": {"charset": "utf8mb4"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
DATABASES = {
|
||||||
|
"default": {
|
||||||
|
"ENGINE": "django.db.backends.sqlite3",
|
||||||
|
"NAME": Path(os.environ.get("COULOBRE_SQLITE_PATH", "db.sqlite3")),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
|
{
|
||||||
|
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
|
||||||
|
},
|
||||||
|
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
|
||||||
|
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
|
||||||
|
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
|
||||||
|
]
|
||||||
|
|
||||||
|
TIME_ZONE = "UTC"
|
||||||
|
STATIC_URL = "/static/"
|
||||||
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||||
|
LOGIN_URL = "panel:login"
|
||||||
|
LOGIN_REDIRECT_URL = "panel:accounts"
|
||||||
|
LOGOUT_REDIRECT_URL = "panel:login"
|
||||||
|
|
||||||
|
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},
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from django.urls import include, path
|
||||||
|
|
||||||
|
admin.site.site_header = "Coulobre Panel"
|
||||||
|
admin.site.site_title = "Coulobre Panel"
|
||||||
|
admin.site.index_title = "Administration"
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path("admin/", admin.site.urls),
|
||||||
|
path("", include("coulobre.hosting.urls")),
|
||||||
|
]
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
FROM ubuntu:26.04
|
||||||
|
|
||||||
|
RUN apt-get update \
|
||||||
|
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
||||||
|
apache2 curl jq php8.5-fpm \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
COPY smoke.sh /usr/local/bin/coulobre-web-smoke
|
||||||
|
|
||||||
|
ENTRYPOINT ["/bin/sh", "/usr/local/bin/coulobre-web-smoke"]
|
||||||
|
CMD ["/test/site.tar"]
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
scratch=$(mktemp -d)
|
||||||
|
tar --extract --file "$1" --directory "$scratch" --no-same-owner --no-same-permissions
|
||||||
|
account_id=$(jq -er '.account_id' "$scratch/site.json")
|
||||||
|
domain=$(jq -er '.domain' "$scratch/site.json")
|
||||||
|
|
||||||
|
case "$account_id" in
|
||||||
|
''|*[!0-9]*) echo 'Invalid hosting account ID.' >&2; exit 1 ;;
|
||||||
|
esac
|
||||||
|
case "$domain" in
|
||||||
|
''|*[!a-z0-9.-]*) echo 'Invalid primary domain.' >&2; exit 1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
account_dir="/srv/coulobre/web/$account_id"
|
||||||
|
site_user="coulobre-$account_id"
|
||||||
|
site_conf="$site_user.conf"
|
||||||
|
|
||||||
|
useradd --system --user-group --no-create-home --home-dir "$account_dir" \
|
||||||
|
--shell /usr/sbin/nologin "$site_user"
|
||||||
|
install -d -m 0755 "$account_dir" /run/php
|
||||||
|
install -d -m 0750 -o "$site_user" -g www-data "$account_dir/public"
|
||||||
|
install -m 0640 -o "$site_user" -g www-data \
|
||||||
|
"$scratch/public/index.php" "$account_dir/public/index.php"
|
||||||
|
|
||||||
|
install -m 0644 "$scratch/apache.conf" "/etc/apache2/sites-available/$site_conf"
|
||||||
|
a2enmod proxy_fcgi >/dev/null
|
||||||
|
a2dissite 000-default >/dev/null
|
||||||
|
a2ensite "$site_conf" >/dev/null
|
||||||
|
printf 'ServerName localhost\n' > /etc/apache2/conf-enabled/coulobre-smoke.conf
|
||||||
|
|
||||||
|
printf '[global]\nerror_log = /proc/self/fd/2\ninclude = %s\n' \
|
||||||
|
"$scratch/php-fpm.conf" > "$scratch/fpm.conf"
|
||||||
|
php-fpm8.5 --test --fpm-config "$scratch/fpm.conf"
|
||||||
|
apache2ctl configtest
|
||||||
|
|
||||||
|
php-fpm8.5 --daemonize --fpm-config "$scratch/fpm.conf"
|
||||||
|
apache2ctl start
|
||||||
|
|
||||||
|
body=$(curl --fail --silent --show-error --noproxy '*' --max-time 5 \
|
||||||
|
--retry 5 --retry-connrefused --header "Host: $domain" http://127.0.0.1/index.php)
|
||||||
|
if [ "$body" != 'Coulobre PHP-FPM smoke check passed.' ]; then
|
||||||
|
echo 'The test site did not return the expected PHP response.' >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf '%s via %s\n' "$body" "$domain"
|
||||||
Reference in new issue
Block a user