private void VpnNotifyIconContextMenuStrip_Opening(object sender, CancelEventArgs e) { try { e.Cancel = false; if (useMainTrayIconForVPN == false) { vpnNotifyIcon.ContextMenuStrip.Items.Clear(); } else { //MainTrayIcon cleared and filled in BaseApplicationContext vpnNotifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator()); } List <ToolStripItem> subitems = new List <ToolStripItem>(); VpnConnUtils.MakeDefaultContextMenu(subitems); VpnConnUtils.MakeFavoriteContextMenu(subitems); VpnConnUtils.MakeContextMenuForAllBaseVPNServers(subitems); vpnNotifyIcon.ContextMenuStrip.Items.AddRange(subitems.ToArray()); } catch (Exception ex) { Log.ShowError(ex); } }
override public void InitApplication() { base.InitApplication(); VpnSelectorDm.MyLocalIP = BaseNetworkUtils.GetHostIp(); if ("127.0.0.1".Equals(VpnSelectorDm.MyLocalIP) == false) { VpnSelectorDm.MyMac = BaseNetworkUtils.GetMacByIP(VpnSelectorDm.MyLocalIP); VpnSelectorDm.DnsIP = BaseNetworkUtils.GetDnsAddressForIP(VpnSelectorDm.MyLocalIP); if (VpnSelectorDm.DnsIP != null) { VpnSelectorDm.DnsMac = BaseNetworkUtils.GetMacByIP(VpnSelectorDm.DnsIP); } } bool _isActiveConnectionPresent = VpnConnUtils.IsActiveConnectionPresent(); if (_isActiveConnectionPresent) { VpnConnUtils.CurrentVPNServer = JVPNServer.FindFromNames(VpnConnUtils.GetActiveConnectionsNames()); } Console.WriteLine("IP: " + VpnSelectorDm.MyLocalIP); Console.WriteLine("MAC: " + VpnSelectorDm.MyMac); Console.WriteLine("DNS: " + VpnSelectorDm.DnsIP); Console.WriteLine("DNS MAC: " + VpnSelectorDm.DnsMac); Console.WriteLine("Current VPN Server: " + VpnConnUtils.CurrentVPNServer); BaseNetworkUtils.ShowNetworkInterfaces(); }
private void VpnNotifyIcon_DoubleClick(object sender, EventArgs e) { try { VpnConnUtils.ConnectOrDisconnectDefautBaseVPNServerAsync(); } catch (Exception ex) { Log.ShowError(ex); } }
private void VpnButton_MouseDown(object sender, MouseEventArgs e) { if (e.Clicks > 1) { try { VpnConnUtils.ConnectOrDisconnectDefautBaseVPNServerAsync(); } catch (Exception ex) { Log.ShowError(ex); } } }
private static void ScheduleJobChekVpnServer(JVPNServer item) { JRunningJob job = null; job = JobManager.Instance.CreateJob("ChekVpn", VpnSelectorLibRes.Test_for_VPN_server, item.Url, JobConcurrentTypeEnum.Wait); job.DoJob += (sd, ew) => { job.JobLog.Info("Plan VPN server test for " + item.Url); bool res = VpnConnUtils.TestConnectionWithConfirmation(item, job.JobLog); Thread.Sleep(5 * 1000); job.JobLog.Info("End VPN server test for " + item.Url); JobManager.Instance.ReportProgresJob(job, 100); if (res) { ew.StageResult = RunningJobResultEnum.ok; } else { ew.StageResult = RunningJobResultEnum.error; } }; item.JRunningJob = job; Dm.Instance.SaveObject(item); }
public void MakeContextMenu(IListProcessor list, List <ToolStripItem> menuItemList, object selectedListItem, object selectedObject, string aspectName) { //base.MakeContextMenu(menuItemList, selectedListItem, selectedObject, aspectName); menuItemList.Add(new ToolStripSeparator()); JVPNServer item = (JVPNServer)selectedObject; List <ToolStripItem> subitems = new List <ToolStripItem>(); if (item != null) { VpnConnUtils.MakeContextMenuForBaseVPNServer(subitems, item); } VpnConnUtils.MakeContextMenuForAllBaseVPNServers(subitems); menuItemList.AddRange(subitems.ToArray()); ToolStripMenuItem groupItem = null; ToolStripMenuItem menuItem = null; menuItem = new ToolStripMenuItem(); menuItem.Text = VpnSelectorLibRes.Import_VPN_servers_from_vpngate_net; menuItem.Click += (s, em) => { try { VpngateImporter.DowloadAndParse(); } catch (Exception ex) { Log.ShowError(ex); } }; menuItemList.Add(menuItem); groupItem = new ToolStripMenuItem(); groupItem.Text = VpnSelectorLibRes.Run_test; menuItemList.Add(groupItem); if (item != null) { menuItem = new ToolStripMenuItem(); menuItem.Text = ((list.SelectedObjects.Count > 1) ? VpnSelectorLibRes.Run_test_for_selected_VPN_servers : VpnSelectorLibRes.Run_test_for_this_VPN_server); menuItem.Click += (s, em) => { try { ScheduleJobChekVpnAll(list, list.SelectedObjects, false, false); } catch (Exception ex) { Log.ShowError(ex); } }; groupItem.DropDownItems.Add(menuItem); if (item.JRunningJob != null && item.JRunningJob.JJobType != null)//JRunningJob.JJobType = null for manualy deleted job { List <ToolStripItem> subitems2 = new List <ToolStripItem>(); JobManager.MakeTitleContextMenuForRunningJob(item.JRunningJob, subitems2, list.ContentContainer); groupItem.DropDownItems.AddRange(subitems2.ToArray <ToolStripItem>()); } if (currQueueJobType != null) { List <ToolStripItem> subitems22 = new List <ToolStripItem>(); JobManager.MakeTitleContextMenuForRunningJobTypeQueue(currQueueJobType, subitems22, list.ContentContainer); groupItem.DropDownItems.AddRange(subitems22.ToArray <ToolStripItem>()); } } menuItem = new ToolStripMenuItem(); menuItem.Text = VpnSelectorLibRes.Run_test_for_favorite_VPN_servers; menuItem.Click += (s, em) => { try { ScheduleJobChekVpnAll(list, null, false, true); } catch (Exception ex) { Log.ShowError(ex); } }; groupItem.DropDownItems.Add(menuItem); menuItem = new ToolStripMenuItem(); menuItem.Text = VpnSelectorLibRes.Run_test_for_all_VPN_servers; menuItem.Click += (s, em) => { try { ScheduleJobChekVpnAll(list, null, true, false); } catch (Exception ex) { Log.ShowError(ex); } }; groupItem.DropDownItems.Add(menuItem); }
protected void CreateVPNSupport() { VpnConnUtils.InitSettings(); // // vpnButton // this.vpnButton = new System.Windows.Forms.ToolStripSplitButton(); this.vpnButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.vpnButton.Enabled = true; this.vpnButton.ImageTransparentColor = System.Drawing.Color.Magenta; this.vpnButton.Name = "vpnButton"; this.vpnButton.Size = new System.Drawing.Size(19, 23); this.vpnButton.Text = "VPN"; this.vpnButton.ToolTipText = "VPN"; vpnButton.Image = VpnSelectorLibRes.network_off; //vpnButton.DoubleClick += VpnButton_DoubleClick; - do not working // // ipAddressLabel // this.ipAddressLabel = new System.Windows.Forms.ToolStripStatusLabel(); this.ipAddressLabel.AutoToolTip = true; this.ipAddressLabel.Enabled = false; this.ipAddressLabel.Name = "ipAddressLabel"; this.ipAddressLabel.Size = new System.Drawing.Size(66, 20); this.ipAddressLabel.Text = "127.0.0.1"; this.ipAddressLabel.ToolTipText = "127.0.0.1"; this.statusBar.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.eventWarrningButton, this.vpnButton, this.ipAddressLabel }); if (useMainTrayIconForVPN && BaseApplicationContext.NotifyIcon != null) { vpnNotifyIcon = BaseApplicationContext.NotifyIcon; } else { vpnNotifyIcon = new NotifyIcon(components) { ContextMenuStrip = new ContextMenuStrip(), Icon = vpnOffIcon, Text = "VPN", Visible = true }; } vpnButton.MouseDown += VpnButton_MouseDown; vpnNotifyIcon.ContextMenuStrip.Opening += VpnNotifyIconContextMenuStrip_Opening; vpnNotifyIcon.DoubleClick += VpnNotifyIcon_DoubleClick; VpnConnUtils.OnCheckExternalIPAddressComplatedEvent += JustNetworkUtils_OnCheckExternalIPAddressComplatedEvent; VpnConnUtils.VpnDisconnectedEvent += VpnSelector_OnVpnDisconnectedEvent; VpnConnUtils.VpnConnectedEvent += VpnSelector_OnVpnConnectedEvent; VpnConnUtils.VpnDialerErrorEvent += VpnSelector_OnVpnDialerErrorEvent; VpnConnUtils.CreateDialerAndBeginWatch(); if (VpnConnUtils.CurrentVPNServer != null)//checked in InitApplication() { //vpn connection presents before app started if (VpnConnUtils.CurVPNServerChangedEvent != null) { VpnConnUtils.CurVPNServerChangedEvent(null, new CurVPNServerChangedEventArgs()); } ProcessVpnConnectedEvent(); } if ((bool)FrwConfig.Instance.GetPropertyValue(VpnConnUtils.SETTING_CHECK_IP_ON_STARTUP, true) == true) { VpnConnUtils.ConfirmIpAddressAsync(); } }
public bool CheckIfWeNeedVPN(WebEntryInfo webEntryInfo) { string mes = null; JVPNServer allowedVPNServer = null; if (webEntryInfo.AllowedVPNServerId != null) { allowedVPNServer = Dm.Instance.Find <JVPNServer>(webEntryInfo.AllowedVPNServerId); } //if (webEntryInfo.AllowedVPNServerId != null || webEntryInfo.AllowedVPNCountrу != null || webEntryInfo.AllowedVPNTown != null) if (webEntryInfo.AllowedVPNServerId != null) { string allowedMes = WebAccountLibRes.For_this_entity_you_need_access_to_the_Internet_through_a_specific_VPN; if (VpnConnUtils.CurrentVPNServer == null) { mes = allowedMes + WebAccountLibRes.Current_VPN_connection_is_not_established; } else { if (webEntryInfo.AllowedVPNServerId != null) { if (allowedVPNServer == null) { mes = allowedMes + WebAccountLibRes.This_VPN_connection_has_not_been_established; } else if (VpnConnUtils.CurrentVPNServer != allowedVPNServer) { mes = allowedMes + WebAccountLibRes.The_current_VPN_connection_does_not_match; } } } } if (mes != null) { if (allowedVPNServer != null) { DialogResult res = MessageBox.Show(mes + " " + WebAccountLibRes.Click_Yes_to_connect_to_the_desired_VPN_server, FrwConstants.WARNING, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (res == DialogResult.Yes) { try { Cursor.Current = Cursors.WaitCursor; bool conRes = VpnConnUtils.ConnectWithConfirmation(allowedVPNServer); return(conRes); } finally { Cursor.Current = Cursors.Default; } } else if (res == DialogResult.No) { //do nothing } else //Cancel or close { return(false); } } else { DialogResult res = MessageBox.Show(mes + " " + WebAccountLibRes.Click_OK_to_ignore_the_warning_and_continue_Click_Cancel_to_cancel, FrwConstants.WARNING, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (res != DialogResult.OK) //Cancel or close { return(false); } } } return(true); }