Parcourir la source

Fixes #370: Notify user when secret decryption fails

Jeremy Stretch il y a 8 ans
Parent
commit
b62cd32428

+ 11 - 7
netbox/project-static/js/secrets.js

@@ -10,15 +10,16 @@ $(document).ready(function() {
             $('#privkey_modal').modal('show');
         } else {
             unlock_secret(secret_id, private_key);
-            $(this).hide();
-            $(this).siblings('button.lock-secret').show();
         }
     });
 
     // Locking a secret
     $('button.lock-secret').click(function (event) {
         var secret_id = $(this).attr('secret-id');
-        $('#secret_' + secret_id).html('********');
+        var secret_div = $('#secret_' + secret_id);
+
+        // Delete the plaintext
+        secret_div.html('********');
         $(this).hide();
         $(this).siblings('button.unlock-secret').show();
     });
@@ -81,13 +82,16 @@ $(document).ready(function() {
                 xhr.setRequestHeader("X-CSRFToken", csrf_token);
             },
             success: function (response, status) {
-                var secret_plaintext = response.plaintext;
-                $('#secret_' + secret_id).html(secret_plaintext);
-                return true;
+                $('#secret_' + secret_id).html(response.plaintext);
+                $('button.unlock-secret').hide();
+                $('button.lock-secret').show();
             },
             error: function (xhr, ajaxOptions, thrownError) {
                 if (xhr.status == 403) {
-                    alert("Decryption failed: " + xhr.statusText);
+                    alert("Permission denied");
+                } else {
+                    var json = jQuery.parseJSON(xhr.responseText);
+                    alert("Decryption failed: " + json['error']);
                 }
             }
         });

+ 4 - 1
netbox/templates/secrets/inc/private_key_modal.html

@@ -17,7 +17,10 @@
                     <textarea class="form-control" id="user_privkey" style="height: 300px;"></textarea>
                 </div>
                 <div class="form-group text-right">
-                    <button id="submit_privkey" class="btn btn-primary unlock-secret" data-dismiss="modal">Submit RSA Key</button>
+                    <button id="submit_privkey" class="btn btn-primary unlock-secret" data-dismiss="modal">
+                        <i class="fa fa-save" aria-hidden="True"></i>
+                        Save RSA Key
+                    </button>
                 </div>
             </div>
         </div>