예제 #1
0
        public void StartCloseVNCTimer(VNCView vncView)
        {
            if (vncView == null)
                return;

            // find the <VM, VNCView> pair in vncViews and start timer on the vm 
            foreach (var kvp in vncViews.Where(kvp => kvp.Value == vncView))
            {
                StartCloseVNCTimer(kvp.Key);
                break;
            }
        }
예제 #2
0
        private bool tryToConnectRDP = false; // This parameter will be set after click "TURN ON Rremote Desktop" and will connect RDP when RDP status changed.

        #endregion Fields

        #region Constructors

        public VNCTabView(VNCView parent, VM source, string elevatedUsername, string elevatedPassword)
        {
            Program.AssertOnEventThread();

            InitializeComponent();

            HostLabel.Font = Program.HeaderGradientFont;
            HostLabel.ForeColor = Program.HeaderGradientForeColor;
            multipleDvdIsoList1.LabelSingleDvdForeColor = Program.HeaderGradientForeColor;
            multipleDvdIsoList1.LabelNewCdForeColor = Program.HeaderGradientForeColor;
            multipleDvdIsoList1.LinkLabelLinkColor = Color.White;

            #pragma warning disable 0219
            // Force the handle to be created, because resize events
            // could be fired before this component is placed on-screen.
            IntPtr _ = Handle;
            #pragma warning restore 0219

            this.parentVNCView = parent;
            this.scaleCheckBox.Checked = false;
            this.source = source;
            this.guestMetrics = source.Connection.Resolve(source.guest_metrics);
            if (this.guestMetrics != null)
                guestMetrics.PropertyChanged += guestMetrics_PropertyChanged;
            log.DebugFormat("'{0}' console: Register Server_PropertyChanged event listener on {0}", this.source.Name);
            this.source.PropertyChanged += Server_PropertyChanged;
            Host_CollectionChangedWithInvoke = Program.ProgramInvokeHandler(Host_CollectionChanged);
            VM_CollectionChangedWithInvoke = Program.ProgramInvokeHandler(VM_CollectionChanged);
            source.Connection.Cache.RegisterCollectionChanged<VM>(VM_CollectionChangedWithInvoke);

            if (source.is_control_domain)
            {
                Host host = source.Connection.Resolve(source.resident_on);
                if (host != null)
                {
                    log.DebugFormat("'{0}' console: Register Server_PropertyChanged event listener on {1}", this.source.Name, host.Name);
                    host.PropertyChanged += Server_PropertyChanged;

                    Host_metrics hostMetrics = source.Connection.Resolve(host.metrics);
                    if (hostMetrics != null)
                    {
                        log.DebugFormat("'{0}' console: Register Server_PropertyChanged event listener on host metrics", this.source.Name);
                        hostMetrics.PropertyChanged += Server_PropertyChanged;
                    }

                    HostLabel.Text = string.Format(source.IsControlDomainZero ? Messages.CONSOLE_HOST : Messages.CONSOLE_HOST_NUTANIX, host.Name);
                    HostLabel.Visible = true;
                }
            }
            else
            {
                source.Connection.Cache.RegisterCollectionChanged<Host>(Host_CollectionChangedWithInvoke);
                targetHost = source.GetStorageHost(false);

                foreach (Host cachedHost in source.Connection.Cache.Hosts)
                {
                    log.DebugFormat("'{0}' console: Register Server_EnabledPropertyChanged event listener on {1}",
                                    source.Name, cachedHost.Name);
                    cachedHost.PropertyChanged += Server_EnabledPropertyChanged;
                }

                HostLabel.Visible = false;
            }

            log.DebugFormat("'{0}' console: Update power state (on VNCTabView constructor)", this.source.Name);
            updatePowerState();
            this.vncScreen = new XSVNCScreen(source, new EventHandler(RDPorVNCResizeHandler), this, elevatedUsername, elevatedPassword);
            ShowGpuWarningIfRequired(vncScreen.MustConnectRemoteDesktop());
            vncScreen.GpuStatusChanged += ShowGpuWarningIfRequired;

            if (source.IsControlDomainZero || source.IsHVM && !hasRDP) //Linux HVM guests should only have one console: the console switch button vanishes altogether.
            {
                toggleConsoleButton.Visible = false;
            }
            else
            {
                toggleConsoleButton.Visible = true;
                this.vncScreen.OnDetectRDP = this.OnDetectRDP;
                this.vncScreen.OnDetectVNC = this.OnDetectVNC;
                this.vncScreen.UserCancelledAuth += this.OnUserCancelledAuth;
                this.vncScreen.VncConnectionAttemptCancelled += this.OnVncConnectionAttemptCancelled;
            }

            LastDesktopSize = vncScreen.DesktopSize;

            this.insKeyTimer = new System.Threading.Timer(new TimerCallback(notInsKeyPressed));

            Properties.Settings.Default.PropertyChanged += Default_PropertyChanged;

            registerShortCutKeys();

            //
            // Ctlr - Alt - Ins send Ctrl - Alt - Delete, and cancels and pending full screen.
            //

            KeyHandler.AddKeyHandler(ConsoleShortcutKey.CTRL_ALT_INS, cancelWaitForInsKeyAndSendCAD);

            this.vncScreen.Parent = this.contentPanel;
            this.vncScreen.Dock = DockStyle.Fill;

            string rdpLabel = GuessNativeConsoleLabel(source);
            this.toggleConsoleButton.Text = rdpLabel;

            UpdateFullScreenButton();

            UpdateDockButton();

            setupCD();

            UpdateParentMinimumSize();

            UpdateTooltipOfToogleButton();

            UpdateOpenSSHConsoleButtonState();

            toggleConsoleButton.EnabledChanged += toggleConsoleButton_EnabledChanged;

            //If RDP enabled and AutoSwitchToRDP selected, switch RDP connection will be done when VNC already get the correct screen resolution.
            //This change is only for Cream, because RDP port scan was removed in Cream.
            if ( Helpers.CreamOrGreater(source.Connection) && Properties.Settings.Default.AutoSwitchToRDP && RDPEnabled )
                vncScreen.AutoSwitchRDPLater = true;
        }
예제 #3
0
        internal Image Snapshot(VM vm, string elevatedUsername, string elevatedPassword)
        {
            Program.AssertOffEventThread();

            VNCView view = null;

            bool useElevatedCredentials = false;

            if (!vncViews.ContainsKey(vm))
            {
                Program.Invoke(this, delegate
                {
                    // use elevated credentials, if provided, to create a vncView (CA-91132)
                    useElevatedCredentials = !String.IsNullOrEmpty(elevatedUsername) && !String.IsNullOrEmpty(elevatedPassword);
                    if (useElevatedCredentials)
                        view = new VNCView(vm, elevatedUsername, elevatedPassword);
                    else
                    {
                        setCurrentSource(vm);
                        if (vncViews.ContainsKey(vm))
                            view = vncViews[vm];
                    }
                });
            }
            else
            {
                view = vncViews[vm];
            }

            if (view == null)
                return null;

            Image snapshot = view.Snapshot();

            // TODO: only pause the view if we're not currently using it.
            // view.Pause();

            if (useElevatedCredentials)
            {
                //used the elevated credentials for snapshot, need to close vnc when finished
                Program.Invoke(this, () => view.Dispose());
            }

            return snapshot;
        }
예제 #4
0
        internal void setCurrentSource(VM source)
        {
            Program.AssertOnEventThread();

            // activeVNCView is going to change, so the current activeVNCView will become inactive
            // Start a timer for closing the inactive VNC connection after an interval (20 seconds)
            StartCloseVNCTimer(activeVNCView);

            this.Controls.Clear();

            if (source == null)
            {
                activeVNCView = null;
                return;
            }
            List<Role> allowedRoles = null;
            if (RbacDenied(source, out allowedRoles))
            {
                lableRbacWarning.Text = String.Format(allowedRoles.Count == 1 ? Messages.RBAC_CONSOLE_WARNING_ONE : Messages.RBAC_CONSOLE_WARNING_MANY,
                                                      Role.FriendlyCSVRoleList(source.Connection.Session.Roles),
                                                      Role.FriendlyCSVRoleList(allowedRoles));

                this.Controls.Add(RbacWarningPanel);
                if (activeVNCView != null)
                    this.Controls.Remove(activeVNCView);
                return;
            }
            activeVMConsoles.Remove(source);
            activeVMConsoles.Add(source);

            StopCloseVncTimer(source);
            
            while (activeVMConsoles.Count > MAX_ACTIVE_VM_CONSOLES)
            {
                closeVNCForSource(activeVMConsoles[0]);
            }

            if (vncViews.ContainsKey(source))
            {
                activeVNCView = vncViews[source];
            }
            else
            {
                activeVNCView = new VNCView(source, null, null);
                vncViews[source] = activeVNCView;
            }
            activeVNCView.refreshIsoList();
            this.Controls.Add(activeVNCView);
            this.ClearErrorMessage();
        }
예제 #5
0
        public VNCTabView(VNCView parent, VM source, string elevatedUsername, string elevatedPassword)
        {
            Program.AssertOnEventThread();

            InitializeComponent();

            HostLabel.Font = Program.HeaderGradientFont;
            HostLabel.ForeColor = Program.HeaderGradientForeColor;
            multipleDvdIsoList1.SetTextColor(Program.HeaderGradientForeColor);

            #pragma warning disable 0219
            // Force the handle to be created, because resize events
            // could be fired before this component is placed on-screen.
            IntPtr _ = Handle;
            #pragma warning restore 0219

            this.parentVNCView = parent;
            this.scaleCheckBox.Checked = false;
            this.source = source;
            log.DebugFormat("'{0}' console: Register Server_PropertyChanged event listener on {0}", this.source.Name);
            this.source.PropertyChanged += Server_PropertyChanged;
            Host_CollectionChangedWithInvoke = Program.ProgramInvokeHandler(Host_CollectionChanged);
            VM_CollectionChangedWithInvoke = Program.ProgramInvokeHandler(VM_CollectionChanged);
            source.Connection.Cache.RegisterCollectionChanged<VM>(VM_CollectionChangedWithInvoke);

            if (source.is_control_domain)
            {
                Host host = source.Connection.Resolve(source.resident_on);
                if (host != null)
                {
                    log.DebugFormat("'{0}' console: Register Server_PropertyChanged event listener on {1}", this.source.Name, host.Name);
                    host.PropertyChanged += Server_PropertyChanged;

                    Host_metrics hostMetrics = source.Connection.Resolve(host.metrics);
                    if (hostMetrics != null)
                    {
                        log.DebugFormat("'{0}' console: Register Server_PropertyChanged event listener on host metrics", this.source.Name);
                        hostMetrics.PropertyChanged += Server_PropertyChanged;
                    }

                    HostLabel.Text = string.Format(Messages.CONSOLE_HOST, host.Name);
                    HostLabel.Visible = true;
                }
            }
            else
            {
                source.Connection.Cache.RegisterCollectionChanged<Host>(Host_CollectionChangedWithInvoke);
                targetHost = source.GetStorageHost(false);

                foreach (Host cachedHost in source.Connection.Cache.Hosts)
                {
                    log.DebugFormat("'{0}' console: Register Server_EnabledPropertyChanged event listener on {1}",
                                    source.Name, cachedHost.Name);
                    cachedHost.PropertyChanged += Server_EnabledPropertyChanged;
                }

                HostLabel.Visible = false;
            }

            log.DebugFormat("'{0}' console: Update power state (on VNCTabView constructor)", this.source.Name);
            updatePowerState();
            this.vncScreen = new XSVNCScreen(source, new EventHandler(RDPorVNCResizeHandler), this, elevatedUsername, elevatedPassword);
            ShowGpuWarningIfRequired();

            if (source.is_control_domain)
            {
                toggleConsoleButton.Visible = false;
            }
            else
            {
                toggleConsoleButton.Visible = true;
                this.vncScreen.OnDetectRDP = this.OnDetectRDP;
                this.vncScreen.OnDetectVNC = this.OnDetectVNC;
                this.vncScreen.UserCancelledAuth += this.OnUserCancelledAuth;
            }

            LastDesktopSize = vncScreen.DesktopSize;

            this.insKeyTimer = new System.Threading.Timer(new TimerCallback(notInsKeyPressed));

            Properties.Settings.Default.PropertyChanged += Default_PropertyChanged;

            registerShortCutKeys();

            //
            // Ctlr - Alt - Ins send Ctrl - Alt - Delete, and cancels and pending full screen.
            //

            KeyHandler.AddKeyHandler(ConsoleShortcutKey.CTRL_ALT_INS, cancelWaitForInsKeyAndSendCAD);

            this.vncScreen.Parent = this.contentPanel;
            this.vncScreen.Dock = DockStyle.Fill;

            this.Dock = DockStyle.Fill;

            string rdpLabel = GuessNativeConsoleLabel(source);
            this.toggleConsoleButton.Text = rdpLabel;

            UpdateFullScreenButton();

            UpdateDockButton();

            setupCD();

            UpdateParentMinimumSize();

            toggleConsoleButton.EnabledChanged += toggleConsoleButton_EnabledChanged;
        }
예제 #6
0
        internal void setCurrentSource(VM source)
        {
            Program.AssertOnEventThread();

            // activeVNCView is going to change, so the current activeVNCView will become inactive
            // Start a timer for closing the inactive VNC connection after an interval (20 seconds)
            StartCloseVNCTimer(activeVNCView);

            tableLayoutPanelRbac.Visible = false;

            if (activeVNCView != null)
            {
                Controls.Remove(activeVNCView);
                activeVNCView = null;
            }

            if (source == null)
                return;

            List<Role> allowedRoles;
            if (RbacDenied(source, out allowedRoles))
            {
                string msg = allowedRoles.Count == 1 ? Messages.RBAC_CONSOLE_WARNING_ONE : Messages.RBAC_CONSOLE_WARNING_MANY;
                lableRbacWarning.Text = string.Format(msg,
                    Role.FriendlyCSVRoleList(source.Connection.Session.Roles),
                    Role.FriendlyCSVRoleList(allowedRoles));

                tableLayoutPanelRbac.Visible = true;
                return;
            }

            StopCloseVncTimer(source);

            //remove one more as we're adding the selected further down
            //Take(arg) returns empty list if the arg <= 0
            var viewsToRemove = vncViews.Where(v => v.Key.opaque_ref != source.opaque_ref).Take(vncViews.Count -1 - MAX_ACTIVE_VM_CONSOLES);

            foreach (var view in viewsToRemove)
                closeVNCForSource(view.Key);

            if (vncViews.ContainsKey(source))
            {
                activeVNCView = vncViews[source];
            }
            else
            {
                activeVNCView = new VNCView(source, null, null) { Dock = DockStyle.Fill };
                vncViews[source] = activeVNCView;
            }

            activeVNCView.refreshIsoList();
            Controls.Add(activeVNCView);
            ClearErrorMessage();
        }
예제 #7
0
        internal void setCurrentSource(VM source)
        {
            Program.AssertOnEventThread();

            this.Controls.Clear();

            if (source == null)
            {
                activeVNCView = null;
                return;
            }
            List<Role> allowedRoles = null;
            if (RbacDenied(source, out allowedRoles))
            {
                lableRbacWarning.Text = String.Format(allowedRoles.Count == 1 ? Messages.RBAC_CONSOLE_WARNING_ONE : Messages.RBAC_CONSOLE_WARNING_MANY,
                                                      Role.FriendlyCSVRoleList(source.Connection.Session.Roles),
                                                      Role.FriendlyCSVRoleList(allowedRoles));

                this.Controls.Add(RbacWarningPanel);
                if (activeVNCView != null)
                    this.Controls.Remove(activeVNCView);
                return;
            }
            activeVMConsoles.Remove(source);
            activeVMConsoles.Add(source);
            while (activeVMConsoles.Count > MAX_ACTIVE_VM_CONSOLES)
            {
                closeVNCForSource(activeVMConsoles[0]);
                activeVMConsoles.RemoveAt(0);
            }

            if (vncViews.ContainsKey(source))
            {
                activeVNCView = vncViews[source];
            }
            else
            {
                activeVNCView = new VNCView(source, null, null);
                vncViews[source] = activeVNCView;
            }
            activeVNCView.refreshIsoList();
            this.Controls.Add(activeVNCView);
            this.ClearErrorMessage();
        }