summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-09-23 14:20:58 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-09-23 14:20:58 +0200
commit26c1290391eb5540d6e2c5f6eceb877e0075d087 (patch)
tree6a9864d545aa83c4574931eedaf7f37691b6aa32
parent0eddc28a331437ef95a60418ed1fc6de4e9b63c1 (diff)
downloadmad-26c1290391eb5540d6e2c5f6eceb877e0075d087.tar
mad-26c1290391eb5540d6e2c5f6eceb877e0075d087.zip
Client: UserListManager client
-rw-r--r--src/Client/CMakeLists.txt5
-rw-r--r--src/Client/CommandParser.cpp4
-rw-r--r--src/Client/CommandParser.h4
-rw-r--r--src/Client/Requests/DaemonListRequest.h2
-rw-r--r--src/Client/Requests/UserLists/UserListDiffListRequest.h43
-rw-r--r--src/Client/Requests/UserLists/UserListDownloadRequest.cpp38
-rw-r--r--src/Client/Requests/UserLists/UserListDownloadRequest.h50
-rw-r--r--src/Client/Requests/UserLists/UserListListRequest.h43
-rw-r--r--src/Client/UserListCommands.cpp198
-rw-r--r--src/Client/UserListCommands.h52
10 files changed, 435 insertions, 4 deletions
diff --git a/src/Client/CMakeLists.txt b/src/Client/CMakeLists.txt
index cb2611d..4e83c4e 100644
--- a/src/Client/CMakeLists.txt
+++ b/src/Client/CMakeLists.txt
@@ -11,11 +11,16 @@ mad_library(Client
Requests/DaemonListRequest.h
Requests/DaemonStatusRequest.h Requests/DaemonStatusRequest.cpp
+ Requests/UserLists/UserListListRequest.h
+ Requests/UserLists/UserListDownloadRequest.h Requests/UserLists/UserListDownloadRequest.cpp
+ Requests/UserLists/UserListDiffListRequest.h
+
Application.cpp Application.h
CommandParser.cpp CommandParser.h
InformationManager.cpp InformationManager.h
PasswordReader.cpp PasswordReader.h
SystemCommands.cpp SystemCommands.h
UserCommands.cpp UserCommands.h
+ UserListCommands.cpp UserListCommands.h
)
target_link_libraries(Client Common Net Core)
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index d93b432..3f1850c 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -22,6 +22,7 @@
#include "InformationManager.h"
#include "SystemCommands.h"
#include "UserCommands.h"
+#include "UserListCommands.h"
#include <Core/Tokenizer.h>
@@ -37,8 +38,8 @@ namespace Mad {
namespace Client {
const CommandParser::Command CommandParser::commands[] = {
- {{"fsinfo", 0}, "fsinfo [host]", "Display file system usage information", "Display file system usage information of a host or the server (if no host is given).", &SystemCommands::fsinfoCommand},
{{"help", "?", 0}, "help [command]", "Display usage information about commands", "Display usage information about a command. If no command is given, display a list of all available commands.", &CommandParser::helpCommand},
+ {{"fsinfo", 0}, "fsinfo [host]", "Display file system usage information", "Display file system usage information of a host or the server (if no host is given).", &SystemCommands::fsinfoCommand},
{{"list_hosts", "hosts", 0}, "list_hosts [-a]", "List the currently active hosts", "List the currently active hosts.\n\n -a\tAlso list inactive hosts", &CommandParser::listHostsCommand},
{{"reboot", 0}, "reboot *|host...", "Reboot host", "Reboot hosts. * will reboot all hosts.", &SystemCommands::rebootCommand},
{{"shutdown", "halt", 0}, "shutdown *|host...", "Shut hosts down", "Shut hosts down. * will shut down all hosts.", &SystemCommands::shutdownCommand},
@@ -56,6 +57,7 @@ const CommandParser::Command CommandParser::commands[] = {
{{"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},
{{"set_password", "password", 0}, "set_password uid", "Set the password of a user", "Set the password of a user.", &UserCommands::setPasswordCommand},
+ {{"user_lists", "ul", 0}, "user_lists command [args]", "Perform user list commands", "Perform user list commands. Type 'user_lists help' for more information.", &UserListCommands::userListCommand},
{{"exit", "quit", 0}, "exit", "Close the connection and quit the client", "Close the connection and quit the client.", &CommandParser::exitCommand},
{{0}, 0, 0, 0, 0}
};
diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h
index 8077a30..c4a0f79 100644
--- a/src/Client/CommandParser.h
+++ b/src/Client/CommandParser.h
@@ -43,11 +43,13 @@ namespace Client {
class Application;
class SystemCommands;
class UserCommands;
+class UserListCommands;
class MAD_CLIENT_EXPORT CommandParser {
private:
friend class SystemCommands;
friend class UserCommands;
+ friend class UserListCommands;
struct Command {
const char* commands[3];
@@ -68,7 +70,7 @@ class MAD_CLIENT_EXPORT CommandParser {
static const Command* findCommand(const std::string& command);
- void printUsage(const std::string& command);
+ static void printUsage(const std::string& command);
std::map<std::string, Common::HostInfo> parseHostList(const std::vector<std::string> &args, bool mustBeActive = false);
void helpCommand(const std::vector<std::string> &args);
diff --git a/src/Client/Requests/DaemonListRequest.h b/src/Client/Requests/DaemonListRequest.h
index 85fc4e1..76f85cd 100644
--- a/src/Client/Requests/DaemonListRequest.h
+++ b/src/Client/Requests/DaemonListRequest.h
@@ -20,8 +20,6 @@
#ifndef MAD_CLIENT_REQUEST_DAEMONLISTREQUEST_H_
#define MAD_CLIENT_REQUEST_DAEMONLISTREQUEST_H_
-#include "../export.h"
-
#include <Common/Requests/SimpleRequest.h>
namespace Mad {
diff --git a/src/Client/Requests/UserLists/UserListDiffListRequest.h b/src/Client/Requests/UserLists/UserListDiffListRequest.h
new file mode 100644
index 0000000..54831c1
--- /dev/null
+++ b/src/Client/Requests/UserLists/UserListDiffListRequest.h
@@ -0,0 +1,43 @@
+/*
+ * UserListDiffListRequest.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_CLIENT_USERLISTS_USERLISTDIFFLISTREQUEST_H_
+#define MAD_CLIENT_USERLISTS_USERLISTDIFFLISTREQUEST_H_
+
+#include <Common/Requests/SimpleRequest.h>
+
+namespace Mad {
+namespace Client {
+namespace Requests {
+namespace UserLists {
+
+class UserListDiffListRequest : public Common::Requests::SimpleRequest {
+ public:
+ UserListDiffListRequest(Common::Application *application) : SimpleRequest(application, "ListUserListDiffs") {}
+};
+
+}
+
+}
+
+}
+
+}
+
+#endif /* MAD_CLIENT_USERLISTS_USERLISTDIFFLISTREQUEST_H_ */
diff --git a/src/Client/Requests/UserLists/UserListDownloadRequest.cpp b/src/Client/Requests/UserLists/UserListDownloadRequest.cpp
new file mode 100644
index 0000000..8e31fce
--- /dev/null
+++ b/src/Client/Requests/UserLists/UserListDownloadRequest.cpp
@@ -0,0 +1,38 @@
+/*
+ * UserListDownloadRequest.cpp
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "UserListDownloadRequest.h"
+
+namespace Mad {
+namespace Client {
+namespace Requests {
+namespace UserLists {
+
+void UserListDownloadRequest::sendRequest() {
+ Common::XmlData packet;
+ packet.setType("DownloadUserList");
+ packet.set("name", name);
+
+ sendPacket(packet);
+}
+
+}
+}
+}
+}
diff --git a/src/Client/Requests/UserLists/UserListDownloadRequest.h b/src/Client/Requests/UserLists/UserListDownloadRequest.h
new file mode 100644
index 0000000..570899f
--- /dev/null
+++ b/src/Client/Requests/UserLists/UserListDownloadRequest.h
@@ -0,0 +1,50 @@
+/*
+ * UserListDownloadRequest.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_CLIENT_REQUESTS_USERLISTS_USERLISTDOWNLOADREQUEST_H_
+#define MAD_CLIENT_REQUESTS_USERLISTS_USERLISTDOWNLOADREQUEST_H_
+
+#include <Common/Request.h>
+
+namespace Mad {
+namespace Client {
+namespace Requests {
+namespace UserLists {
+
+class UserListDownloadRequest : public Common::Request {
+ private:
+ std::string name;
+
+ protected:
+ virtual void sendRequest();
+
+ public:
+ UserListDownloadRequest(Common::Application *application, const std::string &name0)
+ : Common::Request(application), name(name0) {}
+};
+
+}
+
+}
+
+}
+
+}
+
+#endif /* MAD_CLIENT_REQUESTS_USERLISTS_USERLISTDOWNLOADREQUEST_H_ */
diff --git a/src/Client/Requests/UserLists/UserListListRequest.h b/src/Client/Requests/UserLists/UserListListRequest.h
new file mode 100644
index 0000000..805142a
--- /dev/null
+++ b/src/Client/Requests/UserLists/UserListListRequest.h
@@ -0,0 +1,43 @@
+/*
+ * UserListListRequest.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_CLIENT_USERLISTS_USERLISTLISTREQUEST_H_
+#define MAD_CLIENT_USERLISTS_USERLISTLISTREQUEST_H_
+
+#include <Common/Requests/SimpleRequest.h>
+
+namespace Mad {
+namespace Client {
+namespace Requests {
+namespace UserLists {
+
+class UserListListRequest : public Common::Requests::SimpleRequest {
+ public:
+ UserListListRequest(Common::Application *application) : SimpleRequest(application, "ListUserLists") {}
+};
+
+}
+
+}
+
+}
+
+}
+
+#endif /* MAD_CLIENT_USERLISTS_USERLISTLISTREQUEST_H_ */
diff --git a/src/Client/UserListCommands.cpp b/src/Client/UserListCommands.cpp
new file mode 100644
index 0000000..eb4aee1
--- /dev/null
+++ b/src/Client/UserListCommands.cpp
@@ -0,0 +1,198 @@
+/*
+ * UserListCommands.cpp
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "UserListCommands.h"
+#include "Application.h"
+#include "Requests/UserLists/UserListListRequest.h"
+#include "Requests/UserLists/UserListDownloadRequest.h"
+#include "Requests/UserLists/UserListDiffListRequest.h"
+
+#include <Common/RequestManager.h>
+#include <Common/UserLists/UserList.h>
+#include <Common/UserLists/Util.h>
+
+#include <iostream>
+
+namespace Mad {
+namespace Client {
+
+const UserListCommands::Command UserListCommands::commands[] = {
+ {{"help", "?", 0}, "help [command]", "Display usage information about user list commands", "Display usage information about a user list command. If no command is given, display a list of all available user list commands.", &UserListCommands::helpCommand},
+ {{"list", "ls", 0}, "list", "List the stored user lists", "List the stored user lists.", &UserListCommands::listCommand},
+ {{"show_list", "sl", 0}, "show_list list", "Displays a user list", "Displays a user list.", &UserListCommands::showListCommand},
+ {{0}, 0, 0, 0, 0}
+};
+
+const UserListCommands::Command* UserListCommands::findCommand(const std::string& command) {
+ for(int i = 0; commands[i].commands[0] != 0; ++i) {
+ for(int j = 0; commands[i].commands[j] != 0; ++j) {
+ if(command == commands[i].commands[j]) {
+ return &commands[i];
+ }
+ }
+ }
+
+ return 0;
+}
+
+void UserListCommands::printUsage(const std::string& command) {
+ const UserListCommands::Command *cmd = findCommand(command);
+
+ if(cmd)
+ std::cerr << "Usage: " << "user_lists " << cmd->cmdline << std::endl;
+}
+
+
+void UserListCommands::helpCommand(CommandParser* /*commandParser*/, const std::vector<std::string> &args) {
+ if(args.size() <= 2) {
+ std::cout << "Available commands:" << std::endl << std::endl;
+
+ for(int i = 0; commands[i].commands[0] != 0; ++i) {
+ std::cout << commands[i].commands[0];
+
+ for(int j = 1; commands[i].commands[j] != 0; ++j)
+ std::cout << ", " << commands[i].commands[j];
+
+ std::cout << std::endl << "\t" << commands[i].desc << std::endl;
+ }
+ }
+ else if(args.size() == 3) {
+ const Command* command = findCommand(args[2]);
+
+ if(command) {
+ std::cout << "Usage: " << "user_lists " << command->cmdline << std::endl << std::endl;
+ std::cout << command->longdesc << std::endl << std::endl;
+ }
+ else
+ std::cerr << args[0] << " " << args[1] << ": Command '" << args[2] << "' doesn't exist." << std::endl;
+ }
+ else {
+ std::cerr << args[0] << " " << args[1] << ": Too many arguments." << std::endl;
+ printUsage("help");
+ }
+}
+
+void UserListCommands::listCommand(CommandParser *commandParser, const std::vector<std::string>& /*args*/) {
+ boost::shared_ptr<Requests::UserLists::UserListListRequest> userListRequest(new Requests::UserLists::UserListListRequest(commandParser->application));
+ boost::shared_ptr<Requests::UserLists::UserListDiffListRequest> userListDiffRequest(new Requests::UserLists::UserListDiffListRequest(commandParser->application));
+
+ commandParser->application->getRequestManager()->sendRequest(commandParser->connection, userListRequest);
+ commandParser->application->getRequestManager()->sendRequest(commandParser->connection, userListDiffRequest);
+
+ userListRequest->wait();
+ userListDiffRequest->wait();
+
+ std::pair<boost::shared_ptr<const Common::XmlData>, Core::Exception> userListResult = userListRequest->getResult();
+ std::pair<boost::shared_ptr<const Common::XmlData>, Core::Exception> userListDiffResult = userListDiffRequest->getResult();
+
+ if(userListResult.second) {
+ std::cerr << "An error occurred during your request: " << userListResult.second.what() << "." << std::endl;
+ return;
+ }
+ else if(!userListResult.first || !userListDiffResult.first || userListDiffResult.second) {
+ std::cerr << "An error occurred during your request: " << userListDiffResult.second.what() << "." << std::endl;
+ return;
+ }
+
+ const Common::XmlData::List *userLists = userListResult.first->getList("userLists");
+ const Common::XmlData::List *userListDiffs = userListDiffResult.first->getList("userListDiffs");
+
+ if(userLists->isEmpty()) {
+ std::cout << "There aren't any user lists stored on the server." << std::endl;
+ }
+ else {
+ if(userLists->getSize() == 1)
+ std::cout << "There is 1 user list stored on the server:" << std::endl;
+ else
+ std::cout << "There are " << userLists->getSize() << " user lists stored on the server:" << std::endl;
+
+ for(Common::XmlData::List::const_iterator userList = userLists->begin(); userList != userLists->end(); ++userList) {
+ std::cout << " " << userList->get<const std::string&>("name") << std::endl;
+ }
+ }
+
+ std::cout << std::endl;
+
+ if(!userListDiffs->isEmpty()) {
+ if(userListDiffs->getSize() == 1)
+ std::cout << "There is 1 user list difference record stored on the server:" << std::endl;
+ else
+ std::cout << "There are " << userListDiffs->getSize() << " user list difference records stored on the server:" << std::endl;
+
+ for(Common::XmlData::List::const_iterator diff = userListDiffs->begin(); diff != userListDiffs->end(); ++diff) {
+ std::cout << " " << diff->get<const std::string&>("name") << std::endl;
+ }
+ }
+}
+
+void UserListCommands::showListCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
+ if(args.size() < 3) {
+ std::cerr << args[0] << " " << args[1] << ": No list name given." << std::endl;
+ printUsage("show_list");
+ return;
+ }
+ else if(args.size() == 3) {
+ boost::shared_ptr<Requests::UserLists::UserListDownloadRequest> request(
+ new Requests::UserLists::UserListDownloadRequest(commandParser->application, args[2]));
+ commandParser->application->getRequestManager()->sendRequest(commandParser->connection, request);
+ request->wait();
+
+ std::pair<boost::shared_ptr<const Common::XmlData>, Core::Exception> result = request->getResult();
+
+ if(!result.first || result.second) {
+ std::cerr << "An error occurred during your request: " << result.second.what() << "." << std::endl;
+ return;
+ }
+
+ boost::shared_ptr<Common::UserLists::UserList> userList = Common::UserLists::Util::deserializeUserList(result.first.get());
+
+ std::cout << "User list '" << args[2] << "':" << std::endl;
+
+ for(Common::UserLists::UserList::iterator user = userList->begin(); user != userList->end(); ++user) {
+ std::cout << " " << user->getName() << std::endl;
+ }
+
+ std::cout << std::endl;
+ }
+ else {
+ std::cerr << args[0] << " " << args[1] << ": Too many arguments." << std::endl;
+ printUsage("show_list");
+ return;
+ }
+}
+
+
+void UserListCommands::userListCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
+ std::string cmd;
+
+ if(args.size() < 2)
+ cmd = "help";
+ else
+ cmd = args[1];
+
+ const Command* command = findCommand(cmd);
+
+ if(command)
+ command->function(commandParser, args);
+ else
+ std::cerr << args[0] << ": Unknown command '" << cmd << "'." << std::endl;
+}
+
+}
+}
diff --git a/src/Client/UserListCommands.h b/src/Client/UserListCommands.h
new file mode 100644
index 0000000..17fcb4e
--- /dev/null
+++ b/src/Client/UserListCommands.h
@@ -0,0 +1,52 @@
+/*
+ * UserListCommands.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_CLIENT_USERLISTCOMMANDS_H_
+#define MAD_CLIENT_USERLISTCOMMANDS_H_
+
+#include "export.h"
+
+#include "CommandParser.h"
+
+namespace Mad {
+namespace Client {
+
+class MAD_CLIENT_EXPORT UserListCommands {
+ private:
+ typedef CommandParser::Command Command;
+
+ static const Command commands[];
+
+ UserListCommands();
+
+ static const Command* findCommand(const std::string& command);
+ static void printUsage(const std::string& command);
+
+ static void helpCommand(CommandParser *commandParser, const std::vector<std::string> &args);
+ static void listCommand(CommandParser *commandParser, const std::vector<std::string> &args);
+ static void showListCommand(CommandParser *commandParser, const std::vector<std::string> &args);
+
+ public:
+ static void userListCommand(CommandParser *commandParser, const std::vector<std::string> &args);
+};
+
+}
+}
+
+#endif /* MAD_CLIENT_USERLISTCOMMANDS_H_ */