Merge branch 'mikesir87-128-replace-underscores-in-urls'

This commit is contained in:
Marcos Lilljedahl
2017-05-12 16:26:03 -03:00
5 changed files with 8 additions and 8 deletions

4
api.go
View File

@@ -60,8 +60,8 @@ func main() {
corsHandler := gh.CORS(gh.AllowCredentials(), gh.AllowedHeaders([]string{"x-requested-with", "content-type"}), gh.AllowedOrigins([]string{"*"})) corsHandler := gh.CORS(gh.AllowCredentials(), gh.AllowedHeaders([]string{"x-requested-with", "content-type"}), gh.AllowedOrigins([]string{"*"}))
// Specific routes // 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}}-{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}}.{tld:.*}`).Handler(tcpHandler)
r.Host(`pwd{alias:.*}-{session:.*}-{port:[0-9]*}.{tld:.*}`).Handler(tcpHandler) r.Host(`pwd{alias:.*}-{session:.*}-{port:[0-9]*}.{tld:.*}`).Handler(tcpHandler)
r.Host(`pwd{alias:.*}-{session:.*}.{tld:.*}`).Handler(tcpHandler) r.Host(`pwd{alias:.*}-{session:.*}.{tld:.*}`).Handler(tcpHandler)
r.HandleFunc("/ping", handlers.Ping).Methods("GET") r.HandleFunc("/ping", handlers.Ping).Methods("GET")

View File

@@ -11,7 +11,7 @@ import (
"github.com/play-with-docker/play-with-docker/services" "github.com/play-with-docker/play-with-docker/services"
) )
var dnsFilter = regexp.MustCompile(`^.*pwd([0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}(?:-[0-9]{1,5})?)\..*$`) var dnsFilter = regexp.MustCompile(`^.*pwd([0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}(?:-[0-9]{1,5})?)\..*$`)
var aliasFilter = regexp.MustCompile(`^.*pwd(.*?)-(.*?)[\.-].*`) var aliasFilter = regexp.MustCompile(`^.*pwd(.*?)-(.*?)[\.-].*`)
func DnsRequest(w dns.ResponseWriter, r *dns.Msg) { func DnsRequest(w dns.ResponseWriter, r *dns.Msg) {
@@ -22,7 +22,7 @@ func DnsRequest(w dns.ResponseWriter, r *dns.Msg) {
match := dnsFilter.FindStringSubmatch(question) match := dnsFilter.FindStringSubmatch(question)
tldChunks := strings.Split(match[1], "-") tldChunks := strings.Split(match[1], "-")
ip := strings.Replace(tldChunks[0], "_", ".", -1) ip := strings.Replace(tldChunks[0], "-", ".", -1)
m := new(dns.Msg) m := new(dns.Msg)
m.SetReply(r) m.SetReply(r)

View File

@@ -38,7 +38,7 @@ func getTargetInfo(vars map[string]string, req *http.Request) (string, string) {
if strings.HasPrefix(node, "pwd") { if strings.HasPrefix(node, "pwd") {
// Node is actually an ip, need to convert underscores by dots. // 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 { if net.ParseIP(ip) == nil {
// Not a valid IP, so treat this is a hostname. // Not a valid IP, so treat this is a hostname.
@@ -143,7 +143,7 @@ func NewSSLDaemonHandler() http.Handler {
node := v["node"] node := v["node"]
if strings.HasPrefix(node, "pwd") { if strings.HasPrefix(node, "pwd") {
// Node is actually an ip, need to convert underscores by dots. // 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 { if net.ParseIP(ip) == nil {
// Not a valid IP, so treat this is a hostname. // Not a valid IP, so treat this is a hostname.

View File

@@ -13,7 +13,7 @@ import (
) )
func StartTLSProxy(port string) { func StartTLSProxy(port string) {
var validProxyHost = regexp.MustCompile(`^.*pwd([0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}(?:-[0-9]{1,5})?)\..*$`) var validProxyHost = regexp.MustCompile(`^.*pwd([0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}(?:-[0-9]{1,5})?)\..*$`)
tlsListener, tlsErr := net.Listen("tcp", fmt.Sprintf(":%s", port)) tlsListener, tlsErr := net.Listen("tcp", fmt.Sprintf(":%s", port))
log.Println("Listening on port " + port) log.Println("Listening on port " + port)

View File

@@ -185,7 +185,7 @@
} }
$scope.getProxyUrl = function(instance, port) { $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; return url;
} }