Merge branch 'master' of https://gitea.inhome.blapointe.com/local/rproxy3
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -2,12 +2,16 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gitea.inhome.blapointe.com/local/args"
|
||||
"gitea.inhome.blapointe.com/local/logb"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitea.inhome.blapointe.com/local/args"
|
||||
"gitea.inhome.blapointe.com/local/logb"
|
||||
|
||||
"gitea.inhome.blapointe.com/local/args"
|
||||
"gitea.inhome.blapointe.com/local/logb"
|
||||
)
|
||||
|
||||
var conf *args.ArgSet
|
||||
@@ -50,9 +54,7 @@ func parseArgs() (*args.ArgSet, error) {
|
||||
as.Append(args.STRING, "trim", "path prefix to trim, like '/abc' to change '/abc/def' to '/def'", "")
|
||||
as.Append(args.STRING, "tcp", "address for tcp only tunnel", "")
|
||||
as.Append(args.DURATION, "timeout", "timeout for tunnel", time.Minute)
|
||||
as.Append(args.STRING, "proxy", "double-comma separated (+ if auth)from,scheme://to.tld:port,,", "")
|
||||
as.Append(args.STRING, "oauth", "url for boauthz", "")
|
||||
as.Append(args.STRING, "authelia", "url for authelia", "")
|
||||
as.Append(args.STRING, "proxy2", "double-comma separated 'from,scheme://to.tld:port,,' OR a yaml dictionary of 'from: (password:)scheme://to.tld:port'", "")
|
||||
as.Append(args.STRING, "cors", "json dict key:true for keys to set CORS permissive headers, like {\"from\":true}", "{}")
|
||||
as.Append(args.STRING, "nopath", "json dict key:true for keys to remove all path info from forwarded request, like -cors", "{}")
|
||||
as.Append(args.STRING, "level", "log level", "info")
|
||||
|
||||
Reference in New Issue
Block a user