diff --git a/README.md b/README.md index 44e43f8..1b0f2de 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Certain sites may display missing images or encounter formatting issues. This ca - [x] Mac OS binary - [x] Windows binary (Untested) - [x] Remove most of the ads (unexpected side effect) -- [ ] Basic Auth +- [x] Basic Auth ## Installation @@ -73,3 +73,4 @@ http://localhost:8080/debug/https://www.google.com | `PREFORK` | Spawn multiple server instances | `false` | | `USER_AGENT` | User agent to emulate | `Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)` | | `X_FORWARDED_FOR` | IP Forwarder address | `66.249.66.1` | +| `USERPASS` | Enables Basic Auth, format `admin:123456` | | diff --git a/cmd/main.go b/cmd/main.go index 72332e7..15427b0 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -5,8 +5,10 @@ import ( "log" "os" "strconv" + "strings" "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/basicauth" ) func main() { @@ -18,6 +20,16 @@ func main() { }, ) + userpass := os.Getenv("USERPASS") + if userpass != "" { + userpass := strings.Split(userpass, ":") + app.Use(basicauth.New(basicauth.Config{ + Users: map[string]string{ + userpass[0]: userpass[1], + }, + })) + } + app.Get("/", handlers.Form) app.Get("raw/*", handlers.Raw) app.Get("api/*", handlers.Api)