115 lines
4.3 KiB
JavaScript
115 lines
4.3 KiB
JavaScript
/**
|
|
* DB Console 복호화 기능
|
|
* - SafeDB 암호화 데이터 복호화
|
|
*/
|
|
(function(DbConsole) {
|
|
'use strict';
|
|
|
|
// 암호화된 값인지 확인 (16진수 패턴, 32자 이상)
|
|
DbConsole.isEncryptedValue = function(value) {
|
|
if (!value || typeof value !== 'string' || value.length < 32) {
|
|
return false;
|
|
}
|
|
return /^[0-9A-Fa-f]{32,}$/.test(value);
|
|
};
|
|
|
|
// 셀 복호화
|
|
DbConsole.decryptCell = function(btn) {
|
|
var $cell = $(btn).closest('.cell-encrypted');
|
|
var encryptedValue = $cell.data('value');
|
|
|
|
if (!encryptedValue) {
|
|
alert('복호화할 값이 없습니다.');
|
|
return;
|
|
}
|
|
|
|
// 버튼 비활성화
|
|
$(btn).prop('disabled', true);
|
|
|
|
$.ajax({
|
|
url: DbConsole.getContextPath() + '/admin/dbconsole/decrypt.do',
|
|
type: 'POST',
|
|
contentType: 'application/json',
|
|
data: JSON.stringify({ value: encryptedValue }),
|
|
success: function(response) {
|
|
if (response.success) {
|
|
$cell.html('<span class="cell-decrypted" title="원본: ' + DbConsole.escapeHtml(encryptedValue) + '">' +
|
|
DbConsole.escapeHtml(response.decryptedValue) +
|
|
'<i class="bi bi-check-circle text-success ms-1"></i></span>');
|
|
} else {
|
|
alert('복호화 실패: ' + (response.message || '알 수 없는 오류'));
|
|
$(btn).prop('disabled', false);
|
|
}
|
|
},
|
|
error: function(xhr) {
|
|
alert('복호화 요청 오류: ' + xhr.statusText);
|
|
$(btn).prop('disabled', false);
|
|
}
|
|
});
|
|
};
|
|
|
|
// 컬럼 전체 복호화
|
|
DbConsole.decryptColumn = function(columnName) {
|
|
var encryptedValues = [];
|
|
var $cells = $('.cell-encrypted[data-column="' + columnName + '"]');
|
|
|
|
$cells.each(function() {
|
|
var value = $(this).data('value');
|
|
if (value) {
|
|
encryptedValues.push(value);
|
|
}
|
|
});
|
|
|
|
if (encryptedValues.length === 0) {
|
|
alert('복호화할 암호화 데이터가 없습니다.');
|
|
return;
|
|
}
|
|
|
|
$.ajax({
|
|
url: DbConsole.getContextPath() + '/admin/dbconsole/decryptBatch.do',
|
|
type: 'POST',
|
|
contentType: 'application/json',
|
|
data: JSON.stringify({ values: encryptedValues }),
|
|
success: function(response) {
|
|
if (response.success) {
|
|
var decryptedMap = response.decrypted;
|
|
$cells.each(function() {
|
|
var value = $(this).data('value');
|
|
if (decryptedMap[value]) {
|
|
$(this).html('<span class="cell-decrypted" title="원본: ' + DbConsole.escapeHtml(value) + '">' +
|
|
DbConsole.escapeHtml(decryptedMap[value]) +
|
|
'<i class="bi bi-check-circle text-success ms-1"></i></span>');
|
|
}
|
|
});
|
|
} else {
|
|
alert('일괄 복호화 실패: ' + (response.message || '알 수 없는 오류'));
|
|
}
|
|
},
|
|
error: function(xhr) {
|
|
alert('복호화 요청 오류: ' + xhr.statusText);
|
|
}
|
|
});
|
|
};
|
|
|
|
// 암호화 셀 렌더러 확장
|
|
DbConsole.encryptedCellRenderer = function(params, escapeHtml) {
|
|
if (params.value === null || params.value === undefined) {
|
|
return '<span class="cell-null">(NULL)</span>';
|
|
}
|
|
|
|
var strValue = String(params.value);
|
|
|
|
// 암호화된 값인지 확인
|
|
if (DbConsole.isEncryptedValue(strValue)) {
|
|
var displayValue = strValue.length > 20 ? strValue.substring(0, 20) + '...' : strValue;
|
|
return '<span class="cell-encrypted" data-value="' + escapeHtml(strValue) + '" data-column="' + params.colDef.field + '">' +
|
|
escapeHtml(displayValue) +
|
|
'<button class="btn-decrypt" onclick="DbConsole.decryptCell(this)" title="복호화">' +
|
|
'<i class="bi bi-unlock"></i></button></span>';
|
|
}
|
|
|
|
return escapeHtml(strValue);
|
|
};
|
|
|
|
})(window.DbConsole || (window.DbConsole = {}));
|