https.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="apple-mobile-web-app-capable" content="yes" />
  5. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
  6. <meta charset="UTF-8">
  7. <meta name="theme-color" content="#4b75ff">
  8. <link rel="icon" type="image/png" href="./favicon.png" />
  9. <title>HTTPS Setup Wizard | Zoraxy</title>
  10. <link rel="stylesheet" href="../script/semantic/semantic.min.css">
  11. <script src="../script/jquery-3.6.0.min.js"></script>
  12. <script src="../../script/ao_module.js"></script>
  13. <script src="../script/semantic/semantic.min.js"></script>
  14. <script src="../script/tablesort.js"></script>
  15. <link rel="stylesheet" href="shepherd.js/dist/css/shepherd.css"/>
  16. <script src="shepherd.js/dist/js/shepherd.min.js"></script>
  17. <link rel="stylesheet" href="../main.css">
  18. </head>
  19. <body>
  20. <br>
  21. <div class="ui container">
  22. <div class="ui yellow message">
  23. This Wizard require both client and server connected to the internet.
  24. </div>
  25. <div class="ui segment">
  26. <h3 class="ui header">
  27. HTTPS (TLS/SSL Certificate) Setup Wizard
  28. <div class="sub header">This tool help you setup https with your domain / subdomain on your Zoraxy host. <br>
  29. Follow the steps below to get started</div>
  30. </h3>
  31. </div>
  32. <div class="ui segment stepContainer" step="1">
  33. <h4 class="ui header">
  34. 1. Setup Zoraxy to listen to port 80 or 443 and start listening
  35. <div class="sub header">ACME can only works on port 80 (or 80 redirected 443). Please make sure Zoarxy is listening to either one of the ports.</div>
  36. </h4>
  37. <button class="ui basic green button" onclick="checkStep(1, step1Callback, this);">Check Port Setup</button>
  38. <div class="checkResult" style="margin-top: 1em;">
  39. </div>
  40. </div>
  41. <div class="ui segment stepContainer" step="2">
  42. <h4 class="ui header">
  43. 2. If you are under NAT, setup Port Forward and forward external port 80 (<b style="color: rgb(206, 29, 29); font-weight:bolder;">and</b> 443, if you are using 443) to your Zoraxy's LAN IP address port 80 (and 443)
  44. <div class="sub header">If your Zoraxy server IP address starts with 192.168., you are mostly under a NAT router.</div>
  45. </h4>
  46. <small>The check function below will use public ip to check if port is opened. Make sure your host is reachable from the internet!<br>
  47. <b style="color: rgb(206, 29, 29); font-weight:bolder;">If you are using 443, you still need to forward port 80 for performing 80 to 443 redirect.</b></small><br>
  48. <button style="margin-top: 0.6em;" class="ui basic green button" onclick="checkStep(2, step2Callback, this);">Check Internet Reachable</button>
  49. <div class="checkResult" style="margin-top: 1em;">
  50. </div>
  51. </div>
  52. <div class="ui segment stepContainer" step="3">
  53. <h4 class="ui header">
  54. 3. Point your domain (or sub-domain) to your Zoraxy server public IP address
  55. <div class="sub header">DNS records might takes 5 - 10 minutes to take effect. If checking did not poss the first time, wait for a few minutes and retry.</div>
  56. </h4>
  57. <div class="ui fluid input">
  58. <input type="text" name="domain" placeholder="Your Domain / DNS name (e.g. dev.example.com)">
  59. </div>
  60. <br>
  61. <button class="ui basic green button" onclick="checkStep(3, step3Callback, this);">Check Domain Reachable</button>
  62. <div class="checkResult" style="margin-top: 1em;">
  63. </div>
  64. </div>
  65. <div class="ui segment stepContainer" step="4">
  66. <h4 class="ui header">
  67. 4. Request a public CA to assign you a certificate
  68. <div class="sub header">This process might take a few minutes and usually fully automated. If there are any error, you can see Zoraxy STDOUT / log for more information.</div>
  69. </h4>
  70. <div class="ui form">
  71. <div class="field">
  72. <label>Renewer Email</label>
  73. <div class="ui fluid input">
  74. <input id="caRegisterEmail" type="text" placeholder="[email protected]">
  75. </div>
  76. <small>Your CA might send expire notification to you via this email.</small>
  77. </div>
  78. <div class="field">
  79. <label>Domain(s)</label>
  80. <input id="domainsInput" type="text" placeholder="example.com" onkeyup="checkIfInputDomainIsMultiple();">
  81. <small>If you have more than one domain in a single certificate, enter the domains separated by commas (e.g. s1.dev.example.com,s2.dev.example.com)</small>
  82. </div>
  83. <div class="field multiDomainOnly" style="display:none;">
  84. <label>Matching Rule</label>
  85. <input id="filenameInput" type="text" placeholder="Enter filename (no file extension)">
  86. <small>Matching rule to let Zoraxy pick which certificate to use (Also be used as filename). Usually is the longest common suffix of the entered addresses. (e.g. dev.example.com)</small>
  87. </div>
  88. <div class="field multiDomainOnly" style="display:none;">
  89. <button class="ui basic fluid button" onclick="autoDetectMatchingRules();">Auto Detect Matching Rule</button>
  90. </div>
  91. <div class="field">
  92. <label>Certificate Authority (CA)</label>
  93. <div class="ui selection dropdown" id="ca">
  94. <input type="hidden" name="ca">
  95. <i class="dropdown icon"></i>
  96. <div class="default text">Let's Encrypt</div>
  97. <div class="menu">
  98. <div class="item" data-value="Let's Encrypt">Let's Encrypt</div>
  99. <div class="item" data-value="Buypass">Buypass</div>
  100. <div class="item" data-value="ZeroSSL">ZeroSSL</div>
  101. <!-- <div class="item" data-value="Google">Google</div> -->
  102. </div>
  103. </div>
  104. </div>
  105. <button id="obtainButton" class="ui green basic button" type="submit"><i class="green download icon"></i> Get Certificate</button>
  106. </div>
  107. <div class="ui green message" id="installSucc" style="display:none;">
  108. <i class="ui check icon"></i> Certificate for this domain has been installed. Visit the TLS/SSL tab for advance operations.
  109. </div>
  110. </div>
  111. <script>
  112. function checkIfInputDomainIsMultiple(){
  113. var inputDomains = $("#domainsInput").val();
  114. if (inputDomains.includes(",")){
  115. $(".multiDomainOnly").show();
  116. }else{
  117. $(".multiDomainOnly").hide();
  118. }
  119. }
  120. //Grab the longest common suffix of all domains
  121. //not that smart technically
  122. function autoDetectMatchingRules(){
  123. var domainsString = $("#domainsInput").val();
  124. if (!domainsString.includes(",")){
  125. return domainsString;
  126. }
  127. let domains = domainsString.split(",");
  128. //Clean out any spacing between commas
  129. for (var i = 0; i < domains.length; i++){
  130. domains[i] = domains[i].trim();
  131. }
  132. function getLongestCommonSuffix(strings) {
  133. if (strings.length === 0) {
  134. return ''; // Return an empty string if the array is empty
  135. }
  136. var sortedStrings = strings.slice().sort(); // Create a sorted copy of the array
  137. var firstString = sortedStrings[0];
  138. var lastString = sortedStrings[sortedStrings.length - 1];
  139. var suffix = '';
  140. var minLength = Math.min(firstString.length, lastString.length);
  141. for (var i = 0; i < minLength; i++) {
  142. if (firstString[firstString.length - 1 - i] !== lastString[lastString.length - 1 - i]) {
  143. break; // Stop iterating if characters don't match
  144. }
  145. suffix = firstString[firstString.length - 1 - i] + suffix;
  146. }
  147. return suffix;
  148. }
  149. let longestSuffix = getLongestCommonSuffix(domains);
  150. //Check if the suffix is a valid domain
  151. if (longestSuffix.substr(0,1) == "."){
  152. //Trim off the first dot
  153. longestSuffix = longestSuffix.substr(1);
  154. }
  155. if (!longestSuffix.includes(".")){
  156. alert("Auto Detect failed: Multiple Domains");
  157. return;
  158. }
  159. $("#filenameInput").val(longestSuffix);
  160. }
  161. $("#obtainButton").click(function() {
  162. $("#obtainButton").addClass("loading").addClass("disabled");
  163. obtainCertificate();
  164. });
  165. // Obtain certificate from API
  166. function obtainCertificate() {
  167. var domains = $("#domainsInput").val();
  168. var filename = $("#filenameInput").val();
  169. var email = $("#caRegisterEmail").val();
  170. if (email == ""){
  171. alert("ACME renew email is not set")
  172. return;
  173. }
  174. if (filename.trim() == "" && !domains.includes(",")){
  175. //Zoraxy filename are the matching name for domains.
  176. //Use the same as domains
  177. filename = domains;
  178. }else if (filename != "" && !domains.includes(",")){
  179. //Invalid settings. Force the filename to be same as domain
  180. //if there are only 1 domain
  181. filename = domains;
  182. }else{
  183. alert("Filename cannot be empty for certs containing multiple domains.")
  184. return;
  185. }
  186. var ca = $("#ca").dropdown("get value");
  187. $.ajax({
  188. url: "/api/acme/obtainCert",
  189. method: "GET",
  190. data: {
  191. domains: domains,
  192. filename: filename,
  193. email: email,
  194. ca: ca,
  195. },
  196. success: function(response) {
  197. $("#obtainButton").removeClass("loading").removeClass("disabled");
  198. if (response.error) {
  199. console.log("Error:", response.error);
  200. // Show error message
  201. alert(response.error);
  202. $("#installSucc").hide();
  203. } else {
  204. console.log("Certificate installed successfully");
  205. // Show success message
  206. //alert("Certificate installed successfully");
  207. $("#installSucc").show();
  208. }
  209. },
  210. error: function(error) {
  211. $("#obtainButton").removeClass("loading").removeClass("disabled");
  212. console.log("Failed to renewed certificate:", error);
  213. }
  214. });
  215. }
  216. function step3Callback(resultContainer, data){
  217. if (data == true){
  218. $(resultContainer).html(`<div class="ui green message">
  219. <i class="ui check icon"></i> Domain is reachable and seems there is a HTTP server listening. Please move on to the next step.
  220. </div>`);
  221. }else{
  222. $(resultContainer).html(`<div class="ui red message">
  223. <i class="ui remove icon"></i> Domain is reachable but there are no HTTP server listening<br>
  224. Make sure you have point to the correct IP address and there are not another proxy server above Zoraxy.
  225. </div>`);
  226. }
  227. }
  228. function step2Callback(resultContainer, data){
  229. if (data == true){
  230. $(resultContainer).html(`<div class="ui green message">
  231. <i class="ui check icon"></i> HTTP Server reachable from public IP address. Please move on to the next step.
  232. </div>`);
  233. }else{
  234. $(resultContainer).html(`<div class="ui red message">
  235. <i class="ui remove icon"></i> Server unreachable from public IP address<br>
  236. Check if you have correct NAT port forward setup in your home router, firewall and make sure network is reachable from the public internet.
  237. </div>`);
  238. }
  239. }
  240. function step1Callback(resultContainer, data){
  241. if (data == true){
  242. $(resultContainer).html(`<div class="ui green message">
  243. <i class="ui check icon"></i> Supported listening port. Please move on to the next step.
  244. </div>`);
  245. }else{
  246. $(resultContainer).html(`<div class="ui red message">
  247. <i class="ui remove icon"></i> Invalid listening port.<br>
  248. Go to Status tab and change the listening port to 80 or 443
  249. </div>`);
  250. }
  251. }
  252. function getStepContainerByNo(stepNo){
  253. let targetStepContainer = undefined;
  254. $(".stepContainer").each(function(){
  255. if ($(this).attr("step") == stepNo){
  256. let thisContainer = $(this);
  257. targetStepContainer = thisContainer;
  258. }
  259. });
  260. return targetStepContainer;
  261. }
  262. function checkStep(stepNo, callback, btn){
  263. let targetContainer = getStepContainerByNo(stepNo);
  264. $(btn).addClass("loading");
  265. //Load all the inputs
  266. data = {};
  267. $(targetContainer).find("input").each(function(){
  268. let key = $(this).attr("name")
  269. if (key != undefined){
  270. data[key] = $(this).val();
  271. }
  272. });
  273. $.ajax({
  274. url: "/api/acme/wizard?step=" + stepNo,
  275. data: data,
  276. success: function(data){
  277. $(btn).removeClass("loading");
  278. if (data.error != undefined){
  279. $(targetContainer).find(".checkResult").html(`
  280. <div class="ui red message">${data.error}</div>`);
  281. }else{
  282. callback($(targetContainer).find(".checkResult"), data);
  283. }
  284. },
  285. error: function(){
  286. $(btn).removeClass("loading");
  287. $(targetContainer).find(".checkResult").html(`
  288. <div class="ui red message">Server return an Unknown Error</div>`);
  289. }
  290. });
  291. }
  292. </script>
  293. </body>
  294. </html>