Exemplo n.º 1
0
        public virtual bool RouteRemove(Json jRoute)
        {
            lock (m_routes)
            {
                bool known = false;
                for (int i = 0; i < m_routes.Count; i++)
                {
                    Json jRouteC = m_routes[i] as Json;
                    if ((jRouteC["address"].Value as string == jRoute["address"].Value as string) &&
                        (jRouteC["gateway"].Value as string == jRoute["gateway"].Value as string) &&
                        (jRouteC["type"].Value as string == "added"))
                    {
                        Engine.Instance.Logs.LogVerbose(LanguageManager.GetText("RouteDelAdded", new IpAddress(jRoute["address"].Value as string).ToCIDR(), new IpAddress(jRoute["gateway"].Value as string).ToCIDR()));
                        m_routes.RemoveAt(i);
                        known = true;
                        break;
                    }
                }

                if (known == false)
                {
                    Engine.Instance.Logs.LogVerbose(LanguageManager.GetText("RouteDelExist", new IpAddress(jRoute["address"].Value as string).ToCIDR(), new IpAddress(jRoute["gateway"].Value as string).ToCIDR()));
                    jRoute["type"].Value = "removed";
                    m_routes.Add(jRoute);
                }
            }

            Recovery.Save();

            return(true);
        }
Exemplo n.º 2
0
        public void Deactivation(bool onExit)
        {
            if (m_current != null)
            {
                if (onExit == false)
                {
                    Engine.Instance.WaitMessageSet(LanguageManager.GetText("NetworkLockDeactivation"), false);
                    Engine.Instance.Logs.Log(LogType.InfoImportant, LanguageManager.GetText("NetworkLockDeactivation"));
                }
                else
                {
                    Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("NetworkLockDeactivation"));
                }

                try
                {
                    m_current.Deactivation();
                }
                catch (Exception e)
                {
                    Engine.Instance.Logs.Log(e);
                }

                m_current = null;
            }

            Recovery.Save();
        }
Exemplo n.º 3
0
 public string Get(string name)
 {
     lock (Options)
     {
         if (Engine.Instance.StartCommandLine.Exists(name))
         {
             return(Engine.Instance.StartCommandLine.Get(name, ""));
         }
         else if (Exists(name))
         {
             Option option = Options[name];
             if (option.Value != "")
             {
                 return(option.Value);
             }
             else
             {
                 return(option.Default);
             }
         }
         else
         {
             Engine.Instance.Logs.Log(LogType.Error, LanguageManager.GetText("OptionsUnknown", name));
             return("");
         }
     }
 }
Exemplo n.º 4
0
        public static string SendCommand(string cmd)
        {
            string result = "";

            try
            {
                using (TcpClient s = new TcpClient())
                {
                    Connect(s);

                    Write(s, cmd + "\n");

                    result = Read(s);

                    return(result);
                }
            }
            catch (Exception e)
            {
                result = LanguageManager.GetText("TorControlException", e.Message);
            }

            Engine.Instance.Logs.Log(LogType.Verbose, "Tor Test: " + result);
            return(result);
        }
Exemplo n.º 5
0
        public static string Test(string host, int controlPort, string controlPassword)
        {
            string result = "";

            try
            {
                using (TcpClient s = new TcpClient())
                {
                    Connect(s, host, controlPort, controlPassword);

                    Write(s, "getinfo version\n");

                    result = Read(s);

                    if ((result.IndexOfInv("250 OK") != -1) && (result.IndexOfInv("version=") != -1))
                    {
                        result = result.Replace("250-", "").Trim();
                        result = result.Replace("250 OK", "");
                        result = result.Replace("version=", "");
                        result = LanguageManager.GetText("TorControlTest", result.Trim());
                    }
                }
            }
            catch (Exception e)
            {
                result = LanguageManager.GetText("TorControlException", e.Message);
            }

            Engine.Instance.Logs.Log(LogType.Verbose, "Tor Test: " + result);
            return(result);
        }
Exemplo n.º 6
0
        public static void Load()
        {
            lock (Lock)
            {
                string path = RecoveryPath();

                // Platform.Instance.OnRecovery();

                if (Platform.Instance.FileExists(path))
                {
                    try
                    {
                        Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("RecoveryDetected"));

                        XmlDocument doc = new XmlDocument();

                        doc.Load(path);

                        XmlElement root = doc.ChildNodes[0] as XmlElement;

                        Platform.Instance.OnRecoveryLoad(root);

                        Engine.Instance.NetworkLockManager.OnRecoveryLoad(root);
                    }
                    catch (Exception e)
                    {
                        Engine.Instance.Logs.Log(e);
                    }

                    Platform.Instance.FileDelete(path);
                }
            }
        }
Exemplo n.º 7
0
        public static void Log()
        {
            if (TunDriver != "")
            {
                Engine.Instance.Logs.Log(LogType.Verbose, "Tun Driver - " + TunDriver);
            }
            else
            {
                Engine.Instance.Logs.Log(LogType.Error, "Tun Driver - " + LanguageManager.GetText("OsDriverNotAvailable"));
            }

            if (Engine.Instance.GetOpenVpnTool().Available())
            {
                Engine.Instance.Logs.Log(LogType.Verbose, "OpenVPN - Version: " + Engine.Instance.GetOpenVpnTool().Version + " (" + Engine.Instance.GetOpenVpnTool().Path + ")");
            }
            else
            {
                Engine.Instance.Logs.Log(LogType.Error, "OpenVPN - " + LanguageManager.GetText("NotAvailable"));
            }

            if (GetTool("ssh").Available())
            {
                Engine.Instance.Logs.Log(LogType.Verbose, "SSH - Version: " + GetTool("ssh").Version + " (" + GetTool("ssh").Path + ")");
            }
            else
            {
                Engine.Instance.Logs.Log(LogType.Warning, "SSH - " + LanguageManager.GetText("NotAvailable"));
            }

            if (GetTool("ssl").Available())
            {
                Engine.Instance.Logs.Log(LogType.Verbose, "SSL - Version: " + GetTool("ssl").Version + " (" + GetTool("ssl").Path + ")");
            }
            else
            {
                Engine.Instance.Logs.Log(LogType.Warning, "SSL - " + LanguageManager.GetText("NotAvailable"));
            }

            if (GetTool("curl").Available())
            {
                Engine.Instance.Logs.Log(LogType.Verbose, "curl - Version: " + GetTool("curl").Version + " (" + GetTool("curl").Path + ")");
            }
            else
            {
                Engine.Instance.Logs.Log(LogType.Warning, "curl - " + LanguageManager.GetText("NotAvailable"));
            }

            /*
             *          string pathCacert = Engine.Instance.LocateResource("cacert.pem");
             *          if (pathCacert != "")
             * {
             *  Engine.Instance.Logs.Log(LogType.Verbose, "Certification Authorities: " + pathCacert);
             * }
             * else
             * {
             *  Engine.Instance.Logs.Log(LogType.Warning, "Certification Authorities - " + LanguageManager.GetText("NotAvailable"));
             *
             *          }
             */
        }
Exemplo n.º 8
0
        public void Log(LogType type, string message, Exception e)
        {
            // Avoid repetition
            if ((type != LogType.Fatal) && (Engine.Instance.Storage != null) && (Engine.Instance.Storage.GetBool("log.repeat") == false))
            {
                string logRepetitionNormalized = message;
                logRepetitionNormalized = System.Text.RegularExpressions.Regex.Replace(logRepetitionNormalized, "#\\d+", "#n");
                if (logRepetitionNormalized == m_logLast)
                {
                    m_logLastCount++;
                    return;
                }
                else
                {
                    int oldCount = m_logLastCount;
                    m_logLast      = logRepetitionNormalized;
                    m_logLastCount = 0;

                    if (oldCount != 0)
                    {
                        Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("LogsLineRepetitionSummary", oldCount.ToString()));
                    }
                }
            }

            LogEntry l = new LogEntry();

            l.Type      = type;
            l.Message   = message;
            l.Exception = e;

            if (l.Type > LogType.Realtime)
            {
                m_lastLogMessage = l.Message;
                m_logDotCount   += 1;
                m_logDotCount    = m_logDotCount % 10;
            }

            lock (Entries)
            {
                Entries.Add(l);
                if ((Engine.Instance != null) && (Engine.Instance.Storage != null) && (Entries.Count >= Engine.Instance.Storage.GetInt("log.limit")))
                {
                    Entries.RemoveAt(0);
                }
            }

            if (LogEvent != null)
            {
                LogEvent(l);
            }

            Engine.Instance.OnLog(l);

            Json j = l.GetJson();

            j["command"].Value = "log";
            Engine.Instance.UiManager.Broadcast(j);
        }
Exemplo n.º 9
0
        public virtual void EnsureDriverAndAdapterAvailable(string driver)
        {
            if (GetDriverVersion(driver) != "")
            {
                return;
            }

            throw new Exception(LanguageManager.GetText("OsDriverCannotInstall"));
        }
Exemplo n.º 10
0
        public void Activation()
        {
            try
            {
                if (m_current != null)
                {
                    throw new Exception(LanguageManager.GetText("NetworkLockUnexpectedAlreadyActive"));
                }

                NetworkLockPlugin nextCurrent = null;

                string requestedMode = Engine.Instance.Storage.GetLower("netlock.mode");
                if (requestedMode == "auto")
                {
                    requestedMode = Platform.Instance.OnNetworkLockRecommendedMode();
                }

                if (requestedMode != "none")
                {
                    foreach (NetworkLockPlugin plugin in Modes)
                    {
                        if (plugin.GetSupport())
                        {
                            if (requestedMode == plugin.GetCode())
                            {
                                nextCurrent = plugin;
                                break;
                            }
                        }
                    }
                }

                if (nextCurrent == null)
                {
                    Engine.Instance.Logs.Log(LogType.Fatal, LanguageManager.GetText("NetworkLockNoMode"));
                }
                else
                {
                    string message = LanguageManager.GetText("NetworkLockActivation") + " - " + nextCurrent.GetName();
                    Engine.Instance.WaitMessageSet(message, false);
                    Engine.Instance.Logs.Log(LogType.InfoImportant, message);

                    // This is not useless: resolve hostnames (available later as cache) before a possible lock of DNS server.
                    nextCurrent.GetIpsWhiteListOutgoing(true);

                    nextCurrent.Activation();

                    m_current = nextCurrent;
                }
            }
            catch (Exception e)
            {
                Engine.Instance.Logs.Log(LogType.Fatal, e);
            }

            Recovery.Save();
        }
Exemplo n.º 11
0
 public string GetNameForList()
 {
     if (Name == "")
     {
         return(LanguageManager.GetText("Unknown"));
     }
     else
     {
         return(Name);
     }
 }
Exemplo n.º 12
0
 public override string ToString()
 {
     if (Engine.Instance.IsConnected())
     {
         return(LanguageManager.GetText("PingerStatsPending", LanguageManager.FormatTime(LatestCheckDate)));
     }
     else
     {
         return(LanguageManager.GetText("PingerStatsNormal", Invalid.ToString(), LanguageManager.FormatTime(OlderCheckDate), LanguageManager.FormatTime(LatestCheckDate)));
     }
 }
Exemplo n.º 13
0
        public static void SendNEWNYM()
        {
            using (TcpClient s = new TcpClient())
            {
                Connect(s);

                Write(s, "SIGNAL NEWNYM\n");
                Flush(s);

                Engine.Instance.Logs.LogVerbose(LanguageManager.GetText("TorControlNEWNYM"));
            }
        }
Exemplo n.º 14
0
        public void Tests()
        {
            IpAddresses dns = DnsManager.ResolveDNS("dnstest.eddie.website", true);

            Add("Test DNS IPv4", (dns.CountIPv4 == 2) ? LanguageManager.GetText("Ok") : LanguageManager.GetText("Failed"));
            Add("Test DNS IPv6", (dns.CountIPv6 == 2) ? LanguageManager.GetText("Ok") : LanguageManager.GetText("Failed"));

            Add("Test Ping IPv4", TestPing(Constants.WebSiteIPv4));
            Add("Test Ping IPv6", TestPing(Constants.WebSiteIPv6));

            Add("Test HTTP IPv4", TestUrl("http://" + Constants.WebSiteIPv4 + "/test/"));
            Add("Test HTTP IPv6", TestUrl("http://[" + Constants.WebSiteIPv6 + "]/test/"));
            Add("Test HTTPS", TestUrl("https://" + Constants.Domain + "/test/"));
        }
Exemplo n.º 15
0
 public void Set(string name, string val)
 {
     lock (this)
     {
         if (Exists(name) == false)
         {
             Engine.Instance.Logs.Log(LogType.Warning, LanguageManager.GetText("OptionsUnknown", name));
         }
         else
         {
             Options[name].Value = val;
         }
     }
 }
Exemplo n.º 16
0
        public static void Connect(TcpClient client, string host, int controlPort, string controlPassword)
        {
            if (client == null)
            {
                throw new Exception("Internal error (client is null)");
            }

            bool controlAuthenticate = Engine.Instance.Storage.GetBool("proxy.tor.control.auth");

            byte[] password = System.Text.Encoding.ASCII.GetBytes(controlPassword);

            if (controlAuthenticate)
            {
                if (controlPassword == "")
                {
                    Init();

                    if (m_torCookiePath == "")
                    {
                        throw new Exception(LanguageManager.GetText("TorControlNoPath"));
                    }

                    Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("TorControlAuth", "Cookie, from " + m_torCookiePath));

                    password = m_torCookiePassword;
                }
                else
                {
                    Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("TorControlAuth", "Password"));
                }
            }

            client.Connect(host, controlPort);

            if (controlAuthenticate)
            {
                Write(client, "AUTHENTICATE ");
                Write(client, ExtensionsString.BytesToHex(password));
                Write(client, "\n");

                string result = Read(client);

                if (result != "250 OK")
                {
                    throw new Exception(result);
                }
            }

            Flush(client);
        }
Exemplo n.º 17
0
        public void Environment()
        {
            Add("Eddie version", Constants.VersionShow);
            Add("Eddie OS build", Platform.Instance.GetSystemCode());
            Add("Eddie architecture", Platform.Instance.GetArchitecture());
            Add("OS type", Platform.Instance.GetCode());
            Add("OS name", Platform.Instance.GetName());
            Add("OS version", Platform.Instance.GetVersion());
            Add("OS architecture", Platform.Instance.GetOsArchitecture());
            Add("Mono /.Net Framework", Platform.Instance.GetNetFrameworkVersion());

            Add("TUN driver", Software.TunDriver);
            Add("OpenVPN", Software.GetTool("openvpn").Version + " (" + Software.GetTool("openvpn").Path + ")");
            Add("Hummingbird", Software.GetTool("hummingbird").Version + " (" + Software.GetTool("hummingbird").Path + ")");
            Add("SSH", Software.GetTool("ssh").Version + " (" + Software.GetTool("ssh").Path + ")");
            Add("SSL", Software.GetTool("ssl").Version + " (" + Software.GetTool("ssl").Path + ")");
            if (Platform.Instance.FetchUrlInternal() == false)
            {
                Add("curl", Software.GetTool("curl").Version + " (" + Software.GetTool("curl").Path + ")");
            }

            Add("Profile path", Engine.Instance.GetProfilePath());
            Add("Data path", Engine.Instance.GetDataPath());
            Add("Application path", Platform.Instance.GetApplicationPath());
            Add("Executable path", Platform.Instance.GetExecutablePath());
            Add("Command line arguments", "(" + Engine.Instance.StartCommandLine.Params.Count.ToString() + " args) " + Engine.Instance.StartCommandLine.GetFull());

            {
                string nl = LanguageManager.GetText("No");
                if (Engine.Instance.NetworkLockManager.IsActive())
                {
                    nl = LanguageManager.GetText("Yes") + ", " + Engine.Instance.NetworkLockManager.GetActive().GetName();
                }
                Add("Network Lock Active", nl);
            }

            {
                string cn = LanguageManager.GetText("No");
                if (Engine.Instance.IsConnected())
                {
                    cn = LanguageManager.GetText("Yes") + ", " + Engine.Instance.Stats.Get("ServerName").Text;
                }
                Add("Connected to VPN", cn);
            }

            Add("Detected DNS", Platform.Instance.DetectDNS().ToString());
            //Add("Detected Exit", Engine.Instance.DiscoverExit().ToString());
        }
Exemplo n.º 18
0
        public void Start2(UiClient client)
        {
            Json jReport = new Json();

            jReport["command"].Value = "system.report.progress";
            jReport["step"].Value    = LanguageManager.GetText("ReportStepCollectEnvironmentInfo");
            jReport["body"].Value    = LanguageManager.GetText("PleaseWait");
            jReport["perc"].Value    = 0;
            client.OnReceive(jReport);

            Environment();

            jReport["step"].Value = LanguageManager.GetText("ReportStepTests");
            jReport["body"].Value = ToString();
            jReport["perc"].Value = 10;
            client.OnReceive(jReport);

            Tests();

            jReport["step"].Value = LanguageManager.GetText("ReportStepLogs");
            jReport["body"].Value = ToString();
            jReport["perc"].Value = 50;
            client.OnReceive(jReport);

            Add(LanguageManager.GetText("ReportOptions"), Engine.Instance.Storage.GetReportForSupport());

            Add(LanguageManager.GetText("ReportLogs"), Engine.Instance.Logs.ToString());

            jReport["step"].Value = LanguageManager.GetText("ReportStepLogs");
            jReport["body"].Value = ToString();
            jReport["perc"].Value = 60;
            client.OnReceive(jReport);

            jReport["step"].Value = LanguageManager.GetText("ReportStepPlatform");
            jReport["body"].Value = ToString();
            jReport["perc"].Value = 70;
            client.OnReceive(jReport);

            NetworkInfo();

            Platform.Instance.OnReport(this);

            jReport["step"].Value = LanguageManager.GetText("ReportStepDone");
            jReport["body"].Value = ToString();
            jReport["perc"].Value = 100;
            client.OnReceive(jReport);
        }
Exemplo n.º 19
0
        public Stats()
        {
            Charts = new UI.Charts();


            Add("ServerName", LanguageManager.GetText("StatsServerName"), "server");
            Add("ServerLatency", LanguageManager.GetText("StatsServerLatency"), "server");
            Add("ServerLocation", LanguageManager.GetText("StatsServerLocation"), "server");
            Add("ServerLoad", LanguageManager.GetText("StatsServerLoad"), "server");
            Add("ServerUsers", LanguageManager.GetText("StatsServerUsers"), "server");
            Add("AccountLogin", LanguageManager.GetText("StatsLogin"), "session");
            Add("AccountKey", LanguageManager.GetText("StatsKey"), "session");
            Add("VpnSpeedDownload", LanguageManager.GetText("StatsVpnSpeedDownload"), "session");
            Add("VpnSpeedUpload", LanguageManager.GetText("StatsVpnSpeedUpload"), "session");
            Add("VpnStart", LanguageManager.GetText("StatsVpnStart"), "session");
            Add("VpnTotalDownload", LanguageManager.GetText("StatsVpnTotalDownload"), "vpn");
            Add("VpnTotalUpload", LanguageManager.GetText("StatsVpnTotalUpload"), "vpn");
            Add("VpnEntryIP", LanguageManager.GetText("StatsVpnEntryIP"), "vpn");
            Add("VpnExitIPv4", LanguageManager.GetText("StatsVpnExitIPv4"), "vpn");
            Add("VpnExitIPv6", LanguageManager.GetText("StatsVpnExitIPv6"), "vpn");
            Add("VpnProtocol", LanguageManager.GetText("StatsVpnProtocol"), "vpn");
            Add("VpnPort", LanguageManager.GetText("StatsVpnPort"), "vpn");
            Add("VpnRealIp", LanguageManager.GetText("StatsVpnRealIp"), "vpn");
            Add("VpnIp", LanguageManager.GetText("StatsVpnIp"), "vpn");
            Add("VpnDns", LanguageManager.GetText("StatsVpnDns"), "vpn");
            Add("VpnInterface", LanguageManager.GetText("StatsVpnInterface"), "vpn");
            Add("VpnGateway", LanguageManager.GetText("StatsVpnGateway"), "vpn");
            Add("VpnCipher", LanguageManager.GetText("StatsVpnCipher"), "vpn");
            Add("VpnControlChannel", LanguageManager.GetText("StatsVpnControlChannel"), "vpn");
            Add("VpnGeneratedOVPN", LanguageManager.GetText("StatsVpnGeneratedOVPN"), "vpn", "view");
            Add("VpnGeneratedOVPNPush", LanguageManager.GetText("StatsVpnGeneratedOVPNPush"), "vpn", "view");
            Add("SessionStart", LanguageManager.GetText("StatsSessionStart"), "session");
            Add("SessionTotalDownload", LanguageManager.GetText("StatsSessionTotalDownload"), "session");
            Add("SessionTotalUpload", LanguageManager.GetText("StatsSessionTotalUpload"), "session");
            Add("Discovery", LanguageManager.GetText("StatsDiscovery"), "system", "Update");
            Add("Pinger", LanguageManager.GetText("StatsPinger"), "system", "Update");
            Add("SystemTimeServerDifference", LanguageManager.GetText("StatsSystemTimeServerDifference"), "system");
            Add("PathProfile", LanguageManager.GetText("StatsSystemPathProfile"), "system", "Open");
            Add("PathData", LanguageManager.GetText("StatsSystemPathData"), "system", "Open");
            Add("PathApp", LanguageManager.GetText("StatsSystemPathApp"), "system", "Open");

            UpdateValue("PathProfile", Engine.Instance.GetProfilePath());
            UpdateValue("PathData", Engine.Instance.GetDataPath());
            UpdateValue("PathApp", Platform.Instance.GetApplicationPath());
        }
Exemplo n.º 20
0
 public string TestPing(string host)
 {
     try
     {
         Int64 result = Platform.Instance.Ping(new IpAddress(host), 5000);
         if (result == -1)
         {
             return(LanguageManager.GetText("Failed"));
         }
         else
         {
             return(result + " ms");
         }
     }
     catch (Exception ex)
     {
         return("Error: " + ex.Message);
     }
 }
Exemplo n.º 21
0
        public void UpdatePath()
        {
            try
            {
                OnUpdatePath();
                OnUpdateVersion();
                OnNormalizeVersion();
            }
            catch (Exception e)
            {
                Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("BundleExecutableError", Code, Path));
                Engine.Instance.Logs.Log(LogType.Verbose, e.Message);
                Engine.Instance.Logs.Log(LogType.Verbose, Platform.Instance.GetExecutableReport(Path));

                Path     = "";
                Version  = "";
                Location = "missing";
            }
        }
Exemplo n.º 22
0
 public string TestUrl(string url)
 {
     try
     {
         HttpRequest request = new HttpRequest();
         request.Url = url;
         HttpResponse response = Engine.Instance.FetchUrl(request);
         if (response.GetBodyAscii().Trim() == "Success.")
         {
             return(LanguageManager.GetText("Ok"));
         }
         else
         {
             return(LanguageManager.GetText("Failed") + " - " + response.GetLineReport());
         }
     }
     catch (Exception ex)
     {
         return("Error:" + ex.Message);
     }
 }
Exemplo n.º 23
0
        public void Init()
        {
            KnownCommands["cli"]           = "";
            KnownCommands["version"]       = LanguageManager.GetText("ManCommandLineVersion");
            KnownCommands["version.short"] = LanguageManager.GetText("ManCommandLineVersionShort");
            KnownCommands["help"]          = LanguageManager.GetText("ManCommandLineHelp");
            KnownCommands["help.format"]   = LanguageManager.GetText("ManCommandLineHelpFormat");

            KnownCommands["linux.xhost"]  = "";             // Internal
            KnownCommands["linux.dbus"]   = "";             // Internal
            KnownCommands["console.mode"] = "";             // Internal
            KnownCommands["path.exec"]    = "";             // Internal
            //KnownCommands["gui.osx.style"] = "";  // Internal
            KnownCommands["advanced.skip_privileges"] = ""; // Internal

            KnownCommands["profile"] = LanguageManager.GetText("ManCommandLineProfile");
            KnownCommands["path"]    = LanguageManager.GetText("ManCommandLinePath");

            KnownCommands["path.resources"] = "";
            KnownCommands["path.tools"]     = "";
        }
Exemplo n.º 24
0
        public void OnRecoveryLoad(XmlElement root)
        {
            try
            {
                if (m_current != null)
                {
                    throw new Exception(LanguageManager.GetText("NetworkLockRecoveryWhenActive"));
                }

                XmlElement node = root.GetFirstElementByTagName("netlock");
                if (node != null)
                {
                    string code = node.GetAttribute("mode");

                    foreach (NetworkLockPlugin lockPlugin in Engine.Instance.NetworkLockManager.Modes)
                    {
                        if (lockPlugin.GetCode() == code)
                        {
                            m_current = lockPlugin;
                            break;
                        }
                    }

                    if (m_current != null)
                    {
                        m_current.OnRecoveryLoad(node);
                    }
                    else
                    {
                        Engine.Instance.Logs.Log(LogType.Warning, LanguageManager.GetText("NetworkLockRecoveryUnknownMode"));
                    }

                    Deactivation(false);
                }
            }
            catch (Exception e)
            {
                Engine.Instance.Logs.Log(e);
            }
        }
Exemplo n.º 25
0
        public void Tests()
        {
            IpAddresses dns = DnsManager.ResolveDNS("dnstest.eddie.website", true);

            Add("Test DNS IPv4", (dns.CountIPv4 == 2) ? LanguageManager.GetText("Ok") : LanguageManager.GetText("Failed"));
            Add("Test DNS IPv6", (dns.CountIPv6 == 2) ? LanguageManager.GetText("Ok") : LanguageManager.GetText("Failed"));

            /* Changed in 2.17.1
             * Add("Test Ping IPv4", Platform.Instance.Ping(dns.OnlyIPv4.First, 5000).ToString() + " ms");
             * Add("Test Ping IPv6", Platform.Instance.Ping(dns.OnlyIPv6.First, 5000).ToString() + " ms");
             *
             * Add("Test HTTP IPv4", TestUrl("http://" + "ipv4." + Constants.Domain + "/test/"));
             * Add("Test HTTP IPv6", TestUrl("http://" + "ipv6." + Constants.Domain + "/test/"));
             * Add("Test HTTPS", TestUrl("https://" + Constants.Domain + "/test/"));
             */
            Add("Test Ping IPv4", Platform.Instance.Ping(new IpAddress(Constants.WebSiteIPv4), 5000).ToString() + " ms");
            Add("Test Ping IPv6", Platform.Instance.Ping(new IpAddress(Constants.WebSiteIPv6), 5000).ToString() + " ms");

            Add("Test HTTP IPv4", TestUrl("http://" + Constants.WebSiteIPv4 + "/test/"));
            Add("Test HTTP IPv6", TestUrl("http://[" + Constants.WebSiteIPv6 + "]/test/"));
            Add("Test HTTPS", TestUrl("https://" + Constants.Domain + "/test/"));
        }
Exemplo n.º 26
0
        public void FatalError(string reason)
        {
            if (m_failedReason != "")             // Already catched
            {
                return;
            }

            m_failedReason = reason;
            lock (PendingCommands)
            {
                foreach (KeyValuePair <UInt32, Command> kp in PendingCommands)
                {
                    kp.Value.Abort();
                }
            }

            if (m_started)
            {
                Engine.Instance.Logs.LogFatal(LanguageManager.GetText("HelperPrivilegesCrash") + ":" + reason);
                Environment.Exit(0);                 // Brutal, but correct.
            }
        }
Exemplo n.º 27
0
        public ConnectionActive BuildConnectionActive(bool preview)
        {
            // If preview, no physical additional files are created.

            ConnectionActive connectionActive = new ConnectionActive();

            Storage s = Engine.Instance.Storage;

            connectionActive.OpenVpnProfileStartup = new OvpnBuilder();
            OvpnBuilder ovpn = connectionActive.OpenVpnProfileStartup;

            ovpn.AppendDirective("setenv", "IV_GUI_VER " + Constants.Name + Constants.VersionDesc, "Client level");

            if (s.GetBool("openvpn.skip_defaults") == false)
            {
                ovpn.AppendDirectives(Engine.Instance.Storage.Get("openvpn.directives"), "Client level");
                string directivesPath = Engine.Instance.Storage.Get("openvpn.directives.path");
                if (directivesPath.Trim() != "")
                {
                    try
                    {
                        if (Platform.Instance.FileExists(directivesPath))
                        {
                            string text = Platform.Instance.FileContentsReadText(directivesPath);
                            ovpn.AppendDirectives(text, "Client level");
                        }
                        else
                        {
                            Engine.Instance.Logs.Log(LogType.Warning, LanguageManager.GetText("FileNotFound", directivesPath));
                        }
                    }
                    catch (Exception ex)
                    {
                        Engine.Instance.Logs.Log(LogType.Warning, LanguageManager.GetText("FileErrorRead", directivesPath, ex.Message));
                    }
                }
                Provider.OnBuildOvpnDefaults(ovpn);

                ovpn.AppendDirectives(OvpnDirectives, "Server level");

                if (Path != "")
                {
                    if (Platform.Instance.FileExists(Path))
                    {
                        string text = Platform.Instance.FileContentsReadText(Path);
                        ovpn.AppendDirectives(text, "Config file");

                        string dirPath = Platform.Instance.FileGetDirectoryPath(Path);
                        ovpn.NormalizeRelativePath(dirPath);
                    }
                }
            }

            if (s.Get("openvpn.dev_node") != "")
            {
                ovpn.AppendDirective("dev-node", s.Get("openvpn.dev_node"), "");
            }

            if (s.Get("network.entry.iface") != "")
            {
                ovpn.AppendDirective("local", s.Get("network.entry.iface"), "");
                ovpn.RemoveDirective("nobind");
            }
            else
            {
                ovpn.RemoveDirective("local");
                ovpn.AppendDirective("nobind", "", "");
            }

            int rcvbuf = s.GetInt("openvpn.rcvbuf");

            if (rcvbuf == -2)
            {
                rcvbuf = Platform.Instance.GetRecommendedRcvBufDirective();
            }
            if (rcvbuf == -2)
            {
                rcvbuf = -1;
            }
            if (rcvbuf != -1)
            {
                ovpn.AppendDirective("rcvbuf", rcvbuf.ToString(), "");
            }

            int sndbuf = s.GetInt("openvpn.sndbuf");

            if (sndbuf == -2)
            {
                sndbuf = Platform.Instance.GetRecommendedSndBufDirective();
            }
            if (sndbuf == -2)
            {
                sndbuf = -1;
            }
            if (sndbuf != -1)
            {
                ovpn.AppendDirective("sndbuf", sndbuf.ToString(), "");
            }

            string proxyDirectiveName = "";
            string proxyDirectiveArgs = "";

            string proxyMode = s.GetLower("proxy.mode");
            string proxyWhen = s.GetLower("proxy.when");

            if ((proxyWhen == "none") || (proxyWhen == "web"))
            {
                proxyMode = "none";
            }
            if (proxyMode == "tor")
            {
                proxyDirectiveName = "socks-proxy";
            }
            else if (proxyMode == "http")
            {
                proxyDirectiveName = "http-proxy";
            }
            else if (proxyMode == "socks")
            {
                proxyDirectiveName = "socks-proxy";
            }

            if (proxyDirectiveName != "")
            {
                proxyDirectiveArgs += s.Get("proxy.host") + " " + s.Get("proxy.port");

                if ((s.GetLower("proxy.mode") != "none") && (s.GetLower("proxy.mode") != "tor"))
                {
                    if (s.Get("proxy.auth") != "None")
                    {
                        string fileNameAuthOvpn = "";
                        if (preview)
                        {
                            fileNameAuthOvpn = "dummy.ppw";
                        }
                        else
                        {
                            connectionActive.ProxyAuthFile = new TemporaryFile("ppw");
                            fileNameAuthOvpn = connectionActive.ProxyAuthFile.Path;
                            string fileNameData = s.Get("proxy.login") + "\n" + s.Get("proxy.password") + "\n";
                            Platform.Instance.FileContentsWriteText(connectionActive.ProxyAuthFile.Path, fileNameData, Encoding.Default);                             // TOFIX: Check if OpenVPN expect UTF-8
                            Platform.Instance.FileEnsurePermission(connectionActive.ProxyAuthFile.Path, "600");
                        }
                        proxyDirectiveArgs += " " + ovpn.EncodePath(fileNameAuthOvpn) + " " + s.Get("proxy.auth").ToLowerInvariant();                         // 2.6 Auth Fix
                    }
                }

                ovpn.AppendDirective(proxyDirectiveName, proxyDirectiveArgs, "");
            }

            if (Constants.FeatureIPv6ControlOptions)
            {
                if (s.GetLower("network.ipv4.mode") == "in")
                {
                    connectionActive.TunnelIPv4 = true;
                }
                else if (s.GetLower("network.ipv4.mode") == "in-out")
                {
                    if (SupportIPv4)
                    {
                        connectionActive.TunnelIPv4 = true;
                    }
                    else
                    {
                        connectionActive.TunnelIPv4 = false;
                    }
                }
                else if (s.GetLower("network.ipv4.mode") == "in-block")
                {
                    if (SupportIPv4)
                    {
                        connectionActive.TunnelIPv4 = true;
                    }
                    else
                    {
                        connectionActive.TunnelIPv4 = false;                         // Out, but doesn't matter, will be blocked.
                    }
                }
                else if (s.GetLower("network.ipv4.mode") == "out")
                {
                    connectionActive.TunnelIPv4 = false;
                }
                else if (s.GetLower("network.ipv4.mode") == "block")
                {
                    connectionActive.TunnelIPv4 = false;                     // Out, but doesn't matter, will be blocked.
                }

                if (Engine.Instance.GetNetworkIPv6Mode() == "in")
                {
                    connectionActive.TunnelIPv6 = true;
                }
                else if (Engine.Instance.GetNetworkIPv6Mode() == "in-out")
                {
                    if (SupportIPv6)
                    {
                        connectionActive.TunnelIPv6 = true;
                    }
                    else
                    {
                        connectionActive.TunnelIPv6 = false;
                    }
                }
                else if (Engine.Instance.GetNetworkIPv6Mode() == "in-block")
                {
                    if (SupportIPv6)
                    {
                        connectionActive.TunnelIPv6 = true;
                    }
                    else
                    {
                        connectionActive.TunnelIPv6 = false;
                    }
                }
                else if (Engine.Instance.GetNetworkIPv6Mode() == "out")
                {
                    connectionActive.TunnelIPv6 = false;
                }
                else if (Engine.Instance.GetNetworkIPv6Mode() == "block")
                {
                    connectionActive.TunnelIPv6 = false;
                }

                if (Software.GetTool("openvpn").VersionAboveOrEqual("2.4"))
                {
                    ovpn.RemoveDirective("redirect-gateway");                     // Remove if exists
                    ovpn.AppendDirective("pull-filter", "ignore \"redirect-gateway\"", "Forced at client side");

                    if (connectionActive.TunnelIPv6 == false)
                    {
                        ovpn.AppendDirective("pull-filter", "ignore \"dhcp-option DNS6\"", "Client side");
                        ovpn.AppendDirective("pull-filter", "ignore \"tun-ipv6\"", "Client side");
                        ovpn.AppendDirective("pull-filter", "ignore \"ifconfig-ipv6\"", "Client side");
                    }

                    if ((connectionActive.TunnelIPv4 == false) && (connectionActive.TunnelIPv6 == false))
                    {
                        // no redirect-gateway
                    }
                    else if ((connectionActive.TunnelIPv4 == true) && (connectionActive.TunnelIPv6 == false))
                    {
                        ovpn.AppendDirective("redirect-gateway", "def1 bypass-dhcp", "");
                    }
                    else if ((connectionActive.TunnelIPv4 == false) && (connectionActive.TunnelIPv6 == true))
                    {
                        ovpn.AppendDirective("redirect-gateway", "ipv6 !ipv4 def1 bypass-dhcp", "");
                    }
                    else
                    {
                        ovpn.AppendDirective("redirect-gateway", "ipv6 def1 bypass-dhcp", "");
                    }
                }
                else
                {
                    // OpenVPN <2.4, IPv6 not supported, IPv4 required.
                    connectionActive.TunnelIPv4 = true;
                    connectionActive.TunnelIPv6 = false;

                    if (connectionActive.TunnelIPv4)
                    {
                        ovpn.AppendDirective("redirect-gateway", "def1 bypass-dhcp", "");
                    }
                    else
                    {
                        ovpn.AppendDirective("route-nopull", "", "For Routes Out");

                        // 2.9, this is used by Linux resolv-conf DNS method. Need because route-nopull also filter pushed dhcp-option.
                        // Incorrect with other provider, but the right-approach (pull-filter based) require OpenVPN <2.4.
                        ovpn.AppendDirective("dhcp-option", "DNS " + Constants.DnsVpn, "");
                    }
                }
            }
            else
            {
                string routesDefault = s.Get("routes.default");

                connectionActive.TunnelIPv4 = (routesDefault == "in");
                connectionActive.TunnelIPv6 = (routesDefault == "in");

                if (routesDefault == "out")
                {
                    if (Software.GetTool("openvpn").VersionAboveOrEqual("2.4"))
                    {
                        ovpn.RemoveDirective("redirect-gateway");                         // Remove if exists
                        ovpn.AppendDirective("pull-filter", "ignore \"redirect-gateway\"", "For Routes Out");
                    }
                    else                     // Compatibility <2.4
                    {
                        ovpn.AppendDirective("route-nopull", "", "For Routes Out");

                        // For DNS
                        // < 2.9. route directive useless, and DNS are forced manually in every supported platform. // TOCLEAN

                        /*
                         * ovpn += "dhcp-option DNS " + Constants.DnsVpn + "\n"; // Manually because route-nopull skip it
                         * ovpn += "route 10.4.0.1 255.255.255.255 vpn_gateway # AirDNS\n";
                         * ovpn += "route 10.5.0.1 255.255.255.255 vpn_gateway # AirDNS\n";
                         * ovpn += "route 10.6.0.1 255.255.255.255 vpn_gateway # AirDNS\n";
                         * ovpn += "route 10.7.0.1 255.255.255.255 vpn_gateway # AirDNS\n";
                         * ovpn += "route 10.8.0.1 255.255.255.255 vpn_gateway # AirDNS\n";
                         * ovpn += "route 10.9.0.1 255.255.255.255 vpn_gateway # AirDNS\n";
                         * ovpn += "route 10.30.0.1 255.255.255.255 vpn_gateway # AirDNS\n";
                         * ovpn += "route 10.50.0.1 255.255.255.255 vpn_gateway # AirDNS\n";
                         */

                        // 2.9, this is used by Linux resolv-conf DNS method. Need because route-nopull also filter pushed dhcp-option.
                        // Incorrect with other provider, but the right-approach (pull-filter based) require OpenVPN <2.4.
                        ovpn.AppendDirective("dhcp-option", "DNS " + Constants.DnsVpn, "");
                    }
                }
            }

            // For Checking
            foreach (IpAddress ip in IpsExit.IPs)
            {
                connectionActive.AddRoute(ip, "vpn_gateway", "For Checking Route");
            }

            string routes = s.Get("routes.custom");

            string[] routes2 = routes.Split(';');
            foreach (string route in routes2)
            {
                string[] routeEntries = route.Split(',');
                if (routeEntries.Length != 3)
                {
                    continue;
                }

                string      ipCustomRoute  = routeEntries[0];
                IpAddresses ipsCustomRoute = new IpAddresses(ipCustomRoute);

                if (ipsCustomRoute.Count == 0)
                {
                    Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("CustomRouteInvalid", ipCustomRoute.ToString()));
                }
                else
                {
                    string action = routeEntries[1];
                    string notes  = routeEntries[2];

                    foreach (IpAddress ip in ipsCustomRoute.IPs)
                    {
                        bool layerIn = false;
                        if (ip.IsV4)
                        {
                            layerIn = connectionActive.TunnelIPv4;
                        }
                        else if (ip.IsV6)
                        {
                            layerIn = connectionActive.TunnelIPv6;
                        }
                        string gateway = "";
                        if ((layerIn == false) && (action == "in"))
                        {
                            gateway = "vpn_gateway";
                        }
                        if ((layerIn == true) && (action == "out"))
                        {
                            gateway = "net_gateway";
                        }
                        if (gateway != "")
                        {
                            connectionActive.AddRoute(ip, gateway, (notes != "") ? notes.Safe() : ipCustomRoute);
                        }
                    }
                }
            }

            if (proxyMode == "tor")
            {
                if (preview == false)
                {
                    TorControl.SendNEWNYM();
                }
                IpAddresses torNodeIps = TorControl.GetGuardIps((preview == false));
                foreach (IpAddress torNodeIp in torNodeIps.IPs)
                {
                    if (((connectionActive.TunnelIPv4) && (torNodeIp.IsV4)) ||
                        ((connectionActive.TunnelIPv6) && (torNodeIp.IsV6)))
                    {
                        connectionActive.AddRoute(torNodeIp, "net_gateway", "Tor Guard");
                    }
                }
            }

            {
                string managementPasswordFile = "dummy.ppw";
                if (preview == false)
                {
                    connectionActive.ManagementPassword     = RandomGenerator.GetHash();
                    connectionActive.ManagementPasswordFile = new TemporaryFile("ppw");
                    managementPasswordFile = connectionActive.ManagementPasswordFile.Path;
                    Platform.Instance.FileContentsWriteText(managementPasswordFile, connectionActive.ManagementPassword, Encoding.ASCII); // UTF8 not recognized by OpenVPN
                    Platform.Instance.FileEnsurePermission(managementPasswordFile, "600");
                }

                ovpn.AppendDirective("management", "127.0.0.1 " + Engine.Instance.Storage.Get("openvpn.management_port") + " " + ovpn.EncodePath(managementPasswordFile), "");
            }

            // Experimental - Allow identification as Public Network in Windows. Advanced Option?
            // ovpn.Append("route-metric 512");
            // ovpn.Append("route 0.0.0.0 0.0.0.0");

            Provider.OnBuildConnectionActive(this, connectionActive);

            Provider.OnBuildConnectionActiveAuth(connectionActive);

            Platform.Instance.OnBuildOvpn(ovpn);

            ovpn.AppendDirectives(Engine.Instance.Storage.Get("openvpn.custom"), "Custom level");

            foreach (ConnectionActiveRoute route in connectionActive.Routes)
            {
                if ((route.Address.IsV6) || (Constants.FeatureAlwaysBypassOpenvpnRoute))
                {
                }
                else
                {
                    // We never find a better method to manage IPv6 route via OpenVPN, at least <2.4.4
                    ovpn.AppendDirective("route", route.Address.ToOpenVPN() + " " + route.Gateway, route.Notes.Safe());
                }
            }

            ovpn.Normalize();

            return(connectionActive);
        }
Exemplo n.º 28
0
        public virtual void FlushDNS()
        {
            Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("ConnectionFlushDNS"));

            DnsManager.Invalidate();
        }
Exemplo n.º 29
0
 public virtual string GetDriverAvailable()
 {
     return(LanguageManager.GetText("NotImplemented"));
 }
Exemplo n.º 30
0
        public static IpAddresses GetGuardIps(bool force)
        {
            // This is called a lots of time.
            Int64 now = Utils.UnixTimeStamp();

            if ((force == false) && ((now - m_lastGuardTime < 60)))
            {
                return(m_lastGuardIps);
            }

            IpAddresses ips = new IpAddresses();

            try
            {
                string controlHost = Engine.Instance.Storage.Get("proxy.host").ToLowerInvariant().Trim();

                if ((controlHost != "127.0.0.1") && (controlHost.ToLowerInvariant() != "localhost"))
                {
                    // Guard IPS are used to avoid routing loop, that occur only if the Tor host is the same machine when OpenVPN run.
                    return(ips);
                }

                List <string> ipsMessages = new List <string>();

                using (TcpClient s = new TcpClient())
                {
                    Connect(s);

                    Write(s, "getinfo circuit-status\n");
                    Flush(s);
                    string circuits = Read(s);

                    string[] circuitsLines = circuits.Split('\n');
                    foreach (string circuit in circuitsLines)
                    {
                        string id = circuit.ToLowerInvariant().RegExMatchOne("\\d+\\sbuilt\\s\\$([0-9a-f]+)");

                        if (id != "")
                        {
                            Write(s, "getinfo ns/id/" + id.ToUpperInvariant() + "\n");
                            string nodeInfo = Read(s);

                            string[] nodeLines = nodeInfo.Split('\n');
                            foreach (string line in nodeLines)
                            {
                                string ip = line.RegExMatchOne("r\\s.+?\\s.+?\\s.+?\\s.+?\\s.+?\\s(.+?)\\s");

                                if ((IpAddress.IsIP(ip)) && (!ips.Contains(ip)))
                                {
                                    ips.Add(ip);
                                    ipsMessages.Add(ip + " (circuit)");
                                }
                            }
                        }
                    }

                    Write(s, "getconf bridge\n");
                    Flush(s);
                    string bridges = Read(s);

                    if (bridges.IndexOf("meek") == -1)                     //Panic if we have meek enabled, don't yet know what to do :-(
                    {
                        string[] bridgeLines = bridges.Split('\n');
                        foreach (string bridge in bridgeLines)
                        {
                            List <string> matches = bridge.ToLowerInvariant().RegExMatchSingle("250.bridge=(.+?)\\s([0-9a-f\\.\\:]+?):\\d+\\s");
                            if ((matches != null) && (matches.Count == 2))
                            {
                                string bridgeType = matches[0];
                                string ip         = matches[1];

                                if ((IpAddress.IsIP(ip)) && (!ips.Contains(ip)))
                                {
                                    ips.Add(matches[1]);
                                    ipsMessages.Add(matches[1] + " (" + bridgeType + ")");
                                }
                            }
                        }
                    }
                    else
                    {
                        Engine.Instance.Logs.Log(LogType.Warning, LanguageManager.GetText("TorControlMeekUnsupported"));
                    }

                    if (ips.Count == 0)
                    {
                        Engine.Instance.Logs.Log(LogType.Warning, LanguageManager.GetText("TorControlNoIps"));
                        //throw new Exception(Messages.TorControlNoIps);
                    }
                    else
                    {
                        string list = String.Join("; ", ipsMessages.ToArray());
                        Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("TorControlGuardIps", list));
                    }
                }
            }
            catch (Exception e)
            {
                //throw new Exception(LanguageManager.GetText("TorControlException, e.Message));
                Engine.Instance.Logs.Log(LogType.Warning, LanguageManager.GetText("TorControlException", e.Message));
            }

            m_lastGuardIps  = ips;
            m_lastGuardTime = now;

            return(ips);
        }