public static bool Connect2Relayer(Tunnel tunnel)
        {
            bool result = false;

            if (tunnel != null)
            {
                Socket     socket2Server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                IPEndPoint ipeOfServer   = Conf.GetRemoteIPEndPoint();
                try
                {
                    socket2Server.Connect(ipeOfServer);
                }
                catch { socket2Server = null; }
                tunnel.SocketR  = socket2Server;
                tunnel.EncryptR = false;
                if (CheckVersion(tunnel))
                {
                    tunnel.EncryptR = true;
                    result          = CheckUser(tunnel);
                }
            }
            return(result);
        }
        private static void CheckConfig(string confPath)
        {
            if (!File.Exists(confPath))
            {
                Console.WriteLine("error:\tconfig file not found: -> {0}", confPath);
                return;
            }
            Conf.Init(confPath);

            if (!Conf.allConf.ContainsKey("listen"))
            {
                Console.WriteLine("error:\tno listen");
                return;
            }
            else
            {
                string[] listen = Conf.allConf["listen"][0].Split(':');
                if (!IPAddress.TryParse(listen[0], out IPAddress ipa))
                {
                    Console.WriteLine("error:\tip for listen is invalid ip address");
                    return;
                }
                if (listen.Length >= 2)
                {
                    if (!int.TryParse(listen[1], out int port))
                    {
                        Console.WriteLine("error:\tport for listen is not an integer");
                        return;
                    }
                }
            }

            if (!Conf.allConf.ContainsKey("relayer"))
            {
                if ((Conf.allConf.ContainsKey("http") && Conf.allConf["http"][0] == "on") ||
                    (Conf.allConf.ContainsKey("socks") && Conf.allConf["socks"][0] == "on"))
                {
                    Console.WriteLine("error:\tno relayer for http or socks");
                    return;
                }
            }
            else
            {
                string[] relayer = Conf.allConf["relayer"][0].Split(':');
                if (!IPAddress.TryParse(relayer[0], out IPAddress ipa))
                {
                    Console.WriteLine("error:\tip for relayer is invalid ip address");
                    return;
                }
                if (relayer.Length >= 2)
                {
                    if (!int.TryParse(relayer[1], out int port))
                    {
                        Console.WriteLine("error:\tport for relayer is not an integer");
                        return;
                    }
                }
            }

            if (!Conf.allConf.ContainsKey("config-dir"))
            {
                Console.WriteLine("error:\tno config-dir");
                return;
            }

            if (Conf.allConf.ContainsKey("user-check") &&
                Conf.allConf["user-check"][0] == "on")
            {
                if (EagleTunnelUser.users.Count == 0)
                {
                    Console.WriteLine("error:\tuser-check is on, but there is no user");
                }
            }

            Console.WriteLine("finished:\tno error!");
        }
Example #3
0
 public void Close()
 {
     Conf.Close();
 }