summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client')
-rw-r--r--src/Client/CommandParser.cpp5
-rw-r--r--src/Client/UserCommands.cpp97
-rw-r--r--src/Client/UserCommands.h4
3 files changed, 105 insertions, 1 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index 838c831..b06f4b4 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -47,9 +47,12 @@ const CommandParser::Command CommandParser::commands[] = {
{{"user_info", "user", 0}, "user_info uid|name", "Search for a user id", "Search for a user.", &UserCommands::userInfoCommand},
{{"list_groups", "groups", 0}, "list_groups", "Show the user group database", "Show the user group database.", &UserCommands::listGroupsCommand},
{{"group_info", "group", 0}, "group_info gid|name", "Search for a group id", "Search for a group.", &UserCommands::groupInfoCommand},
- {{"add_user", 0}, "add_user uid gid username full_name", "Add a new user", "Add a new user with the given info to the account database.", &UserCommands::addUserCommand},
+ {{"add_user", 0}, "add_user uid gid username full_name", "Add a new user", "Add a new user with the given information to the account database.", &UserCommands::addUserCommand},
{{"update_user", 0}, "update_user uid new_uid gid username full_name", "Update a user", "Update user data in the account database.", &UserCommands::updateUserCommand},
{{"delete_user", 0}, "delete_user uid", "Delete user", "Delete a user from the account database.", &UserCommands::deleteUserCommand},
+ {{"add_group", 0}, "add_group gid name", "Add a new group", "Add a new user group with the given name to the account database.", &UserCommands::addGroupCommand},
+ {{"update_group", 0}, "update_group gid new_gid name", "Update a group", "Update group data in the account database.", &UserCommands::updateGroupCommand},
+ {{"delete_group", 0}, "delete_group did", "Delete group", "Delete a user group from the account database.", &UserCommands::deleteGroupCommand},
{{"add_user_to_group", 0}, "add_user_to_group uid gid", "Add a user to a group", "Add a user to a group.", &UserCommands::addUserToGroupCommand},
{{"delete_user_from_group", 0}, "delete_user_from_group uid gid", "Remove a user from a group", "Remove a user from a group.", &UserCommands::deleteUserFromGroupCommand},
{{"exit", "quit", 0}, "exit", "Close the connection and quit the client", "Close the connection and quit the client.", &CommandParser::exitCommand},
diff --git a/src/Client/UserCommands.cpp b/src/Client/UserCommands.cpp
index 43131c7..b93de94 100644
--- a/src/Client/UserCommands.cpp
+++ b/src/Client/UserCommands.cpp
@@ -320,6 +320,103 @@ void UserCommands::deleteUserCommand(CommandParser *commandParser, const std::ve
}
}
+void UserCommands::addGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
+ if(args.size() < 3) {
+ std::cerr << args[0] << ": Too few arguments." << std::endl;
+ commandParser->printUsage("add_group");
+ return;
+ }
+ if(args.size() > 3) {
+ std::cerr << args[0] << ": Too many arguments." << std::endl;
+ commandParser->printUsage("add_group");
+ return;
+ }
+
+ char *endptr;
+ unsigned long gid = std::strtoul(args[1].c_str(), &endptr, 10);
+ if(args[2].empty() || *endptr != '\0') {
+ std::cerr << args[0] << ": Unable to parse group id." << std::endl;
+ commandParser->printUsage("add_group");
+ return;
+ }
+
+ try {
+ commandParser->application->getUserManager()->addGroup(Common::GroupInfo(gid, args[2]));
+
+ std::cout << "Group added." << std::endl;
+ }
+ catch(Core::Exception e) {
+ std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl;
+ }
+}
+
+void UserCommands::updateGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
+ if(args.size() < 4) {
+ std::cerr << args[0] << ": Too few arguments." << std::endl;
+ commandParser->printUsage("update_group");
+ return;
+ }
+ if(args.size() > 4) {
+ std::cerr << args[0] << ": Too many arguments." << std::endl;
+ commandParser->printUsage("update_group");
+ return;
+ }
+
+ char *endptr;
+ unsigned long origGid = std::strtoul(args[1].c_str(), &endptr, 10);
+ if(args[1].empty() || *endptr != '\0') {
+ std::cerr << args[0] << ": Unable to parse the old group id." << std::endl;
+ commandParser->printUsage("update_group");
+ return;
+ }
+
+ unsigned long gid = std::strtoul(args[2].c_str(), &endptr, 10);
+ if(args[2].empty() || *endptr != '\0') {
+ std::cerr << args[0] << ": Unable to parse the new group id." << std::endl;
+ commandParser->printUsage("update_group");
+ return;
+ }
+
+ try {
+ commandParser->application->getUserManager()->updateGroup(origGid, Common::GroupInfo(gid, args[3]));
+
+ std::cout << "Group updated." << std::endl;
+ }
+ catch(Core::Exception e) {
+ std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl;
+ }
+}
+
+void UserCommands::deleteGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
+ if(args.size() < 2) {
+ std::cerr << args[0] << ": No group id given." << std::endl;
+ commandParser->printUsage("delete_group");
+ return;
+ }
+ if(args.size() > 2) {
+ std::cerr << args[0] << ": Too many arguments." << std::endl;
+ commandParser->printUsage("delete_group");
+ return;
+ }
+
+ char *endptr;
+ unsigned long gid = std::strtoul(args[1].c_str(), &endptr, 10);
+ if(args[1].empty() || *endptr != '\0') {
+ std::cerr << args[0] << ": Unable to parse group id." << std::endl;
+ commandParser->printUsage("delete_group");
+ return;
+ }
+
+ try {
+ commandParser->application->getUserManager()->deleteGroup(gid);
+
+ std::cout << "Group deleted." << std::endl;
+ }
+ catch(Core::Exception e) {
+ std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl;
+ }
+}
+
void UserCommands::addUserToGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
if(args.size() < 3) {
std::cerr << args[0] << ": Too few arguments." << std::endl;
diff --git a/src/Client/UserCommands.h b/src/Client/UserCommands.h
index d5793fa..62d42c1 100644
--- a/src/Client/UserCommands.h
+++ b/src/Client/UserCommands.h
@@ -46,6 +46,10 @@ class UserCommands {
static void updateUserCommand(CommandParser *commandParser, const std::vector<std::string> &args);
static void deleteUserCommand(CommandParser *commandParser, const std::vector<std::string> &args);
+ static void addGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args);
+ static void updateGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args);
+ static void deleteGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args);
+
static void addUserToGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args);
static void deleteUserFromGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args);
};