mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 18:20:27 +00:00
Merge pull request #9 from weaveworks/configure-pac-domain
socks: Make main shExpMatch expression configurable
This commit is contained in:
@@ -13,13 +13,18 @@ import (
|
|||||||
"github.com/weaveworks/weave/common/mflagext"
|
"github.com/weaveworks/weave/common/mflagext"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type pacFileParameters struct {
|
||||||
|
HostMatch string
|
||||||
|
Aliases map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
pacfile = `
|
pacfile = `
|
||||||
function FindProxyForURL(url, host) {
|
function FindProxyForURL(url, host) {
|
||||||
if(shExpMatch(host, "*.weave.local")) {
|
if(shExpMatch(host, "{{.HostMatch}}")) {
|
||||||
return "SOCKS5 localhost:8000";
|
return "SOCKS5 localhost:8000";
|
||||||
}
|
}
|
||||||
{{range $key, $value := .}}
|
{{range $key, $value := .Aliases}}
|
||||||
if (host == "{{$key}}") {
|
if (host == "{{$key}}") {
|
||||||
return "SOCKS5 localhost:8000";
|
return "SOCKS5 localhost:8000";
|
||||||
}
|
}
|
||||||
@@ -30,8 +35,12 @@ function FindProxyForURL(url, host) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var as []string
|
var (
|
||||||
|
as []string
|
||||||
|
hostMatch string
|
||||||
|
)
|
||||||
mflagext.ListVar(&as, []string{"a", "-alias"}, []string{}, "Specify hostname aliases in the form alias:hostname. Can be repeated.")
|
mflagext.ListVar(&as, []string{"a", "-alias"}, []string{}, "Specify hostname aliases in the form alias:hostname. Can be repeated.")
|
||||||
|
mflag.StringVar(&hostMatch, []string{"h", "-host-match"}, "*.weave.local", "Specify main host shExpMatch expression in pacfile")
|
||||||
mflag.Parse()
|
mflag.Parse()
|
||||||
|
|
||||||
var aliases = map[string]string{}
|
var aliases = map[string]string{}
|
||||||
@@ -50,7 +59,7 @@ func main() {
|
|||||||
t := template.Must(template.New("pacfile").Parse(pacfile))
|
t := template.Must(template.New("pacfile").Parse(pacfile))
|
||||||
http.HandleFunc("/proxy.pac", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/proxy.pac", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/x-ns-proxy-autoconfig")
|
w.Header().Set("Content-Type", "application/x-ns-proxy-autoconfig")
|
||||||
t.Execute(w, aliases)
|
t.Execute(w, pacFileParameters{hostMatch, aliases})
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := http.ListenAndServe(":8080", nil); err != nil {
|
if err := http.ListenAndServe(":8080", nil); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user