cert.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <button onclick="uploadPublicKey();">Upload</button>
  2. <button onclick="uploadPrivateKey();">Upload Private Key</button>
  3. <script>
  4. function uploadPrivateKey(){
  5. // create file input element
  6. const input = document.createElement('input');
  7. input.type = 'file';
  8. // add change listener to file input
  9. input.addEventListener('change', () => {
  10. // create form data object
  11. const formData = new FormData();
  12. // add selected file to form data
  13. formData.append('file', input.files[0]);
  14. // send form data to server
  15. fetch('/cert/upload?ktype=pri', {
  16. method: 'POST',
  17. body: formData
  18. })
  19. .then(response => {
  20. if (response.ok) {
  21. alert('File upload successful!');
  22. } else {
  23. response.text().then(text => {
  24. alert(text);
  25. });
  26. //console.log(response.text());
  27. //alert('File upload failed!');
  28. }
  29. })
  30. .catch(error => {
  31. alert('An error occurred while uploading the file.');
  32. console.error(error);
  33. });
  34. });
  35. // click file input to open file selector
  36. input.click();
  37. }
  38. function uploadPublicKey() {
  39. // create file input element
  40. const input = document.createElement('input');
  41. input.type = 'file';
  42. // add change listener to file input
  43. input.addEventListener('change', () => {
  44. // create form data object
  45. const formData = new FormData();
  46. // add selected file to form data
  47. formData.append('file', input.files[0]);
  48. // send form data to server
  49. fetch('/cert/upload?ktype=pub', {
  50. method: 'POST',
  51. body: formData
  52. })
  53. .then(response => {
  54. if (response.ok) {
  55. alert('File upload successful!');
  56. } else {
  57. response.text().then(text => {
  58. alert(text);
  59. });
  60. //console.log(response.text());
  61. //alert('File upload failed!');
  62. }
  63. })
  64. .catch(error => {
  65. alert('An error occurred while uploading the file.');
  66. console.error(error);
  67. });
  68. });
  69. // click file input to open file selector
  70. input.click();
  71. }
  72. </script>