Merge pull request #76 from levivm/develop

Develop
This commit is contained in:
Levi Velázquez 2016-05-20 16:43:48 -04:30
commit b4bd728e35
9 changed files with 90 additions and 9 deletions

View file

@ -449,7 +449,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')

View file

@ -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):

View file

@ -150,6 +150,9 @@
<script src="{% static 'hosting/js/jquery.js' %}"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/jquery.validation/1.13.1/jquery.validate.min.js"></script>
<!-- Copy Clipboard -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.5.10/clipboard.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="{% static 'hosting/js/bootstrap.min.js' %}"></script>

View file

@ -8,7 +8,7 @@
{% block messages %}
{% if request.GET.logged_out %}
<div class="alert alert-warning"> <!-- singular -->
<div class="alert"> <!-- singular -->
<a class="close" data-dismiss="alert">×</a>
You haven been logged out
</div>
@ -23,7 +23,7 @@
{% for field in form %}
{% bootstrap_field field show_label=False type='fields'%}
{% endfor %}
{% bootstrap_form_errors form type='non_fields'%}
<p>{{form.non_field_errors|striptags}}</p>
{% buttons %}
<button type="submit" class="btn btn-default">
Login

View file

@ -0,0 +1,37 @@
{% extends "hosting/base_short.html" %}
{% load staticfiles bootstrap3 %}
{% block content %}
<div>
<div class="container virtual-machine-container dashboard-container ">
<div class="row">
<div class="col-md-9 col-md-offset-2">
<div class="col-sm-12">
<h3><i class="fa fa-key" aria-hidden="true"></i> Private Key</h3>
<hr/>
<div class="form-group">
<label for="comment">private_key.pem</label>
<textarea class="form-control" rows="8" id="ssh_key">{{private_key}}</textarea>
<span class="h3 pull-right"><button type="button" class="btn btn-default"><a href=""> Download </a></button></span>
<span class="h3 pull-right"><button type="button" data-clipboard-target="#ssh_key" class="btn btn-default">Copy to Clipboard</button></span>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
(function () {new Clipboard('.btn');})();
</script>
{%endblock%}

View file

@ -3,7 +3,7 @@ from django.conf.urls import url
from .views import DjangoHostingView, RailsHostingView, PaymentVMView, \
NodeJSHostingView, LoginView, SignupView, IndexView, \
OrdersHostingListView, OrdersHostingDetailView, VirtualMachinesPlanListView,\
OrdersHostingDeleteView,VirtualMachineDetailView
VirtualMachineDetailView, GenerateVMSSHKeysView, OrdersHostingDeleteView
urlpatterns = [
# url(r'pricing/?$', VMPricingView.as_view(), name='pricing'),
@ -18,6 +18,8 @@ urlpatterns = [
url(r'my-virtual-machines/?$', VirtualMachinesPlanListView.as_view(), name='virtual_machines'),
url(r'my-virtual-machines/(?P<pk>\d+)/?$', VirtualMachineDetailView.as_view(),
name='virtual_machines'),
url(r'my-virtual-machines/(?P<pk>\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',

View file

@ -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,DeleteView
from django.http import HttpResponseRedirect
from django.views.generic import View, CreateView, FormView, ListView, DetailView, UpdateView, DeleteView
from django.http import HttpResponseRedirect, HttpResponse
from django.contrib.auth import authenticate, login
from django.conf import settings
@ -145,6 +145,31 @@ 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')

View file

@ -17,6 +17,7 @@ django-mptt
easy_thumbnails
django-polymorphic
model-mommy
pycryptodome
#PLUGINS
djangocms_flash