/// <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> /// <param name="smartCardSupport">Enable SmartCard support</param> /// <seealso cref="Connection.Logs"/> public ServiceConnection(string config, EventHandler <LogEventArgs> earlyLogEvent, int earlyLogLevel, bool smartCardSupport) { if (config == null) { throw new ArgumentNullException(config, "Config file is null"); } if (!new FileInfo(config).Exists) { throw new FileNotFoundException(config, "Config file \"" + config + "\" does not exist"); } ConfigParser cf = new ConfigParser(config); //management 127.0.0.1 11194 foreach (var directive in UtilsHelper.managementConfigItems) { if (!cf.DirectiveExists(directive.name)) { throw new ArgumentException("The directive '" + directive.name + "' is needed in '" + config + "'"); } } if (smartCardSupport) { if (!cf.DirectiveExists("pkcs11-id-management")) { throw new ArgumentException( "The directive 'pkcs11-id-management' is needed in '" + config + "'"); } } int port; string[] args = cf.GetValue("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[2] + "' is invalid in '" + config + "'"); } m_logFile = getLogFile(config); this.Init(args[1], port, earlyLogEvent, earlyLogLevel, false); }
/// <summary> /// check if the configuration file is to be used with a management console /// </summary> /// <param name="config">the config filename</param> /// <returns>returns if the config file is to be used as as service</returns> static public bool IsConfigForService(string config) { // if only a single management configuration item is pressent still asume it is meant for use with the service. ConfigParser cf = new ConfigParser(config); foreach (var directive in managementConfigItems) { if (directive.serviceOnly) { if (cf.GetValue(directive.name) != null) { return(true); } } } //cf.Dispose(); return(false); }