|
@@ -4,6 +4,7 @@ import (
|
|
"fmt"
|
|
"fmt"
|
|
"io"
|
|
"io"
|
|
"net/http"
|
|
"net/http"
|
|
|
|
+ "strings"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
)
|
|
@@ -25,8 +26,9 @@ func NewController(cfg *HttpServerConfig) *Controller {
|
|
This handler will be responsible for proxying out the GET requests that the server recieves
|
|
This handler will be responsible for proxying out the GET requests that the server recieves
|
|
*/
|
|
*/
|
|
func (c *Controller) Get(ctx *gin.Context) {
|
|
func (c *Controller) Get(ctx *gin.Context) {
|
|
- url := fmt.Sprintf("https://%s%s", c.Config.RevProxySite, ctx.Param("ProxiedPath"))
|
|
|
|
- req, err := http.NewRequest("GET", url, nil)
|
|
|
|
|
|
+
|
|
|
|
+ url := fmt.Sprintf("https://%s%s", c.Config.AllowedDomain, ctx.Param("ProxiedPath"))
|
|
|
|
+ req, err := http.NewRequest(ctx.Request.Method, url, ctx.Request.Body)
|
|
if err != nil {
|
|
if err != nil {
|
|
ctx.JSON(500, map[string]string{
|
|
ctx.JSON(500, map[string]string{
|
|
"Error": "Error creating the request.",
|
|
"Error": "Error creating the request.",
|
|
@@ -35,9 +37,17 @@ func (c *Controller) Get(ctx *gin.Context) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
req.URL.Path = ctx.Param("ProxiedPath")
|
|
req.URL.Path = ctx.Param("ProxiedPath")
|
|
- req.Header.Add("user-agent", c.Config.UserAgent)
|
|
|
|
- req.Header.Add("Referer", c.Config.AllowedDomain)
|
|
|
|
- // fmt.Printf("%+v\n", req)
|
|
|
|
|
|
+ req.Header.Add("User-Agent", c.Config.UserAgent)
|
|
|
|
+ req.Header.Set("Referer", c.Config.AllowedDomain)
|
|
|
|
+ for idx := range c.Config.CookieJar {
|
|
|
|
+ req.AddCookie(c.Config.CookieJar[idx])
|
|
|
|
+ }
|
|
|
|
+ if ctx.Param("ProxiedPath") == "/" {
|
|
|
|
+ req.Header.Add("Location", "https://sem.bunnytools.shop/analytics/overview/")
|
|
|
|
+ }
|
|
|
|
+ if ctx.Param("ProxiedPath") == "/_compatibility/traffic/overview/" {
|
|
|
|
+ req.Header.Add("Location", "https://sem.bunnytools.shop/analytics/traffic/overview/ebay.com")
|
|
|
|
+ }
|
|
client := &http.Client{}
|
|
client := &http.Client{}
|
|
resp, err := client.Do(req)
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -56,25 +66,12 @@ func (c *Controller) Get(ctx *gin.Context) {
|
|
})
|
|
})
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- ctx.Data(200, "text/html", b)
|
|
|
|
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/*
|
|
|
|
-This handler will be responsible for proxying any POST requests
|
|
|
|
-*/
|
|
|
|
-func (c *Controller) Post(ctx *gin.Context) {
|
|
|
|
- url := fmt.Sprintf("%s/%s", c.Config.RevProxySite, ctx.FullPath())
|
|
|
|
- req, err := http.NewRequest("POST", url, ctx.Request.Body)
|
|
|
|
- if err != nil {
|
|
|
|
- ctx.JSON(500, map[string]string{
|
|
|
|
- "Error": "Error creating the request.",
|
|
|
|
- "Msg:": err.Error(),
|
|
|
|
- })
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- req.Header.Add("user-agent", c.Config.UserAgent)
|
|
|
|
- req.Header.Add("Referer", c.Config.AllowedDomain)
|
|
|
|
- fmt.Printf("%+v\n", req)
|
|
|
|
|
|
+ newBody := strings.ReplaceAll(string(b), "\"srf-browser-unhappy\"", "\"srf-browser-unhappy\" style=\"display:none;\"")
|
|
|
|
+ newBody = strings.ReplaceAll(newBody, "\"srf-navbar__right\"", "\"srf-navbar__right\" style=\"display:none;\"")
|
|
|
|
+ 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, "www.semrush.com", "sem.bunnytools.shop")
|
|
|
|
+ ctx.Data(resp.StatusCode, resp.Header.Get("Content-Type"), []byte(newBody))
|
|
|
|
|
|
}
|
|
}
|