add basic auth

This commit is contained in:
Gianni Carafa
2023-11-02 20:57:44 +01:00
parent 3e3eebcdc2
commit c98e49f2b3
2 changed files with 14 additions and 1 deletions

View File

@@ -23,7 +23,7 @@ Certain sites may display missing images or encounter formatting issues. This ca
- [x] Mac OS binary - [x] Mac OS binary
- [x] Windows binary (Untested) - [x] Windows binary (Untested)
- [x] Remove most of the ads (unexpected side effect) - [x] Remove most of the ads (unexpected side effect)
- [ ] Basic Auth - [x] Basic Auth
## Installation ## Installation
@@ -73,3 +73,4 @@ http://localhost:8080/debug/https://www.google.com
| `PREFORK` | Spawn multiple server instances | `false` | | `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)` | | `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` | | `X_FORWARDED_FOR` | IP Forwarder address | `66.249.66.1` |
| `USERPASS` | Enables Basic Auth, format `admin:123456` | |

View File

@@ -5,8 +5,10 @@ import (
"log" "log"
"os" "os"
"strconv" "strconv"
"strings"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/basicauth"
) )
func main() { 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("/", handlers.Form)
app.Get("raw/*", handlers.Raw) app.Get("raw/*", handlers.Raw)
app.Get("api/*", handlers.Api) app.Get("api/*", handlers.Api)