Browse Source

Fixed acme domain too long table cant see bug

Toby Chui 3 months ago
parent
commit
e5935be22c
2 changed files with 69 additions and 10 deletions
  1. 57 0
      mod/dynamicproxy/authelia.go
  2. 12 10
      web/snippet/acme.html

+ 57 - 0
mod/dynamicproxy/authelia.go

@@ -0,0 +1,57 @@
+package dynamicproxy
+
+import (
+	"errors"
+	"fmt"
+	"net/http"
+	"net/url"
+)
+
+func (h *ProxyHandler) handleAutheliaAuthRouting(w http.ResponseWriter, r *http.Request, pe *ProxyEndpoint) error {
+	err := handleAutheliaAuth(w, r, pe)
+	if err != nil {
+		h.Parent.logRequest(r, false, 401, "host", r.URL.Hostname())
+	}
+	return err
+}
+
+func handleAutheliaAuth(w http.ResponseWriter, r *http.Request, pe *ProxyEndpoint) error {
+
+	client := &http.Client{}
+
+	// TODO: provide authelia url by config variable
+	req, err := http.NewRequest("POST", "https://authelia.mydomain.com/api/verify", nil)
+	if err != nil {
+		pe.parent.Option.Logger.PrintAndLog("Authelia", "Unable to create request", err)
+		w.WriteHeader(401)
+		return errors.New("unauthorized")
+	}
+
+	scheme := "http"
+	if r.TLS != nil {
+		scheme = "https"
+	}
+	req.Header.Add("X-Original-URL", fmt.Sprintf("%s://%s", scheme, r.Host))
+
+	// Copy cookies from the incoming request
+	for _, cookie := range r.Cookies() {
+		req.AddCookie(cookie)
+	}
+
+	resp, err := client.Do(req)
+	if err != nil {
+		pe.parent.Option.Logger.PrintAndLog("Authelia", "Unable to verify", err)
+		w.WriteHeader(401)
+		return errors.New("unauthorized")
+	}
+
+	if resp.StatusCode != 200 {
+		// TODO: provide authelia url by config variable
+		redirectURL := "https://authelia.mydomain.com/?rd=" + url.QueryEscape(scheme+"://"+r.Host+r.URL.String()) + "&rm=" + r.Method
+
+		http.Redirect(w, r, redirectURL, http.StatusSeeOther)
+		return errors.New("unauthorized")
+	}
+
+	return nil
+}

+ 12 - 10
web/snippet/acme.html

@@ -67,16 +67,18 @@
               <button id="renewNowBtn" onclick="renewNow();" class="ui basic right floated button" style="margin-top: -2em;"><i class="yellow refresh icon"></i> Renew Now</button>
               <button id="renewNowBtn" onclick="renewNow();" class="ui basic right floated button" style="margin-top: -2em;"><i class="yellow refresh icon"></i> Renew Now</button>
               <div class="ui horizontal divider"> OR </div>
               <div class="ui horizontal divider"> OR </div>
               <p>Select the certificates to automatic renew in the list below</p>
               <p>Select the certificates to automatic renew in the list below</p>
-              <table id="domainCertFileTable" class="ui very compact unstackable basic disabled table">
-                <thead>
-                  <tr>
-                    <th>Domain Name</th>
-                    <th>Match Rule</th>
-                    <th>Auto-Renew</th>
-                  </tr>
-                </thead>
-                <tbody id="domainTableBody"></tbody>
-              </table>
+              <div style="width: 100%; overflow-x: auto; margin-bottom: 1em; min-height: 300px;">
+                <table id="domainCertFileTable" class="ui very compact unstackable basic disabled table">
+                  <thead>
+                    <tr>
+                      <th>Domain Name</th>
+                      <th>Match Rule</th>
+                      <th>Auto-Renew</th>
+                    </tr>
+                  </thead>
+                  <tbody id="domainTableBody"></tbody>
+                </table>
+              </div>
               <small><i class="ui red info circle icon"></i> Domain in red are expired</small><br>
               <small><i class="ui red info circle icon"></i> Domain in red are expired</small><br>
               <div class="ui yellow message">
               <div class="ui yellow message">
                 Certificate Renew only works on the certification authority (CA) supported by Zoraxy. Check Zoraxy wiki for more information on supported list of CAs.
                 Certificate Renew only works on the certification authority (CA) supported by Zoraxy. Check Zoraxy wiki for more information on supported list of CAs.