|
@@ -32,7 +32,6 @@ import (
|
|
|
"log"
|
|
|
"net/http"
|
|
|
"os"
|
|
|
- "strings"
|
|
|
"time"
|
|
|
|
|
|
"github.com/patrickmn/go-cache"
|
|
@@ -76,83 +75,6 @@ type Cookie struct {
|
|
|
IncludeSub bool `json:"include_sub"`
|
|
|
}
|
|
|
|
|
|
-type RouteMapping struct {
|
|
|
- DomainName string `json:"domain_name"`
|
|
|
- UriPaths []string `json:"uri_paths"`
|
|
|
- RouteSet map[string]struct{}
|
|
|
-}
|
|
|
-
|
|
|
-type RouteMap struct {
|
|
|
- Mappings map[string]string `json:"mappings"`
|
|
|
- Shotgun map[string]string `json:"shotgun"`
|
|
|
- MapCache *cache.Cache
|
|
|
-}
|
|
|
-
|
|
|
-type RouteMapper interface {
|
|
|
- mapUriToDomain(string, string)
|
|
|
- GetMappedDomain(string) (string, bool)
|
|
|
- ExportRouteMaps(string)
|
|
|
-}
|
|
|
-
|
|
|
-/*
|
|
|
-Set a route to exist for the URI to the specific domain
|
|
|
-
|
|
|
- :param uri: the URI to set the route for
|
|
|
- :param domain: the domain name to resolve the uri to
|
|
|
-*/
|
|
|
-func (r *RouteMap) MapUriToDomain(uri string, domain string) {
|
|
|
- r.MapCache.Set(uri, domain, cache.DefaultExpiration)
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-// returns the domain/url that the uri belongs to as defined in the routemap
|
|
|
-func (r *RouteMap) GetMappedDomain(uri string) (string, bool) {
|
|
|
- dname, ok := r.MapCache.Get(uri)
|
|
|
- if ok {
|
|
|
- return fmt.Sprint(dname), true
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- for k, v := range r.Shotgun {
|
|
|
-
|
|
|
- if strings.Contains(uri, k) {
|
|
|
- return v, true
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return "", false
|
|
|
-}
|
|
|
-
|
|
|
-// This populates the cache in a RouteMap with the data from the config file
|
|
|
-func (r *RouteMap) populateRouteMaps() {
|
|
|
- for k, v := range r.Mappings {
|
|
|
- r.MapUriToDomain(k, v)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// Exports the cache into a JSON-friendly data structure (so that it can be written to the file system)
|
|
|
-func (r *RouteMap) ExportRouteMap(loc string) {
|
|
|
- routeMapOut := &RouteMap{
|
|
|
- Mappings: map[string]string{},
|
|
|
- Shotgun: map[string]string{},
|
|
|
- }
|
|
|
-
|
|
|
- cachedRoutes := r.MapCache.Items()
|
|
|
- for k, v := range cachedRoutes {
|
|
|
- routeMapOut.Mappings[k] = fmt.Sprint(v.Object)
|
|
|
- }
|
|
|
- for k, v := range r.Shotgun {
|
|
|
- routeMapOut.Shotgun[k] = v
|
|
|
- }
|
|
|
-
|
|
|
- b, err := json.Marshal(routeMapOut)
|
|
|
- if err != nil {
|
|
|
- log.Fatal("failed to marshal struct: ", err)
|
|
|
- }
|
|
|
- os.WriteFile(loc, b, os.ModePerm)
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
/*
|
|
|
Reads the server configuration file, along with the cookie file so that the correlated account can be
|
|
|
accessed through the proxy
|