|
@@ -21,6 +21,9 @@ var (
|
|
|
|
|
|
// Add user customizable reverse proxy
|
|
|
func ReverseProxtInit() {
|
|
|
+ /*
|
|
|
+ Load Reverse Proxy Global Settings
|
|
|
+ */
|
|
|
inboundPort := 80
|
|
|
if sysdb.KeyExists("settings", "inbound") {
|
|
|
sysdb.Read("settings", "inbound", &inboundPort)
|
|
@@ -63,6 +66,12 @@ func ReverseProxtInit() {
|
|
|
SystemWideLogger.Println("Force HTTPS mode disabled")
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ Create a new proxy object
|
|
|
+ The DynamicProxy is the parent of all reverse proxy handlers,
|
|
|
+ use for managemening and provide functions to access proxy handlers
|
|
|
+ */
|
|
|
+
|
|
|
dprouter, err := dynamicproxy.NewDynamicProxy(dynamicproxy.RouterOption{
|
|
|
HostUUID: nodeUUID,
|
|
|
Port: inboundPort,
|
|
@@ -83,55 +92,28 @@ func ReverseProxtInit() {
|
|
|
|
|
|
dynamicProxyRouter = dprouter
|
|
|
|
|
|
- //Load all conf from files
|
|
|
+ /*
|
|
|
+
|
|
|
+ Load all conf from files
|
|
|
+
|
|
|
+ */
|
|
|
confs, _ := filepath.Glob("./conf/proxy/*.config")
|
|
|
- rootConfigExists := false
|
|
|
for _, conf := range confs {
|
|
|
- record, err := LoadReverseProxyConfig(conf)
|
|
|
+ err := LoadReverseProxyConfig(conf)
|
|
|
if err != nil {
|
|
|
SystemWideLogger.PrintAndLog("Proxy", "Failed to load config file: "+filepath.Base(conf), err)
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- if record.ProxyType == "root" {
|
|
|
- dynamicProxyRouter.SetRootProxy(&dynamicproxy.RootOptions{
|
|
|
- ProxyLocation: record.ProxyTarget,
|
|
|
- RequireTLS: record.UseTLS,
|
|
|
- })
|
|
|
- rootConfigExists = true
|
|
|
- } else if record.ProxyType == "subd" {
|
|
|
- dynamicProxyRouter.AddSubdomainRoutingService(&dynamicproxy.SubdOptions{
|
|
|
- MatchingDomain: record.Rootname,
|
|
|
- Domain: record.ProxyTarget,
|
|
|
- RequireTLS: record.UseTLS,
|
|
|
- BypassGlobalTLS: record.BypassGlobalTLS,
|
|
|
- SkipCertValidations: record.SkipTlsValidation,
|
|
|
- RequireBasicAuth: record.RequireBasicAuth,
|
|
|
- BasicAuthCredentials: record.BasicAuthCredentials,
|
|
|
- BasicAuthExceptionRules: record.BasicAuthExceptionRules,
|
|
|
- })
|
|
|
- } else if record.ProxyType == "vdir" {
|
|
|
- dynamicProxyRouter.AddVirtualDirectoryProxyService(&dynamicproxy.VdirOptions{
|
|
|
- RootName: record.Rootname,
|
|
|
- Domain: record.ProxyTarget,
|
|
|
- RequireTLS: record.UseTLS,
|
|
|
- BypassGlobalTLS: record.BypassGlobalTLS,
|
|
|
- SkipCertValidations: record.SkipTlsValidation,
|
|
|
- RequireBasicAuth: record.RequireBasicAuth,
|
|
|
- BasicAuthCredentials: record.BasicAuthCredentials,
|
|
|
- BasicAuthExceptionRules: record.BasicAuthExceptionRules,
|
|
|
- })
|
|
|
- } else {
|
|
|
- SystemWideLogger.PrintAndLog("Proxy", "Unsupported endpoint type: "+record.ProxyType+". Skipping "+filepath.Base(conf), nil)
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- if !rootConfigExists {
|
|
|
+ if dynamicProxyRouter.Root == nil {
|
|
|
//Root config not set (new deployment?), use internal static web server as root
|
|
|
- dynamicProxyRouter.SetRootProxy(&dynamicproxy.RootOptions{
|
|
|
- ProxyLocation: "127.0.0.1:" + staticWebServer.GetListeningPort(),
|
|
|
- RequireTLS: false,
|
|
|
- })
|
|
|
+ defaultRootRouter, err := GetDefaultRootConfig()
|
|
|
+ if err != nil {
|
|
|
+ SystemWideLogger.PrintAndLog("Proxy", "Failed to generate default root routing", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ dynamicProxyRouter.SetProxyRouteAsRoot(defaultRootRouter)
|
|
|
}
|
|
|
|
|
|
//Start Service
|
|
@@ -183,7 +165,7 @@ func ReverseProxyHandleOnOff(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
func ReverseProxyHandleAddEndpoint(w http.ResponseWriter, r *http.Request) {
|
|
|
- eptype, err := utils.PostPara(r, "type") //Support root, vdir and subd
|
|
|
+ eptype, err := utils.PostPara(r, "type") //Support root and host
|
|
|
if err != nil {
|
|
|
utils.SendErrorResponse(w, "type not defined")
|
|
|
return
|
|
@@ -251,73 +233,96 @@ func ReverseProxyHandleAddEndpoint(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- rootname := ""
|
|
|
- if eptype == "vdir" {
|
|
|
- vdir, err := utils.PostPara(r, "rootname")
|
|
|
+ var proxyEndpointCreated *dynamicproxy.ProxyEndpoint
|
|
|
+ if eptype == "host" {
|
|
|
+ rootOrMatchingDomain, err := utils.PostPara(r, "rootname")
|
|
|
if err != nil {
|
|
|
- utils.SendErrorResponse(w, "vdir not defined")
|
|
|
+ utils.SendErrorResponse(w, "subdomain not defined")
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- //Vdir must start with /
|
|
|
- if !strings.HasPrefix(vdir, "/") {
|
|
|
- vdir = "/" + vdir
|
|
|
+ thisProxyEndpoint := dynamicproxy.ProxyEndpoint{
|
|
|
+ //I/O
|
|
|
+ ProxyType: dynamicproxy.ProxyType_Host,
|
|
|
+ RootOrMatchingDomain: rootOrMatchingDomain,
|
|
|
+ Domain: endpoint,
|
|
|
+ //TLS
|
|
|
+ RequireTLS: useTLS,
|
|
|
+ BypassGlobalTLS: useBypassGlobalTLS,
|
|
|
+ SkipCertValidations: skipTlsValidation,
|
|
|
+ //VDir
|
|
|
+ VirtualDirectories: []*dynamicproxy.ProxyEndpoint{},
|
|
|
+ //Auth
|
|
|
+ RequireBasicAuth: requireBasicAuth,
|
|
|
+ BasicAuthCredentials: basicAuthCredentials,
|
|
|
+ BasicAuthExceptionRules: []*dynamicproxy.BasicAuthExceptionRule{},
|
|
|
+ DefaultSiteOption: 0,
|
|
|
+ DefaultSiteValue: "",
|
|
|
+ }
|
|
|
+
|
|
|
+ preparedEndpoint, err := dynamicProxyRouter.PrepareProxyRoute(&thisProxyEndpoint)
|
|
|
+ if err != nil {
|
|
|
+ utils.SendErrorResponse(w, "unable to prepare proxy route to target endpoint: "+err.Error())
|
|
|
+ return
|
|
|
}
|
|
|
- rootname = vdir
|
|
|
|
|
|
- thisOption := dynamicproxy.VdirOptions{
|
|
|
- RootName: vdir,
|
|
|
- Domain: endpoint,
|
|
|
- RequireTLS: useTLS,
|
|
|
- BypassGlobalTLS: useBypassGlobalTLS,
|
|
|
- SkipCertValidations: skipTlsValidation,
|
|
|
- RequireBasicAuth: requireBasicAuth,
|
|
|
- BasicAuthCredentials: basicAuthCredentials,
|
|
|
+ dynamicProxyRouter.AddProxyRouteToRuntime(preparedEndpoint)
|
|
|
+ proxyEndpointCreated = &thisProxyEndpoint
|
|
|
+ } else if eptype == "root" {
|
|
|
+ //Get the default site options and target
|
|
|
+ dsOptString, err := utils.PostPara(r, "defaultSiteOpt")
|
|
|
+ if err != nil {
|
|
|
+ utils.SendErrorResponse(w, "default site action not defined")
|
|
|
+ return
|
|
|
}
|
|
|
- dynamicProxyRouter.AddVirtualDirectoryProxyService(&thisOption)
|
|
|
|
|
|
- } else if eptype == "subd" {
|
|
|
- subdomain, err := utils.PostPara(r, "rootname")
|
|
|
+ var defaultSiteOption int = 1
|
|
|
+ opt, err := strconv.Atoi(dsOptString)
|
|
|
if err != nil {
|
|
|
+ utils.SendErrorResponse(w, "invalid default site option")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ defaultSiteOption = opt
|
|
|
+
|
|
|
+ dsVal, err := utils.PostPara(r, "defaultSiteVal")
|
|
|
+ if err != nil && (defaultSiteOption == 2 || defaultSiteOption == 3) {
|
|
|
+ //Reverse proxy or redirect, must require value to be set
|
|
|
utils.SendErrorResponse(w, "subdomain not defined")
|
|
|
return
|
|
|
}
|
|
|
- rootname = subdomain
|
|
|
- thisOption := dynamicproxy.SubdOptions{
|
|
|
- MatchingDomain: subdomain,
|
|
|
+
|
|
|
+ //Write the root options to file
|
|
|
+ rootRoutingEndpoint := dynamicproxy.ProxyEndpoint{
|
|
|
+ ProxyType: dynamicproxy.ProxyType_Root,
|
|
|
+ RootOrMatchingDomain: "/",
|
|
|
Domain: endpoint,
|
|
|
RequireTLS: useTLS,
|
|
|
- BypassGlobalTLS: useBypassGlobalTLS,
|
|
|
- SkipCertValidations: skipTlsValidation,
|
|
|
- RequireBasicAuth: requireBasicAuth,
|
|
|
- BasicAuthCredentials: basicAuthCredentials,
|
|
|
+ BypassGlobalTLS: false,
|
|
|
+ SkipCertValidations: false,
|
|
|
+
|
|
|
+ DefaultSiteOption: defaultSiteOption,
|
|
|
+ DefaultSiteValue: dsVal,
|
|
|
}
|
|
|
- dynamicProxyRouter.AddSubdomainRoutingService(&thisOption)
|
|
|
- } else if eptype == "root" {
|
|
|
- rootname = "root"
|
|
|
- thisOption := dynamicproxy.RootOptions{
|
|
|
- ProxyLocation: endpoint,
|
|
|
- RequireTLS: useTLS,
|
|
|
+ preparedRootProxyRoute, err := dynamicProxyRouter.PrepareProxyRoute(&rootRoutingEndpoint)
|
|
|
+ if err != nil {
|
|
|
+ utils.SendErrorResponse(w, "unable to prepare root routing: "+err.Error())
|
|
|
+ return
|
|
|
}
|
|
|
- dynamicProxyRouter.SetRootProxy(&thisOption)
|
|
|
+
|
|
|
+ dynamicProxyRouter.SetProxyRouteAsRoot(preparedRootProxyRoute)
|
|
|
+ proxyEndpointCreated = &rootRoutingEndpoint
|
|
|
} else {
|
|
|
//Invalid eptype
|
|
|
- utils.SendErrorResponse(w, "Invalid endpoint type")
|
|
|
+ utils.SendErrorResponse(w, "invalid endpoint type")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- //Save it
|
|
|
- thisProxyConfigRecord := Record{
|
|
|
- ProxyType: eptype,
|
|
|
- Rootname: rootname,
|
|
|
- ProxyTarget: endpoint,
|
|
|
- UseTLS: useTLS,
|
|
|
- BypassGlobalTLS: useBypassGlobalTLS,
|
|
|
- SkipTlsValidation: skipTlsValidation,
|
|
|
- RequireBasicAuth: requireBasicAuth,
|
|
|
- BasicAuthCredentials: basicAuthCredentials,
|
|
|
+ //Save the config to file
|
|
|
+ err = SaveReverseProxyConfig(proxyEndpointCreated)
|
|
|
+ if err != nil {
|
|
|
+ SystemWideLogger.PrintAndLog("Proxy", "Unable to save new proxy rule to file", err)
|
|
|
+ return
|
|
|
}
|
|
|
- SaveReverseProxyConfigToFile(&thisProxyConfigRecord)
|
|
|
|
|
|
//Update utm if exists
|
|
|
if uptimeMonitor != nil {
|
|
@@ -330,17 +335,11 @@ func ReverseProxyHandleAddEndpoint(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
/*
|
|
|
ReverseProxyHandleEditEndpoint handles proxy endpoint edit
|
|
|
-This endpoint do not handle
|
|
|
-basic auth credential update. The credential
|
|
|
-will be loaded from old config and reused
|
|
|
+(host only, for root use Default Site page to edit)
|
|
|
+This endpoint do not handle basic auth credential update.
|
|
|
+The credential will be loaded from old config and reused
|
|
|
*/
|
|
|
func ReverseProxyHandleEditEndpoint(w http.ResponseWriter, r *http.Request) {
|
|
|
- eptype, err := utils.PostPara(r, "type") //Support root, vdir and subd
|
|
|
- if err != nil {
|
|
|
- utils.SendErrorResponse(w, "type not defined")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
rootNameOrMatchingDomain, err := utils.PostPara(r, "rootname")
|
|
|
if err != nil {
|
|
|
utils.SendErrorResponse(w, "Target proxy rule not defined")
|
|
@@ -381,50 +380,31 @@ func ReverseProxyHandleEditEndpoint(w http.ResponseWriter, r *http.Request) {
|
|
|
requireBasicAuth := (rba == "true")
|
|
|
|
|
|
//Load the previous basic auth credentials from current proxy rules
|
|
|
- targetProxyEntry, err := dynamicProxyRouter.LoadProxy(eptype, rootNameOrMatchingDomain)
|
|
|
+ targetProxyEntry, err := dynamicProxyRouter.LoadProxy(rootNameOrMatchingDomain)
|
|
|
if err != nil {
|
|
|
utils.SendErrorResponse(w, "Target proxy config not found or could not be loaded")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if eptype == "vdir" {
|
|
|
- thisOption := dynamicproxy.VdirOptions{
|
|
|
- RootName: targetProxyEntry.RootOrMatchingDomain,
|
|
|
- Domain: endpoint,
|
|
|
- RequireTLS: useTLS,
|
|
|
- BypassGlobalTLS: false,
|
|
|
- SkipCertValidations: skipTlsValidation,
|
|
|
- RequireBasicAuth: requireBasicAuth,
|
|
|
- BasicAuthCredentials: targetProxyEntry.BasicAuthCredentials,
|
|
|
- }
|
|
|
- targetProxyEntry.Remove()
|
|
|
- dynamicProxyRouter.AddVirtualDirectoryProxyService(&thisOption)
|
|
|
+ //Generate a new proxyEndpoint from the new config
|
|
|
+ newProxyEndpoint := dynamicproxy.CopyEndpoint(targetProxyEntry)
|
|
|
+ newProxyEndpoint.Domain = endpoint
|
|
|
+ newProxyEndpoint.RequireTLS = useTLS
|
|
|
+ newProxyEndpoint.BypassGlobalTLS = bypassGlobalTLS
|
|
|
+ newProxyEndpoint.SkipCertValidations = skipTlsValidation
|
|
|
+ newProxyEndpoint.RequireBasicAuth = requireBasicAuth
|
|
|
|
|
|
- } else if eptype == "subd" {
|
|
|
- thisOption := dynamicproxy.SubdOptions{
|
|
|
- MatchingDomain: targetProxyEntry.RootOrMatchingDomain,
|
|
|
- Domain: endpoint,
|
|
|
- RequireTLS: useTLS,
|
|
|
- BypassGlobalTLS: bypassGlobalTLS,
|
|
|
- SkipCertValidations: skipTlsValidation,
|
|
|
- RequireBasicAuth: requireBasicAuth,
|
|
|
- BasicAuthCredentials: targetProxyEntry.BasicAuthCredentials,
|
|
|
- }
|
|
|
- targetProxyEntry.Remove()
|
|
|
- dynamicProxyRouter.AddSubdomainRoutingService(&thisOption)
|
|
|
+ //Prepare to replace the current routing rule
|
|
|
+ readyRoutingRule, err := dynamicProxyRouter.PrepareProxyRoute(newProxyEndpoint)
|
|
|
+ if err != nil {
|
|
|
+ utils.SendErrorResponse(w, err.Error())
|
|
|
+ return
|
|
|
}
|
|
|
+ targetProxyEntry.Remove()
|
|
|
+ dynamicProxyRouter.AddProxyRouteToRuntime(readyRoutingRule)
|
|
|
|
|
|
//Save it to file
|
|
|
- thisProxyConfigRecord := Record{
|
|
|
- ProxyType: eptype,
|
|
|
- Rootname: targetProxyEntry.RootOrMatchingDomain,
|
|
|
- ProxyTarget: endpoint,
|
|
|
- UseTLS: useTLS,
|
|
|
- SkipTlsValidation: skipTlsValidation,
|
|
|
- RequireBasicAuth: requireBasicAuth,
|
|
|
- BasicAuthCredentials: targetProxyEntry.BasicAuthCredentials,
|
|
|
- }
|
|
|
- SaveReverseProxyConfigToFile(&thisProxyConfigRecord)
|
|
|
+ SaveReverseProxyConfig(newProxyEndpoint)
|
|
|
|
|
|
//Update uptime monitor
|
|
|
UpdateUptimeMonitorTargets()
|
|
@@ -453,7 +433,7 @@ func DeleteProxyEndpoint(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
//Remove the config from file
|
|
|
- RemoveReverseProxyConfigFile(ep)
|
|
|
+ RemoveReverseProxyConfig(ep)
|
|
|
|
|
|
//Update utm if exists
|
|
|
if uptimeMonitor != nil {
|
|
@@ -483,14 +463,8 @@ func UpdateProxyBasicAuthCredentials(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- ptype, err := utils.GetPara(r, "ptype")
|
|
|
- if err != nil {
|
|
|
- utils.SendErrorResponse(w, "Invalid ptype given")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
//Load the target proxy object from router
|
|
|
- targetProxy, err := dynamicProxyRouter.LoadProxy(ptype, ep)
|
|
|
+ targetProxy, err := dynamicProxyRouter.LoadProxy(ep)
|
|
|
if err != nil {
|
|
|
utils.SendErrorResponse(w, err.Error())
|
|
|
return
|
|
@@ -512,17 +486,6 @@ func UpdateProxyBasicAuthCredentials(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- ptype, err := utils.PostPara(r, "ptype")
|
|
|
- if err != nil {
|
|
|
- utils.SendErrorResponse(w, "Invalid ptype given")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if ptype != "vdir" && ptype != "subd" {
|
|
|
- utils.SendErrorResponse(w, "Invalid ptype given")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
creds, err := utils.PostPara(r, "creds")
|
|
|
if err != nil {
|
|
|
utils.SendErrorResponse(w, "Invalid ptype given")
|
|
@@ -530,7 +493,7 @@ func UpdateProxyBasicAuthCredentials(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
//Load the target proxy object from router
|
|
|
- targetProxy, err := dynamicProxyRouter.LoadProxy(ptype, ep)
|
|
|
+ targetProxy, err := dynamicProxyRouter.LoadProxy(ep)
|
|
|
if err != nil {
|
|
|
utils.SendErrorResponse(w, err.Error())
|
|
|
return
|
|
@@ -580,7 +543,7 @@ func UpdateProxyBasicAuthCredentials(w http.ResponseWriter, r *http.Request) {
|
|
|
targetProxy.BasicAuthCredentials = mergedCredentials
|
|
|
|
|
|
//Save it to file
|
|
|
- SaveReverseProxyEndpointToFile(targetProxy)
|
|
|
+ SaveReverseProxyConfig(targetProxy)
|
|
|
|
|
|
//Replace runtime configuration
|
|
|
targetProxy.UpdateToRuntime()
|
|
@@ -603,14 +566,8 @@ func ListProxyBasicAuthExceptionPaths(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- ptype, err := utils.GetPara(r, "ptype")
|
|
|
- if err != nil {
|
|
|
- utils.SendErrorResponse(w, "Invalid ptype given")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
//Load the target proxy object from router
|
|
|
- targetProxy, err := dynamicProxyRouter.LoadProxy(ptype, ep)
|
|
|
+ targetProxy, err := dynamicProxyRouter.LoadProxy(ep)
|
|
|
if err != nil {
|
|
|
utils.SendErrorResponse(w, err.Error())
|
|
|
return
|
|
@@ -634,12 +591,6 @@ func AddProxyBasicAuthExceptionPaths(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- ptype, err := utils.PostPara(r, "ptype")
|
|
|
- if err != nil {
|
|
|
- utils.SendErrorResponse(w, "Invalid ptype given")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
matchingPrefix, err := utils.PostPara(r, "prefix")
|
|
|
if err != nil {
|
|
|
utils.SendErrorResponse(w, "Invalid matching prefix given")
|
|
@@ -647,7 +598,7 @@ func AddProxyBasicAuthExceptionPaths(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
//Load the target proxy object from router
|
|
|
- targetProxy, err := dynamicProxyRouter.LoadProxy(ptype, ep)
|
|
|
+ targetProxy, err := dynamicProxyRouter.LoadProxy(ep)
|
|
|
if err != nil {
|
|
|
utils.SendErrorResponse(w, err.Error())
|
|
|
return
|
|
@@ -676,7 +627,7 @@ func AddProxyBasicAuthExceptionPaths(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
//Save configs to runtime and file
|
|
|
targetProxy.UpdateToRuntime()
|
|
|
- SaveReverseProxyEndpointToFile(targetProxy)
|
|
|
+ SaveReverseProxyConfig(targetProxy)
|
|
|
|
|
|
utils.SendOK(w)
|
|
|
}
|
|
@@ -689,12 +640,6 @@ func RemoveProxyBasicAuthExceptionPaths(w http.ResponseWriter, r *http.Request)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- ptype, err := utils.PostPara(r, "ptype")
|
|
|
- if err != nil {
|
|
|
- utils.SendErrorResponse(w, "Invalid ptype given")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
matchingPrefix, err := utils.PostPara(r, "prefix")
|
|
|
if err != nil {
|
|
|
utils.SendErrorResponse(w, "Invalid matching prefix given")
|
|
@@ -702,7 +647,7 @@ func RemoveProxyBasicAuthExceptionPaths(w http.ResponseWriter, r *http.Request)
|
|
|
}
|
|
|
|
|
|
// Load the target proxy object from router
|
|
|
- targetProxy, err := dynamicProxyRouter.LoadProxy(ptype, ep)
|
|
|
+ targetProxy, err := dynamicProxyRouter.LoadProxy(ep)
|
|
|
if err != nil {
|
|
|
utils.SendErrorResponse(w, err.Error())
|
|
|
return
|
|
@@ -727,7 +672,7 @@ func RemoveProxyBasicAuthExceptionPaths(w http.ResponseWriter, r *http.Request)
|
|
|
|
|
|
// Save configs to runtime and file
|
|
|
targetProxy.UpdateToRuntime()
|
|
|
- SaveReverseProxyEndpointToFile(targetProxy)
|
|
|
+ SaveReverseProxyConfig(targetProxy)
|
|
|
|
|
|
utils.SendOK(w)
|
|
|
}
|
|
@@ -738,16 +683,19 @@ func ReverseProxyStatus(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
func ReverseProxyList(w http.ResponseWriter, r *http.Request) {
|
|
|
- eptype, err := utils.PostPara(r, "type") //Support root, vdir and subd
|
|
|
+ eptype, err := utils.PostPara(r, "type") //Support root and host
|
|
|
if err != nil {
|
|
|
utils.SendErrorResponse(w, "type not defined")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if eptype == "vdir" {
|
|
|
+ if eptype == "host" {
|
|
|
results := []*dynamicproxy.ProxyEndpoint{}
|
|
|
dynamicProxyRouter.ProxyEndpoints.Range(func(key, value interface{}) bool {
|
|
|
- results = append(results, value.(*dynamicproxy.ProxyEndpoint))
|
|
|
+ thisEndpoint := value.(*dynamicproxy.ProxyEndpoint)
|
|
|
+ //Clear the auth credentials before showing to front-end
|
|
|
+ thisEndpoint.BasicAuthCredentials = []*dynamicproxy.BasicAuthCredentials{}
|
|
|
+ results = append(results, thisEndpoint)
|
|
|
return true
|
|
|
})
|
|
|
|
|
@@ -755,19 +703,6 @@ func ReverseProxyList(w http.ResponseWriter, r *http.Request) {
|
|
|
return results[i].Domain < results[j].Domain
|
|
|
})
|
|
|
|
|
|
- js, _ := json.Marshal(results)
|
|
|
- utils.SendJSONResponse(w, string(js))
|
|
|
- } else if eptype == "subd" {
|
|
|
- results := []*dynamicproxy.ProxyEndpoint{}
|
|
|
- dynamicProxyRouter.SubdomainEndpoint.Range(func(key, value interface{}) bool {
|
|
|
- results = append(results, value.(*dynamicproxy.ProxyEndpoint))
|
|
|
- return true
|
|
|
- })
|
|
|
-
|
|
|
- sort.Slice(results, func(i, j int) bool {
|
|
|
- return results[i].RootOrMatchingDomain < results[j].RootOrMatchingDomain
|
|
|
- })
|
|
|
-
|
|
|
js, _ := json.Marshal(results)
|
|
|
utils.SendJSONResponse(w, string(js))
|
|
|
} else if eptype == "root" {
|