Ejemplo n.º 1
0
        private bool HasEvents(UUID RequestID, UUID sessionID)
        {
            ConsoleConnection c = null;

            lock (m_Connections)
            {
                if (!m_Connections.ContainsKey(sessionID))
                {
                    return(false);
                }
                c = m_Connections[sessionID];
            }
            c.last = Environment.TickCount;
            if (c.lastLineSeen < m_LineNumber)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        byte [] HandleHttpStartSession (string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            DoExpire ();

            Hashtable post = DecodePostString (HttpServerHandlerHelpers.ReadString (request));

            httpResponse.StatusCode = 401;
            httpResponse.ContentType = "text/plain";
            if (m_UserName == string.Empty)
                return MainServer.BlankResponse;

            if (post ["USER"] == null || post ["PASS"] == null)
                return MainServer.BlankResponse;

            if (m_UserName != post ["USER"].ToString () ||
                m_Password != post ["PASS"].ToString ())
                return MainServer.BlankResponse;

            ConsoleConnection c = new ConsoleConnection { last = Environment.TickCount, lastLineSeen = 0 };

            UUID sessionID = UUID.Random ();

            lock (m_Connections) {
                m_Connections [sessionID] = c;
            }

            string uri = "/ReadResponses/" + sessionID + "/";

            m_Server.AddPollServiceHTTPHandler (uri, new PollServiceEventArgs (null, HasEvents, GetEvents, NoEvents,
                                                                        sessionID));

            XmlDocument xmldoc = new XmlDocument ();
            XmlNode xmlnode = xmldoc.CreateNode (XmlNodeType.XmlDeclaration, "", "");

            xmldoc.AppendChild (xmlnode);
            XmlElement rootElement = xmldoc.CreateElement ("", "ConsoleSession", "");

            xmldoc.AppendChild (rootElement);

            XmlElement id = xmldoc.CreateElement ("", "SessionID", "");
            id.AppendChild (xmldoc.CreateTextNode (sessionID.ToString ()));

            rootElement.AppendChild (id);

            XmlElement prompt = xmldoc.CreateElement ("", "Prompt", "");
            prompt.AppendChild (xmldoc.CreateTextNode (DefaultPrompt));

            rootElement.AppendChild (prompt);

            httpResponse.StatusCode = 200;
            httpResponse.ContentType = "text/xml";
            return Encoding.UTF8.GetBytes (xmldoc.InnerXml);
        }
Ejemplo n.º 3
0
        private byte[] GetEvents(UUID RequestID, UUID sessionID, string req, OSHttpResponse response)
        {
            ConsoleConnection c = null;

            lock (m_Connections)
            {
                if (!m_Connections.ContainsKey(sessionID))
                {
                    return(NoEvents(RequestID, UUID.Zero, response));
                }
                c = m_Connections[sessionID];
            }
            c.last = Environment.TickCount;
            if (c.lastLineSeen >= m_LineNumber)
            {
                return(NoEvents(RequestID, UUID.Zero, response));
            }

            XmlDocument xmldoc  = new XmlDocument();
            XmlNode     xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration,
                                                    "", "");

            xmldoc.AppendChild(xmlnode);
            XmlElement rootElement = xmldoc.CreateElement("", "ConsoleSession",
                                                          "");

            if (c.newConnection)
            {
                c.newConnection = false;
                Output("+++" + DefaultPrompt, Threshold);
            }

            lock (m_Scrollback)
            {
                long startLine = m_LineNumber - m_Scrollback.Count;
                long sendStart = startLine;
                if (sendStart < c.lastLineSeen)
                {
                    sendStart = c.lastLineSeen;
                }

                for (long i = sendStart; i < m_LineNumber; i++)
                {
                    XmlElement res  = xmldoc.CreateElement("", "Line", "");
                    long       line = i + 1;
                    res.SetAttribute("Number", line.ToString());
                    res.AppendChild(xmldoc.CreateTextNode(m_Scrollback[(int)(i - startLine)]));

                    rootElement.AppendChild(res);
                }
            }
            c.lastLineSeen = m_LineNumber;

            xmldoc.AppendChild(rootElement);


            response.StatusCode  = 200;
            response.ContentType = "application/xml";

            return(Encoding.UTF8.GetBytes(xmldoc.InnerXml));
        }
Ejemplo n.º 4
0
        private byte[] HandleHttpStartSession(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            DoExpire();

            Hashtable post = DecodePostString(HttpServerHandlerHelpers.ReadString(request));

            httpResponse.StatusCode  = 401;
            httpResponse.ContentType = "text/plain";
            if (m_UserName == String.Empty)
            {
                return(MainServer.BlankResponse);
            }

            if (post["USER"] == null || post["PASS"] == null)
            {
                return(MainServer.BlankResponse);
            }

            if (m_UserName != post["USER"].ToString() ||
                m_Password != post["PASS"].ToString())
            {
                return(MainServer.BlankResponse);
            }

            ConsoleConnection c = new ConsoleConnection {
                last = Environment.TickCount, lastLineSeen = 0
            };

            UUID sessionID = UUID.Random();

            lock (m_Connections)
            {
                m_Connections[sessionID] = c;
            }

            string uri = "/ReadResponses/" + sessionID.ToString() + "/";

            m_Server.AddPollServiceHTTPHandler(uri, new PollServiceEventArgs(null, HasEvents, GetEvents, NoEvents,
                                                                             sessionID));

            XmlDocument xmldoc  = new XmlDocument();
            XmlNode     xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration,
                                                    "", "");

            xmldoc.AppendChild(xmlnode);
            XmlElement rootElement = xmldoc.CreateElement("", "ConsoleSession",
                                                          "");

            xmldoc.AppendChild(rootElement);

            XmlElement id = xmldoc.CreateElement("", "SessionID", "");

            id.AppendChild(xmldoc.CreateTextNode(sessionID.ToString()));

            rootElement.AppendChild(id);

            XmlElement prompt = xmldoc.CreateElement("", "Prompt", "");

            prompt.AppendChild(xmldoc.CreateTextNode(DefaultPrompt));

            rootElement.AppendChild(prompt);

            httpResponse.StatusCode  = 200;
            httpResponse.ContentType = "text/xml";
            return(Encoding.UTF8.GetBytes(xmldoc.InnerXml));
        }