1 <div id="sshkeys_placeholder">
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));
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));
31 function safeMethod(method) {
32 return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
35 if (!safeMethod(settings.type) && sameOrigin(settings.url)) {
36 xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
41 $('.remove_btn').button({
43 primary: "ui-icon-circle-close"
47 $('#add_ssh_key_btn').button();
48 $('#add_ssh_key_btn').click(function() {
49 str = $('#sshkeyform').serialize();
52 url: "{% url user-keys %}",
54 success: function(response){
55 // var $response=$(response);
56 // var resdata = $response.filter("#sshkeys_placeholder").html();
57 $("#sshkeys_placeholder").html(response);
62 $('a[id^="remove_key_"]').click(function() {
64 var id = $this.attr("id");
65 var key_id = id.replace("remove_key_", "")
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);
80 <style type="text/css">
82 font-family: monospace;
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>
90 <tr><th>{% trans "Fingerprint" %}</th><th>{% trans "Comment" %}</th></tr>
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>
96 <h2>{% trans "Add new key" %}</h2>
98 <div class="error">{{msg}}</div>
100 <form method="POST" id="sshkeyform">
102 {% if form.ssh_pubkey.errors %}
103 <div class="error">{{ form.ssh_pubkey.errors }}</div>
105 {{ form.ssh_pubkey }}<br />
106 <button id="add_ssh_key_btn">{% trans "Add key" %}</button>