Check permissions for cli commands
This commit is contained in:
parent
8fe9f86423
commit
68922365d5
1020
client/js/chat.js
1020
client/js/chat.js
File diff suppressed because it is too large
Load Diff
37
index.js
37
index.js
@ -6,6 +6,7 @@ var config = require("./config.json");
|
||||
var ClientManager= new require("./src/clientManager");
|
||||
var program = require("commander");
|
||||
var shout = require("./src/server.js");
|
||||
var fs = require("fs");
|
||||
|
||||
program
|
||||
.option("-p, --port <port>")
|
||||
@ -31,22 +32,36 @@ program
|
||||
.description("List all existing users")
|
||||
.action(function() {
|
||||
var users = new ClientManager().getUsers();
|
||||
console.log("");
|
||||
if (!users.length) {
|
||||
console.log("");
|
||||
console.log("No users found!");
|
||||
console.log("");
|
||||
} else {
|
||||
console.log("");
|
||||
console.log("Users:");
|
||||
for (var i = 0; i < users.length; i++) {
|
||||
console.log((i + 1) + ": " + users[i]);
|
||||
}
|
||||
console.log("");
|
||||
}
|
||||
console.log("");
|
||||
});
|
||||
|
||||
program
|
||||
.command("add-user <name>")
|
||||
.description("Add a new user")
|
||||
.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 users = manager.getUsers();
|
||||
if (users.indexOf(name) !== -1) {
|
||||
@ -75,15 +90,29 @@ program
|
||||
.command("remove-user <name>")
|
||||
.description("Remove an existing user")
|
||||
.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 success = manager.removeUser(name);
|
||||
console.log("");
|
||||
if (success) {
|
||||
console.log("");
|
||||
console.log("Removed '" + name + "'.");
|
||||
console.log("");
|
||||
} else {
|
||||
console.log("");
|
||||
console.log("User '" + name + "' doesn't exist.");
|
||||
console.log("");
|
||||
}
|
||||
console.log("");
|
||||
});
|
||||
|
||||
program.parse(process.argv)
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "shout",
|
||||
"description": "A web IRC client",
|
||||
"version": "0.9.9",
|
||||
"version": "0.9.10",
|
||||
"author": "Mattias Erming",
|
||||
"preferGlobal": true,
|
||||
"bin": {
|
||||
|
Loading…
Reference in New Issue
Block a user