package httpserver import ( "fmt" "io" "net/http" "strings" "github.com/gin-gonic/gin" ) type Controller struct { Config *HttpServerConfig } /* Returns a new Controller struct to register routes to the gin router :param cfg: A pointer to an HttpServerConfig struct */ func NewController(cfg *HttpServerConfig) *Controller { return &Controller{Config: cfg} } /* This handler will be responsible for proxying out the GET requests that the server recieves */ func (c *Controller) Get(ctx *gin.Context) { 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 { ctx.JSON(500, map[string]string{ "Error": "Error creating the request.", "Msg:": err.Error(), }) return } req.URL.Path = ctx.Param("ProxiedPath") 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{} resp, err := client.Do(req) if err != nil { ctx.JSON(500, map[string]string{ "Error": "Error creating the request.", "Msg:": err.Error(), }) return } defer resp.Body.Close() b, err := io.ReadAll(resp.Body) if err != nil { ctx.JSON(500, map[string]string{ "Error": "Error creating the request.", "Msg:": err.Error(), }) return } 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, "