add api path

This commit is contained in:
Gianni Carafa
2023-11-02 18:25:31 +01:00
parent ca26f6d88d
commit aa1caaca98
4 changed files with 81 additions and 4 deletions

View File

@@ -10,18 +10,21 @@
Freedom of information is an essential pillar of democracy and informed decision-making. While media organizations have legitimate financial interests, it is crucial to strike a balance between profitability and the public's right to access information. The proliferation of paywalls raises concerns about the erosion of this fundamental freedom, and it is imperative for society to find innovative ways to preserve access to vital information without compromising the sustainability of journalism. In a world where knowledge should be shared and not commodified, paywalls should be critically examined to ensure that they do not undermine the principles of an open and informed society. Freedom of information is an essential pillar of democracy and informed decision-making. While media organizations have legitimate financial interests, it is crucial to strike a balance between profitability and the public's right to access information. The proliferation of paywalls raises concerns about the erosion of this fundamental freedom, and it is imperative for society to find innovative ways to preserve access to vital information without compromising the sustainability of journalism. In a world where knowledge should be shared and not commodified, paywalls should be critically examined to ensure that they do not undermine the principles of an open and informed society.
Some site might have missing images or other formating issues. This is due to the fact that the site using javascript or CSS to load the images/JS/CSS. This is a limitation of this proxy. If you prefer a full experience, please concider buying a subscription for the site. Certain sites may display missing images or encounter formatting issues. This can be attributed to the site's reliance on JavaScript or CSS for image and resource loading, which presents a limitation when accessed through this proxy. If you prefer a full experience, please concider buying a subscription for the site.
### Features ### Features
- [x] Bypass Paywalls - [x] Bypass Paywalls
- [x] Remove CORS - [x] Remove CORS Headers from Responses, Assets, and Images ...
- [x] Keep Site browsable - [x] Keep Site browsable
- [x] Add a debug path
- [x] Add a API
- [x] Docker Container - [x] Docker Container
- [x] Linux Binary - [x] Linux Binary
- [x] Mac OS Binary - [x] Mac OS Binary
- [x] Windows Binary (Untested) - [x] Windows Binary (Untested)
- [ ] Basic Auth
## How to use ## Installation
### Binary ### Binary
1) Download Binary 1) Download Binary

View File

@@ -20,6 +20,7 @@ func main() {
app.Get("/", handlers.Form) app.Get("/", handlers.Form)
app.Get("debug/*", handlers.Debug) app.Get("debug/*", handlers.Debug)
app.Get("api/*", handlers.Api)
app.Get("/*", handlers.ProxySite) app.Get("/*", handlers.ProxySite)
port := os.Getenv("PORT") port := os.Getenv("PORT")

73
handlers/api.go Normal file
View File

@@ -0,0 +1,73 @@
package handlers
import (
"io"
"log"
"net/http"
"net/url"
"github.com/gofiber/fiber/v2"
)
func Api(c *fiber.Ctx) error {
// Get the url from the URL
urlQuery := c.Params("*")
u, err := url.Parse(urlQuery)
if err != nil {
return c.SendString(err.Error())
}
log.Println(u.String())
// Fetch the site
client := &http.Client{}
req, _ := http.NewRequest("GET", u.String(), nil)
req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")
req.Header.Set("X-Forwarded-For", "66.249.66.1")
req.Header.Set("Referer", u.String())
req.Header.Set("Host", u.Host)
resp, err := client.Do(req)
if err != nil {
return c.SendString(err.Error())
}
defer resp.Body.Close()
bodyB, err := io.ReadAll(resp.Body)
if err != nil {
log.Println("ERROR", err)
return c.SendString(err.Error())
}
body := rewriteHtml(bodyB, u)
response := Response{
Body: body,
}
response.Request.Headers = make([]interface{}, 0)
for k, v := range req.Header {
response.Request.Headers = append(response.Request.Headers, map[string]string{
"key": k,
"value": v[0],
})
}
response.Response.Headers = make([]interface{}, 0)
for k, v := range resp.Header {
response.Response.Headers = append(response.Response.Headers, map[string]string{
"key": k,
"value": v[0],
})
}
return c.JSON(response)
}
type Response struct {
Body string `json:"body"`
Request struct {
Headers []interface{} `json:"headers"`
} `json:"request"`
Response struct {
Headers []interface{} `json:"headers"`
} `json:"response"`
}

View File

@@ -63,7 +63,7 @@ func rewriteHtml(bodyB []byte, u *url.URL) string {
// scripts // scripts
scriptPattern := `<script\s+([^>]*\s+)?src="(/)([^"]*)"` scriptPattern := `<script\s+([^>]*\s+)?src="(/)([^"]*)"`
reScript := regexp.MustCompile(scriptPattern) reScript := regexp.MustCompile(scriptPattern)
body = reScript.ReplaceAllString(body, fmt.Sprintf(`<script $1 script="%s$3"`, "/https://"+u.Host)) body = reScript.ReplaceAllString(body, fmt.Sprintf(`<script $1 script="%s$3"`, "/https://"+u.Host+"/"))
//body = strings.ReplaceAll(body, "srcset=\"/", "srcset=\"/https://"+u.Host+"/") // TODO: Needs a regex to rewrite the URL's //body = strings.ReplaceAll(body, "srcset=\"/", "srcset=\"/https://"+u.Host+"/") // TODO: Needs a regex to rewrite the URL's
body = strings.ReplaceAll(body, "href=\"/", "href=\"/https://"+u.Host+"/") body = strings.ReplaceAll(body, "href=\"/", "href=\"/https://"+u.Host+"/")