diff --git a/hosting/migrations/0018_virtualmachineplan_public_key.py b/hosting/migrations/0018_virtualmachineplan_public_key.py
new file mode 100644
index 00000000..bd869a48
--- /dev/null
+++ b/hosting/migrations/0018_virtualmachineplan_public_key.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.4 on 2016-05-24 03:57
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('hosting', '0017_virtualmachinetype_location'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='virtualmachineplan',
+ name='public_key',
+ field=models.TextField(default='sada'),
+ preserve_default=False,
+ ),
+ ]
diff --git a/hosting/models.py b/hosting/models.py
index 2d322aad..55709fca 100644
--- a/hosting/models.py
+++ b/hosting/models.py
@@ -1,12 +1,14 @@
-import json
+import os
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.functional import cached_property
-from django.core import serializers
from membership.models import StripeCustomer
from utils.models import BillingAddress
+from Crypto.PublicKey import RSA
+
+
from .managers import VMPlansManager
@@ -84,6 +86,7 @@ class VirtualMachinePlan(models.Model):
disk_size = models.IntegerField()
vm_type = models.ForeignKey(VirtualMachineType)
price = models.FloatField()
+ public_key = models.TextField()
objects = VMPlansManager()
@@ -104,20 +107,24 @@ class VirtualMachinePlan(models.Model):
instance = cls.objects.create(**data)
return instance
- @classmethod
+ @staticmethod
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")
+ public_key = new_key.publickey().exportKey("OpenSSH")
+ private_key = new_key.exportKey("PEM")
return private_key, public_key
+ def generate_keys(self):
+ private_key, public_key = self.generate_RSA()
+ self.public_key = public_key
+ self.save(update_fields=['public_key'])
+ return private_key
+
class HostingOrder(models.Model):
diff --git a/hosting/static/hosting/js/gen-ssh-key.js b/hosting/static/hosting/js/gen-ssh-key.js
new file mode 100644
index 00000000..46e701d7
--- /dev/null
+++ b/hosting/static/hosting/js/gen-ssh-key.js
@@ -0,0 +1,42 @@
+$( document ).ready(function() {
+
+
+
+
+
+ // Create a file with ssh private key info
+ function donwloadKeyFile(){
+
+ var key = $('#ssh_key').text();
+ var a = window.document.createElement('a');
+
+ a.href = window.URL.createObjectURL(new Blob([key], {type: 'text'}));
+ a.download = 'private_key.pem';
+
+ // Append anchor to body.
+ document.body.appendChild(a);
+ a.click();
+
+ // Remove anchor from body
+ document.body.removeChild(a);
+
+ }
+
+
+ // Create a file with ssh private key info
+ $('#download_ssh_key').on('click',donwloadKeyFile);
+
+
+ $('[data-toggle="tooltip"]').tooltip();
+
+ var clipboard = new Clipboard('#copy_to_clipboard');
+
+ clipboard.on('success', function(e) {
+ var selector = "#";
+ var copy_button_id = selector.concat(e.trigger.id);
+ setTimeout(function(){
+ $(copy_button_id).tooltip('hide');
+ }, 1000);
+ });
+
+});
\ No newline at end of file
diff --git a/hosting/templates/hosting/base_short.html b/hosting/templates/hosting/base_short.html
index cc41f453..a050a3d9 100644
--- a/hosting/templates/hosting/base_short.html
+++ b/hosting/templates/hosting/base_short.html
@@ -163,6 +163,9 @@
+
+
+