Prechádzať zdrojové kódy

configuration changes and such

svcs 1 rok pred
rodič
commit
16a637324d
3 zmenil súbory, kde vykonal 20 pridanie a 17 odobranie
  1. 3 3
      pkg/client.go
  2. 2 2
      pkg/controller.go
  3. 15 12
      pkg/include.go

+ 3 - 3
pkg/client.go

@@ -14,9 +14,9 @@ Retrieve the site audit config file from Semrush
 
 	returns a byte array of the body, the content type of the resp, and an error
 */
-func (c *Controller) RetrieveStaticResource(path string, ctx *gin.Context) ([]byte, string, int, error) {
-	url := fmt.Sprintf("https://static.semrush.com%s", path)
-	req, err := http.NewRequest("GET", url, nil)
+func (c *Controller) RetrieveStaticResource(method string, path string, ctx *gin.Context) ([]byte, string, int, error) {
+	url := fmt.Sprintf("%s%s", c.Config.FullAltAllowedDomain, path)
+	req, err := http.NewRequest(method, url, nil)
 	if err != nil {
 		return nil, "", 500, err
 	}

+ 2 - 2
pkg/controller.go

@@ -89,7 +89,7 @@ func (c *Controller) Get(ctx *gin.Context) {
 	incomingPath := ctx.Param("ProxiedPath")
 	for idx := range staticRoutes {
 		if strings.Contains(incomingPath, staticRoutes[idx]) {
-			data, ctype, rcode, err := c.RetrieveStaticResource(incomingPath, ctx)
+			data, ctype, rcode, err := c.RetrieveStaticResource(ctx.Request.Method, incomingPath, ctx)
 			if err != nil {
 				log.Fatal(err, "reroute to the static domain")
 			}
@@ -129,6 +129,6 @@ func (c *Controller) Get(ctx *gin.Context) {
 	newBody = strings.ReplaceAll(newBody, "<footer", "<footer style=\"display:none;\"")
 	newBody = strings.ReplaceAll(newBody, "\"srf-report-sidebar-extras\"", "\"srf-report-sidebar-extra\" style=\"display:none;\"")
 	newBody = strings.ReplaceAll(newBody, c.Config.AllowedDomain, c.Config.ProxyAddr)
-	newBody = strings.ReplaceAll(newBody, "static.semrush.com", c.Config.ProxyAddr)
+	newBody = strings.ReplaceAll(newBody, c.Config.AltAllowedDomain, c.Config.ProxyAddr)
 	ctx.Data(rcode, ctype, []byte(newBody))
 }

+ 15 - 12
pkg/include.go

@@ -8,18 +8,20 @@ import (
 )
 
 type HttpServerConfig struct {
-	HttpPort        int    `json:"http_port"`
-	HttpsPort       int    `json:"https_port"`
-	AllowedDomain   string `json:"allowed_domain"`
-	FullDomain      string // The domain name with the protocol before it
-	Proto           string `json:"proto"` // http/https
-	UserAgent       string `json:"user_agent"`
-	UseSsl          bool   `json:"use_ssl"`
-	ProxyAddr       string `json:"proxy_addr"`
-	FullProxyDomain string // the domain name of the proxied site with the protocol
-	CookieJar       []*http.Cookie
-	PhpSession      *http.Cookie
-	SsoToken        *http.Cookie
+	HttpPort             int    `json:"http_port"`
+	HttpsPort            int    `json:"https_port"`
+	AllowedDomain        string `json:"allowed_domain"`
+	FullDomain           string // The domain name with the protocol before it
+	AltAllowedDomain     string `json:"alt_allowed_domain"` // alternate domain that resources are sourced from
+	FullAltAllowedDomain string // the alt domain with the protocol
+	Proto                string `json:"proto"` // http/https
+	UserAgent            string `json:"user_agent"`
+	UseSsl               bool   `json:"use_ssl"`
+	ProxyAddr            string `json:"proxy_addr"`
+	FullProxyDomain      string // the domain name of the proxied site with the protocol
+	CookieJar            []*http.Cookie
+	PhpSession           *http.Cookie
+	SsoToken             *http.Cookie
 }
 
 type Cookie struct {
@@ -55,6 +57,7 @@ func ReadConfig(loc string) (*HttpServerConfig, error) {
 	}
 	cfg.FullDomain = fmt.Sprintf("%s://%s", cfg.Proto, cfg.AllowedDomain)
 	cfg.FullProxyDomain = fmt.Sprintf("%s://%s", cfg.Proto, cfg.ProxyAddr)
+	cfg.FullAltAllowedDomain = fmt.Sprintf("%s://%s", cfg.Proto, cfg.AltAllowedDomain)
 	var cookies []Cookie
 	err = json.Unmarshal(cf, &cookies)
 	if err != nil {