Merge pull request #61 from everywall/proxy_v2/cleanup-main
cleanup main
This commit is contained in:
58
cmd/main.go
58
cmd/main.go
@@ -1,12 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"ladder/handlers"
|
||||
"ladder/internal/cli"
|
||||
@@ -14,20 +13,9 @@ import (
|
||||
|
||||
"github.com/akamensky/argparse"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/basicauth"
|
||||
"github.com/gofiber/fiber/v2/middleware/favicon"
|
||||
"github.com/gofiber/template/html/v2"
|
||||
)
|
||||
|
||||
//go:embed favicon.ico
|
||||
var faviconData string
|
||||
|
||||
//go:embed styles.css
|
||||
var cssData embed.FS
|
||||
|
||||
//go:embed script.js
|
||||
var scriptData embed.FS
|
||||
|
||||
//go:embed VERSION
|
||||
var version string
|
||||
|
||||
@@ -151,23 +139,8 @@ func main() {
|
||||
},
|
||||
)
|
||||
|
||||
// TODO: move to cmd/auth.go
|
||||
userpass := os.Getenv("USERPASS")
|
||||
if userpass != "" {
|
||||
userpass := strings.Split(userpass, ":")
|
||||
|
||||
app.Use(basicauth.New(basicauth.Config{
|
||||
Users: map[string]string{
|
||||
userpass[0]: userpass[1],
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
// TODO: move to handlers/favicon.go
|
||||
app.Use(favicon.New(favicon.Config{
|
||||
Data: []byte(faviconData),
|
||||
URL: "/favicon.ico",
|
||||
}))
|
||||
app.Use(handlers.Auth())
|
||||
app.Use(handlers.Favicon())
|
||||
|
||||
if os.Getenv("NOLOGS") != "true" {
|
||||
app.Use(func(c *fiber.Ctx) error {
|
||||
@@ -179,29 +152,8 @@ func main() {
|
||||
|
||||
app.Get("/", handlers.Form)
|
||||
|
||||
app.Get("/styles.css", func(c *fiber.Ctx) error {
|
||||
cssData, err := cssData.ReadFile("styles.css")
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
|
||||
c.Set("Content-Type", "text/css")
|
||||
|
||||
return c.Send(cssData)
|
||||
})
|
||||
|
||||
// TODO: move to handlers/script.go
|
||||
app.Get("/script.js", func(c *fiber.Ctx) error {
|
||||
scriptData, err := scriptData.ReadFile("script.js")
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
|
||||
c.Set("Content-Type", "text/javascript")
|
||||
|
||||
return c.Send(scriptData)
|
||||
})
|
||||
|
||||
app.Get("styles.css", handlers.Styles)
|
||||
app.Get("script.js", handlers.Script)
|
||||
app.Get("ruleset", handlers.Ruleset)
|
||||
app.Get("raw/*", handlers.Raw)
|
||||
|
||||
|
||||
25
handlers/auth.go
Normal file
25
handlers/auth.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/basicauth"
|
||||
)
|
||||
|
||||
func Auth() fiber.Handler {
|
||||
userpass := os.Getenv("USERPASS")
|
||||
if userpass != "" {
|
||||
userpass := strings.Split(userpass, ":")
|
||||
return basicauth.New(basicauth.Config{
|
||||
Users: map[string]string{
|
||||
userpass[0]: userpass[1],
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return func(c *fiber.Ctx) error {
|
||||
return c.Next()
|
||||
}
|
||||
}
|
||||
18
handlers/favicon.go
Normal file
18
handlers/favicon.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/favicon"
|
||||
)
|
||||
|
||||
//go:embed favicon.ico
|
||||
var faviconData string
|
||||
|
||||
func Favicon() fiber.Handler {
|
||||
return favicon.New(favicon.Config{
|
||||
Data: []byte(faviconData),
|
||||
URL: "/favicon.ico",
|
||||
})
|
||||
}
|
||||
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
23
handlers/script.go
Normal file
23
handlers/script.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"embed"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
//go:embed script.js
|
||||
var scriptData embed.FS
|
||||
|
||||
func Script(c *fiber.Ctx) error {
|
||||
|
||||
scriptData, err := scriptData.ReadFile("script.js")
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
|
||||
c.Set("Content-Type", "text/javascript")
|
||||
|
||||
return c.Send(scriptData)
|
||||
|
||||
}
|
||||
23
handlers/styles.go
Normal file
23
handlers/styles.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"embed"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
//go:embed styles.css
|
||||
var cssData embed.FS
|
||||
|
||||
func Styles(c *fiber.Ctx) error {
|
||||
|
||||
cssData, err := cssData.ReadFile("styles.css")
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
|
||||
c.Set("Content-Type", "text/css")
|
||||
|
||||
return c.Send(cssData)
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"scripts": {
|
||||
"build": "pnpx tailwindcss -i ./styles/input.css -o ./styles/output.css --build && pnpx minify ./styles/output.css > ./cmd/styles.css"
|
||||
"build": "pnpx tailwindcss -i ./styles/input.css -o ./styles/output.css --build && pnpx minify ./styles/output.css > ./handlers/styles.css"
|
||||
},
|
||||
"devDependencies": {
|
||||
"minify": "^10.5.2",
|
||||
|
||||
@@ -2,8 +2,9 @@ package requestmodifiers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"ladder/proxychain"
|
||||
"regexp"
|
||||
|
||||
"ladder/proxychain"
|
||||
)
|
||||
|
||||
func ModifyPathWithRegex(matchRegex string, replacement string) proxychain.RequestModification {
|
||||
|
||||
@@ -3,8 +3,9 @@ package responsemodifiers
|
||||
import (
|
||||
_ "embed"
|
||||
"io"
|
||||
"ladder/proxychain"
|
||||
"strings"
|
||||
|
||||
"ladder/proxychain"
|
||||
)
|
||||
|
||||
//go:embed patch_google_analytics.js
|
||||
|
||||
@@ -4,9 +4,10 @@ import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"ladder/proxychain"
|
||||
"log"
|
||||
"regexp"
|
||||
|
||||
"ladder/proxychain"
|
||||
)
|
||||
|
||||
//go:embed vendor/ddg-tracker-surrogates/mapping.json
|
||||
|
||||
@@ -3,6 +3,7 @@ package ruleset_v2
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"ladder/proxychain"
|
||||
)
|
||||
@@ -84,7 +85,6 @@ func (rule *Rule) MarshalJSON() ([]byte, error) {
|
||||
|
||||
// implement type yaml marshaller
|
||||
func (rule *Rule) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
|
||||
type Aux struct {
|
||||
Domains []string `yaml:"domains"`
|
||||
RequestModifications []_rqm `yaml:"requestmodifications"`
|
||||
@@ -122,7 +122,6 @@ func (rule *Rule) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
}
|
||||
|
||||
func (rule *Rule) MarshalYAML() (interface{}, error) {
|
||||
|
||||
type Aux struct {
|
||||
Domains []string `yaml:"domains"`
|
||||
RequestModifications []_rqm `yaml:"requestmodifications"`
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
package ruleset_v2
|
||||
|
||||
// DO NOT EDIT THIS FILE. It is automatically generated by ladder/proxychain/codegen/codegen.go
|
||||
// The purpose of this is serialization of rulesets from JSON or YAML into functional options suitable
|
||||
// for use in proxychains.
|
||||
@@ -179,5 +179,4 @@ func init() {
|
||||
rqmModMap["SpoofXForwardedFor"] = func(params ...string) proxychain.RequestModification {
|
||||
return rx.SpoofXForwardedFor(params[0])
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
package ruleset_v2
|
||||
|
||||
// DO NOT EDIT THIS FILE. It is automatically generated by ladder/proxychain/codegen/codegen.go
|
||||
// The purpose of this is serialization of rulesets from JSON or YAML into functional options suitable
|
||||
// for use in proxychains.
|
||||
@@ -95,5 +95,4 @@ func init() {
|
||||
rsmModMap["RewriteHTMLResourceURLs"] = func(_ ...string) proxychain.ResponseModification {
|
||||
return tx.RewriteHTMLResourceURLs()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,8 +3,9 @@ package ruleset_v2
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gopkg.in/yaml.v3"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// unmarshalRule is a helper function to unmarshal a Rule from a JSON string.
|
||||
|
||||
Reference in New Issue
Block a user