summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client')
-rw-r--r--src/Client/CommandParser.cpp2
-rw-r--r--src/Client/UserCommands.cpp136
-rw-r--r--src/Client/UserCommands.h5
3 files changed, 61 insertions, 82 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index 644a392..b81d6df 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -47,10 +47,8 @@ const CommandParser::Command CommandParser::commands[] = {
{{"status", "st", 0}, "status [host]", "Display status information", "Display host status information. If no host is given, display server status information.", &SystemCommands::statusCommand},
{{"list_users", "users", 0}, "list_users", "Show the user account database", "Show the user account database.", &UserCommands::listUsersCommand},
{{"user_info", "user", 0}, "user_info uid|name", "Search for a user id", "Search for a user.", &UserCommands::userInfoCommand},
- {{"list_user_groups", "user_groups", 0}, "list_user_groups uid", "List user's groups", "List the groups that the user is member of.", &UserCommands::listUserGroupsCommand},
{{"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},
- {{"list_group_users", "group_users", 0}, "list_group_users gid", "List group's users", "List the users that are members of the group.", &UserCommands::listGroupUsersCommand},
{{"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},
{{"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},
diff --git a/src/Client/UserCommands.cpp b/src/Client/UserCommands.cpp
index d58eaca..cd2ff5a 100644
--- a/src/Client/UserCommands.cpp
+++ b/src/Client/UserCommands.cpp
@@ -33,19 +33,58 @@
namespace Mad {
namespace Client {
+std::string UserCommands::getUserName(CommandParser *commandParser, unsigned long uid, bool withId) {
+ std::ostringstream stream;
+
+ try {
+ stream << commandParser->application->getUserManager()->getUserInfo(uid)->getUsername();
+ }
+ catch(...) {
+ stream << uid;
+ }
+
+ if(withId) {
+ stream << " (";
+ stream << uid;
+ stream << ")";
+ }
+
+ return stream.str();
+}
+
+std::string UserCommands::getGroupName(CommandParser *commandParser, unsigned long gid, bool withId) {
+ std::ostringstream stream;
+
+ try {
+ stream << commandParser->application->getUserManager()->getGroupInfo(gid)->getName();
+ }
+ catch(...) {
+ stream << gid;
+ }
+
+ if(withId) {
+ stream << " (";
+ stream << gid;
+ stream << ")";
+ }
+
+ return stream.str();
+}
+
void UserCommands::listUsersCommand(CommandParser *commandParser, const std::vector<std::string> &args _UNUSED_PARAMETER_) {
try {
boost::shared_ptr<const std::map<unsigned long, Common::UserInfo> > users = commandParser->application->getUserManager()->getUserList();
if(users->empty()) {
- std::cout << "User list is empty." << std::endl;
+ std::cout << "The user list is empty." << std::endl;
}
else {
std::cout << "Found " << users->size() << " user" << (users->size()==1 ? "" : "s") << ":" << std::endl;
for(std::map<unsigned long, Common::UserInfo>::const_iterator user = users->begin(); user != users->end(); ++user) {
- std::cout << " " << user->second.getUid() << ", " << user->second.getGid() << ", "
- << user->second.getUsername() << ", " << user->second.getFullName() << std::endl;
+ std::cout << " " << user->second.getUsername() << ":"
+ << getGroupName(commandParser, user->second.getGid(), false) << " ("
+ << user->second.getFullName() << ")" << std::endl;
}
}
@@ -80,49 +119,19 @@ void UserCommands::userInfoCommand(CommandParser *commandParser, const std::vect
else
userInfo = commandParser->application->getUserManager()->getUserInfo(uid);
- std::cout << " " << userInfo->getUid() << ", " << userInfo->getGid() << ", "
- << userInfo->getUsername() << ", " << userInfo->getFullName() << std::endl << std::endl;
- }
- catch(Core::Exception e) {
- std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl;
- }
-}
-
-void UserCommands::listUserGroupsCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
- if(args.size() == 1) {
- std::cerr << args[0] << ": No user id given." << std::endl;
- commandParser->printUsage("list_user_groups");
- return;
- }
- if(args.size() > 2) {
- std::cerr << args[0] << ": Too many arguments." << std::endl;
- commandParser->printUsage("list_user_groups");
- return;
- }
+ std::cout << " User name: " << userInfo->getUsername() << " (" << userInfo->getUid() << ")" << std::endl;
+ std::cout << " Group: " << getGroupName(commandParser, userInfo->getGid(), true) << std::endl;
+ std::cout << " Full name: " << userInfo->getFullName() << std::endl << std::endl;
- char *endptr;
- unsigned long uid = std::strtoul(args[1].c_str(), &endptr, 10);
- if(args[1].empty() || *endptr != '\0') {
- std::cerr << args[0] << ": Unable to parse user id." << std::endl;
- commandParser->printUsage("list_user_groups");
- return;
- }
-
- try {
boost::shared_ptr<const std::set<unsigned long> > groups = commandParser->application->getUserManager()->getUserGroupList(uid);
- if(groups->empty()) {
- std::cout << "The user isn't member of any group." << std::endl;
- }
- else {
- std::cout << "User is member of " << groups->size() << " group" << (groups->size()==1 ? "" : "s") << ":" << std::endl;
-
-
+ if(!groups->empty()) {
+ std::cout << " The user is member of " << groups->size() << " group" << (groups->size()==1 ? "" : "s") << ":" << std::endl;
for(std::set<unsigned long>::const_iterator group = groups->begin(); group != groups->end(); ++group)
- std::cout << " " << *group << std::endl;
- }
+ std::cout << " " << getGroupName(commandParser, *group, true) << std::endl;
- std::cout << std::endl;
+ std::cout << std::endl;
+ }
}
catch(Core::Exception e) {
std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl;
@@ -134,13 +143,13 @@ void UserCommands::listGroupsCommand(CommandParser *commandParser, const std::ve
boost::shared_ptr<const std::map<unsigned long, Common::GroupInfo> > groups = commandParser->application->getUserManager()->getGroupList();
if(groups->empty()) {
- std::cout << "Group list is empty." << std::endl;
+ std::cout << "The group list is empty." << std::endl;
}
else {
std::cout << "Found " << groups->size() << " group" << (groups->size()==1 ? "" : "s") << ":" << std::endl;
for(std::map<unsigned long, Common::GroupInfo>::const_iterator group = groups->begin(); group != groups->end(); ++group) {
- std::cout << " " << group->second.getGid() << ", " << group->second.getName() << std::endl;
+ std::cout << " " << group->second.getName() << " (" << group->second.getGid() << ")" << std::endl;
}
}
@@ -175,48 +184,19 @@ void UserCommands::groupInfoCommand(CommandParser *commandParser, const std::vec
else
groupInfo = commandParser->application->getUserManager()->getGroupInfo(gid);
- std::cout << " " << groupInfo->getGid() << ", " << groupInfo->getName() << std::endl << std::endl;
- }
- catch(Core::Exception e) {
- std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl;
- }
-}
+ std::cout << " Group name: " << groupInfo->getName() << " (" << groupInfo->getGid() << ")" << std::endl << std::endl;
-void UserCommands::listGroupUsersCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
- if(args.size() == 1) {
- std::cerr << args[0] << ": No group id given." << std::endl;
- commandParser->printUsage("list_group_users");
- return;
- }
- if(args.size() > 2) {
- std::cerr << args[0] << ": Too many arguments." << std::endl;
- commandParser->printUsage("list_group_users");
- 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("list_group_users");
- return;
- }
-
- try {
boost::shared_ptr<const std::set<unsigned long> > users = commandParser->application->getUserManager()->getGroupUserList(gid);
- if(users->empty()) {
- std::cout << "The group doesn't have any members." << std::endl;
- }
- else {
- std::cout << "The group has " << users->size() << " member" << (users->size()==1 ? "" : "s") << ":" << std::endl;
+ if(!users->empty()) {
+ std::cout << " The group has " << users->size() << " member" << (users->size()==1 ? "" : "s") << ":" << std::endl;
for(std::set<unsigned long>::const_iterator user = users->begin(); user != users->end(); ++user)
- std::cout << " " << *user << std::endl;
- }
+ std::cout << " " << getUserName(commandParser, *user, true) << std::endl;
- std::cout << std::endl;
+ std::cout << std::endl;
+ }
}
catch(Core::Exception e) {
std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl;
diff --git a/src/Client/UserCommands.h b/src/Client/UserCommands.h
index b62c8e4..d5793fa 100644
--- a/src/Client/UserCommands.h
+++ b/src/Client/UserCommands.h
@@ -32,14 +32,15 @@ class UserCommands {
private:
UserCommands();
+ static std::string getUserName(CommandParser *commandParser, unsigned long uid, bool withId);
+ static std::string getGroupName(CommandParser *commandParser, unsigned long gid, bool withId);
+
public:
static void listUsersCommand(CommandParser *commandParser, const std::vector<std::string> &args);
static void userInfoCommand(CommandParser *commandParser, const std::vector<std::string> &args);
- static void listUserGroupsCommand(CommandParser *commandParser, const std::vector<std::string> &args);
static void listGroupsCommand(CommandParser *commandParser, const std::vector<std::string> &args);
static void groupInfoCommand(CommandParser *commandParser, const std::vector<std::string> &args);
- static void listGroupUsersCommand(CommandParser *commandParser, const std::vector<std::string> &args);
static void addUserCommand(CommandParser *commandParser, const std::vector<std::string> &args);
static void updateUserCommand(CommandParser *commandParser, const std::vector<std::string> &args);