예제 #1
0
        public bool Initialization(bool cli)
        {
            if (ResourcesFiles.Count() == 0)
            {
                ResourcesFiles.SetString("AirVPN.xml", Lib.Core.Properties.Resources.AirVPN); // TOCLEAN with Eddie3
                ResourcesFiles.SetString("OpenVPN.xml", Lib.Core.Properties.Resources.OpenVPN); // TOCLEAN with Eddie3
                ResourcesFiles.SetString("license.txt", Lib.Core.Properties.Resources.License);
                ResourcesFiles.SetString("thirdparty.txt", Lib.Core.Properties.Resources.ThirdParty);
                ResourcesFiles.SetString("tos.txt", Lib.Core.Properties.Resources.TOS); // TOCLEAN
            }

            DevelopmentEnvironment = Platform.Instance.FileExists(Platform.Instance.NormalizePath(Platform.Instance.GetApplicationPath() + "/dev.txt"));
            m_logsManager = new LogsManager();

            Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);

            m_storage = new Core.Storage();

            if (cli)
            {
                if (Storage.GetBool("help"))
                {
                    Engine.Instance.Logs.Log(LogType.Info, Storage.GetMan(Storage.Get("help_format")));
                    return false;
                }
            }

            Logs.Log(LogType.Info, "Eddie client version: " + Constants.VersionDesc + " / " + Platform.Instance.GetSystemCode() + ", System: " + Platform.Instance.GetCode() + ", Name: " + Platform.Instance.GetName() + ", Mono/.Net Framework: " + Platform.Instance.GetMonoVersion());

            if (DevelopmentEnvironment)
                Logs.Log(LogType.Info, "Development environment.");

            // This is before the Storage.Load, because non-root can't read option (chmod)
            if (Storage.GetBool("advanced.skip_privileges") == false)
            {
                if (Platform.Instance.IsAdmin() == false)
                {
                    if (OnNoRoot() == false)
                        Logs.Log(LogType.Fatal, Messages.AdminRequiredStop);

                    return false;
                }
            }

            CountriesManager.Init();

            // Providers
            m_providersManager = new ProvidersManager();
            m_providersManager.Init();

            m_storage.Load();

            if (Storage.GetBool("tcpserver.enabled") == true)
            {
                m_tcpServer = new TcpServer();
                m_tcpServer.Start();

                /*
                string pathControl = Storage.Get("console.control.path");
                if (pathControl != "")
                {
                    Platform.Instance.FileContentsWriteText(pathControl, Storage.Get("tcpserver.port"));

                    m_tcpServer.SignalConnection.WaitOne(); // Clodo, TOCHECK; CTRL+C stop it?
                }
                */

                if (Storage.Get("console.mode") == "tcp")
                {
                    // Start requested by an UI, wait it.
                    m_tcpServer.SignalConnection.WaitOne(); // Clodo, TOCHECK; CTRL+C stop it?
                }
            }

            m_providersManager.Load();

            if (Storage.GetBool("cli"))
                ConsoleMode = true;

            if(Storage.Get("paramtest") != "") // Look comment in storage.cs
                Logs.Log(LogType.Warning, "Param test:-" + Storage.Get("paramtest") + "-");

            if(Storage.GetBool("os.single_instance") == true)
            {
                if(Platform.Instance.OnCheckSingleInstance() == false)
                {
                    Logs.Log(LogType.Fatal, Messages.OsInstanceAlreadyRunning);
                    return false;
                }
            }

            m_stats = new Core.Stats();

            if( (WebServer.GetPath() != "") && (Storage.GetBool("webui.enabled") == true) )
            {
                m_webServer = new WebServer();
                m_webServer.Start();
            }

            m_networkLockManager = new NetworkLockManager();
            m_networkLockManager.Init();

            CompatibilityManager.Init();

            Platform.Instance.OnInit();

            return true;
        }
예제 #2
0
        public void EnsureDefaults()
        {
            string NotInMan = "";             // Option not listed in 'man' documentation.

            SetDefaultBool("cli", false, Messages.ManOptionCli);
            SetDefaultBool("version", false, NotInMan);
            SetDefaultBool("version.short", false, NotInMan);
            SetDefaultBool("help", false, Messages.ManOptionHelp);
            SetDefault("help.format", "choice:text,bbcode,html,man", "text", Messages.ManOptionHelpFormat); // Maybe 'text' or 'bbcode' or 'html' or 'man'.
            SetDefaultBool("batch", false, NotInMan);                                                       // Don't lock interface, exit when connection is closed.
            SetDefault("login", "text", "", Messages.ManOptionLogin);
            SetDefault("password", "password", "", Messages.ManOptionPassword);
            SetDefaultBool("remember", false, Messages.ManOptionRemember);
            SetDefault("key", "text", "Default", Messages.ManOptionKey);
            SetDefault("server", "text", "", Messages.ManOptionServer);
            SetDefaultBool("connect", false, Messages.ManOptionConnect);
            SetDefaultBool("netlock", false, Messages.ManOptionNetLock);

            SetDefault("console.mode", "choice:batch,keys,backend,tcp", "keys", NotInMan);
            SetDefault("console.control.path", "text", "", NotInMan);

            SetDefault("profile", "text", "AirVPN.xml", Messages.ManOptionProfile); // Not in Settings
            SetDefault("path", "text", "", Messages.ManOptionPath);                 // Not in Settings // Path. Maybe a full path, or special values 'home' or 'program'.

            SetDefault("servers.last", "text", "", NotInMan, false);
            SetDefault("servers.whitelist", "text", "", Messages.ManOptionServersWhiteList);
            SetDefault("servers.blacklist", "text", "", Messages.ManOptionServersBlackList);
            SetDefaultBool("servers.startlast", false, Messages.ManOptionServersStartLast);
            SetDefaultBool("servers.locklast", false, Messages.ManOptionServersLockLast);
            SetDefault("servers.scoretype", "choice:Speed,Latency", "Speed", Messages.ManOptionServersScoreType);

            SetDefault("areas.whitelist", "text", "", Messages.ManOptionAreasWhiteList);
            SetDefault("areas.blacklist", "text", "", Messages.ManOptionAreasBlackList);

            SetDefault("discover.ip_webservice.list", "text", "https://ipleak.net/xml/{@ip};https://freegeoip.net/xml/{@ip};http://ip-api.com/xml/{@ip}", NotInMan);
            SetDefaultBool("discover.ip_webservice.first", true, NotInMan);

            SetDefaultBool("log.file.enabled", false, NotInMan);
            SetDefault("log.file.encoding", "encoding", "utf-8", NotInMan);
            SetDefault("log.file.path", "text", "logs/eddie_%y-%m-%d.log", NotInMan);
            SetDefaultBool("log.level.debug", false, NotInMan);
            SetDefaultBool("log.repeat", false, NotInMan);

            SetDefault("mode.protocol", "text", "AUTO", Messages.ManOptionModeProtocol);
            SetDefaultInt("mode.port", 443, Messages.ManOptionModePort);
            SetDefaultInt("mode.alt", 0, Messages.ManOptionModeAlt);

            SetDefault("proxy.mode", "text", "None", Messages.ManOptionProxyMode);
            SetDefault("proxy.host", "ip", "127.0.0.1", Messages.ManOptionProxyHost);
            SetDefaultInt("proxy.port", 8080, Messages.ManOptionProxyPort);
            SetDefault("proxy.auth", "text", "None", Messages.ManOptionProxyAuth);
            SetDefault("proxy.login", "text", "", Messages.ManOptionProxyLogin);
            SetDefault("proxy.password", "password", "", Messages.ManOptionProxyPassword);
            SetDefaultInt("proxy.tor.control.port", 9151, Messages.ManOptionProxyTorControlPort);
            SetDefaultBool("proxy.tor.control.auth", true, Messages.ManOptionProxyTorControlAuth);
            SetDefault("proxy.tor.control.cookie-path", "", "", NotInMan);
            SetDefault("proxy.tor.control.password", "password", "", Messages.ManOptionProxyTorControlPassword);

            SetDefault("routes.default", "choice:in,out", "in", Messages.ManOptionRoutesDefault);
            SetDefault("routes.custom", "text", "", Messages.ManOptionRoutesCustom);
            SetDefaultBool("routes.remove_default", false, Messages.ManOptionRoutesRemoveDefault);             // Will be probably deprecated, issues with DHCP renew.

            SetDefault("dns.mode", "text", "auto", Messages.ManOptionDnsMode);
            SetDefault("dns.servers", "text", "", Messages.ManOptionDnsServers);
            SetDefaultBool("dns.check", true, Messages.ManOptionDnsCheck);

            SetDefault("netlock.mode", "text", "auto", Messages.ManOptionNetLockMode);
            SetDefaultBool("netlock.allow_private", true, Messages.ManOptionNetLockAllowPrivate);
            SetDefaultBool("netlock.allow_ping", true, Messages.ManOptionNetLockAllowPing);
            SetDefault("netlock.allowed_ips", "text", "", Messages.ManOptionNetLockAllowedsIps);

            SetDefault("ipv6.mode", "text", "disable", Messages.ManOptionIpV6);

            SetDefault("tools.openvpn.path", "path_file", "", Messages.ManOptionToolsOpenVpnPath);
            SetDefault("tools.ssh.path", "path_file", "", Messages.ManOptionToolsSshPath);
            SetDefault("tools.ssl.path", "path_file", "", Messages.ManOptionToolsSslPath);
            SetDefault("tools.curl.path", "path_file", "", Messages.ManOptionToolsCurlPath);

            SetDefaultInt("tools.curl.max-time", 10, NotInMan);

            SetDefault("openvpn.custom", "text", "", Messages.ManOptionOpenVpnCustom);
            SetDefault("openvpn.dev_node", "text", "", Messages.ManOptionOpenVpnDevNode);
            SetDefaultInt("openvpn.sndbuf", -2, Messages.ManOptionOpenVpnSndBuf); // 2.11
            SetDefaultInt("openvpn.rcvbuf", -2, Messages.ManOptionOpenVpnRcvBuf); // 2.11
            SetDefault("openvpn.directives", "text", "client\r\ndev tun\r\nresolv-retry infinite\r\nnobind\r\npersist-key\r\npersist-tun\r\nverb 3\r\nconnect-retry-max 1\r\nping 10\r\nping-exit 32\r\nexplicit-exit-notify 5", Messages.ManOptionOpenVpnDirectives);
            SetDefaultBool("openvpn.skip_defaults", false, Messages.ManOptionOpenVpnSkipDefaults);

            // Not in Settings
            SetDefaultInt("openvpn.management_port", 3100, Messages.ManOptionOpenVpnManagementPort);
            SetDefaultInt("ssh.port", 0, Messages.ManOptionSshPort);
            SetDefaultInt("ssl.port", 0, Messages.ManOptionSslPort);
            SetDefault("ssl.options", "text", "", NotInMan); // "NO_SSLv2" < 2.11.10
            SetDefaultInt("ssl.verify", -1, NotInMan);

            SetDefaultBool("os.single_instance", true, Messages.ManOptionOsSingleInstance);

            bool webui = (WebServer.GetPath() != "");              // WebUI it's a Eddie 3.* feature not yet committed on GitHub.

            SetDefaultBool("webui.enabled", webui, NotInMan);      // Messages.ManOptionWebUiEnabled
            SetDefault("webui.ip", "text", "localhost", NotInMan); // Messages.ManOptionWebUiAddress
            SetDefaultInt("webui.port", 4649, NotInMan);           // Messages.ManOptionWebUiPort

            SetDefaultBool("tcpserver.enabled", webui, NotInMan);
            SetDefault("tcpserver.ip", "text", "localhost", NotInMan);
            SetDefaultInt("tcpserver.port", Constants.DefaultTcpPort, NotInMan);

            SetDefaultBool("advanced.expert", false, Messages.ManOptionAdvancedExpert);
            SetDefaultBool("advanced.check.route", true, Messages.ManOptionAdvancedCheckRoute);

            SetDefaultInt("advanced.penality_on_error", 30, NotInMan);

            SetDefaultBool("pinger.enabled", true, Messages.ManOptionAdvancedPingerEnabled);
            SetDefaultInt("pinger.delay", 0, Messages.ManOptionAdvancedPingerDelay);
            SetDefaultInt("pinger.retry", 0, Messages.ManOptionAdvancedPingerRetry);
            SetDefaultInt("pinger.jobs", 10, Messages.ManOptionAdvancedPingerJobs);
            SetDefaultInt("pinger.valid", 0, Messages.ManOptionAdvancedPingerValid);

            SetDefaultInt("advanced.manifest.refresh", -1, NotInMan);

            SetDefaultBool("advanced.skip_privileges", false, NotInMan); // Skip 'root' detection.
            SetDefaultBool("advanced.skip_tun_detect", false, NotInMan); // Skip TUN driver detection.
            SetDefaultBool("advanced.skip_alreadyrun", false, NotInMan); // Continue even if openvpn is already running.
            SetDefaultBool("servers.allow_anyway", false, NotInMan);     // Allow connection to server in 'Closed' status
            SetDefaultBool("advanced.testonly", false, NotInMan);        // Disconnect when connection occur.


            EnsureDefaultsEvent("app.start");
            EnsureDefaultsEvent("app.stop");
            EnsureDefaultsEvent("session.start");
            EnsureDefaultsEvent("session.stop");
            EnsureDefaultsEvent("vpn.pre");
            EnsureDefaultsEvent("vpn.up");
            EnsureDefaultsEvent("vpn.down");

            // Windows only
            SetDefault("windows.adapter_service", "text", "tap0901", Messages.ManOptionWindowsAdapterService);
            SetDefaultBool("windows.disable_driver_upgrade", false, Messages.ManOptionWindowsDisableDriverUpgrade);
            SetDefaultBool("windows.tap_up", true, Messages.ManOptionWindowsTapUp);
            SetDefaultBool("windows.dhcp_disable", false, Messages.ManOptionWindowsDhcpDisable);
            SetDefaultBool("windows.wfp.enable", true, Messages.ManOptionWindowsWfp);                                  // TOCLEAN
            SetDefaultBool("windows.wfp.dynamic", false, Messages.ManOptionWindowsWfpDynamic);
            SetDefaultBool("windows.ipv6.os_disable", false, Messages.ManOptionWindowsIPv6DisableAtOs);                // Must be default FALSE if WFP works well
            SetDefaultBool("windows.dns.force_all_interfaces", false, Messages.ManOptionWindowsDnsForceAllInterfaces); // Important: With WFP can be false, but users report DNS leak. Maybe not a real DNS Leak, simply request on DNS of other interfaces through VPN tunnel.
            SetDefaultBool("windows.dns.lock", true, Messages.ManOptionWindowsDnsLock);

            SetDefaultBool("windows.workarounds", false, NotInMan); // If true, some variants to identify issues

            // General UI
            SetDefault("ui.unit", "text", "", Messages.ManOptionUiUnit);
            SetDefaultBool("ui.iec", false, Messages.ManOptionUiIEC);

            // GUI only
            SetDefaultBool("gui.exit_confirm", true, NotInMan, false);
            SetDefault("gui.skin", "text", "Light", NotInMan, false);
            SetDefaultBool("gui.tos", false, NotInMan, false);
            SetDefault("gui.font.normal.name", "text", "", NotInMan);
            SetDefaultFloat("gui.font.normal.size", 0, NotInMan);
            SetDefaultInt("gui.log_limit", 1000, NotInMan);
            SetDefault("gui.window.main", "text", "", NotInMan, false);
            SetDefault("gui.list.servers", "text", "", NotInMan, false);
            SetDefault("gui.list.areas", "text", "", NotInMan, false);
            SetDefault("gui.list.logs", "text", "", NotInMan, false);

            // GUI - Windows only
            SetDefaultBool("gui.windows.start_minimized", false, NotInMan);
            SetDefaultBool("gui.windows.tray", true, NotInMan);
            SetDefaultBool("gui.windows.notifications", true, NotInMan);

            // GUI - OSX Only
            SetDefaultBool("gui.osx.notifications", false, NotInMan);
            // SetDefaultBool("gui.osx.dock", false, NotInMan); // See this FAQ: https://airvpn.org/topic/13331-its-possible-to-hide-the-icon-in-dock-bar-under-os-x/
            SetDefaultBool("gui.osx.visible", false, NotInMan);
            SetDefault("gui.osx.style", "text", "light", NotInMan);
            SetDefaultBool("gui.osx.sysbar.show_info", false, NotInMan);
            SetDefaultBool("gui.osx.sysbar.show_speed", false, NotInMan);
            SetDefaultBool("gui.osx.sysbar.show_server", false, NotInMan);

            // TODO: we need to test params with space in different linux platform, with focus on escaping gksu/kdesu shell to obtain elevated privileges
            SetDefault("paramtest", "text", "", NotInMan, false);



            // Command-line only?
            Options["cli"].CommandLineOnly         = true;
            Options["help"].CommandLineOnly        = true;
            Options["help.format"].CommandLineOnly = true;

            // Internal only?
            Options["gui.window.main"].InternalOnly  = true;
            Options["gui.list.servers"].InternalOnly = true;
            Options["gui.list.areas"].InternalOnly   = true;
            Options["gui.list.logs"].InternalOnly    = true;

            // Don't clean with user Reset All
            Options["login"].DontUserReset    = true;
            Options["password"].DontUserReset = true;
            Options["remember"].DontUserReset = true;
            Options["key"].DontUserReset      = true;
        }