aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ApplicationPlugins
diff options
context:
space:
mode:
authorSean Dague2008-04-04 11:48:27 +0000
committerSean Dague2008-04-04 11:48:27 +0000
commitae490c7d6f74ec4dd3a29cc7d0aeab1d875ca4fa (patch)
tree25c4a3938e94eb988b2ba34ddbcb27b3f5436ef3 /OpenSim/ApplicationPlugins
parent* Fixed up some documentation regarding the inventory descendants method XML.... (diff)
downloadopensim-SC_OLD-ae490c7d6f74ec4dd3a29cc7d0aeab1d875ca4fa.zip
opensim-SC_OLD-ae490c7d6f74ec4dd3a29cc7d0aeab1d875ca4fa.tar.gz
opensim-SC_OLD-ae490c7d6f74ec4dd3a29cc7d0aeab1d875ca4fa.tar.bz2
opensim-SC_OLD-ae490c7d6f74ec4dd3a29cc7d0aeab1d875ca4fa.tar.xz
From: Dr Scofield <hud@zurich.ibm.com>
ansgar and i have done a bit of clean up for the "create user" and "create region" XmlRpc methods in RemoteController (contributed earlier by ansgar), this add a bit of consistency checking, more error checking and also documentation of the expected XmlRpc parameters.
Diffstat (limited to 'OpenSim/ApplicationPlugins')
-rw-r--r--OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs334
1 files changed, 231 insertions, 103 deletions
diff --git a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
index cfd3885..9d4bfea 100644
--- a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
+++ b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Net; 30using System.Net;
31using System.IO;
31using System.Timers; 32using System.Timers;
32using libsecondlife; 33using libsecondlife;
33using Mono.Addins; 34using Mono.Addins;
@@ -233,104 +234,228 @@ namespace OpenSim.ApplicationPlugins.LoadRegions
233 m_app.Shutdown(); 234 m_app.Shutdown();
234 } 235 }
235 236
237 /// <summary>
238 /// Create a new region.
239 /// <summary>
240 /// <param name="request">incoming XML RPC request</param>
241 /// <remarks>
242 /// XmlRpcCreateRegionMethod takes the following XMLRPC
243 /// parameters
244 /// <list type="table">
245 /// <listheader><term>parameter name</term><description>description</description></listheader>
246 /// <item><term>password</term>
247 /// <description>admin password as set in OpenSim.ini</description></item>
248 /// <item><term>region_name</term>
249 /// <description>desired region name</description></item>
250 /// <item><term>region_id</term>
251 /// <description>(optional) desired region UUID</description></item>
252 /// <item><term>region_x</term>
253 /// <description>desired region X coordinate</description></item>
254 /// <item><term>region_y</term>
255 /// <description>desired region Y coordinate</description></item>
256 /// <item><term>region_master_first</term>
257 /// <description>firstname of region master</description></item>
258 /// <item><term>region_master_last</term>
259 /// <description>lastname of region master</description></item>
260 /// <item><term>listen_ip</term>
261 /// <description>internal IP address</description></item>
262 /// <item><term>listen_port</term>
263 /// <description>internal port</description></item>
264 /// <item><term>external_address</term>
265 /// <description>external IP address</description></item>
266 /// <item><term>datastore</term>
267 /// <description>datastore parameter (?)</description></item>
268 /// </list>
269 ///
270 /// XmlRpcCreateRegionMethod returns
271 /// <list type="table">
272 /// <listheader><term>name</term><description>description</description></listheader>
273 /// <item><term>success</term>
274 /// <description>true or false</description></item>
275 /// <item><term>error</term>
276 /// <description>error message if success is false</description></item>
277 /// <item><term>region_uuid</term>
278 /// <description>UUID of the newly created region</description></item>
279 /// <item><term>region_name</term>
280 /// <description>name of the newly created region</description></item>
281 /// </list>
282 /// </remarks>
236 public XmlRpcResponse XmlRpcCreateRegionMethod(XmlRpcRequest request) 283 public XmlRpcResponse XmlRpcCreateRegionMethod(XmlRpcRequest request)
237 { 284 {
238 m_log.Info("[RADMIN]: Received Create Region Administrator Request"); 285 m_log.Info("[RADMIN]: Received Create Region Administrator Request");
239 XmlRpcResponse response = new XmlRpcResponse(); 286 XmlRpcResponse response = new XmlRpcResponse();
240 Hashtable requestData = (Hashtable) request.Params[0]; 287 Hashtable requestData = (Hashtable) request.Params[0];
241 Hashtable responseData = new Hashtable(); 288 Hashtable responseData = new Hashtable();
242 if (requiredPassword != System.String.Empty &&
243 (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword))
244 {
245 responseData["created"] = "false";
246 response.Value = responseData;
247 }
248 else
249 {
250 RegionInfo newRegionData = new RegionInfo();
251 289
252 try 290 try {
291 // check completeness
292 foreach (string p in new string[] { "password",
293 "region_name", "region_x", "region_y",
294 "region_master_first", "region_master_last",
295 "listen_ip", "listen_port", "external_address"})
253 { 296 {
254 newRegionData.RegionID = (string) requestData["region_id"]; 297 if (!requestData.Contains(p))
255 newRegionData.RegionName = (string) requestData["region_name"]; 298 throw new Exception(String.Format("missing parameter {0}", p));
256 newRegionData.RegionLocX = Convert.ToUInt32((Int32) requestData["region_x"]); 299 }
257 newRegionData.RegionLocY = Convert.ToUInt32((Int32) requestData["region_y"]);
258
259 // Security risk
260 newRegionData.DataStore = (string) requestData["datastore"];
261 300
262 newRegionData.InternalEndPoint = new IPEndPoint( 301 // check password
263 IPAddress.Parse((string) requestData["listen_ip"]), 0); 302 if (!String.IsNullOrEmpty(requiredPassword) &&
303 (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
304
305 // bool persist = Convert.ToBoolean((string)requestData["persist"]);
306 RegionInfo region = null;
307 // if (!persist)
308 // {
309 // region = new RegionInfo();
310 // }
311 // else
312 // {
313 // region = new RegionInfo("DEFAULT REGION CONFIG",
314 // Path.Combine(regionConfigPath, "default.xml"), false);
315 // }
316 region = new RegionInfo();
317
318
319 if (requestData.ContainsKey("region_id") &&
320 !String.IsNullOrEmpty((string) requestData["region_id"]))
321 {
322 // FIXME: need to check whether region_id already
323 // in use
324 region.RegionID = (string) requestData["region_id"];
325 }
326 else
327 {
328 region.RegionID = LLUUID.Random();
329 }
264 330
265 newRegionData.InternalEndPoint.Port = (Int32) requestData["listen_port"]; 331 // FIXME: need to check whether region_name already
266 newRegionData.ExternalHostName = (string) requestData["external_address"]; 332 // in use
333 region.RegionName = (string) requestData["region_name"];
334 region.RegionLocX = Convert.ToUInt32((Int32) requestData["region_x"]);
335 region.RegionLocY = Convert.ToUInt32((Int32) requestData["region_y"]);
336
337 // Security risk
338 if (requestData.ContainsKey("datastore"))
339 region.DataStore = (string) requestData["datastore"];
340
341 region.InternalEndPoint =
342 new IPEndPoint(IPAddress.Parse((string) requestData["listen_ip"]), 0);
343
344 // FIXME: need to check whether listen_port already in use!
345 region.InternalEndPoint.Port = (Int32) requestData["listen_port"];
346 region.ExternalHostName = (string) requestData["external_address"];
347
348 region.MasterAvatarFirstName = (string) requestData["region_master_first"];
349 region.MasterAvatarLastName = (string) requestData["region_master_last"];
350
351 m_app.CreateRegion(region, true);
267 352
268 newRegionData.MasterAvatarFirstName = (string) requestData["region_master_first"]; 353 responseData["success"] = "true";
269 newRegionData.MasterAvatarLastName = (string) requestData["region_master_last"]; 354 responseData["region_name"] = region.RegionName;
355 responseData["region_uuid"] = region.RegionID.ToString();
270 356
271 m_app.CreateRegion(newRegionData, true); 357 response.Value = responseData;
358 }
359 catch (Exception e)
360 {
361 responseData["success"] = "false";
362 responseData["error"] = e.Message;
272 363
273 responseData["created"] = "true"; 364 response.Value = responseData;
274 response.Value = responseData;
275 }
276 catch (Exception e)
277 {
278 responseData["created"] = "false";
279 responseData["error"] = e.ToString();
280 response.Value = responseData;
281 }
282 } 365 }
283 366
284 return response; 367 return response;
285 } 368 }
286 369
370 /// <summary>
371 /// Create a new user account.
372 /// <summary>
373 /// <param name="request">incoming XML RPC request</param>
374 /// <remarks>
375 /// XmlRpcCreateUserMethod takes the following XMLRPC
376 /// parameters
377 /// <list type="table">
378 /// <listheader><term>parameter name</term><description>description</description></listheader>
379 /// <item><term>password</term>
380 /// <description>admin password as set in OpenSim.ini</description></item>
381 /// <item><term>user_firstname</term>
382 /// <description>avatar's first name</description></item>
383 /// <item><term>user_lastname</term>
384 /// <description>avatar's last name</description></item>
385 /// <item><term>user_password</term>
386 /// <description>avatar's password</description></item>
387 /// <item><term>start_region_x</term>
388 /// <description>avatar's start region coordinates, X value</description></item>
389 /// <item><term>start_region_y</term>
390 /// <description>avatar's start region coordinates, Y value</description></item>
391 /// </list>
392 ///
393 /// XmlRpcCreateUserMethod returns
394 /// <list type="table">
395 /// <listheader><term>name</term><description>description</description></listheader>
396 /// <item><term>success</term>
397 /// <description>true or false</description></item>
398 /// <item><term>error</term>
399 /// <description>error message if success is false</description></item>
400 /// <item><term>avatar_uuid</term>
401 /// <description>UUID of the newly created avatar
402 /// account; LLUUID.Zero if failed.
403 /// </description></item>
404 /// </list>
405 /// </remarks>
287 public XmlRpcResponse XmlRpcCreateUserMethod(XmlRpcRequest request) 406 public XmlRpcResponse XmlRpcCreateUserMethod(XmlRpcRequest request)
288 { 407 {
289 m_log.Info("[RADMIN]: Received Create User Administrator Request"); 408 m_log.Info("[RADMIN]: Received Create User Administrator Request");
290 XmlRpcResponse response = new XmlRpcResponse(); 409 XmlRpcResponse response = new XmlRpcResponse();
291 Hashtable requestData = (Hashtable) request.Params[0]; 410 Hashtable requestData = (Hashtable) request.Params[0];
292 Hashtable responseData = new Hashtable(); 411 Hashtable responseData = new Hashtable();
293 if (requiredPassword != System.String.Empty && 412
294 (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword)) 413 try
295 { 414 {
296 responseData["created"] = "false"; 415 // check completeness
416 foreach (string p in new string[] { "password",
417 "user_firstname", "user_lastname", "user_password",
418 "start_region_x", "start_region_y" })
419 {
420 if (!requestData.Contains(p))
421 throw new Exception(String.Format("missing parameter {0}", p));
422 }
423
424 // check password
425 if (!String.IsNullOrEmpty(requiredPassword) &&
426 (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
427
428 // do the job
429 string firstname = (string) requestData["user_firstname"];
430 string lastname = (string) requestData["user_lastname"];
431 string passwd = (string) requestData["user_password"];
432 uint regX = Convert.ToUInt32((Int32)requestData["start_region_x"]);
433 uint regY = Convert.ToUInt32((Int32)requestData["start_region_y"]);
434
435 // FIXME: need to check whether "firstname lastname"
436 // already exists!
437 LLUUID userID = m_app.CreateUser(firstname, lastname, passwd, regX, regY);
438
439 if (userID == LLUUID.Zero) throw new Exception(String.Format("failed to create new user {0} {1}",
440 firstname, lastname));
441
442 responseData["success"] = "true";
443 responseData["avatar_uuid"] = userID.ToString();
444
297 response.Value = responseData; 445 response.Value = responseData;
446
447 m_log.InfoFormat("[RADMIN]: User {0} {1} created, UUID {2}", firstname, lastname, userID);
298 } 448 }
299 else 449 catch (Exception e)
300 { 450 {
301 try 451 m_log.ErrorFormat("[RADMIN] create user: failed: {0}", e.Message);
302 { 452 m_log.DebugFormat("[RADMIN] create user: failed: {0}", e.ToString());
303 string tempfirstname = (string) requestData["user_firstname"]; 453
304 string templastname = (string) requestData["user_lastname"]; 454 responseData["success"] = "false";
305 string tempPasswd = (string) requestData["user_password"]; 455 responseData["avatar_uuid"] = LLUUID.Zero.ToString();
306 uint regX = Convert.ToUInt32((Int32) requestData["start_region_x"]); 456 responseData["error"] = e.Message;
307 uint regY = Convert.ToUInt32((Int32) requestData["start_region_y"]); 457
308 458 response.Value = responseData;
309 LLUUID tempuserID = m_app.CreateUser(tempfirstname, templastname, tempPasswd, regX, regY);
310
311 if (tempuserID == LLUUID.Zero)
312 {
313 responseData["created"] = "false";
314 responseData["error"] = "Error creating user";
315 responseData["avatar_uuid"] = LLUUID.Zero;
316 response.Value = responseData;
317 m_log.Error("[RADMIN]: Error creating user (" + tempfirstname + " " + templastname + ") :");
318 }
319 else
320 {
321 responseData["created"] = "true";
322 responseData["avatar_uuid"] = tempuserID;
323 response.Value = responseData;
324 m_log.Info("[RADMIN]: User " + tempfirstname + " " + templastname + " created. Userid " + tempuserID + " assigned.");
325 }
326 }
327 catch (Exception e)
328 {
329 responseData["created"] = "false";
330 responseData["error"] = e.ToString();
331 responseData["avatar_uuid"] = LLUUID.Zero;
332 response.Value = responseData;
333 }
334 } 459 }
335 460
336 return response; 461 return response;
@@ -342,42 +467,45 @@ namespace OpenSim.ApplicationPlugins.LoadRegions
342 XmlRpcResponse response = new XmlRpcResponse(); 467 XmlRpcResponse response = new XmlRpcResponse();
343 Hashtable requestData = (Hashtable) request.Params[0]; 468 Hashtable requestData = (Hashtable) request.Params[0];
344 Hashtable responseData = new Hashtable(); 469 Hashtable responseData = new Hashtable();
345 if (requiredPassword != System.String.Empty && 470
346 (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword)) 471 try
347 {
348 responseData["loaded"] = "false";
349 responseData["switched"] = "false";
350 response.Value = responseData;
351 }
352 else
353 { 472 {
354 try 473 // check completeness
355 { 474 foreach (string p in new string[] { "password",
356 string region_name = (string) requestData["region_name"]; 475 "region_name", "filename" })
357 string filename = (string) requestData["filename"];
358
359 if (m_app.SceneManager.TrySetCurrentScene(region_name))
360 {
361 m_log.Info("[RADMIN] Switched to region "+region_name);
362 responseData["switched"] = "true";
363 m_app.SceneManager.LoadCurrentSceneFromXml(filename, true, new LLVector3(0, 0, 0));
364 responseData["loaded"] = "true";
365 response.Value = responseData;
366 }
367 else
368 {
369 m_log.Info("[RADMIN] Failed to switch to region "+region_name);
370 responseData["loaded"] = "false";
371 responseData["switched"] = "false";
372 response.Value = responseData;
373 }
374 }
375 catch (Exception e)
376 { 476 {
377 responseData["loaded"] = "false"; 477 if (!requestData.Contains(p))
378 responseData["error"] = e.ToString(); 478 throw new Exception(String.Format("missing parameter {0}", p));
379 response.Value = responseData;
380 } 479 }
480
481 // check password
482 if (!String.IsNullOrEmpty(requiredPassword) &&
483 (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
484
485 string region_name = (string)requestData["region_name"];
486 string filename = (string)requestData["filename"];
487
488 if (!m_app.SceneManager.TrySetCurrentScene(region_name))
489 throw new Exception(String.Format("failed to switch to region {0}", region_name));
490 m_log.InfoFormat("[RADMIN] Switched to region {0}");
491
492 responseData["switched"] = "true";
493
494 m_app.SceneManager.LoadCurrentSceneFromXml(filename, true, new LLVector3(0, 0, 0));
495 responseData["loaded"] = "true";
496
497 response.Value = responseData;
498 }
499 catch (Exception e)
500 {
501 m_log.InfoFormat("[RADMIN] LoadXml: {0}", e.Message);
502 m_log.DebugFormat("[RADMIN] LoadXML {0}: {1}", e.ToString());
503
504 responseData["loaded"] = "false";
505 responseData["switched"] = "false";
506 responseData["error"] = e.Message;
507
508 response.Value = responseData;
381 } 509 }
382 510
383 return response; 511 return response;