Exemple #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>
        /// <seealso cref="OVPNConnection.logs"/>
        public OVPNUserConnection(string bin, string config, string logfile,
                                  OVPNLogManager.LogEventDelegate earlyLogEvent, int earlyLogLevel) :
            base("127.0.0.1", 11195 + obj_count++, earlyLogEvent, earlyLogLevel)
        {
            if (bin == null)
            {
                throw new ArgumentNullException("Binary is null");
            }
            if (config == null)
            {
                throw new ArgumentNullException("Config file is null");
            }
            if (!new FileInfo(bin).Exists)
            {
                throw new FileNotFoundException("Binary \"" + bin + "\" does not exist");
            }
            if (!new FileInfo(config).Exists)
            {
                throw new FileNotFoundException("Config file \"" + config + "\" does not exist");
            }

            m_ovpnService = new OVPNService(bin, config,
                                            Path.GetDirectoryName(config), logs, base.host, base.port, logfile);

            m_ovpnService.serviceExited += new EventHandler(m_ovpnService_serviceExited);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new OVPN Object.
        /// </summary>
        /// <param name="host">Host to connect to which holds the management interface</param>
        /// <param name="port">Port to connect to</param>
        /// <param name="earlyLogEvent">Delegate to a event processor</param>
        /// <param name="earlyLogLevel">Log level</param>
        /// <seealso cref="logs"/>
        public OVPNConnection(string host, int port, OVPNLogManager.LogEventDelegate earlyLogEvent, int earlyLogLevel)
        {
            m_host = host;
            m_port = port;

            m_logs            = new OVPNLogManager(this);
            m_logs.debugLevel = earlyLogLevel;
            if (earlyLogEvent != null)
            {
                m_logs.LogEvent += earlyLogEvent;
            }

            m_ovpnMLogic = new OVPNManagementLogic(this, host, port, m_logs);
            changeState(OVPNState.STOPPED);
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new OVPN Object.
        /// Also set a LogEventDelegate so that the first log lines are reveived.
        /// </summary>
        /// <param name="config">Path to configuration file</param>
        /// <param name="earlyLogEvent">Delegate to a event processor</param>
        /// <param name="earlyLogLevel">Log level</param>
        /// <seealso cref="OVPNConnection.logs"/>
        public OVPNServiceConnection(string config,
                                     OVPNLogManager.LogEventDelegate earlyLogEvent, int earlyLogLevel)
            : base(earlyLogEvent, earlyLogLevel)
        {
            if (config == null)
            {
                throw new ArgumentNullException("Config file is null");
            }
            if (!new FileInfo(config).Exists)
            {
                throw new FileNotFoundException("Config file \"" + config + "\" does not exist");
            }

            OVPNConfigFile cf = new OVPNConfigFile(config);


            //management 127.0.0.1 11194
            foreach (string directive in new String[] {
                "management-query-passwords", "management-hold",
                "management-signal", "management-forget-disconnect",
                "pkcs11-id-management", "management"
            })
            {
                if (!cf.exists(directive))
                {
                    throw new ArgumentException("The directive '" + directive
                                                + "' is needed in '" + config + "'");
                }
            }

            int port;

            string[] args = cf.get("management");
            if (args.GetUpperBound(0) != 2)
            {
                throw new ArgumentException("The directive 'management'"
                                            + " is invalid in '" + config + "'");
            }

            if (!int.TryParse(args[2], out port))
            {
                throw new ArgumentException("The port '" + args[0]
                                            + "' is invalid in '" + config + "'");
            }

            this.port = port;
            this.host = args[1];
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new OVPN Object.
 /// </summary>
 /// <param name="earlyLogEvent">Delegate to a event processor</param>
 /// <param name="earlyLogLevel">Log level</param>
 /// <seealso cref="logs"/>
 public OVPNConnection(OVPNLogManager.LogEventDelegate earlyLogEvent, int earlyLogLevel)
     : this("127.0.0.1", 11194, earlyLogEvent, earlyLogLevel)
 {
 }