Skip to content

Commit 199efb4

Browse files
committed
Merge branch 'master' into dist
2 parents 6d8f99d + 7e1d533 commit 199efb4

File tree

11 files changed

+100
-50
lines changed

11 files changed

+100
-50
lines changed

app/app.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ angular.module('dockerui', [
2525
'volumes'])
2626
.config(['$routeProvider', '$httpProvider', function ($routeProvider, $httpProvider) {
2727
'use strict';
28+
29+
$httpProvider.defaults.xsrfCookieName = 'csrfToken';
30+
$httpProvider.defaults.xsrfHeaderName = 'X-CSRF-Token';
31+
2832
$routeProvider.when('/', {
2933
templateUrl: 'app/components/dashboard/dashboard.html',
3034
controller: 'DashboardController'
@@ -75,10 +79,14 @@ angular.module('dockerui', [
7579
if (typeof(response.data) === 'string' && response.data.startsWith('Conflict.')) {
7680
$.gritter.add({
7781
title: 'Error',
78-
text: response.data,
82+
text: $('<div>').text(response.data).html(),
7983
time: 10000
8084
});
8185
}
86+
var csrfToken = response.headers('X-Csrf-Token');
87+
if (csrfToken) {
88+
document.cookie = 'csrfToken=' + csrfToken;
89+
}
8290
return response;
8391
}
8492
};
@@ -88,4 +96,4 @@ angular.module('dockerui', [
8896
// You need to set this to the api endpoint without the port i.e. http://192.168.1.9
8997
.constant('DOCKER_ENDPOINT', 'dockerapi')
9098
.constant('DOCKER_PORT', '') // Docker port, leave as an empty string if no port is requred. If you have a port, prefix it with a ':' i.e. :4243
91-
.constant('UI_VERSION', 'v0.10.0-beta');
99+
.constant('UI_VERSION', 'v0.10.1-beta');

app/shared/services.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
angular.module('dockerui.services', ['ngResource'])
1+
angular.module('dockerui.services', ['ngResource', 'ngSanitize'])
22
.factory('Container', ['$resource', 'Settings', function ContainerFactory($resource, Settings) {
33
'use strict';
44
// Resource for interacting with the docker containers
@@ -171,13 +171,13 @@ angular.module('dockerui.services', ['ngResource'])
171171
}
172172
};
173173
})
174-
.factory('Messages', ['$rootScope', function MessagesFactory($rootScope) {
174+
.factory('Messages', ['$rootScope', '$sanitize', function MessagesFactory($rootScope, $sanitize) {
175175
'use strict';
176176
return {
177177
send: function (title, text) {
178178
$.gritter.add({
179-
title: title,
180-
text: text,
179+
title: $sanitize(title),
180+
text: $sanitize(text),
181181
time: 2000,
182182
before_open: function () {
183183
if ($('.gritter-item-wrapper').length === 3) {
@@ -188,8 +188,8 @@ angular.module('dockerui.services', ['ngResource'])
188188
},
189189
error: function (title, text) {
190190
$.gritter.add({
191-
title: title,
192-
text: text,
191+
title: $sanitize(title),
192+
text: $sanitize(text),
193193
time: 10000,
194194
before_open: function () {
195195
if ($('.gritter-item-wrapper').length === 4) {

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dockerui",
3-
"version": "0.10.0-beta",
3+
"version": "0.10.1-beta",
44
"homepage": "https://github.com/crosbymichael/dockerui",
55
"authors": [
66
"Michael Crosby <[email protected]>",
@@ -23,6 +23,7 @@
2323
"dependencies": {
2424
"Chart.js": "1.0.2",
2525
"angular": "1.3.15",
26+
"angular-sanitize": "1.3.15",
2627
"angular-bootstrap": "0.12.0",
2728
"angular-mocks": "1.3.15",
2829
"angular-oboe": "*",

dist/angular.js

Lines changed: 23 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/dockerui

1.09 MB
Binary file not shown.

dist/dockerui.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vendor.js

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dockerui-checksum.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9d2349d7d4fd3b7a22f87e2b54cd7fb2cfd6d537 dockerui
1+
965f7ce53139cf9e75e5b8a8206a4af5791eb8f8 dockerui

dockerui.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ import (
1010
"net/url"
1111
"os"
1212
"strings"
13+
"github.com/gorilla/csrf"
14+
"io/ioutil"
15+
"fmt"
16+
"github.com/gorilla/securecookie"
1317
)
1418

1519
var (
1620
endpoint = flag.String("e", "/var/run/docker.sock", "Dockerd endpoint")
1721
addr = flag.String("p", ":9000", "Address and port to serve dockerui")
1822
assets = flag.String("a", ".", "Path to the assets")
23+
authKey []byte
24+
authKeyFile = "authKey.dat"
1925
)
2026

2127
type UnixHandler struct {
@@ -85,9 +91,35 @@ func createHandler(dir string, e string) http.Handler {
8591
h = createUnixHandler(e)
8692
}
8793

94+
// Use existing csrf authKey if present or generate a new one.
95+
dat, err := ioutil.ReadFile(authKeyFile)
96+
if err != nil {
97+
fmt.Println(err)
98+
authKey = securecookie.GenerateRandomKey(32)
99+
err := ioutil.WriteFile(authKeyFile, authKey, 0644)
100+
if err != nil {
101+
fmt.Println("unable to persist auth key", err)
102+
}
103+
} else {
104+
authKey = dat
105+
}
106+
107+
CSRF := csrf.Protect(
108+
authKey,
109+
csrf.HttpOnly(false),
110+
csrf.Secure(false),
111+
)
112+
88113
mux.Handle("/dockerapi/", http.StripPrefix("/dockerapi", h))
89114
mux.Handle("/", fileHandler)
90-
return mux
115+
return CSRF(csrfWrapper(mux))
116+
}
117+
118+
func csrfWrapper(h http.Handler) http.Handler {
119+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
120+
w.Header().Set("X-CSRF-Token", csrf.Token(r))
121+
h.ServeHTTP(w, r)
122+
})
91123
}
92124

93125
func main() {

gruntFile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ module.exports = function (grunt) {
153153
},
154154
angular: {
155155
src: ['bower_components/angular/angular.js',
156+
'bower_components/angular-sanitize/angular-sanitize.js',
156157
'bower_components/angular-route/angular-route.js',
157158
'bower_components/angular-resource/angular-resource.js',
158159
'bower_components/angular-bootstrap/ui-bootstrap-tpls.js',

0 commit comments

Comments
 (0)