Beispiel #1
0
        /// <summary>
        /// notepad exited <br />
        /// reload configuration
        /// </summary>
        /// <param name="sender">ignored</param>
        /// <param name="e">ignored</param>
        private void p_Exited(object sender, EventArgs e)
        {
            // was a connection established?
            bool wasConnected        = false;
            VPNConnectionState state = m_vpn.State.CreateSnapshot().ConnectionState;

            if (m_vpn != null)
            {
                wasConnected = state == VPNConnectionState.Initializing ||
                               state == VPNConnectionState.Running;
            }

            // close the connection if needed, reload the configuration
            Disconnect();
            init();

            // reconnect, if the user wants it
            if (wasConnected && m_error_message == null)
            {
                if (RTLMessageBox.Show(m_parent,
                                       ProgramVPN.res.GetString("BOX_Reconnect"),
                                       MessageBoxButtons.YesNoCancel,
                                       MessageBoxDefaultButton.Button1,
                                       MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Connect();
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Show error detail in a message box
 /// </summary>
 public void ShowErrors()
 {
     RTLMessageBox.Show(m_parent,
                        ProgramVPN.res.GetString("BOX_Error_Information") +
                        Environment.NewLine + m_error_message,
                        MessageBoxIcon.Error);
 }
Beispiel #3
0
        static void ProgramVPNInit(string[] args)
        {
            try
            {
                List <string> arguments = new List <string>(args);

                Microsoft.Win32.SystemEvents.PowerModeChanged +=
                    new Microsoft.Win32.PowerModeChangedEventHandler(
                        SystemEvents_PowerModeChanged);

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                if (CommandLineArgumentsContain(arguments, "INSTALL-AUTOSTART"))
                {
                    Helper.InstallAutostart();
                    return;
                }
                else if (CommandLineArgumentsContain(arguments, "REMOVE-AUTOSTART"))
                {
                    Helper.RemoveAutostart(); // Remove autostart, quit (for setup, e.g.)
                    return;
                }
                else if (CommandLineArgumentsContain(arguments, "?") || CommandLineArgumentsContain(arguments, "HELP") || CommandLineArgumentsContain(arguments, "H"))
                {
                    RTLMessageBox.Show(res.GetString("ARGS_Help"), // Show help
                                       MessageBoxIcon.Information);
                    return;
                }
                Mutex appSingleton = new Mutex(false, Application.ProductName + ".SingleInstance");
                if (appSingleton.WaitOne(0, false))
                {
                    //m_mainform = new FrmGlobalStatus(arguments.ToArray());
                    //Application.Run(m_mainform);
                }
                else
                {
                    if (arguments.Count > 0)
                    {
                        SimpleComm sc = new SimpleComm(4911);
                        if (!sc.client(arguments.ToArray()))
                        {
                            RTLMessageBox.Show(res.GetString("ARGS_Error"),
                                               MessageBoxIcon.Error);
                        }
                    }
                }

                appSingleton.Close();
            }
            catch (Exception ex)
            {
                //In case of 'something terible' dont disappear without a message.
                MessageBox.Show(ex.ToString());
            }
        }
Beispiel #4
0
        /// <summary>
        /// OVPN requests a SmardCard id <br />
        /// generates and shows a form, answers via e
        /// </summary>
        /// <param name="sender">OVPN which requests the id</param>
        /// <param name="e">Information, what was found</param>
        private void m_vpn_needCardID(object sender, NeedCardIdEventArgs e)
        {
            // if there is no id
            if (e.CardDetails.Count == 0)
            {
                if (RTLMessageBox.Show(m_parent,
                                       ProgramVPN.res.GetString("BOX_NoKey"),
                                       MessageBoxButtons.RetryCancel,
                                       MessageBoxDefaultButton.Button1,
                                       MessageBoxIcon.Warning) == DialogResult.Retry)
                {
                    e.SelectedId = NeedCardIdEventArgs.Retry;
                }
                else
                {
                    e.SelectedId = NeedCardIdEventArgs.None;
                    m_disconnectTimer.Start();
                }
            }

            // if there is only one id, use it
            else if (e.CardDetails.Count == 1)
            {
                e.SelectedId = e.CardDetails[0].Number;
            }
            else
            {
                // request key
                m_frmkey = new ViewVPNSelectPKCS11Key();
                int res = m_frmkey.SelectKey(e.CardDetails, this.Name);
                if (res == -1)
                {
                    e.SelectedId = NeedCardIdEventArgs.None;
                    if (VPNConnection.State.CreateSnapshot().ConnectionState
                        == VPNConnectionState.Initializing)
                    {
                        m_disconnectTimer.Start();
                    }
                }
                else if (res == -2)
                {
                    e.SelectedId = NeedCardIdEventArgs.Retry;
                }
                else
                {
                    e.SelectedId = res;
                }
                m_frmkey = null;
            }
        }
Beispiel #5
0
 /// <summary>
 /// connect to the VPN <br />
 /// show message box on error
 /// </summary>
 public void Connect()
 {
     try
     {
         m_status.ShowTemporary();
         m_vpn.Connect();
     }
     catch (InvalidOperationException e)
     {
         /*
          * TODO it would be nicer if the message would hold less detail
          * about the problem
          */
         RTLMessageBox.Show(m_parent,
                            ProgramVPN.res.GetString("BOX_Error_Connect") +
                            Environment.NewLine + e.Message,
                            MessageBoxIcon.Error);
     }
 }
Beispiel #6
0
        /// <summary>
        /// OVPN changes it status.
        /// Show or hide elements.
        /// </summary>
        /// <param name="sender">ignored</param>
        /// <param name="e">the new state</param>
        /// <seealso cref="stateChanged"/>
        void State_StateChanged(object sender, StateChangedEventArgs e)
        {
            try
            {
                if (m_parent.InvokeRequired)
                {
                    m_parent.BeginInvoke(
                        new EventHandler <StateChangedEventArgs>(
                            State_StateChanged), sender, e);
                    return;
                }
            }
            catch (ObjectDisposedException)
            {
                return;
            }

            switch (e.NewState.ConnectionState)
            {
            case VPNConnectionState.Initializing:
                m_menu_disconnect.Visible = true;
                m_menu_connect.Visible    = false;
                m_menu.Image = Properties.Resources.STATE_Initializing;
                break;

            case VPNConnectionState.Running:

                m_menu_disconnect.Visible = true;
                m_menu_connect.Visible    = false;
                m_menu.Image = Properties.Resources.STATE_Running;

                // show assigned ip if possible
                string text = ProgramVPN.res.GetString("STATE_Connected");
                if (m_vpn.IP != null)
                {
                    text += Environment.NewLine +
                            "IP: " + m_vpn.IP;
                }

                //m_parent.ShowPopup(Name, text);
                break;

            case VPNConnectionState.Stopped:
                m_menu_disconnect.Visible = false;
                m_menu_connect.Visible    = true;
                m_menu.Image = Properties.Resources.STATE_Stopped;
                break;

            case VPNConnectionState.Stopping:
                m_menu_disconnect.Visible = false;
                m_menu_connect.Visible    = false;
                m_menu.Image = Properties.Resources.STATE_Stopping;
                break;

            case VPNConnectionState.Error:
            default:
                m_menu_disconnect.Visible = false;
                m_menu_connect.Visible    = true;
                m_menu.Image = Properties.Resources.STATE_Error;

                if (m_vpn.LogFile != null)
                {
                    if (RTLMessageBox.Show(m_status,
                                           ProgramVPN.res.GetString("BOX_VPN_Error"),
                                           MessageBoxButtons.YesNo, MessageBoxDefaultButton.Button2,
                                           MessageBoxIcon.Error) == DialogResult.Yes)
                    {
                        ProcessStartInfo pi = new ProcessStartInfo();
                        pi.Arguments       = "\"" + m_vpn.LogFile + "\"";
                        pi.ErrorDialog     = true;
                        pi.FileName        = "notepad.exe";
                        pi.UseShellExecute = true;


                        Process.Start(pi);
                    }
                }
                else
                {
                    RTLMessageBox.Show(m_status,
                                       ProgramVPN.res.GetString("BOX_VPNS_Error"),
                                       MessageBoxButtons.OK, MessageBoxDefaultButton.Button2,
                                       MessageBoxIcon.Error);
                }
                break;
            }

            //m_parent.SetTrayIconAndPopupText();
        }