Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new OVPN Object.
        /// Also set a LogEventDelegate so that the first log lines are reveived.
        /// </summary>
        /// <param name="bin">Path to openvpn binary</param>
        /// <param name="config">Path to configuration file</param>
        /// <param name="earlyLogEvent">Delegate to a event processor</param>
        /// <param name="earlyLogLevel">Log level</param>
        /// <param name="logfile">File to write OpenVPN log message to</param>
        /// <param name="smartCardSupport">Enable SmartCard support</param>
        /// <seealso cref="Connection.Logs"/>
        public UserSpaceConnection(string bin, string config, string logfile,
                                   EventHandler <LogEventArgs> earlyLogEvent, int earlyLogLevel, bool smartCardSupport)
        {
            if (bin == null || bin.Length == 0)
            {
                throw new ArgumentNullException(bin, "OpenVPN Binary is not valid/selected");
            }
            if (config == null || config.Length == 0)
            {
                throw new ArgumentNullException(config, "Config file is not valid/selected");
            }
            if (!new FileInfo(bin).Exists)
            {
                throw new FileNotFoundException(bin,
                                                "Binary \"" + bin + "\" does not exist");
            }
            if (!new FileInfo(config).Exists)
            {
                throw new FileNotFoundException(config,
                                                "Config file \"" + config + "\" does not exist");
            }

            this.Init("127.0.0.1", 11195 + obj_count++, earlyLogEvent, earlyLogLevel, true);
            m_ovpnService = new UserSpaceService(bin, config,
                                                 Path.GetDirectoryName(config), Logs, base.Host, base.Port,
                                                 logfile, smartCardSupport);

            m_ovpnService.serviceExited += new EventHandler(m_ovpnService_serviceExited);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Dispose this object.
        /// </summary>
        /// <param name="disposing">true if called from Dispose(), false if called from destructor</param>
        private void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                base.Dispose();
                if (disposing)
                {
                    m_ovpnService.Dispose();
                }

                m_ovpnService = null;
                disposed      = true;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Dispose this object.
        /// </summary>
        /// <param name="disposing">true if called from Dispose(), false if called from destructor</param>
        private void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (m_deleteLogFile)
                {
                    File.Delete(m_logFile);
                }

                base.Dispose();
                if (disposing)
                {
                    m_ovpnService.Dispose();
                }

                m_ovpnService = null;
                disposed      = true;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new OVPN Object.
        /// Also set a LogEventDelegate so that the first log lines are reveived.
        /// </summary>
        /// <param name="bin">Path to openvpn binary</param>
        /// <param name="config">Path to configuration file</param>
        /// <param name="earlyLogEvent">Delegate to a event processor</param>
        /// <param name="earlyLogLevel">Log level</param>
        /// <param name="logfile">File to write OpenVPN log message to</param>
        /// <param name="smartCardSupport">Enable SmartCard support</param>
        /// <seealso cref="Connection.Logs"/>
        public UserSpaceConnection(string bin, string config, string logfile,
            EventHandler<LogEventArgs> earlyLogEvent, int earlyLogLevel, bool smartCardSupport)
        {
            if (bin == null || bin.Length == 0)
                throw new ArgumentNullException(bin, "OpenVPN Binary is not valid/selected");
            if (config == null || config.Length == 0)
                throw new ArgumentNullException(config, "Config file is not valid/selected");
            if (!new FileInfo(bin).Exists)
                throw new FileNotFoundException(bin,
                    "Binary \"" + bin + "\" does not exist");
            if (!new FileInfo(config).Exists)
                throw new FileNotFoundException(config,
                    "Config file \"" + config + "\" does not exist");

            this.Init("127.0.0.1", 11195 + obj_count++, earlyLogEvent, earlyLogLevel, true);
            m_ovpnService = new UserSpaceService(bin, config,
                Path.GetDirectoryName(config), Logs, base.Host, base.Port,
                logfile, smartCardSupport);

            m_ovpnService.serviceExited += new EventHandler(m_ovpnService_serviceExited);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Dispose this object.
        /// </summary>
        /// <param name="disposing">true if called from Dispose(), false if called from destructor</param>
        private void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (m_deleteLogFile)
                {
                    File.Delete(m_logFile);
                }

                base.Dispose();
                if (disposing)
                {
                    m_ovpnService.Dispose();
                }

                m_ovpnService = null;
                disposed = true;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Dispose this object.
        /// </summary>
        /// <param name="disposing">true if called from Dispose(), false if called from destructor</param>
        private void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                base.Dispose();
                if (disposing)
                {
                    m_ovpnService.Dispose();
                }

                m_ovpnService = null;
                disposed = true;
            }
        }