2014-08-05 08:32:25 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
process.chdir(__dirname);
|
|
|
|
|
2014-08-05 08:44:21 +00:00
|
|
|
var config = require("./config.json");
|
2014-08-14 01:51:54 +00:00
|
|
|
var ClientManager= new require("./src/clientManager");
|
2014-08-05 08:32:25 +00:00
|
|
|
var program = require("commander");
|
|
|
|
var shout = require("./src/server.js");
|
2014-08-05 08:44:21 +00:00
|
|
|
|
|
|
|
program
|
2014-08-14 16:35:37 +00:00
|
|
|
.option("-p, --port <port>")
|
|
|
|
.option("-P, --public");
|
2014-08-05 08:32:25 +00:00
|
|
|
|
|
|
|
program
|
|
|
|
.command("start")
|
2014-08-05 08:44:21 +00:00
|
|
|
.description("Start the server")
|
2014-08-05 08:32:25 +00:00
|
|
|
.action(function() {
|
2014-08-14 17:25:22 +00:00
|
|
|
var users = new ClientManager().getUsers();
|
|
|
|
if (!program.public && !users.length) {
|
|
|
|
console.log("");
|
|
|
|
console.log("No users found!");
|
|
|
|
console.log("Create a new user with 'shout add-user <name>'.")
|
|
|
|
console.log("");
|
|
|
|
} else {
|
|
|
|
shout(program.port, program.public);
|
|
|
|
}
|
2014-08-05 08:32:25 +00:00
|
|
|
});
|
|
|
|
|
2014-08-13 23:43:11 +00:00
|
|
|
program
|
|
|
|
.command("list-users")
|
|
|
|
.description("List all existing users")
|
|
|
|
.action(function() {
|
2014-08-14 17:25:22 +00:00
|
|
|
var users = new ClientManager().getUsers();
|
|
|
|
console.log("");
|
|
|
|
if (!users.length) {
|
|
|
|
console.log("No users found!");
|
|
|
|
} else {
|
|
|
|
console.log("Users:");
|
|
|
|
for (var i = 0; i < users.length; i++) {
|
|
|
|
console.log((i + 1) + ": " + users[i]);
|
|
|
|
}
|
2014-08-13 23:43:11 +00:00
|
|
|
}
|
2014-08-14 17:25:22 +00:00
|
|
|
console.log("");
|
2014-08-13 23:43:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
program
|
|
|
|
.command("add-user <name>")
|
|
|
|
.description("Add a new user")
|
|
|
|
.action(function(name) {
|
|
|
|
var manager = new ClientManager();
|
2014-08-14 17:25:22 +00:00
|
|
|
var users = manager.getUsers();
|
|
|
|
if (users.indexOf(name) !== -1) {
|
|
|
|
console.log("");
|
|
|
|
console.log("User '" + name + "' already exists.");
|
|
|
|
console.log("");
|
|
|
|
return;
|
|
|
|
}
|
2014-08-14 01:51:54 +00:00
|
|
|
require("read")({
|
|
|
|
prompt: "Password: "
|
|
|
|
}, function(err, password) {
|
2014-08-14 17:25:22 +00:00
|
|
|
console.log("");
|
2014-08-14 01:51:54 +00:00
|
|
|
if (err) {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-14 17:25:22 +00:00
|
|
|
var success = manager.addUser(
|
2014-08-14 01:51:54 +00:00
|
|
|
name,
|
|
|
|
password
|
|
|
|
);
|
2014-08-14 17:25:22 +00:00
|
|
|
console.log("Added '" + name + "'.");
|
|
|
|
console.log("");
|
2014-08-14 01:51:54 +00:00
|
|
|
});
|
2014-08-13 23:43:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
program
|
|
|
|
.command("remove-user <name>")
|
|
|
|
.description("Remove an existing user")
|
|
|
|
.action(function(name) {
|
|
|
|
var manager = new ClientManager();
|
2014-08-14 17:25:22 +00:00
|
|
|
var success = manager.removeUser(name);
|
|
|
|
console.log("");
|
|
|
|
if (success) {
|
|
|
|
console.log("Removed '" + name + "'.");
|
|
|
|
} else {
|
|
|
|
console.log("User '" + name + "' doesn't exist.");
|
|
|
|
}
|
|
|
|
console.log("");
|
2014-08-13 23:43:11 +00:00
|
|
|
});
|
|
|
|
|
2014-08-05 08:32:25 +00:00
|
|
|
program.parse(process.argv)
|
|
|
|
|
|
|
|
if (!program.args.length) {
|
|
|
|
program.help();
|
|
|
|
}
|