diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fe8d3619..46cbf949 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -91,8 +91,8 @@ jobs: - name: Check Translation Catalogs if: matrix.python-version == '3.12' && matrix.database == 'sqlite' run: | - python manage.py makemessages -l tr -l zh --no-obsolete --ignore=staticfiles -v0 - for dir in locale/tr/LC_MESSAGES locale/zh/LC_MESSAGES; do + python manage.py makemessages -l tr -l zh -l uk --no-obsolete --ignore=staticfiles -v0 + for dir in locale/tr/LC_MESSAGES locale/zh/LC_MESSAGES locale/uk/LC_MESSAGES; do msgfmt --check -o /tmp/django.mo "$dir/django.po" missing=$(msgattrib --untranslated "$dir/django.po"; msgattrib --only-fuzzy "$dir/django.po") if [ -n "$missing" ]; then echo "$missing"; echo "::error file=$dir/django.po::untranslated or fuzzy messages"; exit 1; fi diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d974050e..be8b16d6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -61,9 +61,9 @@ It lists the dead keys it leaves out: a character only a dead key types cannot b English is the source language; the panel is translated into the other languages of `LANGUAGES` in `settings.py`, each with a full catalog in `locale/`. A new or changed text needs its translation in each before CI passes (needs `gettext`): ```bash -python manage.py makemessages -l tr -l zh --no-obsolete --ignore=staticfiles --ignore=.venv -# translate the new and fuzzy entries of locale/tr/LC_MESSAGES/django.po and locale/zh/LC_MESSAGES/django.po -python manage.py compilemessages -l tr -l zh +python manage.py makemessages -l tr -l zh -l uk --no-obsolete --ignore=staticfiles --ignore=.venv +# translate the new and fuzzy entries of the django.po of locale/tr, locale/zh and locale/uk +python manage.py compilemessages -l tr -l zh -l uk ``` ## Running tests diff --git a/Dockerfile b/Dockerfile index ae75b611..d12820d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,7 @@ RUN apt-get update -qq \ libvirt0 \ nginx \ openssh-client \ + postgresql-client \ python3 \ supervisor \ tzdata \ diff --git a/README.md b/README.md index 5cc03272..17076009 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ flowchart TB
  • VMs created, renamed or deleted with virsh or virt-manager are picked up on their own
  • Tags, protected VMs, search by IP or MAC address and a VM report as an Excel file
  • Alerts by e-mail or webhook, and a health check URL
  • -
  • English, Turkish and Simplified Chinese
  • +
  • English, Turkish, Simplified Chinese and Ukrainian
  • diff --git a/accounts/templates/accounts/change_password_form.html b/accounts/templates/accounts/change_password_form.html index f91d8802..d8a48f54 100644 --- a/accounts/templates/accounts/change_password_form.html +++ b/accounts/templates/accounts/change_password_form.html @@ -1,39 +1,93 @@ {% extends "base.html" %} -{% load django_bootstrap5 %} +{% load static %} {% load i18n %} {% block title %}{% trans "Change password" %}{% endblock title %} - -{% block page_heading %}{% trans "Change password" %}{% endblock page_heading %} +{# a user who must change it (the first admin, a new or reset account) can go nowhere else first #} +{% block navbar %}{% if not must_change %}{{ block.super }}{% endif %}{% endblock navbar %} +{% block page_header %}{% endblock page_header %}{# the card has its own heading #} {% block content %} -{# a user changes their own password; one who must (a new or reset account) cannot go elsewhere first #} -
    - {% csrf_token %} - {% bootstrap_form_errors form type="non_fields" %} +
    +
    +
    +
    +
    +
    +

    {% if must_change %}{% trans "Set your own password" %}{% else %}{% trans "Change password" %}{% endif %}

    +

    + {% if must_change %} + {% blocktrans with name=request.user.username %}Signed in as {{ name }} with a temporary password. Replace it to continue.{% endblocktrans %} + {% else %} + {% blocktrans with name=request.user.username %}For {{ name }}. You stay signed in here; your other sessions end.{% endblocktrans %} + {% endif %} +

    +
    -
    -
    -
    -

    {{ request.user.username }}

    -

    - {% if must_change %}{% trans "Choose a new password before you go on." %}{% else %}{% trans "You stay signed in here; your other sessions end." %}{% endif %} -

    -
    -
    -
    -
    {% bootstrap_field form.old_password %}
    -
    -
    {% bootstrap_field form.new_password1 %}
    -
    {% bootstrap_field form.new_password2 show_help=False %}
    + {% for error in form.non_field_errors %} + + {% endfor %} + + + {% csrf_token %} + {# focus: the first entry with an error; a refused new password is typed again from the first entry #} + {% with old_bad=form.old_password.errors new_bad=form.new_password1.errors again_bad=form.new_password2.errors %} +
    + + + {% if old_bad %}
    {{ old_bad|join:" " }}
    {% endif %} + {% if must_change %}
    {% trans "The one you just signed in with." %}
    {% endif %} +
    + +
    + +
    + + + {% if new_bad %}
    {{ new_bad|join:" " }}
    {% endif %} +
    +
    + +
    + + +
    + + {# the rules the server checks; the first three are checked as you type, its refusals follow #} +
      +
    • {% trans "8 characters or more" %} {% trans "not met" %}
    • +
    • {% trans "Not only digits" %} {% trans "not met" %}
    • +
    • {% trans "Both entries match" %} {% trans "not met" %}
    • +
    • {% trans "Not like your name or e-mail, and not a common password: checked when you save" %}
    • + {% for error in again_bad %} +
    • {{ error }}
    • + {% endfor %} +
    + {% endwith %} + + + + +
    + {% if must_change %} +
    {% csrf_token %} + +
    + {% else %} + {% trans "Cancel" %} + {% endif %}
    -
    - -
    - {% if not must_change %}{% trans "Cancel" %}{% endif %} -
    - +
    {% endblock content %} + +{% block script %} + +{% endblock script %} diff --git a/accounts/templates/login.html b/accounts/templates/login.html index 1aca143e..6f76e932 100644 --- a/accounts/templates/login.html +++ b/accounts/templates/login.html @@ -11,7 +11,7 @@
    -
    +

    WebVirtCloud

    {% trans "Virtualization management console" %}

    diff --git a/accounts/tests/test_audit_rows.py b/accounts/tests/test_audit_rows.py index 57764be5..f8284adf 100644 --- a/accounts/tests/test_audit_rows.py +++ b/accounts/tests/test_audit_rows.py @@ -1,7 +1,10 @@ """Changes to a user's own account, VM ownership, OTP mails and SSH keys write rows on the Logs page.""" +import tempfile +from pathlib import Path + from django.contrib.auth import get_user_model -from django.test import TestCase +from django.test import TestCase, override_settings from django.urls import reverse from accounts.models import UserAttributes @@ -38,8 +41,10 @@ class OwnAccountRowTests(TestCase): def test_the_first_login_password_change(self): self.bob.user_permissions.clear() UserAttributes.objects.update_or_create(user=self.bob, defaults={"must_change_password": True}) - self.client.post(reverse("accounts:change_password"), { - "old_password": "Bob-pass-2026", "new_password1": "Bob-new-pass-1", "new_password2": "Bob-new-pass-1"}) + # the last forced change deletes data/admin_password: not this checkout's + with tempfile.TemporaryDirectory() as base, override_settings(BASE_DIR=Path(base)): + self.client.post(reverse("accounts:change_password"), { + "old_password": "Bob-pass-2026", "new_password1": "Bob-new-pass-1", "new_password2": "Bob-new-pass-1"}) self.assertEqual(rows(), [("User bob: change password", True)]) diff --git a/accounts/tests/test_change_password_permission.py b/accounts/tests/test_change_password_permission.py index fbce3e20..e60f3caf 100644 --- a/accounts/tests/test_change_password_permission.py +++ b/accounts/tests/test_change_password_permission.py @@ -44,7 +44,7 @@ class ChangePasswordPermissionTestCase(TestCase): self.assertContains(page, f'href="{reverse("accounts:profile")}">Cancel') UserAttributes.objects.create(user=user, must_change_password=True) page = self.client.get(reverse("accounts:change_password")) - self.assertContains(page, "Choose a new password before you go on.") + self.assertContains(page, "Replace it to continue.") self.assertNotContains(page, f'href="{reverse("accounts:profile")}">Cancel') def test_a_user_without_a_local_password_cannot_change_it(self): diff --git a/accounts/tests/test_first_login_password.py b/accounts/tests/test_first_login_password.py index 796deddc..9144b7fd 100644 --- a/accounts/tests/test_first_login_password.py +++ b/accounts/tests/test_first_login_password.py @@ -59,6 +59,43 @@ class FirstLoginPasswordChangeTestCase(TestCase): response = self.client.get(reverse("instances:index")) self.assertEqual(response.status_code, 200) + def test_the_forced_form_has_no_menu_and_offers_sign_out(self): + # every page but this one sends the user back here: no links that lead nowhere + self.client.force_login(self.admin) + response = self.client.get(reverse("accounts:change_password")) + self.assertNotContains(response, f'href="{reverse("instances:index")}"') + self.assertContains(response, f'action="{reverse("accounts:logout")}"') + self.assertContains(response, "Temporary password") + + def test_a_refused_new_password_shows_the_reasons_in_the_rules(self): + self.client.force_login(self.admin) + response = self.client.post(reverse("accounts:change_password"), { + "old_password": GENERATED, "new_password1": "12345678", "new_password2": "12345678", + }) + rules = response.content.decode().split('id="password-rules"')[1].split("")[0] + self.assertIn("This password is entirely numeric.", rules) + + def test_an_empty_first_new_entry_is_shown_and_focused(self): + self.client.force_login(self.admin) + response = self.client.post(reverse("accounts:change_password"), { + "old_password": GENERATED, "new_password1": "", "new_password2": "A-new-strong-pass-456", + }) + page = response.content.decode() + self.assertIn('id="new-password-error"', page) + first_entry = page.split('id="id_new_password1"')[1].split(">")[0] + self.assertIn('aria-invalid="true"', first_entry) + self.assertIn("autofocus", first_entry) + + def test_a_chosen_change_keeps_the_menu_and_a_way_back(self): + other = get_user_model().objects.create_superuser( + username="otheradmin", email="otheradmin@example.com", password="Other-pass-789" + ) + self.client.force_login(other) + response = self.client.get(reverse("accounts:change_password")) + self.assertContains(response, f'href="{reverse("instances:index")}"') + self.assertContains(response, f'href="{reverse("accounts:profile")}"') + self.assertContains(response, "Current password") + def test_user_with_another_password_is_not_forced(self): get_user_model().objects.create_superuser( username="otheradmin", email="otheradmin@example.com", password="Other-pass-789" diff --git a/appsettings/management/commands/backup.py b/appsettings/management/commands/backup.py index 8229a67e..1cbfacf0 100644 --- a/appsettings/management/commands/backup.py +++ b/appsettings/management/commands/backup.py @@ -15,8 +15,8 @@ PREFIX = "webvirtcloud-backup-" class Command(BaseCommand): - help = ("Copy the database, secret key, worker id, local settings and the SSH keys and TLS certificates of the " - "panel's user into a new directory in backups/, then delete all but the newest --keep backups.") + help = ("Copy the database (sqlite) or dump it (PostgreSQL), the secret key, worker id, local settings and the " + "SSH keys and TLS certificates of the panel's user into a new directory in backups/, then delete all but the newest --keep backups.") def add_arguments(self, parser): parser.add_argument("--keep", type=int, default=7, help="how many backups to keep (default 7)") @@ -65,6 +65,8 @@ class Command(BaseCommand): result = copy.execute("PRAGMA integrity_check").fetchone()[0] if result != "ok": raise CommandError(f"The copy of the database is damaged: {result}") + elif database["ENGINE"] == "django.db.backends.postgresql": + self.dump_postgresql(database, to / "db.pgdump") else: self.stderr.write("The database is not sqlite and is not in the backup: back it up with its own tools.") # the key in use: SECRET_KEY from the environment has no data/secret_key @@ -87,3 +89,16 @@ class Command(BaseCommand): commit = subprocess.run(["git", "rev-parse", "HEAD"], cwd=settings.BASE_DIR, capture_output=True, text=True) if commit.returncode == 0: (to / "commit").write_text(commit.stdout) + + @staticmethod + def dump_postgresql(database, to): + """pg_dump's own format, which pg_restore reads; a consistent state while the panel writes.""" + if shutil.which("pg_dump") is None: + raise CommandError("pg_dump is not installed: install the PostgreSQL client (postgresql-client)") + # libpq reads the password and the connect timeout from the environment, not the command line + env = {**os.environ, "PGPASSWORD": database["PASSWORD"], "PGCONNECT_TIMEOUT": "10"} + dump = subprocess.run(["pg_dump", "--format=custom", f"--file={to}", f"--host={database['HOST']}", + f"--port={database['PORT']}", f"--username={database['USER']}", f"--dbname={database['NAME']}"], + env=env, capture_output=True, text=True) + if dump.returncode != 0: + raise CommandError(f"pg_dump failed: {dump.stderr.strip()}") diff --git a/appsettings/tests/test_appsettings.py b/appsettings/tests/test_appsettings.py index c6474b40..39e1a4d9 100644 --- a/appsettings/tests/test_appsettings.py +++ b/appsettings/tests/test_appsettings.py @@ -31,7 +31,7 @@ class AppSettingsTestCase(TestCase): page = self.client.get(reverse("appsettings")).content.decode() choice = page[page.index('