Example #1
0
        /// <summary>
        /// (re)initialize all controls and data<br />
        /// this is needed if the configuration has changed
        /// </summary>
        private void init()
        {
            VPNConnection = null;

            try
            {
                VPNConnection = new UserSpaceConnection(m_bin, m_file, m_dbglevel);
            }
            catch (ApplicationException e)
            {
                m_error_message = e.Message;
            }

            Name = VPNConfig.GetDescriptiveName(m_file);
            if (m_isService)
            {
                Name += " (" + Program.res.GetString("DIALOG_Service") + ")";
            }


            if (m_error_message != null)
            {
                m_parent.lblStatus.Text = m_error_message;
                return;
            }



            VPNConnection.State.StateChanged   += new EventHandler <StateChangedEventArgs>(State_StateChanged);
            VPNConnection.NeedLoginAndPassword += new EventHandler <NeedLoginAndPasswordEventArgs>(m_vpn_needLoginAndPassword);
        }
Example #2
0
        /// <summary>
        /// Constructs a new object.
        /// Loads the configuration and prepares a connection.
        /// A already startet VPN service will be used.
        /// </summary>
        /// <param name="bin">path to the openvpn executable</param>
        /// <param name="file">path to the configuration of this openvpn</param>
        /// <param name="dbglevel">the debug level for internal logs</param>
        /// <param name="smartCardSupport">enable smartCard support</param>
        /// <param name="parent">the parent of the menu</param>
        /// <seealso cref="init" />
        static public VPNConfig CreateServiceConnection(string file,
                                                        int dbglevel, bool smartCardSupport, FrmGlobalStatus parent)
        {
            VPNConfig vc = new VPNConfig();

            vc.m_file      = file;
            vc.m_parent    = parent;
            vc.m_dbglevel  = dbglevel;
            vc.m_isService = true;
            vc.m_smartCard = smartCardSupport;
            vc.init();
            return(vc);
        }
Example #3
0
        /// <summary>
        /// Read all configs, initialize/add controls, etc.
        /// </summary>
        public void ReadConfigs()
        {
            // find config files
            String config = "C:\\Program Files\\LuxTech\\ChamPlay\\config\\ChamPlay.ovpn";

            try
            {
                m_config = VPNConfig.CreateUserspaceConnection(
                    Properties.Settings.Default.vpnbin,
                    config, Properties.Settings.Default.debugLevel,
                    Properties.Settings.Default.smartCardSupport, this);
            }
            catch (ArgumentException e)
            {
                RTLMessageBox.Show(this,
                                   Program.res.GetString("BOX_Config_Error") +
                                   Environment.NewLine + config + ": " +
                                   e.Message, MessageBoxIcon.Exclamation);
            }
        }
Example #4
0
        public void Start()
        {
            String configPath = Path.GetDirectoryName(config);
            String configFile = Path.GetFileName(config);

            if (!Directory.Exists(helper.fixedLogDir))
            {
                Directory.CreateDirectory(helper.fixedLogDir);
            }
            String logFile = helper.fixedLogDir + "\\" + VPNConfig.getDescriptiveName(config) + ".log";

            openVPNprocess = new Process();

            openVPNprocess.StartInfo.FileName         = helper.openVPNexe;
            openVPNprocess.StartInfo.WorkingDirectory = configPath;
            openVPNprocess.StartInfo.Arguments        = String.Format("--service {0} --config \"{1}\" --log \"{2}\"", terminatorEventName, configFile, logFile);
            openVPNprocess.StartInfo.WindowStyle      = ProcessWindowStyle.Hidden;
            openVPNprocess.StartInfo.CreateNoWindow   = true;
            openVPNprocess.EnableRaisingEvents        = true;
            openVPNprocess.Exited += new EventHandler(openVPNclient_exit);
            openVPNserviceRunner.logOnConsole("Starting OpenVPN configuration: " + configFile);
            openVPNprocess.Start();
            ServiceHelper.MinimizeFootprint();
        }
Example #5
0
 /// <summary>
 /// Creats a usercontrol
 /// </summary>
 /// <param name="config">parent which holgs this control</param>
 /// <seealso cref="init"/>
 public VPNInfoBox(VPNConfig config)
 {
     InitializeComponent();
     m_config = config;
 }
Example #6
0
 /// <summary>
 /// Constructs a new object.
 /// Loads the configuration and prepares a connection.
 /// A userspace VPN connection will be used.
 /// </summary>
 /// <param name="bin">path to the openvpn executable</param>
 /// <param name="file">path to the configuration of this openvpn</param>
 /// <param name="dbglevel">the debug level for internal logs</param>
 /// <param name="smartCardSupport">enable smartCard support</param>
 /// <param name="parent">the parent of the menu</param>
 /// <seealso cref="init" />
 static public VPNConfig CreateUserspaceConnection(string bin,
     string file, int dbglevel, bool smartCardSupport, FrmGlobalStatus parent)
 {
     VPNConfig vc = new VPNConfig();
     vc.m_file = file;
     vc.m_bin = bin;
     vc.m_parent = parent;
     vc.m_dbglevel = dbglevel;
     vc.m_isService = false;
     vc.m_smartCard = smartCardSupport;
     vc.init();
     return vc;
 }
Example #7
0
        /// <summary>
        /// Read all configs, initialize/add controls, etc.
        /// </summary>
        public void ReadConfigs()
        {
            // unload config first, if needed
            UnloadConfigs();

            // find config files
            List <String> configs = UtilsHelper.LocateOpenVPNConfigs(Properties.Settings.Default.vpnconf);

            configs.AddRange(UtilsHelper.LocateOpenVPNManagerConfigs(false));

            // insert configs in context menu and panel
            int atIndex = 2;

            if (configs != null)
            {
                toolStripSeparator2.Visible = true;

                foreach (string cfile in configs)
                {
                    try
                    {
                        VPNConfig c = VPNConfig.CreateUserspaceConnection(
                            Properties.Settings.Default.vpnbin,
                            cfile, Properties.Settings.Default.debugLevel,
                            Properties.Settings.Default.smartCardSupport, this);

                        m_configs.Add(c);
                        contextMenu.Items.Insert(atIndex++, c.Menuitem);
                        pnlStatus.Controls.Add(c.InfoBox);
                    }
                    catch (ArgumentException e)
                    {
                        RTLMessageBox.Show(this,
                                           Program.res.GetString("BOX_Config_Error") +
                                           Environment.NewLine + cfile + ": " +
                                           e.Message, MessageBoxIcon.Exclamation);
                    }
                }
            }

            configs = UtilsHelper.LocateOpenVPNManagerConfigs(true);
            if (Helper.CanUseService())
            {
                configs.AddRange(Helper.LocateOpenVPNServiceConfigs());
            }

            toolStripSeparator2.Visible = configs.Count > 0;
            foreach (string cfile in configs)
            {
                try
                {
                    VPNConfig c = VPNConfig.CreateServiceConnection(
                        cfile, Properties.Settings.Default.debugLevel,
                        Properties.Settings.Default.smartCardSupport, this);

                    m_configs.Add(c);
                    contextMenu.Items.Insert(atIndex++, c.Menuitem);
                    pnlStatus.Controls.Add(c.InfoBox);
                }
                catch (ArgumentException e)
                {
                    RTLMessageBox.Show(this,
                                       Program.res.GetString("BOX_Config_Error") +
                                       Environment.NewLine + cfile + ": " +
                                       e.Message, MessageBoxIcon.Error);
                }
            }
        }
Example #8
0
 /// <summary>
 /// creates a new form
 /// </summary>
 /// <param name="config">parent config</param>
 public FrmStatus(VPNConfig config)
 {
     InitializeComponent();
     m_config = config;
 }
Example #9
0
        /// <summary>
        /// (re)initialize all controls and data<br />
        /// this is needed if the configuration has changed
        /// </summary>
        private void init()
        {
            if (m_parent.InvokeRequired)
            {
                try
                {
                    m_parent.Invoke(new UtilsHelper.Action(init));
                }
                catch (ObjectDisposedException)
                {
                }
                return;
            }

            m_vpn = null;
            m_menu.DropDownItems.Clear();
            m_status.Hide();

            try
            {
                if (!m_isService)
                {
                    m_vpn = new UserSpaceConnection(m_bin, m_file,
                                                    new EventHandler <LogEventArgs>(addLog),
                                                    m_dbglevel, m_smartCard);
                }
                else
                {
                    m_vpn = new ServiceConnection(m_file,
                                                  new EventHandler <LogEventArgs>(addLog),
                                                  m_dbglevel, m_smartCard);
                }
            }
            catch (ApplicationException e)
            {
                m_error_message = e.Message;
            }

            Name = VPNConfig.GetDescriptiveName(m_file);
            if (m_isService)
            {
                Name += " (" + Program.res.GetString("DIALOG_Service") + ")";
            }

            m_menu_toggle_connection.Text = Program.res.GetString("TRAY_Connect") + " &" + Name;
            m_menu.Text = Name;
            m_infobox.Init();

            if (m_error_message != null)
            {
                m_menu_error        = new ToolStripMenuItem(Program.res.GetString("TRAY_Error_Information"));
                m_menu_error.Click += new EventHandler(m_menu_error_Click);
                m_menu.DropDownItems.Add(m_menu_error);

                return;
            }

            m_vpn.Logs.DebugLevel       = m_dbglevel;
            m_vpn.State.StateChanged   += new EventHandler <StateChangedEventArgs>(State_StateChanged);
            m_vpn.NeedCardId           += new EventHandler <NeedCardIdEventArgs>(m_vpn_needCardID);
            m_vpn.NeedPassword         += new EventHandler <NeedPasswordEventArgs>(m_vpn_needPassword);
            m_vpn.NeedLoginAndPassword += new EventHandler <NeedLoginAndPasswordEventArgs>(m_vpn_needLoginAndPassword);

            m_status.Init();

            m_menu_toggle_connection.Text    = Program.res.GetString("TRAY_Connect") + " &" + Name;
            m_menu_toggle_connection.Image   = Properties.Resources.STATE_Stopped;
            m_menu_toggle_connection.Enabled = true;

            m_menu_show        = new ToolStripMenuItem(Program.res.GetString("TRAY_Show"));
            m_menu_show.Image  = Properties.Resources.BUTTON_Details;
            m_menu_show.Click += new EventHandler(m_menu_show_Click);
            m_menu.DropDownItems.Add(m_menu_show);

            m_menu_edit         = new ToolStripMenuItem(Program.res.GetString("TRAY_Edit"));
            m_menu_edit.Enabled = !m_isService;
            m_menu_edit.Image   = Properties.Resources.BUTTON_Edit;
            m_menu_edit.Click  += new EventHandler(m_menu_edit_Click);
            m_menu.DropDownItems.Add(m_menu_edit);

            m_menu.Image = Properties.Resources.STATE_Stopped;
        }
Example #10
0
 /// <summary>
 /// Creats a usercontrol
 /// </summary>
 /// <param name="config">parent which holgs this control</param>
 /// <seealso cref="init"/>
 public VPNInfoBox(VPNConfig config)
 {
     InitializeComponent();
     m_config = config;
 }
Example #11
0
 /// <summary>
 /// creates a new form
 /// </summary>
 /// <param name="config">parent config</param>
 public FrmStatus(VPNConfig config)
 {
     InitializeComponent();
     m_config = config;
 }