1
0

RemoteConsole.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  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 OpenSimulator 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.Xml;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.Reflection;
  32. using System.Threading;
  33. using System.Timers;
  34. using OpenMetaverse;
  35. using Nini.Config;
  36. using OpenSim.Framework.Servers.HttpServer;
  37. using log4net;
  38. namespace OpenSim.Framework.Console
  39. {
  40. // A console that uses REST interfaces
  41. //
  42. public class RemoteConsole : CommandConsole
  43. {
  44. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  45. // Connection specific data, indexed by a session ID
  46. // we create when a client connects.
  47. protected class ConsoleConnection
  48. {
  49. // Last activity from the client
  50. public int last;
  51. // Last line of scrollback posted to this client
  52. public long lastLineSeen;
  53. // True if this is a new connection, e.g. has never
  54. // displayed a prompt to the user.
  55. public bool newConnection = true;
  56. }
  57. // A line in the scrollback buffer.
  58. protected class ScrollbackEntry
  59. {
  60. // The line number of this entry
  61. public long lineNumber;
  62. // The text to send to the client
  63. public string text;
  64. // The level this should be logged as. Omitted for
  65. // prompts and input echo.
  66. public string level;
  67. // True if the text above is a prompt, e.g. the
  68. // client should turn on the cursor / accept input
  69. public bool isPrompt;
  70. // True if the requested input is a command. A
  71. // client may offer help or validate input if
  72. // this is set. If false, input should be sent
  73. // as typed.
  74. public bool isCommand;
  75. // True if this text represents a line of text that
  76. // was input in response to a prompt. A client should
  77. // turn off the cursor and refrain from sending commands
  78. // until a new prompt is received.
  79. public bool isInput;
  80. }
  81. // Data that is relevant to all connections
  82. // The scrollback buffer
  83. protected List<ScrollbackEntry> m_Scrollback = new List<ScrollbackEntry>();
  84. // Monotonously incrementing line number. This may eventually
  85. // wrap. No provision is made for that case because 64 bits
  86. // is a long, long time.
  87. protected long m_lineNumber = 0;
  88. // These two variables allow us to send the correct
  89. // information about the prompt status to the client,
  90. // irrespective of what may have run off the top of the
  91. // scrollback buffer;
  92. protected bool m_expectingInput = false;
  93. protected bool m_expectingCommand = true;
  94. protected string m_lastPromptUsed;
  95. // This is the list of things received from clients.
  96. // Note: Race conditions can happen. If a client sends
  97. // something while nothing is expected, it will be
  98. // intepreted as input to the next prompt. For
  99. // commands this is largely correct. For other prompts,
  100. // YMMV.
  101. // TODO: Find a better way to fix this
  102. protected List<string> m_InputData = new List<string>();
  103. // Event to allow ReadLine to wait synchronously even though
  104. // everthing else is asynchronous here.
  105. protected ManualResetEvent m_DataEvent = new ManualResetEvent(false);
  106. // The list of sessions we maintain. Unlike other console types,
  107. // multiple users on the same console are explicitly allowed.
  108. protected Dictionary<UUID, ConsoleConnection> m_Connections =
  109. new Dictionary<UUID, ConsoleConnection>();
  110. // Timer to control expiration of sessions that have been
  111. // disconnected.
  112. protected System.Timers.Timer m_expireTimer = new System.Timers.Timer(5000);
  113. // The less interesting stuff that makes the actual server
  114. // work.
  115. protected IHttpServer m_Server = null;
  116. protected IConfigSource m_Config = null;
  117. protected string m_UserName = String.Empty;
  118. protected string m_Password = String.Empty;
  119. protected string m_AllowedOrigin = String.Empty;
  120. public RemoteConsole(string defaultPrompt) : base(defaultPrompt)
  121. {
  122. // There is something wrong with this architecture.
  123. // A prompt is sent on every single input, so why have this?
  124. // TODO: Investigate and fix.
  125. m_lastPromptUsed = defaultPrompt;
  126. // Start expiration of sesssions.
  127. m_expireTimer.Elapsed += DoExpire;
  128. m_expireTimer.Start();
  129. }
  130. public override void ReadConfig(IConfigSource config)
  131. {
  132. m_Config = config;
  133. // We're pulling this from the 'Network' section for legacy
  134. // compatibility. However, this is so essentially insecure
  135. // that TLS and client certs should be used instead of
  136. // a username / password.
  137. IConfig netConfig = m_Config.Configs["Network"];
  138. if (netConfig == null)
  139. return;
  140. // Get the username and password.
  141. m_UserName = netConfig.GetString("ConsoleUser", String.Empty);
  142. m_Password = netConfig.GetString("ConsolePass", String.Empty);
  143. // Woefully underdocumented, this is what makes javascript
  144. // console clients work. Set to "*" for anywhere or (better)
  145. // to specific addresses.
  146. m_AllowedOrigin = netConfig.GetString("ConsoleAllowedOrigin", String.Empty);
  147. }
  148. public void SetServer(IHttpServer server)
  149. {
  150. // This is called by the framework to give us the server
  151. // instance (means: port) to work with.
  152. m_Server = server;
  153. // Add our handlers
  154. m_Server.AddHTTPHandler("/StartSession", HandleHttpStartSession);
  155. m_Server.AddHTTPHandler("/CloseSession", HandleHttpCloseSession);
  156. m_Server.AddHTTPHandler("/SessionCommand", HandleHttpSessionCommand);
  157. }
  158. public override void Output(string format)
  159. {
  160. Output(format, null);
  161. }
  162. public override void Output(string format, params object[] components)
  163. {
  164. string level = null;
  165. if (components != null && components.Length > 0)
  166. {
  167. ConsoleLevel cl = components[0] as ConsoleLevel;
  168. if (cl != null)
  169. {
  170. level = cl.ToString();
  171. if (components.Length > 1)
  172. {
  173. object[] tmp = new object[components.Length - 1];
  174. Array.Copy(components, 1, tmp, 0, components.Length - 1);
  175. components = tmp;
  176. }
  177. else
  178. components = null;
  179. }
  180. }
  181. string text = (components == null || components.Length == 0) ? format : String.Format(format, components);
  182. Output(text, level, false, false, false);
  183. }
  184. protected void Output(string text, string level, bool isPrompt, bool isCommand, bool isInput)
  185. {
  186. if (level == null)
  187. level = String.Empty;
  188. // Increment the line number. It was 0 and they start at 1
  189. // so we need to pre-increment.
  190. m_lineNumber++;
  191. // Create and populate the new entry.
  192. ScrollbackEntry newEntry = new ScrollbackEntry();
  193. newEntry.lineNumber = m_lineNumber;
  194. newEntry.text = text;
  195. newEntry.level = level;
  196. newEntry.isPrompt = isPrompt;
  197. newEntry.isCommand = isCommand;
  198. newEntry.isInput = isInput;
  199. // Add a line to the scrollback. In some cases, that may not
  200. // actually be a line of text.
  201. lock (m_Scrollback)
  202. {
  203. // Prune the scrollback to the length se send as connect
  204. // burst to give the user some context.
  205. while (m_Scrollback.Count >= 1000)
  206. m_Scrollback.RemoveAt(0);
  207. m_Scrollback.Add(newEntry);
  208. }
  209. // Let the rest of the system know we have output something.
  210. FireOnOutput(text.Trim());
  211. // Also display it for debugging.
  212. System.Console.WriteLine(text.Trim());
  213. }
  214. public override string ReadLine(string p, bool isCommand, bool e)
  215. {
  216. // Output the prompt an prepare to wait. This
  217. // is called on a dedicated console thread and
  218. // needs to be synchronous. Old architecture but
  219. // not worth upgrading.
  220. if (isCommand)
  221. {
  222. m_expectingInput = true;
  223. m_expectingCommand = true;
  224. Output(p, String.Empty, true, true, false);
  225. m_lastPromptUsed = p;
  226. }
  227. else
  228. {
  229. m_expectingInput = true;
  230. Output(p, String.Empty, true, false, false);
  231. }
  232. // Here is where we wait for the user to input something.
  233. m_DataEvent.WaitOne();
  234. string cmdinput;
  235. // Check for empty input. Read input if not empty.
  236. lock (m_InputData)
  237. {
  238. if (m_InputData.Count == 0)
  239. {
  240. m_DataEvent.Reset();
  241. m_expectingInput = false;
  242. m_expectingCommand = false;
  243. return "";
  244. }
  245. cmdinput = m_InputData[0];
  246. m_InputData.RemoveAt(0);
  247. if (m_InputData.Count == 0)
  248. m_DataEvent.Reset();
  249. }
  250. m_expectingInput = false;
  251. m_expectingCommand = false;
  252. // Echo to all the other users what we have done. This
  253. // will also go to ourselves.
  254. Output (cmdinput, String.Empty, false, false, true);
  255. // If this is a command, we need to resolve and execute it.
  256. if (isCommand)
  257. {
  258. // This call will actually execute the command and create
  259. // any output associated with it. The core just gets an
  260. // empty string so it will call again immediately.
  261. string[] cmd = Commands.Resolve(Parser.Parse(cmdinput));
  262. if (cmd.Length != 0)
  263. {
  264. int i;
  265. for (i=0 ; i < cmd.Length ; i++)
  266. {
  267. if (cmd[i].Contains(' '))
  268. cmd[i] = "\"" + cmd[i] + "\"";
  269. }
  270. return String.Empty;
  271. }
  272. }
  273. // Return the raw input string if not a command.
  274. return cmdinput;
  275. }
  276. // Very simplistic static access control header.
  277. protected Hashtable CheckOrigin(Hashtable result)
  278. {
  279. if (!string.IsNullOrEmpty(m_AllowedOrigin))
  280. result["access_control_allow_origin"] = m_AllowedOrigin;
  281. return result;
  282. }
  283. /* TODO: Figure out how PollServiceHTTPHandler can access the request headers
  284. * in order to use m_AllowedOrigin as a regular expression
  285. protected Hashtable CheckOrigin(Hashtable headers, Hashtable result)
  286. {
  287. if (!string.IsNullOrEmpty(m_AllowedOrigin))
  288. {
  289. if (headers.ContainsKey("origin"))
  290. {
  291. string origin = headers["origin"].ToString();
  292. if (Regex.IsMatch(origin, m_AllowedOrigin))
  293. result["access_control_allow_origin"] = origin;
  294. }
  295. }
  296. return result;
  297. }
  298. */
  299. protected void DoExpire(Object sender, ElapsedEventArgs e)
  300. {
  301. // Iterate the list of console connections and find those we
  302. // haven't heard from for longer then the longpoll interval.
  303. // Remove them.
  304. List<UUID> expired = new List<UUID>();
  305. lock (m_Connections)
  306. {
  307. // Mark the expired ones
  308. foreach (KeyValuePair<UUID, ConsoleConnection> kvp in m_Connections)
  309. {
  310. if (System.Environment.TickCount - kvp.Value.last > 500000)
  311. expired.Add(kvp.Key);
  312. }
  313. // Delete them
  314. foreach (UUID id in expired)
  315. {
  316. m_Connections.Remove(id);
  317. CloseConnection(id);
  318. }
  319. }
  320. }
  321. // Start a new session.
  322. protected Hashtable HandleHttpStartSession(Hashtable request)
  323. {
  324. // The login is in the form of a http form post
  325. Hashtable post = DecodePostString(request["body"].ToString());
  326. Hashtable reply = new Hashtable();
  327. reply["str_response_string"] = "";
  328. reply["int_response_code"] = 401;
  329. reply["content_type"] = "text/plain";
  330. // Check user name and password
  331. if (m_UserName.Length == 0)
  332. return reply;
  333. if (post["USER"] == null || post["PASS"] == null)
  334. return reply;
  335. if (m_UserName != post["USER"].ToString() ||
  336. m_Password != post["PASS"].ToString())
  337. {
  338. return reply;
  339. }
  340. // Set up the new console connection record
  341. ConsoleConnection c = new ConsoleConnection();
  342. c.last = System.Environment.TickCount;
  343. c.lastLineSeen = 0;
  344. // Assign session ID
  345. UUID sessionID = UUID.Random();
  346. // Add connection to list.
  347. lock (m_Connections)
  348. {
  349. m_Connections[sessionID] = c;
  350. }
  351. // This call is a CAP. The URL is the authentication.
  352. string uri = "/ReadResponses/" + sessionID.ToString();
  353. m_Server.AddPollServiceHTTPHandler(new PollServiceEventArgs(null, uri, HasEvents, GetEvents, NoEvents, null, sessionID,25000)); // 25 secs timeout
  354. // Our reply is an XML document.
  355. // TODO: Change this to Linq.Xml
  356. XmlDocument xmldoc = new XmlDocument();
  357. XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration,
  358. "", "");
  359. xmldoc.AppendChild(xmlnode);
  360. XmlElement rootElement = xmldoc.CreateElement("", "ConsoleSession",
  361. "");
  362. xmldoc.AppendChild(rootElement);
  363. XmlElement id = xmldoc.CreateElement("", "SessionID", "");
  364. id.AppendChild(xmldoc.CreateTextNode(sessionID.ToString()));
  365. rootElement.AppendChild(id);
  366. XmlElement prompt = xmldoc.CreateElement("", "Prompt", "");
  367. prompt.AppendChild(xmldoc.CreateTextNode(m_lastPromptUsed));
  368. rootElement.AppendChild(prompt);
  369. rootElement.AppendChild(MainConsole.Instance.Commands.GetXml(xmldoc));
  370. // Set up the response and check origin
  371. reply["str_response_string"] = xmldoc.InnerXml;
  372. reply["int_response_code"] = 200;
  373. reply["content_type"] = "text/xml";
  374. reply = CheckOrigin(reply);
  375. return reply;
  376. }
  377. // Client closes session. Clean up.
  378. protected Hashtable HandleHttpCloseSession(Hashtable request)
  379. {
  380. Hashtable post = DecodePostString(request["body"].ToString());
  381. Hashtable reply = new Hashtable();
  382. reply["str_response_string"] = "";
  383. reply["int_response_code"] = 404;
  384. reply["content_type"] = "text/plain";
  385. if (post["ID"] == null)
  386. return reply;
  387. UUID id;
  388. if (!UUID.TryParse(post["ID"].ToString(), out id))
  389. return reply;
  390. lock (m_Connections)
  391. {
  392. if (m_Connections.ContainsKey(id))
  393. {
  394. m_Connections.Remove(id);
  395. CloseConnection(id);
  396. }
  397. }
  398. XmlDocument xmldoc = new XmlDocument();
  399. XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration,
  400. "", "");
  401. xmldoc.AppendChild(xmlnode);
  402. XmlElement rootElement = xmldoc.CreateElement("", "ConsoleSession",
  403. "");
  404. xmldoc.AppendChild(rootElement);
  405. XmlElement res = xmldoc.CreateElement("", "Result", "");
  406. res.AppendChild(xmldoc.CreateTextNode("OK"));
  407. rootElement.AppendChild(res);
  408. reply["str_response_string"] = xmldoc.InnerXml;
  409. reply["int_response_code"] = 200;
  410. reply["content_type"] = "text/xml";
  411. reply = CheckOrigin(reply);
  412. return reply;
  413. }
  414. // Command received from the client.
  415. protected Hashtable HandleHttpSessionCommand(Hashtable request)
  416. {
  417. Hashtable post = DecodePostString(request["body"].ToString());
  418. Hashtable reply = new Hashtable();
  419. reply["str_response_string"] = "";
  420. reply["int_response_code"] = 404;
  421. reply["content_type"] = "text/plain";
  422. // Check the ID
  423. if (post["ID"] == null)
  424. return reply;
  425. UUID id;
  426. if (!UUID.TryParse(post["ID"].ToString(), out id))
  427. return reply;
  428. // Find the connection for that ID.
  429. lock (m_Connections)
  430. {
  431. if (!m_Connections.ContainsKey(id))
  432. return reply;
  433. }
  434. // Empty post. Just error out.
  435. if (post["COMMAND"] == null)
  436. return reply;
  437. // Place the input data in the buffer.
  438. lock (m_InputData)
  439. {
  440. m_DataEvent.Set();
  441. m_InputData.Add(post["COMMAND"].ToString());
  442. }
  443. // Create the XML reply document.
  444. XmlDocument xmldoc = new XmlDocument();
  445. XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration,
  446. "", "");
  447. xmldoc.AppendChild(xmlnode);
  448. XmlElement rootElement = xmldoc.CreateElement("", "ConsoleSession",
  449. "");
  450. xmldoc.AppendChild(rootElement);
  451. XmlElement res = xmldoc.CreateElement("", "Result", "");
  452. res.AppendChild(xmldoc.CreateTextNode("OK"));
  453. rootElement.AppendChild(res);
  454. reply["str_response_string"] = xmldoc.InnerXml;
  455. reply["int_response_code"] = 200;
  456. reply["content_type"] = "text/xml";
  457. reply = CheckOrigin(reply);
  458. return reply;
  459. }
  460. // Decode a HTTP form post to a Hashtable
  461. protected Hashtable DecodePostString(string data)
  462. {
  463. Hashtable result = new Hashtable();
  464. string[] terms = data.Split(new char[] {'&'});
  465. foreach (string term in terms)
  466. {
  467. string[] elems = term.Split(new char[] {'='});
  468. if (elems.Length == 0)
  469. continue;
  470. string name = System.Web.HttpUtility.UrlDecode(elems[0]);
  471. string value = String.Empty;
  472. if (elems.Length > 1)
  473. value = System.Web.HttpUtility.UrlDecode(elems[1]);
  474. result[name] = value;
  475. }
  476. return result;
  477. }
  478. // Close the CAP receiver for the responses for a given client.
  479. public void CloseConnection(UUID id)
  480. {
  481. try
  482. {
  483. string uri = "/ReadResponses/" + id.ToString() + "/";
  484. m_Server.RemovePollServiceHTTPHandler("", uri);
  485. }
  486. catch (Exception)
  487. {
  488. }
  489. }
  490. // Check if there is anything to send. Return true if this client has
  491. // lines pending.
  492. protected bool HasEvents(UUID RequestID, UUID sessionID)
  493. {
  494. ConsoleConnection c = null;
  495. lock (m_Connections)
  496. {
  497. if (!m_Connections.ContainsKey(sessionID))
  498. return false;
  499. c = m_Connections[sessionID];
  500. }
  501. c.last = System.Environment.TickCount;
  502. if (c.lastLineSeen < m_lineNumber)
  503. return true;
  504. return false;
  505. }
  506. // Send all pending output to the client.
  507. protected Hashtable GetEvents(UUID RequestID, UUID sessionID)
  508. {
  509. // Find the connection that goes with this client.
  510. ConsoleConnection c = null;
  511. lock (m_Connections)
  512. {
  513. if (!m_Connections.ContainsKey(sessionID))
  514. return NoEvents(RequestID, UUID.Zero);
  515. c = m_Connections[sessionID];
  516. }
  517. // If we have nothing to send, send the no events response.
  518. c.last = System.Environment.TickCount;
  519. if (c.lastLineSeen >= m_lineNumber)
  520. return NoEvents(RequestID, UUID.Zero);
  521. Hashtable result = new Hashtable();
  522. // Create the response document.
  523. XmlDocument xmldoc = new XmlDocument();
  524. XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration,
  525. "", "");
  526. xmldoc.AppendChild(xmlnode);
  527. XmlElement rootElement = xmldoc.CreateElement("", "ConsoleSession",
  528. "");
  529. //if (c.newConnection)
  530. //{
  531. // c.newConnection = false;
  532. // Output("+++" + DefaultPrompt);
  533. //}
  534. lock (m_Scrollback)
  535. {
  536. long startLine = m_lineNumber - m_Scrollback.Count;
  537. long sendStart = startLine;
  538. if (sendStart < c.lastLineSeen)
  539. sendStart = c.lastLineSeen;
  540. for (long i = sendStart ; i < m_lineNumber ; i++)
  541. {
  542. ScrollbackEntry e = m_Scrollback[(int)(i - startLine)];
  543. XmlElement res = xmldoc.CreateElement("", "Line", "");
  544. res.SetAttribute("Number", e.lineNumber.ToString());
  545. res.SetAttribute("Level", e.level);
  546. // Don't include these for the scrollback, we'll send the
  547. // real state later.
  548. if (!c.newConnection)
  549. {
  550. res.SetAttribute("Prompt", e.isPrompt ? "true" : "false");
  551. res.SetAttribute("Command", e.isCommand ? "true" : "false");
  552. res.SetAttribute("Input", e.isInput ? "true" : "false");
  553. }
  554. else if (i == m_lineNumber - 1) // Last line for a new connection
  555. {
  556. res.SetAttribute("Prompt", m_expectingInput ? "true" : "false");
  557. res.SetAttribute("Command", m_expectingCommand ? "true" : "false");
  558. res.SetAttribute("Input", (!m_expectingInput) ? "true" : "false");
  559. }
  560. else
  561. {
  562. res.SetAttribute("Input", e.isInput ? "true" : "false");
  563. }
  564. res.AppendChild(xmldoc.CreateTextNode(e.text));
  565. rootElement.AppendChild(res);
  566. }
  567. }
  568. c.lastLineSeen = m_lineNumber;
  569. c.newConnection = false;
  570. xmldoc.AppendChild(rootElement);
  571. result["str_response_string"] = xmldoc.InnerXml;
  572. result["int_response_code"] = 200;
  573. result["content_type"] = "application/xml";
  574. result["keepalive"] = false;
  575. result = CheckOrigin(result);
  576. return result;
  577. }
  578. // This is really just a no-op. It generates what is sent
  579. // to the client if the poll times out without any events.
  580. protected Hashtable NoEvents(UUID RequestID, UUID id)
  581. {
  582. Hashtable result = new Hashtable();
  583. XmlDocument xmldoc = new XmlDocument();
  584. XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
  585. xmldoc.AppendChild(xmlnode);
  586. XmlElement rootElement = xmldoc.CreateElement("", "ConsoleSession", "");
  587. xmldoc.AppendChild(rootElement);
  588. result["str_response_string"] = xmldoc.InnerXml;
  589. result["int_response_code"] = 200;
  590. result["content_type"] = "text/xml";
  591. result["keepalive"] = false;
  592. result = CheckOrigin(result);
  593. return result;
  594. }
  595. }
  596. }