Ejemplo n.º 1
0
        public void InstallConfiguration(ConnectionDefinitionFile pConfigFile)
        {
            var fileName = Configuration.Configuration.Current.ConnecitonDataPath + "\\" + pConfigFile.ConnectionName +
                           ".openvpn";

            if (pConfigFile.AuthorityCert != null)
            {
                CertificateManager.Current.InstallCertificate(pConfigFile.AuthorityCert);
            }
            pConfigFile.SaveFile(fileName);
            var configuration = new OpenVPNConfiguration(_configs.Count, pConfigFile);

            configuration.Deleted += OnDeleted;
            _configs.Add(configuration);

            if (TapDeviceManager.GetTapDevices().ToArray().Length < _configs.Count)
            {
                TapDeviceManager.SetupTapDevice();
            }

            if (NewConfiguration != null)
            {
                NewConfiguration(configuration);
            }
        }
Ejemplo n.º 2
0
        private static void Main(string[] pArgs)
        {
            if (pArgs.Length == 0 || pArgs[0] == "--help" || pArgs[0] == "-h")
            {
                PrintHelp();
                return;
            }

            switch (pArgs[0])
            {
            case "--makefile":
                var output         = pArgs[1];
                var config         = pArgs[2];
                var ca             = pArgs[3];
                var name           = pArgs[4];
                var connectionFile = new ConnectionDefinitionFile
                {
                    ConfigurationData = File.ReadAllText(config),
                    AuthorityCertData = File.ReadAllBytes(ca),
                    ConnectionName    = name
                };
                connectionFile.SaveFile(output + ".connection");

                return;
            }

            ControllerPipeClient pipeClient;

            try
            {
                pipeClient = new ControllerPipeClient();
            }
            catch (Exception exception)
            {
                Console.WriteLine("An error has occured connecting to the OpenVPN UI Host service.");
                Console.WriteLine("Exception: " + exception.Message);
                return;
            }

            pipeClient.Initialized +=
                pMessage =>
            {
                switch (pArgs[0])
                {
                case "--list":
                    ListConnections(pipeClient);
                    return;

                //case "--start":
                //    var con = 0;
                //    if(pArgs.Length!=2 || !Int32.TryParse(pArgs[1],out con))
                //    {
                //        Console.WriteLine("SYNTAX: --start {connection number}");
                //        return;
                //    }

                //    if(con < pipeClient.ConnectionCount)
                //    {
                //        if(pipeClient[con].ConnectionStatus==ConnectionStatus.Disconnected)
                //        {

                //        } else
                //        {
                //            Console.WriteLine("{0} is already {1}.", pipeClient[con].Name, pipeClient[i].ConnectionStatus.ToString().ToLower());
                //        }
                //    }
                //    else
                //        Console.WriteLine("ERROR: Invalid connection number.");
                //    break;
                case "--stop":

                    if (pArgs.Length != 2 || !int.TryParse(pArgs[1], out var _))
                    {
                        Console.WriteLine("SYNTAX: --start {connection number}");
                        return;
                    }

                    if (0 < pipeClient.ConnectionCount)
                    {
                        if (pipeClient[0].ConnectionStatus == ConnectionStatus.Disconnected)
                        {
                        }
                        else
                        {
                            Console.WriteLine("{0} is already {1}.", pipeClient[0].Name,
                                              pipeClient[0].ConnectionStatus.ToString().ToLower());
                        }
                    }
                    else
                    {
                        Console.WriteLine("ERROR: Invalid connection number.");
                    }
                    break;
                }
            };
        }
Ejemplo n.º 3
0
        private static void Main(string[] pArgs)
        {
            if (pArgs.Length < 4)
            {
                Console.WriteLine("SYNTAX: MakeOpenVPNConfig [ovpn file] [ca cert] [display name] [output file]");
                Console.WriteLine();
                Console.WriteLine("For example:-");
                Console.WriteLine(@"MakeOpenVPNConfig c:\test\myvpn.ovpn c:\test\ca.crt ""My VPN"" myvpn.openvpn");
                return;
            }
            var configFileName = pArgs[0];
            var caFileName     = pArgs[1];
            var displayName    = pArgs[2];
            var outputName     = pArgs[3];

            if (!File.Exists(configFileName))
            {
                Console.WriteLine("ERROR: Configuration file does not exist");
            }
            if (!File.Exists(caFileName))
            {
                Console.WriteLine("ERROR: CA cert file does not exist");
            }
            if (!File.Exists(configFileName) || !File.Exists(caFileName))
            {
                return;
            }

            string configXml;

            byte[] caBytes;
            try
            {
                configXml = File.ReadAllText(configFileName);
            }
            catch (IOException)
            {
                Console.WriteLine("ERROR: Reading Config File");
                return;
            }

            try
            {
                caBytes = File.ReadAllBytes(caFileName);
            }
            catch (IOException)
            {
                Console.WriteLine("ERROR: Reading CA Cert File");
                return;
            }

            var file = new ConnectionDefinitionFile();

            file.AuthorityCertData = caBytes;
            file.ConfigurationData = configXml;
            file.ConnectionName    = displayName;
            try
            {
                file.SaveFile(outputName);
            }
            catch (IOException)
            {
                Console.WriteLine("ERROR: Error writing output file.");
            }
        }