Beispiel #1
0
        string EP_echo(IHttpRequestResponse req)
        {
            string result = "";

            try
            {
                string headers = "";
                foreach (var key in req.Headers.Keys)
                {
                    headers += $"{key}: {req.Headers[key]}\r\n";
                }

                string sentBody = readReqBodyAsString(req);

                result =
                    AndroidApp.Properties.Resources.Echo
                    .Replace("{0}", headers)
                    .Replace("{1}", sentBody)
                    .Replace("{2}", req.Method)
                    .Replace("{3}", req.Path)
                ;
            }
            catch (Exception ex)
            {
                result = stringHTML(ex.ToString(), "Error");
                AndroidBridge.e(TAG, ex.ToString());
            }
            return(result);
        }
Beispiel #2
0
        string EP_show_reason(IHttpRequestResponse req)
        {
            string result = "";
            string prefix = "url=";

            try
            {
                string reason = "No url found";

                if (!string.IsNullOrEmpty(req.QueryString))
                {
                    int startIndex = req.QueryString.IndexOf(prefix);
                    if (startIndex > -1)
                    {
                        Uri url = new Uri(System.Net.WebUtility.UrlDecode(req.QueryString.Substring(startIndex + prefix.Length)));
                        isBlockedFullFlow(url, out reason);
                    }
                }

                result = AndroidApp.Properties.Resources.BlockedPage.Replace("{0}", reasonToHTML(reason));
            }
            catch (Exception ex)
            {
                result = stringHTML(ex.ToString(), "Error");
                AndroidBridge.e(TAG, ex.ToString());
            }
            return(result);
        }
 public TwitterSearchService(IHttpRequestResponse httpRequestResponse, IOAuthCreationService oAuthCreationService, IMapUser mapUser, IHttpServer httpServer, IMapSearch mapSearch)
 {
     _httpRequestResponse  = httpRequestResponse;
     _oAuthCreationService = oAuthCreationService;
     _httpServer           = httpServer;
     _mapSearch            = mapSearch;
 }
 public TwitterSearchService(IHttpRequestResponse httpRequestResponse, IOAuthCreationService oAuthCreationService, IMapUser mapUser, IHttpServer httpServer, IMapSearch mapSearch)
 {
     _httpRequestResponse = httpRequestResponse;
     _oAuthCreationService = oAuthCreationService;
     _httpServer = httpServer;
     _mapSearch = mapSearch;
 }
Beispiel #5
0
        async Task SendResponseAsync(IHttpRequestResponse request, HttpSender httpSender)
        {
            try
            {
                if (request.RequestType == RequestType.TCP)
                {
                    string path = request.Path;
                    string responseContentType = ContentHTML;
                    string responseBody        = $"<html>\r\n<body>Unknown Path:\r\n{path}</body>\r\n</html>";


                    if (path.StartsWith("/echo"))
                    {
                        responseContentType = ContentHTML;
                        responseBody        = EP_echo(request);
                    }
                    else if (path.StartsWith("/history"))
                    {
                        responseContentType = ContentHTML;
                        responseBody        = EP_domainHistory(request);
                    }
                    else if (path.StartsWith("/check"))
                    {
                        responseContentType = ContentJSON;
                        responseBody        = EP_checkDomain(request);
                    }
                    else if (path.StartsWith("/reason"))
                    {
                        responseContentType = ContentHTML;
                        responseBody        = EP_show_reason(request);
                    }

                    var response = new HttpResponse
                    {
                        StatusCode     = (int)HttpStatusCode.OK,
                        ResponseReason = HttpStatusCode.OK.ToString(),
                        Headers        = new Dictionary <string, string>
                        {
                            { "Date", DateTime.UtcNow.ToString("r") },
                            { "Content-Type", responseContentType },
                            { "Connection", "close" }
                        },
                        Body = new MemoryStream(Encoding.UTF8.GetBytes(responseBody))
                    };

                    AndroidBridge.d(TAG, "[RESP-SEND] \"" + request.Path + "\" IP: " + ipString(request.RemoteIpEndPoint));

                    await httpSender.SendTcpResponseAsync(request, response).ConfigureAwait(false);

                    request.TcpClient.Close(); // Force close!

                    AndroidBridge.d(TAG, "[END] \"" + request.Path + "\" IP: " + ipString(request.RemoteIpEndPoint));
                }
            }
            catch (Exception ex)
            {
                AndroidBridge.e(TAG, ex.ToString());
            }
        }
 public TwitterStatusService(IHttpRequestResponse httpRequestResponse, IOAuthCreationService oAuthCreationService,
                             IMapStatus mapStatus, IAnalyzeStatusesService analyzeStatusesService)
 {
     _httpRequestResponse    = httpRequestResponse;
     _oAuthCreationService   = oAuthCreationService;
     _mapStatus              = mapStatus;
     _analyzeStatusesService = analyzeStatusesService;
 }
 public TwitterStatusService(IHttpRequestResponse httpRequestResponse, IOAuthCreationService oAuthCreationService,
                             IMapStatus mapStatus, IAnalyzeStatusesService analyzeStatusesService)
 {
     _httpRequestResponse = httpRequestResponse;
     _oAuthCreationService = oAuthCreationService;
     _mapStatus = mapStatus;
     _analyzeStatusesService = analyzeStatusesService;
 }
Beispiel #8
0
        string EP_domainHistory(IHttpRequestResponse req)
        {
            string result = "";

            try
            {
                string body = String.Join("<br />", domainHistory);
                result = stringHTML(body: body);
            }
            catch (Exception ex)
            {
                AndroidBridge.e(TAG, ex.ToString());
            }
            return(result);
        }
Beispiel #9
0
        string readReqBodyAsString(IHttpRequestResponse req)
        {
            string result = "";

            try
            {
                if (req.Body != null && req.Body.Length > 0)
                {
                    StreamReader reader = new StreamReader(req.Body);
                    req.Body.Position = 0;
                    result            = reader.ReadToEnd();
                }
            }
            catch (Exception ex)
            {
                AndroidBridge.e(TAG, ex.ToString());
            }
            return(result);
        }
Beispiel #10
0
        static async Task SendResponseAsync(IHttpRequestResponse request, HttpSender httpSender)
        {
            if (request.RequestType == RequestType.TCP)
            {
                var response = new HttpResponse
                {
                    StatusCode     = (int)HttpStatusCode.OK,
                    ResponseReason = HttpStatusCode.OK.ToString(),
                    Headers        = new Dictionary <string, string>
                    {
                        { "Date", DateTime.UtcNow.ToString("r") },
                        { "Content-Type", "text/html; charset=UTF-8" },
                    },
                    Body = new MemoryStream(Encoding.UTF8.GetBytes($"<html>\r\n<body>\r\n<h1>Hello, World! {DateTime.Now}</h1>\r\n</body>\r\n</html>"))
                };

                await httpSender.SendTcpResponseAsync(request, response).ConfigureAwait(false);
            }
        }
Beispiel #11
0
        string EP_checkDomain(IHttpRequestResponse req)
        {
            string result = "";

            try
            {
                var    reqJSON = readReqBodyAsString(req);
                string domain  = SpinResultHelper.getDomainName(reqJSON).Trim(new char[] { ' ', '"' });
                domainHistory.Add(domain);

                string reason = "";
                bool   block  = isBlockedFullFlow(new Uri(domain), out reason);


                if (block)
                {
                    try
                    {
                        File.AppendAllLines(Filenames.BLOCK_LOG.getAppPublic(), new[] {
                            string.Format("[{0}] {1} {2}", DateTime.Now, domain, reason)
                        });
                    }
                    catch (Exception ex)
                    {
                        AndroidBridge.e(TAG, ex);
                    }
                }

                result = SpinResultHelper.domainCategoryResult(block);
            }
            catch (Exception ex)
            {
                result = "{\"error\":\"0\"}".Replace("0", ex.ToString());
                AndroidBridge.e(TAG, ex.ToString());
            }
            return(result);
        }
 public TwitterService(IHttpRequestResponse httpRequestResponse, IOAuthCreationService oAuthCreationService, IMapUser mapUser)
 {
     _httpRequestResponse = httpRequestResponse;
     _oAuthCreationService = oAuthCreationService;
     _mapUser = mapUser;
 }
 public HomeController(ITwitterService twitterService, IAppSettings appSettings, IHttpRequestResponse httpRequestResponse)
 {
     _twitterService      = twitterService;
     _appSettings         = appSettings;
     _httpRequestResponse = httpRequestResponse;
 }
 public TwitterService(IHttpRequestResponse httpRequestResponse, IOAuthCreationService oAuthCreationService, IMapUser mapUser)
 {
     _httpRequestResponse  = httpRequestResponse;
     _oAuthCreationService = oAuthCreationService;
     _mapUser = mapUser;
 }
 public HomeController(ITwitterService twitterService, IAppSettings appSettings, IHttpRequestResponse httpRequestResponse)
 {
     _twitterService = twitterService;
     _appSettings = appSettings;
     _httpRequestResponse = httpRequestResponse;
 }