Browse Source

auto update script executed

Toby Chui 1 year ago
parent
commit
7b1a034f65
3 changed files with 76 additions and 2 deletions
  1. 1 1
      main.go
  2. 74 0
      web/components/rules.html
  3. 1 1
      web/main.css

+ 1 - 1
main.go

@@ -41,7 +41,7 @@ var ztAPIPort = flag.Int("ztport", 9993, "ZeroTier controller API port")
 var acmeAutoRenewInterval = flag.Int("autorenew", 86400, "ACME auto TLS/SSL certificate renew check interval (seconds)")
 var (
 	name        = "Zoraxy"
-	version     = "2.6.5"
+	version     = "2.6.6"
 	nodeUUID    = "generic"
 	development = false //Set this to false to use embedded web fs
 	bootTime    = time.Now().Unix()

+ 74 - 0
web/components/rules.html

@@ -179,6 +179,17 @@
                     $("#proxyDomain").val("");
                     credentials = [];
                     updateTable();
+
+                    //Check if it is a new subdomain and TLS enabled
+                    if (type == "subd" && $("#tls").checkbox("is checked")){
+                        confirmBox("Request new SSL Cert for this subdomain?", function(choice){
+                            if (choice == true){
+                                //Get a new cert using ACME
+                                console.log("Trying to get a new certificate via ACME");
+                                obtainCertificate(rootname);
+                            }
+                        });
+                    }
                 }
             }
         });
@@ -437,4 +448,67 @@
         }));
         showSideWrapper("snippet/basicAuthEditor.html?t=" + Date.now() + "#" + payload);
     }
+
+
+    /*
+        Obtain Certificate via ACME
+    */
+
+    //Load the ACME email from server side
+    let acmeEmail = "";
+    $.get("/api/acme/autoRenew/email", function(data){
+        if (data != "" && data != undefined && data != null){
+            acmeEmail = data;
+        }
+    });
+
+   // Obtain certificate from API, only support one domain
+    function obtainCertificate(domains) {
+        let filename = "";
+        let email = acmeEmail;
+        if (acmeEmail == ""){
+            let rootDomain = domains.split(".").pop();
+            email = "admin@" + rootDomain;
+        }
+        if (filename.trim() == "" && !domains.includes(",")){
+            //Zoraxy filename are the matching name for domains.
+            //Use the same as domains
+            filename = domains;
+        }else if (filename != "" && !domains.includes(",")){
+            //Invalid settings. Force the filename to be same as domain
+            //if there are only 1 domain
+            filename = domains;
+        }else{
+            parent.msgbox("Filename cannot be empty for certs containing multiple domains.")
+            return;
+        }
+
+        $.ajax({
+            url: "/api/acme/obtainCert",
+            method: "GET",
+            data: {
+                domains: domains,
+                filename: filename,
+                email: email,
+                ca: "Let's Encrypt",
+            },
+            success: function(response) {
+                if (response.error) {
+                    console.log("Error:", response.error);
+                    // Show error message
+                    msgbox(response.error, false, 12000);
+                } else {
+                    console.log("Certificate renewed successfully");
+                    // Show success message
+                    msgbox("Certificate renewed successfully");
+                    
+                    // Renew the parent certificate list
+                    initManagedDomainCertificateList();
+                }
+            },
+            error: function(error) {
+                console.log("Failed to renewed certificate:", error);
+            }
+        });
+    }
 </script>

+ 1 - 1
web/main.css

@@ -116,7 +116,7 @@ body{
 }
 
 #confirmBox .ui.progress .bar{
-    background: #ffe32b !important;
+    background: #a9d1f3 !important;
 }
 
 #confirmBox .confirmBoxBody .button{