Kaynağa Gözat

auto update script executed

Toby Chui 1 yıl önce
ebeveyn
işleme
1bfd34f22a
3 değiştirilmiş dosya ile 13 ekleme ve 1 silme
  1. 9 0
      cert.go
  2. 1 1
      web/components/cert.html
  3. 3 0
      web/snippet/acme.html

+ 9 - 0
cert.go

@@ -11,6 +11,7 @@ import (
 	"os"
 	"path/filepath"
 	"strings"
+	"time"
 
 	"imuslab.com/zoraxy/mod/utils"
 )
@@ -45,6 +46,7 @@ func handleListCertificate(w http.ResponseWriter, r *http.Request) {
 			Domain           string
 			LastModifiedDate string
 			ExpireDate       string
+			RemainingDays    int
 		}
 
 		results := []*CertInfo{}
@@ -61,6 +63,7 @@ func handleListCertificate(w http.ResponseWriter, r *http.Request) {
 
 			certExpireTime := "Unknown"
 			certBtyes, err := os.ReadFile(certFilepath)
+			expiredIn := 0
 			if err != nil {
 				//Unable to load this file
 				continue
@@ -71,6 +74,11 @@ func handleListCertificate(w http.ResponseWriter, r *http.Request) {
 					cert, err := x509.ParseCertificate(block.Bytes)
 					if err == nil {
 						certExpireTime = cert.NotAfter.Format("2006-01-02 15:04:05")
+
+						duration := cert.NotAfter.Sub(time.Now())
+
+						// Convert the duration to days
+						expiredIn = int(duration.Hours() / 24)
 					}
 				}
 			}
@@ -79,6 +87,7 @@ func handleListCertificate(w http.ResponseWriter, r *http.Request) {
 				Domain:           filename,
 				LastModifiedDate: modifiedTime,
 				ExpireDate:       certExpireTime,
+				RemainingDays:    expiredIn,
 			}
 
 			results = append(results, &thisCertInfo)

+ 1 - 1
web/components/cert.html

@@ -114,7 +114,7 @@
                     $("#certifiedDomainList").append(`<tr>
                         <td>${entry.Domain}</td>
                         <td>${entry.LastModifiedDate}</td>
-                        <td>${entry.ExpireDate}</td>
+                        <td>${entry.ExpireDate} (${entry.RemainingDays} days left)</td>
                         <td><button title="Delete key-pair" class="ui mini basic red icon button" onclick="deleteCertificate('${entry.Domain}');"><i class="ui red trash icon"></i></button></td>
                     </tr>`);
                 });

+ 3 - 0
web/snippet/acme.html

@@ -201,6 +201,7 @@
 
     // Button click event handler for obtaining certificate
     $("#obtainButton").click(function() {
+      $("#obtainButton").addClass("loading").addClass("disabled");
       obtainCertificate();
     });
 
@@ -230,6 +231,7 @@
           ca: ca,
         },
         success: function(response) {
+          $("#obtainButton").removeClass("loading").removeClass("disabled");
           if (response.error) {
             console.log("Error:", response.error);
             // Show error message
@@ -244,6 +246,7 @@
           }
         },
         error: function(error) {
+          $("#obtainButton").removeClass("loading").removeClass("disabled");
           console.log("Failed to renewed certificate:", error);
         }
       });