Browse Source

Added default site close

Toby Chui 2 months ago
parent
commit
f350628875

+ 1 - 1
mod/auth/sso/authelia/authelia.go

@@ -85,7 +85,7 @@ func (ar *AutheliaRouter) HandleAutheliaAuth(w http.ResponseWriter, r *http.Requ
 	if ar.options.AutheliaURL == "" {
 		ar.options.Logger.PrintAndLog("Authelia", "Authelia URL not set", nil)
 		w.WriteHeader(500)
-		w.Write([]byte("500 - Internal Server Error: Authelia URL not set"))
+		w.Write([]byte("500 - Internal Server Error"))
 		return errors.New("authelia URL not set")
 	}
 	protocol := "http"

+ 22 - 0
mod/dynamicproxy/Server.go

@@ -217,5 +217,27 @@ func (h *ProxyHandler) handleRootRouting(w http.ResponseWriter, r *http.Request)
 		} else {
 			w.Write(template)
 		}
+	case DefaultSite_NoResponse:
+		//No response. Just close the connection
+		h.Parent.logRequest(r, false, 444, "root-noresponse", domainOnly)
+		hijacker, ok := w.(http.Hijacker)
+		if !ok {
+			http.Error(w, "Hijacking not supported", http.StatusInternalServerError)
+			return
+		}
+		conn, _, err := hijacker.Hijack()
+		if err != nil {
+			http.Error(w, err.Error(), http.StatusInternalServerError)
+			return
+		}
+		conn.Close()
+	case DefaultSite_TeaPot:
+		//I'm a teapot
+		h.Parent.logRequest(r, false, 418, "root-teapot", domainOnly)
+		http.Error(w, "I'm a teapot", http.StatusTeapot)
+	default:
+		//Unknown routing option. Send empty response
+		h.Parent.logRequest(r, false, 544, "root-unknown", domainOnly)
+		http.Error(w, "544 - No Route Defined", 544)
 	}
 }

+ 3 - 0
mod/dynamicproxy/typedef.go

@@ -201,6 +201,9 @@ const (
 	DefaultSite_ReverseProxy            = 1
 	DefaultSite_Redirect                = 2
 	DefaultSite_NotFoundPage            = 3
+	DefaultSite_NoResponse              = 4
+
+	DefaultSite_TeaPot = 418 //I'm a teapot
 )
 
 /*

+ 7 - 8
web/components/httprp.html

@@ -125,7 +125,7 @@
                         </td>
                         <td data-label="" editable="true" datatype="vdir">${vdList}</td>
                         <td data-label="" editable="true" datatype="advanced" style="width: 350px;">
-                            ${subd.AuthenticationProvider.AuthMethod == 0x1?`<i class="ui green check icon"></i> Basic Auth`:``}
+                            ${subd.AuthenticationProvider.AuthMethod == 0x1?`<i class="ui grey key icon"></i> Basic Auth`:``}
                             ${subd.AuthenticationProvider.AuthMethod == 0x2?`<i class="ui blue key icon"></i> Authelia`:``}
                             ${subd.AuthenticationProvider.AuthMethod == 0x3?`<i class="ui yellow key icon"></i> Oauth2`:``}
                             ${subd.AuthenticationProvider.AuthMethod != 0x0 && subd.RequireRateLimit?"<br>":""}
@@ -197,9 +197,9 @@
 
                     let rule = accessRuleMap[thisAccessRuleID];
                     if (rule == undefined){
-                        //Old configs with no access rule field, use default
-                        rule = {};
-                        rule.ID = "default";
+                        //Missing config or config too old
+                        $(this).html(`<i class="ui red exclamation triangle icon"></i> <b style="color: #db2828;">Access Rule Error</b>`);
+                        return;
                     }
                     let icon = `<i class="ui grey filter icon"></i>`;
                     if (rule.ID == "default"){
@@ -278,7 +278,6 @@
             }else if (datatype == "advanced"){
                 let authProvider = payload.AuthenticationProvider.AuthMethod;
                 
-
                 let skipWebSocketOriginCheck = payload.SkipWebSocketOriginCheck;
                 let wsCheckstate = "";
                 if (skipWebSocketOriginCheck){
@@ -305,19 +304,19 @@
                         <label><b>Authentication Provider</b></label>
                         <div class="field">
                             <div class="ui radio checkbox">
-                                <input type="radio" value="0" checked="checked" name="authProviderType">
+                                <input type="radio" value="0" name="authProviderType" ${authProvider==0x0?"checked":""}>
                                 <label>None (Anyone can access)</label>
                             </div>
                         </div>
                         <div class="field">
                             <div class="ui radio checkbox">
-                                <input type="radio" value="1" name="authProviderType">
+                                <input type="radio" value="1" name="authProviderType" ${authProvider==0x1?"checked":""}>
                                 <label>Basic Auth</label>
                             </div>
                         </div>
                         <div class="field">
                             <div class="ui radio checkbox">
-                                <input type="radio" value="2" name="authProviderType">
+                                <input type="radio" value="2" name="authProviderType" ${authProvider==0x2?"checked":""}>
                                 <label>Authelia</label>
                             </div>
                         </div>

+ 12 - 0
web/components/rproot.html

@@ -37,6 +37,14 @@
                         </label>
                     </div>
                 </div>
+                <div class="field">
+                    <div class="ui radio defaultsite checkbox">
+                        <input type="radio" name="defaultsiteOption" value="closeresp">
+                        <label>Close Connection<br>
+                            <small>Close the connection without any response</small>
+                        </label>
+                    </div>
+                </div>
             </div>
         </div>
 
@@ -105,6 +113,8 @@
             currentDefaultSiteOption = 2;
         }else if (selectedDefaultSite == "notfound"){
             currentDefaultSiteOption = 3;
+        }else if (selectedDefaultSite == "closeresp"){
+            currentDefaultSiteOption = 4;
         }else{
             //Unknown option
             return;
@@ -137,6 +147,8 @@
                     $("#redirectDomain").val(data.DefaultSiteValue);
                 }else if (proxyType == 3){
                     $radios.filter('[value=notfound]').prop('checked', true);
+                }else if (proxyType == 4){
+                    $radios.filter('[value=closeresp]').prop('checked', true);
                 }
                 updateAvaibleDefaultSiteOptions();