diff --git a/handlers/bootstrap.go b/handlers/bootstrap.go index afa217c..635f901 100644 --- a/handlers/bootstrap.go +++ b/handlers/bootstrap.go @@ -77,6 +77,7 @@ func Register(extend HandlerExtender) { r.HandleFunc("/oauth/providers/{provider}/callback", LoginCallback).Methods("GET") r.HandleFunc("/playgrounds", NewPlayground).Methods("PUT") r.HandleFunc("/playgrounds", ListPlaygrounds).Methods("GET") + r.HandleFunc("/my/playground", GetCurrentPlayground).Methods("GET") corsRouter.HandleFunc("/", NewSession).Methods("POST") diff --git a/handlers/home.go b/handlers/home.go index 887aa28..bb6104e 100644 --- a/handlers/home.go +++ b/handlers/home.go @@ -1,6 +1,7 @@ package handlers import ( + "fmt" "log" "net/http" @@ -28,8 +29,8 @@ func Home(w http.ResponseWriter, r *http.Request) { return } - if !playground.AllowWindowsInstances { - http.ServeFile(w, r, "./www/index-nw.html") + if playground.IndexFile != "" { + http.ServeFile(w, r, fmt.Sprintf("./www/%s", playground.IndexFile)) } else { http.ServeFile(w, r, "./www/index.html") } diff --git a/handlers/new_playground.go b/handlers/playground.go similarity index 53% rename from handlers/new_playground.go rename to handlers/playground.go index 964b70f..73a48a8 100644 --- a/handlers/new_playground.go +++ b/handlers/playground.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "net/http" + "time" "github.com/play-with-docker/play-with-docker/config" "github.com/play-with-docker/play-with-docker/pwd/types" @@ -51,6 +52,32 @@ func ListPlaygrounds(rw http.ResponseWriter, req *http.Request) { json.NewEncoder(rw).Encode(playgrounds) } +type PlaygroundConfigurationResponse struct { + Id string `json:"id"` + Domain string `json:"domain"` + DefaultDinDInstanceImage string `json:"default_dind_instance_image"` + AvailableDinDInstanceImages []string `json:"available_dind_instance_images"` + AllowWindowsInstances bool `json:"allow_windows_instances"` + DefaultSessionDuration time.Duration `json:"default_session_duration"` +} + +func GetCurrentPlayground(rw http.ResponseWriter, req *http.Request) { + playground := core.PlaygroundFindByDomain(req.Host) + if playground == nil { + log.Printf("Playground for domain %s was not found!", req.Host) + rw.WriteHeader(http.StatusBadRequest) + return + } + json.NewEncoder(rw).Encode(PlaygroundConfigurationResponse{ + Id: playground.Id, + Domain: playground.Domain, + DefaultDinDInstanceImage: playground.DefaultDinDInstanceImage, + AvailableDinDInstanceImages: playground.AvailableDinDInstanceImages, + AllowWindowsInstances: playground.AllowWindowsInstances, + DefaultSessionDuration: playground.DefaultSessionDuration, + }) +} + func validateToken(req *http.Request) bool { _, password, ok := req.BasicAuth() if !ok { diff --git a/pwd/types/playground.go b/pwd/types/playground.go index 582ed10..47b8bab 100644 --- a/pwd/types/playground.go +++ b/pwd/types/playground.go @@ -79,5 +79,6 @@ type Playground struct { AllowWindowsInstances bool `json:"allow_windows_instances" bson:"allow_windows_instances"` DefaultSessionDuration time.Duration `json:"default_session_duration" bson:"default_session_duration"` Extras PlaygroundExtras `json:"extras" bson:"extras"` + IndexFile string `json:"index_file" bson:"index_file"` Tasks []string `json:"tasks" bson:"tasks"` } diff --git a/www/assets/app.js b/www/assets/app.js index 30e092a..cadaa22 100644 --- a/www/assets/app.js +++ b/www/assets/app.js @@ -155,6 +155,15 @@ } } + $scope.loadPlaygroundConf = function() { + $http({ + method: 'GET', + url: '/my/playground', + }).then(function(response) { + $scope.playground = response.data; + }); + + } $scope.getSession = function(sessionId) { $http({ method: 'GET', @@ -432,6 +441,7 @@ }); } + $scope.loadPlaygroundConf(); $scope.getSession($scope.sessionId); $scope.createBuilderTerminal = function() { diff --git a/www/index-nw.html b/www/index-nw.html deleted file mode 100644 index e0a780c..0000000 --- a/www/index-nw.html +++ /dev/null @@ -1,314 +0,0 @@ - - - - Docker Playground - - - - - - - - - -
-
- -
-

- Your session has expired. -

-
-
-
-
- -
-

No connection to server. Reconnecting...

- -
- -
- - - - {{ttl}} - Close session -
-

Instances

- -
-
-
- - {{newInstanceBtnText}} - - - - -
-

{{instance.ip}}

-

{{instance.hostname}}

-
- -
-
-
-
- -
-

Add instances to your playground.

-

Sessions and all their instances are deleted after {{ttl}} hours.

-
- -
-
- - - - - {{instance.name}} - - - -
- - - - - - - {{$chip}} - - - - - {{$chip}} - - -
-
- - - - - - - - -
-
- - {{deleteInstanceBtnText}} - -
- -
- -
- {{uploadMessage}} -
-
-
Connection has been lost. Sometimes this happens when a windows instance is joining a swarm. Trying to reconnect terminal...
- - -
-
-
-
- -
-
- - -
-

Session stack builder

- -
-
- -
- We are building your stack. This might take a while.
-
-
-
-
-
- Your session is ready! -
-
-
- - - - Close - - -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/www/index.html b/www/index.html index 136f1d3..59fb4b7 100644 --- a/www/index.html +++ b/www/index.html @@ -50,7 +50,7 @@
-
+
Windows containers {{windows}}