示例#1
0
        /// <summary>
        /// User clicks on "update".
        /// </summary>
        /// <param name="sender">ignored</param>
        /// <param name="e">ignored</param>
        private void btnUpdateCheck_Click(object sender, EventArgs e)
        {
            // check if an error is possible
            Update u = new Update(false, this);

            if (u.hadErrors)
            {
                return;
            }

            // update available?
            if (u.checkUpdate())
            {
                // open url, if the user wants
                if (RTLMessageBox.Show(this,
                                       Program.res.GetString("BOX_UpdateInformation")
                                       .Replace("%s", u.getVersion()),
                                       MessageBoxButtons.YesNoCancel,
                                       MessageBoxDefaultButton.Button1,
                                       MessageBoxIcon.Information)
                    == DialogResult.Yes)
                {
                    openUrl(u.getUpdateUrl());
                }
            }

            // no update found
            else
            {
                RTLMessageBox.Show(this,
                                   Program.res.GetString("BOX_UpdateNone"),
                                   MessageBoxIcon.Information);
            }
        }
示例#2
0
        /// <summary>
        /// refreshs the XML data, may reset hadErrors
        /// </summary>
        /// <param name="silence">don't show message boxes on error</param>
        public void refresh(bool silence)
        {
            XmlDocument doc;

            // TODO: Check what happens if we are not connected
            try
            {
                doc = new XmlDocument();
                doc.Load(XmlReader.Create("http://openvpn.jowisoftware.de/versions.xml"));
            }
            catch (WebException e)
            {
                if (!silence)
                {
                    RTLMessageBox.Show(m_parent, Program.res.GetString(
                                           "BOX_UpdateError") + ": " + e.Message,
                                       MessageBoxIcon.Error);
                }
                return;
            }
            catch (XmlException e)
            {
                if (!silence)
                {
                    RTLMessageBox.Show(m_parent, Program.res.GetString(
                                           "BOX_UpdateFormat") + ": " + e.Message,
                                       MessageBoxIcon.Error);
                }
                return;
            }

            n = doc.DocumentElement.SelectSingleNode("application[@name='OpenVPN Manager']");
        }
示例#3
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,
                                       Program.res.GetString("BOX_Reconnect"),
                                       MessageBoxButtons.YesNoCancel,
                                       MessageBoxDefaultButton.Button1,
                                       MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Connect();
                }
            }
        }
示例#4
0
 /// <summary>
 /// Show error detail in a message box
 /// </summary>
 public void ShowErrors()
 {
     RTLMessageBox.Show(m_parent,
                        Program.res.GetString("BOX_Error_Information") +
                        Environment.NewLine + m_error_message,
                        MessageBoxIcon.Error);
 }
示例#5
0
 private void WarnServiceChange(string oldBin, string p)
 {
     if (ServiceIsInstalled() && oldBin != p)
     {
         RTLMessageBox.Show(Program.res.GetString("BOX_UpdateService"),
                            MessageBoxIcon.Information);
     }
 }
示例#6
0
        /// <summary>
        /// Show settings, if wanted, detect defaults.
        /// </summary>
        /// <param name="Detect"></param>
        public void ShowSettings(bool detect)
        {
            String runningConnections = "";

            foreach (VPNConfig c in m_configs)
            {
                if (c.Running)
                {
                    runningConnections += "\r\n" + c.Name;
                }
            }
            if (runningConnections != "")
            {
                if (RTLMessageBox.Show(this,
                                       Program.res.GetString("BOX_Settings_Close") + "\r\n" + runningConnections,
                                       MessageBoxButtons.YesNo,
                                       MessageBoxDefaultButton.Button2,
                                       MessageBoxIcon.Exclamation) != DialogResult.Yes)
                {
                    return;
                }
            }

            // remember visible-state, hide everything, unload everything
            bool reShow = Visible;

            niIcon.Visible = false;
            Hide();
            if (Properties.Settings.Default.allowRemoteControl)
            {
                m_simpleComm.stopServer();
            }
            UnloadConfigs();

            // show settings, detect settings
            FrmSettings m_settingsDialog = new FrmSettings();

            if (detect)
            {
                m_settingsDialog.Detect();
            }

            m_settingsDialog.ShowDialog();

            // reread settings, show icon, show form if needed
            ReadConfigs();
            if (Properties.Settings.Default.allowRemoteControl)
            {
                m_simpleComm.startServer();
            }
            niIcon.Visible = true;

            if (reShow)
            {
                Show();
            }
        }
示例#7
0
        static void Main(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());
            }
        }
示例#8
0
 /// <summary>
 /// a listitem was been double clicked, show text in message box
 /// </summary>
 /// <param name="sender">ignored</param>
 /// <param name="e">ignored</param>
 private void lstLog_DoubleClick(object sender, EventArgs e)
 {
     // show the selected item
     if (lstLog.SelectedItem != null)
     {
         RTLMessageBox.Show(this,
                            ((ColoredListBoxItem)lstLog.SelectedItem).Text,
                            MessageBoxIcon.Information);
     }
 }
示例#9
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,
                                       Program.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 FrmSelectPKCS11Key();
                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;
            }
        }
 /// <summary>
 /// connect to the VPN <br />
 /// show message box on error
 /// </summary>
 public void Connect()
 {
     try
     {
         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,
                            Program.res.GetString("BOX_Error_Connect") +
                            Environment.NewLine + e.Message,
                            MessageBoxIcon.Error);
     }
 }
示例#11
0
        /*/// <summary>
         * /// returns the url to the update file itself
         * /// </summary>
         * /// <returns>the url to the update file itself</returns>
         * public string getDownloadFileUrl()
         * {
         *  if (n == null)
         *      return null;
         *
         *  string url;
         *
         *  try
         *  {
         *      url = n.SelectSingleNode("child::download").InnerText;
         *  }
         *  catch (NullReferenceException)
         *  {
         *      MessageBox.Show(Program.res.GetString("BOX_UpdateMissing"),
         *          "OpenVPN Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
         *      return null;
         *  }
         *
         *  return url;
         * }*/

        /// <summary>
        /// returns the version of the update
        /// </summary>
        /// <returns>version of the update</returns>
        public string getVersion()
        {
            if (n == null)
            {
                return(null);
            }

            try
            {
                return(n.SelectSingleNode("child::version").InnerText);
            }
            catch (NullReferenceException)
            {
                RTLMessageBox.Show(m_parent,
                                   Program.res.GetString("BOX_UpdateMissing"),
                                   MessageBoxIcon.Error);
                return(null);
            }
        }
示例#12
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);
            }
        }
示例#13
0
        /// <summary>
        /// returns the url to the update page
        /// </summary>
        /// <returns>the url to the update page</returns>
        public string getUpdateUrl()
        {
            if (n == null)
            {
                return(null);
            }

            string url;

            try
            {
                url = n.SelectSingleNode("child::url").InnerText;
            }
            catch (NullReferenceException)
            {
                RTLMessageBox.Show(m_parent,
                                   Program.res.GetString("BOX_UpdateMissing"),
                                   MessageBoxIcon.Error);
                return(null);
            }

            return(url);
        }
示例#14
0
        static void Main(string[] args)
        {
            bool noUserInteraction = false;//service process only

            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"))
                {
                    ServiceHelper.installService();
                    return;
                }
                if (CommandLineArgumentsContain(arguments, "UNINSTALL"))
                {
                    ServiceHelper.uninstallService();
                    return;
                }
                if (CommandLineArgumentsContain(arguments, "EXECUTESERVICE"))
                {   // EXECUTESERVICE is not to be used by the end-user but only for service installation run command
                    // this to be able to know it should start as a service.
                    noUserInteraction = true;
                    ServiceHelper.executeService();
                    return;
                }
                if (CommandLineArgumentsContain(arguments, "EXECUTESERVICEASCONSOLE"))
                {
                    ServiceHelper.executeServiceAsConsole();
                    return;
                }
                else 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)
            {
                if (noUserInteraction)
                {
                    string eventlogAppName = "OpenVPNManager";
                    if (!EventLog.SourceExists(eventlogAppName))
                    {
                        EventLog.CreateEventSource(eventlogAppName, "Application");
                    }
                    EventLog.WriteEntry(eventlogAppName, ex.ToString(), EventLogEntryType.Error, 0);
                }
                else
                {
                    //In case of 'something terible' dont disappear without a message.
                    MessageBox.Show(ex.ToString());
                }
            }
        }
示例#15
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);
                }
            }
        }
示例#16
0
        /// <summary>
        /// Executes the given commandline.
        /// </summary>
        /// <param name="commands">Array of commands</param>
        private void parseCommandLine(string[] commands)
        {
            List <string> args = new List <string>(commands);

            int    i     = 0;
            bool   found = false;
            string names;

            while (i < args.Count)
            {
                switch (args[i].ToUpperInvariant())
                {
                // -connect "vpn name"
                case "-CONNECT":
                    if (i == args.Count - 1)
                    {
                        RTLMessageBox.Show(this, String.Format(
                                               CultureInfo.InvariantCulture,
                                               Program.res.GetString(
                                                   "ARGS_Missing_Parameter"),
                                               args[i]), MessageBoxIcon.Error);
                        return;
                    }

                    found = false;
                    names = "";

                    foreach (VPNConfig c in m_configs)
                    {
                        names += c.Name + "\n";
                        if (c.Name.Equals(args[i + 1],
                                          StringComparison.OrdinalIgnoreCase))
                        {
                            c.Connect();
                            found = true;
                        }
                    }

                    if (!found)
                    {
                        RTLMessageBox.Show(this, String.Format(
                                               CultureInfo.InvariantCulture,
                                               Program.res.GetString(
                                                   "ARGS_Invalid_Parameter"),
                                               args[i], args[i + 1], names),
                                           MessageBoxIcon.Error);
                    }

                    ++i;
                    break;

                case "-DISCONNECT":
                    if (i == args.Count - 1)
                    {
                        RTLMessageBox.Show(this, String.Format(
                                               CultureInfo.InvariantCulture,
                                               Program.res.GetString(
                                                   "ARGS_Missing_Parameter"),
                                               args[i]), MessageBoxIcon.Error);
                        return;
                    }

                    found = false;
                    names = "";

                    foreach (VPNConfig c in m_configs)
                    {
                        names += c.Name + "\n";
                        if (c.Name.Equals(args[i + 1],
                                          StringComparison.OrdinalIgnoreCase))
                        {
                            c.Disconnect();
                            found = true;
                        }
                    }

                    if (!found)
                    {
                        RTLMessageBox.Show(this, String.Format(
                                               CultureInfo.InvariantCulture,
                                               Program.res.GetString(
                                                   "ARGS_Invalid_Parameter"),
                                               args[i], args[i + 1], names),
                                           MessageBoxIcon.Error);
                    }

                    ++i;

                    break;

                case "-QUIT":
                case "-EXIT":
                    m_quit = true;
                    this.Close();
                    break;

                default:
                    RTLMessageBox.Show(this, String.Format(
                                           CultureInfo.InvariantCulture,
                                           Program.res.GetString(
                                               "ARGS_Unknown_Parameter"),
                                           args[i]), MessageBoxIcon.Error);
                    break;
                }

                ++i;
            }
        }
示例#17
0
 private void llHowChange_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     RTLMessageBox.Show(this,
                        Program.res.GetString("BOX_Service_How_Change"),
                        MessageBoxIcon.Information);
 }
示例#18
0
 private void llWhy_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     RTLMessageBox.Show(this,
                        m_error, MessageBoxIcon.Information);
 }
示例#19
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_toggle_connection.Text    = Program.res.GetString("TRAY_Disconnect") + " &" + Name;
                m_menu_toggle_connection.Image   = Properties.Resources.STATE_Initializing;
                m_menu_toggle_connection.Enabled = true;

                m_menu.Image = Properties.Resources.STATE_Initializing;
                break;

            case VPNConnectionState.Running:
                m_menu_toggle_connection.Text    = Program.res.GetString("TRAY_Disconnect") + " &" + Name;
                m_menu_toggle_connection.Image   = Properties.Resources.STATE_Running;
                m_menu_toggle_connection.Enabled = true;

                m_menu.Image = Properties.Resources.STATE_Running;

                // show assigned ip if possible
                string text = Program.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_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.Image = Properties.Resources.STATE_Stopped;
                break;

            case VPNConnectionState.Stopping:
                m_menu_toggle_connection.Text    = Name + ": " + Program.res.GetString("STATE_Stopping");
                m_menu_toggle_connection.Image   = Properties.Resources.STATE_Stopping;
                m_menu_toggle_connection.Enabled = false;

                m_menu.Image = Properties.Resources.STATE_Stopping;
                break;

            case VPNConnectionState.Error:
            default:
                m_menu_toggle_connection.Text    = Program.res.GetString("TRAY_Connect") + " &" + Name;
                m_menu_toggle_connection.Image   = Properties.Resources.STATE_Error;
                m_menu_toggle_connection.Enabled = true;

                m_menu.Image = Properties.Resources.STATE_Error;

                if (m_vpn.LogFile != null)
                {
                    if (RTLMessageBox.Show(m_status,
                                           Program.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,
                                       Program.res.GetString("BOX_VPNS_Error"),
                                       MessageBoxButtons.OK, MessageBoxDefaultButton.Button2,
                                       MessageBoxIcon.Error);
                }
                break;
            }

            m_parent.SetTrayIconAndPopupText();
        }