Browse Source

auto update script executed

TC pushbot 5 3 years ago
parent
commit
c51cd98714
3 changed files with 88 additions and 12 deletions
  1. 15 0
      mod/dynamicproxy/dynamicproxy.go
  2. 21 2
      reverseproxy.go
  3. 52 10
      web/index.html

+ 15 - 0
mod/dynamicproxy/dynamicproxy.go

@@ -146,6 +146,21 @@ func (router *Router) AddVirtualDirectoryProxyService(rootname string, domain st
 	return nil
 }
 
+/*
+	Remove routing from RP
+
+*/
+func (router *Router) RemoveProxy(ptype string, key string) error {
+	if ptype == "vdir" {
+		router.ProxyEndpoints.Delete(key)
+		return nil
+	} else if ptype == "subd" {
+		router.SubdomainEndpoint.Delete(key)
+		return nil
+	}
+	return errors.New("invalid ptype")
+}
+
 /*
 	Add an default router for the proxy server
 */

+ 21 - 2
reverseproxy.go

@@ -84,7 +84,7 @@ func ReverseProxyHandleAddEndpoint(w http.ResponseWriter, r *http.Request) {
 	useTLS := (tls == "true")
 
 	if eptype == "vdir" {
-		vdir, err := mv(r, "vdir", true)
+		vdir, err := mv(r, "rootname", true)
 		if err != nil {
 			sendErrorResponse(w, "vdir not defined")
 			return
@@ -92,7 +92,7 @@ func ReverseProxyHandleAddEndpoint(w http.ResponseWriter, r *http.Request) {
 		dynamicProxyRouter.AddVirtualDirectoryProxyService(vdir, endpoint, useTLS)
 
 	} else if eptype == "subd" {
-		subdomain, err := mv(r, "subdomain", true)
+		subdomain, err := mv(r, "rootname", true)
 		if err != nil {
 			sendErrorResponse(w, "subdomain not defined")
 			return
@@ -106,6 +106,25 @@ func ReverseProxyHandleAddEndpoint(w http.ResponseWriter, r *http.Request) {
 
 }
 
+func DeleteProxyEndpoint(w http.ResponseWriter, r *http.Request) {
+	ep, err := mv(r, "ep", true)
+	if err != nil {
+		sendErrorResponse(w, "Invalid ep given")
+	}
+
+	ptype, err := mv(r, "ptype", true)
+	if err != nil {
+		sendErrorResponse(w, "Invalid ptype given")
+	}
+
+	err = dynamicProxyRouter.RemoveProxy(ptype, ep)
+	if err != nil {
+		sendErrorResponse(w, err.Error())
+	}
+
+	sendOK(w)
+}
+
 func ReverseProxyStatus(w http.ResponseWriter, r *http.Request) {
 	js, _ := json.Marshal(dynamicProxyRouter)
 	sendJSONResponse(w, string(js))

+ 52 - 10
web/index.html

@@ -107,22 +107,22 @@
                         <div class=""> 
                             <h3><i class="ui exchange icon"></i> New Proxy Endpoint</h3>
                             <p>You can create a proxy endpoing by subdomain or virtual directories</p>
-                            <form class="ui form">
+                            <div class="ui form">
                                 <div class="field">
                                     <label>Proxy Type</label>
                                     <div class="ui selection dropdown">
-                                        <input type="hidden" name="ptype">
+                                        <input type="hidden" id="ptype" value="subd">
                                         <i class="dropdown icon"></i>
                                         <div class="default text">Proxy Type</div>
                                         <div class="menu">
-                                            <div class="item" data-value="domain">Sub-domain</div>
+                                            <div class="item" data-value="subd">Sub-domain</div>
                                             <div class="item" data-value="vdir">Virtual Directory</div>
                                         </div>
                                     </div>
                                 </div>
                                 <div class="field">
                                     <label>Subdomain Matching Keyword / Virtual Directory Name</label>
-                                    <input type="text" name="first-name" placeholder="First Name">
+                                    <input type="text" id="rootname" placeholder="s1">
                                     <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>
@@ -132,12 +132,17 @@
                                 </div>
                                 <div class="field">
                                     <label>IP Address or Domain Name with port</label>
-                                    <input type="text" name="last-name" placeholder="Last Name">
+                                    <input type="text" id="proxyDomain">
                                     <small>E.g. 192.168.0.101:8000 or example.com</small>
                                 </div>
-                                
-                                <button class="ui teal button" type="submit">Create Proxy Endpoint</button>
-                            </form>
+                                    <div class="field">
+                                    <div class="ui checkbox">
+                                        <input type="checkbox" id="reqTls">
+                                        <label>Proxy Target require TLS Connection (Unstable)</label>
+                                    </div>
+                                </div>
+                                <button class="ui teal button" onclick="newProxyEndpoint();">Create Proxy Endpoint</button>
+                            </div>
                         </div>
                      </div>
 
@@ -162,6 +167,7 @@
             initRPStaste();
             $("#status").slideDown('fast');
             $(".ui.dropdown").dropdown();
+            $(".ui.checkbox").checkbox();
 
             $("#mainmenu").find(".item").each(function(){
                 $(this).on("click", function(e){
@@ -238,8 +244,8 @@
                 });
             }
 
-            initSubdomainProxy();
-            function initSubdomainProxy(){
+            listSubd();
+            function listSubd(){
                 $("#subdList").html(``);
                 $.get("list?type=subd", function(data){
                     if (data.error !== undefined){
@@ -266,7 +272,43 @@
                 });
             }
 
+            //New Proxy Endpoint
+            function newProxyEndpoint(){
+                var type = $("#ptype").val();
+                var rootname = $("#rootname").val();
+                var proxyDomain = $("#proxyDomain").val();
+                var useTLS = $("#reqTls")[0].checked;
+
+                if (rootname.trim() == ""){
+                    $("#rootname").parent().addClass("error");
+                    return
+                }else{
+                    $("#rootname").parent().removeClass("error");
+                }
+
+                if (proxyDomain.trim() == ""){
+                    $("#proxyDomain").parent().addClass("error");
+                    return
+                }else{
+                    $("#proxyDomain").parent().removeClass("error");
+                }
 
+                //Create the endpoint by calling add
+                $.ajax({
+                    url: "./add",
+                    data: {type: type, rootname: rootname, tls: useTLS, ep: proxyDomain},
+                    success: function(data){
+                        if (data.error != undefined){
+                            alert(data.error);
+                        }else{
+                            //OK
+                            listVdirs();
+                            listSubd();
+                        }
+                    }
+                });
+               
+            }
 
             function errmsg(message){
                 $("#errmsg").html(`<i class="red remove icon"></i> ${message}`);