]>
Commit | Line | Data |
---|---|---|
82f09291 | 1 | /** |
2 | * LISTHOSTSCommand.cc | |
3 | * | |
4 | * 12/28/2005 - Reed Loden <reed@reedloden.com> | |
5 | * Initial Version | |
6 | * | |
7 | * Shows all the host entries assigned to an oper | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU General Public License | |
11 | * as published by the Free Software Foundation; either version 2 | |
12 | * of the License, or (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
22 | * USA. | |
23 | * | |
24 | * $Id$ | |
25 | */ | |
26 | ||
27 | #include "gnuworld_config.h" | |
28 | ||
29 | #include "chanfix.h" | |
30 | #include "responses.h" | |
31 | #include "StringTokenizer.h" | |
13a50edb | 32 | #include "sqlcfUser.h" |
82f09291 | 33 | |
34 | RCSTAG("$Id$"); | |
35 | ||
36 | namespace gnuworld | |
37 | { | |
1d54d2a1 | 38 | namespace cf |
39 | { | |
82f09291 | 40 | |
13a50edb | 41 | void LISTHOSTSCommand::Exec(iClient* theClient, sqlcfUser* theUser, const std::string& Message) |
82f09291 | 42 | { |
43 | StringTokenizer st(Message); | |
44 | ||
13a50edb | 45 | sqlcfUser* targetUser; |
82f09291 | 46 | if (st.size() == 2) |
47 | targetUser = bot->isAuthed(st[1]); | |
48 | else | |
49 | targetUser = theUser; | |
50 | ||
51 | if (!targetUser) { | |
52 | bot->SendTo(theClient, | |
53 | bot->getResponse(theUser, | |
54 | language::no_such_user, | |
55 | std::string("No such user %s.")).c_str(), | |
56 | st[1].c_str()); | |
57 | return; | |
58 | } | |
59 | ||
13a50edb | 60 | sqlcfUser::flagType requiredFlags = sqlcfUser::F_USERMANAGER | sqlcfUser::F_SERVERADMIN; |
82f09291 | 61 | if ((targetUser != theUser) && !theUser->getFlag(requiredFlags)) { |
62 | bot->SendTo(theClient, | |
63 | bot->getResponse(theUser, | |
64 | language::requires_auth_and_flags, | |
65 | std::string("This command requires authentication and one of these flags: \"%s\".")).c_str(), | |
66 | bot->getFlagsString(requiredFlags).c_str()); | |
67 | return; | |
68 | } | |
69 | ||
70 | /* A serveradmin can only view hosts of users in his/her own group. */ | |
13a50edb | 71 | if (theUser->getFlag(sqlcfUser::F_SERVERADMIN) && |
72 | !theUser->getFlag(sqlcfUser::F_USERMANAGER)) { | |
82f09291 | 73 | if (targetUser->getGroup() != theUser->getGroup()) { |
74 | bot->SendTo(theClient, | |
75 | bot->getResponse(theUser, | |
76 | language::cant_view_hosts_diff_group, | |
77 | std::string("You cannot view hosts of a user in a different group.")).c_str()); | |
78 | return; | |
79 | } | |
80 | } | |
81 | ||
82 | bot->SendTo(theClient, | |
83 | bot->getResponse(theUser, | |
84 | language::host_list_header, | |
85 | std::string("Host list for %s:")).c_str(), | |
86 | targetUser->getUserName().c_str()); | |
87 | ||
13a50edb | 88 | sqlcfUser::hostListType sqlHostList = targetUser->getHostList(); |
82f09291 | 89 | if (!sqlHostList.empty()) { |
13a50edb | 90 | for (sqlcfUser::hostListType::iterator itr = sqlHostList.begin(); |
82f09291 | 91 | itr != sqlHostList.end(); ++itr) |
92 | bot->SendTo(theClient, *itr); | |
93 | } else { | |
94 | bot->SendTo(theClient, "None."); | |
95 | } | |
96 | ||
97 | bot->SendTo(theClient, | |
98 | bot->getResponse(theUser, | |
99 | language::host_list_footer, | |
100 | std::string("End of host list.")).c_str()); | |
101 | ||
8de4dcba | 102 | bot->logAdminMessage("%s (%s) LISTHOSTS %s", |
87fb1731 | 103 | theUser->getUserName().c_str(), |
104 | theClient->getRealNickUserHost().c_str(), | |
105 | targetUser->getUserName().c_str()); | |
8de4dcba | 106 | |
25f00d30 | 107 | bot->logLastComMessage(theClient, Message); |
108 | ||
82f09291 | 109 | return; |
c169a3ca | 110 | } //LISTHOSTSCommand::Exec |
1d54d2a1 | 111 | |
112 | } //namespace cf | |
82f09291 | 113 | } //namespace gnuworld |