Ejemplo n.º 1
0
        public static void Init(string confPath = "/etc/eagle-tunnel.conf")
        {
            allConf = new Dictionary <string, List <string> > (StringComparer.OrdinalIgnoreCase);
            ReadAll(confPath);

            if (allConf.ContainsKey("user-conf"))
            {
                Users =
                    new Dictionary <string, EagleTunnelUser> ();
                ImportUsers();
                Console.WriteLine("find user(s): {0}", Users.Count);
            }

            LocalUser = null;
            if (allConf.ContainsKey("user"))
            {
                if (EagleTunnelUser.TryParse(allConf["user"][0], out EagleTunnelUser user))
                {
                    LocalUser = user;
                }
            }
            if (LocalUser != null)
            {
                Console.WriteLine("User: {0}", LocalUser.ID);
            }

            maxClientsCount = 200;
            if (allConf.ContainsKey("worker"))
            {
                if (int.TryParse(allConf["worker"][0], out int workerCount))
                {
                    maxClientsCount = workerCount;
                }
            }
            Console.WriteLine("worker: {0}", maxClientsCount);

            remoteAddresses = null;
            try {
                List <string> remoteAddressStrs = Conf.allConf["relayer"];
                remoteAddresses = CreateEndPoints(remoteAddressStrs);
            } catch (KeyNotFoundException) {
                Console.WriteLine("`Relayer` not found.");
            }
            if (remoteAddresses != null)
            {
                Console.WriteLine("Count of `Relayer`: {0}", remoteAddresses.Length);
            }
            localAddresses = null;
            try {
                List <string> localAddressStrs = Conf.allConf["listen"];
                localAddresses = CreateEndPoints(localAddressStrs);
                lockOfIndex    = new object();
            } catch (KeyNotFoundException) {
                Console.WriteLine("`Listen` not found");
            }

            if (allConf.ContainsKey("socks"))
            {
                if (allConf["socks"][0] == "on")
                {
                    EnableSOCKS = true;
                }
            }
            Console.WriteLine("SOCKS Switch: {0}", EnableSOCKS.ToString());

            if (allConf.ContainsKey("http"))
            {
                if (allConf["http"][0] == "on")
                {
                    EnableHTTP = true;
                }
            }
            Console.WriteLine("HTTP Switch: {0}", EnableHTTP.ToString());

            if (allConf.ContainsKey("eagle tunnel"))
            {
                if (allConf["eagle tunnel"][0] == "on")
                {
                    EnableEagleTunnel = true;
                }
            }
            Console.WriteLine("Eagle Tunnel Switch: {0}", EnableEagleTunnel.ToString());
        }
Ejemplo n.º 2
0
        public static void Init(string confPath)
        {
            allConf      = new ConcurrentDictionary <string, List <string> > (StringComparer.OrdinalIgnoreCase);
            confFilePath = confPath;
            ReadAll();

            ImportUsers();
            Console.WriteLine("find user(s): {0}", EagleTunnelUser.users.Count);

            encryptionKey = 0x22;
            if (allConf.ContainsKey("data-key"))
            {
                if (byte.TryParse(allConf["data-key"][0], out byte tmpByte))
                {
                    encryptionKey = tmpByte;
                }
            }

            if (allConf.ContainsKey("user"))
            {
                if (EagleTunnelUser.TryParse(allConf["user"][0], out EagleTunnelUser user, true))
                {
                    localUser = user;
                }
            }
            if (LocalUser != null)
            {
                Console.WriteLine("User: {0}", LocalUser.ID);
            }

            PipeTimeOut = 0;
            if (Conf.allConf.ContainsKey("timeout"))
            {
                if (int.TryParse(Conf.allConf["timeout"][0], out int timeout))
                {
                    PipeTimeOut = timeout;
                }
            }
            Console.WriteLine("TimeOut(ms): {0} (0 means infinite timeout period.)", PipeTimeOut);

            maxClientsCount = 500;
            if (allConf.ContainsKey("worker"))
            {
                if (int.TryParse(allConf["worker"][0], out int workerCount))
                {
                    maxClientsCount = workerCount;
                }
            }
            Console.WriteLine("worker: {0}", maxClientsCount);

            try
            {
                List <string> remoteAddressStrs = Conf.allConf["relayer"];
                remoteAddresses = CreateEndPoints(remoteAddressStrs);
            }
            catch (KeyNotFoundException)
            {
                Console.WriteLine("Warning: Relayer not found.");
            }
            if (RemoteAddresses != null)
            {
                Console.WriteLine("Count of Relayer: {0}", RemoteAddresses.Length);
            }

            try
            {
                List <string> localAddressStrs = Conf.allConf["listen"];
                localAddresses = CreateEndPoints(localAddressStrs);
            }
            catch (KeyNotFoundException)
            {
                Console.WriteLine("Warning: Listen not found");
            }

            if (allConf.ContainsKey("socks"))
            {
                if (allConf["socks"][0] == "on")
                {
                    enableSOCKS = true;
                }
            }
            Console.WriteLine("SOCKS Switch: {0}", EnableSOCKS.ToString());

            if (allConf.ContainsKey("http"))
            {
                if (allConf["http"][0] == "on")
                {
                    enableHTTP = true;
                }
            }
            Console.WriteLine("HTTP Switch: {0}", EnableHTTP.ToString());

            if (allConf.ContainsKey("et"))
            {
                if (allConf["et"][0] == "on")
                {
                    enableEagleTunnel = true;
                }
            }
            Console.WriteLine("Eagle Tunnel Switch: {0}", EnableEagleTunnel.ToString());

            if (allConf.ContainsKey("proxy-status"))
            {
                proxyStatus = (ProxyStatus)Enum.Parse(typeof(Conf.ProxyStatus),
                                                      allConf["proxy-status"][0].ToUpper());
            }
            else
            {
                proxyStatus = ProxyStatus.ENABLE; // default enable proxy
            }
            Console.WriteLine("Proxy Status: {0}", proxyStatus.ToString());
            ImportList("whitelist_domain.txt", out whitelist_domain);
            ImportList("whitelist_ip.txt", out whitelist_ip);
            ImportList("blacklist_ip.txt", out blacklist_ip);
            ImportHosts(out hosts);
        }