Browse Source

auto update script executed

Toby Chui 2 years ago
parent
commit
fed51377cb

+ 3 - 2
main.go

@@ -22,8 +22,9 @@ func SetupCloseHandler() {
 	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
 	go func() {
 		<-c
-		log.Println("\r- Shutting down demo module.")
-		//Do other things like close database or opened files
+		log.Println("\r- Shutting down ReverseProxy")
+
+		sysdb.Close()
 
 		os.Exit(0)
 	}()

+ 2 - 2
mod/dynamicproxy/dpcore/dpcore.go

@@ -277,7 +277,7 @@ func (p *ReverseProxy) ProxyHTTP(rw http.ResponseWriter, req *http.Request) erro
 			p.logf("http: proxy error: %v", err)
 		}
 
-		rw.WriteHeader(http.StatusBadGateway)
+		//rw.WriteHeader(http.StatusBadGateway)
 		return err
 	}
 
@@ -290,7 +290,7 @@ func (p *ReverseProxy) ProxyHTTP(rw http.ResponseWriter, req *http.Request) erro
 				p.logf("http: proxy error: %v", err)
 			}
 
-			rw.WriteHeader(http.StatusBadGateway)
+			//rw.WriteHeader(http.StatusBadGateway)
 			return err
 		}
 	}

+ 7 - 1
mod/dynamicproxy/dynamicproxy.go

@@ -202,7 +202,13 @@ func (router *Router) SetRootProxy(proxyLocation string, requireTLS bool) error
 func (h *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 	if strings.Contains(r.Host, ".") {
 		//This might be a subdomain. See if there are any subdomain proxy router for this
-		sep := h.Parent.getSubdomainProxyEndpointFromHostname(r.Host)
+		//Remove the port if any
+		domainOnly := r.Host
+		if strings.Contains(r.Host, ":") {
+			hostPath := strings.Split(r.Host, ":")
+			domainOnly = hostPath[0]
+		}
+		sep := h.Parent.getSubdomainProxyEndpointFromHostname(domainOnly)
 		if sep != nil {
 			h.subdomainRequest(w, r, sep)
 			return

+ 1 - 0
mod/dynamicproxy/proxyRequestHandler.go

@@ -101,6 +101,7 @@ func (h *ProxyHandler) proxyRequest(w http.ResponseWriter, r *http.Request, targ
 	r.Host = r.URL.Host
 	err := target.Proxy.ServeHTTP(w, r)
 	if err != nil {
+		http.ServeFile(w, r, "./web/rperror.html")
 		log.Println(err.Error())
 	}
 }

BIN
sys.db


+ 0 - 0
sys.db.lock


File diff suppressed because it is too large
+ 27 - 0
web/img/client.ai


+ 16 - 0
web/img/client.svg

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" id="圖層_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+	 width="200px" height="200px" viewBox="0 0 200 200" enable-background="new 0 0 200 200" xml:space="preserve">
+<path fill="#C9CACA" d="M184.795,143.037c0,9.941-8.059,18-18,18H33.494c-9.941,0-18-8.059-18-18V44.952c0-9.941,8.059-18,18-18
+	h133.301c9.941,0,18,8.059,18,18V143.037z"/>
+<circle fill="#FFFFFF" cx="37.39" cy="50.88" r="6.998"/>
+<circle fill="#FFFFFF" cx="54.115" cy="50.88" r="6.998"/>
+<path fill="#FFFFFF" d="M167.188,50.88c0,3.865-3.133,6.998-6.998,6.998H72.379c-3.865,0-6.998-3.133-6.998-6.998l0,0
+	c0-3.865,3.133-6.998,6.998-6.998h87.811C164.055,43.882,167.188,47.015,167.188,50.88L167.188,50.88z"/>
+<rect x="31.296" y="66.907" fill="#FFFFFF" width="132.279" height="77.878"/>
+<circle fill="#9BCA3E" cx="96.754" cy="144.785" r="37.574"/>
+<polyline fill="none" stroke="#FFFFFF" stroke-width="8" stroke-miterlimit="10" points="108.497,133.047 93.373,153.814 
+	82.989,143.204 "/>
+</svg>

File diff suppressed because it is too large
+ 27 - 0
web/img/cloud.ai


+ 15 - 0
web/img/cloud.svg

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" id="圖層_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+	 width="200px" height="200px" viewBox="0 0 200 200" enable-background="new 0 0 200 200" xml:space="preserve">
+<ellipse fill="#9FA0A0" cx="56.465" cy="90.727" rx="22.009" ry="21.783"/>
+<circle fill="#9FA0A0" cx="110.56" cy="83.648" r="43.598"/>
+<circle fill="#9FA0A0" cx="35.456" cy="109.543" r="17.156"/>
+<circle fill="#9FA0A0" cx="165.349" cy="105.547" r="21.477"/>
+<path fill="#9FA0A0" d="M183.44,112.462c0,8.042-6.519,14.561-14.561,14.561H40.213c-8.042,0-14.561-6.519-14.561-14.561l0,0
+	c0-8.041,6.519-14.56,14.561-14.56H168.88C176.922,97.902,183.44,104.421,183.44,112.462L183.44,112.462z"/>
+<circle fill="#9BCA3D" cx="101.273" cy="119.799" r="26.411"/>
+<polyline fill="none" stroke="#FFFFFF" stroke-width="8" stroke-miterlimit="10" points="114.027,109.414 98.903,130.182 
+	88.519,119.571 "/>
+</svg>

File diff suppressed because it is too large
+ 27 - 0
web/img/host.ai


+ 13 - 0
web/img/host.svg

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" id="圖層_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+	 width="200px" height="200px" viewBox="0 0 200 200" enable-background="new 0 0 200 200" xml:space="preserve">
+<path fill="#999999" d="M168.484,113.413c0,9.941,3.317,46.324-6.624,46.324H35.359c-9.941,0-5.873-39.118-5.715-46.324
+	l17.053-50.909c1.928-9.879,8.059-18,18-18h69.419c9.941,0,15.464,7.746,18,18L168.484,113.413z"/>
+<rect x="38.068" y="118.152" fill="#FFFFFF" width="122.573" height="34.312"/>
+<circle fill="#BD2426" cx="141.566" cy="135.873" r="8.014"/>
+<circle fill="#BD2426" cx="99.354" cy="152.464" r="36.343"/>
+<line fill="none" stroke="#FFFFFF" stroke-width="6" stroke-miterlimit="10" x1="90.5" y1="144.125" x2="107.594" y2="161.946"/>
+<line fill="none" stroke="#FFFFFF" stroke-width="6" stroke-miterlimit="10" x1="90.5" y1="161.946" x2="107.594" y2="144.79"/>
+</svg>

+ 2 - 2
web/index.html

@@ -95,7 +95,7 @@
                         <table class="ui celled table">
                             <thead>
                                 <tr>
-                                    <th>Subdomain</th>
+                                    <th>Matching Domain</th>
                                     <th>Proxy To</th>
                                     <th>Remove</th>
                                 </tr>
@@ -126,7 +126,7 @@
                                 </div>
                                 <div class="field">
                                     <label>Subdomain Matching Keyword / Virtual Directory Name</label>
-                                    <input type="text" id="rootname" placeholder="s1">
+                                    <input type="text" id="rootname" placeholder="s1.mydomain.com">
                                     <div class="ui message">
                                         Example of subdomain matching keyword:<br>
                                         <code>s1.arozos.com</code> <br>(Any access starting with s1.arozos.com will be proxy to the IP address below)<br>

+ 142 - 0
web/rperror.html

@@ -0,0 +1,142 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta name="apple-mobile-web-app-capable" content="yes" />
+        <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
+        <meta charset="UTF-8">
+        <meta name="theme-color" content="#4b75ff">
+        <link rel="icon" type="image/png" href="img/small_icon.png"/>
+        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.2/semantic.min.css">
+        <link rel="preconnect" href="https://fonts.googleapis.com">
+        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
+        <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@300;400;500;700;900&display=swap" rel="stylesheet">
+        <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
+        <script src="shttps://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.2/semantic.min.js"></script>
+        <title>521 - Web server is down</title>
+        <style>
+            h1, h2, h3, h4, h5, p, a, span{
+                font-family: 'Noto Sans TC', sans-serif;
+                font-weight: 300;
+                color: rgb(88, 88, 88)
+            }
+
+            .diagram{
+                background-color: #ebebeb;
+                box-shadow: 
+                    inset 0px 11px 8px -10px #CCC,
+                    inset 0px -11px 8px -10px #CCC; 
+                padding-bottom: 2em;
+            }
+
+            .diagramHeader{
+                margin-top: 0.2em;
+            }
+        </style>
+    </head>
+    <body>
+        <div>
+            <br><br>
+            <div class="ui container">
+                <h1 style="font-size: 4rem;">Error 521</h1>
+                <p style="font-size: 2rem; margin-bottom: 0.4em;">Web server is down</p>
+                <small id="timestamp"></small>
+            </div>
+            <br><br>
+        </div>
+        <div class="diagram">
+            <div class="ui text container">
+                <div class="ui stackable grid">
+                    <div class="four wide column" align="center">
+                        <svg version="1.1" id="client_svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+                            width="100%" height="" viewBox="0 0 200 200" enable-background="new 0 0 200 200" xml:space="preserve">
+                        <path fill="#C9CACA" d="M184.795,143.037c0,9.941-8.059,18-18,18H33.494c-9.941,0-18-8.059-18-18V44.952c0-9.941,8.059-18,18-18
+                            h133.301c9.941,0,18,8.059,18,18V143.037z"/>
+                        <circle fill="#FFFFFF" cx="37.39" cy="50.88" r="6.998"/>
+                        <circle fill="#FFFFFF" cx="54.115" cy="50.88" r="6.998"/>
+                        <path fill="#FFFFFF" d="M167.188,50.88c0,3.865-3.133,6.998-6.998,6.998H72.379c-3.865,0-6.998-3.133-6.998-6.998l0,0
+                            c0-3.865,3.133-6.998,6.998-6.998h87.811C164.055,43.882,167.188,47.015,167.188,50.88L167.188,50.88z"/>
+                        <rect x="31.296" y="66.907" fill="#FFFFFF" width="132.279" height="77.878"/>
+                        <circle fill="#9BCA3E" cx="96.754" cy="144.785" r="37.574"/>
+                        <polyline fill="none" stroke="#FFFFFF" stroke-width="8" stroke-miterlimit="10" points="108.497,133.047 93.373,153.814 
+                            82.989,143.204 "/>
+                        </svg>
+                        <small>You</small>
+                        <h2 class="diagramHeader">Browser</h2>
+                        <p style="font-weight: 500; color: #9bca3e;">Working</p>
+                    </div>  
+                    <div class="two wide column" style="margin-top: 6em; text-align: center;">
+                        <i class="ui huge grey exchange alternate icon"></i>
+                    </div>
+                    <div class="four wide column" align="center">
+                        <svg version="1.1" id="cloud_svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+                            width="100%" height="" viewBox="0 0 200 200" enable-background="new 0 0 200 200" xml:space="preserve">
+                        <ellipse fill="#9FA0A0" cx="56.465" cy="90.727" rx="22.009" ry="21.783"/>
+                        <circle fill="#9FA0A0" cx="110.56" cy="83.648" r="43.598"/>
+                        <circle fill="#9FA0A0" cx="35.456" cy="109.543" r="17.156"/>
+                        <circle fill="#9FA0A0" cx="165.349" cy="105.547" r="21.477"/>
+                        <path fill="#9FA0A0" d="M183.44,112.462c0,8.042-6.519,14.561-14.561,14.561H40.213c-8.042,0-14.561-6.519-14.561-14.561l0,0
+                            c0-8.041,6.519-14.56,14.561-14.56H168.88C176.922,97.902,183.44,104.421,183.44,112.462L183.44,112.462z"/>
+                        <circle fill="#9BCA3D" cx="101.273" cy="119.799" r="26.411"/>
+                        <polyline fill="none" stroke="#FFFFFF" stroke-width="8" stroke-miterlimit="10" points="114.027,109.414 98.903,130.182 
+                            88.519,119.571 "/>
+                        </svg>
+
+                        <small>Gateway Node</small>
+                        <h2 class="diagramHeader">Reverse Proxy</h2>
+                        <p style="font-weight: 500; color: #9bca3e;">Working</p>
+                    </div>  
+                    <div class="two wide column" style="margin-top: 6em; text-align: center;">
+                        <i class="ui huge grey exchange alternate icon"></i>
+                    </div>
+                    <div class="four wide column" align="center">
+                        <svg version="1.1" id="host_svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+                            width="100%" height="" viewBox="0 0 200 200" enable-background="new 0 0 200 200" xml:space="preserve">
+                        <path fill="#999999" d="M168.484,113.413c0,9.941,3.317,46.324-6.624,46.324H35.359c-9.941,0-5.873-39.118-5.715-46.324
+                            l17.053-50.909c1.928-9.879,8.059-18,18-18h69.419c9.941,0,15.464,7.746,18,18L168.484,113.413z"/>
+                        <rect x="38.068" y="118.152" fill="#FFFFFF" width="122.573" height="34.312"/>
+                        <circle fill="#BD2426" cx="141.566" cy="135.873" r="8.014"/>
+                        <circle fill="#BD2426" cx="99.354" cy="152.464" r="36.343"/>
+                        <line fill="none" stroke="#FFFFFF" stroke-width="6" stroke-miterlimit="10" x1="90.5" y1="144.125" x2="107.594" y2="161.946"/>
+                        <line fill="none" stroke="#FFFFFF" stroke-width="6" stroke-miterlimit="10" x1="90.5" y1="161.946" x2="107.594" y2="144.79"/>
+                        </svg>
+                        <small id="host"></small>
+                        <h2 class="diagramHeader">Host</h2>
+                        <p style="font-weight: 500; color: #bd2426;">Error</p>
+                    </div>
+                  </div>
+            </div>
+        </div>
+        <div>
+            <br>
+            <div class="ui container">
+                <div class="ui stackable grid">
+                    <div class="eight wide column">
+                        <h1>What happend?</h1>
+                        <p>The web server reported a bad gateway error.<br>For more information, see the error message on the reverse proxy terminal.</p>
+                    </div>
+                    <div class="eight wide column">
+                        <h1>What can I do?</h1>
+                        <h5 style="font-weight: 500;">If you are a visitor of this website: </h5>
+                        <p>Please try again in a few minutes</p>
+                        <h5 style="font-weight: 500;">If you are the owner of this website:</h5>
+                        <div class="ui bulleted list">
+                            <div class="item">Check if the target web server is online</div>
+                            <div class="item">Visit the Reverse Proxy management interface to correct any setting errors</div>
+                        </div>
+                    </div>
+                  </div>
+            </div>
+            <br>
+        </div>
+        <div class="ui divider"></div>
+        <div class="ui container" style="color: grey; font-size: 90%">
+            <p>Reverse Proxy by imuslab, Licensed under MIT</p>
+        </div>
+        <br><br>
+
+        <script>
+            $("#timestamp").text(new Date());
+            $("#host").text(location.hostname);
+        </script>
+    </body>
+</html>

Some files were not shown because too many files changed in this diff