Check permissions for cli commands

This commit is contained in:
Mattias Erming 2014-08-16 09:15:17 -07:00
parent 8fe9f86423
commit 68922365d5
3 changed files with 544 additions and 515 deletions

View File

@ -306,7 +306,7 @@ $(function() {
.sticky() .sticky()
.end(); .end();
if (chan.hasClass("chan")) { if (screen.width > 768 && chan.hasClass("chan")) {
input.focus(); input.focus();
} }
}); });

View File

@ -6,6 +6,7 @@ var config = require("./config.json");
var ClientManager= new require("./src/clientManager"); var ClientManager= new require("./src/clientManager");
var program = require("commander"); var program = require("commander");
var shout = require("./src/server.js"); var shout = require("./src/server.js");
var fs = require("fs");
program program
.option("-p, --port <port>") .option("-p, --port <port>")
@ -31,22 +32,36 @@ program
.description("List all existing users") .description("List all existing users")
.action(function() { .action(function() {
var users = new ClientManager().getUsers(); var users = new ClientManager().getUsers();
console.log("");
if (!users.length) { if (!users.length) {
console.log("");
console.log("No users found!"); console.log("No users found!");
console.log("");
} else { } else {
console.log("");
console.log("Users:"); console.log("Users:");
for (var i = 0; i < users.length; i++) { for (var i = 0; i < users.length; i++) {
console.log((i + 1) + ": " + users[i]); console.log((i + 1) + ": " + users[i]);
} }
}
console.log(""); console.log("");
}
}); });
program program
.command("add-user <name>") .command("add-user <name>")
.description("Add a new user") .description("Add a new user")
.action(function(name) { .action(function(name) {
try {
var path = __dirname + "/users";
var test = path + "/.test";
fs.mkdirSync(test);
fs.rmdirSync(test);
} catch (e) {
console.log("");
console.log("You have no permissions to write to " + path);
console.log("Try running the command as sudo.");
console.log("");
return;
}
var manager = new ClientManager(); var manager = new ClientManager();
var users = manager.getUsers(); var users = manager.getUsers();
if (users.indexOf(name) !== -1) { if (users.indexOf(name) !== -1) {
@ -75,15 +90,29 @@ program
.command("remove-user <name>") .command("remove-user <name>")
.description("Remove an existing user") .description("Remove an existing user")
.action(function(name) { .action(function(name) {
try {
var path = __dirname + "/users";
var test = path + "/.test";
fs.mkdirSync(test);
fs.rmdirSync(test);
} catch (e) {
console.log("");
console.log("You have no permissions to delete from " + path);
console.log("Try running the command as sudo.");
console.log("");
return;
}
var manager = new ClientManager(); var manager = new ClientManager();
var success = manager.removeUser(name); var success = manager.removeUser(name);
console.log("");
if (success) { if (success) {
console.log("Removed '" + name + "'.");
} else {
console.log("User '" + name + "' doesn't exist.");
}
console.log(""); console.log("");
console.log("Removed '" + name + "'.");
console.log("");
} else {
console.log("");
console.log("User '" + name + "' doesn't exist.");
console.log("");
}
}); });
program.parse(process.argv) program.parse(process.argv)

View File

@ -1,7 +1,7 @@
{ {
"name": "shout", "name": "shout",
"description": "A web IRC client", "description": "A web IRC client",
"version": "0.9.9", "version": "0.9.10",
"author": "Mattias Erming", "author": "Mattias Erming",
"preferGlobal": true, "preferGlobal": true,
"bin": { "bin": {