diff --git a/.travis.yml b/.travis.yml index 2eed2e2..c5fb27a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,14 +2,14 @@ language: python python: - "3.6" env: - - DJANGO=2.2.16 + - DJANGO=3.2.4 install: - pip install -r dev/requirements.txt script: - pep8 --exclude=IPy.py --ignore=E501 vrtManager accounts admin appsettings computes \ console create datasource instances interfaces \ - logs networks nwfilters secrets storages + logs networks nwfilters storages virtsecrets - pyflakes vrtManager accounts admin appsettings computes console create datasource instances interfaces \ - nwfilters networks secrets storages logs + logs networks nwfilters storages virtsecrets - python manage.py migrate - python manage.py test --settings=webvirtcloud.settings-dev diff --git a/Dockerfile b/Dockerfile index 4582751..6bd18b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM phusion/baseimage:18.04-1.0.0 +FROM phusion/baseimage:focal-1.0.0 EXPOSE 80 EXPOSE 6080 diff --git a/README.md b/README.md index d0dc575..055ad67 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/retspen/webvirtcloud) # WebVirtCloud -###### Python3 & Django 2.2 +###### Python 3.x & Django 3.2 LTS ## Features * QEMU/KVM Hypervisor Management diff --git a/admin/templates/admin/group_list.html b/admin/templates/admin/group_list.html index d101466..1f9562f 100644 --- a/admin/templates/admin/group_list.html +++ b/admin/templates/admin/group_list.html @@ -9,9 +9,7 @@ {% icon 'plus' %} - + {% include 'search_block.html' %}

{% trans "Groups" %}

diff --git a/admin/templates/admin/user_list.html b/admin/templates/admin/user_list.html index f1a6323..9bcb683 100644 --- a/admin/templates/admin/user_list.html +++ b/admin/templates/admin/user_list.html @@ -12,9 +12,7 @@ {% icon 'plus' %} - +{% include 'search_block.html' %} {% endblock page_heading_extra %} {% block content %} diff --git a/computes/templates/computes/instances.html b/computes/templates/computes/instances.html index f69143f..489262f 100644 --- a/computes/templates/computes/instances.html +++ b/computes/templates/computes/instances.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% load i18n %} -{% load staticfiles %} +{% load static %} {% load icons %} {% block title %}{% trans "Instances" %} - {{ compute.name }}{% endblock %} {% block style %} @@ -14,9 +14,7 @@ {% icon 'plus' %} {% if instances %} - + {% include 'search_block.html' %} {% endif %} {% endblock page_heading_extra %} @@ -44,7 +42,7 @@ {% icon 'filter' %} {% trans "NWFilters" %} diff --git a/computes/templates/computes/list.html b/computes/templates/computes/list.html index 8e4b899..9cb3233 100644 --- a/computes/templates/computes/list.html +++ b/computes/templates/computes/list.html @@ -22,9 +22,9 @@ {% else %}
- +
- + @@ -33,7 +33,7 @@ {% for compute in computes %} - + @@ -64,5 +64,6 @@ {% endblock content %} {% block script %} - + + {% endblock script %} diff --git a/computes/templates/overview.html b/computes/templates/overview.html index 2894ebb..a6b72c9 100644 --- a/computes/templates/overview.html +++ b/computes/templates/overview.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% load i18n %} -{% load staticfiles %} +{% load static %} {% load icons %} {% block title %}{% trans "Overview" %} - {{ compute.name }}{% endblock %} @@ -31,7 +31,7 @@ {% icon 'filter' %} {% trans "NWFilters" %} diff --git a/computes/tests.py b/computes/tests.py index 488202d..7b94825 100644 --- a/computes/tests.py +++ b/computes/tests.py @@ -115,7 +115,7 @@ class ComputesTestCase(TestCase): # TODO: add test for single nwfilter def test_secrets(self): - response = self.client.get(reverse('secrets', args=[1])) + response = self.client.get(reverse('virtsecrets', args=[1])) self.assertEqual(response.status_code, 200) # def test_create_instance_select_type(self): diff --git a/computes/urls.py b/computes/urls.py index 6e43695..d69509a 100644 --- a/computes/urls.py +++ b/computes/urls.py @@ -1,4 +1,4 @@ -from secrets.views import secrets +from virtsecrets.views import secrets from django.urls import include, path # from instances.views import create_instance, create_instance_select_type @@ -33,7 +33,7 @@ urlpatterns = [ path('interface//', interface, name='interface'), path('nwfilters/', nwfilters, name='nwfilters'), path('nwfilter//', nwfilter, name='nwfilter'), - path('secrets/', secrets, name='secrets'), + path('virtsecrets/', secrets, name='virtsecrets'), # path('create/', create_instance_select_type, name='create_instance_select_type'), # path('create/archs//machines//', create_instance, name='create_instance'), path('archs//machines/', views.get_compute_machine_types, name='machines'), diff --git a/conf/requirements.txt b/conf/requirements.txt index 8d13382..235cd22 100644 --- a/conf/requirements.txt +++ b/conf/requirements.txt @@ -1,4 +1,4 @@ -Django==2.2.22 +Django==3.2.4 django-bootstrap4==3.0.1 django-icons==4.0.0 django-login-required-middleware==0.6.1 diff --git a/console/templates/console-base.html b/console/templates/console-base.html index 7875f7e..8627cec 100644 --- a/console/templates/console-base.html +++ b/console/templates/console-base.html @@ -1,4 +1,4 @@ -{% load staticfiles %} +{% load static %} {% load i18n %} diff --git a/console/templates/console-spice-full.html b/console/templates/console-spice-full.html index da7dae1..0dfed9f 100644 --- a/console/templates/console-spice-full.html +++ b/console/templates/console-spice-full.html @@ -24,7 +24,7 @@ --> {% extends "console-base.html" %} {% load i18n %} -{% load staticfiles %} +{% load static %} {% block head %} WebVirtCloud - Spice Client - Full diff --git a/console/templates/console-spice-lite.html b/console/templates/console-spice-lite.html index a984063..469c971 100644 --- a/console/templates/console-spice-lite.html +++ b/console/templates/console-spice-lite.html @@ -24,7 +24,7 @@ --> {% extends "console-base.html" %} {% load i18n %} -{% load staticfiles %} +{% load static %} {% block head %} WebVirtCloud - Spice - Lite diff --git a/console/templates/console-vnc-full.html b/console/templates/console-vnc-full.html index 05bf5b4..fae93e5 100755 --- a/console/templates/console-vnc-full.html +++ b/console/templates/console-vnc-full.html @@ -1,6 +1,6 @@ {% extends "console-base.html" %} {% load i18n %} -{% load staticfiles %} +{% load static %} {% block head %} diff --git a/instances/templates/instances/settings_tab.html b/instances/templates/instances/settings_tab.html index ef79a45..ddcf390 100644 --- a/instances/templates/instances/settings_tab.html +++ b/instances/templates/instances/settings_tab.html @@ -290,7 +290,7 @@ - {% include 'edit_instance_volume.html' with id=forloop.counter0 %} + {% include 'instances/edit_instance_volume.html' with id=forloop.counter0 %}
{% csrf_token %} diff --git a/instances/views.py b/instances/views.py index 2fb3ab5..6669aa9 100644 --- a/instances/views.py +++ b/instances/views.py @@ -596,8 +596,8 @@ def edit_volume(request, pk): shareable = bool(request.POST.get("vol_shareable", False)) readonly = bool(request.POST.get("vol_readonly", False)) disk_type = request.POST.get("vol_type", "") - new_bus = request.POST.get("vol_bus", "") bus = request.POST.get("vol_bus_old", "") + new_bus = request.POST.get("vol_bus", bus) serial = request.POST.get("vol_serial", "") format = request.POST.get("vol_format", "") cache = request.POST.get("vol_cache", app_settings.INSTANCE_VOLUME_DEFAULT_CACHE) diff --git a/interfaces/templates/interface.html b/interfaces/templates/interface.html index a06a950..00f0385 100644 --- a/interfaces/templates/interface.html +++ b/interfaces/templates/interface.html @@ -28,7 +28,7 @@ {% trans "NWFilters" %} diff --git a/interfaces/templates/interfaces.html b/interfaces/templates/interfaces.html index 413691f..d36e91a 100644 --- a/interfaces/templates/interfaces.html +++ b/interfaces/templates/interfaces.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% load i18n %} -{% load staticfiles %} +{% load static %} {% block title %}{% trans "Interfaces" %} - {{ compute.name }}{% endblock %} @@ -32,7 +32,7 @@ {% trans "NWFilters" %} diff --git a/networks/templates/network.html b/networks/templates/network.html index 7672038..0f67022 100644 --- a/networks/templates/network.html +++ b/networks/templates/network.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% load i18n %} -{% load staticfiles %} +{% load static %} {% block title %}{% trans "Network" %} - {{ pool }}{% endblock %} @@ -29,7 +29,7 @@ {% trans "NWFilters" %} diff --git a/networks/templates/networks.html b/networks/templates/networks.html index b847749..14a50bc 100644 --- a/networks/templates/networks.html +++ b/networks/templates/networks.html @@ -31,7 +31,7 @@ {% trans "NWFilters" %} diff --git a/nwfilters/templates/nwfilter.html b/nwfilters/templates/nwfilter.html index c14282f..e1db43d 100644 --- a/nwfilters/templates/nwfilter.html +++ b/nwfilters/templates/nwfilter.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% load i18n %} -{% load staticfiles %} +{% load static %} {% block title %}{% trans "NWFilter" %}: {{ name }}{% endblock %} @@ -29,7 +29,7 @@ {% trans "NWFilters" %} @@ -66,8 +66,6 @@
{% trans "Name" %} {% trans "Status" %} {% trans "Details" %}
{{ compute.name }} {% csrf_token %} - @@ -148,7 +146,7 @@ - @@ -162,21 +160,8 @@ {% endblock %} {% block script %} - - - + + + + + - - - + + - {% endblock %} diff --git a/storages/templates/storages.html b/storages/templates/storages.html index 21edf6f..25253d0 100644 --- a/storages/templates/storages.html +++ b/storages/templates/storages.html @@ -31,7 +31,7 @@ {% trans "NWFilters" %} diff --git a/templates/search_block.html b/templates/search_block.html index 7f2b515..f80a4ce 100644 --- a/templates/search_block.html +++ b/templates/search_block.html @@ -1,4 +1,4 @@ {% load i18n %} diff --git a/secrets/__init__.py b/virtsecrets/__init__.py similarity index 100% rename from secrets/__init__.py rename to virtsecrets/__init__.py diff --git a/secrets/forms.py b/virtsecrets/forms.py similarity index 100% rename from secrets/forms.py rename to virtsecrets/forms.py diff --git a/secrets/migrations/__init__.py b/virtsecrets/migrations/__init__.py similarity index 100% rename from secrets/migrations/__init__.py rename to virtsecrets/migrations/__init__.py diff --git a/secrets/models.py b/virtsecrets/models.py similarity index 100% rename from secrets/models.py rename to virtsecrets/models.py diff --git a/secrets/templates/create_secret_block.html b/virtsecrets/templates/create_secret_block.html similarity index 100% rename from secrets/templates/create_secret_block.html rename to virtsecrets/templates/create_secret_block.html diff --git a/secrets/templates/secrets.html b/virtsecrets/templates/secrets.html similarity index 99% rename from secrets/templates/secrets.html rename to virtsecrets/templates/secrets.html index 7536032..74d8fbf 100644 --- a/secrets/templates/secrets.html +++ b/virtsecrets/templates/secrets.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% load i18n %} -{% load staticfiles %} +{% load static %} {% block title %}{% trans "Secrets" %} - {{ compute.name }}{% endblock %} {% block style %} diff --git a/secrets/tests.py b/virtsecrets/tests.py similarity index 100% rename from secrets/tests.py rename to virtsecrets/tests.py diff --git a/secrets/views.py b/virtsecrets/views.py similarity index 97% rename from secrets/views.py rename to virtsecrets/views.py index 3bcee54..d7804c6 100644 --- a/secrets/views.py +++ b/virtsecrets/views.py @@ -1,4 +1,4 @@ -from secrets.forms import AddSecret +from virtsecrets.forms import AddSecret from admin.decorators import superuser_only from computes.models import Compute @@ -13,7 +13,7 @@ from libvirt import ( VIR_SECRET_USAGE_TYPE_VOLUME, libvirtError, ) -from vrtManager.secrets import wvmSecrets +from vrtManager.virtsecrets import wvmSecrets @superuser_only diff --git a/vrtManager/secrets.py b/vrtManager/virtsecrets.py similarity index 100% rename from vrtManager/secrets.py rename to vrtManager/virtsecrets.py diff --git a/webvirtcloud/asgi.py b/webvirtcloud/asgi.py new file mode 100644 index 0000000..521fe59 --- /dev/null +++ b/webvirtcloud/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for webvirtcloud project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webvirtcloud.settings') + +application = get_asgi_application() diff --git a/webvirtcloud/ldapbackend.py b/webvirtcloud/ldapbackend.py index 2d38e8f..6f246c6 100644 --- a/webvirtcloud/ldapbackend.py +++ b/webvirtcloud/ldapbackend.py @@ -11,33 +11,35 @@ try: #/srv/webvirtcloud/ldap/ldapbackend.py class LdapAuthenticationBackend(ModelBackend): - def get_LDAP_user(self, username, password, filterString): - print('get_LDAP_user') - try: - server = Server(settings.LDAP_URL, port=settings.LDAP_PORT, - use_ssl=settings.USE_SSL,get_info=ALL) - connection = Connection(server, - settings.LDAP_MASTER_DN, - settings.LDAP_MASTER_PW, auto_bind=True) + def get_LDAP_user(self, username, password, filterString): + print('get_LDAP_user') + try: + server = Server(settings.LDAP_URL, port=settings.LDAP_PORT, + use_ssl=settings.USE_SSL,get_info=ALL) + connection = Connection(server, + settings.LDAP_MASTER_DN, + settings.LDAP_MASTER_PW, auto_bind=True) + + connection.search(settings.LDAP_ROOT_DN, + '(&({attr}={login})({filter}))'.format( + attr=settings.LDAP_USER_UID_PREFIX, + login=username, + filter=filterString), attributes=['*']) + + if len(connection.response) == 0: + print('get_LDAP_user-no response') + return None + specificUser = connection.response[0] + userDn = str(specificUser.get('raw_dn'),'utf-8') + with Connection(server, + userDn, + password) as con: + return username + except: + return None + return None - connection.search(settings.LDAP_ROOT_DN, - '(&({attr}={login})({filter}))'.format( - attr=settings.LDAP_USER_UID_PREFIX, - login=username, - filter=filterString), attributes=['*']) - - if len(connection.response) == 0: - print('get_LDAP_user-no response') - return None - specificUser = connection.response[0] - userDn = str(specificUser.get('raw_dn'),'utf-8') - with Connection(server, - userDn, - password) as con: - return username - return None - - def authenticate(self, request, username=None, password=None, **kwargs): + def authenticate(self, request, username=None, password=None, **kwargs): if not settings.LDAP_ENABLED: return None print("authenticate_ldap") @@ -96,7 +98,7 @@ try: print("authenticate-user created") return user - def get_user(self, user_id): + def get_user(self, user_id): if not settings.LDAP_ENABLED: return None print("get_user_ldap") diff --git a/webvirtcloud/settings.py.template b/webvirtcloud/settings.py.template index 74be031..9407b7e 100644 --- a/webvirtcloud/settings.py.template +++ b/webvirtcloud/settings.py.template @@ -3,10 +3,10 @@ Django settings for webvirtcloud project. """ -import os +from pathlib import Path -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent SECRET_KEY = "" @@ -36,7 +36,7 @@ INSTALLED_APPS = [ "interfaces", "nwfilters", "storages", - "secrets", + "virtsecrets", "logs", "qr_code", ] @@ -63,7 +63,7 @@ TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", "DIRS": [ - os.path.join(BASE_DIR, "templates"), + Path.joinpath(BASE_DIR, "templates"), ], "APP_DIRS": True, "OPTIONS": { @@ -83,6 +83,7 @@ TEMPLATES = [ WSGI_APPLICATION = "webvirtcloud.wsgi.application" + # Settings for django-icons DJANGO_ICONS = { @@ -96,13 +97,14 @@ DJANGO_ICONS = { }, } + # Database # https://docs.djangoproject.com/en/3.0/ref/settings/#databases DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", - "NAME": os.path.join(BASE_DIR, "db.sqlite3"), + "NAME": Path.joinpath(BASE_DIR, "db.sqlite3"), } } @@ -128,13 +130,35 @@ USE_TZ = True STATIC_URL = "/static/" STATICFILES_DIRS = [ - os.path.join(BASE_DIR, "static"), + Path.joinpath(BASE_DIR, "static"), ] + +# Default primary key field type +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + + LOCALE_PATHS = [ "locale/", ] + +# Settings for django-icons +DJANGO_ICONS = { + + 'DEFAULTS': { + 'renderer': 'fontawesome4', + }, + + 'RENDERERS': { + 'fontawesome4': 'FontAwesome4Renderer', + 'bootstrap3': 'Bootstrap3Renderer', + }, +} + + LOGGING = { "version": 1, "disable_existing_loggers": False, @@ -150,6 +174,7 @@ LOGGING = { }, } + # # WebVirtCloud settings # @@ -223,10 +248,15 @@ ALLOW_EMPTY_PASSWORD = False NEW_USER_DEFAULT_INSTANCES = [] SHOW_PROFILE_EDIT_PASSWORD = True + +# OTP Config OTP_ENABLED = False LOGIN_REQUIRED_IGNORE_VIEW_NAMES = ["accounts:login", "accounts:email_otp"] +# LDAP Config +# + LDAP_ENABLED = False LDAP_URL = '' LDAP_PORT = 389 diff --git a/webvirtcloud/wsgi.py b/webvirtcloud/wsgi.py index d444f71..00c2ae3 100644 --- a/webvirtcloud/wsgi.py +++ b/webvirtcloud/wsgi.py @@ -4,7 +4,7 @@ WSGI config for webvirtcloud project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see -https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ +https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ """ import os diff --git a/webvirtcloud/wsgi_custom.py b/webvirtcloud/wsgi_custom.py index acf22aa..109c99e 100644 --- a/webvirtcloud/wsgi_custom.py +++ b/webvirtcloud/wsgi_custom.py @@ -4,7 +4,7 @@ WSGI config for webvirtcloud project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see -https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ +https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ """ import os import sys