Browse Source

Add an (ugly) template with VPN details

Baptiste Jonglez 10 years ago
parent
commit
7bd843704b
3 changed files with 34 additions and 2 deletions
  1. 21 0
      coin/vpn/templates/vpn/vpn.html
  2. 5 2
      coin/vpn/urls.py
  3. 8 0
      coin/vpn/views.py

+ 21 - 0
coin/vpn/templates/vpn/vpn.html

@@ -0,0 +1,21 @@
+{% extends "base.html" %}
+
+{% block content %}
+<h2>VPN details</h2>
+
+<ul>
+  <li>Login: {{ object.login }}</li>
+  <li>Password: <a href="{% url 'vpn:generate_password' object.pk %}">Generate new password</a></li>
+  <li>Comment: {{ object.comment }}</li>
+  <li>IPv4 endpoint: {{ object.ipv4_endpoint }}</li>
+  <li>IPv6 endpoint: {{ object.ipv6_endpoint }}</li>
+</ul>
+
+<p>IP subnets attributed to this VPN:</p>
+<ul>
+  {% for subnet in object.administrative_subscription.ip_subnet.all %}
+  <li>{{ subnet }}</li>
+  {% endfor %}
+</ul>
+
+{% endblock %}

+ 5 - 2
coin/vpn/urls.py

@@ -1,7 +1,10 @@
 from django.conf.urls import patterns, url
-from coin.vpn import views
+from coin.vpn.views import VPNView, generate_password
 
 urlpatterns = patterns(
     '',
-    url(r'^password/(?P<vpn_id>.+)$', views.generate_password, name="generate_password"),
+    # This is part of the generic configuration interface (the "name" is
+    # the same as the "backend_name" of the model).
+    url(r'^([0-9]+)$', VPNView.as_view(template_name="vpn/vpn.html"), name="openvpn_ldap"),
+    url(r'^password/(?P<vpn_id>.+)$', generate_password, name="generate_password"),
 )

+ 8 - 0
coin/vpn/views.py

@@ -1,8 +1,16 @@
 from django.contrib.auth.models import User
 from django.shortcuts import render_to_response, get_object_or_404
+from django.views.generic.detail import DetailView
 
 from coin.vpn.models import VPNSubscription
 
+
+class VPNView(DetailView):
+ def get_object(self):
+        return get_object_or_404(VPNSubscription, pk=self.args[0],
+                                 administrative_subscription__member__user=self.request.user)
+
+
 def generate_password(request, vpn_id):
     """This generates a random password, saves it in hashed form, and returns
     it to the user in cleartext.