Allow users to delete ssh keys
This commit is contained in:
parent
ab29b138c3
commit
346733fbcd
6 changed files with 250 additions and 202 deletions
|
|
@ -85,7 +85,7 @@
|
|||
<ul id="g-account-menu" class="dropdown-menu" role="menu">
|
||||
<li><a href="{% url 'hosting:logout' %}"><i class="glyphicon glyphicon-lock"></i>{% trans "Logout"%} </a></li>
|
||||
<li>
|
||||
<a href="{% url 'hosting:key_pair' %}">
|
||||
<a href="{% url 'hosting:ssh_keys' %}">
|
||||
<i class="fa fa-key"></i> {% trans "Keys"%}
|
||||
</a>
|
||||
</li>
|
||||
|
|
@ -149,7 +149,7 @@
|
|||
<li>⋅</li>
|
||||
<li>
|
||||
<li>
|
||||
<a href="{% url 'hosting:key_pair' %}">
|
||||
<a href="{% url 'hosting:ssh_keys' %}">
|
||||
{% trans "Keys"%}
|
||||
</a>
|
||||
</li>
|
||||
|
|
|
|||
92
hosting/templates/hosting/user_key.html
Normal file
92
hosting/templates/hosting/user_key.html
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
{% extends "hosting/base_short.html" %}
|
||||
{% load staticfiles bootstrap3 i18n %}
|
||||
{% 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">
|
||||
<form method="POST" action="" novalidate>
|
||||
{% csrf_token %}
|
||||
<h3><i class="fa fa-key" aria-hidden="true"></i>{% trans "Access Key"%} </h3>
|
||||
{% if messages %}
|
||||
<div class="alert alert-warning">
|
||||
{% for message in messages %}
|
||||
<span>{{ message }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% for field in form %}
|
||||
{% bootstrap_field field %}
|
||||
{% endfor %}
|
||||
{% buttons %}
|
||||
<button type="submit" class="btn btn-success">
|
||||
{% trans "Upload your own key. "%}
|
||||
</button>
|
||||
<br />
|
||||
<br />
|
||||
{% trans "Or generate a new key pair."%} <br />
|
||||
<br />
|
||||
<button class="btn btn-success">{% trans "Generate Key Pair"%} </a>
|
||||
</button>
|
||||
|
||||
{% endbuttons %}
|
||||
</form>
|
||||
<h5> Use your created key to access to the machine. If you lost it, contact us. </h5>
|
||||
|
||||
{% if private_key %}
|
||||
<div class="alert alert-warning">
|
||||
|
||||
<strong>{% trans "Warning!"%}</strong>{% trans "You can download your SSH private key once. Don't lost your key"%}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<textarea class="form-control" rows="6" id="ssh_key" type="hidden" style="display:none">{{private_key}}</textarea>
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if private_key %}
|
||||
<!-- Force to download ssh key on page load -->
|
||||
<script type="text/javascript">
|
||||
|
||||
var key = window.document.getElementById('ssh_key');
|
||||
|
||||
var a = window.document.createElement('a');
|
||||
|
||||
a.href = window.URL.createObjectURL(new Blob([key.value], {type: 'text'}));
|
||||
a.download = '{{key_name}}.pem';
|
||||
|
||||
// Append anchor to body.
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
|
||||
// Remove anchor from body
|
||||
document.body.removeChild(a);
|
||||
|
||||
|
||||
</script>
|
||||
{%endif%}
|
||||
|
||||
{% if next_url %}
|
||||
<script type="text/javascript">
|
||||
window.location.href = '{{next_url}}';
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
{%endblock%}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
96
hosting/templates/hosting/user_keys.html
Normal file
96
hosting/templates/hosting/user_keys.html
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
{% extends "hosting/base_short.html" %}
|
||||
{% load staticfiles bootstrap3 i18n %}
|
||||
{% 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>{% trans "Access Key"%} </h3>
|
||||
{% if messages %}
|
||||
<div class="alert alert-warning">
|
||||
{% for message in messages %}
|
||||
<span>{{ message }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<p class="pull-right">
|
||||
<a class="btn btn-success" href="{% url 'hosting:create_ssh_key' %}" >{% trans "Add Key"%} </a>
|
||||
</p>
|
||||
<h5> Use your created key to access to the machine. If you lost it, contact us. </h5>
|
||||
<table class="table borderless table-hover">
|
||||
<br/>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "Name"%}</th>
|
||||
<th>{% trans "Created at"%} </th>
|
||||
<th>{% trans "Status"%} </th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for user_key in keys %}
|
||||
<tr>
|
||||
<td scope="row">{{user_key.name}}</td>
|
||||
<td>{{user_key.created_at}}</td>
|
||||
<td>
|
||||
<span class="h3 label label-success"><strong>Active</strong></span>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-default" data-toggle="modal"
|
||||
data-target="#Modal{{ user_key.id }}"><a
|
||||
href="#">{% trans "Delete Key"%}</a>
|
||||
</button>
|
||||
|
||||
<div class="modal fade" id="Modal{{user_key.id }}" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"
|
||||
aria-label="Confirm"><span
|
||||
aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<h4 class="modal-title" id="ModalLabel">{% trans "Do You want to delete this key?"%}</h4>
|
||||
|
||||
<form method="post" action="{% url 'hosting:delete_ssh_key' user_key.id %}">
|
||||
{% csrf_token %}
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default"
|
||||
data-dismiss="modal">
|
||||
{% trans "Close"%}
|
||||
</button>
|
||||
<button type="submit" class="btn btn-primary">{% trans "Delete"%}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
{% if next_url %}
|
||||
<script type="text/javascript">
|
||||
window.location.href = '{{next_url}}';
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
{%endblock%}
|
||||
|
||||
|
|
@ -1,163 +0,0 @@
|
|||
{% extends "hosting/base_short.html" %}
|
||||
{% load staticfiles bootstrap3 i18n %}
|
||||
{% 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">
|
||||
<form method="POST" action="" novalidate>
|
||||
{% csrf_token %}
|
||||
<h3><i class="fa fa-key" aria-hidden="true"></i>{% trans "Access Key"%} </h3>
|
||||
{% if messages %}
|
||||
<div class="alert alert-warning">
|
||||
{% for message in messages %}
|
||||
<span>{{ message }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% for field in form %}
|
||||
|
||||
{% bootstrap_field field %}
|
||||
{% endfor %}
|
||||
{% buttons %}
|
||||
<button type="submit" class="btn btn-success">
|
||||
{% trans "Upload your own key. "%}
|
||||
</button>
|
||||
<br />
|
||||
<br />
|
||||
{% trans "Or generate a new key pair."%} <br />
|
||||
<br />
|
||||
<button class="btn btn-success">{% trans "Generate Key Pair"%} </a>
|
||||
</button>
|
||||
|
||||
{% endbuttons %}
|
||||
<div class="form-group">
|
||||
</div>
|
||||
<h5> Use your created key to access to the machine. If you lost it, contact us. </h5>
|
||||
<table class="table borderless table-hover">
|
||||
<br/>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "Name"%}</th>
|
||||
<th>{% trans "Created at"%} </th>
|
||||
<th>{% trans "Status"%} </th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for user_key in keys %}
|
||||
<tr>
|
||||
<td scope="row">{{user_key.name}}</td>
|
||||
<td>{{user_key.created_at}}</td>
|
||||
<td>
|
||||
<span class="h3 label label-success"><strong>Active</strong></span>
|
||||
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-default" data-toggle="modal"
|
||||
data-target="#Modal{{ user_key.id }}"><a
|
||||
href="#">{% trans "Delete Key"%}</a>
|
||||
</button>
|
||||
<div class="modal fade" id="Modal{{user_key.id }}" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"
|
||||
aria-label="Confirm"><span
|
||||
aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<h4 class="modal-title" id="ModalLabel">{% trans "Do You want to delete this key?"%}</h4>
|
||||
|
||||
<form method="post"
|
||||
action="{% url 'hosting:delete_ssh_key' user_key.id %}">
|
||||
{% csrf_token %}
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default"
|
||||
data-dismiss="modal">
|
||||
{% trans "Close"%}
|
||||
</button>
|
||||
<button type="submit" class="btn btn-primary">{% trans "Delete"%}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
{% if private_key %}
|
||||
<div class="alert alert-warning">
|
||||
|
||||
<strong>{% trans "Warning!"%}</strong>{% trans "You can download your SSH private key once. Don't lost your key"%}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<textarea class="form-control" rows="6" id="ssh_key" type="hidden" style="display:none">{{private_key}}</textarea>
|
||||
|
||||
</div>
|
||||
<!-- <div class="form-group pull-right">
|
||||
<button type="button" id="copy_to_clipboard" data-clipboard-target="#ssh_key" class="btn btn-warning"
|
||||
data-toggle="tooltip" data-placement="bottom" title="Copied" data-trigger="click">{% trans "Copy to Clipboard"%}</button>
|
||||
<button type="button" id="download_ssh_key" class="btn btn-warning">{% trans "Download"%}</button>
|
||||
</div> -->
|
||||
{% else %}
|
||||
<!-- <div class="alert alert-warning">
|
||||
<strong>{% trans "Warning!"%}</strong>{% trans "Your SSH private key was already generated and downloaded, if you lost it, contact us. "%}
|
||||
</div>
|
||||
--> {% endif %}
|
||||
<!-- <a class="btn btn-success" href="{% url 'hosting:virtual_machines' %}">{% trans "Generate my key"%} </a> -->
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if private_key %}
|
||||
<!-- Force to download ssh key on page load -->
|
||||
<script type="text/javascript">
|
||||
|
||||
var key = window.document.getElementById('ssh_key');
|
||||
|
||||
var a = window.document.createElement('a');
|
||||
|
||||
a.href = window.URL.createObjectURL(new Blob([key.value], {type: 'text'}));
|
||||
a.download = '{{key_name}}.pem';
|
||||
|
||||
// Append anchor to body.
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
|
||||
// Remove anchor from body
|
||||
document.body.removeChild(a);
|
||||
|
||||
|
||||
</script>
|
||||
{%endif%}
|
||||
|
||||
{% if next_url %}
|
||||
<script type="text/javascript">
|
||||
window.location.href = '{{next_url}}';
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
{%endblock%}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue