Add client view that shows all VPNs with a script link
diff --git a/views/ngXosViews/vpnDashboard/src/js/main.js b/views/ngXosViews/vpnDashboard/src/js/main.js
index 7a576df..a93f720 100644
--- a/views/ngXosViews/vpnDashboard/src/js/main.js
+++ b/views/ngXosViews/vpnDashboard/src/js/main.js
@@ -45,20 +45,17 @@
controllerAs: 'vm',
templateUrl: 'templates/vpn-list.tpl.html',
controller: function(Vpn){
- // retrieving user list
Vpn.getVpnTenants()
.then((vpns) => {
this.vpns = vpns;
+ for (var i = 0; i < this.vpns.length; i++) {
+ var blob = new Blob([ this.vpns[i].script_text ], { type : 'text/plain' });
+ this.vpns[i].script_text = (window.URL || window.webkitURL).createObjectURL( blob );
+ }
})
.catch((e) => {
throw new Error(e);
});
-
- this.getScriptLocation = function(vpn) {
- var content = vpn.create_client_script();
- var blob = new Blob([ content ], { type : 'text/plain' });
- return (window.URL || window.webkitURL).createObjectURL( blob );
- }
}
};
});
diff --git a/views/ngXosViews/vpnDashboard/src/templates/vpn-list.tpl.html b/views/ngXosViews/vpnDashboard/src/templates/vpn-list.tpl.html
index 95d197f..a8fa8f3 100644
--- a/views/ngXosViews/vpnDashboard/src/templates/vpn-list.tpl.html
+++ b/views/ngXosViews/vpnDashboard/src/templates/vpn-list.tpl.html
@@ -13,7 +13,7 @@
<div class="cell">{{ vpn.server_network }}</div>
<div class="cell">{{ vpn.vpn_subnet }}</div>
<div class="cell">
- <a download="connect-{{ vpn.id }}.vpn" ng-href="{{ vm.getScriptLocation(vpn) }}">Script</a>
+ <a download="connect-{{ vpn.id }}.vpn" ng-href="{{ vpn.script_text }}">Script</a>
</div>
</div>
</div>
diff --git a/xos/core/xoslib/methods/vpnview.py b/xos/core/xoslib/methods/vpnview.py
index ccbb2e7..7a101f5 100644
--- a/xos/core/xoslib/methods/vpnview.py
+++ b/xos/core/xoslib/methods/vpnview.py
@@ -31,6 +31,7 @@
port_number = ReadOnlyField()
creator = ReadOnlyField()
instance = ReadOnlyField()
+ script_text = ReadOnlyField()
provider_service = serializers.PrimaryKeyRelatedField(queryset=VPNService.get_service_objects().all(), default=get_default_vpn_service)
humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
@@ -43,7 +44,7 @@
'service_specific_attribute', 'vpn_subnet',
'server_network', 'creator', 'instance',
'computeNodeName', 'is_persistent', 'clients_can_see_each_other',
- 'ca_crt', 'port_number')
+ 'ca_crt', 'port_number', 'script_text')
def getHumanReadableName(self, obj):
return obj.__unicode__()
@@ -56,18 +57,11 @@
class VPNTenantList(XOSListCreateAPIView):
serializer_class = VPNTenantSerializer
- queryset = VPNTenant.get_tenant_objects().all()
method_kind = "list"
method_name = "vpntenant"
-
-class ClientScript(APIView):
- method_kind = "detail"
- method_name = "clientscript"
-
- def get(self, request, format=None):
- if (not request.user.is_authenticated()):
- raise PermissionDenied("You must be authenticated in order to use this API")
- tenantId = request.QUERY_PARAMS.get('tenantId', None)
- serializer = VPNTenantSerializer(VPNTenant.get_tenant_objects().filter(id=tenantId)[0])
- return Response(serializer.data, status=HTTP_200_OK)
+ def get_queryset(self):
+ queryset = VPNTenant.get_tenant_objects().all()
+ for tenant in queryset:
+ tenant.script_text = tenant.create_client_script()
+ return queryset
diff --git a/xos/services/vpn/admin.py b/xos/services/vpn/admin.py
index bec46aa..35e1174 100644
--- a/xos/services/vpn/admin.py
+++ b/xos/services/vpn/admin.py
@@ -102,9 +102,6 @@
if (not self.instance.ca_crt):
self.instance.ca_crt = self.generate_ca_crt()
- if (not self.instance.script):
- self.instance.script = str(time.time()) + ".vpn"
-
return super(VPNTenantForm, self).save(commit=commit)
def generate_ca_crt(self):
diff --git a/xos/services/vpn/models.py b/xos/services/vpn/models.py
index 146168f..5f0a7d4 100644
--- a/xos/services/vpn/models.py
+++ b/xos/services/vpn/models.py
@@ -33,7 +33,8 @@
'clients_can_see_each_other': True,
'is_persistent': True,
'ca_crt': None,
- 'port': None}
+ 'port': None,
+ 'script_text': None}
def __init__(self, *args, **kwargs):
vpn_services = VPNService.get_service_objects().all()
@@ -139,6 +140,14 @@
def port_number(self, value):
self.set_attribute("port", value)
+ @property
+ def script_text(self):
+ return self.get_attribute("script_text", self.default_attributes['script_text'])
+
+ @script_text.setter
+ def script_text(self, value):
+ self.set_attribute("script_text", value)
+
def create_client_script(self):
script = ""
# write the configuration portion