diff --git a/publicdb/default/templates/robots.txt b/publicdb/default/templates/robots.txt index e4bf22f83..d02523da3 100644 --- a/publicdb/default/templates/robots.txt +++ b/publicdb/default/templates/robots.txt @@ -9,5 +9,4 @@ Disallow: /maps/ Disallow: /analysis-session/ Disallow: /software-updates/ Disallow: /config/ -Disallow: /keys/ Disallow: /admin/ diff --git a/publicdb/inforecords/admin.py b/publicdb/inforecords/admin.py index 3b47a4841..fc5cb7c64 100644 --- a/publicdb/inforecords/admin.py +++ b/publicdb/inforecords/admin.py @@ -71,7 +71,7 @@ def type(self, obj): @admin.register(models.Pc) class PcAdmin(admin.ModelAdmin): - list_display = ('station', 'name', 'is_active', 'is_test', 'ip', 'url', 'keys') + list_display = ('station', 'name', 'is_active', 'is_test', 'ip') list_filter = ('is_active', 'is_test') ordering = ('station',) list_per_page = 200 diff --git a/publicdb/inforecords/models.py b/publicdb/inforecords/models.py index 218e2f032..11c09f17e 100644 --- a/publicdb/inforecords/models.py +++ b/publicdb/inforecords/models.py @@ -1,5 +1,4 @@ import datetime -import ipaddress from xmlrpc.client import ServerProxy @@ -7,8 +6,6 @@ from django.core.exceptions import ValidationError from django.db import models, transaction from django.db.models import Max -from django.urls import reverse -from django.utils.safestring import mark_safe from django.utils.text import slugify from ..histograms.models import Configuration, Summary @@ -335,67 +332,8 @@ def __str__(self): def save(self, *args, **kwargs): # slugify the short name to keep it clean self.name = slugify(self.name).replace('-', '').replace('_', '') - - if self.id is None: - if self.type.slug == 'admin': - try: - last_ip = Pc.objects.filter(type__slug='admin').latest('id').ip - except Pc.DoesNotExist: - # Initial Admin IP - last_ip = '172.16.66.1' - else: - try: - last_ip = Pc.objects.exclude(type__slug='admin').latest('id').ip - except Pc.DoesNotExist: - # Initial station IP - last_ip = '194.171.82.1' - self.ip = self.get_next_ip_address(last_ip) - - # First create keys, then issue final save - create_keys(self) - super().save(*args, **kwargs) - def keys(self): - url = reverse('keys', kwargs={'host': self.name}) - return mark_safe(f'Certificate {self.name}') - - keys.short_description = 'Certificates' - - def url(self): - if self.type.slug == 'admin': - return '' - else: - return mark_safe(f's{self.station.number}.his') - - url.short_description = 'VNC URL' - - def get_next_ip_address(self, ip): - """Generate new IP address - - Increments given IP address by 1. - - """ - return str(ipaddress.ip_address(ip) + 1) - - -def create_keys(pc): - """Create VPN keys for the given Pc""" - - if settings.VPN_PROXY: - proxy = ServerProxy(settings.VPN_PROXY) - proxy.create_key(pc.name, pc.type.slug, pc.ip) - - -def update_aliases(): - """Update VPN aliases""" - - if settings.VPN_PROXY: - proxy = ServerProxy(settings.VPN_PROXY) - aliases = [(f's{x.station.number}', x.ip) for x in Pc.objects.all()] - aliases.extend([(x.name, x.ip) for x in Pc.objects.all()]) - proxy.register_hosts_ip(aliases) - def reload_datastore(): """Reload the datastore configuration""" diff --git a/publicdb/inforecords/views.py b/publicdb/inforecords/views.py index 418f624db..155aeaab2 100644 --- a/publicdb/inforecords/views.py +++ b/publicdb/inforecords/views.py @@ -1,33 +1,10 @@ -import base64 import socket -from xmlrpc.client import ServerProxy - from django.conf import settings -from django.contrib.auth.decorators import login_required from django.core.exceptions import PermissionDenied -from django.http import HttpResponse -from django.shortcuts import get_object_or_404, render - -from .models import Pc, Station - - -@login_required -def keys(request, host): - """Return a zip-file containing the hosts OpenVPN keys""" - - host = get_object_or_404(Pc, name=host) - - if settings.VPN_PROXY: - proxy = ServerProxy(settings.VPN_PROXY) - key_file = proxy.get_key(host.name, host.type.slug).data - key_file = base64.b64decode(key_file) - else: - key_file = 'dummy' +from django.shortcuts import render - response = HttpResponse(key_file, content_type='application/zip') - response['Content-Disposition'] = f'attachment; filename={host.name}.zip' - return response +from .models import Station def create_datastore_config(request): diff --git a/publicdb/urls.py b/publicdb/urls.py index 782eaa4b2..bad3e72ad 100644 --- a/publicdb/urls.py +++ b/publicdb/urls.py @@ -2,7 +2,7 @@ from django.urls import include, path from django.views.generic import RedirectView, TemplateView -from .inforecords.views import create_datastore_config, keys +from .inforecords.views import create_datastore_config urlpatterns = [ path('', RedirectView.as_view(url='show/stations', permanent=False)), @@ -16,6 +16,5 @@ path('raw_data/', include('publicdb.raw_data.urls', namespace='raw_data')), path('data/', include('publicdb.raw_data.urls')), path('config/datastore', create_datastore_config, name='datastore_config'), - path('keys//', keys, name='keys'), path('admin/', admin.site.urls), ]