From 04363ca342914ba75e693edb876cbe535839fa79 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 13 Feb 2009 00:00:05 +0100 Subject: Einfache Abfrage der Benutzerdatenbank implementiert --- src/Client/CommandManager.cpp | 26 ++++++++++++++++++++++++++ src/Client/CommandManager.h | 2 ++ src/Client/CommandParser.cpp | 22 +++++++++++++++------- src/Client/CommandParser.h | 1 + src/Client/Makefile.in | 9 +++++---- src/Client/Requests/Makefile.in | 9 +++++---- 6 files changed, 54 insertions(+), 15 deletions(-) (limited to 'src/Client') diff --git a/src/Client/CommandManager.cpp b/src/Client/CommandManager.cpp index 4b24782..aacf939 100644 --- a/src/Client/CommandManager.cpp +++ b/src/Client/CommandManager.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -205,5 +206,30 @@ void CommandManager::statusRequestFinished(const Common::Request &request) { + try { + const Net::Packets::UserListPacket &packet = request.getResult(); + + const std::vector &users = packet.getUserInfo(); + + if(users.empty()) { + std::cout << "User list is empty." << std::endl; + } + else { + std::cout << "Found " << packet.getUserInfo().size() << " users:" << std::endl; + + for(std::vector::const_iterator user = users.begin(); user != users.end(); ++user) + std::cout << " " << user->getUid() << ", " << user->getGid() << ", " << user->getUsername() << ", " << user->getFullName() << std::endl; + } + + std::cout << std::endl; + } + catch(Common::Exception &exception) { + Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.", exception.strerror().c_str()); + } + + requestFinished(); +} + } } diff --git a/src/Client/CommandManager.h b/src/Client/CommandManager.h index ef20e8a..454c77e 100644 --- a/src/Client/CommandManager.h +++ b/src/Client/CommandManager.h @@ -29,6 +29,7 @@ namespace Packets { class FSInfoPacket; class HostStatusPacket; class HostListPacket; +class UserListPacket; } } @@ -61,6 +62,7 @@ class CommandManager { void disconnectRequestFinished(const Common::Request<> &request); void fsInfoRequestFinished(const Common::Request &request); void statusRequestFinished(const Common::Request &request); + void userListRequestFinished(const Common::Request &request); CommandManager() : activeRequests(0), disconnect(false) {} diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp index efc9c4b..304a2ff 100644 --- a/src/Client/CommandParser.cpp +++ b/src/Client/CommandParser.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -40,13 +41,14 @@ namespace Mad { namespace Client { const CommandParser::Command CommandParser::commands[] = { - {{"fsinfo", 0}, "fsinfo [host]", "Displays file system usage information", "Displays file system usage information of a host or the server (if no host is given).", &CommandParser::fsinfoCommand}, - {{"help", "?", 0}, "help [command]", "Displays usage information about commands", "Displays usage information about a command. If no command is given, a list of all available commands is displayed.", &CommandParser::helpCommand}, - {{"list_hosts", "hosts", 0}, "list_hosts [-a]", "Lists the currently active hosts", "Lists the currently active hosts.\n\n -a\tAlso list inactive hosts", &CommandParser::listHostsCommand}, - {{"reboot", 0}, "reboot *|host...", "Reboots host", "Reboots hosts. * will reboot all hosts.", &CommandParser::rebootCommand}, - {{"shutdown", "halt", 0}, "shutdown *|host...", "Shuts hosts down", "Shuts hosts down. * will shut down all hosts.", &CommandParser::shutdownCommand}, - {{"status", "st", 0}, "status [host]", "Displays status information", "Displays host status information. If no host is given, server status information is displayed.", &CommandParser::statusCommand}, - {{"exit", "quit", 0}, "exit", "Closes the connection and quits the client", "Closes the connection and quits the client.", &CommandParser::exitCommand}, + {{"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).", &CommandParser::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}, + {{"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.", &CommandParser::rebootCommand}, + {{"shutdown", "halt", 0}, "shutdown *|host...", "Shut hosts down", "Shut hosts down. * will shut down all hosts.", &CommandParser::shutdownCommand}, + {{"status", "st", 0}, "status [host]", "Display status information", "Display host status information. If no host is given, display server status information.", &CommandParser::statusCommand}, + {{"list_users", "users", 0}, "list_users", "Show the user account database", "Show the user account database.", &CommandParser::listUsersCommand}, + {{"exit", "quit", 0}, "exit", "Close the connection and quit the client", "Closes the connection and quits the client.", &CommandParser::exitCommand}, {{0}, 0, 0, 0, 0} }; @@ -253,6 +255,12 @@ void CommandParser::statusCommand(const std::vector &args) { ++CommandManager::get()->activeRequests; } +void CommandParser::listUsersCommand(const std::vector&) { + ++CommandManager::get()->activeRequests; + + Common::RequestManager::get()->sendRequest(connection, std::auto_ptr(new Common::Requests::UserListRequest(sigc::mem_fun(CommandManager::get(), &CommandManager::userListRequestFinished)))); +} + void CommandParser::exitCommand(const std::vector&) { ++CommandManager::get()->activeRequests; diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h index e01449a..de65788 100644 --- a/src/Client/CommandParser.h +++ b/src/Client/CommandParser.h @@ -66,6 +66,7 @@ class CommandParser { void rebootCommand(const std::vector &args); void shutdownCommand(const std::vector &args); void statusCommand(const std::vector &args); + void listUsersCommand(const std::vector &args); void exitCommand(const std::vector&); CommandParser() : connection(0) {} diff --git a/src/Client/Makefile.in b/src/Client/Makefile.in index 3d3ddda..20f85ee 100644 --- a/src/Client/Makefile.in +++ b/src/Client/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.10.1 from Makefile.am. +# Makefile.in generated by automake 1.10.2 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, @@ -221,6 +221,7 @@ srcdir = @srcdir@ sys_symbol_underscore = @sys_symbol_underscore@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ SUBDIRS = Requests @@ -236,8 +237,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ - && exit 0; \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ @@ -385,7 +386,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ - $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ mkid -fID $$unique tags: TAGS diff --git a/src/Client/Requests/Makefile.in b/src/Client/Requests/Makefile.in index bba3c7f..842713e 100644 --- a/src/Client/Requests/Makefile.in +++ b/src/Client/Requests/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.10.1 from Makefile.am. +# Makefile.in generated by automake 1.10.2 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, @@ -212,6 +212,7 @@ srcdir = @srcdir@ sys_symbol_underscore = @sys_symbol_underscore@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LTLIBRARIES = librequests.la @@ -225,8 +226,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ - && exit 0; \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ @@ -305,7 +306,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ - $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ mkid -fID $$unique tags: TAGS -- cgit v1.2.3