protected void Page_Load(object sender, EventArgs e)
    {
        string response = string.Empty;
        bool debug = false;

        try
        {
            // load global settings
            debug = Convert.ToBoolean(ConfigurationManager.AppSettings["spGengo_debug"]);
            string apiUrl = ConfigurationManager.AppSettings["spGengo_apiUrl"];
            string responseFormat = ConfigurationManager.AppSettings["spGengo_responseFormat"];
            bool useProxy = Convert.ToBoolean(ConfigurationManager.AppSettings["spGengo_useProxy"]);
            string proxyHost = ConfigurationManager.AppSettings["spGengo_proxyHost"];
            int proxyPort = int.Parse(ConfigurationManager.AppSettings["spGengo_proxyPort"]);
            string proxyUsername = ConfigurationManager.AppSettings["spGengo_proxyUsername"];
            string proxyPassword = ConfigurationManager.AppSettings["spGengo_proxyPassword"];
            string jobCount = ConfigurationManager.AppSettings["spGengo_jobCount"];

            // retrieve params from request
            string publicKey = Request.Params["publicKey"];
            string privateKey = Request.Params["privateKey"];
            string status = Request.Params["status"];
            string timestamp_after = Request.Params["timestamp_after"];
            string count = Request.Params["count"];

            // initialize api client
            WebProxy proxy = null;
            if (useProxy)
            {
                proxy = new WebProxy(proxyHost, proxyPort);
                proxy.Credentials = new NetworkCredential(proxyUsername, proxyPassword);
            }
            myGengoClient.myGengoClient.initialize(apiUrl, publicKey, privateKey, responseFormat, proxy);

            // invoke api
            bool lazyLoad = true; // if true, response doesn't include body_src and body_tgt
            response = myGengoClient.myGengoClient.GetMyJobs(status, timestamp_after, jobCount, lazyLoad);

            // return response
            Response.Write(response);
        }
        catch (Exception ex)
        {
            // return server error
            string debugInfo = string.Empty;
            if (debug)
            {
                debugInfo = "Message: " + ex.Message + "<br />" + "Type: " + ex.GetType().Name + "<br />" + "Source: " + ex.Source;
            }
            response = "{\"opstat\" : \"serverError\", \"response\" : \"" + debugInfo + "\"}";

            // unescape response
            response = response.Replace("\\", "");
            response = response.Replace("'", "");

            // return
            Response.Write(response);

        }
    }
    public ProxyManager(string[] proxies)
    {
        SEOWebRequest.Init();
            WebProxy proxyBuffer;
            foreach(string s in proxies)
            {
                string[] data = s.Split(':');
                proxyBuffer = new WebProxy(data[0], Int32.Parse(data[1]));
                if(data.Length==4)
                {
                    proxyBuffer.UseDefaultCredentials=false;
                    proxyBuffer.Credentials = new NetworkCredential(data[2], data[3]);
                }
                proxiesList.Add(proxyBuffer);
            }

            foreach(WebProxy proxy in proxiesList)
            {

                new Thread(() =>
                {
                    SEOWebRequest req = new SEOWebRequest();
                    string s = req.GET("http://www.google.com", proxy);
                    if (req.LastOK)
                    {
                        workingProxiesList.Add(proxy);
                    }
                    IncreaseCount();
                }).Start();
            }
    }
        public void GetProxy_IsSameForStringAndUriConstructors()
        {
            WebProxy proxy1 = new WebProxy("http://localhost:3000");
            WebProxy proxy2 = new WebProxy(new Uri("http://localhost:3000"));

            Uri uri = new Uri("http://0.0.0.0");

            Assert.AreEqual(proxy1.GetProxy(uri).OriginalString, proxy2.GetProxy(uri).OriginalString);
        }
Beispiel #4
0
 public static void Ctor_ExpectedPropertyValues(
     WebProxy p, Uri address, bool useDefaultCredentials, bool bypassLocal, string[] bypassedAddresses, ICredentials creds)
 {
     Assert.Equal(address, p.Address);
     Assert.Equal(useDefaultCredentials, p.UseDefaultCredentials);
     Assert.Equal(bypassLocal, p.BypassProxyOnLocal);
     Assert.Equal(bypassedAddresses, p.BypassList);
     Assert.Equal(bypassedAddresses, (string[])p.BypassArrayList.ToArray(typeof(string)));
     Assert.Equal(creds, p.Credentials);
 }
Beispiel #5
0
        public static void BypassProxyOnLocal_Roundtrip()
        {
            var p = new WebProxy();
            Assert.False(p.BypassProxyOnLocal);

            p.BypassProxyOnLocal = true;
            Assert.True(p.BypassProxyOnLocal);

            p.BypassProxyOnLocal = false;
            Assert.False(p.BypassProxyOnLocal);
        }
    public DataPrev.Domain.SistemaModel.ErroModel RequisicaoRV(long NumeroBeneficio)
    {
        DataPrev.Domain.SistemaModel.ErroModel Retorno = new Domain.SistemaModel.ErroModel();
        try
        {

            Domain.SistemaModel.IpModel IpList = new Domain.SistemaModel.IpModel();
            if (System.Configuration.ConfigurationManager.AppSettings["Consulta"] == "Lote")
                IpList = Rep.IpsLiberados();
            if (System.Configuration.ConfigurationManager.AppSettings["Consulta"] == "Sistema")
                IpList = Rep.IpsLiberados2();
            WebProxy proxyObj = new WebProxy(IpList.IP, IpList.Porta);
            proxyObj.Credentials = CredentialCache.DefaultCredentials;
            Retorno.Retorno3 = IpList.IP;

            Uri link = new Uri("http://www010.dataprev.gov.br/CWS/BIN/CWS.asp");
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(link);
            request.ProtocolVersion = HttpVersion.Version10;
            request.Proxy = proxyObj;
            request.Credentials = CredentialCache.DefaultCredentials;

            CookieContainer _Cookies = new CookieContainer();
            request.CookieContainer = _Cookies;
            request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            request.Referer = "http://www3.dataprev.gov.br/cws/contexto/hiscre/hiscrenet2.asp";

            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            byte[] byteArray = Encoding.UTF8.GetBytes("C_1=BLR00.11&C_2=&C_3=" + NumeroBeneficio + "&layout=8%2C69%2C10%2C8%2C1&submit=Transmite");
            request.ContentLength = byteArray.Length;

            var h = request.CookieContainer.GetCookies(request.RequestUri);
            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            int d = dataStream.ReadTimeout;
            dataStream.Close();

            //Fonte extrato retorno
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            Retorno.Fonte = reader.ReadToEnd();

            response.Close();
            request.Abort();
        }
        catch (Exception e)
        {
            Retorno.Fonte = e.Message;
        }
        Thread.Sleep(20000);

        return Retorno;
    }
Beispiel #7
0
        public WebClientEx(WebProxy proxy)
        {
            this.proxy = proxy;

            if (proxy != null)
            {
                if (proxy.Credentials != null)
                    this.Credentials = proxy.Credentials;
                if (proxy.Proxy != null)
                    this.Proxy = proxy.Proxy;
            }
        }
    public static HttpWebRequest AddProxyInfoToRequest(HttpWebRequest httpRequest, Uri proxyUri, string proxyId, string proxyPassword, string proxyDomain)
    {
        if (httpRequest != null)
            {

                WebProxy proxyInfo = new WebProxy();
                proxyInfo.Address = proxyUri;
                proxyInfo.BypassProxyOnLocal = true;
                proxyInfo.Credentials = new NetworkCredential(proxyId, proxyPassword, proxyDomain);
                httpRequest.Proxy = proxyInfo;

            }
            return httpRequest;
    }
Beispiel #9
0
        public static void UseDefaultCredentials_Roundtrip()
        {
            var p = new WebProxy();
            Assert.False(p.UseDefaultCredentials);
            Assert.Null(p.Credentials);

            p.UseDefaultCredentials = true;
            Assert.True(p.UseDefaultCredentials);
            Assert.NotNull(p.Credentials);

            p.UseDefaultCredentials = false;
            Assert.False(p.UseDefaultCredentials);
            Assert.Null(p.Credentials);
        }
Beispiel #10
0
 //Fact]
 public void WebProxyPrecedenceSetting()
 {
     var config = new AmazonS3Config
     {
         ProxyHost = "127.0.0.1",
         ProxyPort = 0,
         ProxyCredentials = new NetworkCredential("1", "1"),
         RegionEndpoint = RegionEndpoint.USEast1,
         UseHttp = true
     };
     var customProxy = new WebProxy("http://localhost:8888/");
     config.SetWebProxy(customProxy);
     Assert.Equal(customProxy, config.GetWebProxy()); 
 }
Beispiel #11
0
 //[Fact]
 public void HostPortPrecedenceSetting()
 {
     var customProxy = new WebProxy("http://localhost:8889/");
     var config = new AmazonS3Config();
     config.SetWebProxy(customProxy);
     config.ProxyHost = "127.0.0.1";
     config.ProxyPort = 8888;
     config.ProxyCredentials = new NetworkCredential("1", "1");
     config.RegionEndpoint = RegionEndpoint.USEast1;
     
     var setProxy = new WebProxy(config.ProxyHost, config.ProxyPort);
     config.SetWebProxy(setProxy);
     var c = config.GetWebProxy();
     Assert.Equal(setProxy, config.GetWebProxy());
 }
        internal void ConfigureProxy(HttpWebRequest httpRequest)
        {
#if BCL||CORECLR
#if BCL
            if (!string.IsNullOrEmpty(Config.ProxyHost) && Config.ProxyPort != -1)
            {
                WebProxy proxy = new WebProxy(Config.ProxyHost, Config.ProxyPort);
                httpRequest.Proxy = proxy;
            }
#elif CORECLR
            httpRequest.Proxy = Config.GetWebProxy();
#endif
            if (httpRequest.Proxy != null && Config.ProxyCredentials != null)
            {
                httpRequest.Proxy.Credentials = Config.ProxyCredentials;
            }
#endif
        }
Beispiel #13
0
        public static void BypassList_Roundtrip()
        {
            var p = new WebProxy();
            Assert.Empty(p.BypassList);
            Assert.Empty(p.BypassArrayList);

            string[] strings;

            strings = new string[] { "hello", "world" };
            p.BypassList = strings;
            Assert.Equal(strings, p.BypassList);
            Assert.Equal(strings, (string[])p.BypassArrayList.ToArray(typeof(string)));

            strings = new string[] { "hello" };
            p.BypassList = strings;
            Assert.Equal(strings, p.BypassList);
            Assert.Equal(strings, (string[])p.BypassArrayList.ToArray(typeof(string)));
        }
        public virtual void ProcessResponse(WebProxy proxy, HttpWebResponse httpResponse)
        {
            // send "as-is"
            Response.ClearHeaders();
            Response.Clear();
            Response.ContentType = httpResponse.ContentType;

            string s = httpResponse.CharacterSet;
            if (!string.IsNullOrEmpty(s))
                Response.Charset = s;

            using (Stream responseStream = httpResponse.GetResponseStream())
            {
                if (responseStream != null)
                    responseStream.CopyTo(Response.OutputStream);
            }
            Response.Flush();
            Response.End();
        }
Beispiel #15
0
public static void CheckAutoGlobalProxyForRequest(Uri resource)
{
    WebProxy proxy = new WebProxy();

    // Display the proxy's properties.
    DisplayProxyProperties(proxy);

    // See what proxy is used for the resource.
    Uri resourceProxy = proxy.GetProxy(resource);

    // Test to see whether a proxy was selected.
    if (resourceProxy == resource)
    {
        Console.WriteLine("No proxy for {0}", resource);
    } 
    else
    {
        Console.WriteLine("Proxy for {0} is {1}", resource.OriginalString,
            resourceProxy.ToString());
    }
}
        public HttpClient GenerateHttpClientFromWebRequest(WebRequest webRequest)
        {
            var handler = new HttpClientHandler
            {
                UseCookies = false,
                UseDefaultCredentials = false,
            };

            if (!string.IsNullOrEmpty(_tweetinviSettingsAccessor.ProxyURL))
            {
                var proxyUri = new Uri(_tweetinviSettingsAccessor.ProxyURL);
                var proxy = new WebProxy(string.Format("{0}://{1}:{2}", proxyUri.Scheme, proxyUri.Host, proxyUri.Port));

                // Check if Uri has user authentication specified
                if (!string.IsNullOrEmpty(proxyUri.UserInfo))
                {
                    var credentials = proxyUri.UserInfo.Split(':');

                    var username = credentials[0];
                    var password = credentials[1];
                    
                    proxy.Credentials = new NetworkCredential(username, password);
                }

                // Assign proxy to handler
                handler.Proxy = proxy;
                handler.UseProxy = true;
            }

            var httpClient = new HttpClient(handler);

            var webRequestHeaders = webRequest.Headers;
            foreach (var headerKey in webRequestHeaders.AllKeys)
            {
                httpClient.DefaultRequestHeaders.Add(headerKey, webRequestHeaders[headerKey]);
            }

            return httpClient;
        }
Beispiel #17
0
    public DataTable GetLocation1()
    {
        string strIPAddress = GetUserIP();
        //Create a WebRequest with the current Ip
        WebRequest _objWebRequest =
            WebRequest.Create("http://ipinfodb.com/ip_query.php?ip=" 
            //http://ipinfodb.com/ip_query.php?ip=
                           +strIPAddress);
        //Create a Web Proxy
        WebProxy _objWebProxy =
           new WebProxy("http://freegeoip.appspot.com/xml/"
                     + strIPAddress, true);

        //Assign the proxy to the WebRequest
        _objWebRequest.Proxy = _objWebProxy;

        //Set the timeout in Seconds for the WebRequest
        _objWebRequest.Timeout = 2000;

        try
        {
            //Get the WebResponse 
            WebResponse _objWebResponse = _objWebRequest.GetResponse();
            //Read the Response in a XMLTextReader
            XmlTextReader _objXmlTextReader
                = new XmlTextReader(_objWebResponse.GetResponseStream());

            //Create a new DataSet
            DataSet _objDataSet = new DataSet();
            //Read the Response into the DataSet
            _objDataSet.ReadXml(_objXmlTextReader);

            return _objDataSet.Tables[0];
        }
        catch
        {
            return null;
        }
    }
 public string GET(string url,WebProxy proxy=null)
 {
     LastOK = false;
         string s = string.Empty;
         req = (HttpWebRequest)WebRequest.Create(url);
         req.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36";
         req.Proxy = (WebProxy)proxy;
         req.UseDefaultCredentials = false;
         req.KeepAlive = false;
         req.Timeout = 3000;
         try
         {
             using (StreamReader sr = new StreamReader(req.GetResponse().GetResponseStream()))
             {
                 LastOK = true;
                 return sr.ReadToEnd();
             }
         }
         catch(Exception ex)
         {
             LastError = ex.Message;
             return null;
         }
 }
        public IWebProxy GetProxy(string proxyURL)
        {
            if (!string.IsNullOrEmpty(proxyURL))
            {
                var proxyUri = new Uri(proxyURL);
                var proxy = new WebProxy(string.Format("{0}://{1}:{2}", proxyUri.Scheme, proxyUri.Host, proxyUri.Port));

                // Check if Uri has user authentication specified
                if (!string.IsNullOrEmpty(proxyUri.UserInfo))
                {
                    var credentials = proxyUri.UserInfo.Split(':');

                    var username = credentials[0];
                    var password = credentials[1];

                    proxy.Credentials = new NetworkCredential(username, password);
                }

                // Assign proxy to handler
                return proxy;
            }

            return null;
        }
Beispiel #20
0
        static void Main(string[] args)
        {
            // Each suzuki account has two parameters : User, Password
            var user     = "******";          // !!! rewrite value from your account !!!
            var password = "******";      // !!! rewrite value from your account !!!

            // We keep cookies here
            var cookies = new CookieContainer();

            // Any proxy, for example Fiddler
            var proxy = new WebProxy("127.0.0.1:8888");

            var getRequest = new GetRequest()
            {
                Address   = "https://suzuki.snaponepc.com/epc/#/",
                Accept    = "text/html, application/xhtml+xml, */*",
                Host      = "suzuki.snaponepc.com",
                KeepAlive = true,
                Proxy     = proxy
            };

            getRequest.Run(ref cookies);

            // password must be encoded into base64
            var passBase64 = password.ToBase64();
            var data       = $"user={user}&password={passBase64}";

            // auth request
            var postRequest = new PostRequest()
            {
                Data        = data,
                Address     = $"https://suzuki.snaponepc.com/epc-services/auth/login/",
                Accept      = "text/html, application/xhtml+xml, */*",
                Host        = "suzuki.snaponepc.com",
                ContentType = "application/x-www-form-urlencoded",
                Referer     = "https://suzuki.snaponepc.com/epc/#/",
                KeepAlive   = true,
                Proxy       = proxy
            };

            postRequest.Run(ref cookies);

            // we need to use try/catch. if auth is unsuccessful then we will catch an exception
            try
            {
                postRequest = new PostRequest()
                {
                    Data        = "",
                    Address     = $"https://suzuki.snaponepc.com/epc-services/auth/account",
                    Accept      = "text/html, application/xhtml+xml, */*",
                    Host        = "suzuki.snaponepc.com",
                    ContentType = "application/x-www-form-urlencoded",
                    Referer     = "https://suzuki.snaponepc.com/epc/",
                    KeepAlive   = true,
                    Proxy       = proxy
                };
                postRequest.Run(ref cookies);
            }
            catch (Exception exception)
            {
                Config.Instance.AddLogInfo($"Auth result: bad. {exception.Message}");
                return;
            }



            // if we here then auth is successful

            // comfortable cookies presentation
            var catalogCookies = cookies.GetCookieCollection().CatalogCookies();

            // writing cookies in log
            foreach (var cookie in catalogCookies)
            {
                Config.Instance.AddLogInfo($"cookie: {cookie}");
            }

            // writing Authentication result status in log
            Config.Instance.AddLogInfo($"Auth result: successful");
        }
Beispiel #21
0
        public string 查询进场码头(string 英文船名, string 航次, string 提单号)
        {
            string 进场码头url = m_运抵报告对比进场码头url.Replace("#英文船名#", 英文船名);
            进场码头url = 进场码头url.Replace("#航次#", 航次);
            进场码头url = 进场码头url.Replace("#提单号#", 提单号);

            WebProxy webProxy = new WebProxy();
            webProxy.Encoding = Encoding.UTF8;
            string htmlInfo = webProxy.GetToString(进场码头url);
            return nbedi.PageAnalyze.Parse查询进场码头(htmlInfo);
        }
Beispiel #22
0
        public static void BypassList_DoesntContainUrl_NotBypassed()
        {
            var p = new WebProxy("http://microsoft.com");

            Assert.Equal(new Uri("http://microsoft.com"), p.GetProxy(new Uri("http://bing.com")));
        }
Beispiel #23
0
        public static void GetDefaultProxy_NotSupported()
        {
#pragma warning disable 0618 // obsolete method
            Assert.Throws <PlatformNotSupportedException>(() => WebProxy.GetDefaultProxy());
#pragma warning restore 0618
        }
Beispiel #24
0
 public static void BypassList_ContainsUrl_IsBypassed()
 {
     var p = new WebProxy("http://microsoft.com", false, new[] { "hello", "bing.*", "world" });
     Assert.Equal(new Uri("http://bing.com"), p.GetProxy(new Uri("http://bing.com")));
 }
Beispiel #25
0
 public static void InvalidBypassUrl_AddedDirectlyToList_SilentlyEaten()
 {
     var p = new WebProxy("http://bing.com");
     p.BypassArrayList.Add("*.com");
     p.IsBypassed(new Uri("http://microsoft.com")); // exception should be silently eaten
 }
Beispiel #26
0
        public void Configure()
        {
            if (Type == "None")
            {
                log.Info("Removing proxy usage.");
                WebRequest.DefaultWebProxy = null;
            }
            else if (Type == "Custom")
            {
                log.Info("Setting custom proxy.");
                WebProxy wp = new WebProxy();
                wp.Address = new System.Uri(string.Format("http://{0}:{1}", ServerName, Port));
                log.Debug("Using " + wp.Address);
                wp.BypassProxyOnLocal = true;
                if (AuthenticationRequired && !string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password))
                {
                    if (UserName.Contains(@"\"))
                    {
                        try {
                            string[] usernameBits = UserName.Split('\\');
                            wp.Credentials = new NetworkCredential(usernameBits[1], Password, usernameBits[0]);
                        } catch (System.Exception ex) {
                            log.Error("Failed to extract domain from proxy username: "******"Using default proxy (app.config / IE).");
                log.Info("Setting system-wide proxy.");
                IWebProxy iwp = WebRequest.GetSystemWebProxy();
                iwp.Credentials            = CredentialCache.DefaultNetworkCredentials;
                WebRequest.DefaultWebProxy = iwp;
            }

            if (WebRequest.DefaultWebProxy != null)
            {
                try {
                    log.Debug("Testing the system proxy.");
                    String     testUrl  = "http://www.google.com";
                    WebRequest wr       = WebRequest.CreateDefault(new System.Uri(testUrl));
                    System.Uri proxyUri = wr.Proxy.GetProxy(new System.Uri(testUrl));
                    log.Debug("Confirmation of configured proxy: " + proxyUri.OriginalString);
                    if (testUrl != proxyUri.OriginalString)
                    {
                        try {
                            new Extensions.OgcsWebClient().OpenRead(testUrl);
                        } catch (WebException ex) {
                            if (ex.Response != null)
                            {
                                System.IO.Stream       stream = null;
                                System.IO.StreamReader sr     = null;
                                try {
                                    HttpWebResponse hwr = ex.Response as HttpWebResponse;
                                    log.Debug("Proxy error status code: " + hwr.StatusCode + " = " + hwr.StatusDescription);
                                    stream = hwr.GetResponseStream();
                                    sr     = new System.IO.StreamReader(stream);
                                    log.Fail(sr.ReadToEnd());
                                } catch (System.Exception ex2) {
                                    OGCSexception.Analyse("Could not analyse WebException response.", ex2);
                                } finally {
                                    if (sr != null)
                                    {
                                        sr.Close();
                                    }
                                    if (stream != null)
                                    {
                                        stream.Close();
                                    }
                                }
                            }
                            else
                            {
                                OGCSexception.Analyse("Testing proxy connection failed.", ex);
                            }
                        }
                    }
                } catch (System.Exception ex) {
                    OGCSexception.Analyse("Failed to confirm proxy settings.", ex);
                }
            }
        }
Beispiel #27
0
 public static void AssignWebProxy()
 {
     UpStreamWebProxy = new WebProxy(UpStream.IPAddress, UpStream.Port);
 }
Beispiel #28
0
        private void DownloadFile(string url, FileInfo file, int size)
        {
            AbortFlag = false;

            if (file.Exists)
            {
                if (file.Length == size)
                {
                    return;
                }
                else
                {
                    file.Delete();
                }
            }
            if (!file.Directory.Exists)
            {
                file.Directory.Create();
            }

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);

            request.Headers.Add("Cache-Control", "no-cache");
            request.Credentials = CredentialCache.DefaultCredentials;

            if (Configure.Proxy.Enable)
            {
                WebProxy proxyObject = Configure.Proxy.GetWebProxy();
                if (proxyObject != null)
                {
                    request.Proxy = proxyObject;
                }
            }

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream          strm     = response.GetResponseStream();

            FileStream   fst = new FileStream(file.FullName, FileMode.CreateNew);
            StreamWriter sw  = new StreamWriter(fst);

            long time = DateTime.Now.Ticks;
            int  countRead;
            int  downloadSize = 0;
            bool userAbort    = false;

            do
            {
                byte[] buf = new byte[2 * 1024];
                countRead = strm.Read(buf, 0, 2 * 1024);
                fst.Write(buf, 0, countRead);
                downloadSize += countRead;

                #region if (DateTime.Now.Ticks - time > 10000000L) {...}
                if (DateTime.Now.Ticks - time > 10000000L)
                {
                    this.OnDownloadFileProcess(new WebReaderProcessEventArgs(file, size, downloadSize));
                    time = DateTime.Now.Ticks;
                }
                #endregion

#if DEBUG
                // Thread.Sleep(500);
#endif
                userAbort = AbortFlag;
                if (userAbort)
                {
                    break;
                }
            } while (countRead > 0);

            fst.Flush();
            fst.Close();
            response.Close();
            file.Refresh();
            AbortFlag = false;

            if (userAbort)
            {
                file.Delete();
                throw (new WebReaderException(UpdateManagerError.UserAbort, "Abort"));
            }

            if (file.Length != size)
            {
                file.Delete();
                throw(new WebReaderException(UpdateManagerError.ServerError, "It is impossible to download a file"));
            }
        }
Beispiel #29
0
 public ProxyFactory(WebProxy proxy)
 {
     this.proxy = proxy;
 }
Beispiel #30
0
        //Scans URL and determines whether it is good, bad, or seized
        public void ScanURL(string url)
        {
            if (url.Length > 0)
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.UserAgent = @"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4";
                WebProxy myproxy = new WebProxy(proxyUrl_text.Text, Convert.ToInt32(proxyPort_text.Text));
                myproxy.BypassProxyOnLocal = false;
                request.Proxy  = myproxy;
                request.Method = "GET";

                try {
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                    //If the website is up and working let's check if it's header is ok
                    if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted)
                    {
                        var stream = response.GetResponseStream();
                        var reader = new StreamReader(stream);
                        var html   = reader.ReadToEnd();

                        if (html.Contains("<title>Alert!</title>"))
                        {
                            //Page has been taken down, and contains nothing interesting/useful
                            if (verbose.Checked)
                            {
                                WriteOutput("Site Seized: " + url);
                            }
                            if (saveBad.Checked)
                            {
                                seizedSites.Add(url);
                            }
                        }
                        else
                        {
                            //Page is still alive
                            if (verbose.Checked)
                            {
                                WriteOutput("Site Good: " + url);
                            }

                            if (desc.Checked)
                            {
                                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                                doc.LoadHtml(html);

                                HtmlNodeCollection titlenode = doc.DocumentNode.SelectNodes("//title");
                                HtmlNode           title     = titlenode[0];
                                string             t         = title.InnerText;
                                goodSites.Add(t + " - " + url);
                            }
                            else
                            {
                                goodSites.Add(url);
                            }
                        }
                    }
                    else    //Site did not return a 200 status...must be bad
                    {
                        if (verbose.Checked)
                        {
                            WriteOutput("Site Bad: " + url);
                        }
                        if (saveBad.Checked)
                        {
                            removedSites.Add(url);
                        }
                    }
                    response.Close();
                    return;
                } catch (System.Net.WebException e) { //Site returned a 5** status...must be bad
                    if (verbose.Checked)
                    {
                        WriteOutput("Site Bad: " + url);
                    }
                    if (saveBad.Checked)
                    {
                        removedSites.Add(url);
                    }
                }

                progressbar.Value = (rawLinks.FindIndex(delegate(string s) {
                    return(s == url);
                }) / rawLinks.Count) * 100;
            }
        }
Beispiel #31
0
        //Gets links from YATD and scans them
        public void ScanYATD()
        {
            if (verbose.Checked)
            {
                WriteOutput("Scanning YATD...");
            }

            string yatdurl = "http://bdpuqvsqmphctrcs.onion/noscript.html";
            int    count   = 0;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(yatdurl);

            request.UserAgent = @useragent_text.Text;
            WebProxy myproxy = new WebProxy(proxyUrl_text.Text, Convert.ToInt32(proxyPort_text.Text));

            myproxy.BypassProxyOnLocal = false;
            request.Proxy  = myproxy;
            request.Method = "GET";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            //If the website is up and working let's check if it's header is ok
            if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted)
            {
                var stream = response.GetResponseStream();
                var reader = new StreamReader(stream);
                var html   = reader.ReadToEnd();

                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();

                doc.LoadHtml(html);

                foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//table[@id='example_noscript']/tbody/tr/td[2]/a"))
                {
                    string link = node.Attributes["href"].Value;
                    rawLinks.Add(link);
                    if (verbose.Checked)
                    {
                        WriteOutput("Found Link: " + link);
                    }
                    if (Convert.ToInt32(numlinks_text.Text) > 0)
                    {
                        count++;
                        if (count >= Convert.ToInt32(numlinks_text.Text))
                        {
                            break;
                        }
                    }
                }

                if (verbose.Checked)
                {
                    WriteOutput("Done searching YATD, now on to scanning links");
                }

                return;
            }
            else
            {
                Console.WriteLine("ERROR! COULD NOT OPEN YATD!");
                System.Threading.Thread.Sleep(5000);
                System.Environment.Exit(1);
            }
        }
        public static Boolean validarDatos()
        {
            long currentTime = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond);

            //Console.WriteLine($"Validando ... currentTime {currentTime} - continousWorkingTimeMillis {continousWorkingTimeMillis} ");

            if (continousWorkingTimeMillis == 0)
            {
                //JUST STARTED OR RETURNED FROM BREAK
                //SEND NOTIFICATION TO TAKE BREAKS EVERY HOUR


                new NotificationManager().sendNotificationMessage("Keep in mind: It is recommended to take at least 5 min break each hour.", "", false, "");
                lastBreakMillis            = currentTime;
                continousWorkingTimeMillis = 1;
                lastNotificationMillis     = currentTime;
                return(true);
            }

            continousWorkingTimeMillis = currentTime - lastBreakMillis;
            long idleTime    = currentTime - lastActivityMillis;
            long elapsedTime = continousWorkingTimeMillis;

            Console.WriteLine($"Validando ... elapsedTime {elapsedTime / 60000} - idleTime {idleTime / 60000} ");

            if (idleTime > idleTimeToUpdateBreakMiliseconds) //15 segundos idle
            {
                //ENVIAR
                Console.WriteLine($"BREAK REPORT DUE TO {idleTimeToUpdateBreakMiliseconds} IDLE!!");
                continousWorkingTimeMillis = 1;
                lastBreakMillis            = currentTime;
                return(false);
            }

            if (elapsedTime > workingTimeBeforeAlertMiliseconds)  //X tiempo trabajado
            {
                //CREATE WEB OBBECT WITH OLIVER WYMAN PROXY
                WebProxy proxyObj = new WebProxy("http://usdal1-03pr02-vip.mgd.mrshmc.com:8888");
                proxyObj.Credentials = CredentialCache.DefaultCredentials;
                WebClient myWebClient = new WebClient();
                myWebClient.Proxy = proxyObj;

                // GETTING JSON
                var json = myWebClient.DownloadString("https://spreadsheets.google.com/feeds/list/1xRGex8sYPd6P4OaxLbSkTgoTFkK2KWU2U8M9NmaTrd8/od6/public/basic?alt=json&pli=1");

                dynamic spreadsheets  = Newtonsoft.Json.JsonConvert.DeserializeObject(json.ToString());
                JArray  messages      = (JArray)spreadsheets["feed"]["entry"];
                int     messagesCount = messages.Count - 1;

                Random random             = new Random();
                int    rInt               = random.Next(0, messagesCount);
                String messageFullToWrite = spreadsheets["feed"]["entry"][rInt]["content"]["$t"];
                String messageToWrite     = messageFullToWrite.Substring(0, messageFullToWrite.IndexOf(", imageurl: "));

                String[] arrString = messageFullToWrite.Split(',');
                Console.WriteLine(arrString[1]);



                String imageHero = arrString[1];
                imageHero = imageHero.Replace(" imageurl: ", "");

                Console.WriteLine(imageHero);
                new NotificationManager().sendNotificationMessage($"We noticed that you been working for to long, Please take a break!", messageToWrite.Replace("message: ", ""), true, imageHero);
                lastNotificationMillis = currentTime;
                lastBreakMillis        = currentTime;
                return(true);
            }
            return(false);
        }
Beispiel #33
0
        public void DownloadFile(Object stateInfo)
        {
            long maxBytes   = downloadItem.MaxBytes;
            int  intStep    = 100 * 1024;
            int  intCounter = 0;

            int bytesProcessed = 0;

            string ProgressStatus = "";
            // Assign values to these objects here so that they can
            // be referenced in the finally block
            Stream remoteStream = null;
            Stream localStream  = null;

            WebResponse response  = null;
            bool        boolRetry = true;

            while (boolRetry && intTimeoutRetry < 10)
            {
                boolRetry = false;
                // Use a try/catch/finally block as both the WebRequest and Stream
                // classes throw exceptions upon error
                try
                {
                    // Create a request for the specified remote file name

                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadItem.Url);
                    request.ProtocolVersion = HttpVersion.Version11;


                    //	WebRequest request = WebRequest.Create(remoteFilename);

                    if (downloadItem.Username != "")
                    {
                        request.Credentials = new NetworkCredential(downloadItem.Username, downloadItem.Password);
                    }
                    ((HttpWebRequest)request).UserAgent = "Doppler " + Application.ProductVersion;
                    if (downloadItem.UseProxy)
                    {
                        if (downloadItem.UseIEProxy == true)
                        {
                            request.Proxy = WebRequest.DefaultWebProxy;
                        }
                        else
                        {
                            WebProxy proxy = new WebProxy(downloadItem.ProxyServer, int.Parse(downloadItem.ProxyPort));

                            if (downloadItem.ProxyAuthentication == true)
                            {
                                proxy.Credentials = new NetworkCredential(downloadItem.ProxyUsername, downloadItem.ProxyPassword);
                            }
                            request.Proxy = proxy;
                        }
                    }

                    WebHeaderCollection webHeaderCollection = request.Headers;
                    webHeaderCollection.Add("Pragma", "no-cache");
                    webHeaderCollection.Add("Cache-Control", "no-cache");
                    webHeaderCollection.Add("Accept-Encoding", "gzip, deflate");
                    request.Pipelined = true;
                    request.KeepAlive = true;
                    int intLength = 0;

                    if ((System.IO.File.Exists(filename) || System.IO.File.Exists(filename + ".incomplete")) && downloadItem.DownloadSize > 0)
                    {
                        System.IO.FileInfo fileInfo;
                        // file exists try byte-ranging
                        if (System.IO.File.Exists(filename))
                        {
                            fileInfo = new System.IO.FileInfo(filename);
                        }
                        else
                        {
                            fileInfo = new System.IO.FileInfo(filename + ".incomplete");
                        }
                        intLength = Convert.ToInt32(fileInfo.Length);

                        int intRange = Convert.ToInt32(downloadItem.DownloadSize) - intLength;

                        //MessageBox.Show(intRange.ToString());
                        if (downloadItem.ByteRanging)
                        {
                            request.AddRange(-intRange);
                        }
                        //request.AddRange(intLength,Convert.ToInt32(longDownloadsize));
                        //((HttpWebRequest)request).AddRange(intLength,Convert.ToInt32(longDownloadsize));
                    }


                    request.Timeout = downloadItem.TimeOut;

                    if (request != null)
                    {
                        request.Method = "GET";
                        response       = request.GetResponse();

                        if (response != null)
                        {
                            // Once the WebResponse object has been retrieved,
                            // get the stream object associated with the response's data

                            if (maxBytes == 0)
                            {
                                maxBytes = response.ContentLength;
                            }

                            if (maxBytes <= response.ContentLength)
                            {
                                remoteStream = GetResponseStream((HttpWebResponse)response);

                                //remoteStream = response.GetResponseStream()
                                // Create the local file
                                try
                                {
                                    if (intLength > 0 && maxBytes <= response.ContentLength)
                                    {
                                        localStream = File.OpenWrite(filename + ".incomplete");
                                        localStream.Seek(Convert.ToInt64(intLength), System.IO.SeekOrigin.Begin);
                                    }
                                    else
                                    {
                                        localStream = File.Create(filename + ".incomplete");
                                    }
                                }

                                catch (Exception)
                                {
                                    //Console.Error.WriteLine(ex.Message);
                                    //log.logMsg(ex.Message + ", while downloading " + remoteFilename, true, "Retriever");
                                    localStream.Close();
                                    localStream = File.Create(filename + ".incomplete");
                                }

                                // Allocate a 1k buffer or a buffer of a different size if set
                                byte[] buffer;
                                if (downloadItem.BufferSize == 0)
                                {
                                    buffer = new byte[1024 * 10];
                                }
                                else
                                {
                                    buffer = new byte[downloadItem.BufferSize];
                                }


                                string strFile = (new System.IO.FileInfo(filename)).Name;

                                long longKb = (response.ContentLength + Convert.ToInt64(intLength)) / 1024;

                                string strDecodedFile = System.Web.HttpUtility.UrlDecode(strFile);

                                int bytesProcessedKb = 0;
                                int bytesRead;
                                if (intLength > 0 && maxBytes <= response.ContentLength)
                                {
                                    bytesProcessed = intLength;
                                }
                                if (downloadItem.ByteRanging == false)
                                {
                                    bytesProcessed = 0;
                                }
                                int intImageCounter = 0;

                                if (Settings.Default.LogLevel > 1)
                                {
                                    if (bytesProcessed > 0)
                                    {
                                        log.Info("Continueing download: " + downloadItem.Filename);
                                    }
                                    else
                                    {
                                        log.Info("Starting download: " + downloadItem.Filename);
                                    }
                                }
                                long startTicks            = DateTime.Now.Ticks;
                                int  currentBytesProcessed = 0;
                                do
                                {
                                    while (paused)
                                    { // do nothing, just pause
                                    }
                                    bytesRead = remoteStream.Read(buffer, 0, buffer.Length);
                                    localStream.Write(buffer, 0, bytesRead);

                                    bytesProcessed        += bytesRead;
                                    currentBytesProcessed += bytesRead;
                                    if (intCounter > intStep)
                                    {
                                        if (intImageCounter < 9)
                                        {
                                            intImageCounter++;
                                        }
                                        else
                                        {
                                            intImageCounter = 0;
                                        }
                                        intCounter = 0;

                                        if (response.ContentLength > 0)
                                        {
                                            //string strStatus = bytesProcessedKb.ToString() + " / " + longKb.ToString() + " KB - " + strDecodedFile;

                                            string finishedIn = "UNK";
                                            try
                                            {
                                                long     currentTicks  = DateTime.Now.Ticks;
                                                long     ticksPerBlock = currentTicks - startTicks;
                                                long     ticksPerByte  = ticksPerBlock / Convert.ToInt64(currentBytesProcessed);
                                                long     totalTicks    = startTicks + (ticksPerByte * (response.ContentLength));
                                                TimeSpan timeSpan      = new TimeSpan(totalTicks - currentTicks);
                                                finishedIn = String.Format("{0}:{1}{2}", timeSpan.Minutes, ((timeSpan.Seconds < 10) ? "0" : ""), (timeSpan.Seconds > 0) ? timeSpan.Seconds : 0);
                                            }
                                            catch { }

                                            ProgressStatus = GetStatusText(longKb, bytesProcessedKb);

                                            DownloadProgress(downloadItem, 0, Convert.ToInt32(response.ContentLength) + intLength, bytesProcessed, ProgressStatus, finishedIn, listViewItem);
                                        }
                                    }
                                    else
                                    {
                                        intCounter += bytesRead;
                                    }
                                    bytesProcessedKb = bytesProcessed / 1024;
                                    remoteStream.Flush();
                                } while (bytesRead > 0 && boolAbort == false);
                                if (Settings.Default.LogLevel > 1)
                                {
                                    log.Info("Finished download: " + downloadItem.Filename);
                                }

                                if (response != null)
                                {
                                    response.Close();
                                }
                                if (remoteStream != null)
                                {
                                    remoteStream.Close();
                                }
                                if (localStream != null)
                                {
                                    localStream.Close();
                                }
                                // remove the '.incomplete' extension if it wasn't aborted
                                if (boolAbort == false)
                                {
                                    System.IO.File.Move(filename + ".incomplete", filename);
                                }
                            }
                        }
                    }

                    if (boolAbort == false)
                    {
                        DownloadComplete(downloadItem, listViewItem);
                    }
                    else
                    {
                        DownloadAborted(downloadItem, listViewItem);
                    }
                }
                catch (ThreadAbortException)
                {
                    // thread aborted
                    if (Thread.CurrentThread.ThreadState != System.Threading.ThreadState.AbortRequested)
                    {
                        DownloadAborted(downloadItem, listViewItem);
                    }
                }
                catch (WebException e)
                {
                    //Console.Error.WriteLine(e.Message);
                    if (e.Status == System.Net.WebExceptionStatus.Timeout || e.Message.ToLower().StartsWith("parameter name: count") || e.Message.ToLower().StartsWith("Non-negative number"))
                    {
                        // retry the download
                        boolRetry = true;
                        intTimeoutRetry++;

                        maxBytes = 0;
                        Thread.Sleep(new System.TimeSpan(0, 0, 5 * intTimeoutRetry));
                        int intRetrySeconds = intTimeoutRetry * 5;
                        //log.logMsg(e.Message + ", while downloading " + remoteFilename +". Retry " + timeoutRetry.ToString() + " of 10 after " + intRetrySeconds.ToString() + " seconds.", true, "Retriever");
                        // Thread.Sleep(new System.TimeSpan(0, 0, 0, 5 * intTimeoutRetry, 0));
                    }
                    else
                    {
                        if (e.Status == WebExceptionStatus.ProtocolError)
                        {
                            log.Error("Protocol error, removing temporary file and retrying", e);
                            boolRetry = true;
                            intTimeoutRetry++;
                            Thread.Sleep(new System.TimeSpan(0, 0, 5 * intTimeoutRetry));
                            if (File.Exists(filename + ".incomplete"))
                            {
                                File.Delete(filename + ".incomplete");
                            }
                        }
                        else
                        {
                            DownloadError(downloadItem, listViewItem, String.Format(FormStrings.xWhileDownloadingy, e.Message, downloadItem.Url), e);
                        }
                        //	boolError = true;
                        //log.logMsg(e.Message + ", while downloading " + remoteFilename, true, "Retriever");
                    }
                }
                catch (Exception e)
                {
                    if (e.Message.ToLower().StartsWith("parameter: count") || e.Message.ToLower().StartsWith("non-negative number"))
                    {
                        boolRetry = true;
                        intTimeoutRetry++;

                        maxBytes = 0;
                        Thread.Sleep(new System.TimeSpan(0, 0, 5 * intTimeoutRetry));
                        int intRetrySeconds = intTimeoutRetry & 5;
                    }
                    else
                    {
                        if (Settings.Default.LogLevel > 0)
                        {
                            log.Error("Error while downloading from " + downloadItem.Url, e);
                        }
                        DownloadError(downloadItem, listViewItem, String.Format(FormStrings.xWhileDownloadingy, e.Message, downloadItem.Url), e);
                        //Console.Error.WriteLine(e.Message);
                        //boolError = true;
                        //log.logMsg(e.Message + ", while downloading " + remoteFilename, true, "Retriever");
                    }
                }
                finally
                {
                    //	fMain.notifyIcon1.Icon = new Icon(typeof(frmMain), "SystemTray.ico");
                    // Close the response and streams objects here
                    // to make sure they're closed even if an exception
                    // is thrown at some point
                    if (response != null)
                    {
                        response.Close();
                    }
                    if (remoteStream != null)
                    {
                        remoteStream.Close();
                    }
                    if (localStream != null)
                    {
                        localStream.Close();
                    }

                    //	fMain.notifyIcon1.Icon = new Icon(typeof(frmMain), "SystemTray.ico");
                    //	lvi.SubItems[1].ImageIndex = intOldImage;
                    //	lvi.SubItems[3].ForceText = true;
                    //	lvi.SubItems[4].Text = "";
                }
            }
            // Return total bytes processed to caller.

            //return bytesProcessed;
        }
Beispiel #34
0
    internal static HtmlAgilityPack.HtmlDocument GetHtmlDocumentByUrl(string url, Getrix.Logging.Log logger)
    {
        string result = "";
        int ms = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SleepMillisecondi"]);
        //int msbuffer = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SleepBufferMillisecondi"]);
        System.Threading.Thread.Sleep(ms);
        try
        {
            HttpWebRequest myHttpWebRequest1 =
              (HttpWebRequest)WebRequest.Create(url);
            WebProxy p = new WebProxy(ConfigurationManager.AppSettings["proxyUrl"],
                Convert.ToInt32(ConfigurationManager.AppSettings["proxyPort"]));
            p.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["proxyUser"],
                ConfigurationManager.AppSettings["proxyPassword"]);
            myHttpWebRequest1.Proxy = p;
            myHttpWebRequest1.KeepAlive = true;
            HttpWebResponse myHttpWebResponse1 =
              (HttpWebResponse)myHttpWebRequest1.GetResponse();

            Stream streamResponse = myHttpWebResponse1.GetResponseStream();
            StreamReader streamRead = new StreamReader(streamResponse);
            Char[] readBuff = new Char[256];
            int count = streamRead.Read(readBuff, 0, 256);

            while (count > 0)
            {

                String outputData = new String(readBuff, 0, count);
                result += outputData;
                //System.Threading.Thread.Sleep(msbuffer);
                count = streamRead.Read(readBuff, 0, 256);
            }
            streamResponse.Close();
            streamRead.Close();
            myHttpWebResponse1.Close();

        }
        catch (Exception ex)
        {
            logger.Error("Errore scaricamento url " + url, ex);
            xxxx.Program.esitoErrors += 1;
            xxxx.Program.esitoErrorsNotes += "\r\nErrore scaricamento url " + url + "  - " + ex.Message;
        }
        var doc = new HtmlAgilityPack.HtmlDocument();
        doc.LoadHtml(result);

        return doc;
    }
Beispiel #35
0
 /// <summary>
 /// 异步创建爬虫
 /// </summary>
 /// <param name="uri"></param>
 /// <param name="proxy"></param>
 /// <returns></returns>
 public async Task <string> Start(Uri uri, WebProxy proxy = null)
 {
     return(await Task.Run(() =>
     {
         var pageSource = string.Empty;
         try
         {
             OnStart?.Invoke(this, new OnStartEventArgs(uri));
             Stopwatch watch = new Stopwatch();
             watch.Start();
             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
             request.Accept = "*/*";
             //定义文档类型及编码
             request.ContentType = "application/x-www-form-urlencoded";
             request.AllowAutoRedirect = false;//禁止自动跳转
             request.UserAgent = UAString;
             //定义请求超时事件为5s
             request.Timeout = 5000;
             //长连接
             request.KeepAlive = true;
             request.Method = "GET";
             //设置代理服务器IP,伪装请求地址
             if (proxy != null)
             {
                 request.Proxy = proxy;
             }
             //附加Cookie容器
             request.CookieContainer = this.CookieContainer;
             //定义最大链接数
             request.ServicePoint.ConnectionLimit = int.MaxValue;
             //获取请求响应
             HttpWebResponse response = (HttpWebResponse)request.GetResponse();
             //将Cookie加入容器,保持登录状态
             foreach (Cookie cookie in response.Cookies)
             {
                 this.CookieContainer.Add(cookie);
             }
             //获取响应流
             Stream stream = response.GetResponseStream();
             //以UTF8的方式读取流
             StreamReader reader = new StreamReader(stream, Encoding.UTF8);
             //获取网站资源
             pageSource = reader.ReadToEnd();
             watch.Stop();
             //获取当前任务线程ID
             var threadID = Thread.CurrentThread.ManagedThreadId;
             //获取请求执行时间
             var milliseconds = watch.ElapsedMilliseconds;
             reader.Close();
             stream.Close();
             request.Abort();
             response.Close();
             OnCompleted?.Invoke(this, new OnCompletedEventArgs(uri, threadID, milliseconds, pageSource));
         }
         catch (Exception ex)
         {
             OnError?.Invoke(this, ex);
         }
         return pageSource;
     }));
 }
 /// <summary>
 /// Gets an HTML document from an Internet resource and saves it to the specified file. - Proxy aware
 /// </summary>
 /// <param name="url">The requested URL, such as "http://Myserver/Mypath/Myfile.asp".</param>
 /// <param name="path">The location of the file where you want to save the document.</param>
 /// <param name="proxy"></param>
 /// <param name="credentials"></param>
 public void Get(string url, string path, WebProxy proxy, NetworkCredential credentials)
 {
     Get(url, path, proxy, credentials, "GET");
 }
Beispiel #37
0
 static bool Prefix(ref WebProxy value)
 {
     Overrides.RaiseProxyChangeEvent(value);
     return(true);
 }
Beispiel #38
0
 public V2RayVersion GetLatestV2RayVersion(WebProxy proxy = null) => GetLatestV2RayVersion(GetLatestReleaseInfo(proxy));
Beispiel #39
0
 public static void BypassList_DoesntContainUrl_NotBypassed()
 {
     var p = new WebProxy("http://microsoft.com");
     Assert.Equal(new Uri("http://microsoft.com"), p.GetProxy(new Uri("http://bing.com")));
 }
        /// <summary>
        /// http 请求
        /// </summary>
        /// <param name="hostUrl"></param>
        /// <param name="action"></param>
        /// <param name="requestParams"></param>
        /// <param name="requestType"></param>
        /// <returns></returns>
        public static string QueryRequest(string url, string requestParams = "", RequestEnum requestType = RequestEnum.GET, CookieContainer cookieContainer = null, string referer = "", string contentType = "", string accept = "")
        {
To:

            HttpWebRequest httpRequest;

            WebProxy proxy = new WebProxy();

            try
            {
                if (requestType == RequestEnum.POST)
                {
                    httpRequest = (HttpWebRequest)WebRequest.Create(url);
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(requestParams))
                    {
                        httpRequest = (HttpWebRequest)WebRequest.Create(url);
                    }
                    else
                    {
                        httpRequest = (HttpWebRequest)WebRequest.Create(url + "?" + requestParams.Trim());
                    }
                }


                httpRequest.Method      = requestType.ToString();
                httpRequest.Timeout     = 30 * 1000;
                httpRequest.ContentType = string.IsNullOrWhiteSpace(contentType) ? defaultContentType : contentType;
                httpRequest.Accept      = string.IsNullOrWhiteSpace(accept) ? defaultAccept : accept;
                httpRequest.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
                httpRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
                httpRequest.UserAgent       = userAgent;
                httpRequest.CookieContainer = cookieContainer;

                if (isEnanbleProxy && !url.Contains("192.168."))
                {
                    proxy = NextProxy();

                    httpRequest.Proxy = proxy;
                }
                if (!string.IsNullOrWhiteSpace(referer))
                {
                    httpRequest.Referer = referer;
                }

                if (requestType == RequestEnum.POST)
                {
                    Encoding encoding    = Encoding.GetEncoding("utf-8");
                    byte[]   bytesToPost = encoding.GetBytes(requestParams);

                    httpRequest.ContentLength = bytesToPost.Length;
                    Stream requestStream = httpRequest.GetRequestStream();
                    requestStream.Write(bytesToPost, 0, bytesToPost.Length);
                    requestStream.Close();
                }

                HttpWebResponse response = (HttpWebResponse)httpRequest.GetResponse();

                StreamReader sr    = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"));
                string       reStr = sr.ReadToEnd();
                sr.Close();
                response.Close();
                return(reStr);
            }
            catch (WebException ex)
            {
                if (!url.Contains("192.168") && isEnanbleProxy)
                {
                    proxyData.ExpirationTime = DateTime.Now.AddSeconds(-30);

                    proxyDataList.Add(proxy.Address.Host);
                }

                return(string.Empty);

                goto To;

                //return QueryRequest(url, requestParams, requestType, cookieContainer, referer, contentType);
            }
            catch
            {
                return(string.Empty);
            }
        }
Beispiel #41
0
        public BetfairClient(Exchange exchange, string appKey, Action preNetworkRequest = null, WebProxy proxy = null)
        {
            if (string.IsNullOrWhiteSpace(appKey))
            {
                throw new ArgumentException("appKey");
            }

            this.exchange          = exchange;
            this.appKey            = appKey;
            this.preNetworkRequest = preNetworkRequest;
            this.proxy             = proxy;
        }
Beispiel #42
0
 public HttpWebHelper(bool cred, WebProxy wp, string certFilepath) : this(cred, wp)
 {
     this.certFilepath = certFilepath;
 }
Beispiel #43
0
        public static void BypassList_ContainsUrl_IsBypassed()
        {
            var p = new WebProxy("http://microsoft.com", false, new[] { "hello", "bing.*", "world" });

            Assert.Equal(new Uri("http://bing.com"), p.GetProxy(new Uri("http://bing.com")));
        }
Beispiel #44
0
 public HttpWebHelper(bool cred, WebProxy wp) : this()
 {
     this.certificatedMode = cred;
     this.webProxySrv      = wp;
 }
Beispiel #45
0
        public static void Address_Roundtrip()
        {
            var p = new WebProxy();
            Assert.Null(p.Address);

            p.Address = new Uri("http://hello");
            Assert.Equal(new Uri("http://hello"), p.Address);

            p.Address = null;
            Assert.Null(p.Address);
        }
Beispiel #46
0
 public HttpWebHelper(WebProxy wp) : this()
 {
     this.webProxySrv = wp;
 }
Beispiel #47
0
        /// <summary>
        /// 查询英文船名、航次、箱号、箱型、进港时间(运抵时间)、提单号
        /// </summary>
        /// <param name="提单号"></param>
        /// <returns></returns>
        public IList<集装箱数据> 查询集装箱数据(string 提单号, string 英文船名, string 航次)
        {
            List<集装箱数据> jzx = new List<集装箱数据>();

            WebProxy webProxy = new WebProxy();
            webProxy.Encoding = Encoding.UTF8;

            string htmlInfo = webProxy.GetToString(m_运抵报告url);

            HtmlAgilityPack.HtmlDocument _html = new HtmlAgilityPack.HtmlDocument();
            _html.LoadHtml(htmlInfo);

            HtmlAgilityPack.HtmlNode node_viewState = _html.DocumentNode.SelectSingleNode("/html[1]/body[1]/center[1]/input[1]/@value[1]");
            string viewState = node_viewState.Attributes["value"].Value;
            string postData = m_PostData运抵报告_first.Replace("#VIEWSTATE#", System.Web.HttpUtility.UrlEncode(viewState));

            HtmlAgilityPack.HtmlNode node_viewStateEncrypted = _html.DocumentNode.SelectSingleNode("/html[1]/body[1]/center[1]/input[2]/@value[1]");
            string viewStateEncrypted = node_viewStateEncrypted.Attributes["value"].Value;
            postData = postData.Replace("#VIEWSTATEENCRYPTED#", System.Web.HttpUtility.UrlEncode(viewStateEncrypted));

            HtmlAgilityPack.HtmlNode node_eventValidation = _html.DocumentNode.SelectSingleNode("/html[1]/body[1]/center[1]/input[3]/@value[1]");
            string eventValidation = node_eventValidation.Attributes["value"].Value;
            postData = postData.Replace("#EVENTVALIDATION#", System.Web.HttpUtility.UrlEncode(eventValidation));

            postData = postData.Replace("#提单号#", 提单号);
            postData = postData.Replace("#当前页数#", "1");

            htmlInfo = webProxy.PostToString(m_运抵报告url, postData);
            foreach (集装箱数据 item in nbedi.PageAnalyze.Parse查询集装箱数据(htmlInfo))
            {
                if (item.提单号 == 提单号 && item.船舶英文名称 == 英文船名 && item.航次 == 航次)
                {
                    jzx.Add(item);
                }
            }

            int pageCount = GetPageCount运抵报告(htmlInfo);

            if (pageCount > 1)
            {
                postData = m_PostData运抵报告_next.Replace("#VIEWSTATE#", System.Web.HttpUtility.UrlEncode(viewState));
                postData = postData.Replace("#VIEWSTATEENCRYPTED#", System.Web.HttpUtility.UrlEncode(viewStateEncrypted));
                postData = postData.Replace("#EVENTVALIDATION#", System.Web.HttpUtility.UrlEncode(eventValidation));
                postData = postData.Replace("#提单号#", 提单号);
            }

            for (int i = 2; i <= pageCount; i++)
            {
                System.Threading.Thread.Sleep(1000);

                postData = postData.Replace("#当前页数#", i.ToString());

                htmlInfo = webProxy.PostToString(m_运抵报告url, postData);
                foreach (集装箱数据 item in nbedi.PageAnalyze.Parse查询集装箱数据(htmlInfo))
                {
                    if (item.提单号 == 提单号 && item.船舶英文名称 == 英文船名 && item.航次 == 航次)
                    {
                        jzx.Add(item);
                    }
                }
            }

            foreach (集装箱数据 x in jzx)
            {
                x.堆场区 = 查询进场码头(x.船舶英文名称, x.航次, x.提单号);
            }

            return jzx;
        }
Beispiel #48
0
 /// <summary>
 /// 清除Web代理状态
 /// </summary>
 public static void RemoveHttpProxy()
 {
     _webproxy = null;
 }
Beispiel #49
0
 internal virtual void PrepareSession()
 {
     if (this.WebSession == null)
     {
         this.WebSession = new WebRequestSession();
     }
     if (this.SessionVariable != null)
     {
         base.SessionState.PSVariable.Set(this.SessionVariable, this.WebSession);
     }
     if (this.Credential != null)
     {
         NetworkCredential networkCredential = this.Credential.GetNetworkCredential();
         this.WebSession.Credentials = networkCredential;
         this.WebSession.UseDefaultCredentials = false;
     }
     else if (this.UseDefaultCredentials != 0)
     {
         this.WebSession.UseDefaultCredentials = true;
     }
     if (this.CertificateThumbprint != null)
     {
         X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
         store.Open(OpenFlags.OpenExistingOnly);
         X509Certificate2Collection certificates2 = store.Certificates.Find(X509FindType.FindByThumbprint, this.CertificateThumbprint, false);
         if (certificates2.Count == 0)
         {
             CryptographicException exception = new CryptographicException(WebCmdletStrings.ThumbprintNotFound);
             throw exception;
         }
         X509Certificate2Enumerator enumerator = certificates2.GetEnumerator();
         while (enumerator.MoveNext())
         {
             X509Certificate current = enumerator.Current;
             this.WebSession.AddCertificate(current);
         }
     }
     if (this.Certificate != null)
     {
         this.WebSession.AddCertificate(this.Certificate);
     }
     if (this.UserAgent != null)
     {
         this.WebSession.UserAgent = this.UserAgent;
     }
     if (null != this.Proxy)
     {
         WebProxy proxy = new WebProxy(this.Proxy) {
             BypassProxyOnLocal = false
         };
         if (this.ProxyCredential != null)
         {
             proxy.Credentials = this.ProxyCredential.GetNetworkCredential();
             proxy.UseDefaultCredentials = false;
         }
         else if (this.ProxyUseDefaultCredentials != 0)
         {
             proxy.UseDefaultCredentials = true;
         }
         this.WebSession.Proxy = proxy;
     }
     if (-1 < this.MaximumRedirection)
     {
         this.WebSession.MaximumRedirection = this.MaximumRedirection;
     }
     if (this.Headers != null)
     {
         foreach (string str in this.Headers.Keys)
         {
             this.WebSession.Headers[str] = (string) this.Headers[str];
         }
     }
 }
Beispiel #50
0
 public Downloader(string downloadLink, string saveDirectory, WebProxy proxy)
 {
     DownloadLink  = downloadLink;
     SaveDirectory = new DirectoryInfo(saveDirectory.Trim()).FullName;
     Proxy         = proxy;
 }
Beispiel #51
0
    private object[] getContentDMItem(string pointer, string resourceType, string collection)
    {
        object[] array = new object[10];

        string format = "xml"; //either "xml" or "json".
        string url = commonfunctions.contentDMServer + "dmwebservices/index.php?q=dmGetItemInfo" + collection + "/" + pointer + "/" + format;
        //  Response.Write(url);

        WebRequest request = WebRequest.Create(url);

        if (commonfunctions.Environment == "PROD" || commonfunctions.Environment == "DEV")
        {
            WebProxy wp = new WebProxy("http://access.lb.ssa.gov:80/", true);
            request.Proxy = wp;
        }
        WebResponse response = request.GetResponse();
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(response.GetResponseStream());

        XmlNodeList xmlDocuments = xmlDoc.SelectNodes("/xml");

        // Response.Write(xmlDocuments.Count);
        foreach (XmlNode node in xmlDocuments)
        {

            // string id = node["pointer"].InnerText;
            //title = node["title"].InnerText;
            //descri = node["descri"].InnerText;
            //creato = node["creato"].InnerText;
            //publis = node["publis"].InnerText;
            //date = node["date"].InnerText;
            // Response.Write(title);

            array[0] = pointer;
            array[1] = node["title"].InnerText;
            array[2] = node["descri"].InnerText;
            array[3] = "https://cdm16760.contentdm.oclc.org/cdm/compoundobject/collection" + collection + "/id/" + pointer; // "/templates/ssa_reportsdetails.aspx?collection=" + collection + "&pointer=" + pointer;
            array[4] = "Y";
            array[5] = ""; // rdr["ShowLogin"].ToString();
            array[6] = ""; //rdr["SharedUsername"].ToString();
            array[7] = ""; // rdr["SharedPassword"].ToString();
            array[8] = resourceType;
            array[9] = "/" + collection;

        }

        return array;
    }
        private void BotProcess()
        {
            if (CGlobalVar.g_strProxyID != "")
            {
                var proxy = new WebProxy
                {
                    Address               = new Uri($"http://{CGlobalVar.g_strProxyIP}:{CGlobalVar.g_nProxyPort}"),
                    BypassProxyOnLocal    = false,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(
                        userName: CGlobalVar.g_strProxyID,
                        password: CGlobalVar.g_strProxyPass)
                };
                HttpClientHandler clientHandler = new HttpClientHandler()
                {
                    CookieContainer        = _cookiejar,
                    Proxy                  = proxy,
                    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
                };
                botclient = new HttpClient(clientHandler);
            }
            else
            {
                HttpClientHandler clientHandler = new HttpClientHandler()
                {
                    CookieContainer        = _cookiejar,
                    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
                };
                botclient = new HttpClient(clientHandler);
            }

            switch (bottask.store)
            {
            case "A+S":
                if (!TaskManagement.GA_token.Contains("_ga"))
                {
                    Dispatcher.Invoke(new Action(() => CustomMessageBox.Show("Please input the GA Token")));
                    return;
                }
                as_thread = new Thread(AS_Thread);
                as_thread.Start();
                break;

            case "zozo":
                zozo_thread = new Thread(Zozo_Thread);
                zozo_thread.Start();
                break;

            case "MORTAR":
                mortar_thread = new Thread(Mortar_Thread);
                mortar_thread.Start();
                break;

            case "mct":
                mct_thread = new Thread(MCT_Thread);
                mct_thread.Start();
                break;

            case "FTC":
                ftc_thread = new Thread(FTC_Thread);
                ftc_thread.Start();
                break;

            case "arktz":
                ark_thread = new Thread(ARK_Thread);
                ark_thread.Start();
                break;

            case "ZINGARO":
                zingaro_thread = new Thread(ZINGARO_Thread);
                zingaro_thread.Start();
                break;
            }
        }
Beispiel #53
0
        protected override async Task <Response> ImplDownloadAsync(Request request)
        {
            var response = new Response
            {
                Request = request
            };

            for (int i = 0; i < RetryTime; ++i)
            {
                HttpResponseMessage httpResponseMessage = null;
                WebProxy            proxy = null;
                try
                {
                    var httpRequestMessage = GenerateHttpRequestMessage(request);

                    if (UseProxy)
                    {
                        if (HttpProxyPool == null)
                        {
                            response.Exception = "未正确配置代理池";
                            response.Success   = false;
                            Logger?.LogError(
                                $"任务 {request.OwnerId} 下载 {request.Url} 失败 [{i}]: {response.Exception}");
                            return(response);
                        }
                        else
                        {
                            proxy = HttpProxyPool.GetProxy();
                            if (proxy == null)
                            {
                                response.Exception = "没有可用的代理";
                                response.Success   = false;
                                Logger?.LogError(
                                    $"任务 {request.OwnerId} 下载 {request.Url} 失败 [{i}]: {response.Exception}");
                                return(response);
                            }
                        }
                    }

                    var httpClientEntry = GetHttpClientEntry(proxy == null ? "DEFAULT" : $"{proxy.Address}", proxy);


                    httpResponseMessage = Framework.NetworkCenter == null
                                                ? await httpClientEntry.HttpClient.SendAsync(httpRequestMessage)
                                                : await Framework.NetworkCenter.Execute(async() =>
                                                                                        await httpClientEntry.HttpClient.SendAsync(httpRequestMessage));

                    httpResponseMessage.EnsureSuccessStatusCode();
                    response.TargetUrl = httpResponseMessage.RequestMessage.RequestUri.AbsoluteUri;
                    var bytes = httpResponseMessage.Content.ReadAsByteArrayAsync().Result;
                    if (!ExcludeMediaTypes.Any(t =>
                                               httpResponseMessage.Content.Headers.ContentType.MediaType.Contains(t)))
                    {
                        if (!DownloadFile)
                        {
                            StorageFile(request, bytes);
                        }
                    }
                    else
                    {
                        var content = ReadContent(request, bytes,
                                                  httpResponseMessage.Content.Headers.ContentType.CharSet);

                        if (DecodeHtml)
                        {
#if NETFRAMEWORK
                            content = System.Web.HttpUtility.UrlDecode(
                                System.Web.HttpUtility.HtmlDecode(content),
                                string.IsNullOrEmpty(request.Encoding)
                                    ? Encoding.UTF8
                                    : Encoding.GetEncoding(request.Encoding));
#else
                            content = WebUtility.UrlDecode(WebUtility.HtmlDecode(content));
#endif
                        }

                        response.RawText = content;
                    }

                    if (!string.IsNullOrWhiteSpace(request.ChangeIpPattern) &&
                        Regex.IsMatch(response.RawText, request.ChangeIpPattern))
                    {
                        if (UseProxy)
                        {
                            response.TargetUrl = null;
                            response.RawText   = null;
                            response.Success   = false;
                            // 把代理设置为空,影响 final 代码块里不作归还操作,等于删除此代理
                            proxy = null;
                        }
                        else
                        {
                            // 不支持切换 IP
                            if (Framework.NetworkCenter == null ||
                                !Framework.NetworkCenter.SupportAdsl)
                            {
                                response.Success   = false;
                                response.Exception = "IP Banded";
                                Logger?.LogError(
                                    $"任务 {request.OwnerId} 下载 {request.Url} 失败 [{i}]: {response.Exception}");
                                return(response);
                            }
                            else
                            {
                                Framework.NetworkCenter.Redial();
                            }
                        }
                    }
                    else
                    {
                        response.Success = true;
                        Logger?.LogInformation(
                            $"任务 {request.OwnerId} 下载 {request.Url} 成功");
                        return(response);
                    }
                }
                catch (Exception e)
                {
                    response.Exception = e.Message;
                    response.Success   = false;
                    Logger?.LogError($"任务 {request.OwnerId} 下载 {request.Url} 失败 [{i}]: {e}");
                }
                finally
                {
                    if (HttpProxyPool != null && proxy != null)
                    {
                        HttpProxyPool.ReturnProxy(proxy,
                                                  httpResponseMessage?.StatusCode ?? HttpStatusCode.ServiceUnavailable);
                    }

                    try
                    {
                        httpResponseMessage?.Dispose();
                    }
                    catch (Exception e)
                    {
                        Logger?.LogWarning($"任务 {request.OwnerId} 释放 {request.Url} 失败 [{i}]: {e}");
                    }
                }

                // 下载失败需要等待一秒,防止频率过高。
                // TODO: 改成可配置
                Thread.Sleep(1000);
            }

            return(response);
        }
Beispiel #54
0
        public static string SendDataByPost(string Url, string postDataStr, string refer, ref CookieContainer cookie, WebProxy proxy)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);

            if (cookie.Count == 0)
            {
                request.CookieContainer = new CookieContainer();
                cookie = request.CookieContainer;
            }
            else
            {
                request.CookieContainer = cookie;
            }

            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            //request.Headers.Add("Accept:", "*/*");
            //request.Headers.Add("Accept - Encoding", "gzip, deflate");
            //request.Headers.Add("Accept - Language", "zh - CN,zh; q = 0.8");
            //request.Headers.Add("X - Requested - With", "XMLHttpRequest");
            //request.Headers.Add("Origin", "http://weibo.com");
            request.Accept        = "*/*";
            request.Referer       = refer;
            request.UserAgent     = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36 QIHU 360SE";
            request.UserAgent     = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko";
            request.ContentLength = postDataStr.Length;
            request.Proxy         = proxy;
            Stream       myRequestStream = request.GetRequestStream();
            StreamWriter myStreamWriter  = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));

            myStreamWriter.Write(postDataStr);
            myStreamWriter.Close();

            HttpWebResponse response         = (HttpWebResponse)request.GetResponse();
            Stream          myResponseStream = response.GetResponseStream();
            StreamReader    myStreamReader   = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            string          retString        = myStreamReader.ReadToEnd();

            myStreamReader.Close();
            myResponseStream.Close();
            response.Close();
            return(retString);
        }
Beispiel #55
0
 public Proxy(string url, int port, WebProxy proxy = null)
 {
     this.URL   = url;
     this.Port  = port;
     this.proxy = proxy;
 }
Beispiel #56
0
        void downloadPic(String fileName, String ext)
        {
            try
            {
                string sDirPath;
                sDirPath = Application.StartupPath + "\\imgFile";
                DirectoryInfo di = new DirectoryInfo(sDirPath);
                if (di.Exists == false)
                {
                    di.Create();
                }

                string      path    = ".\\imgFile\\" + fileName + ext;
                MyWebClient WClient = new MyWebClient(10);

                if (proxyCheck.Checked)
                {
                    WebProxy proxy = new WebProxy(proxyText.Text, Convert.ToInt32(proxyPortText.Text));
                    proxy.UseDefaultCredentials = false;
                    proxy.BypassProxyOnLocal    = false;

                    WClient.Proxy = proxy;
                }

                WClient.Headers.Add("Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
                WClient.Headers.Add("User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2300.0 Safari/537.36");
                WClient.DownloadFile(fileSrcText.Text, path);

                if (!checkFile(path))
                {
                    if (retry)
                    {
                        retry = false;
                        proxyCheck.Checked = !proxyCheck.Checked;
                        downloadPic(fileName, ext);
                        retry = true;
                        proxyCheck.Checked = !proxyCheck.Checked;
                    }
                }

                WClient.Dispose();
                statusLabel.Text = "";
            }
            catch (Exception e)
            {
                statusLabel.Text = e.Message;

                if (p1PageText.Text != "")
                {
                    try
                    {
                        click = Convert.ToInt32(p1PageText.Text);
                    }
                    catch
                    {
                    }
                }
                click--;
                nameText.Text   = click.ToString();
                p1PageText.Text = click.ToString();
            }
        }
Beispiel #57
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string response = string.Empty;
        bool debug = false;

        try
        {
            // load global settings
            debug = Convert.ToBoolean(ConfigurationManager.AppSettings["spGengo_debug"]);
            string apiUrl = ConfigurationManager.AppSettings["spGengo_apiUrl"];
            string responseFormat = ConfigurationManager.AppSettings["spGengo_responseFormat"];
            bool useProxy = Convert.ToBoolean(ConfigurationManager.AppSettings["spGengo_useProxy"]);
            string proxyHost = ConfigurationManager.AppSettings["spGengo_proxyHost"];
            int proxyPort = int.Parse(ConfigurationManager.AppSettings["spGengo_proxyPort"]);
            string proxyUsername = ConfigurationManager.AppSettings["spGengo_proxyUsername"];
            string proxyPassword = ConfigurationManager.AppSettings["spGengo_proxyPassword"];

            // retrieve params from request
            string publicKey = Request.Params["publicKey"];
            string privateKey = Request.Params["privateKey"];
            string type = Request.Params["type"];
            string slug = Request.Params["slug"];
            string body_src = Request.Params["body_src"];
            string lc_src = Request.Params["lc_src"];
            string lc_tgt = Request.Params["lc_tgt"];
            string tier = Request.Params["tier"];
            string auto_approve = Request.Params["auto_approve"];
            string custom_data = Request.Params["custom_data"];
            string comment = Request.Params["comment"];

            // initialize api client
            WebProxy proxy = null;
            if (useProxy)
            {
                proxy = new WebProxy(proxyHost, proxyPort);
                proxy.Credentials = new NetworkCredential(proxyUsername, proxyPassword);
            }
            myGengoClient.myGengoClient.initialize(apiUrl, publicKey, privateKey, responseFormat, proxy);

            // invoke api
            response = myGengoClient.myGengoClient.Translate_JobsRaw(type,
                slug,
                body_src,
                lc_src,
                lc_tgt,
                tier,
                auto_approve,
                custom_data,
                comment);

            // return response
            Response.Write(response);
        }
        catch (Exception ex)
        {
            // return server error
            string debugInfo = string.Empty;
            if (debug)
            {
                debugInfo = "Message: " + ex.Message + "<br />" + "Type: " + ex.GetType().Name + "<br />" + "Source: " + ex.Source;
            }
            response = "{\"opstat\" : \"serverError\", \"response\" : \"" + debugInfo + "\"}";

            // unescape response
            response = response.Replace("\\", "");
            response = response.Replace("'", "");

            // return
            Response.Write(response);

        }
    }
    static void ReadParameters(string[] args)
    {
        prot = new DiscoveryClientProtocol();
        NetworkCredential cred      = new NetworkCredential();
        NetworkCredential proxyCred = new NetworkCredential();
        WebProxy          proxy     = new WebProxy();

        url = null;

        foreach (string arg in args)
        {
            if (arg.StartsWith("/") || arg.StartsWith("-"))
            {
                string parg  = arg.Substring(1);
                int    i     = parg.IndexOf(":");
                string param = null;
                if (i != -1)
                {
                    param = parg.Substring(i + 1);
                    parg  = parg.Substring(0, i);
                }

                switch (parg)
                {
                case "nologo":
                    logo = false;
                    break;

                case "nosave":
                    save = false;
                    break;

                case "out":
                case "o":
                    directory = param;
                    break;

                case "username":
                case "u":
                    cred.UserName = param;
                    break;

                case "password":
                case "p":
                    cred.Password = param;
                    break;

                case "domain":
                case "d":
                    cred.Domain = param;
                    break;

                case "proxy":
                    proxy.Address = new Uri(param);
                    break;

                case "proxyusername":
                    proxyCred.UserName = param;
                    break;

                case "proxypassword":
                    proxyCred.Password = param;
                    break;

                case "proxydomain":
                    proxyCred.Domain = param;
                    break;
                }

                if (cred.UserName != null)
                {
                    prot.Credentials = cred;
                }

                if (proxyCred.UserName != null)
                {
                    proxy.Credentials = proxyCred;
                }

                if (proxy.Address != null)
                {
                    prot.Proxy = proxy;
                }
            }
            else
            {
                url = arg;
            }
        }
    }
Beispiel #59
0
    /// <summary>
    /// Creates list of offices and shows it.
    /// </summary>
    private void FillOfficesList()
    {
        try
        {
            Office[] offices = Office.GetOffices();
            if (offices == null)
                return;

            // Create object for work with proxy.
            WebProxy proxy = null;
            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["ProxyURL"]))
            {
                proxy = new WebProxy(ConfigurationManager.AppSettings["ProxyURL"]);
                string proxyDomain = ConfigurationManager.AppSettings["ProxyUserDomain"];
                string proxyUser = ConfigurationManager.AppSettings["ProxyUserLogin"];
                string proxyPassword = ConfigurationManager.AppSettings["ProxyUserPassword"];
                if (!string.IsNullOrEmpty(proxyUser))
                {
                    NetworkCredential netCred = new NetworkCredential();
                    netCred.UserName = proxyUser;
                    if (!string.IsNullOrEmpty(proxyDomain))
                        netCred.Domain = proxyDomain;
                    if (!string.IsNullOrEmpty(proxyPassword))
                        netCred.Password = proxyPassword;
                    proxy.Credentials = netCred;
                }
            }

            List<OfficeDescription> coll = new List<OfficeDescription>();
            foreach (Office office in Office.GetOffices())
            {
                //if (!string.IsNullOrEmpty(office.StatusesServiceURL))
                {
                    try
                    {
                        OfficeDescription officeDescr = new OfficeDescription();

                        if (!string.IsNullOrEmpty(office.StatusesServiceURL))
                        {
                            UsersStatusesService service = new UsersStatusesService(office.StatusesServiceURL);
                            if (proxy != null)
                            { service.Proxy = proxy; }
                            service.Timeout = 180000;

                            officeDescr.OfficeName = service.GetOfficeName();
                        }
                        if (string.IsNullOrEmpty(officeDescr.OfficeName))
                            officeDescr.OfficeName = office.OfficeName;
                        officeDescr.OfficeID = office.ID.Value;
                        officeDescr.ServiceURL = office.StatusesServiceURL;
                        officeDescr.ServiceUserName = office.StatusesServiceUserName;
                        officeDescr.ServicePassword = office.StatusesServicePassword;
                        officeDescr.SelectedDate = Calendar.SelectedDate;
                        coll.Add(officeDescr);
                    }
                    catch (Exception ex)
                    { Logger.Log.Error(ex.Message, ex); }
                }
            }

            repOffices.DataSource = coll;
            repOffices.DataBind();
        }
         catch (Exception ex)
        { Logger.Log.Error(ex.Message, ex); }
    }
Beispiel #60
0
        private void continueButton_Click(object sender, EventArgs e)
        {
            if (_sender == generalTabPage)
            {
                if (!ValidationManager.Validate(generalPanel))
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Missing information found.",
                                    "All fields need to have a value.", PopupButtons.Ok);
                    return;
                }

                if (!_generalTabPassed)
                {
                    _projectConfiguration =
                        ProjectConfiguration.Load().ToList();
                    if (_projectConfiguration != null)
                    {
                        if (_projectConfiguration.Any(item => item.Name == nameTextBox.Text))
                        {
                            Popup.ShowPopup(this, SystemIcons.Error, "The project is already existing.",
                                            $"The project \"{nameTextBox.Text}\" is already existing.", PopupButtons.Ok);
                            return;
                        }
                    }
                    else
                    {
                        _projectConfiguration = new List <ProjectConfiguration>();
                    }
                }

                if (!Uri.IsWellFormedUriString(updateUrlTextBox.Text, UriKind.Absolute))
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Invalid adress.", "The given Update-URL is invalid.",
                                    PopupButtons.Ok);
                    return;
                }

                if (!Path.IsPathRooted(localPathTextBox.Text))
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Invalid path.",
                                    "The given local path for the project is invalid.", PopupButtons.Ok);
                    return;
                }

                try
                {
                    Path.GetFullPath(localPathTextBox.Text);
                }
                catch
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Invalid path.",
                                    "The given local path for the project is invalid.", PopupButtons.Ok);
                    return;
                }

                _sender            = ftpTabPage;
                backButton.Enabled = true;
                informationCategoriesTabControl.SelectedTab = ftpTabPage;
            }
            else if (_sender == ftpTabPage)
            {
                if (!ValidationManager.Validate(ftpPanel) || string.IsNullOrEmpty(ftpPasswordTextBox.Text))
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Missing information found.",
                                    "All fields need to have a value.", PopupButtons.Ok);
                    return;
                }

                _ftp.Host      = ftpHostTextBox.Text;
                _ftp.Port      = int.Parse(ftpPortTextBox.Text);
                _ftp.Username  = ftpUserTextBox.Text;
                _ftp.Directory = ftpDirectoryTextBox.Text;

                var ftpPassword = new SecureString();
                foreach (var c in ftpPasswordTextBox.Text)
                {
                    ftpPassword.AppendChar(c);
                }
                _ftp.Password = ftpPassword; // Same instance that FtpManager will automatically dispose

                _ftp.UsePassiveMode = ftpModeComboBox.SelectedIndex == 0;
                _ftp.Protocol       = (FtpsSecurityProtocol)ftpProtocolComboBox.SelectedIndex;
                _ftp.NetworkVersion = (NetworkVersion)ipVersionComboBox.SelectedIndex;

                if (!backButton.Enabled) // If the back-button was disabled, enabled it again
                {
                    backButton.Enabled = true;
                }

                _sender = statisticsServerTabPage;
                informationCategoriesTabControl.SelectedTab = statisticsServerTabPage;
            }
            else if (_sender == statisticsServerTabPage)
            {
                if (useStatisticsServerRadioButton.Checked)
                {
                    if (SqlDatabaseName == null || string.IsNullOrWhiteSpace(sqlPasswordTextBox.Text))
                    {
                        Popup.ShowPopup(this, SystemIcons.Error, "Missing information found.",
                                        "All fields need to have a value.", PopupButtons.Ok);
                        return;
                    }
                }

                _sender = proxyTabPage;
                informationCategoriesTabControl.SelectedTab = proxyTabPage;
            }
            else if (_sender == proxyTabPage)
            {
                if (useProxyRadioButton.Checked)
                {
                    if (!ValidationManager.ValidateTabPage(proxyTabPage) && !string.IsNullOrEmpty(proxyUserTextBox.Text) &&
                        !string.IsNullOrEmpty(proxyPasswordTextBox.Text))
                    {
                        Popup.ShowPopup(this, SystemIcons.Error, "Missing information found.",
                                        "All fields need to have a value.", PopupButtons.Ok);
                        return;
                    }
                }

                try
                {
                    using (File.Create(localPathTextBox.Text))
                    {
                    }
                    _projectFileCreated = true;
                }
                catch (IOException ex)
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Failed to create project file.", ex, PopupButtons.Ok);
                    Close();
                }

                var usePassive = ftpModeComboBox.SelectedIndex == 0;

                WebProxy proxy         = null;
                string   proxyUsername = null;
                string   proxyPassword = null;
                if (!string.IsNullOrEmpty(proxyHostTextBox.Text))
                {
                    proxy = new WebProxy(proxyHostTextBox.Text);
                    if (!string.IsNullOrEmpty(proxyUserTextBox.Text) &&
                        !string.IsNullOrEmpty(proxyPasswordTextBox.Text))
                    {
                        proxyUsername = proxyUserTextBox.Text;
                        if (!saveCredentialsCheckBox.Checked)
                        {
                            proxyPassword = Convert.ToBase64String(AesManager.Encrypt(proxyPasswordTextBox.Text,
                                                                                      ftpPasswordTextBox.Text,
                                                                                      ftpUserTextBox.Text));
                        }
                        else
                        {
                            proxyPassword =
                                Convert.ToBase64String(AesManager.Encrypt(proxyPasswordTextBox.Text,
                                                                          Program.AesKeyPassword,
                                                                          Program.AesIvPassword));
                        }
                    }
                }

                string sqlPassword = null;
                if (useStatisticsServerRadioButton.Checked)
                {
                    if (!saveCredentialsCheckBox.Checked)
                    {
                        sqlPassword = Convert.ToBase64String(AesManager.Encrypt(sqlPasswordTextBox.Text,
                                                                                ftpPasswordTextBox.Text,
                                                                                ftpUserTextBox.Text));
                    }
                    else
                    {
                        sqlPassword =
                            Convert.ToBase64String(AesManager.Encrypt(sqlPasswordTextBox.Text, Program.AesKeyPassword,
                                                                      Program.AesIvPassword));
                    }
                }

                Settings.Default.ApplicationID += 1;
                Settings.Default.Save();
                Settings.Default.Reload();

                string ftpPassword;
                if (!saveCredentialsCheckBox.Checked)
                {
                    ftpPassword = Convert.ToBase64String(AesManager.Encrypt(ftpPasswordTextBox.Text,
                                                                            ftpPasswordTextBox.Text,
                                                                            ftpUserTextBox.Text));
                }
                else
                {
                    ftpPassword =
                        Convert.ToBase64String(AesManager.Encrypt(ftpPasswordTextBox.Text, Program.AesKeyPassword,
                                                                  Program.AesIvPassword));
                }

                // Create a new package...
                var project = new UpdateProject
                {
                    Path                        = localPathTextBox.Text,
                    Name                        = nameTextBox.Text,
                    Guid                        = Guid.NewGuid().ToString(),
                    ApplicationId               = Settings.Default.ApplicationID,
                    UpdateUrl                   = updateUrlTextBox.Text,
                    Packages                    = null,
                    SaveCredentials             = saveCredentialsCheckBox.Checked,
                    FtpHost                     = ftpHostTextBox.Text,
                    FtpPort                     = int.Parse(ftpPortTextBox.Text),
                    FtpUsername                 = ftpUserTextBox.Text,
                    FtpPassword                 = ftpPassword,
                    FtpDirectory                = ftpDirectoryTextBox.Text,
                    FtpProtocol                 = ftpProtocolComboBox.SelectedIndex,
                    FtpUsePassiveMode           = usePassive,
                    FtpTransferAssemblyFilePath = _ftpAssemblyPath,
                    FtpNetworkVersion           = (NetworkVersion)ipVersionComboBox.SelectedIndex,
                    Proxy                       = proxy,
                    ProxyUsername               = proxyUsername,
                    ProxyPassword               = proxyPassword,
                    UseStatistics               = useStatisticsServerRadioButton.Checked,
                    SqlDatabaseName             = SqlDatabaseName,
                    SqlWebUrl                   = SqlWebUrl,
                    SqlUsername                 = SqlUsername,
                    SqlPassword                 = sqlPassword,
                    PrivateKey                  = PrivateKey,
                    PublicKey                   = PublicKey,
                    Log = null
                };

                try
                {
                    UpdateProject.SaveProject(localPathTextBox.Text, project); // ... and save it
                }
                catch (IOException ex)
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Error while saving the project file.", ex, PopupButtons.Ok);
                    _mustClose = true;
                    Reset();
                }

                try
                {
                    var projectDirectoryPath = Path.Combine(Program.Path, "Projects", nameTextBox.Text);
                    Directory.CreateDirectory(projectDirectoryPath);
                }
                catch (Exception ex)
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Error while creating the project'S directory.", ex,
                                    PopupButtons.Ok);
                    _mustClose = true;
                    Reset();
                }

                try
                {
                    _projectConfiguration.Add(new ProjectConfiguration(nameTextBox.Text, localPathTextBox.Text));
                    File.WriteAllText(Program.ProjectsConfigFilePath, Serializer.Serialize(_projectConfiguration));
                    _projectConfigurationEdited = true;
                }
                catch (Exception ex)
                {
                    Popup.ShowPopup(this, SystemIcons.Error,
                                    "Error while editing the project confiuration file. Please choose another name for the project.",
                                    ex,
                                    PopupButtons.Ok);
                    _mustClose = true;
                    Reset();
                }

                if (useStatisticsServerRadioButton.Checked)
                {
                    var phpFilePath = Path.Combine(Program.Path, "Projects", nameTextBox.Text, "statistics.php");
                    try
                    {
                        File.WriteAllBytes(phpFilePath, Resources.statistics);

                        var phpFileContent = File.ReadAllText(phpFilePath);
                        phpFileContent = phpFileContent.Replace("_DBURL", SqlWebUrl);
                        phpFileContent = phpFileContent.Replace("_DBUSER", SqlUsername);
                        phpFileContent = phpFileContent.Replace("_DBNAME", SqlDatabaseName);
                        phpFileContent = phpFileContent.Replace("_DBPASS", sqlPasswordTextBox.Text);
                        File.WriteAllText(phpFilePath, phpFileContent);
                        _phpFileCreated = true;
                    }
                    catch (Exception ex)
                    {
                        Popup.ShowPopup(this, SystemIcons.Error, "Failed to initialize the project-files.", ex,
                                        PopupButtons.Ok);
                        _mustClose = true;
                        Reset();
                    }
                }

                _generalTabPassed = true;
                InitializeProject();
            }
        }