/// <summary> /// Initializes a new OVPNCommunicator object. /// </summary> /// <param name="host">Host to connect to (127.0.0.1)</param> /// <param name="port">Port to connect to</param> /// <param name="logs">Log manager</param> /// <param name="ovpn">Parent object</param> public OVPNCommunicator(string host, int port, OVPNLogManager logs, OVPNConnection ovpn) { m_host = host; m_port = port; m_logs = logs; m_ovpn = ovpn; m_tcpC = new TcpClient(); }
/// <summary> /// Creates a new management parser. /// </summary> /// <param name="oc">reference to the network communicator</param> /// <param name="ol">reference to the management logic</param> /// <param name="logs">reference to the log interface</param> internal OVPNManagementParser(OVPNCommunicator oc, OVPNManagementLogic ol, OVPNLogManager logs) { // copy data m_logs = logs; m_ol = ol; // receive new data oc.gotLine += new OVPNCommunicator.GotLineEvent(oc_gotLine); }
/// <summary> /// Creates a new ManagementLogic object. /// </summary> /// <param name="ovpn">parent</param> /// <param name="host">host to connect to (e.g. 127.0.0.1)</param> /// <param name="port">port to connect to</param> /// <param name="logs">LogManager to write the logs to</param> public OVPNManagementLogic(OVPNConnection ovpn,string host, int port,OVPNLogManager logs) { m_ovpn = ovpn; m_logs = logs; m_releaselock = true; // initialize required components m_ovpnComm = new OVPNCommunicator(host,port,logs,ovpn); m_ovpnMParser = new OVPNManagementParser(m_ovpnComm,this,logs); m_pkcs11details = new List <PKCS11Detail>(); m_ovpnComm.connectionClosed += new System.EventHandler(m_ovpnComm_connectionClosed); }
/// <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); }
/// <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); }
/// <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]; }
/// <summary> /// Initialize a new OpenVPN service. /// </summary> /// <param name="binfile">path to openvpn</param> /// <param name="configfile">path to openvpn config</param> /// <param name="dir">directory where config lies</param> /// <param name="logs">provider to write logs to</param> /// <param name="host">The host to connect to (e.g. 127.0.0.1)</param> /// <param name="port">The port to connect to</param> /// <param name="logfile">file to write OpenVPN log to</param> public OVPNService(string binfile, string configfile, string dir, OVPNLogManager logs, string host, int port, string logfile) { m_objid = ++objcount; m_logs = logs; running = false; m_psi.FileName = binfile; m_psi.WorkingDirectory = dir; m_psi.WindowStyle = ProcessWindowStyle.Hidden; m_psi.UseShellExecute = true; m_psi.Verb = "runas"; m_psi.CreateNoWindow = true; m_psi.Arguments = "--log \"" + logfile + "\"" + " --config \"" + configfile + "\"" + " --management " + host + " " + port.ToString() + " --management-query-passwords" + " --management-hold" + " --management-signal" + " --management-forget-disconnect" + " --pkcs11-id-management"; }
/// <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); }
/// <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) { }
/// <summary> /// Creates a new ManagementLogic object. /// </summary> /// <param name="ovpn">parent</param> /// <param name="host">host to connect to (e.g. 127.0.0.1)</param> /// <param name="port">port to connect to</param> /// <param name="logs">LogManager to write the logs to</param> public OVPNManagementLogic(OVPNConnection ovpn, string host, int port, OVPNLogManager logs) { m_ovpn = ovpn; m_logs = logs; m_releaselock = true; // initialize required components m_ovpnComm = new OVPNCommunicator(host, port, logs, ovpn); m_ovpnMParser = new OVPNManagementParser(m_ovpnComm, this, logs); m_pkcs11details = new List<PKCS11Detail>(); m_ovpnComm.connectionClosed += new System.EventHandler(m_ovpnComm_connectionClosed); }