Skip to content

Commit

Permalink
Merge pull request rabchev#16 from dcbartlett/master
Browse files Browse the repository at this point in the history
Added Interface declaration support
  • Loading branch information
rabchev committed Jan 12, 2015
2 parents 5b91eeb + a41cf39 commit 978ea64
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
9 changes: 7 additions & 2 deletions bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ var commander = require("commander"),
if (commander.options.length === 0) {
commander
.version(pkg.version)
.option("-p, --port <port>", "Cpecifies the TCP port for the HTTP server.")
.option("-i, --interface <ip>", "Interface (ip) to listen on.")
.option("-p, --port <port>", "Specifies the TCP port for the HTTP server.")
.option("-s, --ssl", "Start HTTP server over secure socket layer.")
.option("-h, --shell <shell>", "Executes commands in the specified command shell. Example: --shell bash")
.option("-l, --login", "Require login to use the terminal. The process is executed with the logged user account. NOTE: this option works only for POSIX platforms and it requires libpam-dev package to be installed prior to installing web-terminal.")
Expand All @@ -24,4 +25,8 @@ if (commander.login) {
process.env.WEBT_LOGIN = commander.login;
}

terminal(commander.port);
terminal({
port: commander.port,
interface: commander.interface,
ssl: commander.ssl,
});
36 changes: 23 additions & 13 deletions lib/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ function initLogin(socket) {
return false;
}

function initialize(server, options, fn) {
var port, sPort, protocol;
function initialize(options, fn) {

var port, sPort, protocol, server;

if (process.env.WEBT_LOGIN) {
initLogin();
Expand All @@ -83,34 +84,43 @@ function initialize(server, options, fn) {
options = {};
}

if (undefined === server) {
if (undefined === options.port) {
if (process.env.PORT) {
server = (+process.env.PORT);
options.port = (+process.env.PORT);
} else {
server = (+config.port) || 8088;
options.port = (+config.port) || 8088;
}
}

if ("string" === typeof server) {
server = (+server);
if ("string" === typeof options.port) {
options.port = (+options.port);
}

if (/\b(?:\d{1,3}\.){3}\d{1,3}\b/.test(options.interface)) {
var host = options.interface;
}

if ("number" === typeof server) {
if ("number" === typeof options.port) {
// if a port number is passed
port = server;
port = options.port;

if (options && options.key) {
protocol = "https";
http = require(protocol);
sPort = (port !== 443) ? ":" + port : "";
} else {
protocol = "http";
http = require(protocol);
sPort = (port !== 80) ? ":" + port : "";
}

server = http.createServer(options);
server.listen(port, fn);
http = require(protocol);

server = http.createServer();

if (host) {
server.listen(port, host, fn);
} else {
server.listen(port, fn);
}
standalone = true;

console.log(util.format("Web-Terminal running at %s://localhost%s/terminal", protocol, sPort));
Expand Down

0 comments on commit 978ea64

Please sign in to comment.