Browse Source

auto update script executed

Toby Chui 1 year ago
parent
commit
b3e77490d0
1 changed files with 51 additions and 52 deletions
  1. 51 52
      web/components/rules.html

+ 51 - 52
web/components/rules.html

@@ -117,7 +117,6 @@
 <script>
     $("#advanceProxyRules").accordion();
 
-   
 
     //New Proxy Endpoint
     function newProxyEndpoint(){
@@ -305,61 +304,61 @@
         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, usingCa = "Let's Encrypt") {
-        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;
-        }
+        //Load the ACME email from server side
+        let acmeEmail = "";
+        $.get("/api/acme/autoRenew/email", function(data){
+            if (data != "" && data != undefined && data != null){
+                acmeEmail = data;
+            }
 
-        $.ajax({
-            url: "/api/acme/obtainCert",
-            method: "GET",
-            data: {
-                domains: domains,
-                filename: filename,
-                email: email,
-                ca: usingCa,
-            },
-            success: function(response) {
-                if (response.error) {
-                    console.log("Error:", response.error);
-                    // Show error message
-                    msgbox(response.error, false, 12000);
-                } else {
-                    console.log("Certificate installed successfully");
-                    // Show success message
-                    msgbox("Certificate installed successfully");
-                    
-                    // Renew the parent certificate list
-                    initManagedDomainCertificateList();
-                }
-            },
-            error: function(error) {
-                console.log("Failed to install certificate:", error);
+            let filename = "";
+            let email = acmeEmail;
+            if (acmeEmail == ""){
+                msgbox("Unable to obtain certificate: ACME email not set", false, 8000);
+                return;
+            }
+            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{
+                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: usingCa,
+                },
+                success: function(response) {
+                    if (response.error) {
+                        console.log("Error:", response.error);
+                        // Show error message
+                        msgbox(response.error, false, 12000);
+                    } else {
+                        console.log("Certificate installed successfully");
+                        // Show success message
+                        msgbox("Certificate installed successfully");
+                        
+                        // Renew the parent certificate list
+                        initManagedDomainCertificateList();
+                    }
+                },
+                error: function(error) {
+                    console.log("Failed to install certificate:", error);
+                }
+            });
         });
     }