proxy2 does auth inline

This commit is contained in:
bel
2024-03-10 11:08:51 -06:00
parent fb6d7af6d3
commit abf628d2bb
6 changed files with 51 additions and 172 deletions

View File

@@ -4,15 +4,19 @@ import (
"encoding/json"
"fmt"
"log"
"regexp"
"strings"
"time"
"gopkg.in/yaml.v2"
)
type Proxy struct {
To string
Auth string
To string
}
func parseProxy(s string) (string, Proxy) {
func parseOneProxyCSV(s string) (string, Proxy) {
p := Proxy{}
key := ""
l := strings.Split(s, ",")
@@ -25,16 +29,6 @@ func parseProxy(s string) (string, Proxy) {
return key, p
}
func GetAuthelia() (string, bool) {
authelia := conf.Get("authelia").GetString()
return authelia, authelia != ""
}
func GetBOAuthZ() (string, bool) {
boauthz := conf.Get("oauth").GetString()
return boauthz, boauthz != ""
}
func GetAuth() (string, string, bool) {
user := conf.Get("user").GetString()
pass := conf.Get("pass").GetString()
@@ -63,11 +57,30 @@ func GetRate() (int, int) {
}
func GetRoutes() map[string]Proxy {
list := conf.Get("proxy").GetString()
s := conf.Get("proxy2").GetString()
var dict map[string]string
if err := yaml.Unmarshal([]byte(s), &dict); err == nil && len(s) > 0 {
pattern := regexp.MustCompile(`(([^:]*):)?([a-z0-9]*:.*)`)
result := map[string]Proxy{}
for k, v := range dict {
submatches := pattern.FindAllStringSubmatch(v, -1)
log.Printf("%+v", submatches)
result[k] = Proxy{
Auth: submatches[0][2],
To: submatches[0][3],
}
}
return result
}
return getRoutesCSV()
}
func getRoutesCSV() map[string]Proxy {
list := conf.Get("proxy2").GetString()
definitions := strings.Split(list, ",,")
routes := make(map[string]Proxy)
for _, definition := range definitions {
k, v := parseProxy(definition)
k, v := parseOneProxyCSV(definition)
routes[k] = v
}
return routes