diff --git a/src/main/java/com/jetbrains/help/context/CertificateContextHolder.java b/src/main/java/com/jetbrains/help/context/CertificateContextHolder.java index e0acbfa..154c24c 100644 --- a/src/main/java/com/jetbrains/help/context/CertificateContextHolder.java +++ b/src/main/java/com/jetbrains/help/context/CertificateContextHolder.java @@ -78,7 +78,7 @@ public class CertificateContextHolder { return CertificateContextHolder.crtFile; } - private static void generateCertificate() { + public static void generateCertificate() { KeyPair keyPair = SecureUtil.generateKeyPair("RSA", 4096); PrivateKey privateKey = keyPair.getPrivate(); PublicKey publicKey = keyPair.getPublic(); diff --git a/src/main/resources/static/js/index.js b/src/main/resources/static/js/index.js index 0f3af82..6875a7b 100644 --- a/src/main/resources/static/js/index.js +++ b/src/main/resources/static/js/index.js @@ -1,83 +1,71 @@ -window.submitLicenseInfo = function () { - let licenseeName = document.getElementById('licenseeName').value - let assigneeName = document.getElementById('assigneeName').value - let expiryDate = document.getElementById('expiryDate').value - let licenseInfo = { - licenseeName: licenseeName, - assigneeName: assigneeName, - expiryDate: expiryDate - } - localStorage.setItem('licenseInfo', JSON.stringify(licenseInfo)) - document.getElementById('mask').style.display = 'none' - document.getElementById('form').style.display = 'none' -} -document.getElementById('search').oninput = function (e) { - $("#product-list").load('/search?search=' + e.target.value) -} -window.showLicenseForm = function () { - let licenseInfo = localStorage.getItem('licenseInfo'); - if (licenseInfo !== null) { - licenseInfo = JSON.parse(licenseInfo) - document.getElementById('licenseeName').value = licenseInfo.licenseeName - document.getElementById('assigneeName').value = licenseInfo.assigneeName - document.getElementById('expiryDate').value = licenseInfo.expiryDate - } else { - document.getElementById('licenseeName').value = '光云' - document.getElementById('assigneeName').value = '藏柏' - document.getElementById('expiryDate').value = '2111-11-11' - } - document.getElementById('mask').style.display = 'block' - document.getElementById('form').style.display = 'block' -} -window.showVmoptins = function () { - alert("-javaagent:/(Your Path)/ja-netfilter/ja-netfilter.jar\n" + - "--add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED\n" + - "--add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED") -} -//@see https://zhuanlan.zhihu.com/p/597944027 -const copyText = async (val) => { - if (navigator.clipboard && navigator.permissions) { - await navigator.clipboard.writeText(val) - } else { - const textArea = document.createElement('textArea') - textArea.value = val - textArea.style.width = 0 - textArea.style.position = 'fixed' - textArea.style.left = '-999px' - textArea.style.top = '10px' - textArea.setAttribute('readonly', 'readonly') - document.body.appendChild(textArea) - - textArea.select() - document.execCommand('copy') - document.body.removeChild(textArea) - } -} -window.copyLicense = async function (e) { - - while (localStorage.getItem('licenseInfo') === null) { - document.getElementById('mask').style.display = 'block' - document.getElementById('form').style.display = 'block' - await new Promise(r => setTimeout(r, 1000)); - } - let licenseInfo = JSON.parse(localStorage.getItem('licenseInfo')) - let productCode = e.closest('.card').dataset.productCodes; - let data = { - "licenseName": licenseInfo.licenseeName, - "assigneeName": licenseInfo.assigneeName, - "expiryDate": licenseInfo.expiryDate, - "productCode": productCode, - } - let resp = await fetch('/generateLicense', { - method: 'POST', +$(document).ready(function() { + // Set default headers for AJAX requests + $.ajaxSetup({ headers: { 'Content-Type': 'application/json' - }, - body: JSON.stringify(data) - }).then(response => response.text()) + } + }); - copyText(resp) - .then(() => { - alert("The activation code has been copied"); - }) -} \ No newline at end of file + // Function to handle submission of license information + window.submitLicenseInfo = function () { + let licenseInfo = { + licenseeName: $('#licenseeName').val(), + assigneeName: $('#assigneeName').val(), + expiryDate: $('#expiryDate').val() + }; + localStorage.setItem('licenseInfo', JSON.stringify(licenseInfo)); + $('#mask, #form').hide(); + }; + + // Function to handle search input + $('#search').on('input', function(e) { + $("#product-list").load('/search?search=' + e.target.value); + }); + + // Function to show license form + window.showLicenseForm = function () { + let licenseInfo = JSON.parse(localStorage.getItem('licenseInfo')); + $('#licenseeName').val(licenseInfo?.licenseeName || '光云'); + $('#assigneeName').val(licenseInfo?.assigneeName || '藏柏'); + $('#expiryDate').val(licenseInfo?.expiryDate || '2111-11-11'); + $('#mask, #form').show(); + }; + + // Function to show VM options + window.showVmoptins = function () { + alert("-javaagent:/(Your Path)/ja-netfilter/ja-netfilter.jar\n" + + "--add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED\n" + + "--add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED"); + }; + + // Function to copy license + window.copyLicense = async function (e) { + while (localStorage.getItem('licenseInfo') === null) { + $('#mask, #form').show(); + await new Promise(r => setTimeout(r, 1000)); + } + let licenseInfo = JSON.parse(localStorage.getItem('licenseInfo')); + let productCode = $(e).closest('.card').data('productCodes'); + let data = { + "licenseName": licenseInfo.licenseeName, + "assigneeName": licenseInfo.assigneeName, + "expiryDate": licenseInfo.expiryDate, + "productCode": productCode, + }; + $.post('/generateLicense', JSON.stringify(data)) + .then(response => { + copyText(response) + .then(() => { + alert("The activation code has been copied"); + }); + }); + }; + +// Function to copy text to clipboard + const copyText = async (val) => { + if (navigator.clipboard && navigator.permissions) { + await navigator.clipboard.writeText(val); + } + }; + +}); diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 91b3374..aeafa20 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -101,6 +101,6 @@ - + \ No newline at end of file