Пример #1
0
        public void CleanAfterStart()
        {
            if (OvpnFile != null)
            {
                OvpnFile.Close();
                OvpnFile = null;
            }

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

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

            if (PasswordAuthFile != null)
            {
                PasswordAuthFile.Close();
                PasswordAuthFile = null;
            }
        }
Пример #2
0
        public void Close()
        {
            CleanAfterStart();

            // Here because reneg keys require it, and we can't know when OpenVPN need it.
            if (PasswordAuthFile != null)
            {
                PasswordAuthFile.Close();
                PasswordAuthFile = null;
            }
        }
Пример #3
0
        public void SetAuthUserPass(string username, string password)
        {
            if (FilePasswordAuth != null)
            {
                FilePasswordAuth.Close();
                FilePasswordAuth = null;
            }

            FilePasswordAuth = new TemporaryFile("ppw");
            string fileNameAuthOvpn = FilePasswordAuth.Path.Replace("\\", "\\\\");
            string fileNameData     = username + "\n" + password + "\n";

            Platform.Instance.FileContentsWriteText(FilePasswordAuth.Path, fileNameData);
            // Platform.Instance.FileEnsurePermission(FilePasswordAuth.Path, "644"); // TOFIX, macOS with custom .ovpn throw a warning about file permissions

            AppendDirective("auth-user-pass", "\"" + fileNameAuthOvpn + "\"", "Auth");
        }
Пример #4
0
        public void Close()
        {
            if (FilePasswordAuth != null)
            {
                FilePasswordAuth.Close();
                FilePasswordAuth = null;
            }

            if (FileProxyAuth != null)
            {
                FileProxyAuth.Close();
                FileProxyAuth = null;
            }
        }
Пример #5
0
        public byte[] FetchUrlEx(string url, System.Collections.Specialized.NameValueCollection parameters, string title, int ntry, bool bypassProxy)
        {
            string lastException = "";
            for (int t = 0; t < ntry; t++)
            {
                try
                {
                    // Note: by default WebClient try to determine the proxy used by IE/Windows
                    WebClientEx wc = new WebClientEx();

                    if (bypassProxy)
                    {
                        // Don't use a proxy if connected to the VPN
                        wc.Proxy = null;
                    }
                    else
                    {
                        string proxyMode = Storage.Get("proxy.mode").ToLowerInvariant();
                        string proxyHost = Storage.Get("proxy.host");
                        int proxyPort = Storage.GetInt("proxy.port");
                        string proxyAuth = Storage.Get("proxy.auth").ToLowerInvariant();
                        string proxyLogin = Storage.Get("proxy.login");
                        string proxyPassword = Storage.Get("proxy.password");

                        if(proxyMode == "Tor")
                        {
                            proxyMode = "socks";
                            proxyAuth = "none";
                            proxyLogin = "";
                            proxyPassword = "";
                        }

                        if (proxyMode == "http")
                        {
                            System.Net.WebProxy proxy = new System.Net.WebProxy(proxyHost, proxyPort);
                            //string proxyUrl = "http://" + Storage.Get("proxy.host") + ":" + Storage.GetInt("proxy.port").ToString() + "/";
                            //System.Net.WebProxy proxy = new System.Net.WebProxy(proxyUrl, true);

                            if (proxyAuth != "none")
                            {
                                //wc.Credentials = new System.Net.NetworkCredential(Storage.Get("proxy.login"), Storage.Get("proxy.password"), Storage.Get("proxy.host"));
                                wc.Credentials = new System.Net.NetworkCredential(proxyLogin, proxyPassword, "");
                                proxy.Credentials = new System.Net.NetworkCredential(proxyLogin, proxyPassword, "");
                                wc.UseDefaultCredentials = false;
                            }

                            wc.Proxy = proxy;
                        }
                        else if (proxyMode == "socks")
                        {
                            // Socks Proxy supported with a curl shell
                            if (Software.CurlPath == "")
                            {
                                throw new Exception(Messages.CUrlRequiredForProxySocks);
                            }
                            else
                            {
                                string dataParameters = "";
                                if (parameters != null)
                                {
                                    foreach (string k in parameters.Keys)
                                    {
                                        if (dataParameters != "")
                                            dataParameters += "&";
                                        dataParameters += k + "=" + Uri.EscapeUriString(parameters[k]);
                                    }
                                }

                                TemporaryFile fileOutput = new TemporaryFile("bin");
                                string args = " \"" + url + "\" --socks4a " + proxyHost + ":" + proxyPort;
                                if (proxyAuth != "none")
                                {
                                    args += " -U " + proxyLogin + ":" + proxyPassword;
                                }
                                args += " -o \"" + fileOutput.Path + "\"";
                                args += " --progress-bar";
                                if (dataParameters != "")
                                    args += " --data \"" + dataParameters + "\"";
                                string str = Platform.Instance.Shell(Software.CurlPath, args);
                                byte[] bytes;
                                if (Platform.Instance.FileExists(fileOutput.Path))
                                {
                                    bytes = Platform.Instance.FileContentsReadBytes(fileOutput.Path);
                                    fileOutput.Close();
                                    return bytes;
                                }
                                else
                                {
                                    throw new Exception(str);
                                }
                            }
                        }
                        else if (proxyMode != "detect")
                        {
                            wc.Proxy = null;
                        }
                    }

                    if (parameters == null)
                        return wc.DownloadData(url);
                    else
                        return wc.UploadValues(url, "POST", parameters);
                }
                catch (Exception e)
                {
                    if (ntry == 1) // AirAuth have it's catch errors retry logic.
                        throw e;
                    else
                    {
                        lastException = e.Message;

                        if(Engine.Storage.GetBool("advanced.expert"))
                            Engine.Instance.Logs.Log(LogType.Warning, MessagesFormatter.Format(Messages.FetchTryFailed, title, (t + 1).ToString(), lastException));
                    }
                }
            }

            throw new Exception(lastException);
        }