Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                searchBox.AddCriteria("ItemName", GetLocalizedString("SearchField.ItemName"));
                searchBox.AddCriteria("Username", GetLocalizedString("SearchField.Username"));
                searchBox.AddCriteria("ExternalIP", GetLocalizedString("SearchField.ExternalIP"));
                searchBox.AddCriteria("IPAddress", GetLocalizedString("SearchField.IPAddress"));
            }
            searchBox.AjaxData = this.GetSearchBoxAjaxData();

            // toggle columns
            bool isUserSelected = PanelSecurity.SelectedUser.Role == SolidCP.EnterpriseServer.UserRole.User;

            gvServers.Columns[3].Visible = !isUserSelected;
            gvServers.Columns[4].Visible = !isUserSelected;

            // replication
            gvServers.Columns[5].Visible = false;
            btnReplicaStates.Visible     = false;
            ///PackagesHelper.IsQuotaEnabled(PanelSecurity.PackageId, Quotas.PROXMOX_REPLICATION_ENABLED);

            // check package quotas
            bool manageAllowed = VirtualMachinesProxmoxHelper.IsVirtualMachineManagementAllowed(PanelSecurity.PackageId);

            btnCreate.Visible = manageAllowed;

            btnImport.Visible            = (PanelSecurity.EffectiveUser.Role == UserRole.Administrator);
            gvServers.Columns[6].Visible = manageAllowed;

            // admin operations column
            gvServers.Columns[7].Visible = false;
            //(PanelSecurity.EffectiveUser.Role == UserRole.Administrator);
        }
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            try
            {
                // check rights
                bool manageAllowed = VirtualMachinesProxmoxHelper.IsVirtualMachineManagementAllowed(PanelSecurity.PackageId);
                if (!manageAllowed)
                {
                    return;
                }

                VirtualMachine virtualMachine = new VirtualMachine();

                // the custom provider control
                this.SaveSettingsControls(ref virtualMachine);

                ResultObject res = ES.Services.Proxmox.UpdateVirtualMachineConfiguration(PanelRequest.ItemID,
                                                                                         Utils.ParseInt(ddlCpu.SelectedValue),
                                                                                         Utils.ParseInt(txtRam.Text.Trim()),
                                                                                         Utils.ParseInt(txtHdd.Text.Trim()),
                                                                                         Utils.ParseInt(txtSnapshots.Text.Trim()),
                                                                                         chkDvdInstalled.Checked,
                                                                                         chkBootFromCd.Checked,
                                                                                         false,
                                                                                         chkStartShutdown.Checked,
                                                                                         chkPauseResume.Checked,
                                                                                         chkReboot.Checked,
                                                                                         chkReset.Checked,
                                                                                         chkReinstall.Checked,
                                                                                         chkExternalNetworkEnabled.Checked,
                                                                                         chkPrivateNetworkEnabled.Checked,
                                                                                         virtualMachine);

                if (res.IsSuccess)
                {
                    // redirect back
                    RedirectBack("changed");
                }
                else
                {
                    // show error
                    messageBox.ShowMessage(res, "VPS_CHANGE_VM_CONFIGURATION", "VPS");
                }
            }
            catch (Exception ex)
            {
                messageBox.ShowErrorMessage("VPS_CHANGE_VM_CONFIGURATION", ex);
            }
        }
Example #3
0
        private void ToggleButtons()
        {
            bool manageAllowed = VirtualMachinesProxmoxHelper.IsVirtualMachineManagementAllowed(PanelSecurity.PackageId);

            btnAddExternalAddress.Visible          = manageAllowed;
            btnSetPrimaryExternal.Visible          = manageAllowed;
            btnDeleteExternal.Visible              = manageAllowed;
            gvExternalAddresses.Columns[0].Visible = manageAllowed;

            btnAddPrivateAddress.Visible          = manageAllowed;
            btnSetPrimaryPrivate.Visible          = manageAllowed;
            btnDeletePrivate.Visible              = manageAllowed;
            gvPrivateAddresses.Columns[0].Visible = manageAllowed;
        }
        private void BindConfiguration()
        {
            VirtualMachine vm = null;

            try
            {
                // load machine
                vm = ES.Services.Proxmox.GetVirtualMachineItem(PanelRequest.ItemID);

                if (vm == null)
                {
                    messageBox.ShowErrorMessage("VPS_LOAD_VM_META_ITEM");
                    return;
                }

                // bind item
                litOperatingSystem.Text = vm.OperatingSystemTemplate;

                litCpu.Text       = String.Format(GetLocalizedString("CpuCores.Text"), vm.CpuCores);
                litRam.Text       = String.Format(GetLocalizedString("Ram.Text"), vm.RamSize);
                litHdd.Text       = String.Format(GetLocalizedString("Hdd.Text"), vm.HddSize[0]);
                litSnapshots.Text = vm.SnapshotsNumber.ToString();

                optionDvdInstalled.Value = vm.DvdDriveInstalled;
                optionBootFromCD.Value   = vm.BootFromCD;
                //optionNumLock.Value = vm.NumLockEnabled;

                optionStartShutdown.Value = vm.StartTurnOffAllowed;
                optionPauseResume.Value   = vm.PauseResumeAllowed;
                optionReset.Value         = vm.ResetAllowed;
                optionReboot.Value        = vm.RebootAllowed;
                optionReinstall.Value     = vm.ReinstallAllowed;

                optionExternalNetwork.Value = vm.ExternalNetworkEnabled;
                optionPrivateNetwork.Value  = vm.PrivateNetworkEnabled;

                // toggle buttons
                bool manageAllowed = VirtualMachinesProxmoxHelper.IsVirtualMachineManagementAllowed(PanelSecurity.PackageId);
                btnEdit.Visible = manageAllowed;

                this.BindSettingsControls(vm);
            }
            catch (Exception ex)
            {
                messageBox.ShowErrorMessage("VPS_LOAD_VM_META_ITEM", ex);
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     packageAddresses.ManageAllowed = VirtualMachinesProxmoxHelper.IsVirtualMachineManagementAllowed(PanelSecurity.PackageId);
 }
Example #6
0
        private void BindGeneralDetails()
        {
            VirtualMachine item = VirtualMachinesProxmoxHelper.GetCachedVirtualMachine(PanelRequest.ItemID);

            if (!String.IsNullOrEmpty(item.CurrentTaskId) ||
                item.ProvisioningStatus == VirtualMachineProvisioningStatus.Error)
            {
                DetailsTable.Visible = false;
                return;
            }

            VirtualMachine vm = null;

            try
            {
                vm = ES.Services.Proxmox.GetVirtualMachineGeneralDetails(PanelRequest.ItemID);
            }
            catch (Exception ex)
            {
                messageBox.ShowErrorMessage("VPS_ERROR_GET_VM_DETAILS", ex);
            }

            if (vm != null)
            {
                bool displayRDP = (Request.Browser.Browser == "IE" &&
                                   Request.Browser.ActiveXControls &&
                                   Request.Browser.VBScript &&
                                   vm.State != VirtualMachineState.Off &&
                                   vm.State != VirtualMachineState.Paused &&
                                   vm.State != VirtualMachineState.Saved &&
                                   item.RemoteDesktopEnabled);
                lnkHostname.Text    = item.Hostname.ToUpper();
                lnkHostname.Visible = displayRDP;

                litHostname.Text    = item.Hostname.ToUpper();
                litHostname.Visible = !displayRDP;

                litDomain.Text = item.Domain;

                if (!IsPostBack)
                {
                    // set host name change form
                    txtHostname.Text = item.Hostname;
                    txtDomain.Text   = item.Domain;
                }

                lnkHostname.Visible = false;
                //litRdpPageUrl.Text = Page.ResolveUrl(ES.Services.Proxmox.GetVirtualMachineVNCURL(PanelRequest.ItemID));


                TimeSpan uptime = TimeSpan.FromMilliseconds(vm.Uptime * 1000);
                uptime          = uptime.Subtract(TimeSpan.FromMilliseconds(uptime.Milliseconds));
                litUptime.Text  = uptime.ToString();
                litStatus.Text  = GetLocalizedString("State." + vm.State);
                litCreated.Text = vm.CreatedDate.ToString();
                //litHeartbeat.Text = GetLocalizedString("Heartbeat." + vm.Heartbeat);

                // CPU
                cpuGauge.Progress     = vm.CpuUsage;
                litCpuPercentage.Text = String.Format(GetLocalizedString("CpuPercentage.Text"), vm.CpuUsage);

                // RAM
                if (vm.RamSize > 0)
                {
                    var totalRam = vm.RamSize;

                    if (vm.DynamicMemory != null && vm.DynamicMemory.Enabled)
                    {
                        totalRam = vm.DynamicMemory.Maximum;
                    }

                    int ramPercent = Convert.ToInt32((float)vm.RamUsage / (float)totalRam * 100);
                    ramGauge.Total        = totalRam;
                    ramGauge.Progress     = vm.RamUsage;
                    litRamPercentage.Text = String.Format(GetLocalizedString("MemoryPercentage.Text"), ramPercent);
                    litRamUsage.Text      = String.Format(GetLocalizedString("MemoryUsage.Text"), vm.RamUsage, totalRam);
                }

                // HDD
                if (vm.HddLogicalDisks != null && vm.HddLogicalDisks.Length > 0)
                {
                    HddRow.Visible = true;

                    int freeHdd = 0;
                    int sizeHdd = 0;

                    foreach (LogicalDisk disk in vm.HddLogicalDisks)
                    {
                        freeHdd += disk.FreeSpace;
                        sizeHdd += disk.Size;
                    }

                    int usedHdd = sizeHdd - freeHdd;

                    int hddPercent = Convert.ToInt32((float)usedHdd / (float)sizeHdd * 100);
                    hddGauge.Total        = sizeHdd;
                    hddGauge.Progress     = usedHdd;
                    litHddPercentage.Text = String.Format(GetLocalizedString("HddPercentage.Text"), hddPercent);
                    litHddUsage.Text      = String.Format(GetLocalizedString("HddUsage.Text"), freeHdd, sizeHdd, vm.HddLogicalDisks.Length);
                }

                // update image
                imgThumbnail.ImageUrl =
                    String.Format("~/DesktopModules/SolidCP/Proxmox/VirtualMachineImage.ashx?ItemID={0}&rnd={1}",
                                  PanelRequest.ItemID, DateTime.Now.Ticks);

                // load virtual machine meta item
                VirtualMachine vmi = VirtualMachinesProxmoxHelper.GetCachedVirtualMachine(PanelRequest.ItemID);

                // draw buttons
                List <ActionButton> buttons = new List <ActionButton>();

                if (vmi.StartTurnOffAllowed &&
                    (vm.State == VirtualMachineState.Off ||
                     vm.State == VirtualMachineState.Saved))
                {
                    buttons.Add(CreateActionButton("Start", "start.png"));
                }

                if (vm.State == VirtualMachineState.Running)
                {
                    if (vmi.RebootAllowed)
                    {
                        buttons.Add(CreateActionButton("Reboot", "reboot.png"));
                    }

                    if (vmi.StartTurnOffAllowed)
                    {
                        buttons.Add(CreateActionButton("ShutDown", "shutdown.png"));
                    }
                }

                if (vmi.StartTurnOffAllowed &&
                    (vm.State == VirtualMachineState.Running ||
                     vm.State == VirtualMachineState.Paused))
                {
                    buttons.Add(CreateActionButton("TurnOff", "turnoff.png"));
                }

                if (vmi.PauseResumeAllowed &&
                    vm.State == VirtualMachineState.Running)
                {
                    buttons.Add(CreateActionButton("Pause", "pause.png"));
                }

                if (vmi.PauseResumeAllowed &&
                    vm.State == VirtualMachineState.Paused)
                {
                    buttons.Add(CreateActionButton("Resume", "start2.png"));
                }

                if (vmi.ResetAllowed &&
                    (vm.State == VirtualMachineState.Running ||
                     vm.State == VirtualMachineState.Paused))
                {
                    buttons.Add(CreateActionButton("Reset", "reset2.png"));
                }

                repButtons.DataSource = buttons;
                repButtons.DataBind();

                // other actions
                bool manageAllowed = VirtualMachinesProxmoxHelper.IsVirtualMachineManagementAllowed(PanelSecurity.PackageId);
                btnChangeHostnamePopup.Visible = manageAllowed;
            }
            else
            {
                DetailsTable.Visible = false;
                messageBox.ShowErrorMessage("VPS_LOAD_VM_ITEM");
            }
        }