initial commit
This commit is contained in:
55
cmd/main.go
Normal file
55
cmd/main.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"paywall-ladder/handlers"
|
||||
"syscall"
|
||||
|
||||
"github.com/elazarl/goproxy"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
//os.Setenv("HTTP_PROXY", "http://localhost:3000")
|
||||
proxyForkID, _, _ := syscall.Syscall(syscall.SYS_FORK, 0, 0, 0) // LINUX
|
||||
//_, proxyForkID, _ := syscall.Syscall(syscall.SYS_FORK, 0, 0, 0) // MAC
|
||||
|
||||
fmt.Println("Proxy fork id", proxyForkID)
|
||||
|
||||
if proxyForkID == 0 {
|
||||
|
||||
app := fiber.New()
|
||||
app.Static("/", "./public")
|
||||
|
||||
app.Get("/proxy/*", handlers.FetchSite)
|
||||
app.Get("debug/*", handlers.Debug)
|
||||
app.Get("/*", handlers.ProxySite)
|
||||
|
||||
port := os.Getenv("PORT")
|
||||
if os.Getenv("PORT") == "" {
|
||||
port = "2000"
|
||||
}
|
||||
app.Listen(":" + port)
|
||||
} else {
|
||||
proxy := goproxy.NewProxyHttpServer()
|
||||
proxy.Verbose = true
|
||||
proxy.OnRequest().DoFunc(
|
||||
func(req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
|
||||
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")
|
||||
return req, nil
|
||||
})
|
||||
|
||||
proxyport := os.Getenv("PORT_PROXY")
|
||||
if os.Getenv("PORT_PROXY") == "" {
|
||||
proxyport = "3000"
|
||||
}
|
||||
log.Println("Proxy listening on port " + proxyport)
|
||||
log.Fatal(http.ListenAndServe(":"+proxyport, proxy))
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user