예제 #1
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            try
            {
                ScriptProxyClientFactory factory = new ScriptProxyClientFactory();
                factory.Script = textBoxScript.Text;
                IWebProxyScript proxy = factory.GetProxyInstance();

                if (proxy != null)
                {
                    Uri u = new Uri(textBoxUrl.Text, UriKind.Absolute);

                    MessageBox.Show(this, String.Format(Properties.Resources.ConfigurePacScriptForm_TestReturned,
                                                        proxy.Run(u.AbsoluteUri, u.Host)));
                }
                else
                {
                    MessageBox.Show(this, Properties.Resources.ConfigurePacScriptForm_CannotUseProxyScript,
                                    Properties.Resources.MessageBox_ErrorString,
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                TargetInvocationException tex = ex as TargetInvocationException;

                MessageBox.Show(this, tex != null ? tex.InnerException.Message : ex.Message, Properties.Resources.MessageBox_ErrorString,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
 // Forward these to the site.
 internal string FindProxyForURL(string url, string host)
 {
     GlobalLog.Print("AutoWebProxyScriptWrapper::FindProxyForURL() Calling JScript for url:" + url.ToString() + " host:" + host.ToString());
     return(site.Run(url, host));
 }
예제 #3
0
        private ProxyClient CreateClient(Uri url, Logger logger)
        {
            string             token   = _proxyScript.Run(url.AbsoluteUri, url.Host);
            List <ProxyClient> clients = new List <ProxyClient>();

            if (token != null)
            {
                string[] proxies = token.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                logger.LogVerbose(String.Format(CANAPE.Net.Properties.Resources.ScriptProxyClient_ScriptReturned, token, url.AbsoluteUri));

                foreach (string proxy in proxies)
                {
                    string[] values = proxy.Trim().Split(new char[] { ' ' });

                    if (values.Length == 2)
                    {
                        string host = null;
                        int    port = 0;

                        string[] hostport = values[1].Split(':');
                        if (hostport.Length == 2)
                        {
                            host = hostport[0].Trim();
                            int.TryParse(hostport[1].Trim(), out port);
                        }

                        if (String.IsNullOrWhiteSpace(host) || (port <= 0) || (port > 65535))
                        {
                            throw new ArgumentException(String.Format(CANAPE.Net.Properties.Resources.ScriptProxyClient_InvalidServer, proxy));
                        }

                        if (values[0].Equals("PROXY", StringComparison.OrdinalIgnoreCase))
                        {
                            clients.Add(new HttpProxyClient(host, port, false));
                        }
                        else if (values[0].Equals("SOCKS", StringComparison.OrdinalIgnoreCase))
                        {
                            clients.Add(new SocksProxyClient(host, port, false, SocksProxyClient.SupportedVersion.Version4, false));
                        }
                        else
                        {
                            throw new ArgumentException(String.Format(CANAPE.Net.Properties.Resources.ScriptProxyClient_InvalidType, values[0]));
                        }
                    }
                    else
                    {
                        clients.Add(new IpProxyClient());
                    }
                }
            }

            if (clients.Count > 0)
            {
                return(new ChainProxyClient(clients.ToArray()));
            }
            else
            {
                return(new IpProxyClient());
            }
        }