diff --git a/app/services/SessionsServ.js b/app/services/SessionsServ.js index e4b18f4..e883fff 100644 --- a/app/services/SessionsServ.js +++ b/app/services/SessionsServ.js @@ -1,5 +1,6 @@ var SessionModl = require('../models/SessionModl'); var NomsServ = require('../services/NomsServ'); +var SshAuthServ = require('../services/SshAuthServ'); var sessions = {}; @@ -80,18 +81,7 @@ sessions.create = function (login, cb) { }; sessions.login = function (data, cb) { - // DUMMY - NomsServ.get(data.login, function (nom) { - if (nom === false) { - cb(null, false); - } else { - if (data.pass == 'cool') { - cb(null, true); - } else { - cb(null, false); - } - } - }); + SshAuthServ.verify(data.login, data.pass, cb); }; sessions.open = function (data, cb) { diff --git a/app/services/SshAuthServ.js b/app/services/SshAuthServ.js new file mode 100644 index 0000000..2c53ad4 --- /dev/null +++ b/app/services/SshAuthServ.js @@ -0,0 +1,25 @@ +var Client = require('ssh2').Client; + +var creds = require('../../config/sshAuth'); + +var SshAuth = {}; + +SshAuth.verify = function (login, pass, cb) { + var conn = new Client(); + conn.on('ready', function () { + cb(null, true); + }).on('error', function(err) { + if (err.level === 'client-authentication') { + cb(null, false); + } else { + cb(err); + } + }).connect({ + host: creds.host, + port: creds.port, + username: login, + password: pass + }); +}; + +module.exports = SshAuth; diff --git a/package.json b/package.json index 7938a38..f25c87b 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,16 @@ { - "name": "ci-site", - "main": "server.js", - "dependencies": { - "async": "^0.9.0", - "body-parser": "^1.12.0", - "cookie-parser": "^1.3.4", - "express": "^4.12.2", - "method-override": "^2.3.1", - "mongoose": "^3.8.25", - "morgan": "^1.5.1", - "node-line-reader": "0.0.2", - "ursa": "^0.8.4" - } + "name": "ci-site", + "main": "server.js", + "dependencies": { + "async": "^0.9.0", + "body-parser": "^1.12.0", + "cookie-parser": "^1.3.4", + "express": "^4.12.2", + "method-override": "^2.3.1", + "mongoose": "^3.8.25", + "morgan": "^1.5.1", + "node-line-reader": "0.0.2", + "ssh2": "^0.4.6", + "ursa": "^0.8.4" + } } -- libgit2 0.21.2