diff --git a/academon/settings.py b/academon/settings.py index 9298a11..a1941cb 100644 --- a/academon/settings.py +++ b/academon/settings.py @@ -22,8 +22,8 @@ SECRET_KEY = ASK.secret_key # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] - +ALLOWED_HOSTS = [ASK.config["ACADEMON"]["Host"]] +CSRF_TRUSTED_ORIGINS = [f"https://{host}" for host in ALLOWED_HOSTS] # Application definition @@ -128,12 +128,22 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.0/howto/static-files/ -STATIC_URL = 'static/' +STATIC_URL = '/static/' + +STATIC_ROOT = None if DEBUG else ASK.config.get("ACADEMON", "StaticRoot", fallback=BASE_DIR / "static") STATICFILES_DIRS = [ BASE_DIR / "static", ] +if "S3" in ASK.config: + DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' + STATICFILES_STORAGE = 'storages.backends.s3boto3.S3StaticStorage' + AWS_ACCESS_KEY_ID = ASK.config.get("S3", "AccessKey") + AWS_SECRET_ACCESS_KEY = ASK.config.get("S3", "SecretKey") + AWS_STORAGE_BUCKET_NAME = ASK.config.get("S3", "Bucket") + AWS_S3_ENDPOINT_URL = ASK.config.get("S3", "Endpoint") + # Default primary key field type # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field diff --git a/academon/urls.py b/academon/urls.py index 42f7321..cece570 100644 --- a/academon/urls.py +++ b/academon/urls.py @@ -3,5 +3,6 @@ from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), + path('api/', include(("api.urls", "api"))), path('', include(("core.urls", "core"))), ] diff --git a/api/__init__.py b/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/admin.py b/api/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/api/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/api/apps.py b/api/apps.py new file mode 100644 index 0000000..66656fd --- /dev/null +++ b/api/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ApiConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'api' diff --git a/api/migrations/__init__.py b/api/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/models.py b/api/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/api/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/api/tests.py b/api/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/api/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/api/urls.py b/api/urls.py new file mode 100644 index 0000000..ad783e1 --- /dev/null +++ b/api/urls.py @@ -0,0 +1,4 @@ +from django.urls import path, include + +urlpatterns = [ +] diff --git a/api/views.py b/api/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/api/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/core/backends/reportmonster.py b/core/backends/reportmonster.py index 4120403..7778934 100644 --- a/core/backends/reportmonster.py +++ b/core/backends/reportmonster.py @@ -3,19 +3,23 @@ from django.contrib.auth import get_user_model from django.contrib import messages from django.conf import settings +from reportmonster.classes.vessel import Vessel + from bcrypt import checkpw class ReportMonsterBackend(ModelBackend): - def authenticate(self, request, username: str = None, password:str = None): + def authenticate(self, request, username: str = None, password: str = None): self.request = request monster = settings.MONSTERCONFIG - loginvessel = filter(lambda x: x.name = settings.LOGIN_VESSEL, monster.vessels)[0] + loginvessel = list( + filter(lambda x: x.name == settings.LOGIN_VESSEL, monster.vessels) + )[0] - + userdata = list(loginvessel.getUsers(username=username).values())[0] - if checkpw(password.encode(), userdata.content["password"].encode()): + if checkpw(password.encode(), userdata["password"].encode()): user, _ = get_user_model().objects.get_or_create(email=username) user.save() return user diff --git a/core/models/vessel.py b/core/models/vessel.py new file mode 100644 index 0000000..1754f4e --- /dev/null +++ b/core/models/vessel.py @@ -0,0 +1,33 @@ +from django.db import models + +from pycruisemapper.classes import CruiseMapper, Ship + + +class Vessel(models.Model): + name = models.CharField(max_length=64) + imo = models.IntegerField(null=True, blank=True) + mmsi = models.IntegerField(null=True, blank=True) + + def query_cruisemapper(self) -> Ship: + cm = CruiseMapper() + all_ships = cm.get_ships() + + try: + if self.imo: + filtered = filter(lambda x: x.imo == self.imo, all_ships) + elif self.mmsi: + filtered = filter(lambda x: x.mmsi == self.mmsi, all_ships) + else: + return False + + ship = list(filtered)[0] + + except: + return False + + try: + ship = cm.fill_ship(ship) + except: + pass + + return ship diff --git a/core/urls/frontend.py b/core/urls/frontend.py index bf55389..9b0e1bd 100644 --- a/core/urls/frontend.py +++ b/core/urls/frontend.py @@ -1,10 +1,12 @@ from django.urls import path, reverse_lazy from django.views.generic import RedirectView -from ..views.frontend import DashboardView +from ..views.frontend import DashboardView, NotImplementedView urlpatterns = [ + path("admin/", NotImplementedView.as_view(), name="admin"), + path("admin/vessels/", NotImplementedView.as_view(), name="admin_vessels"), path("dashboard/", DashboardView.as_view(), name="dashboard"), path("", RedirectView.as_view(url=reverse_lazy("core:dashboard"))), ] \ No newline at end of file diff --git a/core/views/admin.py b/core/views/admin.py new file mode 100644 index 0000000..1045c50 --- /dev/null +++ b/core/views/admin.py @@ -0,0 +1,7 @@ +from django.views.generic import ListView + +from ..mixins.auth import SuperuserRequiredMixin + + +class AdminVesselsListView(TemplateView, SuperuserRequiredMixin): + template_name = "core/base.html" diff --git a/requirements.txt b/requirements.txt index 14e8774..8ec3531 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,14 @@ django -dbsettings -django-autosecretkey pyotp bcrypt +certifi +django-storages +boto3 +django-ajax-datatable + +dbsettings +django-autosecretkey +pycruisemapper git+https://kumig.it/kumisystems/reportmonster.git git+https://kumig.it/kumisystems/pyadonis.git \ No newline at end of file diff --git a/settings.dist.ini b/settings.dist.ini index 5ec74d4..9749dca 100644 --- a/settings.dist.ini +++ b/settings.dist.ini @@ -1,20 +1,26 @@ [ACADEMON] +Host = academon.example.com + +[ADONIS] +CrewPortalBaseURL=http://adonis/AdonisWebServices/CrewPortalWebService.svc/ +Login=Adonis_API +Password= [REPORTMONSTER] Login = 1 -LoginVessel = test +LoginVessel = Login -[Vessel test] +# Define a ReportMonster vessel to use for authentication *only* +# To manage that vessel from within AcadeMon set it up in the adimnistration too! +# Make sure the vessel name matches LoginVessel in [REPORTMONSTER] above + +[Vessel Login] Host = 10.11.12.13 Username = moodle_test Password = 1quite_secret*indeed! Database = moodle_test SSH = 1 # Whether or not to tunnel the MySQL connection through SSH -# ReportMonster / AcadeMon does not handle authentication, so use SSH agent! - -# Only used if anything actually enables the ReportMonster API -# [User test] -# Password = test123! +# ReportMonster / AcadeMon does not handle SSH auth, so use SSH agent! # [MySQL] # Database = academon diff --git a/templates/core/base.html b/templates/core/base.html index 479813e..d432c28 100644 --- a/templates/core/base.html +++ b/templates/core/base.html @@ -4,14 +4,15 @@ -Academon | {{ title }} +AcadeMon | {{ title }} - - +{% block styles %} +{% endblock %} +
@@ -61,148 +62,7 @@ - - +{% include "core/frontend/sidebar.html" %}
@@ -242,16 +102,13 @@ All rights reserved.
- - - - - - + +{% block scripts %} +{% endblock %} diff --git a/templates/core/frontend/sidebar.html b/templates/core/frontend/sidebar.html new file mode 100644 index 0000000..e1de513 --- /dev/null +++ b/templates/core/frontend/sidebar.html @@ -0,0 +1,141 @@ +{% load static %} + + \ No newline at end of file