Communication from CN to Mongo id

This commit is contained in:
Marvin Martinson 2021-06-01 19:20:39 +00:00
parent 4254a9c567
commit 974b3e5bb2
4 changed files with 28 additions and 25 deletions

View File

@ -30,19 +30,19 @@ function onLaunchShell(common_name) {
return false; return false;
} }
function onRejectRequest(e, common_name, sha256sum) { function onRejectRequest(e, id, sha256sum) {
$(this).button('loading'); $(this).button('loading');
$.ajax({ $.ajax({
url: "/api/request/" + common_name + "/?sha256sum=" + sha256sum, url: "/api/request/id/" + id + "/?sha256sum=" + sha256sum,
type: "delete" type: "delete"
}); });
} }
function onSignRequest(e, common_name, sha256sum) { function onSignRequest(e, id, sha256sum) {
e.preventDefault(); e.preventDefault();
$(e.target).button('loading'); $(e.target).button('loading');
$.ajax({ $.ajax({
url: "/api/request/" + common_name + "/?sha256sum=" + sha256sum, url: "/api/request/id/" + id + "/?sha256sum=" + sha256sum,
type: "post" type: "post"
}); });
return false; return false;
@ -284,6 +284,7 @@ function onHashChanged() {
function onTagClicked(e) { function onTagClicked(e) {
e.preventDefault(); e.preventDefault();
var cn = $(e.target).attr("data-cn"); var cn = $(e.target).attr("data-cn");
var cert_id = $(e.target).attr("data-id");
var id = $(e.target).attr("title"); var id = $(e.target).attr("title");
var value = $(e.target).html(); var value = $(e.target).html();
var updated = prompt("Enter new tag or clear to remove the tag", value); var updated = prompt("Enter new tag or clear to remove the tag", value);
@ -291,13 +292,13 @@ function onTagClicked(e) {
$(event.target).addClass("disabled"); $(event.target).addClass("disabled");
$.ajax({ $.ajax({
method: "DELETE", method: "DELETE",
url: "/api/signed/" + cn + "/tag/" + id + "/" url: "/api/signed/id/" + cert_id + "/tag/" + id + "/"
}); });
} else if (updated && updated != value) { } else if (updated && updated != value) {
$(e.target).addClass("disabled"); $(e.target).addClass("disabled");
$.ajax({ $.ajax({
method: "PUT", method: "PUT",
url: "/api/signed/" + cn + "/tag/" + id + "/", url: "/api/signed/id/" + cert_id + "/tag/" + id + "/",
data: { value: updated }, data: { value: updated },
dataType: "text", dataType: "text",
complete: function(xhr, status) { complete: function(xhr, status) {
@ -319,13 +320,14 @@ function onNewTagClicked(e) {
var cn = $(e.target).attr("data-cn"); var cn = $(e.target).attr("data-cn");
var key = $(e.target).attr("data-key"); var key = $(e.target).attr("data-key");
var value = prompt("Enter new " + key + " tag for " + cn); var value = prompt("Enter new " + key + " tag for " + cn);
var id = $(e.target).attr("data-id");
if (!value) return; if (!value) return;
if (value.length == 0) return; if (value.length == 0) return;
var $container = $(".tags[data-cn='" + cn + "']"); var $container = $(".tags[data-id='" + id + "']");
$container.addClass("disabled"); $container.addClass("disabled");
$.ajax({ $.ajax({
method: "POST", method: "POST",
url: "/api/signed/" + cn + "/tag/", url: "/api/signed/id/" + id + "/tag/",
data: { value: value, key: key }, data: { value: value, key: key },
dataType: "text", dataType: "text",
complete: function(xhr, status) { complete: function(xhr, status) {
@ -446,18 +448,19 @@ function onCertificateRevoked(e) {
} }
function onTagUpdated(e) { function onTagUpdated(e) {
var cn = e.data; var id = e.data;
console.log("Tag updated event recevied", cn);
console.log("Tag updated event recevied", id);
$.ajax({ $.ajax({
method: "GET", method: "GET",
url: "/api/signed/" + cn + "/tag/", url: "/api/signed/id/" + id + "/tag/",
dataType: "json", dataType: "json",
success:function(tags, status, xhr) { success:function(tags, status, xhr) {
console.info("Updated", cn, "tags", tags); console.info("Updated", id, "tags", tags);
$(".tags[data-cn='" + cn+"']").html( $(".tags[data-id='" + id+"']").html(
env.render('views/tags.html', { env.render('views/tags.html', {
certificate: { certificate: {
common_name: cn, id:id,
tags:tags }})); tags:tags }}));
} }
}) })

View File

@ -19,11 +19,11 @@
<button type="button" class="btn btn-secondary" data-toggle="collapse" data-target="#details-{{ request.sha256sum }}"><i class="fa fa-list"></i> Details</button> <button type="button" class="btn btn-secondary" data-toggle="collapse" data-target="#details-{{ request.sha256sum }}"><i class="fa fa-list"></i> Details</button>
<button type="button" class="btn btn-danger" <button type="button" class="btn btn-danger"
data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Rejecting..." data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Rejecting..."
onclick="onRejectRequest(event, '{{ request.common_name }}', '{{ request.sha256sum }}');"> onclick="onRejectRequest(event, '{{ request.id }}', '{{ request.sha256sum }}');">
<i class="fa fa-trash"></i> Reject</button> <i class="fa fa-trash"></i> Reject</button>
<button type="button" class="btn btn-success" <button type="button" class="btn btn-success"
data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Processing Order" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Processing Order"
onclick="onSignRequest(event, '{{ request.common_name }}', '{{ request.sha256sum }}');"> onclick="onSignRequest(event, '{{ request.id }}', '{{ request.sha256sum }}');">
<i class="fa fa-thumbs-up"></i> Approve</button> <i class="fa fa-thumbs-up"></i> Approve</button>
<button type="button" class="btn btn-success dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <button type="button" class="btn btn-success dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span> <span class="sr-only">Toggle Dropdown</span>
@ -32,7 +32,7 @@
{% for p in authority.signature.profiles %} {% for p in authority.signature.profiles %}
<a class="dropdown-item{% if not request.common_name.match(p.common_name) %} disabled{% endif %}" <a class="dropdown-item{% if not request.common_name.match(p.common_name) %} disabled{% endif %}"
{% if not request.common_name.match(p.common_name) %} title="Common name doesn't match expression {{ p.common_name }}"{% endif %} {% if not request.common_name.match(p.common_name) %} title="Common name doesn't match expression {{ p.common_name }}"{% endif %}
href="#" onclick="javascript:$.ajax({url:'/api/request/{{request.common_name}}/?sha256sum={{ request.sha256sum }}&profile={{ p.key }}',type:'post'});"> href="#" onclick="javascript:$.ajax({url:'/api/request/id/{{request.id}}/?sha256sum={{ request.sha256sum }}&profile={{ p.key }}',type:'post'});">
{{ p.key }}, expires in {{ p.lifetime }} days</a> {{ p.key }}, expires in {{ p.lifetime }} days</a>
{% endfor %} {% endfor %}
</div> </div>

View File

@ -29,7 +29,7 @@
</p> </p>
<p> <p>
{% if session.tagging %} {% if session.tagging %}
<span class="tags" data-cn="{{ certificate.common_name }}"> <span class="tags" data-cn="{{ certificate.common_name }}" data-id="{{ certificate.id }}">
{% include "views/tags.html" %} {% include "views/tags.html" %}
</span> </span>
{% endif %} {% endif %}
@ -41,24 +41,24 @@
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-secondary" data-toggle="collapse" data-target="#details-{{ certificate.sha256sum }}"><i class="fa fa-list"></i> Details</button> <button type="button" class="btn btn-secondary" data-toggle="collapse" data-target="#details-{{ certificate.sha256sum }}"><i class="fa fa-list"></i> Details</button>
<button type="button" class="btn btn-danger" <button type="button" class="btn btn-danger"
onclick="javascript:$(this).button('loading');$.ajax({url:'/api/signed/{{certificate.common_name}}/?sha256sum={{ certificate.sha256sum }}',type:'delete'});"> onclick="javascript:$(this).button('loading');$.ajax({url:'/api/signed/id/{{certificate.id}}/?sha256sum={{ certificate.sha256sum }}',type:'delete'});">
<i class="fa fa-ban"></i> Revoke</button> <i class="fa fa-ban"></i> Revoke</button>
<button type="button" class="btn btn-danger dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <button type="button" class="btn btn-danger dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span> <span class="sr-only">Toggle Dropdown</span>
</button> </button>
<div class="dropdown-menu"> <div class="dropdown-menu">
<a class="dropdown-item" href="#" <a class="dropdown-item" href="#"
onclick="javascript:$(this).button('loading');$.ajax({url:'/api/signed/{{certificate.common_name}}/?sha256sum={{ certificate.sha256sum }}&reason=key_compromise',type:'delete'});">Revoke due to key compromise</a> onclick="javascript:$(this).button('loading');$.ajax({url:'/api/signed/id/{{certificate.id}}/?sha256sum={{ certificate.sha256sum }}&reason=key_compromise',type:'delete'});">Revoke due to key compromise</a>
<a class="dropdown-item" href="#" <a class="dropdown-item" href="#"
onclick="javascript:$(this).button('loading');$.ajax({url:'/api/signed/{{certificate.common_name}}/?sha256sum={{ certificate.sha256sum }}&reason=cessation_of_operation',type:'delete'});">Revoke due to cessation of operation</a> onclick="javascript:$(this).button('loading');$.ajax({url:'/api/signed/id/{{certificate.id}}/?sha256sum={{ certificate.sha256sum }}&reason=cessation_of_operation',type:'delete'});">Revoke due to cessation of operation</a>
<a class="dropdown-item" href="#" <a class="dropdown-item" href="#"
onclick="javascript:$(this).button('loading');$.ajax({url:'/api/signed/{{certificate.common_name}}/?sha256sum={{ certificate.sha256sum }}&reason=privilege_withdrawn',type:'delete'});">Revoke due to withdrawn privilege</a> onclick="javascript:$(this).button('loading');$.ajax({url:'/api/signed/id/{{certificate.id}}/?sha256sum={{ certificate.sha256sum }}&reason=privilege_withdrawn',type:'delete'});">Revoke due to withdrawn privilege</a>
</div> </div>
</div> </div>
<div class="btn-group"> <div class="btn-group">
{% if session.tagging %} {% if session.tagging %}
<button type="button" class="btn btn-default" onclick="onNewTagClicked(event);" data-key="other" data-cn="{{ certificate.common_name }}"> <button type="button" class="btn btn-default" onclick="onNewTagClicked(event);" data-key="other" data-cn="{{ certificate.common_name }}" data-id="{{ certificate.id }}">
<i class="fa fa-tag"></i> Tag</button> <i class="fa fa-tag"></i> Tag</button>
<button type="button" class="btn btn-default dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <button type="button" class="btn btn-default dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span> <span class="sr-only">Toggle Dropdown</span>
@ -66,7 +66,7 @@
<div class="dropdown-menu"> <div class="dropdown-menu">
{% for tag_category in session.tagging %} {% for tag_category in session.tagging %}
<a class="dropdown-item" href="#" data-key="{{ tag_category.name }}" data-cn="{{ certificate.common_name }}" <a class="dropdown-item" href="#" data-key="{{ tag_category.name }}" data-cn="{{ certificate.common_name }}"
onclick="onNewTagClicked(event);">{{ tag_category.title }}</a> onclick="onNewTagClicked(event);" data-id="{{ certificate.id }}">{{ tag_category.title }}</a>
{% endfor %} {% endfor %}
</div> </div>
{% endif %} {% endif %}

View File

@ -1,5 +1,5 @@
{% for tag in certificate.tags %} {% for tag in certificate.tags %}
<span data-cn="{{ certificate.common_name }}" <span data-id="{{ certificate.id }}"
title="{{ tag }}" title="{{ tag }}"
class="badge badge-default" class="badge badge-default"
onClick="onTagClicked(event);">{{ tag }}</span> onClick="onTagClicked(event);">{{ tag }}</span>