123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <button onclick="uploadPublicKey();">Upload</button>
- <button onclick="uploadPrivateKey();">Upload Private Key</button>
- <script>
- function uploadPrivateKey(){
- // create file input element
- const input = document.createElement('input');
- input.type = 'file';
-
- // add change listener to file input
- input.addEventListener('change', () => {
- // create form data object
- const formData = new FormData();
-
- // add selected file to form data
- formData.append('file', input.files[0]);
- // send form data to server
- fetch('/cert/upload?ktype=pri', {
- method: 'POST',
- body: formData
- })
- .then(response => {
- if (response.ok) {
- alert('File upload successful!');
- } else {
- response.text().then(text => {
- alert(text);
- });
- //console.log(response.text());
- //alert('File upload failed!');
- }
- })
- .catch(error => {
- alert('An error occurred while uploading the file.');
- console.error(error);
- });
- });
-
- // click file input to open file selector
- input.click();
- }
- function uploadPublicKey() {
- // create file input element
- const input = document.createElement('input');
- input.type = 'file';
-
- // add change listener to file input
- input.addEventListener('change', () => {
- // create form data object
- const formData = new FormData();
-
- // add selected file to form data
- formData.append('file', input.files[0]);
- // send form data to server
- fetch('/cert/upload?ktype=pub', {
- method: 'POST',
- body: formData
- })
- .then(response => {
- if (response.ok) {
- alert('File upload successful!');
- } else {
- response.text().then(text => {
- alert(text);
- });
- //console.log(response.text());
- //alert('File upload failed!');
- }
- })
- .catch(error => {
- alert('An error occurred while uploading the file.');
- console.error(error);
- });
- });
-
- // click file input to open file selector
- input.click();
- }
- </script>
|