Skip to content

Commit

Permalink
Remove references to VPN keys and VPN based urls
Browse files Browse the repository at this point in the history
  • Loading branch information
153957 committed Mar 19, 2024
1 parent 27df648 commit 6743ee2
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 91 deletions.
1 change: 0 additions & 1 deletion publicdb/default/templates/robots.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ Disallow: /maps/
Disallow: /analysis-session/
Disallow: /software-updates/
Disallow: /config/
Disallow: /keys/
Disallow: /admin/
2 changes: 1 addition & 1 deletion publicdb/inforecords/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 0 additions & 62 deletions publicdb/inforecords/models.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import datetime
import ipaddress

from xmlrpc.client import ServerProxy

from django.conf import settings
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
Expand Down Expand Up @@ -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'<a href="{url}">Certificate {self.name}</a>')

keys.short_description = 'Certificates'

def url(self):
if self.type.slug == 'admin':
return ''
else:
return mark_safe(f'<a href="vnc://s{self.station.number}.his">s{self.station.number}.his</a>')

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"""
Expand Down
27 changes: 2 additions & 25 deletions publicdb/inforecords/views.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
3 changes: 1 addition & 2 deletions publicdb/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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/<slug:host>/', keys, name='keys'),
path('admin/', admin.site.urls),
]

0 comments on commit 6743ee2

Please sign in to comment.