From bfaf5591a5fa31a736b4860a39821f5ce6107379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Wed, 23 Nov 2016 15:58:20 +0000 Subject: [PATCH] fixed login issue on chromium; moved docker into mwaeckerlin/docker.js on github --- COPYING | 2 +- ChangeLog | 7 + INSTALL | 2 +- nodejs/docker/docker.js | 483 ----------------------- nodejs/docker/index.js | 8 - nodejs/makefile.am | 2 +- nodejs/package.json.in | 3 +- nodejs/public/javascripts/servicedock.js | 11 +- nodejs/servicedock.js | 4 +- nodejs/sockets/index.js | 23 +- nodejs/views/index.ejs | 8 +- 11 files changed, 39 insertions(+), 514 deletions(-) delete mode 100644 nodejs/docker/docker.js delete mode 100644 nodejs/docker/index.js diff --git a/COPYING b/COPYING index 88798ab..caeca07 120000 --- a/COPYING +++ b/COPYING @@ -1 +1 @@ -/usr/share/automake-1.15/COPYING \ No newline at end of file +/usr/share/automake-1.14/COPYING \ No newline at end of file diff --git a/ChangeLog b/ChangeLog index 3a1af91..f99fd21 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2016-11-22 22:22 marc + + * ChangeLog, nodejs/etc/servicedock.json, + nodejs/public/javascripts/servicedock.js, nodejs/servicedock.js, + nodejs/sockets/index.js: stats: fixed issue with missing /sys/fs + in docker 1.9, using docker stats; login works + 2016-11-22 15:56 marc * nodejs/authentication, nodejs/package.json.in: authentication is diff --git a/INSTALL b/INSTALL index ddcdb76..f812f5a 120000 --- a/INSTALL +++ b/INSTALL @@ -1 +1 @@ -/usr/share/automake-1.15/INSTALL \ No newline at end of file +/usr/share/automake-1.14/INSTALL \ No newline at end of file diff --git a/nodejs/docker/docker.js b/nodejs/docker/docker.js deleted file mode 100644 index 8848210..0000000 --- a/nodejs/docker/docker.js +++ /dev/null @@ -1,483 +0,0 @@ -var Docker = function() { - - function same(array1, array2) { - if (!array1 && !array2) return true; - if (!array1 || !array2) return false; - return (array1.length == array2.length) - && array1.every(function(element, index) { - return element === array2[index]; - }); - } - - function quote(text) { - if (text.match(/[^-_:=\/a-zA-Z0-9]/)) { - if (text.match('"')) { - if (!text.match("'")) return "'"+text+"'"; - else return '"'+text.replace(/"/g, '\\"')+'"'; - } else { - return '"'+text+'"'; - } - } else { - return text; - } - } - - var _docker = this; - - this.Images = function() { - - var _images = this; - var images = []; - var nodes = []; - - function setup() { - delete nodes; nodes = []; - images.forEach(function(c, i) { - if (!nodes[c.Id]) nodes[c.Id] = {}; - nodes[c.Id].id = c.Id; - nodes[c.Id].tags = c.RepoTags; - nodes[c.Id].created = c.Created; - nodes[c.Id].author = c.Author; - nodes[c.Id].os = c.Os+"/"+c.Architecture; - nodes[c.Id].parent = c.Parent; - nodes[c.Id].env = c.Config.Env || []; - nodes[c.Id].cmd = c.Config.Cmd; - nodes[c.Id].entrypoint = c.Config.Entrypoint; - nodes[c.Id].ports = []; - if (c.Config.ExposedPorts) - for (p in c.Config.ExposedPorts) - nodes[c.Id].ports.push(p); - nodes[c.Id].volumes = c.Config.Volumes; - if (c.Parent) { - if (!nodes[c.Parent]) nodes[c.Parent] = {}; - if (!nodes[c.Parent].children) nodes[c.Parent].children = []; - nodes[c.Parent].children.push(c.Id); - } - }); - } - this.tags = function() { - var res = []; - for (n in nodes) if (nodes[n].tags) res = res.concat(nodes[n].tags); - return res; - } - this.get = function(tag) { - for (n in nodes) if (nodes[n].tags && nodes[n].tags.indexOf(tag)>-1) return nodes[n]; - return null; - } - this.cleanup = function(id, instance) { - if (!nodes[id]) return - nodes[id].env.forEach(function(e) { - if ((pos=instance.env.indexOf(e))>-1) instance.env.splice(pos, 1) - }) - if (same(nodes[id].cmd, instance.cmd)) instance.cmd = null - if (same(nodes[id].entrypoint, instance.entrypoint)) instance.entrypoint = null - } - this.set = function(c) { - if (typeof c == "string") c = JSON.parse(c); - if (typeof c != "object") throw "wrong format: "+(typeof c); - images = c; - setup(); - } - - } - - this.Containers = function() { - - var _containers = this; - - this.Status = Object.freeze({ - Error: {color: "indianred1", action1: "start", action2: "remove", bash: false}, - Terminated: {color: "yellow2", action1: "start", action2: "remove", bash: false}, - Restarting: {color: "lightblue", action1: "start", action2: "remove", bash: false}, - Paused: {color: "grey", action1: "unpause", action2: null, bash: false}, - Running: {color: "lightgreen", action1: "pause", action2: "stop", bash: true}, - Preview: {color: "orangered"}, - Prepared: {color: "lightgrey"} - }); - var containers = []; - var nodes = []; - function protocol(port) { - if (port.toString().match("443")) return "https://"; - if (port.toString().match("3304")) return "mysql://"; - if (port.toString().match("22")) return "ssh://"; - return "http://"; - } - this.exists = function(name) { - if (nodes[name]) return true; - return false; - } - function getIps(n, ips) { - if (n.ports) n.ports.forEach(function(p) { - if (!p.ip||p.ip==""||p.ip=="0.0.0.0"||p.ip==0) - p.ip=window.location.hostname; - if (!ips[p.ip]) ips[p.ip] = []; - ips[p.ip].push(p); - }); - } - function graphIpClusters(ips) { - var res = "newrank=true;\n"; - var i = 0; - for (ip in ips) { - res += "subgraph clusterIp"+(++i)+' {\nlabel="'+ip+'";\n'; - ips[ip].forEach(function(p) { - res += '"'+p.ip+":"+p.external - +'" [label="'+p.external+'",URL="' - +protocol(p.internal)+p.ip+':'+p.external+'",shape=box];\n'; - }); - res+="}\n"; - } - res += "{rank=same;\n"; - for (ip in ips) { - ips[ip].forEach(function(p) { - res += '"'+p.ip+":"+p.external+'";\n'; - }); - } - res+="}\n"; - return res; - } - function graphNode(n, omitstats) { - var res = ""; - var label = (n.image?n.image.name:'UNDEFINED')+'\\n' - +(n.name?n.name:"UNKNOWN") - +(omitstats?'':'\\ncpu: ????? mem: ?????'); - res += '"'+n.name+'"' - +' [label="'+label - +'",URL="#'+n.name - +'",fillcolor='+(n.status?n.status.color+',style=filled':'red,shape=octagon,style=filled')+"];\n"; - if (n.ports) n.ports.forEach(function(p) { - res += '"'+(p.ip?p.ip+":":"")+p.external+'" -> "'+n.name - +'" [label="'+p.internal+'"];\n'; - }); - if (n.links) n.links.forEach(function(l) { - res += '"'+n.name+'" -> "'+l.container+'" [label="link: '+l.name+'"];\n' - }); - return res; - } - function graphVolumesInside(n) { - var res = ""; - if (n.volumes) n.volumes.forEach(function(v) { - res += '"'+v.id+v.inside+'" [label="'+v.inside+'",shape=box];\n'; - }); - return res; - } - function graphVolumesOutside(n) { - var res = ""; - if (n.volumes) n.volumes.forEach(function(v) { - if (v.host) - res += '"'+v.outside+'" [label="'+v.host+'",shape=box];\n'; - }); - return res; - } - function graphVolumesConnections(n, nodes) { - var res = ""; - if (n.volumes) n.volumes.forEach(function(v) { - if (v.host) - res += '"'+v.id+v.inside+'" -> "'+v.outside+'" [label="mounted from"]\n'; - res += '"'+n.name+'" -> "'+v.id+v.inside+'" [label="volume/'+v.rw+'"]\n'; - }); - if (n.volumesfrom) n.volumesfrom.forEach(function(o) { - res += '"'+n.name+'" -> "'+nodes[o].name+'" [label="volumes from"]\n'; - }); - return res; - } - this.graph = function(n, omitstats) { - var res = ""; - var ips = []; - n = n || nodes; - for (name in n) getIps(n[name], ips); - res += graphIpClusters(ips); - for (name in n) res += graphNode(n[name], omitstats); - res += "{rank=same;\n"; - for (name in n) res += graphVolumesInside(n[name]); - res+="}\n"; - res += "{rank=same;\n"; - for (name in n) res += graphVolumesOutside(n[name]); - res+="}\n"; - for (name in n) res += graphVolumesConnections(n[name], n); - return res; - } - function addNodes(ns, name) { - var n = nodes[name] || ns[name] || {name: name}; - ns[name] = n; - if (n.links) n.links.forEach(function(peer) { - if (!ns[peer.container]) addNodes(ns, peer.container); - }); - if (n.usedby) n.usedby.forEach(function(peer) { - if (!ns[peer]) addNodes(ns, peer); - }); - if (n.volumesfrom) n.volumesfrom.forEach(function(peer) { - if (!ns[peer]) addNodes(ns, peer); - }); - if (n.volumesto) n.volumesto.forEach(function(peer) { - if (!ns[peer]) addNodes(ns, peer); - }); - } - this.subnet = function(name, nodes) { - var ns = nodes || {}; - addNodes(ns, name); - return ns; - } - this.subgraph = function(name, nodes) { - return this.graph(this.subnet(name, nodes), nodes); - } - this.configuration = function(name) { - var ns = name; - if (typeof name == 'string') ns = this.subnet(name); - var creates = []; - for (n in ns) { - var instance = { - name: ns[n].name, - image: ns[n].image.name, - ports: ns[n].ports, - env: ns[n].env, - cmd: ns[n].cmd, - entrypoint: ns[n].entrypoint, - volumesfrom: ns[n].volumesfrom, - links: ns[n].links, - volumes: [] - }; - if (ns[n].ports) ns[n].ports.forEach(function(p) { - if (p.ip && !p.ip.match(/^([0-9]{1,3}\.){3}[0-9]{1,3}$/)) p.ip = null; - }); - ns[n].volumes.forEach(function(v) { - if (v.host) instance.volumes.push({ - inside: v.inside, - outside: v.host - }); - }); - _docker.images.cleanup(ns[n].image.id, instance); - creates.push(instance); - } - creates.sort(function(a, b) { - if (a.volumesfrom.indexOf(b.name)>=0) return 1; // a after b - if (b.volumesfrom.indexOf(a.name)>=0) return -1; // a before b - for (var i=0; i') - $("#popup").empty(); - if (n.status.action1) { - $("#popup").append(''); - $("#popup1").click(function() { - emit(n.status.action1, name); - }); - } - $("#popup").append(''); - $("#popup2").click(function() { - if (focused) overview(); else details(name); - }); - if (n.status.action2) { - $("#popup").append(''); - $("#popup3").click(function() { - emit(n.status.action2, name); - }); - } - $("#popup").append('
'); - $("#popup").append(''); - $("#popup4").click(function() { - showLogs(); - emit("logs", name); - }); - if (n.status.bash) { - $("#popup").append(''); - $("#popup5").click(function() { - showConsole(); - emit("bash-start", name); - $("#screen").focus(); - $("#screen").keypress(function(e) { - console.log("keypress", e); - if (e.keyCode) emit("bash-input", {name: name, text: String.fromCharCode(e.keyCode)}); - else if (e.charCode) emit("bash-input", {name: name, text: String.fromCharCode(e.charCode)}); - $("#screen").focus(); - }); - // $("#bash").submit(function() { - // emit("bash-input", {name: name, text: $("#command").val()+"\n"}); - // $("#command").val(""); - // }) - }); - } - $("#popup").append(''); - $("#popup6").click(function() { - var download = document.createElement('a'); - download.href = 'data:application/json,' - + encodeURI(JSON.stringify(_containers.configuration(name), null, 2)); - download.target = '_blank'; - download.download = name+'.json'; - var clickEvent = new MouseEvent("click", { - "view": window, - "bubbles": true, - "cancelable": false - }); - download.dispatchEvent(clickEvent); - }); - $("#popup").css("position", "fixed"); - $("#popup").css("top", e.pageY-$("#popup").height()/4); - $("#popup").css("left", e.pageX-$("#popup").width()/2); - $("#popup").mouseleave(function() { - $("#popup").hide(); - }).click(function() { - $("#popup").hide(); - }); - $("#popup").show(); - }) - } - this.set = function(c) { - if (typeof c == "string") c = JSON.parse(c); - if (typeof c != "object") throw "wrong format: "+(typeof c); - containers = c; - setup(); - } - } - - this.images = new this.Images(); - this.containers = new this.Containers(); - -} - -if (typeof module === 'undefined') module = {}; -module.exports = { - Docker: Docker -} diff --git a/nodejs/docker/index.js b/nodejs/docker/index.js deleted file mode 100644 index 9e9bce3..0000000 --- a/nodejs/docker/index.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = function(app) { - - if (app) app.get('/docker/docker.js', function(req, res) { - res.sendfile('docker.js', {root: __dirname}); - }); - - return require(__dirname+'/docker.js'); -} diff --git a/nodejs/makefile.am b/nodejs/makefile.am index a2df96c..30677e5 100644 --- a/nodejs/makefile.am +++ b/nodejs/makefile.am @@ -4,7 +4,7 @@ ## 45678901234567890123456789012345678901234567890123456789012345678901234567890 -EXTRA_DIST = servicedock.js package.json.in public routes sockets docker views +EXTRA_DIST = servicedock.js package.json.in public routes sockets views nodejsdir = ${pkgdatadir}/nodejs diff --git a/nodejs/package.json.in b/nodejs/package.json.in index 5e1d8ee..c2f8f87 100644 --- a/nodejs/package.json.in +++ b/nodejs/package.json.in @@ -10,7 +10,8 @@ "pty.js": "~0.3.0", "async": "~1.5.2", "socketio-auth": "0.0.5", - "authentication.js": ">=0.0.2", + "authentication.js": ">= 0.0.2", + "docker.js": ">= 0.0.0", "ldapauth": "git+https://github.com/DimensionSoftware/node-ldapauth.git" }, "description": "@DESCRIPTION@", diff --git a/nodejs/public/javascripts/servicedock.js b/nodejs/public/javascripts/servicedock.js index 643f387..16b2524 100644 --- a/nodejs/public/javascripts/servicedock.js +++ b/nodejs/public/javascripts/servicedock.js @@ -113,8 +113,8 @@ function connect() { $("#connectionstatus #good").hide(); success("login to server"); socket.emit('authentication', { - username: $("#username").val(), - password: $("#password").val() + username: $("#usernamefield").val(), + password: $("#passwordfield").val() }); } @@ -314,7 +314,7 @@ function showviz(vizpath, more) { .attr('font-weight', 'bold') .attr('font-size', '16') .each(function() {$(this).attr('y', parseFloat($(this).attr('y'))+1.0)}); - $('#main a > ellipse + text + text + text').attr('font-size', '12'); + $('#main a > ellipse + text + text + text, #main a > ellipse + text + text + text + text').attr('font-size', '10'); } catch(e) { (res = res.split("\n")).forEach(function(v, i, a) { a[i] = ("000"+(i+1)).slice(-3)+": "+v; @@ -362,8 +362,11 @@ function stats(data) { lines.forEach(function(line) { if (!line) return; elements = line.split(/ +/); - $('#main text + text:contains("'+elements[0]+'") + text') + $('#main text + text:contains("'+elements[0]+'") + text + text') .html('cpu: '+elements[1]+' mem: '+elements[7]); + $('#main text + text:contains("'+elements[0]+'") + text') + .html('net: '+elements[8]+elements[9]+' '+elements[11]+elements[12] + +' block: '+elements[13]+elements[14]+' '+elements[16]+elements[17]); }); } diff --git a/nodejs/servicedock.js b/nodejs/servicedock.js index 678f1f6..c7cb87a 100644 --- a/nodejs/servicedock.js +++ b/nodejs/servicedock.js @@ -24,9 +24,9 @@ try { var io = require('socket.io').listen(app); var package = require(__dirname+'/package.json'); var config = require(package.path.config); - var docker = require(__dirname+'/docker')(app); + var docker = require('docker.js')(app); var authentication = require('authentication.js')(config.restrict); - var sockets = require(__dirname+'/sockets')(io, authentication); + var sockets = require(__dirname+'/sockets')(app, io, docker, authentication); // Configuration process.argv.forEach(function(val, index) { diff --git a/nodejs/sockets/index.js b/nodejs/sockets/index.js index f688554..a565a4a 100644 --- a/nodejs/sockets/index.js +++ b/nodejs/sockets/index.js @@ -1,8 +1,7 @@ -module.exports = function(io, authentication) { +module.exports = function(app, io, docker, authentication) { var pty = require('pty.js'); var proc = require('child_process'); - var docker = require(__dirname+'/../docker')(); var module={}; var running=""; @@ -186,11 +185,13 @@ module.exports = function(io, authentication) { if (!name.match(/^[a-z0-9][-_:.+a-z0-9]*$/i)) return this.fail("illegal instance name"); if (bash_connections[name]) return; - bash_connections[name] = - pty.spawn("docker", ["exec", "-it", name, "bash", "-i"]); + bash_connections[name] = pty.spawn("docker", ["exec", "-it", name, "bash", "-i"]); bash_connections[name].stdout.on('data', function(data) { emit('bash-data', {name: name, type: 'stdout', text: data.toString()}); }); + bash_connections[name].stderr.on('data', function(data) { + emit('bash-data', {name: name, type: 'stderr', text: data.toString()}); + }); } function bash_start(name) { @@ -241,11 +242,15 @@ module.exports = function(io, authentication) { authenticate: function (socket, data, callback) { console.log("=> authenticate: ", data.username); //get credentials sent by the client - var username = data.username; - var password = data.password; authentication(data.username, data.password, - function() {console.log("####LOGIN-SUCESS####");callback(null, true)}, - function() {console.log("####LOGIN-FAIL####");callback(new Error("wrong credentials"))}); + function() { + console.log("####LOGIN-SUCESS####"); + callback(null, true) + }, + function() { + console.log("####LOGIN-FAIL####"); + callback(new Error("wrong credentials")) + }); }, postAuthenticate: connection, timeout: "none" @@ -259,7 +264,7 @@ module.exports = function(io, authentication) { // Regular Update of Stats setInterval(function() { - exec('docker stats --no-stream'+running, stats); + if (running) exec('docker stats --no-stream'+running, stats); }, 1000); return module; diff --git a/nodejs/views/index.ejs b/nodejs/views/index.ejs index abaf0c3..52d7487 100644 --- a/nodejs/views/index.ejs +++ b/nodejs/views/index.ejs @@ -48,10 +48,10 @@

Login

- - - - + + + +