root / templates / user_keys.html @ ff8bc42e
History | View | Annotate | Download (3.7 kB)
1 |
<div id="sshkeys_placeholder"> |
---|---|
2 |
<script>
|
3 |
$(document).ajaxSend(function(event, xhr, settings) {
|
4 |
function getCookie(name) {
|
5 |
var cookieValue = null;
|
6 |
if (document.cookie && document.cookie != '') {
|
7 |
var cookies = document.cookie.split(';');
|
8 |
for (var i = 0; i < cookies.length; i++) {
|
9 |
var cookie = jQuery.trim(cookies[i]);
|
10 |
// Does this cookie string begin with the name we want?
|
11 |
if (cookie.substring(0, name.length + 1) == (name + '=')) {
|
12 |
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
13 |
break;
|
14 |
}
|
15 |
}
|
16 |
}
|
17 |
return cookieValue;
|
18 |
}
|
19 |
function sameOrigin(url) {
|
20 |
// url could be relative or scheme relative or absolute
|
21 |
var host = document.location.host; // host + port
|
22 |
var protocol = document.location.protocol;
|
23 |
var sr_origin = '//' + host;
|
24 |
var origin = protocol + sr_origin;
|
25 |
// Allow absolute or scheme relative URLs to same origin
|
26 |
return (url == origin || url.slice(0, origin.length + 1) == origin + '/') ||
|
27 |
(url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') ||
|
28 |
// or any other URL that isn't scheme relative or absolute i.e relative.
|
29 |
!(/^(\/\/|http:|https:).*/.test(url));
|
30 |
}
|
31 |
function safeMethod(method) {
|
32 |
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
|
33 |
}
|
34 |
|
35 |
if (!safeMethod(settings.type) && sameOrigin(settings.url)) {
|
36 |
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
|
37 |
}
|
38 |
});
|
39 |
|
40 |
$(function() {
|
41 |
$('.remove_btn').button({
|
42 |
icons: {
|
43 |
primary: "ui-icon-circle-close"
|
44 |
},
|
45 |
text: false
|
46 |
})
|
47 |
$('#add_ssh_key_btn').button();
|
48 |
$('#add_ssh_key_btn').click(function() {
|
49 |
str = $('#sshkeyform').serialize();
|
50 |
$.ajax({
|
51 |
type: "POST",
|
52 |
url: "{% url user-keys %}",
|
53 |
data: str,
|
54 |
success: function(response){
|
55 |
// var $response=$(response);
|
56 |
// var resdata = $response.filter("#sshkeys_placeholder").html();
|
57 |
$("#sshkeys_placeholder").html(response);
|
58 |
}
|
59 |
});
|
60 |
return false;
|
61 |
});
|
62 |
$('a[id^="remove_key_"]').click(function() {
|
63 |
var $this = $(this);
|
64 |
var id = $this.attr("id");
|
65 |
var key_id = id.replace("remove_key_", "")
|
66 |
$.ajax({
|
67 |
type: "GET",
|
68 |
url: "{% url delete-key %}"+key_id,
|
69 |
success: function(response){
|
70 |
// var $response=$(response);
|
71 |
// var resdata = $response.filter("#sshkeys_placeholder").html();
|
72 |
$("#sshkeys_placeholder").html(response);
|
73 |
}
|
74 |
});
|
75 |
return false;
|
76 |
});
|
77 |
});
|
78 |
</script>
|
79 |
|
80 |
<style type="text/css"> |
81 |
.fingerprint { |
82 |
font-family: monospace; |
83 |
} |
84 |
</style>
|
85 |
{% load i18n %} |
86 |
<p>{% trans "Upload your SSH public keys and have them automatically installed on all newly-created instances. Keys must be in OpenSSH format, either RSA, or DSA, with or without a trailing comment." %}</p> |
87 |
|
88 |
{% if keys %} |
89 |
<table>
|
90 |
<tr><th>{% trans "Fingerprint" %}</th><th>{% trans "Comment" %}</th></tr> |
91 |
{% for key in keys %} |
92 |
<tr><td class="fingerprint">{{ key.fingerprint }}</td><td>{{ key.comment|default:"—" }}</td><td><a class="remove_btn" id="remove_key_{{key.id}}" href="#">{% trans "Delete" %}</a></tr> |
93 |
{% endfor %} |
94 |
</table>
|
95 |
{% endif %} |
96 |
<h2>{% trans "Add new key" %}</h2> |
97 |
{% if msg %} |
98 |
<div class="error">{{msg}}</div> |
99 |
{% endif %} |
100 |
<form method="POST" id="sshkeyform"> |
101 |
{% csrf_token %} |
102 |
{% if form.ssh_pubkey.errors %} |
103 |
<div class="error">{{ form.ssh_pubkey.errors }}</div> |
104 |
{% endif %} |
105 |
{{ form.ssh_pubkey }}<br /> |
106 |
<button id="add_ssh_key_btn">{% trans "Add key" %}</button> |
107 |
</form>
|
108 |
</div>
|
109 |
|