Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes netbox-community#1132: Prompt user to unlock session key when i…
Browse files Browse the repository at this point in the history
…mporting secrets
jeremystretch committed May 3, 2017
1 parent 2d44e61 commit 3268b3c
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions netbox/project-static/js/secrets.js
Original file line number Diff line number Diff line change
@@ -15,8 +15,11 @@ $(document).ready(function() {
});

// Adding/editing a secret
$('form.requires-session-key').submit(function(event) {
if ($('#id_plaintext').val() && document.cookie.indexOf('session_key') == -1) {
$('form').submit(function(event) {
if (
$(this).find('input.requires-session-key').filter(function() {return this.value == ""}) &&
document.cookie.indexOf('session_key') == -1
) {
$('#privkey_modal').modal('show');
event.preventDefault();
}
4 changes: 2 additions & 2 deletions netbox/secrets/forms.py
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ class Meta:

class SecretForm(BootstrapMixin, forms.ModelForm):
plaintext = forms.CharField(max_length=65535, required=False, label='Plaintext',
widget=forms.PasswordInput())
widget=forms.PasswordInput(attrs={'class': 'requires-session-key'}))
plaintext2 = forms.CharField(max_length=65535, required=False, label='Plaintext (verify)',
widget=forms.PasswordInput())

@@ -82,7 +82,7 @@ def save(self, *args, **kwargs):


class SecretImportForm(BootstrapMixin, BulkImportForm):
csv = CSVDataField(csv_form=SecretFromCSVForm)
csv = CSVDataField(csv_form=SecretFromCSVForm, widget=forms.Textarea(attrs={'class': 'requires-session-key'}))


class SecretBulkEditForm(BootstrapMixin, BulkEditForm):
2 changes: 1 addition & 1 deletion netbox/templates/secrets/secret_edit.html
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
{% block title %}{% if secret.pk %}Editing {{ secret }}{% else %}Add a Secret{% endif %}{% endblock %}

{% block content %}
<form action="." method="post" class="form form-horizontal requires-session-key">
<form action="." method="post" class="form form-horizontal">
{% csrf_token %}
{{ form.private_key }}
<div class="row">

0 comments on commit 3268b3c

Please sign in to comment.