Merge pull request #6347 from JakubOnderka/hex-binary-convertor

Hex binary convertor
pull/6350/head
Jakub Onderka 2020-09-26 19:32:10 +02:00 committed by GitHub
commit 5a7fe2a576
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 81 deletions

View File

@ -64,9 +64,8 @@ switch ($object['type']) {
break;
case 'hex':
$sigDisplay = str_replace("\r", '', $sigDisplay);
echo '<span class="hex-value" title="' . __('Hexadecimal representation') . '">' . nl2br(h($sigDisplay)) . '</span>&nbsp;';
echo '<span role="button" tabindex="0" aria-label="' . __('Switch to binary representation') . '" class="icon-repeat hex-value-convert useCursorPointer" title="' . __('Switch to binary representation') . '"></span>';
echo '<span class="hex-value" title="' . __('Hexadecimal representation') . '">' . h($sigDisplay) . '</span>&nbsp;';
echo '<span role="button" tabindex="0" aria-label="' . __('Switch to binary representation') . '" class="fas fa-redo hex-value-convert useCursorPointer" title="' . __('Switch to binary representation') . '"></span>';
break;
/** @noinspection PhpMissingBreakStatementInspection */

View File

@ -117,32 +117,6 @@
screenshotPopup($(this).attr('src'), $(this).attr('title'));
});
});
$('.hex-value-convert').click(function() {
var val = $(this).parent().children(':first-child').text();
if ($(this).parent().children(':first-child').attr('data-original-title') == 'Hexadecimal representation') {
var bin = [];
var temp;
val.split('').forEach(function(entry) {
temp = parseInt(entry, 16).toString(2);
bin.push(Array(5 - (temp.length)).join('0') + temp);
});
bin = bin.join(' ');
$(this).parent().children(':first-child').text(bin);
$(this).parent().children(':first-child').attr('data-original-title', __('Binary representation'));
$(this).parent().children(':nth-child(2)').attr('data-original-title', __('Switch to hexadecimal representation'));
$(this).parent().children(':nth-child(2)').attr('aria-label', __('Switch to hexadecimal representation'));
} else {
val = val.split(' ');
hex = '';
val.forEach(function(entry) {
hex += parseInt(entry , 2).toString(16).toUpperCase();
});
$(this).parent().children(':first-child').text(hex);
$(this).parent().children(':first-child').attr('data-original-title', __('Hexadecimal representation'));
$(this).parent().children(':nth-child(2)').attr('data-original-title', __('Switch to binary representation'));
$(this).parent().children(':nth-child(2)').attr('aria-label', __('Switch to binary representation'));
}
});
</script>
<?php
echo $this->Js->writeBuffer();

View File

@ -117,32 +117,6 @@
screenshotPopup($(this).attr('src'), $(this).attr('title'));
});
});
$('.hex-value-convert').click(function() {
var val = $(this).parent().children(':first-child').text();
if ($(this).parent().children(':first-child').attr('data-original-title') == 'Hexadecimal representation') {
var bin = [];
var temp;
val.split('').forEach(function(entry) {
temp = parseInt(entry, 16).toString(2);
bin.push(Array(5 - (temp.length)).join('0') + temp);
});
bin = bin.join(' ');
$(this).parent().children(':first-child').text(bin);
$(this).parent().children(':first-child').attr('data-original-title', __('Binary representation'));
$(this).parent().children(':nth-child(2)').attr('data-original-title', __('Switch to hexadecimal representation'));
$(this).parent().children(':nth-child(2)').attr('aria-label', __('Switch to hexadecimal representation'));
} else {
val = val.split(' ');
hex = '';
val.forEach(function(entry) {
hex += parseInt(entry , 2).toString(16).toUpperCase();
});
$(this).parent().children(':first-child').text(hex);
$(this).parent().children(':first-child').attr('data-original-title', __('Hexadecimal representation'));
$(this).parent().children(':nth-child(2)').attr('data-original-title', __('Switch to binary representation'));
$(this).parent().children(':nth-child(2)').attr('aria-label', __('Switch to binary representation'));
}
});
</script>
<?php
echo $this->Js->writeBuffer();

View File

@ -369,32 +369,6 @@ attributes or the appropriate distribution level. If you think there is a mistak
filterAttributes('value', eventid);
}
});
$('.hex-value-convert').click(function() {
var val = $(this).parent().children(':first-child').text();
if ($(this).parent().children(':first-child').attr('data-original-title') == 'Hexadecimal representation') {
var bin = [];
var temp;
val.split('').forEach(function(entry) {
temp = parseInt(entry, 16).toString(2);
bin.push(Array(5 - (temp.length)).join('0') + temp);
});
bin = bin.join(' ');
$(this).parent().children(':first-child').text(bin);
$(this).parent().children(':first-child').attr('data-original-title', 'Binary representation');
$(this).parent().children(':nth-child(2)').attr('data-original-title', 'Switch to hexadecimal representation');
$(this).parent().children(':nth-child(2)').attr('aria-label', 'Switch to hexadecimal representation');
} else {
val = val.split(' ');
hex = '';
val.forEach(function(entry) {
hex += parseInt(entry , 2).toString(16).toUpperCase();
});
$(this).parent().children(':first-child').text(hex);
$(this).parent().children(':first-child').attr('data-original-title', 'Hexadecimal representation');
$(this).parent().children(':nth-child(2)').attr('data-original-title', 'Switch to binary representation');
$(this).parent().children(':nth-child(2)').attr('aria-label', 'Switch to binary representation');
}
});
$('.searchFilterButton').click(function() {
filterAttributes('value', '<?php echo h($event['Event']['id']); ?>');
});

View File

@ -5087,3 +5087,41 @@ function changeLocationFromIndexDblclick(row_index) {
var href = $('table tr[data-row-id=\"' + row_index + '\"] .dblclickActionElement').attr('href')
window.location = href;
}
$('body').on('click', '.hex-value-convert', function() {
var $hexValueSpan = $(this).parent().children(':first-child');
var val = $hexValueSpan.text().trim();
if (!$hexValueSpan.hasClass('binary-representation')) {
var bin = [];
val.split('').forEach(function (entry) {
var temp = parseInt(entry, 16).toString(2);
bin.push(Array(5 - (temp.length)).join('0') + temp);
});
bin = bin.join(' ');
$hexValueSpan
.text(bin)
.attr('data-original-title', 'Binary representation')
.addClass('binary-representation');
if ($hexValueSpan.attr('title')) {
$hexValueSpan.attr('title', 'Binary representation');
}
$(this)
.attr('data-original-title', 'Switch to hexadecimal representation')
.attr('aria-label', 'Switch to hexadecimal representation');
} else {
var hex = '';
val.split(' ').forEach(function (entry) {
hex += parseInt(entry, 2).toString(16).toUpperCase();
});
$hexValueSpan
.text(hex)
.attr('data-original-title', 'Hexadecimal representation')
.removeClass('binary-representation');
if ($hexValueSpan.attr('title')) {
$hexValueSpan.attr('title', 'Hexadecimal representation');
}
$(this)
.attr('data-original-title', 'Switch to binary representation')
.attr('aria-label', 'Switch to binary representation');
}
});