diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py
index de339f86..5fd2d646 100644
--- a/dynamicweb/settings/base.py
+++ b/dynamicweb/settings/base.py
@@ -457,7 +457,6 @@ STRIPE_DESCRIPTION_ON_PAYMENT = "Payment for ungleich GmbH services"
REGISTRATION_MESSAGE = {'subject': "Validation mail",
'message': 'Thank You for registering for account on Digital Glarus.\nPlease verify Your account under following link http://{host}/en-us/digitalglarus/login/validate/{slug}',
}
-
STRIPE_API_PRIVATE_KEY = env('STRIPE_API_PRIVATE_KEY')
STRIPE_API_PUBLIC_KEY = env('STRIPE_API_PUBLIC_KEY')
diff --git a/hosting/management/commands/create_vm_types.py b/hosting/management/commands/create_vm_types.py
index 493e9e82..6be49f19 100644
--- a/hosting/management/commands/create_vm_types.py
+++ b/hosting/management/commands/create_vm_types.py
@@ -13,7 +13,7 @@ class Command(BaseCommand):
'memory_price': 5,
'disk_size_price': 1,
'description': 'VM auf einzelner HW, Raid1, kein HA',
- 'location':'DE'
+ 'location': 'DE'
}
return {
@@ -46,7 +46,7 @@ class Command(BaseCommand):
'memory_price': 7,
'disk_size_price': 0.70,
'description': "VM in Bern, HA Setup ohne HA Garantie",
- 'location':'CH',
+ 'location': 'CH',
}
}
diff --git a/hosting/models.py b/hosting/models.py
index e2775fc4..2d322aad 100644
--- a/hosting/models.py
+++ b/hosting/models.py
@@ -104,6 +104,20 @@ class VirtualMachinePlan(models.Model):
instance = cls.objects.create(**data)
return instance
+ @classmethod
+ def generate_RSA(bits=2048):
+ '''
+ Generate an RSA keypair with an exponent of 65537 in PEM format
+ param: bits The key length in bits
+ Return private key and public key
+ '''
+ from Crypto.PublicKey import RSA
+ import os
+ new_key = RSA.generate(2048, os.urandom)
+ public_key = new_key.publickey()
+ private_key = new_key.exportKey("OpenSSH")
+ return private_key, public_key
+
class HostingOrder(models.Model):
diff --git a/hosting/templates/hosting/base_short.html b/hosting/templates/hosting/base_short.html
index 8b3f0dbb..cc41f453 100644
--- a/hosting/templates/hosting/base_short.html
+++ b/hosting/templates/hosting/base_short.html
@@ -150,6 +150,9 @@
+
+
+
diff --git a/hosting/templates/hosting/login.html b/hosting/templates/hosting/login.html
index 0c772da6..d88d740c 100644
--- a/hosting/templates/hosting/login.html
+++ b/hosting/templates/hosting/login.html
@@ -8,7 +8,7 @@
{% block messages %}
{% if request.GET.logged_out %}
-
+
×
You haven been logged out
@@ -23,7 +23,7 @@
{% for field in form %}
{% bootstrap_field field show_label=False type='fields'%}
{% endfor %}
- {% bootstrap_form_errors form type='non_fields'%}
+
{{form.non_field_errors|striptags}}
{% buttons %}
Login
diff --git a/hosting/templates/hosting/virtual_machine_key.html b/hosting/templates/hosting/virtual_machine_key.html
new file mode 100644
index 00000000..d2c79fd4
--- /dev/null
+++ b/hosting/templates/hosting/virtual_machine_key.html
@@ -0,0 +1,37 @@
+{% extends "hosting/base_short.html" %}
+{% load staticfiles bootstrap3 %}
+{% block content %}
+
+
+{%endblock%}
+
+
+
+
+
+
+
+
+
diff --git a/hosting/urls.py b/hosting/urls.py
index 67bf9e5e..9801e100 100644
--- a/hosting/urls.py
+++ b/hosting/urls.py
@@ -3,7 +3,7 @@ from django.conf.urls import url
from .views import DjangoHostingView, RailsHostingView, PaymentVMView, \
NodeJSHostingView, LoginView, SignupView, IndexView, \
OrdersHostingListView, OrdersHostingDetailView, VirtualMachinesPlanListView,\
- VirtualMachineDetailView
+ VirtualMachineDetailView, GenerateVMSSHKeysView
urlpatterns = [
# url(r'pricing/?$', VMPricingView.as_view(), name='pricing'),
@@ -17,6 +17,8 @@ urlpatterns = [
url(r'my-virtual-machines/?$', VirtualMachinesPlanListView.as_view(), name='virtual_machines'),
url(r'my-virtual-machines/(?P\d+)/?$', VirtualMachineDetailView.as_view(),
name='virtual_machines'),
+ url(r'my-virtual-machines/(?P\d+)/key/?$', GenerateVMSSHKeysView.as_view(),
+ name='virtual_machine_key'),
url(r'login/?$', LoginView.as_view(), name='login'),
url(r'signup/?$', SignupView.as_view(), name='signup'),
url(r'^logout/?$', 'django.contrib.auth.views.logout',
diff --git a/hosting/views.py b/hosting/views.py
index 83fa16a0..8478be74 100644
--- a/hosting/views.py
+++ b/hosting/views.py
@@ -3,8 +3,8 @@ from django.shortcuts import get_object_or_404, render
from django.core.urlresolvers import reverse_lazy, reverse
from django.contrib.auth.mixins import LoginRequiredMixin
-from django.views.generic import View, CreateView, FormView, ListView, DetailView
-from django.http import HttpResponseRedirect
+from django.views.generic import View, CreateView, FormView, ListView, DetailView, UpdateView
+from django.http import HttpResponseRedirect, HttpResponse
from django.contrib.auth import authenticate, login
from django.conf import settings
@@ -145,6 +145,30 @@ class SignupView(CreateView):
return HttpResponseRedirect(self.get_success_url())
+class GenerateVMSSHKeysView(LoginRequiredMixin, UpdateView):
+ model = VirtualMachinePlan
+ template_name = 'hosting/virtual_machine_key.html'
+ success_url = reverse_lazy('hosting:orders')
+
+ def get_context_data(self, **kwargs):
+ private_key, public_key = VirtualMachinePlan.generate_RSA()
+ context = {
+ 'private_key': private_key
+ }
+ return context
+
+ # def get(self, *args, **kwargs):
+ # vm = self.get_object()
+ # private_key, public_key = VirtualMachinePlan.generate_RSA()
+ # print(private_key)
+ # print(public_key)
+ # key_name = "private_key"
+ # response = HttpResponse(content_type='text/plain')
+ # response['Content-Disposition'] = 'attachment; filename="%s.pem"' % key_name
+ # response.write(private_key)
+ # return response
+ # return HttpResponseRedirect(reverse(''))
+
class PaymentVMView(LoginRequiredMixin, FormView):
template_name = 'hosting/payment.html'
login_url = reverse_lazy('hosting:login')
diff --git a/requirements.txt b/requirements.txt
index 13ea5675..dcf2b02b 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -17,6 +17,7 @@ django-mptt
easy_thumbnails
django-polymorphic
model-mommy
+pycryptodome
#PLUGINS
djangocms_flash