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 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("");
|
||||||
console.log("Removed '" + name + "'.");
|
console.log("Removed '" + name + "'.");
|
||||||
|
console.log("");
|
||||||
} else {
|
} else {
|
||||||
|
console.log("");
|
||||||
console.log("User '" + name + "' doesn't exist.");
|
console.log("User '" + name + "' doesn't exist.");
|
||||||
|
console.log("");
|
||||||
}
|
}
|
||||||
console.log("");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
program.parse(process.argv)
|
program.parse(process.argv)
|
||||||
|
@ -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": {
|
||||||
|
Loading…
Reference in New Issue
Block a user