aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/UserServer/Main.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Grid/UserServer/Main.cs')
-rw-r--r--OpenSim/Grid/UserServer/Main.cs276
1 files changed, 11 insertions, 265 deletions
diff --git a/OpenSim/Grid/UserServer/Main.cs b/OpenSim/Grid/UserServer/Main.cs
index efa090e..61f9800 100644
--- a/OpenSim/Grid/UserServer/Main.cs
+++ b/OpenSim/Grid/UserServer/Main.cs
@@ -40,6 +40,8 @@ using OpenSim.Framework.Console;
40using OpenSim.Framework.Servers; 40using OpenSim.Framework.Servers;
41using OpenSim.Framework.Statistics; 41using OpenSim.Framework.Statistics;
42using OpenSim.Grid.Communications.OGS1; 42using OpenSim.Grid.Communications.OGS1;
43using OpenSim.Grid.Framework;
44using OpenSim.Grid.UserServer.Modules;
43 45
44namespace OpenSim.Grid.UserServer 46namespace OpenSim.Grid.UserServer
45{ 47{
@@ -63,6 +65,8 @@ namespace OpenSim.Grid.UserServer
63 public GridInfoService m_gridInfoService; 65 public GridInfoService m_gridInfoService;
64 public MessageServersConnector m_messagesService; 66 public MessageServersConnector m_messagesService;
65 67
68 protected UserServerCommandModule m_consoleCommandModule;
69
66 private UUID m_lastCreatedUser = UUID.Random(); 70 private UUID m_lastCreatedUser = UUID.Random();
67 71
68 public static void Main(string[] args) 72 public static void Main(string[] args)
@@ -123,6 +127,8 @@ namespace OpenSim.Grid.UserServer
123 127
124 m_messagesService = new MessageServersConnector(); 128 m_messagesService = new MessageServersConnector();
125 129
130 m_consoleCommandModule = new UserServerCommandModule(m_console, Cfg, m_userDataBaseService, m_loginService);
131
126 //register event handlers 132 //register event handlers
127 RegisterEventHandlers(); 133 RegisterEventHandlers();
128 134
@@ -172,34 +178,7 @@ namespace OpenSim.Grid.UserServer
172 178
173 protected virtual void RegisterConsoleCommands() 179 protected virtual void RegisterConsoleCommands()
174 { 180 {
175 m_console.Commands.AddCommand("userserver", false, "create user", 181 m_consoleCommandModule.RegisterConsoleCommands();
176 "create user [<first> [<last> [<x> <y> [email]]]]",
177 "Create a new user account", RunCommand);
178
179 m_console.Commands.AddCommand("userserver", false, "reset user password",
180 "reset user password [<first> [<last> [<new password>]]]",
181 "Reset a user's password", RunCommand);
182
183 m_console.Commands.AddCommand("userserver", false, "login level",
184 "login level <level>",
185 "Set the minimum user level to log in", HandleLoginCommand);
186
187 m_console.Commands.AddCommand("userserver", false, "login reset",
188 "login reset",
189 "Reset the login level to allow all users",
190 HandleLoginCommand);
191
192 m_console.Commands.AddCommand("userserver", false, "login text",
193 "login text <text>",
194 "Set the text users will see on login", HandleLoginCommand);
195
196 m_console.Commands.AddCommand("userserver", false, "test-inventory",
197 "test-inventory",
198 "Perform a test inventory transaction", RunCommand);
199
200 m_console.Commands.AddCommand("userserver", false, "logoff-user",
201 "logoff-user <first> <last> <message>",
202 "Log off a named user", RunCommand);
203 } 182 }
204 183
205 protected virtual void RegisterHttpHandlers() 184 protected virtual void RegisterHttpHandlers()
@@ -261,247 +240,14 @@ namespace OpenSim.Grid.UserServer
261 return m_httpServer; 240 return m_httpServer;
262 } 241 }
263 #endregion 242 #endregion
264
265 #region Console Command Handlers
266 public void do_create(string[] args)
267 {
268 switch (args[0])
269 {
270 case "user":
271 CreateUser(args);
272 break;
273 }
274 }
275
276 /// <summary>
277 /// Execute switch for some of the reset commands
278 /// </summary>
279 /// <param name="args"></param>
280 protected void Reset(string[] args)
281 {
282 if (args.Length == 0)
283 return;
284
285 switch (args[0])
286 {
287 case "user":
288
289 switch (args[1])
290 {
291 case "password":
292 ResetUserPassword(args);
293 break;
294 }
295
296 break;
297 }
298 }
299
300 /// <summary>
301 /// Create a new user
302 /// </summary>
303 /// <param name="cmdparams">string array with parameters: firstname, lastname, password, locationX, locationY, email</param>
304 protected void CreateUser(string[] cmdparams)
305 {
306 string firstName;
307 string lastName;
308 string password;
309 string email;
310 uint regX = 1000;
311 uint regY = 1000;
312
313 if (cmdparams.Length < 2)
314 firstName = MainConsole.Instance.CmdPrompt("First name", "Default");
315 else firstName = cmdparams[1];
316
317 if (cmdparams.Length < 3)
318 lastName = MainConsole.Instance.CmdPrompt("Last name", "User");
319 else lastName = cmdparams[2];
320
321 if (cmdparams.Length < 4)
322 password = MainConsole.Instance.PasswdPrompt("Password");
323 else password = cmdparams[3];
324
325 if (cmdparams.Length < 5)
326 regX = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region X", regX.ToString()));
327 else regX = Convert.ToUInt32(cmdparams[4]);
328
329 if (cmdparams.Length < 6)
330 regY = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region Y", regY.ToString()));
331 else regY = Convert.ToUInt32(cmdparams[5]);
332
333 if (cmdparams.Length < 7)
334 email = MainConsole.Instance.CmdPrompt("Email", "");
335 else email = cmdparams[6];
336
337 if (null == m_userDataBaseService.GetUserProfile(firstName, lastName))
338 {
339 m_lastCreatedUser = m_userDataBaseService.AddUser(firstName, lastName, password, email, regX, regY);
340 }
341 else
342 {
343 m_log.ErrorFormat("[USERS]: A user with the name {0} {1} already exists!", firstName, lastName);
344 }
345 }
346
347 /// <summary>
348 /// Reset a user password.
349 /// </summary>
350 /// <param name="cmdparams"></param>
351 private void ResetUserPassword(string[] cmdparams)
352 {
353 string firstName;
354 string lastName;
355 string newPassword;
356
357 if (cmdparams.Length < 3)
358 firstName = MainConsole.Instance.CmdPrompt("First name");
359 else firstName = cmdparams[2];
360
361 if ( cmdparams.Length < 4 )
362 lastName = MainConsole.Instance.CmdPrompt("Last name");
363 else lastName = cmdparams[3];
364
365 if ( cmdparams.Length < 5 )
366 newPassword = MainConsole.Instance.PasswdPrompt("New password");
367 else newPassword = cmdparams[4];
368
369 m_userDataBaseService.ResetUserPassword(firstName, lastName, newPassword);
370 }
371
372 private void HandleLoginCommand(string module, string[] cmd)
373 {
374 string subcommand = cmd[1];
375
376 switch (subcommand)
377 {
378 case "level":
379 // Set the minimal level to allow login
380 // Useful to allow grid update without worrying about users.
381 // or fixing critical issues
382 //
383 if (cmd.Length > 2)
384 {
385 int level = Convert.ToInt32(cmd[2]);
386 m_loginService.setloginlevel(level);
387 }
388 break;
389 case "reset":
390 m_loginService.setloginlevel(0);
391 break;
392 case "text":
393 if (cmd.Length > 2)
394 {
395 m_loginService.setwelcometext(cmd[2]);
396 }
397 break;
398 }
399 }
400
401 public void RunCommand(string module, string[] cmd)
402 {
403 List<string> args = new List<string>(cmd);
404 string command = cmd[0];
405
406 args.RemoveAt(0);
407
408 string[] cmdparams = args.ToArray();
409
410 switch (command)
411 {
412 case "create":
413 do_create(cmdparams);
414 break;
415
416 case "reset":
417 Reset(cmdparams);
418 break;
419
420
421 case "test-inventory":
422 // RestObjectPosterResponse<List<InventoryFolderBase>> requester = new RestObjectPosterResponse<List<InventoryFolderBase>>();
423 // requester.ReturnResponseVal = TestResponse;
424 // requester.BeginPostObject<UUID>(m_userManager._config.InventoryUrl + "RootFolders/", m_lastCreatedUser);
425 SynchronousRestObjectPoster.BeginPostObject<UUID, List<InventoryFolderBase>>(
426 "POST", Cfg.InventoryUrl + "RootFolders/", m_lastCreatedUser);
427 break;
428
429 case "logoff-user":
430 if (cmdparams.Length >= 3)
431 {
432 string firstname = cmdparams[0];
433 string lastname = cmdparams[1];
434 string message = "";
435
436 for (int i = 2; i < cmdparams.Length; i++)
437 message += " " + cmdparams[i];
438
439 UserProfileData theUser = null;
440 try
441 {
442 theUser = m_loginService.GetTheUser(firstname, lastname);
443 }
444 catch (Exception)
445 {
446 m_log.Error("[LOGOFF]: Error getting user data from the database.");
447 }
448
449 if (theUser != null)
450 {
451 if (theUser.CurrentAgent != null)
452 {
453 if (theUser.CurrentAgent.AgentOnline)
454 {
455 m_log.Info("[LOGOFF]: Logging off requested user!");
456 m_loginService.LogOffUser(theUser, message);
457
458 theUser.CurrentAgent.AgentOnline = false;
459
460 m_loginService.CommitAgent(ref theUser);
461 }
462 else
463 {
464 m_log.Info(
465 "[LOGOFF]: User Doesn't appear to be online, sending the logoff message anyway.");
466 m_loginService.LogOffUser(theUser, message);
467
468 theUser.CurrentAgent.AgentOnline = false;
469
470 m_loginService.CommitAgent(ref theUser);
471 }
472 }
473 else
474 {
475 m_log.Error(
476 "[LOGOFF]: Unable to logoff-user. User doesn't have an agent record so I can't find the simulator to notify");
477 }
478 }
479 else
480 {
481 m_log.Info("[LOGOFF]: User doesn't exist in the database");
482 }
483 }
484 else
485 {
486 m_log.Error(
487 "[LOGOFF]: Invalid amount of parameters. logoff-user takes at least three. Firstname, Lastname, and message");
488 }
489
490 break;
491 }
492 }
493 243
244 #region Console Command Handlers
245
494 protected override void ShowHelp(string[] helpArgs) 246 protected override void ShowHelp(string[] helpArgs)
495 { 247 {
496 base.ShowHelp(helpArgs); 248 base.ShowHelp(helpArgs);
497
498 m_console.Notice("create user - create a new user");
499 m_console.Notice("logoff-user <firstname> <lastname> <message> - logs off the specified user from the grid");
500 m_console.Notice("reset user password - reset a user's password.");
501 m_console.Notice("login-level <value> - Set the miminim userlevel allowed To login.");
502 m_console.Notice("login-reset - reset the login level to its default value.");
503 m_console.Notice("login-text <text to print during the login>");
504 249
250 m_consoleCommandModule.ShowHelp(helpArgs);
505 } 251 }
506 #endregion 252 #endregion
507 253