Skip to content

Commit

Permalink
[ADD] Possibility to copy values from alerts table
Browse files Browse the repository at this point in the history
  • Loading branch information
whikernel committed Nov 9, 2024
1 parent d31acf1 commit 8d03428
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 9 deletions.
22 changes: 21 additions & 1 deletion source/app/static/assets/css/atlantis.css
Original file line number Diff line number Diff line change
Expand Up @@ -16027,4 +16027,24 @@ td.dt-nowrap { white-space: nowrap }
padding: 2px 5px 2px 5px;
border-radius: 50% 50%;
margin-bottom: 3px;
}
}

.copy-value {
position: relative;
}

.copy-btn {
display: none;
position: absolute;
top: 50%;
transform: translateY(-50%);
border: none;
background: transparent;
font-size: 1rem;
color: #007bff;
cursor: pointer;
}

.copy-value:hover .copy-btn {
display: inline;
}
46 changes: 40 additions & 6 deletions source/app/static/assets/js/iris/alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,23 +988,41 @@ function renderAlert(alert, expanded=false, modulesOptionsAlertReq,
</div>` : ''}
${alert.alert_source_link ? `<div class="row mt-2">
<div class="col-md-3"><b>Source Link:</b></div>
<div class="col-md-9">${
<div class="col-md-9 copy-value">${
alert.alert_source_link && alert.alert_source_link.startsWith('http')
? `<a href="${alert.alert_source_link}">${alert.alert_source_link}</a>`
? `<a href="${alert.alert_source_link}" target="_blank" rel="noopener noreferrer">${alert.alert_source_link}</a>
<button class="copy-btn ml-2" data-value="${escapeHtml(alert.alert_source_link)}">
<i class="fa fa-copy text-dark"></i>
</button>`
: 'No valid link provided'
}</div>
</div>` : ''}
${alert.alert_source_ref ? `<div class="row mt-2">
<div class="col-md-3"><b>Source Reference:</b></div>
<div class="col-md-9">${alert.alert_source_ref}</div>
<div class="col-md-9 copy-value">
${alert.alert_source_ref}
<button class="copy-btn ml-2" data-value="${escapeHtml(alert.alert_source_ref)}">
<i class="fa fa-copy text-dark"></i>
</button>
</div>
</div>` : ''}
${alert.alert_source_event_time ? `<div class="row mt-2">
<div class="col-md-3"><b>Source Event Time:</b></div>
<div class="col-md-9">${formatTime(alert.alert_source_event_time)} UTC</div>
<div class="col-md-9 copy-value">
${formatTime(alert.alert_source_event_time)} UTC
<button class="copy-btn ml-2" data-value="${formatTime(alert.alert_source_event_time)}">
<i class="fa fa-copy text-dark"></i>
</button>
</div>
</div>` : ''}
${alert.alert_creation_time ? `<div class="row mt-2">
<div class="col-md-3"><b>IRIS Creation Time:</b></div>
<div class="col-md-9">${formatTime(alert.alert_creation_time)} UTC</div>
<div class="col-md-9 copy-value">
${formatTime(alert.alert_creation_time)} UTC
<button class="copy-btn ml-2" data-value="${formatTime(alert.alert_creation_time)}">
<i class="fa fa-copy text-dark"></i>
</button>
</div>
</div>` : ''}
<div class="separator-solid"></div>
Expand Down Expand Up @@ -1094,7 +1112,12 @@ function renderAlert(alert, expanded=false, modulesOptionsAlertReq,
.map(
(ioc) => `
<tr>
<td>${filterXSS(ioc.ioc_value)}</td>
<td class="copy-value">
${filterXSS(ioc.ioc_value)}
<button class="copy-btn ml-2" data-value="${filterXSS(ioc.ioc_value)}">
<i class="fa fa-copy text-dark"></i>
</button>
</td>
<td>${filterXSS(ioc.ioc_description)}</td>
<td>${ioc.ioc_type ? filterXSS(ioc.ioc_type.type_name) : '-'}</td>
<td>${filterXSS(ioc.ioc_tlp) ? ioc.ioc_tlp : '-'}</td>
Expand Down Expand Up @@ -1146,6 +1169,12 @@ function renderAlert(alert, expanded=false, modulesOptionsAlertReq,
.map(
(asset) => `
<tr>
<td class="copy-value">
${asset.asset_name ? filterXSS(asset.asset_name) : '-'}
<button class="copy-btn ml-2" data-value="${asset.asset_name ? filterXSS(asset.asset_name) : '-'}">
<i class="fa fa-copy text-dark"></i>
</button>
</td>
<td>${asset.asset_name ? filterXSS(asset.asset_name) : '-'}</td>
<td>${asset.asset_description ? filterXSS(asset.asset_description) : '-'}</td>
<td>${asset.asset_type ? filterXSS(asset.asset_type.asset_name) : '-'}</td>
Expand Down Expand Up @@ -1417,6 +1446,11 @@ async function updateAlerts(page, per_page, filters = {}, paging=false){
filterString || queryParams.get('filter_id') ? $('#resetFilters').show() : $('#resetFilters').hide();

alertsContainer.show();

$('.copy-btn').off().on('click', function() {
let value = $(this).data('value');
copy_text_clipboard(value);
});
}

$('#alertsPerPage').on('change', (e) => {
Expand Down
4 changes: 2 additions & 2 deletions source/app/static/assets/js/iris/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ function copy_object_link_md(data_type, node_id){

function copy_text_clipboardb(data){
navigator.clipboard.writeText(fromBinary64(data)).then(function() {
notify_success('Copied!');
notify_success('Copied');
}, function(err) {
notify_error('Can\'t copy link. I printed it in console.');
console.error(err);
Expand All @@ -635,7 +635,7 @@ function copy_text_clipboardb(data){

function copy_text_clipboard(data){
navigator.clipboard.writeText(data).then(function() {
notify_success('Copied!');
notify_success('Copied');
}, function(err) {
notify_error('Can\'t copy link. I printed it in console.');
console.error(err);
Expand Down

0 comments on commit 8d03428

Please sign in to comment.