Commit 51adb054b4571dc0988824c0e57004c1ee278efe
1 parent
b5dead51
Authentification par SSH
Showing
3 changed files
with
41 additions
and
25 deletions
Show diff stats
app/services/SessionsServ.js
1 | var SessionModl = require('../models/SessionModl'); | 1 | var SessionModl = require('../models/SessionModl'); |
2 | var NomsServ = require('../services/NomsServ'); | 2 | var NomsServ = require('../services/NomsServ'); |
3 | +var SshAuthServ = require('../services/SshAuthServ'); | ||
3 | 4 | ||
4 | var sessions = {}; | 5 | var sessions = {}; |
5 | 6 | ||
@@ -80,18 +81,7 @@ sessions.create = function (login, cb) { | @@ -80,18 +81,7 @@ sessions.create = function (login, cb) { | ||
80 | }; | 81 | }; |
81 | 82 | ||
82 | sessions.login = function (data, cb) { | 83 | sessions.login = function (data, cb) { |
83 | - // DUMMY | ||
84 | - NomsServ.get(data.login, function (nom) { | ||
85 | - if (nom === false) { | ||
86 | - cb(null, false); | ||
87 | - } else { | ||
88 | - if (data.pass == 'cool') { | ||
89 | - cb(null, true); | ||
90 | - } else { | ||
91 | - cb(null, false); | ||
92 | - } | ||
93 | - } | ||
94 | - }); | 84 | + SshAuthServ.verify(data.login, data.pass, cb); |
95 | }; | 85 | }; |
96 | 86 | ||
97 | sessions.open = function (data, cb) { | 87 | sessions.open = function (data, cb) { |
@@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
1 | +var Client = require('ssh2').Client; | ||
2 | + | ||
3 | +var creds = require('../../config/sshAuth'); | ||
4 | + | ||
5 | +var SshAuth = {}; | ||
6 | + | ||
7 | +SshAuth.verify = function (login, pass, cb) { | ||
8 | + var conn = new Client(); | ||
9 | + conn.on('ready', function () { | ||
10 | + cb(null, true); | ||
11 | + }).on('error', function(err) { | ||
12 | + if (err.level === 'client-authentication') { | ||
13 | + cb(null, false); | ||
14 | + } else { | ||
15 | + cb(err); | ||
16 | + } | ||
17 | + }).connect({ | ||
18 | + host: creds.host, | ||
19 | + port: creds.port, | ||
20 | + username: login, | ||
21 | + password: pass | ||
22 | + }); | ||
23 | +}; | ||
24 | + | ||
25 | +module.exports = SshAuth; |
package.json
1 | { | 1 | { |
2 | - "name": "ci-site", | ||
3 | - "main": "server.js", | ||
4 | - "dependencies": { | ||
5 | - "async": "^0.9.0", | ||
6 | - "body-parser": "^1.12.0", | ||
7 | - "cookie-parser": "^1.3.4", | ||
8 | - "express": "^4.12.2", | ||
9 | - "method-override": "^2.3.1", | ||
10 | - "mongoose": "^3.8.25", | ||
11 | - "morgan": "^1.5.1", | ||
12 | - "node-line-reader": "0.0.2", | ||
13 | - "ursa": "^0.8.4" | ||
14 | - } | 2 | + "name": "ci-site", |
3 | + "main": "server.js", | ||
4 | + "dependencies": { | ||
5 | + "async": "^0.9.0", | ||
6 | + "body-parser": "^1.12.0", | ||
7 | + "cookie-parser": "^1.3.4", | ||
8 | + "express": "^4.12.2", | ||
9 | + "method-override": "^2.3.1", | ||
10 | + "mongoose": "^3.8.25", | ||
11 | + "morgan": "^1.5.1", | ||
12 | + "node-line-reader": "0.0.2", | ||
13 | + "ssh2": "^0.4.6", | ||
14 | + "ursa": "^0.8.4" | ||
15 | + } | ||
15 | } | 16 | } |