Kaynağa Gözat

auto update script executed

Toby Chui 1 yıl önce
ebeveyn
işleme
ceeff467ae
9 değiştirilmiş dosya ile 102 ekleme ve 6 silme
  1. 21 0
      acme.go
  2. 1 0
      api.go
  3. 1 1
      mod/acme/acme.go
  4. 5 0
      mod/acme/ca.go
  5. 2 0
      start.go
  6. 57 3
      web/components/cert.html
  7. 1 1
      web/components/webserv.html
  8. 10 0
      web/components/zgrok.html
  9. 4 1
      web/index.html

+ 21 - 0
acme.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"encoding/json"
 	"fmt"
 	"io"
 	"log"
@@ -114,3 +115,23 @@ func AcmeCheckAndHandleRenewCertificate(w http.ResponseWriter, r *http.Request)
 		}
 	}
 }
+
+// HandleACMEPreferredCA return the user preferred / default CA for new subdomain auto creation
+func HandleACMEPreferredCA(w http.ResponseWriter, r *http.Request) {
+	ca, err := utils.PostPara(r, "set")
+	if err != nil {
+		//Return the current ca to user
+		prefCA := "Let's Encrypt"
+		sysdb.Read("acmepref", "prefca", prefCA)
+		js, _ := json.Marshal(prefCA)
+		utils.SendJSONResponse(w, string(js))
+	} else {
+		//Check if the CA is supported
+		acme.IsSupportedCA(ca)
+
+		//Set the new config
+		sysdb.Write("acmepref", "prefca", ca)
+		utils.SendOK(w)
+	}
+
+}

+ 1 - 0
api.go

@@ -162,6 +162,7 @@ func initAPIs() {
 	authRouter.HandleFunc("/api/acme/listExpiredDomains", acmeHandler.HandleGetExpiredDomains)
 	authRouter.HandleFunc("/api/acme/obtainCert", AcmeCheckAndHandleRenewCertificate)
 	authRouter.HandleFunc("/api/acme/autoRenew/enable", acmeAutoRenewer.HandleAutoRenewEnable)
+	authRouter.HandleFunc("/api/acme/autoRenew/ca", HandleACMEPreferredCA)
 	authRouter.HandleFunc("/api/acme/autoRenew/email", acmeAutoRenewer.HandleACMEEmail)
 	authRouter.HandleFunc("/api/acme/autoRenew/setDomains", acmeAutoRenewer.HandleSetAutoRenewDomains)
 	authRouter.HandleFunc("/api/acme/autoRenew/listDomains", acmeAutoRenewer.HandleLoadAutoRenewDomains)

+ 1 - 1
mod/acme/acme.go

@@ -361,8 +361,8 @@ func IsPortInUse(port int) bool {
 
 }
 
+// Load cert information from json file
 func loadCertInfoJSON(filename string) (*CertificateInfoJSON, error) {
-
 	certInfoBytes, err := os.ReadFile(filename)
 	if err != nil {
 		return nil, err

+ 5 - 0
mod/acme/ca.go

@@ -49,3 +49,8 @@ func loadCAApiServerFromName(caName string) (string, error) {
 
 	return val, nil
 }
+
+func IsSupportedCA(caName string) bool {
+	_, err := loadCAApiServerFromName(caName)
+	return err == nil
+}

+ 2 - 0
start.go

@@ -204,6 +204,8 @@ func startupSequence() {
 
 		Obtaining certificates from ACME Server
 	*/
+	//Create a table just to store acme related preferences
+	sysdb.NewTable("acmepref")
 	acmeHandler = initACME()
 	acmeAutoRenewer, err = acme.NewAutoRenewer("./conf/acme_conf.json", "./conf/certs/", int64(*acmeAutoRenewInterval), acmeHandler)
 	if err != nil {

+ 57 - 3
web/components/cert.html

@@ -90,6 +90,7 @@
     <p>The default CA to use when create a new subdomain proxy endpoint with TLS certificate</p>
     <div class="ui fluid form">
         <div class="field">
+            <label>Preferred CA</label>
             <div class="ui selection dropdown" id="defaultCA">
                 <input type="hidden" name="defaultCA">
                 <i class="dropdown icon"></i>
@@ -101,10 +102,22 @@
                 </div>
             </div>
         </div>
+        <div class="field">
+            <label>ACME Email</label>
+            <input id="prefACMEEmail" type="text" placeholder="ACME Email">
+        </div>
         <button class="ui basic icon button" onclick="saveDefaultCA();"><i class="ui blue save icon"></i> Save Settings</button>
     </div><br>
-    
     <h5>Certificate Renew / Generation (ACME) Settings</h5>
+    <div class="ui basic segment">
+        <h4 class="ui header" id="acmeAutoRenewer">
+            <i class="red circle icon"></i>
+            <div class="content">
+                <span id="acmeAutoRenewerStatus">Disabled</span>
+                <div class="sub header">Auto-Renewer Status</div>
+            </div>
+        </h4>
+    </div>
     <p>This tool provide you a graphical interface to setup auto certificate renew on your (sub)domains. You can also manually generate a certificate if one of your domain do not have certificate.</p>
     <button class="ui basic button" onclick="openACMEManager();"><i class="yellow external icon"></i> Open ACME Tool</button>
 </div>
@@ -134,9 +147,50 @@
         
     }
 
+    function initAcmeStatus(){
+        //Initialize the current default CA options
+        $.get("/api/acme/autoRenew/email", function(data){
+            $("#prefACMEEmail").val(data);
+        });
+
+        $.get("/api/acme/autoRenew/ca", function(data){
+            $("#defaultCA").dropdown("set selected", data);
+        });
+
+        $.get("/api/acme/autoRenew/enable", function(data){
+            setACMEEnableStates(data);
+        })
+    }
+    //Set the status of the acme enable icon
+    function setACMEEnableStates(enabled){
+        $("#acmeAutoRenewerStatus").text(enabled?"Enabled":"Disabled");
+        $("#acmeAutoRenewer").find("i").attr("class", enabled?"green circle icon":"red circle icon");
+    }
+    initAcmeStatus();
+
     function saveDefaultCA(){
-        //TODO: Add an endpoint to handle default CA set and load
-        alert("WIP");
+        let newDefaultEmail = $("#prefACMEEmail").val().trim();
+        let newDefaultCA = $("#defaultCA").dropdown("get value");
+
+        if (newDefaultEmail == ""){
+            msgbox("Invalid acme email given", false);
+            return;
+        }
+
+        $.post("/api/acme/autoRenew/email?set=" + newDefaultEmail, function(data){
+            if (data.error != undefined){
+                msgbox(data.error, false);
+            }
+        });
+
+        $.post("/api/acme/autoRenew/ca?set=" + newDefaultCA, function(data){
+            if (data.error != undefined){
+                msgbox(data.error, false);
+            }
+        });
+
+        msgbox("Settings updated");
+
     }
 
     //List the stored certificates

+ 1 - 1
web/components/webserv.html

@@ -9,7 +9,7 @@
             <i class="green circle icon"></i>
             <div class="content">
                 <span class="webserv_status">Running</span>
-                <div class="sub header">Listening on :<span class="webserv_port">8081</span></div>
+                <div class="sub header">Listen port :<span class="webserv_port">8081</span></div>
             </div>
         </h4>
     </div>

+ 10 - 0
web/components/zgrok.html

@@ -0,0 +1,10 @@
+<div class="standardContainer">
+    <div class="ui basic segment">
+        <h2>Service Expose Proxy</h2>
+        <p>Expose your local test-site on the internet with single command</p>
+    </div>
+    <div class="ui message">
+        <h4>Work In Progress</h4>
+        We are looking for someone to help with implementing this feature in Zoraxy. <br>If you know how to write Golang and want to contribute, feel free to create a pull request to this feature!
+    </div>
+</div>  

+ 4 - 1
web/index.html

@@ -62,7 +62,7 @@
                     <a class="item" tag="gan">
                         <i class="simplistic globe icon"></i> Global Area Network
                     </a>
-                    <a class="item" tag="">
+                    <a class="item" tag="zgrok">
                         <i class="simplistic podcast icon"></i> Service Expose Proxy
                     </a>
                     <a class="item" tag="tcpprox">
@@ -117,6 +117,9 @@
                 <!-- Global Area Networking -->
                 <div id="gan" class="functiontab" target="gan.html"></div>
 
+                <!-- Service Expose Proxy -->
+                <div id="zgrok" class="functiontab" target="zgrok.html"></div>
+
                 <!-- TCP Proxy -->
                 <div id="tcpprox" class="functiontab" target="tcpprox.html"></div>