21
api.go
21
api.go
@@ -65,8 +65,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.HandleFunc("/ping", handlers.Ping).Methods("GET")
|
r.HandleFunc("/ping", handlers.Ping).Methods("GET")
|
||||||
corsRouter.HandleFunc("/instances/images", handlers.GetInstanceImages).Methods("GET")
|
corsRouter.HandleFunc("/instances/images", handlers.GetInstanceImages).Methods("GET")
|
||||||
corsRouter.HandleFunc("/sessions/{sessionId}", handlers.GetSession).Methods("GET")
|
corsRouter.HandleFunc("/sessions/{sessionId}", handlers.GetSession).Methods("GET")
|
||||||
@@ -116,7 +116,7 @@ func main() {
|
|||||||
|
|
||||||
ssl := mux.NewRouter()
|
ssl := mux.NewRouter()
|
||||||
sslProxyHandler := handlers.NewSSLDaemonHandler()
|
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)
|
log.Println("Listening TLS on port " + config.SSLPortNumber)
|
||||||
|
|
||||||
s := &http.Server{Addr: "0.0.0.0:" + config.SSLPortNumber, Handler: ssl}
|
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(clientHello.ServerName, ".")
|
||||||
chunks = strings.Split(chunks[0], "-")
|
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)
|
i := services.FindInstanceByIP(ip)
|
||||||
if i == nil {
|
if i == nil {
|
||||||
return nil, fmt.Errorf("Instance %s doesn't exist", clientHello.ServerName)
|
return nil, fmt.Errorf("Instance %s doesn't exist", clientHello.ServerName)
|
||||||
@@ -138,15 +139,21 @@ func main() {
|
|||||||
log.Fatal(s.ListenAndServeTLS("", ""))
|
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) {
|
func handleDnsRequest(w dns.ResponseWriter, r *dns.Msg) {
|
||||||
if len(r.Question) > 0 && dnsFilter.MatchString(r.Question[0].Name) {
|
if len(r.Question) > 0 && dnsFilter.MatchString(r.Question[0].Name) {
|
||||||
// this is something we know about and we should try to handle
|
// this is something we know about and we should try to handle
|
||||||
question := r.Question[0].Name
|
question := r.Question[0].Name
|
||||||
domainChunks := strings.Split(question, ".")
|
domainChunks := strings.Split(question, ".")
|
||||||
tldChunks := strings.Split(strings.TrimPrefix(domainChunks[0], "pwd"), "-")
|
ipAndPort := strings.TrimPrefix(domainChunks[0], "pwd")
|
||||||
ip := strings.Replace(tldChunks[0], "_", ".", -1)
|
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 := new(dns.Msg)
|
||||||
m.SetReply(r)
|
m.SetReply(r)
|
||||||
|
|||||||
@@ -27,7 +27,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.
|
||||||
@@ -132,7 +132,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.
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user