RemoteAdminPlugin.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  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 libsecondlife;
  34. using log4net;
  35. using Mono.Addins;
  36. using Nwc.XmlRpc;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Servers;
  39. using OpenSim.Region.Environment.Modules.World.Terrain;
  40. using OpenSim.Region.Environment.Scenes;
  41. [assembly : Addin]
  42. [assembly : AddinDependency("OpenSim", "0.5")]
  43. namespace OpenSim.ApplicationPlugins.RemoteController
  44. {
  45. [Extension("/OpenSim/Startup")]
  46. public class RemoteAdminPlugin : IApplicationPlugin
  47. {
  48. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. private OpenSimBase m_app;
  50. private BaseHttpServer m_httpd;
  51. private string requiredPassword = String.Empty;
  52. // TODO: required by IPlugin, but likely not at all right
  53. string m_name = "RemoteAdminPlugin";
  54. string m_version = "0.0";
  55. public string Version { get { return m_version; } }
  56. public string Name { get { return m_name; } }
  57. public void Initialise()
  58. {
  59. m_log.Info("[RADMIN]: " + Name + " cannot be default-initialized!");
  60. throw new PluginNotInitialisedException (Name);
  61. }
  62. public void Initialise(OpenSimBase openSim)
  63. {
  64. try
  65. {
  66. if (openSim.ConfigSource.Source.Configs["RemoteAdmin"] != null &&
  67. openSim.ConfigSource.Source.Configs["RemoteAdmin"].GetBoolean("enabled", false))
  68. {
  69. m_log.Info("[RADMIN]: Remote Admin Plugin Enabled");
  70. requiredPassword = openSim.ConfigSource.Source.Configs["RemoteAdmin"].GetString("access_password", String.Empty);
  71. m_app = openSim;
  72. m_httpd = openSim.HttpServer;
  73. m_httpd.AddXmlRPCHandler("admin_create_region", XmlRpcCreateRegionMethod);
  74. m_httpd.AddXmlRPCHandler("admin_shutdown", XmlRpcShutdownMethod);
  75. m_httpd.AddXmlRPCHandler("admin_broadcast", XmlRpcAlertMethod);
  76. m_httpd.AddXmlRPCHandler("admin_restart", XmlRpcRestartMethod);
  77. m_httpd.AddXmlRPCHandler("admin_load_heightmap", XmlRpcLoadHeightmapMethod);
  78. m_httpd.AddXmlRPCHandler("admin_create_user", XmlRpcCreateUserMethod);
  79. m_httpd.AddXmlRPCHandler("admin_update_user", XmlRpcUpdateUserAccountMethod);
  80. m_httpd.AddXmlRPCHandler("admin_load_xml", XmlRpcLoadXMLMethod);
  81. }
  82. }
  83. catch (NullReferenceException)
  84. {
  85. // Ignore.
  86. }
  87. }
  88. public XmlRpcResponse XmlRpcRestartMethod(XmlRpcRequest request)
  89. {
  90. XmlRpcResponse response = new XmlRpcResponse();
  91. Hashtable responseData = new Hashtable();
  92. try {
  93. Hashtable requestData = (Hashtable) request.Params[0];
  94. m_log.Info("[RADMIN]: Request to restart Region.");
  95. checkStringParameters(request, new string[] { "password", "regionID" });
  96. if (requiredPassword != String.Empty &&
  97. (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword))
  98. throw new Exception("wrong password");
  99. LLUUID regionID = new LLUUID((string) requestData["regionID"]);
  100. responseData["accepted"] = "true";
  101. response.Value = responseData;
  102. Scene rebootedScene;
  103. if (!m_app.SceneManager.TryGetScene(regionID, out rebootedScene))
  104. throw new Exception("region not found");
  105. responseData["rebooting"] = "true";
  106. rebootedScene.Restart(30);
  107. }
  108. catch(Exception e)
  109. {
  110. m_log.ErrorFormat("[RADMIN]: Restart region: failed: {0}", e.Message);
  111. m_log.DebugFormat("[RADMIN]: Restart region: failed: {0}", e.ToString());
  112. responseData["accepted"] = "false";
  113. responseData["success"] = "false";
  114. responseData["rebooting"] = "false";
  115. responseData["error"] = e.Message;
  116. response.Value = responseData;
  117. }
  118. return response;
  119. }
  120. public XmlRpcResponse XmlRpcAlertMethod(XmlRpcRequest request)
  121. {
  122. XmlRpcResponse response = new XmlRpcResponse();
  123. Hashtable responseData = new Hashtable();
  124. try {
  125. Hashtable requestData = (Hashtable) request.Params[0];
  126. checkStringParameters(request, new string[] { "password", "message" });
  127. if (requiredPassword != String.Empty &&
  128. (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword))
  129. throw new Exception("wrong password");
  130. string message = (string) requestData["message"];
  131. m_log.InfoFormat("[RADMIN]: Broadcasting: {0}", message);
  132. responseData["accepted"] = "true";
  133. response.Value = responseData;
  134. m_app.SceneManager.SendGeneralMessage(message);
  135. }
  136. catch(Exception e)
  137. {
  138. m_log.ErrorFormat("[RADMIN]: Broadcasting: failed: {0}", e.Message);
  139. m_log.DebugFormat("[RADMIN]: Broadcasting: failed: {0}", e.ToString());
  140. responseData["accepted"] = "false";
  141. responseData["success"] = "false";
  142. responseData["error"] = e.Message;
  143. response.Value = responseData;
  144. }
  145. return response;
  146. }
  147. public XmlRpcResponse XmlRpcLoadHeightmapMethod(XmlRpcRequest request)
  148. {
  149. XmlRpcResponse response = new XmlRpcResponse();
  150. Hashtable responseData = new Hashtable();
  151. try {
  152. Hashtable requestData = (Hashtable)request.Params[0];
  153. m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}", request.ToString());
  154. // foreach (string k in requestData.Keys)
  155. // {
  156. // m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}: >{1}< {2}",
  157. // k, (string)requestData[k], ((string)requestData[k]).Length);
  158. // }
  159. checkStringParameters(request, new string[] { "password", "filename", "regionid"});
  160. if (requiredPassword != String.Empty &&
  161. (!requestData.Contains("password") || (string)requestData["password"] != requiredPassword))
  162. throw new Exception("wrong password");
  163. string file = (string)requestData["filename"];
  164. LLUUID regionID = (string) requestData["regionid"];
  165. m_log.InfoFormat("[RADMIN]: Terrain Loading: {0}", file);
  166. responseData["accepted"] = "true";
  167. Scene region = null;
  168. if (!m_app.SceneManager.TryGetScene(regionID, out region))
  169. throw new Exception("1: unable to get a scene with that name");
  170. ITerrainModule terrainModule = region.RequestModuleInterface<ITerrainModule>();
  171. if (null == terrainModule) throw new Exception("terrain module not available");
  172. terrainModule.LoadFromFile(file);
  173. responseData["success"] = "true";
  174. response.Value = responseData;
  175. }
  176. catch (Exception e)
  177. {
  178. m_log.ErrorFormat("[RADMIN] Terrain Loading: failed: {0}", e.Message);
  179. m_log.DebugFormat("[RADMIN] Terrain Loading: failed: {0}", e.ToString());
  180. responseData["success"] = "false";
  181. responseData["error"] = e.Message;
  182. }
  183. return response;
  184. }
  185. public XmlRpcResponse XmlRpcShutdownMethod(XmlRpcRequest request)
  186. {
  187. m_log.Info("[RADMIN]: Received Shutdown Administrator Request");
  188. XmlRpcResponse response = new XmlRpcResponse();
  189. Hashtable responseData = new Hashtable();
  190. try {
  191. Hashtable requestData = (Hashtable) request.Params[0];
  192. if (requiredPassword != String.Empty &&
  193. (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword))
  194. throw new Exception("wrong password");
  195. responseData["accepted"] = "true";
  196. response.Value = responseData;
  197. int timeout = 2000;
  198. if (requestData.ContainsKey("shutdown") &&
  199. ((string) requestData["shutdown"] == "delayed") &&
  200. requestData.ContainsKey("milliseconds"))
  201. {
  202. timeout = (Int32) requestData["milliseconds"];
  203. m_app.SceneManager.SendGeneralMessage("Region is going down in " + ((int) (timeout/1000)).ToString() +
  204. " second(s). Please save what you are doing and log out.");
  205. }
  206. else
  207. {
  208. m_app.SceneManager.SendGeneralMessage("Region is going down now.");
  209. }
  210. // Perform shutdown
  211. Timer shutdownTimer = new Timer(timeout); // Wait before firing
  212. shutdownTimer.AutoReset = false;
  213. shutdownTimer.Elapsed += new ElapsedEventHandler(shutdownTimer_Elapsed);
  214. shutdownTimer.Start();
  215. responseData["success"] = "true";
  216. }
  217. catch (Exception e)
  218. {
  219. m_log.ErrorFormat("[RADMIN] Shutdown: failed: {0}", e.Message);
  220. m_log.DebugFormat("[RADMIN] Shutdown: failed: {0}", e.ToString());
  221. responseData["accepted"] = "false";
  222. responseData["error"] = e.Message;
  223. response.Value = responseData;
  224. }
  225. return response;
  226. }
  227. private void shutdownTimer_Elapsed(object sender, ElapsedEventArgs e)
  228. {
  229. m_app.Shutdown();
  230. }
  231. private static void checkStringParameters(XmlRpcRequest request, string[] param)
  232. {
  233. Hashtable requestData = (Hashtable) request.Params[0];
  234. foreach (string p in param)
  235. {
  236. if (!requestData.Contains(p))
  237. throw new Exception(String.Format("missing string parameter {0}", p));
  238. if (String.IsNullOrEmpty((string)requestData[p]))
  239. throw new Exception(String.Format("parameter {0} is empty", p));
  240. }
  241. }
  242. private static void checkIntegerParams(XmlRpcRequest request, string[] param)
  243. {
  244. Hashtable requestData = (Hashtable) request.Params[0];
  245. foreach (string p in param)
  246. {
  247. if (!requestData.Contains(p))
  248. throw new Exception(String.Format("missing integer parameter {0}", p));
  249. }
  250. }
  251. /// <summary>
  252. /// Create a new region.
  253. /// <summary>
  254. /// <param name="request">incoming XML RPC request</param>
  255. /// <remarks>
  256. /// XmlRpcCreateRegionMethod takes the following XMLRPC
  257. /// parameters
  258. /// <list type="table">
  259. /// <listheader><term>parameter name</term><description>description</description></listheader>
  260. /// <item><term>password</term>
  261. /// <description>admin password as set in OpenSim.ini</description></item>
  262. /// <item><term>region_name</term>
  263. /// <description>desired region name</description></item>
  264. /// <item><term>region_id</term>
  265. /// <description>(optional) desired region UUID</description></item>
  266. /// <item><term>region_x</term>
  267. /// <description>desired region X coordinate (integer)</description></item>
  268. /// <item><term>region_y</term>
  269. /// <description>desired region Y coordinate (integer)</description></item>
  270. /// <item><term>region_master_first</term>
  271. /// <description>firstname of region master</description></item>
  272. /// <item><term>region_master_last</term>
  273. /// <description>lastname of region master</description></item>
  274. /// <item><term>listen_ip</term>
  275. /// <description>internal IP address (dotted quad)</description></item>
  276. /// <item><term>listen_port</term>
  277. /// <description>internal port (integer)</description></item>
  278. /// <item><term>external_address</term>
  279. /// <description>external IP address</description></item>
  280. /// <item><term>datastore</term>
  281. /// <description>datastore parameter (?)</description></item>
  282. /// <item><term>persist</term>
  283. /// <description>if true, persist the region info
  284. /// ('true' or 'false')</description></item>
  285. /// </list>
  286. ///
  287. /// XmlRpcCreateRegionMethod returns
  288. /// <list type="table">
  289. /// <listheader><term>name</term><description>description</description></listheader>
  290. /// <item><term>success</term>
  291. /// <description>true or false</description></item>
  292. /// <item><term>error</term>
  293. /// <description>error message if success is false</description></item>
  294. /// <item><term>region_uuid</term>
  295. /// <description>UUID of the newly created region</description></item>
  296. /// <item><term>region_name</term>
  297. /// <description>name of the newly created region</description></item>
  298. /// </list>
  299. /// </remarks>
  300. public XmlRpcResponse XmlRpcCreateRegionMethod(XmlRpcRequest request)
  301. {
  302. m_log.Info("[RADMIN]: CreateRegion: new request");
  303. XmlRpcResponse response = new XmlRpcResponse();
  304. Hashtable responseData = new Hashtable();
  305. try {
  306. Hashtable requestData = (Hashtable) request.Params[0];
  307. checkStringParameters(request, new string[] { "password",
  308. "region_name",
  309. "region_master_first", "region_master_last",
  310. "region_master_password",
  311. "listen_ip", "external_address"});
  312. checkIntegerParams(request, new string[] { "region_x", "region_y", "listen_port"});
  313. // check password
  314. if (!String.IsNullOrEmpty(requiredPassword) &&
  315. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  316. // extract or generate region ID now
  317. Scene scene = null;
  318. LLUUID regionID = LLUUID.Zero;
  319. if (requestData.ContainsKey("region_id") &&
  320. !String.IsNullOrEmpty((string)requestData["region_id"]))
  321. {
  322. regionID = (string) requestData["region_id"];
  323. if (m_app.SceneManager.TryGetScene(regionID, out scene))
  324. throw new Exception(String.Format("region UUID already in use by region {0}, UUID {1}, <{2},{3}>",
  325. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  326. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  327. }
  328. else
  329. {
  330. regionID = LLUUID.Random();
  331. m_log.DebugFormat("[RADMIN] CreateRegion: new region UUID {0}", regionID);
  332. }
  333. // create volatile or persistent region info
  334. RegionInfo region = new RegionInfo();
  335. region.RegionID = regionID;
  336. region.RegionName = (string) requestData["region_name"];
  337. region.RegionLocX = Convert.ToUInt32(requestData["region_x"]);
  338. region.RegionLocY = Convert.ToUInt32(requestData["region_y"]);
  339. // check for collisions: region name, region UUID,
  340. // region location
  341. if (m_app.SceneManager.TryGetScene(region.RegionName, out scene))
  342. throw new Exception(String.Format("region name already in use by region {0}, UUID {1}, <{2},{3}>",
  343. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  344. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  345. if (m_app.SceneManager.TryGetScene(region.RegionLocX, region.RegionLocY, out scene))
  346. throw new Exception(String.Format("region location <{0},{1}> already in use by region {2}, UUID {3}, <{4},{5}>",
  347. region.RegionLocX, region.RegionLocY,
  348. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  349. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  350. // Security risk [and apparently not used]
  351. // if (requestData.ContainsKey("datastore"))
  352. // region.DataStore = (string) requestData["datastore"];
  353. region.InternalEndPoint =
  354. new IPEndPoint(IPAddress.Parse((string) requestData["listen_ip"]), 0);
  355. region.InternalEndPoint.Port = Convert.ToInt32(requestData["listen_port"]);
  356. if (0 == region.InternalEndPoint.Port) throw new Exception("listen_port is 0");
  357. if (m_app.SceneManager.TryGetScene(region.InternalEndPoint, out scene))
  358. throw new Exception(String.Format("region internal IP {0} and port {1} already in use by region {2}, UUID {3}, <{4},{5}>",
  359. region.InternalEndPoint.Address,
  360. region.InternalEndPoint.Port,
  361. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  362. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  363. region.ExternalHostName = (string) requestData["external_address"];
  364. region.MasterAvatarFirstName = (string) requestData["region_master_first"];
  365. region.MasterAvatarLastName = (string) requestData["region_master_last"];
  366. region.MasterAvatarSandboxPassword = (string) requestData["region_master_password"];
  367. bool persist = Convert.ToBoolean((string)requestData["persist"]);
  368. if (persist)
  369. {
  370. string regionConfigPath = Path.Combine(Path.Combine(Util.configDir(), "Regions"),
  371. String.Format("{0}x{1}-{2}.xml",
  372. region.RegionLocX.ToString(),
  373. region.RegionLocY.ToString(),
  374. regionID.ToString()));
  375. m_log.DebugFormat("[RADMIN] CreateRegion: persisting region {0} to {1}",
  376. region.RegionID, regionConfigPath);
  377. region.SaveRegionToFile("dynamic region", regionConfigPath);
  378. }
  379. m_app.CreateRegion(region);
  380. responseData["success"] = "true";
  381. responseData["region_name"] = region.RegionName;
  382. responseData["region_uuid"] = region.RegionID.ToString();
  383. response.Value = responseData;
  384. }
  385. catch (Exception e)
  386. {
  387. m_log.ErrorFormat("[RADMIN] CreateRegion: failed {0}", e.Message);
  388. m_log.DebugFormat("[RADMIN] CreateRegion: failed {0}", e.ToString());
  389. responseData["success"] = "false";
  390. responseData["error"] = e.Message;
  391. response.Value = responseData;
  392. }
  393. return response;
  394. }
  395. /// <summary>
  396. /// Create a new user account.
  397. /// <summary>
  398. /// <param name="request">incoming XML RPC request</param>
  399. /// <remarks>
  400. /// XmlRpcCreateUserMethod takes the following XMLRPC
  401. /// parameters
  402. /// <list type="table">
  403. /// <listheader><term>parameter name</term><description>description</description></listheader>
  404. /// <item><term>password</term>
  405. /// <description>admin password as set in OpenSim.ini</description></item>
  406. /// <item><term>user_firstname</term>
  407. /// <description>avatar's first name</description></item>
  408. /// <item><term>user_lastname</term>
  409. /// <description>avatar's last name</description></item>
  410. /// <item><term>user_password</term>
  411. /// <description>avatar's password</description></item>
  412. /// <item><term>start_region_x</term>
  413. /// <description>avatar's start region coordinates, X value</description></item>
  414. /// <item><term>start_region_y</term>
  415. /// <description>avatar's start region coordinates, Y value</description></item>
  416. /// </list>
  417. ///
  418. /// XmlRpcCreateUserMethod returns
  419. /// <list type="table">
  420. /// <listheader><term>name</term><description>description</description></listheader>
  421. /// <item><term>success</term>
  422. /// <description>true or false</description></item>
  423. /// <item><term>error</term>
  424. /// <description>error message if success is false</description></item>
  425. /// <item><term>avatar_uuid</term>
  426. /// <description>UUID of the newly created avatar
  427. /// account; LLUUID.Zero if failed.
  428. /// </description></item>
  429. /// </list>
  430. /// </remarks>
  431. public XmlRpcResponse XmlRpcCreateUserMethod(XmlRpcRequest request)
  432. {
  433. m_log.Info("[RADMIN]: CreateUser: new request");
  434. XmlRpcResponse response = new XmlRpcResponse();
  435. Hashtable responseData = new Hashtable();
  436. try
  437. {
  438. Hashtable requestData = (Hashtable) request.Params[0];
  439. // check completeness
  440. checkStringParameters(request, new string[] { "password", "user_firstname",
  441. "user_lastname", "user_password" });
  442. checkIntegerParams(request, new string[] { "start_region_x", "start_region_y" });
  443. // check password
  444. if (!String.IsNullOrEmpty(requiredPassword) &&
  445. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  446. // do the job
  447. string firstname = (string) requestData["user_firstname"];
  448. string lastname = (string) requestData["user_lastname"];
  449. string passwd = (string) requestData["user_password"];
  450. uint regX = Convert.ToUInt32((Int32)requestData["start_region_x"]);
  451. uint regY = Convert.ToUInt32((Int32)requestData["start_region_y"]);
  452. UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(firstname, lastname);
  453. if (null != userProfile)
  454. throw new Exception(String.Format("avatar {0} {1} already exists", firstname, lastname));
  455. LLUUID userID = m_app.CreateUser(firstname, lastname, passwd, regX, regY);
  456. if (userID == LLUUID.Zero) throw new Exception(String.Format("failed to create new user {0} {1}",
  457. firstname, lastname));
  458. responseData["success"] = "true";
  459. responseData["avatar_uuid"] = userID.ToString();
  460. response.Value = responseData;
  461. m_log.InfoFormat("[RADMIN]: CreateUser: User {0} {1} created, UUID {2}", firstname, lastname, userID);
  462. }
  463. catch (Exception e)
  464. {
  465. m_log.ErrorFormat("[RADMIN] CreateUser: failed: {0}", e.Message);
  466. m_log.DebugFormat("[RADMIN] CreateUser: failed: {0}", e.ToString());
  467. responseData["success"] = "false";
  468. responseData["avatar_uuid"] = LLUUID.Zero.ToString();
  469. responseData["error"] = e.Message;
  470. response.Value = responseData;
  471. }
  472. return response;
  473. }
  474. /// <summary>
  475. /// Update the password of a user account.
  476. /// <summary>
  477. /// <param name="request">incoming XML RPC request</param>
  478. /// <remarks>
  479. /// XmlRpcUpdateUserAccountMethod takes the following XMLRPC
  480. /// parameters
  481. /// <list type="table">
  482. /// <listheader><term>parameter name</term><description>description</description></listheader>
  483. /// <item><term>password</term>
  484. /// <description>admin password as set in OpenSim.ini</description></item>
  485. /// <item><term>user_firstname</term>
  486. /// <description>avatar's first name (cannot be changed)</description></item>
  487. /// <item><term>user_lastname</term>
  488. /// <description>avatar's last name (cannot be changed)</description></item>
  489. /// <item><term>user_password</term>
  490. /// <description>avatar's password (changeable)</description></item>
  491. /// <item><term>start_region_x</term>
  492. /// <description>avatar's start region coordinates, X
  493. /// value (changeable)</description></item>
  494. /// <item><term>start_region_y</term>
  495. /// <description>avatar's start region coordinates, Y
  496. /// value (changeable)</description></item>
  497. /// </list>
  498. ///
  499. /// XmlRpcCreateUserMethod returns
  500. /// <list type="table">
  501. /// <listheader><term>name</term><description>description</description></listheader>
  502. /// <item><term>success</term>
  503. /// <description>true or false</description></item>
  504. /// <item><term>error</term>
  505. /// <description>error message if success is false</description></item>
  506. /// </list>
  507. /// </remarks>
  508. public XmlRpcResponse XmlRpcUpdateUserAccountMethod(XmlRpcRequest request)
  509. {
  510. m_log.Info("[RADMIN]: UpdateUserAccount: new request");
  511. XmlRpcResponse response = new XmlRpcResponse();
  512. Hashtable responseData = new Hashtable();
  513. try
  514. {
  515. Hashtable requestData = (Hashtable) request.Params[0];
  516. // check completeness
  517. checkStringParameters(request, new string[] { "password", "user_firstname",
  518. "user_lastname" });
  519. // check password
  520. if (!String.IsNullOrEmpty(requiredPassword) &&
  521. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  522. // do the job
  523. string firstname = (string) requestData["user_firstname"];
  524. string lastname = (string) requestData["user_lastname"];
  525. string passwd = String.Empty;
  526. uint? regX = null;
  527. uint? regY = null;
  528. if (requestData.ContainsKey("user_password")) passwd = (string) requestData["user_password"];
  529. if (requestData.ContainsKey("start_region_x")) regX = Convert.ToUInt32((Int32)requestData["start_region_x"]);
  530. if (requestData.ContainsKey("start_region_y")) regY = Convert.ToUInt32((Int32)requestData["start_region_y"]);
  531. if (String.Empty == passwd && null == regX && null == regY)
  532. throw new Exception("neither user_password nor start_region_x nor start_region_y provided");
  533. UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(firstname, lastname);
  534. if (null == userProfile)
  535. throw new Exception(String.Format("avatar {0} {1} does not exist", firstname, lastname));
  536. if (null != passwd)
  537. {
  538. string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(passwd) + ":" + String.Empty);
  539. userProfile.PasswordHash = md5PasswdHash;
  540. }
  541. if (null != regX) userProfile.HomeRegionX = (uint)regX;
  542. if (null != regY) userProfile.HomeRegionY = (uint)regY;
  543. if (!m_app.CommunicationsManager.UserService.UpdateUserProfile(userProfile))
  544. throw new Exception("did not manage to update user profile");
  545. responseData["success"] = "true";
  546. response.Value = responseData;
  547. m_log.InfoFormat("[RADMIN]: UpdateUserAccount: account for user {0} {1} updated, UUID {2}", firstname, lastname,
  548. userProfile.ID);
  549. }
  550. catch (Exception e)
  551. {
  552. m_log.ErrorFormat("[RADMIN] UpdateUserAccount: failed: {0}", e.Message);
  553. m_log.DebugFormat("[RADMIN] UpdateUserAccount: failed: {0}", e.ToString());
  554. responseData["success"] = "false";
  555. responseData["error"] = e.Message;
  556. response.Value = responseData;
  557. }
  558. return response;
  559. }
  560. public XmlRpcResponse XmlRpcLoadXMLMethod(XmlRpcRequest request)
  561. {
  562. m_log.Info("[RADMIN]: Received Load XML Administrator Request");
  563. XmlRpcResponse response = new XmlRpcResponse();
  564. Hashtable responseData = new Hashtable();
  565. try
  566. {
  567. Hashtable requestData = (Hashtable) request.Params[0];
  568. // check completeness
  569. foreach (string p in new string[] { "password", "filename" })
  570. {
  571. if (!requestData.Contains(p))
  572. throw new Exception(String.Format("missing parameter {0}", p));
  573. if (String.IsNullOrEmpty((string)requestData[p]))
  574. throw new Exception(String.Format("parameter {0} is empty"));
  575. }
  576. // check password
  577. if (!String.IsNullOrEmpty(requiredPassword) &&
  578. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  579. string filename = (string)requestData["filename"];
  580. if (requestData.Contains("region_uuid"))
  581. {
  582. LLUUID region_uuid = (string)requestData["region_uuid"];
  583. if (!m_app.SceneManager.TrySetCurrentScene(region_uuid))
  584. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  585. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString());
  586. }
  587. else if (requestData.Contains("region_name"))
  588. {
  589. string region_name = (string)requestData["region_name"];
  590. if (!m_app.SceneManager.TrySetCurrentScene(region_name))
  591. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  592. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_name);
  593. }
  594. else throw new Exception("neither region_name nor region_uuid given");
  595. responseData["switched"] = "true";
  596. string xml_version = "1";
  597. if (requestData.Contains("xml_version"))
  598. {
  599. xml_version = (string)requestData["xml_version"];
  600. }
  601. switch (xml_version)
  602. {
  603. case "1":
  604. m_app.SceneManager.LoadCurrentSceneFromXml(filename, true, new LLVector3(0, 0, 0));
  605. break;
  606. case "2":
  607. m_app.SceneManager.LoadCurrentSceneFromXml2(filename);
  608. break;
  609. default:
  610. throw new Exception(String.Format("unknown Xml{0} format", xml_version));
  611. }
  612. responseData["loaded"] = "true";
  613. response.Value = responseData;
  614. }
  615. catch (Exception e)
  616. {
  617. m_log.InfoFormat("[RADMIN] LoadXml: {0}", e.Message);
  618. m_log.DebugFormat("[RADMIN] LoadXml: {0}", e.ToString());
  619. responseData["loaded"] = "false";
  620. responseData["switched"] = "false";
  621. responseData["error"] = e.Message;
  622. response.Value = responseData;
  623. }
  624. return response;
  625. }
  626. public void Dispose()
  627. {
  628. }
  629. }
  630. }