Skip to content

Commit

Permalink
Dependency installation for the login feature. Handling home director…
Browse files Browse the repository at this point in the history
…ies for user accounts.
  • Loading branch information
rabchev committed Sep 23, 2013
1 parent a1c6827 commit f790bb2
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
19 changes: 19 additions & 0 deletions bin/dependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*jslint plusplus: true, devel: true, nomen: true, node: true, vars: true, indent: 4, maxerr: 50 */
/*global */

"use strict";

var exec;

if (process.getuid && process.setuid) {
exec = require("child_process").exec;
exec("./bin/libpam-dev-check.sh", function (err) {
if (!err) {
exec("npm install authenticate-pam", function (err) {

});
} else {
console.log(err);
}
});
}
6 changes: 6 additions & 0 deletions bin/libpam-dev-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

if [ `echo '#include <security/pam_appl.h>' | cpp -H -o /dev/null 2>&1 | head -n1 | grep 'fatal error' | wc -l` -eq "1" ]; then
echo "WARNING: Please install the libpam-dev package and than reinstall web-terminal if you want to use the login feature. The current installation will not fail, but the feature won't be available.";
exit 1;
fi
35 changes: 28 additions & 7 deletions lib/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ var io = require("socket.io"),
connect = require("connect"),
path = require("path"),
spawn = require('child_process').spawn,
exec = require('child_process').exec,
pkg = require("../package.json"),
cmdLine = require("./command"),
path = require("path"),
fs = require("fs"),
repl = require("repl"),
util = require("util"),
_ = require("lodash"),
streams = require("./streams"),
config = pkg.config || {},
errs = {
Expand Down Expand Up @@ -125,7 +127,8 @@ function initialize(server, options, fn) {
io.sockets.on("connection", function (socket) {

var cwd = process.cwd(),
env = process.env,
env = _.clone(process.env),
home = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE,
linebreak = "\n", // check if we need to add \r\n for windows
promptChar = process.platform === "win32" ? ">" : "$",
stdin,
Expand All @@ -136,8 +139,8 @@ function initialize(server, options, fn) {
replSrv,
user,
username;

function execCmd(command) {
function execCmd(command, buffered) {
if (env.WEBT_LOGIN && !user) {
socket.emit("exit", "login required");
return;
Expand Down Expand Up @@ -254,7 +257,7 @@ function initialize(server, options, fn) {
case "cd":
arg = args[0];
if (arg[0] === "~") {
basePath = process.env[(process.platform === "win32") ? "USERPROFILE" : "HOME"];
basePath = home;
arg = arg.substring(2);
} else {
basePath = cwd;
Expand Down Expand Up @@ -310,6 +313,9 @@ function initialize(server, options, fn) {
} else {
execCmd(command);
}
break;
case "echo":

break;
default:
execCmd(command);
Expand All @@ -335,12 +341,27 @@ function initialize(server, options, fn) {
pam.authenticate(username, input, function (err) {
if (err) {
console.log("Authentication failed: " + err);
socket.emit(errs.wrongCrdtls);
socket.emit("exit", errs.wrongCrdtls);
socket.emit("username");
} else {
console.log("Authenticated: " + username);
user = username;
begin();
require("uid-number")(username, function (err, uid, gid) {
if (err) {
console.log(err);
socket.emit("exit", err);
} else {
user = uid;
exec("echo ~" + username, function (err, stdout, stderr) {
if (err) {
console.log(err);
socket.emit("exit", err);
} else {
cwd = home = env.HOME = stdout.toString().trim();
begin();
}
});
}
});
}
});
});
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@
"send": "*",
"connect": "*",
"socket.io": "*",
"commander": "*"
"commander": "*",
"lodash": "*"
},
"devDependencies": {
"nodeunit": "*"
},
"optionalDependencies": {
"authenticate-pam": "*",
"uid-number": "*"
},
"keywords": [
"command",
"shell",
Expand Down

0 comments on commit f790bb2

Please sign in to comment.