1
0

RemoteAdminPlugin.cs 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450
  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. using System;
  28. using System.Collections;
  29. using System.IO;
  30. using System.Net;
  31. using System.Reflection;
  32. using System.Timers;
  33. using OpenMetaverse;
  34. using log4net;
  35. using Nini.Config;
  36. using Nwc.XmlRpc;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Servers;
  39. using OpenSim.Region.Environment.Interfaces;
  40. using OpenSim.Region.Environment.Modules.World.Terrain;
  41. using OpenSim.Region.Environment.Scenes;
  42. using System.Collections.Generic;
  43. namespace OpenSim.ApplicationPlugins.RemoteController
  44. {
  45. public class RemoteAdminPlugin : IApplicationPlugin
  46. {
  47. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  48. private OpenSimBase m_app;
  49. private BaseHttpServer m_httpd;
  50. private IConfig m_config;
  51. private IConfigSource m_configSource;
  52. private string requiredPassword = String.Empty;
  53. // TODO: required by IPlugin, but likely not at all right
  54. string m_name = "RemoteAdminPlugin";
  55. string m_version = "0.0";
  56. public string Version { get { return m_version; } }
  57. public string Name { get { return m_name; } }
  58. public void Initialise()
  59. {
  60. m_log.Info("[RADMIN]: " + Name + " cannot be default-initialized!");
  61. throw new PluginNotInitialisedException (Name);
  62. }
  63. public void Initialise(OpenSimBase openSim)
  64. {
  65. m_configSource = openSim.ConfigSource.Source;
  66. try
  67. {
  68. if (m_configSource.Configs["RemoteAdmin"] == null ||
  69. !m_configSource.Configs["RemoteAdmin"].GetBoolean("enabled", false))
  70. {
  71. // No config or disabled
  72. }
  73. else
  74. {
  75. m_config = m_configSource.Configs["RemoteAdmin"];
  76. m_log.Info("[RADMIN]: Remote Admin Plugin Enabled");
  77. requiredPassword = m_config.GetString("access_password", String.Empty);
  78. m_app = openSim;
  79. m_httpd = openSim.HttpServer;
  80. Dictionary<string, XmlRpcMethod> availableMethods = new Dictionary<string, XmlRpcMethod>();
  81. availableMethods["admin_create_region"] = XmlRpcCreateRegionMethod;
  82. availableMethods["admin_delete_region"] = XmlRpcDeleteRegionMethod;
  83. availableMethods["admin_shutdown"] = XmlRpcShutdownMethod;
  84. availableMethods["admin_broadcast"] = XmlRpcAlertMethod;
  85. availableMethods["admin_restart"] = XmlRpcRestartMethod;
  86. availableMethods["admin_load_heightmap"] = XmlRpcLoadHeightmapMethod;
  87. availableMethods["admin_create_user"] = XmlRpcCreateUserMethod;
  88. availableMethods["admin_create_user_email"] = XmlRpcCreateUserMethodEmail;
  89. availableMethods["admin_exists_user"] = XmlRpcUserExistsMethod;
  90. availableMethods["admin_update_user"] = XmlRpcUpdateUserAccountMethod;
  91. availableMethods["admin_load_xml"] = XmlRpcLoadXMLMethod;
  92. availableMethods["admin_save_xml"] = XmlRpcSaveXMLMethod;
  93. availableMethods["admin_load_oar"] = XmlRpcLoadOARMethod;
  94. availableMethods["admin_save_oar"] = XmlRpcSaveOARMethod;
  95. availableMethods["admin_region_query"] = XmlRpcRegionQueryMethod;
  96. // Either enable full remote functionality or just selected features
  97. string enabledMethods = m_config.GetString("enabled_methods", "all");
  98. // The assumption here is that simply enabling Remote Admin as before will produce the same
  99. // behavior - enable all methods unless the whitelist is in place for backward-compatibility.
  100. if (enabledMethods.ToLower() == "all" || String.IsNullOrEmpty(enabledMethods))
  101. {
  102. foreach (string method in availableMethods.Keys)
  103. {
  104. m_httpd.AddXmlRPCHandler(method, availableMethods[method]);
  105. }
  106. }
  107. else
  108. {
  109. foreach (string enabledMethod in enabledMethods.Split('|'))
  110. {
  111. m_httpd.AddXmlRPCHandler(enabledMethod, availableMethods[enabledMethod]);
  112. }
  113. }
  114. }
  115. }
  116. catch (NullReferenceException)
  117. {
  118. // Ignore.
  119. }
  120. }
  121. public XmlRpcResponse XmlRpcRestartMethod(XmlRpcRequest request)
  122. {
  123. XmlRpcResponse response = new XmlRpcResponse();
  124. Hashtable responseData = new Hashtable();
  125. try {
  126. Hashtable requestData = (Hashtable) request.Params[0];
  127. m_log.Info("[RADMIN]: Request to restart Region.");
  128. checkStringParameters(request, new string[] { "password", "regionID" });
  129. if (requiredPassword != String.Empty &&
  130. (!requestData.Contains("password") || (string)requestData["password"] != requiredPassword))
  131. {
  132. throw new Exception("wrong password");
  133. }
  134. UUID regionID = new UUID((string) requestData["regionID"]);
  135. responseData["accepted"] = "true";
  136. responseData["success"] = "true";
  137. response.Value = responseData;
  138. Scene rebootedScene;
  139. if (!m_app.SceneManager.TryGetScene(regionID, out rebootedScene))
  140. throw new Exception("region not found");
  141. responseData["rebooting"] = "true";
  142. response.Value = responseData;
  143. rebootedScene.Restart(30);
  144. }
  145. catch(Exception e)
  146. {
  147. m_log.ErrorFormat("[RADMIN]: Restart region: failed: {0}", e.Message);
  148. m_log.DebugFormat("[RADMIN]: Restart region: failed: {0}", e.ToString());
  149. responseData["accepted"] = "false";
  150. responseData["success"] = "false";
  151. responseData["rebooting"] = "false";
  152. responseData["error"] = e.Message;
  153. response.Value = responseData;
  154. }
  155. return response;
  156. }
  157. public XmlRpcResponse XmlRpcAlertMethod(XmlRpcRequest request)
  158. {
  159. XmlRpcResponse response = new XmlRpcResponse();
  160. Hashtable responseData = new Hashtable();
  161. try {
  162. Hashtable requestData = (Hashtable) request.Params[0];
  163. checkStringParameters(request, new string[] { "password", "message" });
  164. if (requiredPassword != String.Empty &&
  165. (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword))
  166. throw new Exception("wrong password");
  167. string message = (string) requestData["message"];
  168. m_log.InfoFormat("[RADMIN]: Broadcasting: {0}", message);
  169. responseData["accepted"] = "true";
  170. responseData["success"] = "true";
  171. response.Value = responseData;
  172. m_app.SceneManager.SendGeneralMessage(message);
  173. }
  174. catch(Exception e)
  175. {
  176. m_log.ErrorFormat("[RADMIN]: Broadcasting: failed: {0}", e.Message);
  177. m_log.DebugFormat("[RADMIN]: Broadcasting: failed: {0}", e.ToString());
  178. responseData["accepted"] = "false";
  179. responseData["success"] = "false";
  180. responseData["error"] = e.Message;
  181. response.Value = responseData;
  182. }
  183. return response;
  184. }
  185. public XmlRpcResponse XmlRpcLoadHeightmapMethod(XmlRpcRequest request)
  186. {
  187. XmlRpcResponse response = new XmlRpcResponse();
  188. Hashtable responseData = new Hashtable();
  189. try {
  190. Hashtable requestData = (Hashtable)request.Params[0];
  191. m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}", request.ToString());
  192. // foreach (string k in requestData.Keys)
  193. // {
  194. // m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}: >{1}< {2}",
  195. // k, (string)requestData[k], ((string)requestData[k]).Length);
  196. // }
  197. checkStringParameters(request, new string[] { "password", "filename", "regionid"});
  198. if (requiredPassword != String.Empty &&
  199. (!requestData.Contains("password") || (string)requestData["password"] != requiredPassword))
  200. throw new Exception("wrong password");
  201. string file = (string)requestData["filename"];
  202. UUID regionID = (UUID)(string) requestData["regionid"];
  203. m_log.InfoFormat("[RADMIN]: Terrain Loading: {0}", file);
  204. responseData["accepted"] = "true";
  205. Scene region = null;
  206. if (!m_app.SceneManager.TryGetScene(regionID, out region))
  207. throw new Exception("1: unable to get a scene with that name");
  208. ITerrainModule terrainModule = region.RequestModuleInterface<ITerrainModule>();
  209. if (null == terrainModule) throw new Exception("terrain module not available");
  210. terrainModule.LoadFromFile(file);
  211. responseData["success"] = "true";
  212. response.Value = responseData;
  213. }
  214. catch (Exception e)
  215. {
  216. m_log.ErrorFormat("[RADMIN] Terrain Loading: failed: {0}", e.Message);
  217. m_log.DebugFormat("[RADMIN] Terrain Loading: failed: {0}", e.ToString());
  218. responseData["success"] = "false";
  219. responseData["error"] = e.Message;
  220. }
  221. return response;
  222. }
  223. public XmlRpcResponse XmlRpcShutdownMethod(XmlRpcRequest request)
  224. {
  225. m_log.Info("[RADMIN]: Received Shutdown Administrator Request");
  226. XmlRpcResponse response = new XmlRpcResponse();
  227. Hashtable responseData = new Hashtable();
  228. try {
  229. Hashtable requestData = (Hashtable) request.Params[0];
  230. if (requiredPassword != String.Empty &&
  231. (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword))
  232. throw new Exception("wrong password");
  233. responseData["accepted"] = "true";
  234. response.Value = responseData;
  235. int timeout = 2000;
  236. if (requestData.ContainsKey("shutdown") &&
  237. ((string) requestData["shutdown"] == "delayed") &&
  238. requestData.ContainsKey("milliseconds"))
  239. {
  240. timeout = (Int32) requestData["milliseconds"];
  241. m_app.SceneManager.SendGeneralMessage("Region is going down in " + ((int) (timeout/1000)).ToString() +
  242. " second(s). Please save what you are doing and log out.");
  243. }
  244. else
  245. {
  246. m_app.SceneManager.SendGeneralMessage("Region is going down now.");
  247. }
  248. // Perform shutdown
  249. Timer shutdownTimer = new Timer(timeout); // Wait before firing
  250. shutdownTimer.AutoReset = false;
  251. shutdownTimer.Elapsed += new ElapsedEventHandler(shutdownTimer_Elapsed);
  252. shutdownTimer.Start();
  253. responseData["success"] = "true";
  254. }
  255. catch (Exception e)
  256. {
  257. m_log.ErrorFormat("[RADMIN] Shutdown: failed: {0}", e.Message);
  258. m_log.DebugFormat("[RADMIN] Shutdown: failed: {0}", e.ToString());
  259. responseData["accepted"] = "false";
  260. responseData["error"] = e.Message;
  261. response.Value = responseData;
  262. }
  263. return response;
  264. }
  265. private void shutdownTimer_Elapsed(object sender, ElapsedEventArgs e)
  266. {
  267. m_app.Shutdown();
  268. }
  269. private static void checkStringParameters(XmlRpcRequest request, string[] param)
  270. {
  271. Hashtable requestData = (Hashtable) request.Params[0];
  272. foreach (string p in param)
  273. {
  274. if (!requestData.Contains(p))
  275. throw new Exception(String.Format("missing string parameter {0}", p));
  276. if (String.IsNullOrEmpty((string)requestData[p]))
  277. throw new Exception(String.Format("parameter {0} is empty", p));
  278. }
  279. }
  280. private static void checkIntegerParams(XmlRpcRequest request, string[] param)
  281. {
  282. Hashtable requestData = (Hashtable) request.Params[0];
  283. foreach (string p in param)
  284. {
  285. if (!requestData.Contains(p))
  286. throw new Exception(String.Format("missing integer parameter {0}", p));
  287. }
  288. }
  289. /// <summary>
  290. /// Create a new region.
  291. /// <summary>
  292. /// <param name="request">incoming XML RPC request</param>
  293. /// <remarks>
  294. /// XmlRpcCreateRegionMethod takes the following XMLRPC
  295. /// parameters
  296. /// <list type="table">
  297. /// <listheader><term>parameter name</term><description>description</description></listheader>
  298. /// <item><term>password</term>
  299. /// <description>admin password as set in OpenSim.ini</description></item>
  300. /// <item><term>region_name</term>
  301. /// <description>desired region name</description></item>
  302. /// <item><term>region_id</term>
  303. /// <description>(optional) desired region UUID</description></item>
  304. /// <item><term>region_x</term>
  305. /// <description>desired region X coordinate (integer)</description></item>
  306. /// <item><term>region_y</term>
  307. /// <description>desired region Y coordinate (integer)</description></item>
  308. /// <item><term>region_master_first</term>
  309. /// <description>firstname of region master</description></item>
  310. /// <item><term>region_master_last</term>
  311. /// <description>lastname of region master</description></item>
  312. /// <item><term>region_master_uuid</term>
  313. /// <description>explicit UUID to use for master avatar (optional)</description></item>
  314. /// <item><term>listen_ip</term>
  315. /// <description>internal IP address (dotted quad)</description></item>
  316. /// <item><term>listen_port</term>
  317. /// <description>internal port (integer)</description></item>
  318. /// <item><term>external_address</term>
  319. /// <description>external IP address</description></item>
  320. /// <item><term>persist</term>
  321. /// <description>if true, persist the region info
  322. /// ('true' or 'false')</description></item>
  323. /// </list>
  324. ///
  325. /// XmlRpcCreateRegionMethod returns
  326. /// <list type="table">
  327. /// <listheader><term>name</term><description>description</description></listheader>
  328. /// <item><term>success</term>
  329. /// <description>true or false</description></item>
  330. /// <item><term>error</term>
  331. /// <description>error message if success is false</description></item>
  332. /// <item><term>region_uuid</term>
  333. /// <description>UUID of the newly created region</description></item>
  334. /// <item><term>region_name</term>
  335. /// <description>name of the newly created region</description></item>
  336. /// </list>
  337. /// </remarks>
  338. public XmlRpcResponse XmlRpcCreateRegionMethod(XmlRpcRequest request)
  339. {
  340. m_log.Info("[RADMIN]: CreateRegion: new request");
  341. XmlRpcResponse response = new XmlRpcResponse();
  342. Hashtable responseData = new Hashtable();
  343. lock (this)
  344. {
  345. int m_regionLimit = m_config.GetInt("region_limit", 0);
  346. try {
  347. Hashtable requestData = (Hashtable) request.Params[0];
  348. checkStringParameters(request, new string[] { "password",
  349. "region_name",
  350. "region_master_first", "region_master_last",
  351. "region_master_password",
  352. "listen_ip", "external_address"});
  353. checkIntegerParams(request, new string[] {"region_x", "region_y", "listen_port"});
  354. // check password
  355. if (!String.IsNullOrEmpty(requiredPassword) &&
  356. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  357. // check whether we still have space left (iff we are using limits)
  358. if (m_regionLimit != 0 && m_app.SceneManager.Scenes.Count >= m_regionLimit)
  359. throw new Exception(String.Format("cannot instantiate new region, server capacity {0} already reached; delete regions first", m_regionLimit));
  360. // extract or generate region ID now
  361. Scene scene = null;
  362. UUID regionID = UUID.Zero;
  363. if (requestData.ContainsKey("region_id") &&
  364. !String.IsNullOrEmpty((string)requestData["region_id"]))
  365. {
  366. regionID = (UUID)(string)requestData["region_id"];
  367. if (m_app.SceneManager.TryGetScene(regionID, out scene))
  368. throw new Exception(String.Format("region UUID already in use by region {0}, UUID {1}, <{2},{3}>",
  369. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  370. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  371. }
  372. else
  373. {
  374. regionID = UUID.Random();
  375. m_log.DebugFormat("[RADMIN] CreateRegion: new region UUID {0}", regionID);
  376. }
  377. // create volatile or persistent region info
  378. RegionInfo region = new RegionInfo();
  379. region.RegionID = regionID;
  380. region.RegionName = (string) requestData["region_name"];
  381. region.RegionLocX = Convert.ToUInt32(requestData["region_x"]);
  382. region.RegionLocY = Convert.ToUInt32(requestData["region_y"]);
  383. // check for collisions: region name, region UUID,
  384. // region location
  385. if (m_app.SceneManager.TryGetScene(region.RegionName, out scene))
  386. throw new Exception(String.Format("region name already in use by region {0}, UUID {1}, <{2},{3}>",
  387. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  388. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  389. if (m_app.SceneManager.TryGetScene(region.RegionLocX, region.RegionLocY, out scene))
  390. throw new Exception(String.Format("region location <{0},{1}> already in use by region {2}, UUID {3}, <{4},{5}>",
  391. region.RegionLocX, region.RegionLocY,
  392. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  393. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  394. region.InternalEndPoint =
  395. new IPEndPoint(IPAddress.Parse((string) requestData["listen_ip"]), 0);
  396. region.InternalEndPoint.Port = Convert.ToInt32(requestData["listen_port"]);
  397. if (0 == region.InternalEndPoint.Port) throw new Exception("listen_port is 0");
  398. if (m_app.SceneManager.TryGetScene(region.InternalEndPoint, out scene))
  399. throw new Exception(String.Format("region internal IP {0} and port {1} already in use by region {2}, UUID {3}, <{4},{5}>",
  400. region.InternalEndPoint.Address,
  401. region.InternalEndPoint.Port,
  402. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  403. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  404. region.ExternalHostName = (string)requestData["external_address"];
  405. string masterFirst = (string)requestData["region_master_first"];
  406. string masterLast = (string)requestData["region_master_last"];
  407. string masterPassword = (string)requestData["region_master_password"];
  408. UUID userID = UUID.Zero;
  409. if (requestData.ContainsKey("region_master_uuid"))
  410. {
  411. // ok, client wants us to use an explicit UUID
  412. // regardless of what the avatar name provided
  413. userID = new UUID((string)requestData["region_master_uuid"]);
  414. }
  415. else
  416. {
  417. // no client supplied UUID: look it up...
  418. UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(masterFirst, masterLast);
  419. if (null == userProfile)
  420. {
  421. m_log.InfoFormat("master avatar does not exist, creating it");
  422. // ...or create new user
  423. userID = m_app.CommunicationsManager.UserAdminService.AddUser(
  424. masterFirst, masterLast, masterPassword, "", region.RegionLocX, region.RegionLocY);
  425. if (userID == UUID.Zero) throw new Exception(String.Format("failed to create new user {0} {1}",
  426. masterFirst, masterLast));
  427. }
  428. else
  429. {
  430. userID = userProfile.ID;
  431. }
  432. }
  433. region.MasterAvatarFirstName = masterFirst;
  434. region.MasterAvatarLastName = masterLast;
  435. region.MasterAvatarSandboxPassword = masterPassword;
  436. region.MasterAvatarAssignedUUID = userID;
  437. bool persist = Convert.ToBoolean((string)requestData["persist"]);
  438. if (persist)
  439. {
  440. // default place for region XML files is in the
  441. // Regions directory of the config dir (aka /bin)
  442. string regionConfigPath = Path.Combine(Util.configDir(), "Regions");
  443. try
  444. {
  445. // OpenSim.ini can specify a different regions dir
  446. IConfig startupConfig = (IConfig)m_configSource.Configs["Startup"];
  447. regionConfigPath = startupConfig.GetString("regionload_regionsdir", regionConfigPath).Trim();
  448. }
  449. catch (Exception)
  450. {
  451. // No INI setting recorded.
  452. }
  453. string regionXmlPath = Path.Combine(regionConfigPath,
  454. String.Format(m_config.GetString("region_file_template", "{0}x{1}-{2}.xml"),
  455. region.RegionLocX.ToString(),
  456. region.RegionLocY.ToString(),
  457. regionID.ToString(),
  458. region.InternalEndPoint.Port.ToString(),
  459. region.RegionName.Replace(" ", "_").Replace(":", "_").Replace("/", "_")));
  460. m_log.DebugFormat("[RADMIN] CreateRegion: persisting region {0} to {1}",
  461. region.RegionID, regionXmlPath);
  462. region.SaveRegionToFile("dynamic region", regionXmlPath);
  463. }
  464. m_app.CreateRegion(region);
  465. responseData["success"] = "true";
  466. responseData["region_name"] = region.RegionName;
  467. responseData["region_uuid"] = region.RegionID.ToString();
  468. response.Value = responseData;
  469. }
  470. catch (Exception e)
  471. {
  472. m_log.ErrorFormat("[RADMIN] CreateRegion: failed {0}", e.Message);
  473. m_log.DebugFormat("[RADMIN] CreateRegion: failed {0}", e.ToString());
  474. responseData["success"] = "false";
  475. responseData["error"] = e.Message;
  476. response.Value = responseData;
  477. }
  478. return response;
  479. }
  480. }
  481. /// <summary>
  482. /// Delete a new region.
  483. /// <summary>
  484. /// <param name="request">incoming XML RPC request</param>
  485. /// <remarks>
  486. /// XmlRpcCreateRegionMethod takes the following XMLRPC
  487. /// parameters
  488. /// <list type="table">
  489. /// <listheader><term>parameter name</term><description>description</description></listheader>
  490. /// <item><term>password</term>
  491. /// <description>admin password as set in OpenSim.ini</description></item>
  492. /// <item><term>region_name</term>
  493. /// <description>desired region name</description></item>
  494. /// <item><term>region_id</term>
  495. /// <description>(optional) desired region UUID</description></item>
  496. /// </list>
  497. ///
  498. /// XmlRpcCreateRegionMethod returns
  499. /// <list type="table">
  500. /// <listheader><term>name</term><description>description</description></listheader>
  501. /// <item><term>success</term>
  502. /// <description>true or false</description></item>
  503. /// <item><term>error</term>
  504. /// <description>error message if success is false</description></item>
  505. /// </list>
  506. /// </remarks>
  507. public XmlRpcResponse XmlRpcDeleteRegionMethod(XmlRpcRequest request)
  508. {
  509. m_log.Info("[RADMIN]: DeleteRegion: new request");
  510. XmlRpcResponse response = new XmlRpcResponse();
  511. Hashtable responseData = new Hashtable();
  512. lock (this)
  513. {
  514. try {
  515. Hashtable requestData = (Hashtable) request.Params[0];
  516. checkStringParameters(request, new string[] {"password", "region_name"});
  517. Scene scene = null;
  518. string regionName = (string)requestData["region_name"];
  519. if (!m_app.SceneManager.TryGetScene(regionName, out scene))
  520. throw new Exception(String.Format("region \"{0}\" does not exist", regionName));
  521. m_app.RemoveRegion(scene, true);
  522. responseData["success"] = "true";
  523. responseData["region_name"] = regionName;
  524. response.Value = responseData;
  525. }
  526. catch (Exception e)
  527. {
  528. m_log.ErrorFormat("[RADMIN] DeleteRegion: failed {0}", e.Message);
  529. m_log.DebugFormat("[RADMIN] DeleteRegion: failed {0}", e.ToString());
  530. responseData["success"] = "false";
  531. responseData["error"] = e.Message;
  532. response.Value = responseData;
  533. }
  534. return response;
  535. }
  536. }
  537. /// <summary>
  538. /// Create a new user account.
  539. /// <summary>
  540. /// <param name="request">incoming XML RPC request</param>
  541. /// <remarks>
  542. /// XmlRpcCreateUserMethod takes the following XMLRPC
  543. /// parameters
  544. /// <list type="table">
  545. /// <listheader><term>parameter name</term><description>description</description></listheader>
  546. /// <item><term>password</term>
  547. /// <description>admin password as set in OpenSim.ini</description></item>
  548. /// <item><term>user_firstname</term>
  549. /// <description>avatar's first name</description></item>
  550. /// <item><term>user_lastname</term>
  551. /// <description>avatar's last name</description></item>
  552. /// <item><term>user_password</term>
  553. /// <description>avatar's password</description></item>
  554. /// <item><term>start_region_x</term>
  555. /// <description>avatar's start region coordinates, X value</description></item>
  556. /// <item><term>start_region_y</term>
  557. /// <description>avatar's start region coordinates, Y value</description></item>
  558. /// </list>
  559. ///
  560. /// XmlRpcCreateUserMethod returns
  561. /// <list type="table">
  562. /// <listheader><term>name</term><description>description</description></listheader>
  563. /// <item><term>success</term>
  564. /// <description>true or false</description></item>
  565. /// <item><term>error</term>
  566. /// <description>error message if success is false</description></item>
  567. /// <item><term>avatar_uuid</term>
  568. /// <description>UUID of the newly created avatar
  569. /// account; UUID.Zero if failed.
  570. /// </description></item>
  571. /// </list>
  572. /// </remarks>
  573. public XmlRpcResponse XmlRpcCreateUserMethod(XmlRpcRequest request)
  574. {
  575. m_log.Info("[RADMIN]: CreateUser: new request");
  576. XmlRpcResponse response = new XmlRpcResponse();
  577. Hashtable responseData = new Hashtable();
  578. lock (this)
  579. {
  580. try
  581. {
  582. Hashtable requestData = (Hashtable) request.Params[0];
  583. // check completeness
  584. checkStringParameters(request, new string[] { "password", "user_firstname",
  585. "user_lastname", "user_password", });
  586. checkIntegerParams(request, new string[] { "start_region_x", "start_region_y" });
  587. // check password
  588. if (!String.IsNullOrEmpty(requiredPassword) &&
  589. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  590. // do the job
  591. string firstname = (string) requestData["user_firstname"];
  592. string lastname = (string) requestData["user_lastname"];
  593. string passwd = (string) requestData["user_password"];
  594. string email = ""; //Empty string for email
  595. uint regX = Convert.ToUInt32((Int32)requestData["start_region_x"]);
  596. uint regY = Convert.ToUInt32((Int32)requestData["start_region_y"]);
  597. UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(firstname, lastname);
  598. if (null != userProfile)
  599. throw new Exception(String.Format("avatar {0} {1} already exists", firstname, lastname));
  600. UUID userID = m_app.CommunicationsManager.UserAdminService.AddUser(firstname, lastname,
  601. passwd, email, regX, regY);
  602. if (userID == UUID.Zero) throw new Exception(String.Format("failed to create new user {0} {1}",
  603. firstname, lastname));
  604. responseData["success"] = "true";
  605. responseData["avatar_uuid"] = userID.ToString();
  606. response.Value = responseData;
  607. m_log.InfoFormat("[RADMIN]: CreateUser: User {0} {1} created, UUID {2}", firstname, lastname, userID);
  608. }
  609. catch (Exception e)
  610. {
  611. m_log.ErrorFormat("[RADMIN] CreateUser: failed: {0}", e.Message);
  612. m_log.DebugFormat("[RADMIN] CreateUser: failed: {0}", e.ToString());
  613. responseData["success"] = "false";
  614. responseData["avatar_uuid"] = UUID.Zero.ToString();
  615. responseData["error"] = e.Message;
  616. response.Value = responseData;
  617. }
  618. return response;
  619. }
  620. }
  621. /// <summary>
  622. /// Create a new user account.
  623. /// <summary>
  624. /// <param name="request">incoming XML RPC request</param>
  625. /// <remarks>
  626. /// XmlRpcCreateUserMethod takes the following XMLRPC
  627. /// parameters
  628. /// <list type="table">
  629. /// <listheader><term>parameter name</term><description>description</description></listheader>
  630. /// <item><term>password</term>
  631. /// <description>admin password as set in OpenSim.ini</description></item>
  632. /// <item><term>user_firstname</term>
  633. /// <description>avatar's first name</description></item>
  634. /// <item><term>user_lastname</term>
  635. /// <description>avatar's last name</description></item>
  636. /// <item><term>user_password</term>
  637. /// <description>avatar's password</description></item>
  638. /// <item><term>start_region_x</term>
  639. /// <description>avatar's start region coordinates, X value</description></item>
  640. /// <item><term>start_region_y</term>
  641. /// <description>avatar's start region coordinates, Y value</description></item>
  642. /// <item><term>user_email</term>
  643. /// <description>email of avatar</description></item>
  644. /// </list>
  645. ///
  646. /// XmlRpcCreateUserMethod returns
  647. /// <list type="table">
  648. /// <listheader><term>name</term><description>description</description></listheader>
  649. /// <item><term>success</term>
  650. /// <description>true or false</description></item>
  651. /// <item><term>error</term>
  652. /// <description>error message if success is false</description></item>
  653. /// <item><term>avatar_uuid</term>
  654. /// <description>UUID of the newly created avatar
  655. /// account; UUID.Zero if failed.
  656. /// </description></item>
  657. /// </list>
  658. /// </remarks>
  659. public XmlRpcResponse XmlRpcCreateUserMethodEmail(XmlRpcRequest request)
  660. {
  661. m_log.Info("[RADMIN]: CreateUser: new request");
  662. XmlRpcResponse response = new XmlRpcResponse();
  663. Hashtable responseData = new Hashtable();
  664. lock (this)
  665. {
  666. try
  667. {
  668. Hashtable requestData = (Hashtable)request.Params[0];
  669. // check completeness
  670. checkStringParameters(request, new string[] { "password", "user_firstname",
  671. "user_lastname", "user_password", "user_email" });
  672. checkIntegerParams(request, new string[] { "start_region_x", "start_region_y" });
  673. // check password
  674. if (!String.IsNullOrEmpty(requiredPassword) &&
  675. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  676. // do the job
  677. string firstname = (string)requestData["user_firstname"];
  678. string lastname = (string)requestData["user_lastname"];
  679. string passwd = (string)requestData["user_password"];
  680. string email = (string)requestData["user_email"];
  681. uint regX = Convert.ToUInt32((Int32)requestData["start_region_x"]);
  682. uint regY = Convert.ToUInt32((Int32)requestData["start_region_y"]);
  683. UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(firstname, lastname);
  684. if (null != userProfile)
  685. throw new Exception(String.Format("avatar {0} {1} already exists", firstname, lastname));
  686. UUID userID
  687. = m_app.CommunicationsManager.UserAdminService.AddUser(
  688. firstname, lastname, passwd, email, regX, regY);
  689. if (userID == UUID.Zero) throw new Exception(String.Format("failed to create new user {0} {1}",
  690. firstname, lastname));
  691. responseData["success"] = "true";
  692. responseData["avatar_uuid"] = userID.ToString();
  693. response.Value = responseData;
  694. m_log.InfoFormat("[RADMIN]: CreateUser: User {0} {1} created, UUID {2}", firstname, lastname, userID);
  695. }
  696. catch (Exception e)
  697. {
  698. m_log.ErrorFormat("[RADMIN] CreateUser: failed: {0}", e.Message);
  699. m_log.DebugFormat("[RADMIN] CreateUser: failed: {0}", e.ToString());
  700. responseData["success"] = "false";
  701. responseData["avatar_uuid"] = UUID.Zero.ToString();
  702. responseData["error"] = e.Message;
  703. response.Value = responseData;
  704. }
  705. return response;
  706. }
  707. }
  708. /// <summary>
  709. /// Check whether a certain user account exists.
  710. /// <summary>
  711. /// <param name="request">incoming XML RPC request</param>
  712. /// <remarks>
  713. /// XmlRpcUserExistsMethod takes the following XMLRPC
  714. /// parameters
  715. /// <list type="table">
  716. /// <listheader><term>parameter name</term><description>description</description></listheader>
  717. /// <item><term>password</term>
  718. /// <description>admin password as set in OpenSim.ini</description></item>
  719. /// <item><term>user_firstname</term>
  720. /// <description>avatar's first name</description></item>
  721. /// <item><term>user_lastname</term>
  722. /// <description>avatar's last name</description></item>
  723. /// </list>
  724. ///
  725. /// XmlRpcCreateUserMethod returns
  726. /// <list type="table">
  727. /// <listheader><term>name</term><description>description</description></listheader>
  728. /// <item><term>user_firstname</term>
  729. /// <description>avatar's first name</description></item>
  730. /// <item><term>user_lastname</term>
  731. /// <description>avatar's last name</description></item>
  732. /// <item><term>success</term>
  733. /// <description>true or false</description></item>
  734. /// <item><term>error</term>
  735. /// <description>error message if success is false</description></item>
  736. /// </list>
  737. /// </remarks>
  738. public XmlRpcResponse XmlRpcUserExistsMethod(XmlRpcRequest request)
  739. {
  740. m_log.Info("[RADMIN]: UserExists: new request");
  741. XmlRpcResponse response = new XmlRpcResponse();
  742. Hashtable responseData = new Hashtable();
  743. try
  744. {
  745. Hashtable requestData = (Hashtable) request.Params[0];
  746. // check completeness
  747. checkStringParameters(request, new string[] { "password", "user_firstname", "user_lastname"});
  748. string firstname = (string) requestData["user_firstname"];
  749. string lastname = (string) requestData["user_lastname"];
  750. UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(firstname, lastname);
  751. responseData["user_firstname"] = firstname;
  752. responseData["user_lastname"] = lastname;
  753. if (null == userProfile)
  754. responseData["success"] = false;
  755. else
  756. responseData["success"] = true;
  757. response.Value = responseData;
  758. }
  759. catch (Exception e)
  760. {
  761. m_log.ErrorFormat("[RADMIN] UserExists: failed: {0}", e.Message);
  762. m_log.DebugFormat("[RADMIN] UserExists: failed: {0}", e.ToString());
  763. responseData["success"] = "false";
  764. responseData["error"] = e.Message;
  765. response.Value = responseData;
  766. }
  767. return response;
  768. }
  769. /// <summary>
  770. /// Update the password of a user account.
  771. /// <summary>
  772. /// <param name="request">incoming XML RPC request</param>
  773. /// <remarks>
  774. /// XmlRpcUpdateUserAccountMethod takes the following XMLRPC
  775. /// parameters
  776. /// <list type="table">
  777. /// <listheader><term>parameter name</term><description>description</description></listheader>
  778. /// <item><term>password</term>
  779. /// <description>admin password as set in OpenSim.ini</description></item>
  780. /// <item><term>user_firstname</term>
  781. /// <description>avatar's first name (cannot be changed)</description></item>
  782. /// <item><term>user_lastname</term>
  783. /// <description>avatar's last name (cannot be changed)</description></item>
  784. /// <item><term>user_password</term>
  785. /// <description>avatar's password (changeable)</description></item>
  786. /// <item><term>start_region_x</term>
  787. /// <description>avatar's start region coordinates, X
  788. /// value (changeable)</description></item>
  789. /// <item><term>start_region_y</term>
  790. /// <description>avatar's start region coordinates, Y
  791. /// value (changeable)</description></item>
  792. /// </list>
  793. ///
  794. /// XmlRpcCreateUserMethod returns
  795. /// <list type="table">
  796. /// <listheader><term>name</term><description>description</description></listheader>
  797. /// <item><term>success</term>
  798. /// <description>true or false</description></item>
  799. /// <item><term>error</term>
  800. /// <description>error message if success is false</description></item>
  801. /// </list>
  802. /// </remarks>
  803. public XmlRpcResponse XmlRpcUpdateUserAccountMethod(XmlRpcRequest request)
  804. {
  805. m_log.Info("[RADMIN]: UpdateUserAccount: new request");
  806. XmlRpcResponse response = new XmlRpcResponse();
  807. Hashtable responseData = new Hashtable();
  808. lock (this)
  809. {
  810. try
  811. {
  812. Hashtable requestData = (Hashtable) request.Params[0];
  813. // check completeness
  814. checkStringParameters(request, new string[] { "password", "user_firstname",
  815. "user_lastname" });
  816. // check password
  817. if (!String.IsNullOrEmpty(requiredPassword) &&
  818. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  819. // do the job
  820. string firstname = (string) requestData["user_firstname"];
  821. string lastname = (string) requestData["user_lastname"];
  822. string passwd = String.Empty;
  823. uint? regX = null;
  824. uint? regY = null;
  825. uint? ulaX = null;
  826. uint? ulaY = null;
  827. uint? ulaZ = null;
  828. uint? usaX = null;
  829. uint? usaY = null;
  830. uint? usaZ = null;
  831. if (requestData.ContainsKey("user_password")) passwd = (string) requestData["user_password"];
  832. if (requestData.ContainsKey("start_region_x")) regX = Convert.ToUInt32((Int32)requestData["start_region_x"]);
  833. if (requestData.ContainsKey("start_region_y")) regY = Convert.ToUInt32((Int32)requestData["start_region_y"]);
  834. if (requestData.ContainsKey("start_lookat_x")) ulaY = Convert.ToUInt32((Int32)requestData["start_lookat_x"]);
  835. if (requestData.ContainsKey("start_lookat_y")) ulaY = Convert.ToUInt32((Int32)requestData["start_lookat_y"]);
  836. if (requestData.ContainsKey("start_lookat_z")) ulaY = Convert.ToUInt32((Int32)requestData["start_lookat_z"]);
  837. if (requestData.ContainsKey("start_standat_x")) usaY = Convert.ToUInt32((Int32)requestData["start_standat_x"]);
  838. if (requestData.ContainsKey("start_standat_y")) usaY = Convert.ToUInt32((Int32)requestData["start_standat_y"]);
  839. if (requestData.ContainsKey("start_standat_z")) usaY = Convert.ToUInt32((Int32)requestData["start_standat_z"]);
  840. UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(firstname, lastname);
  841. if (null == userProfile)
  842. throw new Exception(String.Format("avatar {0} {1} does not exist", firstname, lastname));
  843. if (null != passwd)
  844. {
  845. string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(passwd) + ":" + String.Empty);
  846. userProfile.PasswordHash = md5PasswdHash;
  847. }
  848. if (null != regX) userProfile.HomeRegionX = (uint)regX;
  849. if (null != regY) userProfile.HomeRegionY = (uint)regY;
  850. if (null != usaX) userProfile.HomeLocationX = (uint)usaX;
  851. if (null != usaY) userProfile.HomeLocationY = (uint)usaY;
  852. if (null != usaZ) userProfile.HomeLocationZ = (uint)usaZ;
  853. if (null != ulaX) userProfile.HomeLookAtX = (uint)ulaX;
  854. if (null != ulaY) userProfile.HomeLookAtY = (uint)ulaY;
  855. if (null != ulaZ) userProfile.HomeLookAtZ = (uint)ulaZ;
  856. if (!m_app.CommunicationsManager.UserService.UpdateUserProfile(userProfile))
  857. throw new Exception("did not manage to update user profile");
  858. responseData["success"] = "true";
  859. response.Value = responseData;
  860. m_log.InfoFormat("[RADMIN]: UpdateUserAccount: account for user {0} {1} updated, UUID {2}", firstname, lastname,
  861. userProfile.ID);
  862. }
  863. catch (Exception e)
  864. {
  865. m_log.ErrorFormat("[RADMIN] UpdateUserAccount: failed: {0}", e.Message);
  866. m_log.DebugFormat("[RADMIN] UpdateUserAccount: failed: {0}", e.ToString());
  867. responseData["success"] = "false";
  868. responseData["error"] = e.Message;
  869. response.Value = responseData;
  870. }
  871. }
  872. return response;
  873. }
  874. /// <summary>
  875. /// Load an OAR file into a region..
  876. /// <summary>
  877. /// <param name="request">incoming XML RPC request</param>
  878. /// <remarks>
  879. /// XmlRpcLoadOARMethod takes the following XMLRPC
  880. /// parameters
  881. /// <list type="table">
  882. /// <listheader><term>parameter name</term><description>description</description></listheader>
  883. /// <item><term>password</term>
  884. /// <description>admin password as set in OpenSim.ini</description></item>
  885. /// <item><term>filename</term>
  886. /// <description>file name of the OAR file</description></item>
  887. /// <item><term>region_uuid</term>
  888. /// <description>UUID of the region</description></item>
  889. /// <item><term>region_name</term>
  890. /// <description>region name</description></item>
  891. /// </list>
  892. ///
  893. /// <code>region_uuid</code> takes precedence over
  894. /// <code>region_name</code> if both are present; one of both
  895. /// must be present.
  896. ///
  897. /// XmlRpcLoadOARMethod returns
  898. /// <list type="table">
  899. /// <listheader><term>name</term><description>description</description></listheader>
  900. /// <item><term>success</term>
  901. /// <description>true or false</description></item>
  902. /// <item><term>error</term>
  903. /// <description>error message if success is false</description></item>
  904. /// </list>
  905. /// </remarks>
  906. public XmlRpcResponse XmlRpcLoadOARMethod(XmlRpcRequest request)
  907. {
  908. m_log.Info("[RADMIN]: Received Load OAR Administrator Request");
  909. XmlRpcResponse response = new XmlRpcResponse();
  910. Hashtable responseData = new Hashtable();
  911. lock (this)
  912. {
  913. try
  914. {
  915. Hashtable requestData = (Hashtable) request.Params[0];
  916. // check completeness
  917. foreach (string p in new string[] { "password", "filename" })
  918. {
  919. if (!requestData.Contains(p))
  920. throw new Exception(String.Format("missing parameter {0}", p));
  921. if (String.IsNullOrEmpty((string)requestData[p]))
  922. throw new Exception(String.Format("parameter {0} is empty"));
  923. }
  924. // check password
  925. if (!String.IsNullOrEmpty(requiredPassword) &&
  926. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  927. string filename = (string)requestData["filename"];
  928. Scene scene = null;
  929. if (requestData.Contains("region_uuid"))
  930. {
  931. UUID region_uuid = (UUID)(string)requestData["region_uuid"];
  932. if (!m_app.SceneManager.TryGetScene(region_uuid, out scene))
  933. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  934. }
  935. else if (requestData.Contains("region_name"))
  936. {
  937. string region_name = (string)requestData["region_name"];
  938. if (!m_app.SceneManager.TryGetScene(region_name, out scene))
  939. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  940. }
  941. else throw new Exception("neither region_name nor region_uuid given");
  942. IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>();
  943. if (archiver != null)
  944. archiver.DearchiveRegion(filename);
  945. else
  946. throw new Exception("Archiver module not present for scene");
  947. responseData["loaded"] = "true";
  948. response.Value = responseData;
  949. }
  950. catch (Exception e)
  951. {
  952. m_log.InfoFormat("[RADMIN] LoadOAR: {0}", e.Message);
  953. m_log.DebugFormat("[RADMIN] LoadOAR: {0}", e.ToString());
  954. responseData["loaded"] = "false";
  955. responseData["error"] = e.Message;
  956. response.Value = responseData;
  957. }
  958. return response;
  959. }
  960. }
  961. /// <summary>
  962. /// Save a region to an OAR file
  963. /// <summary>
  964. /// <param name="request">incoming XML RPC request</param>
  965. /// <remarks>
  966. /// XmlRpcSaveOARMethod takes the following XMLRPC
  967. /// parameters
  968. /// <list type="table">
  969. /// <listheader><term>parameter name</term><description>description</description></listheader>
  970. /// <item><term>password</term>
  971. /// <description>admin password as set in OpenSim.ini</description></item>
  972. /// <item><term>filename</term>
  973. /// <description>file name for the OAR file</description></item>
  974. /// <item><term>region_uuid</term>
  975. /// <description>UUID of the region</description></item>
  976. /// <item><term>region_name</term>
  977. /// <description>region name</description></item>
  978. /// </list>
  979. ///
  980. /// <code>region_uuid</code> takes precedence over
  981. /// <code>region_name</code> if both are present; one of both
  982. /// must be present.
  983. ///
  984. /// XmlRpcLoadOARMethod returns
  985. /// <list type="table">
  986. /// <listheader><term>name</term><description>description</description></listheader>
  987. /// <item><term>success</term>
  988. /// <description>true or false</description></item>
  989. /// <item><term>error</term>
  990. /// <description>error message if success is false</description></item>
  991. /// </list>
  992. /// </remarks>
  993. public XmlRpcResponse XmlRpcSaveOARMethod(XmlRpcRequest request)
  994. {
  995. m_log.Info("[RADMIN]: Received Save OAR Administrator Request");
  996. XmlRpcResponse response = new XmlRpcResponse();
  997. Hashtable responseData = new Hashtable();
  998. try
  999. {
  1000. Hashtable requestData = (Hashtable) request.Params[0];
  1001. // check completeness
  1002. foreach (string p in new string[] { "password", "filename" })
  1003. {
  1004. if (!requestData.Contains(p))
  1005. throw new Exception(String.Format("missing parameter {0}", p));
  1006. if (String.IsNullOrEmpty((string)requestData[p]))
  1007. throw new Exception(String.Format("parameter {0} is empty"));
  1008. }
  1009. // check password
  1010. if (!String.IsNullOrEmpty(requiredPassword) &&
  1011. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  1012. string filename = (string)requestData["filename"];
  1013. Scene scene = null;
  1014. if (requestData.Contains("region_uuid"))
  1015. {
  1016. UUID region_uuid = (UUID)(string)requestData["region_uuid"];
  1017. if (!m_app.SceneManager.TryGetScene(region_uuid, out scene))
  1018. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  1019. }
  1020. else if (requestData.Contains("region_name"))
  1021. {
  1022. string region_name = (string)requestData["region_name"];
  1023. if (!m_app.SceneManager.TryGetScene(region_name, out scene))
  1024. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1025. }
  1026. else throw new Exception("neither region_name nor region_uuid given");
  1027. IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>();
  1028. if (archiver != null)
  1029. archiver.ArchiveRegion(filename);
  1030. else
  1031. throw new Exception("Archiver module not present for scene");
  1032. responseData["saved"] = "true";
  1033. response.Value = responseData;
  1034. }
  1035. catch (Exception e)
  1036. {
  1037. m_log.InfoFormat("[RADMIN] SaveOAR: {0}", e.Message);
  1038. m_log.DebugFormat("[RADMIN] SaveOAR: {0}", e.ToString());
  1039. responseData["saved"] = "false";
  1040. responseData["error"] = e.Message;
  1041. response.Value = responseData;
  1042. }
  1043. return response;
  1044. }
  1045. public XmlRpcResponse XmlRpcLoadXMLMethod(XmlRpcRequest request)
  1046. {
  1047. m_log.Info("[RADMIN]: Received Load XML Administrator Request");
  1048. XmlRpcResponse response = new XmlRpcResponse();
  1049. Hashtable responseData = new Hashtable();
  1050. lock (this)
  1051. {
  1052. try
  1053. {
  1054. Hashtable requestData = (Hashtable) request.Params[0];
  1055. // check completeness
  1056. foreach (string p in new string[] { "password", "filename" })
  1057. {
  1058. if (!requestData.Contains(p))
  1059. throw new Exception(String.Format("missing parameter {0}", p));
  1060. if (String.IsNullOrEmpty((string)requestData[p]))
  1061. throw new Exception(String.Format("parameter {0} is empty"));
  1062. }
  1063. // check password
  1064. if (!String.IsNullOrEmpty(requiredPassword) &&
  1065. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  1066. string filename = (string)requestData["filename"];
  1067. if (requestData.Contains("region_uuid"))
  1068. {
  1069. UUID region_uuid = (UUID)(string)requestData["region_uuid"];
  1070. if (!m_app.SceneManager.TrySetCurrentScene(region_uuid))
  1071. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  1072. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString());
  1073. }
  1074. else if (requestData.Contains("region_name"))
  1075. {
  1076. string region_name = (string)requestData["region_name"];
  1077. if (!m_app.SceneManager.TrySetCurrentScene(region_name))
  1078. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1079. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_name);
  1080. }
  1081. else throw new Exception("neither region_name nor region_uuid given");
  1082. responseData["switched"] = "true";
  1083. string xml_version = "1";
  1084. if (requestData.Contains("xml_version"))
  1085. {
  1086. xml_version = (string)requestData["xml_version"];
  1087. }
  1088. switch (xml_version)
  1089. {
  1090. case "1":
  1091. m_app.SceneManager.LoadCurrentSceneFromXml(filename, true, new Vector3(0, 0, 0));
  1092. break;
  1093. case "2":
  1094. m_app.SceneManager.LoadCurrentSceneFromXml2(filename);
  1095. break;
  1096. default:
  1097. throw new Exception(String.Format("unknown Xml{0} format", xml_version));
  1098. }
  1099. responseData["loaded"] = "true";
  1100. response.Value = responseData;
  1101. }
  1102. catch (Exception e)
  1103. {
  1104. m_log.InfoFormat("[RADMIN] LoadXml: {0}", e.Message);
  1105. m_log.DebugFormat("[RADMIN] LoadXml: {0}", e.ToString());
  1106. responseData["loaded"] = "false";
  1107. responseData["switched"] = "false";
  1108. responseData["error"] = e.Message;
  1109. response.Value = responseData;
  1110. }
  1111. return response;
  1112. }
  1113. }
  1114. public XmlRpcResponse XmlRpcSaveXMLMethod(XmlRpcRequest request)
  1115. {
  1116. m_log.Info("[RADMIN]: Received Save XML Administrator Request");
  1117. XmlRpcResponse response = new XmlRpcResponse();
  1118. Hashtable responseData = new Hashtable();
  1119. try
  1120. {
  1121. Hashtable requestData = (Hashtable)request.Params[0];
  1122. // check completeness
  1123. foreach (string p in new string[] { "password", "filename" })
  1124. {
  1125. if (!requestData.Contains(p))
  1126. throw new Exception(String.Format("missing parameter {0}", p));
  1127. if (String.IsNullOrEmpty((string)requestData[p]))
  1128. throw new Exception(String.Format("parameter {0} is empty"));
  1129. }
  1130. // check password
  1131. if (!String.IsNullOrEmpty(requiredPassword) &&
  1132. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  1133. string filename = (string)requestData["filename"];
  1134. if (requestData.Contains("region_uuid"))
  1135. {
  1136. UUID region_uuid = (UUID)(string)requestData["region_uuid"];
  1137. if (!m_app.SceneManager.TrySetCurrentScene(region_uuid))
  1138. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  1139. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString());
  1140. }
  1141. else if (requestData.Contains("region_name"))
  1142. {
  1143. string region_name = (string)requestData["region_name"];
  1144. if (!m_app.SceneManager.TrySetCurrentScene(region_name))
  1145. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1146. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_name);
  1147. }
  1148. else throw new Exception("neither region_name nor region_uuid given");
  1149. responseData["switched"] = "true";
  1150. string xml_version = "1";
  1151. if (requestData.Contains("xml_version"))
  1152. {
  1153. xml_version = (string)requestData["xml_version"];
  1154. }
  1155. switch (xml_version)
  1156. {
  1157. case "1":
  1158. m_app.SceneManager.SaveCurrentSceneToXml(filename);
  1159. break;
  1160. case "2":
  1161. m_app.SceneManager.SaveCurrentSceneToXml2(filename);
  1162. break;
  1163. default:
  1164. throw new Exception(String.Format("unknown Xml{0} format", xml_version));
  1165. }
  1166. responseData["saved"] = "true";
  1167. response.Value = responseData;
  1168. }
  1169. catch (Exception e)
  1170. {
  1171. m_log.InfoFormat("[RADMIN] SaveXml: {0}", e.Message);
  1172. m_log.DebugFormat("[RADMIN] SaveXml: {0}", e.ToString());
  1173. responseData["saved"] = "false";
  1174. responseData["switched"] = "false";
  1175. responseData["error"] = e.Message;
  1176. response.Value = responseData;
  1177. }
  1178. return response;
  1179. }
  1180. public XmlRpcResponse XmlRpcRegionQueryMethod(XmlRpcRequest request)
  1181. {
  1182. m_log.Info("[RADMIN]: Received Query XML Administrator Request");
  1183. XmlRpcResponse response = new XmlRpcResponse();
  1184. Hashtable responseData = new Hashtable();
  1185. try
  1186. {
  1187. responseData["success"] = "true";
  1188. Hashtable requestData = (Hashtable)request.Params[0];
  1189. // check completeness
  1190. if (!requestData.Contains("password"))
  1191. throw new Exception(String.Format("missing required parameter"));
  1192. if (!String.IsNullOrEmpty(requiredPassword) &&
  1193. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  1194. if (requestData.Contains("region_uuid"))
  1195. {
  1196. UUID region_uuid = (UUID)(string)requestData["region_uuid"];
  1197. if (!m_app.SceneManager.TrySetCurrentScene(region_uuid))
  1198. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  1199. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString());
  1200. }
  1201. else if (requestData.Contains("region_name"))
  1202. {
  1203. string region_name = (string)requestData["region_name"];
  1204. if (!m_app.SceneManager.TrySetCurrentScene(region_name))
  1205. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1206. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_name);
  1207. }
  1208. else throw new Exception("neither region_name nor region_uuid given");
  1209. Scene s = m_app.SceneManager.CurrentScene;
  1210. int health = s.GetHealth();
  1211. responseData["health"] = health;
  1212. response.Value = responseData;
  1213. }
  1214. catch (Exception e)
  1215. {
  1216. m_log.InfoFormat("[RADMIN] RegionQuery: {0}", e.Message);
  1217. responseData["success"] = "false";
  1218. responseData["error"] = e.Message;
  1219. response.Value = responseData;
  1220. }
  1221. return response;
  1222. }
  1223. public void Dispose()
  1224. {
  1225. }
  1226. }
  1227. }