aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/UserServer/UserServerCommandModule.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Grid/UserServer/UserServerCommandModule.cs349
1 files changed, 349 insertions, 0 deletions
diff --git a/OpenSim/Grid/UserServer/UserServerCommandModule.cs b/OpenSim/Grid/UserServer/UserServerCommandModule.cs
new file mode 100644
index 0000000..fbdd73f
--- /dev/null
+++ b/OpenSim/Grid/UserServer/UserServerCommandModule.cs
@@ -0,0 +1,349 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
32using log4net;
33using log4net.Config;
34using OpenMetaverse;
35using OpenSim.Data;
36using OpenSim.Framework;
37using OpenSim.Framework.Communications;
38using OpenSim.Framework.Communications.Cache;
39using OpenSim.Framework.Console;
40using OpenSim.Framework.Servers;
41using OpenSim.Framework.Statistics;
42using OpenSim.Grid.Communications.OGS1;
43using OpenSim.Grid.Framework;
44using OpenSim.Grid.UserServer.Modules;
45
46namespace OpenSim.Grid.UserServer
47{
48 public class UserServerCommandModule
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 protected ConsoleBase m_console;
53 protected UserConfig Cfg;
54
55 protected UserDataBaseService m_userDataBaseService;
56 protected UserLoginService m_loginService;
57
58 private UUID m_lastCreatedUser = UUID.Random();
59
60 public UserServerCommandModule(ConsoleBase console, UserConfig cfg, UserDataBaseService userDBservice, UserLoginService loginService)
61 {
62 m_console = console;
63 Cfg = cfg;
64 m_userDataBaseService = userDBservice;
65 m_loginService = loginService;
66 }
67
68 public virtual void RegisterConsoleCommands()
69 {
70 m_console.Commands.AddCommand("userserver", false, "create user",
71 "create user [<first> [<last> [<x> <y> [email]]]]",
72 "Create a new user account", RunCommand);
73
74 m_console.Commands.AddCommand("userserver", false, "reset user password",
75 "reset user password [<first> [<last> [<new password>]]]",
76 "Reset a user's password", RunCommand);
77
78 m_console.Commands.AddCommand("userserver", false, "login level",
79 "login level <level>",
80 "Set the minimum user level to log in", HandleLoginCommand);
81
82 m_console.Commands.AddCommand("userserver", false, "login reset",
83 "login reset",
84 "Reset the login level to allow all users",
85 HandleLoginCommand);
86
87 m_console.Commands.AddCommand("userserver", false, "login text",
88 "login text <text>",
89 "Set the text users will see on login", HandleLoginCommand);
90
91 m_console.Commands.AddCommand("userserver", false, "test-inventory",
92 "test-inventory",
93 "Perform a test inventory transaction", RunCommand);
94
95 m_console.Commands.AddCommand("userserver", false, "logoff-user",
96 "logoff-user <first> <last> <message>",
97 "Log off a named user", RunCommand);
98
99 m_console.Commands.AddCommand("userserver", false, "test-command",
100 "test-command",
101 "test command", HandleTestCommand);
102 }
103
104 #region Console Command Handlers
105 public void do_create(string[] args)
106 {
107 switch (args[0])
108 {
109 case "user":
110 CreateUser(args);
111 break;
112 }
113 }
114
115 /// <summary>
116 /// Execute switch for some of the reset commands
117 /// </summary>
118 /// <param name="args"></param>
119 protected void Reset(string[] args)
120 {
121 if (args.Length == 0)
122 return;
123
124 switch (args[0])
125 {
126 case "user":
127
128 switch (args[1])
129 {
130 case "password":
131 ResetUserPassword(args);
132 break;
133 }
134
135 break;
136 }
137 }
138
139 /// <summary>
140 /// Create a new user
141 /// </summary>
142 /// <param name="cmdparams">string array with parameters: firstname, lastname, password, locationX, locationY, email</param>
143 protected void CreateUser(string[] cmdparams)
144 {
145 string firstName;
146 string lastName;
147 string password;
148 string email;
149 uint regX = 1000;
150 uint regY = 1000;
151
152 if (cmdparams.Length < 2)
153 firstName = MainConsole.Instance.CmdPrompt("First name", "Default");
154 else firstName = cmdparams[1];
155
156 if (cmdparams.Length < 3)
157 lastName = MainConsole.Instance.CmdPrompt("Last name", "User");
158 else lastName = cmdparams[2];
159
160 if (cmdparams.Length < 4)
161 password = MainConsole.Instance.PasswdPrompt("Password");
162 else password = cmdparams[3];
163
164 if (cmdparams.Length < 5)
165 regX = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region X", regX.ToString()));
166 else regX = Convert.ToUInt32(cmdparams[4]);
167
168 if (cmdparams.Length < 6)
169 regY = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region Y", regY.ToString()));
170 else regY = Convert.ToUInt32(cmdparams[5]);
171
172 if (cmdparams.Length < 7)
173 email = MainConsole.Instance.CmdPrompt("Email", "");
174 else email = cmdparams[6];
175
176 if (null == m_userDataBaseService.GetUserProfile(firstName, lastName))
177 {
178 m_lastCreatedUser = m_userDataBaseService.AddUser(firstName, lastName, password, email, regX, regY);
179 }
180 else
181 {
182 m_log.ErrorFormat("[USERS]: A user with the name {0} {1} already exists!", firstName, lastName);
183 }
184 }
185
186 /// <summary>
187 /// Reset a user password.
188 /// </summary>
189 /// <param name="cmdparams"></param>
190 private void ResetUserPassword(string[] cmdparams)
191 {
192 string firstName;
193 string lastName;
194 string newPassword;
195
196 if (cmdparams.Length < 3)
197 firstName = MainConsole.Instance.CmdPrompt("First name");
198 else firstName = cmdparams[2];
199
200 if (cmdparams.Length < 4)
201 lastName = MainConsole.Instance.CmdPrompt("Last name");
202 else lastName = cmdparams[3];
203
204 if (cmdparams.Length < 5)
205 newPassword = MainConsole.Instance.PasswdPrompt("New password");
206 else newPassword = cmdparams[4];
207
208 m_userDataBaseService.ResetUserPassword(firstName, lastName, newPassword);
209 }
210
211 private void HandleTestCommand(string module, string[] cmd)
212 {
213 m_log.Info("test command received");
214 }
215
216 private void HandleLoginCommand(string module, string[] cmd)
217 {
218 string subcommand = cmd[1];
219
220 switch (subcommand)
221 {
222 case "level":
223 // Set the minimal level to allow login
224 // Useful to allow grid update without worrying about users.
225 // or fixing critical issues
226 //
227 if (cmd.Length > 2)
228 {
229 int level = Convert.ToInt32(cmd[2]);
230 m_loginService.setloginlevel(level);
231 }
232 break;
233 case "reset":
234 m_loginService.setloginlevel(0);
235 break;
236 case "text":
237 if (cmd.Length > 2)
238 {
239 m_loginService.setwelcometext(cmd[2]);
240 }
241 break;
242 }
243 }
244
245 public void RunCommand(string module, string[] cmd)
246 {
247 List<string> args = new List<string>(cmd);
248 string command = cmd[0];
249
250 args.RemoveAt(0);
251
252 string[] cmdparams = args.ToArray();
253
254 switch (command)
255 {
256 case "create":
257 do_create(cmdparams);
258 break;
259
260 case "reset":
261 Reset(cmdparams);
262 break;
263
264
265 case "test-inventory":
266 // RestObjectPosterResponse<List<InventoryFolderBase>> requester = new RestObjectPosterResponse<List<InventoryFolderBase>>();
267 // requester.ReturnResponseVal = TestResponse;
268 // requester.BeginPostObject<UUID>(m_userManager._config.InventoryUrl + "RootFolders/", m_lastCreatedUser);
269 SynchronousRestObjectPoster.BeginPostObject<UUID, List<InventoryFolderBase>>(
270 "POST", Cfg.InventoryUrl + "RootFolders/", m_lastCreatedUser);
271 break;
272
273 case "logoff-user":
274 if (cmdparams.Length >= 3)
275 {
276 string firstname = cmdparams[0];
277 string lastname = cmdparams[1];
278 string message = "";
279
280 for (int i = 2; i < cmdparams.Length; i++)
281 message += " " + cmdparams[i];
282
283 UserProfileData theUser = null;
284 try
285 {
286 theUser = m_loginService.GetTheUser(firstname, lastname);
287 }
288 catch (Exception)
289 {
290 m_log.Error("[LOGOFF]: Error getting user data from the database.");
291 }
292
293 if (theUser != null)
294 {
295 if (theUser.CurrentAgent != null)
296 {
297 if (theUser.CurrentAgent.AgentOnline)
298 {
299 m_log.Info("[LOGOFF]: Logging off requested user!");
300 m_loginService.LogOffUser(theUser, message);
301
302 theUser.CurrentAgent.AgentOnline = false;
303
304 m_loginService.CommitAgent(ref theUser);
305 }
306 else
307 {
308 m_log.Info(
309 "[LOGOFF]: User Doesn't appear to be online, sending the logoff message anyway.");
310 m_loginService.LogOffUser(theUser, message);
311
312 theUser.CurrentAgent.AgentOnline = false;
313
314 m_loginService.CommitAgent(ref theUser);
315 }
316 }
317 else
318 {
319 m_log.Error(
320 "[LOGOFF]: Unable to logoff-user. User doesn't have an agent record so I can't find the simulator to notify");
321 }
322 }
323 else
324 {
325 m_log.Info("[LOGOFF]: User doesn't exist in the database");
326 }
327 }
328 else
329 {
330 m_log.Error(
331 "[LOGOFF]: Invalid amount of parameters. logoff-user takes at least three. Firstname, Lastname, and message");
332 }
333
334 break;
335 }
336 }
337
338 public virtual void ShowHelp(string[] helpArgs)
339 {
340 m_console.Notice("create user - create a new user");
341 m_console.Notice("logoff-user <firstname> <lastname> <message> - logs off the specified user from the grid");
342 m_console.Notice("reset user password - reset a user's password.");
343 m_console.Notice("login-level <value> - Set the miminim userlevel allowed To login.");
344 m_console.Notice("login-reset - reset the login level to its default value.");
345 m_console.Notice("login-text <text to print during the login>");
346 }
347 }
348 #endregion
349}