acme.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <!-- Notes: This should be open in its original path-->
  5. <link rel="stylesheet" href="../script/semantic/semantic.min.css">
  6. <script src="../script/jquery-3.6.0.min.js"></script>
  7. <script src="../script/semantic/semantic.min.js"></script>
  8. <style>
  9. .disabled.table{
  10. opacity: 0.5;
  11. pointer-events: none;
  12. user-select: none;
  13. }
  14. .expiredDomain{
  15. color: rgb(238, 31, 31);
  16. }
  17. .validDomain{
  18. color: rgb(49, 192, 113);
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <br>
  24. <div class="ui container">
  25. <div class="ui header">
  26. <div class="content">
  27. Certificates Auto Renew Settings
  28. <div class="sub header">Fetch and renew your certificates with Automated Certificate Management Environment (ACME) protocol</div>
  29. </div>
  30. </div>
  31. <div class="ui basic segment">
  32. <div class="ui toggle checkbox">
  33. <input type="checkbox" id="enableCertAutoRenew" checked>
  34. <label>Enable Certificate Auto Renew</label>
  35. </div>
  36. </div>
  37. <div class="ui yellow message">
  38. Certificate Renew only works on the certification authority (CA) supported by Zoraxy. Check Zoraxy wiki for more information on supported list of CAs.
  39. </div>
  40. <div class="ui basic segment" style="background-color: #f7f7f7; border-radius: 1em;">
  41. <div class="ui accordion advanceSettings">
  42. <div class="title">
  43. <i class="dropdown icon"></i>
  44. Advance Renew Policy
  45. </div>
  46. <div class="content">
  47. <p>Renew all certificates with ACME supported CAs</p>
  48. <div class="ui toggle checkbox">
  49. <input type="checkbox" id="renewAllSupported" onchange="setAutoRenewIfCASupportMode(this.checked);" checked>
  50. <label>Auto renew if CA is supported</label>
  51. </div>
  52. <div class="ui horizontal divider"> OR </div>
  53. <p>Select the certificates to automatic renew in the list below</p>
  54. <table id="domainCertFileTable" class="ui very compact unstackable basic disabled table">
  55. <thead>
  56. <tr>
  57. <th>Domain Name</th>
  58. <th>Filename</th>
  59. <th>Auto-Renew</th>
  60. </tr>
  61. </thead>
  62. <tbody id="domainTableBody"></tbody>
  63. </table>
  64. <button class="ui basic right floated button"><i class="blue save icon"></i> Save Changes</button>
  65. <button class="ui basic right floated button"><i class="yellow refresh icon"></i> Renew All</button>
  66. <br><br>
  67. </div>
  68. </div>
  69. </div>
  70. <div class="ui divider"></div>
  71. <h3>Manual Renew</h3>
  72. <p>Pick a certificate below to force renew</p>
  73. <div class="ui form">
  74. <div class="field">
  75. <label>Domains</label>
  76. <input id="domainsInput" type="text" placeholder="example.com">
  77. <small>If you have more than one domain in a single certificate, enter the domains separated by commas (e.g. test.example.com,example.com)</small>
  78. </div>
  79. <div class="field">
  80. <label>Filename</label>
  81. <input id="filenameInput" type="text" placeholder="Enter filename">
  82. </div>
  83. <div class="field">
  84. <label>Certificate Authority (CA)</label>
  85. <div class="ui selection dropdown">
  86. <input type="hidden" name="ca">
  87. <i class="dropdown icon"></i>
  88. <div class="default text">Let's Encrypt</div>
  89. <div class="menu">
  90. <div class="item" data-value="Let's Encrypt">Let's Encrypt</div>
  91. <div class="item" data-value="Buypass">Buypass</div>
  92. <div class="item" data-value="ZeroSSL">ZeroSSL</div>
  93. <div class="item" data-value="Google">Google</div>
  94. </div>
  95. </div>
  96. </div>
  97. <button id="obtainButton" class="ui basic button" type="submit"><i class="yellow refresh icon"></i> Renew Certificate</button>
  98. </div>
  99. <button class="ui basic button" style="float: right;" onclick="parent.hideSideWrapper();"><i class="remove icon"></i> Cancel</button>
  100. <br><br><br><br>
  101. </div>
  102. <script>
  103. let expiredDomains = [];
  104. $(".accordion").accordion();
  105. $(".dropdown").dropdown();
  106. function setAutoRenewIfCASupportMode(useAutoMode = true){
  107. if (useAutoMode){
  108. $("#domainCertFileTable").addClass("disabled");
  109. }else{
  110. $("#domainCertFileTable").removeClass("disabled");
  111. }
  112. }
  113. //Render the domains table that exists in this zoraxy host
  114. function renderDomainTable(domains) {
  115. // Get the table body element
  116. var tableBody = $('#domainTableBody');
  117. // Clear the table body
  118. tableBody.empty();
  119. // Iterate over the domain names
  120. var counter = 0;
  121. for (const [domain, srcfile] of Object.entries(domains)) {
  122. // Create a table row
  123. var row = $('<tr>');
  124. // Create the domain name cell
  125. var domainClass = "validDomain";
  126. if (expiredDomains.includes(domain)){
  127. domainClass = "expiredDomain";
  128. }
  129. var domainCell = $('<td class="' + domainClass +'">').text(domain);
  130. row.append(domainCell);
  131. var srcFileCell = $('<td>').text(srcfile);
  132. row.append(srcFileCell);
  133. // Create the auto-renew checkbox cell
  134. var checkboxCell = $(`<td domain="${domain}" srcfile="${srcfile}">`);
  135. var checkbox = $('<input>').attr('type', 'checkbox');
  136. checkboxCell.append(checkbox);
  137. row.append(checkboxCell);
  138. // Add the row to the table body
  139. tableBody.append(row);
  140. counter++;
  141. }
  142. }
  143. //Initiate domain table. If you needs to update the expired domain as well
  144. //call from initDomainFileList() instead
  145. function initDomainTable(){
  146. $.get("/api/cert/listdomains", function(data){
  147. if (data.error != undefined){
  148. parent.msgbox(data.error, false);
  149. }else{
  150. renderDomainTable(data);
  151. }
  152. })
  153. }
  154. function initDomainFileList() {
  155. $.ajax({
  156. url: "/api/acme/listExpiredDomains",
  157. method: "GET",
  158. success: function(response) {
  159. // Render domain table
  160. expiredDomains = response.domain;
  161. initDomainTable();
  162. //renderDomainTable(response.domain);
  163. },
  164. error: function(error) {
  165. console.log("Failed to fetch expired domains:", error);
  166. }
  167. });
  168. }
  169. initDomainFileList();
  170. // Button click event handler for obtaining certificate
  171. $("#obtainButton").click(function() {
  172. obtainCertificate();
  173. });
  174. // Obtain certificate from API
  175. function obtainCertificate() {
  176. var domains = $("#domainsInput").val();
  177. var filename = $("#filenameInput").val();
  178. $.ajax({
  179. url: "/api/acme/obtainCert",
  180. method: "GET",
  181. data: {
  182. domains: domains,
  183. filename: filename
  184. },
  185. success: function(response) {
  186. if (response.error) {
  187. console.log("Error:", response.error);
  188. // Show error message
  189. parent.msgbox(response.error, false, 12000);
  190. } else {
  191. console.log("Certificate renewed successfully");
  192. // Show success message
  193. parent.msgbox("Certificate renewed successfully");
  194. }
  195. },
  196. error: function(error) {
  197. console.log("Failed to renewed certificate:", error);
  198. }
  199. });
  200. }
  201. </script>
  202. </body>
  203. </html>