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