コード例 #1
0
        /// <summary>
        /// Reads the used log files in a given vpn config file
        /// </summary>
        /// <param name="config">the file to read</param>
        /// <returns>the log file, <code>null</code> if none is specified</returns>
        protected string getLogFile(string config)
        {
            ConfigParser parser = new ConfigParser(config);

            string[] logFiles = parser.GetValue("log");
            if (logFiles == null)
            {
                logFiles = parser.GetValue("log-append");
                if (logFiles == null)
                {
                    return(null);
                }
                else
                {
                    return(logFiles[1]);
                }
            }
            else
            {
                return(logFiles[1]);
            }
        }
コード例 #2
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>
        /// <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);
        }
コード例 #3
0
 /// <summary>
 /// Reads the used log files in a given vpn config file
 /// </summary>
 /// <param name="config">the file to read</param>
 /// <returns>the log file, <code>null</code> if none is specified</returns>
 protected string getLogFile(string config)
 {
     ConfigParser parser = new ConfigParser(config);
     string[] logFiles = parser.GetValue("log");
     if (logFiles == null)
     {
         logFiles = parser.GetValue("log-append");
         if (logFiles == null)
         {
             return null;
         }
         else
         {
             return logFiles[1];
         }
     }
     else
     {
         return logFiles[1];
     }
 }
コード例 #4
0
ファイル: UtilsHelper.cs プロジェクト: hapm/openvpn-manager
 /// <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>
 public static 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;
 }