예제 #1
0
        /*
         *
         *
         */
        public static HTTPProxy getInstance()
        {
            if (cInstance == null)
            cInstance = new HTTPProxy();

              return (cInstance);
        }
예제 #2
0
        /*
         *
         *
         */
        public static HTTPProxy getInstance()
        {
            if (cInstance == null)
            {
                cInstance = new HTTPProxy();
            }

            return(cInstance);
        }
예제 #3
0
        /*
         *
         *
         */
        private static void DoHttpProcessing(String pSrcMAC, String pSrcIP, String pSrcPort, TcpClient pClient)
        {
            Stream       lClientStream       = pClient.GetStream();
            Stream       lOutStream          = lClientStream;
            StreamReader lClientStreamReader = new StreamReader(lClientStream);

            String[]  lReqSplitBuffer;
            String    lMethod      = String.Empty;
            String    lRemoteURI   = String.Empty;
            String    lURL         = String.Empty;
            Version   lVersion     = new Version(1, 0);
            int       lContentLen  = 0;
            String    lHTTPData    = String.Empty;
            String    lHTTPCommand = String.Empty;
            String    lLine        = String.Empty;
            String    lPOSTData    = String.Empty;
            Hashtable lHeaders     = new Hashtable();

            try
            {
                // Read the first line HTTP command
                lHTTPCommand = lClientStreamReader.ReadLine();

                /*
                 * Header corrupted. Stop thread execution.
                 */
                if (String.IsNullOrEmpty(lHTTPCommand))
                {
                    lClientStreamReader.Close();
                    lClientStream.Close();

                    return;
                }



                /*
                 * Break up the line into three components
                 */
                lReqSplitBuffer = lHTTPCommand.Split(lSpaceSplit, 3);
                lMethod         = lReqSplitBuffer[0];
                lRemoteURI      = lReqSplitBuffer[1];
                lURL            = String.Empty;

                // Read the request headers from the client and copy them to our request
                lContentLen = ReadRequestHeaders(lClientStreamReader, ref lHeaders);

                // Build the URI
                if (lHeaders != null && lHeaders.ContainsKey("host") && lHeaders["host"].ToString().Length > 0)
                {
                    lURL = string.Format("http://{0}:{1}{2}", lHeaders["host"].ToString(), cRemotePort, lRemoteURI);
                }
                else
                {
                    lURL = string.Format("http://{0}:{1}{2}", cRemoteHost, cRemotePort, lRemoteURI);
                }


                if (Program.cDebuggingOn)
                {
                    Console.WriteLine("{0} URL : \"{1}\"", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), lURL);
                }

                /*
                 * Redirect URL
                 */
                if (!String.IsNullOrEmpty(cRedirectURL) && lMethod.ToLower() == "get")
                {
                    HTTPRedirect.getInstance().processRequest(lOutStream, cRedirectURL, lHeaders);


                    /*
                     * Process HTTP request
                     */
                }
                else
                {
                    // StreamReader pClientStreamReader, Stream pOutStream, String pMethod, String pURL, Hashtable pHeaders, int pContentLen, String pHTTPCommand, String pPOSTData
                    HTTPProxy.getInstance().processRequest(lClientStreamReader, lOutStream, lMethod, lURL, lHeaders, lContentLen, lHTTPCommand, out lHTTPData);

                    String lPipeData = String.Format("TCP||{0}||{1}||{2}||{3}||{4}||{5}\r\n", pSrcMAC, pSrcIP, pSrcPort, cRemoteIP, cRemotePort, lHTTPData);
                    Program.WriteToPipe(lPipeData);

                    if (Program.cDebuggingOn)
                    {
                        Console.WriteLine(lPipeData.TrimEnd());
                    }
                } // if (!String.IsNullOrEmpty(cR...
            }
            catch (Exception ex)
            {
                if (Program.cDebuggingOn)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            finally
            {
                if (lClientStreamReader != null)
                {
                    lClientStreamReader.Close();
                }

                if (lClientStream != null)
                {
                    lClientStream.Close();
                }

                if (lOutStream != null)
                {
                    lOutStream.Close();
                }
            }
        }