Replaced all uses of underscore in proxy URLs with dashes

Issue #128
This commit is contained in:
Michael Irwin
2017-04-26 00:10:35 -04:00
parent 6acb6f47c5
commit e31dc8cfaa
3 changed files with 17 additions and 10 deletions

21
api.go
View File

@@ -65,8 +65,8 @@ func main() {
corsHandler := gh.CORS(gh.AllowCredentials(), gh.AllowedHeaders([]string{"x-requested-with", "content-type"}), gh.AllowedOrigins([]string{"*"}))
// Specific routes
r.Host(`{subdomain:.*}{node:pwd[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}}-{port:[0-9]*}.{tld:.*}`).Handler(tcpHandler)
r.Host(`{subdomain:.*}{node:pwd[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}}.{tld:.*}`).Handler(tcpHandler)
r.Host(`{subdomain:.*}{node:pwd[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}}-{port:[0-9]*}.{tld:.*}`).Handler(tcpHandler)
r.Host(`{subdomain:.*}{node:pwd[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}}.{tld:.*}`).Handler(tcpHandler)
r.HandleFunc("/ping", handlers.Ping).Methods("GET")
corsRouter.HandleFunc("/instances/images", handlers.GetInstanceImages).Methods("GET")
corsRouter.HandleFunc("/sessions/{sessionId}", handlers.GetSession).Methods("GET")
@@ -116,7 +116,7 @@ func main() {
ssl := mux.NewRouter()
sslProxyHandler := handlers.NewSSLDaemonHandler()
ssl.Host(`{subdomain:.*}{node:pwd[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}}-2375.{tld:.*}`).Handler(sslProxyHandler)
ssl.Host(`{subdomain:.*}{node:pwd[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}}-2375.{tld:.*}`).Handler(sslProxyHandler)
log.Println("Listening TLS on port " + config.SSLPortNumber)
s := &http.Server{Addr: "0.0.0.0:" + config.SSLPortNumber, Handler: ssl}
@@ -125,7 +125,8 @@ func main() {
chunks := strings.Split(clientHello.ServerName, ".")
chunks = strings.Split(chunks[0], "-")
ip := strings.Replace(strings.TrimPrefix(chunks[0], "pwd"), "_", ".", -1)
ipAndPort := strings.TrimPrefix(chunks[0], "pwd")
ip := strings.Replace(ipAndPort[0:strings.LastIndex(ipAndPort, "-")], "-", ".", -1)
i := services.FindInstanceByIP(ip)
if i == nil {
return nil, fmt.Errorf("Instance %s doesn't exist", clientHello.ServerName)
@@ -138,15 +139,21 @@ func main() {
log.Fatal(s.ListenAndServeTLS("", ""))
}
var dnsFilter = regexp.MustCompile(`pwd[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}`)
var dnsFilter = regexp.MustCompile(`pwd[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}`)
func handleDnsRequest(w dns.ResponseWriter, r *dns.Msg) {
if len(r.Question) > 0 && dnsFilter.MatchString(r.Question[0].Name) {
// this is something we know about and we should try to handle
question := r.Question[0].Name
domainChunks := strings.Split(question, ".")
tldChunks := strings.Split(strings.TrimPrefix(domainChunks[0], "pwd"), "-")
ip := strings.Replace(tldChunks[0], "_", ".", -1)
ipAndPort := strings.TrimPrefix(domainChunks[0], "pwd")
ip := ""
if len(strings.Split(ipAndPort, "-")) == 5 {
ip = strings.Replace(ipAndPort[0:strings.LastIndex(ipAndPort, "-")], "-", ".", -1)
} else {
ip = strings.Replace(ipAndPort, "-", ".", -1)
}
m := new(dns.Msg)
m.SetReply(r)

View File

@@ -27,7 +27,7 @@ func getTargetInfo(vars map[string]string, req *http.Request) (string, string) {
if strings.HasPrefix(node, "pwd") {
// Node is actually an ip, need to convert underscores by dots.
ip := strings.Replace(strings.TrimPrefix(node, "pwd"), "_", ".", -1)
ip := strings.Replace(strings.TrimPrefix(node, "pwd"), "-", ".", -1)
if net.ParseIP(ip) == nil {
// Not a valid IP, so treat this is a hostname.
@@ -132,7 +132,7 @@ func NewSSLDaemonHandler() http.Handler {
node := v["node"]
if strings.HasPrefix(node, "pwd") {
// Node is actually an ip, need to convert underscores by dots.
ip := strings.Replace(strings.TrimPrefix(node, "pwd"), "_", ".", -1)
ip := strings.Replace(strings.TrimPrefix(node, "pwd"), "-", ".", -1)
if net.ParseIP(ip) == nil {
// Not a valid IP, so treat this is a hostname.

View File

@@ -185,7 +185,7 @@
}
$scope.getProxyUrl = function(instance, port) {
var url = window.location.protocol + '//pwd' + instance.ip.replace(/\./g, '_') + '-' + port + '.' + window.location.host;
var url = window.location.protocol + '//pwd' + instance.ip.replace(/\./g, '-') + '-' + port + '.' + window.location.host;
return url;
}