protected void setSnapshot(int snapshotId) { // 0 means no valid snapshot id, so just use any preexisting one if (!snapshotId.Equals(0)) { m_snapshotId = snapshotId; } // if not valid, get the last one from the server if (m_snapshotId.Equals(0)) { m_snapshotId = m_serverInstance.LastCollectionSnapshotId; } // if still not valid, disable features if (m_snapshotId.Equals(0)) { m_snapshotId = m_serverInstance.LastCollectionSnapshotId; } else { Sql.Snapshot snapshot = Sql.Snapshot.GetSnapShot(m_snapshotId); _linkLabel_Snapshot.Text = @"Snapshot: " + snapshot.StartTime.ToString(Utility.Constants.DATETIME_FORMAT); if (snapshot.Baseline.Equals(Utility.Snapshot.BaselineTrue)) { _linkLabel_Snapshot.Text += @" (baseline)"; } } checkSelections(); }
private void fillSuspectAccountsPage(Sql.Snapshot snapshot) { // Get a list of suspect windows accounts. List <Sql.WindowsAccount> wal = Sql.WindowsAccount.GetSuspectAccounts(snapshot.SnapshotId); // If list is not null, fill the grid. if (wal != null) { _lbl_NumUnresolvedWindowsAccounts.Text = wal.Count.ToString(); _lbl_ItemsUnresolvedWindowsAccounts.Text = wal.Count.ToString() + (wal.Count != 1 ? " Items" : " Item"); // Create the data table. DataTable dt = new DataTable(); dt.Columns.Add(colIcon, typeof(Image)); dt.Columns.Add(colDomain, typeof(string)); dt.Columns.Add(colAccount, typeof(string)); dt.Columns.Add(colType, typeof(string)); // Fill the data table. int numWellknownGroups = 0; foreach (Sql.WindowsAccount wa in wal) { // Determine the image. Image icon = null; switch (wa.AccountType) { case Sql.WindowsAccount.Type.Group: case Sql.WindowsAccount.Type.LocalGroup: case Sql.WindowsAccount.Type.GlobalGroup: case Sql.WindowsAccount.Type.UniversalGroup: icon = AppIcons.AppImage16(AppIcons.Enum.WindowsGroup); break; case Sql.WindowsAccount.Type.WellKnownGroup: icon = AppIcons.AppImage16(AppIcons.Enum.WindowsGroup); ++numWellknownGroups; break; case Sql.WindowsAccount.Type.User: icon = AppIcons.AppImage16(AppIcons.Enum.WindowsUser); break; default: icon = AppIcons.AppImage16(AppIcons.Enum.Unknown); break; } //AppIcons.AppImage16(AppIcons.Enum.WindowsUser); dt.Rows.Add(icon, wa.Domain, wa.Account, wa.AccountTypeString); } // Set the number of wellknown groups count. _lbl_WellKnownGroups.Text = numWellknownGroups.ToString(); // Update the grid. _ultraGridUnresolvedWindowsAccounts.BeginUpdate(); _ultraGridUnresolvedWindowsAccounts.DataSource = dt; _ultraGridUnresolvedWindowsAccounts.DataMember = ""; _ultraGridUnresolvedWindowsAccounts.EndUpdate(); } }
private Form_SnapshotServerProperties( Sql.ServerVersion version, Sql.ObjectTag tag ) { Debug.Assert(version != Sql.ServerVersion.Unsupported); Debug.Assert(tag != null); InitializeComponent(); // Set minimum size. this.MinimumSize = this.Size; // Init fields. m_Version = version; m_ObjectTag = tag; m_Snapshot = Sql.Snapshot.GetSnapShot(tag.SnapshotId); m_IsGridFilled = false; // Init general page. if (m_Snapshot != null) { // Set form title. Text = "Snapshot SQL Server Properties - " + m_Snapshot.FullName; // Init general page. initGeneralPage(); // Init config page. initConfigPage(); } ultraTabControl1.DrawFilter = new HideFocusRectangleDrawFilter(); }
public Form_BaselineSnapshot(Sql.Snapshot snap) { InitializeComponent(); m_snapshot = snap; _listView_Snapshots.Items.Add(snap.StartTime.ToLocalTime().ToString(Utility.Constants.DATETIME_FORMAT)); _listView_Snapshots.Items[_listView_Snapshots.Items.Count - 1].SubItems.Add(snap.Baseline); }
private void fillGeneralPage(Sql.Snapshot snapshot) { _lbl_StartTime.Text = snapshot.StartTime.ToLocalTime().ToString(Utility.Constants.DATETIME_FORMAT); TimeSpan duration = snapshot.EndTime - snapshot.StartTime; _lbl_Duration.Text = duration.ToString(); _lbl_Status.Text = snapshot.SnapshotComment; _lbl_Version.Text = snapshot.CollectorVersion; _lbl_IsBaseline.Text = snapshot.Baseline; _lbl_BaselineComment.Text = snapshot.BaselineComment; _lbl_NumObjects.Text = snapshot.NumObject.ToString(); _lbl_NumPermissions.Text = snapshot.NumPermission.ToString(); _lbl_NumLogins.Text = snapshot.NumLogin.ToString(); _lbl_NumWindowsGroupMembers.Text = snapshot.NumWindowsGroupMember.ToString(); }
public Form_SnapshotProperties( Sql.Snapshot snapshot, List <Sql.DataCollectionFilter> filters ) { Debug.Assert(snapshot != null); Debug.Assert(filters != null); InitializeComponent(); // Set minimum size & icon. this.MinimumSize = this.Size; // Set form text based on snapshot name. m_SnapshotName = snapshot.SnapshotName; this.Text = "Snapshot Properties - " + m_SnapshotName; // Set the icons. _ultraGridUnresolvedWindowsAccounts.DisplayLayout.FilterDropDownButtonImage = AppIcons.AppImage16(AppIcons.Enum.GridFilter); _tsbtn_GroupByBoxUnresolvedWindowsAccounts.Image = AppIcons.AppImage16(AppIcons.Enum.GridGroupBy); _tsbtn_PrintUnresolvedWindowsAccounts.Image = AppIcons.AppImage16(AppIcons.Enum.Print); _tsbtn_SaveAsUnresolvedWindowsAccounts.Image = AppIcons.AppImage16(AppIcons.Enum.GridSaveToExcel); _ultraGridUnavailableDatabases.DisplayLayout.FilterDropDownButtonImage = AppIcons.AppImage16(AppIcons.Enum.GridFilter); _tsbtn_GroupByBoxUnavailableDatabases.Image = AppIcons.AppImage16(AppIcons.Enum.GridGroupBy); _tsbtn_PrintUnavailableDatabases.Image = AppIcons.AppImage16(AppIcons.Enum.Print); _tsbtn_SaveAsUnavailableDatabases.Image = AppIcons.AppImage16(AppIcons.Enum.GridSaveToExcel); // Setup missing windows accounts and unavailable database intro. _lbl_IntroUnresolvedWindowsAccounts.Text = IntroUnresolvedWindowsAccounts; _lbl_IntroUnresolvedWindowsAccounts.LinkArea = new LinkArea(IntroUnresolvedWindowsAccounts.Length - TellMeMoreLen - 1, TellMeMoreLen); _lbl_IntroUnavailableDatabases.Text = IntroUnavailableDatabases; _lbl_IntroUnavailableDatabases.LinkArea = new LinkArea(IntroUnavailableDatabases.Length - TellMeMoreLen - 1, TellMeMoreLen); // Setup the print document format. _ultraGridPrintDocument.DefaultPageSettings.Landscape = true; _ultraGridPrintDocument.DefaultPageSettings.Color = false; _ultraGridPrintDocument.FitWidthToPages = 1; // Fill the pages. fillGeneralPage(snapshot); fillFiltersPage(filters); fillSuspectAccountsPage(snapshot); fillUnavailableDatabases(snapshot); }
protected virtual void showBaseline() { Debug.Assert(!(_grid.Selected.Rows.Count == 0), "Attempt to baseline snapshot with no selections"); Debug.Assert(!(_grid.Selected.Rows.Count > 1), "Attempt to baseline snapshot for multiple selections"); if (m_serverInstance != null && Sql.RegisteredServer.IsServerRegistered(m_serverInstance.ConnectionName)) { Sql.Snapshot snap = (Snapshot)_grid.Selected.Rows[0].Cells[colSnapshot].Value; if (Forms.Form_BaselineSnapshot.Process(snap) == DialogResult.OK) { loadDataSource(); } } else { Utility.MsgBox.ShowError(Utility.ErrorMsgs.BaselineSnapshotCaption, Utility.ErrorMsgs.ServerNotRegistered); Program.gController.SignalRefreshServersEvent(false, null); } }
public static void Process( Sql.ObjectTag tag ) { Debug.Assert(tag != null); // Validate input. if (tag == null) { return; } // Retrieve snapshot & its filters. Sql.Snapshot snapshot = null; List <Sql.DataCollectionFilter> filters = null; snapshot = Sql.Snapshot.GetSnapShot(tag.SnapshotId); if (snapshot != null) { if (string.Compare(snapshot.Status, Utility.Snapshot.StatusInProgress) == 0) { Sql.RegisteredServer rServer = Program.gController.Repository.GetServer(snapshot.ConnectionName); if (rServer != null) { rServer.ShowDataCollectionProgress(); } } else { filters = Sql.DataCollectionFilter.GetSnapshotFilters(snapshot.ConnectionName, tag.SnapshotId); // If snapshot retrieved, then display the form. if (snapshot != null && filters != null) { Form_SnapshotProperties form = new Form_SnapshotProperties(snapshot, filters); form.ShowDialog(); } } } }
private void fillUnavailableDatabases(Sql.Snapshot snapshot) { // Get a list of snapshot databases. List <Sql.Database> list = Sql.Database.GetSnapshotDatabases(snapshot.SnapshotId); // Create the data table. DataTable dt = new DataTable(); dt.Columns.Add(colIcon, typeof(Image)); dt.Columns.Add(colDatabase, typeof(string)); dt.Columns.Add(colStatus, typeof(string)); // Fill the grid. int num = 0; Image icon = Sql.ObjectType.TypeImage16(Sql.ObjectType.TypeEnum.Database); foreach (Sql.Database db in list) { if (!db.IsAvailable) { // Increment count. ++num; // Fill data table row. dt.Rows.Add(icon, db.Name, db.Status); } } // Update the counts. _lbl_ItemsUnavailableDatabases.Text = num.ToString() + (num != 1 ? " Items" : " Item"); _lbl_UnavailableDatabases.Text = num.ToString(); // Update the grid. _ultraGridUnavailableDatabases.BeginUpdate(); _ultraGridUnavailableDatabases.DataSource = dt; _ultraGridUnavailableDatabases.DataMember = ""; _ultraGridUnavailableDatabases.EndUpdate(); }
public static DialogResult Process(Sql.Snapshot snapshot) { Form_BaselineSnapshot form = new Form_BaselineSnapshot(snapshot); return(form.ShowDialog()); }
protected void loadData() { m_serverInstance.RefreshServer(); _label_Server.Text = m_serverInstance.ConnectionName; _label_Version.Text = m_serverInstance.VersionFriendlyLong; _label_Edition.Text = m_serverInstance.Edition; //Start-SQLsecure 3.1 (Tushar)--Added support for Azure SQL Database if (m_serverInstance.ServerType == ServerType.AzureSQLDatabase) { _label_Os.Visible = false; } else { _label_Os.Text = m_serverInstance.OS; } //End-SQLsecure 3.1 (Tushar)--Added support for Azure SQL Database _label_CurrentSnapshotTime.Text = m_serverInstance.CurrentCollectionTime; _label_LastSuccessfulTime.Text = m_serverInstance.LastCollectionTime; _label_NextAuditTime.Text = m_serverInstance.NextCollectionTime; _pictureBox_AuditStatus.Image = null; Sql.Snapshot snap = Sql.Snapshot.GetSnapShot(m_serverInstance.LastCollectionSnapshotId); if (snap != null) { _label_Duration.Text = snap.Duration; _label_Objects.Text = snap.NumObject.ToString("n0"); _label_Permissions.Text = snap.NumPermission.ToString("n0"); _label_Logins.Text = snap.NumLogin.ToString("n0"); //Start-SQLsecure 3.1 (Tushar)--Added support for Azure SQL Database if (m_serverInstance.ServerType == ServerType.AzureSQLDatabase) { this._lbl_ND.Text = "Azure AD accounts"; _label_GroupMembers.Text = Convert.ToString(Helper.AzureADUsersAndGroupCount(snap.SnapshotId)); } else { this._lbl_ND.Text = "Windows accounts"; _label_GroupMembers.Text = snap.NumWindowsGroupMember.ToString("n0"); } //End-SQLsecure 3.1 (Tushar)--Added support for Azure SQL Database if (string.Compare(snap.Status, Utility.Snapshot.StatusSuccessful) == 0) { _pictureBox_AuditStatus.Image = AppIcons.AppImage48(AppIcons.EnumImageList48.StatusGood); } else if (string.Compare(snap.Status, Utility.Snapshot.StatusWarning) == 0) { _pictureBox_AuditStatus.Image = AppIcons.AppImage48(AppIcons.EnumImageList48.StatusWarning); } else { _pictureBox_AuditStatus.Image = AppIcons.AppImage48(AppIcons.EnumImageList48.StatusError); } List <Sql.Database> databases = Sql.Database.GetSnapshotDatabases(snap.SnapshotId); if (databases != null) { _label_Databases.Text = databases.Count.ToString(); } else { _label_Databases.Text = String.Empty; } List <Sql.WindowsAccount> accounts = Sql.WindowsAccount.GetSuspectAccounts(snap.SnapshotId); //Start-SQLsecure 3.1 (Tushar)--Added support for Azure SQL Database if (m_serverInstance.ServerType != ServerType.AzureSQLDatabase) { label5.Visible = true; if (accounts != null) { int wellknownaccounts = 0; foreach (Sql.WindowsAccount acct in accounts) { wellknownaccounts += (acct.AccountType == Sql.WindowsAccount.Type.WellKnownGroup) ? 1 : 0; } _label_WellKnownGroups.Text = wellknownaccounts.ToString("n0"); } else { _label_WellKnownGroups.Text = String.Empty; } } else { label5.Visible = false; _label_WellKnownGroups.Visible = false; } if (m_serverInstance.ServerType == ServerType.AzureSQLDatabase) { _lbl_WindowsOS.Visible = false; } else { _lbl_WindowsOS.Visible = true; } //End-SQLsecure 3.1 (Tushar)--Added support for Azure SQL Database } else { _label_Duration.Text = _label_Objects.Text = _label_Permissions.Text = _label_Logins.Text = _label_GroupMembers.Text = _label_Databases.Text = _label_WellKnownGroups.Text = String.Empty; } }
private void loadDataSource() { if (m_policy.IsAssessment) { if (m_server != null) { ((Interfaces.IView)_reportCard).SetContext(new Data.ReportCard(m_policy, m_server)); } else { ((Interfaces.IView)_reportCard).SetContext(new Data.ReportCard(m_policy)); } } else { if (m_server != null) { ((Interfaces.IView)_reportCard).SetContext(new Data.ReportCard(m_policy, m_context.UseBaseline, m_context.SelectionDate, m_server)); } else { ((Interfaces.IView)_reportCard).SetContext(new Data.ReportCard(m_policy, m_context.UseBaseline, m_context.SelectionDate)); } } logX.loggerX.Info("Get " + (m_policy.IsAssessment ? "Assessment" : "Policy") + (m_server == null ? string.Empty : " Server") + " Summary Security Status"); _viewSection_PolicyStatus.SuspendLayout(); _viewSection_PolicyStatus.Title = string.Format(TitleFormat, m_server == null ? (m_policy.IsAssessment ? string.Format(Display_Assessment, m_policy.AssessmentStateName) : Display_Policy) : Display_Server); logX.loggerX.Verbose("Load Assessment Audit Data Selections"); if (m_policy.IsAssessment) { _label_Selections.Text = string.Format(SelectionsFormat, m_policy.UseBaseline ? Display_Baseline : string.Empty); if (m_policy.AssessmentDate.HasValue) { _label_Selections.Text += "\nas of " + m_policy.AssessmentDate.Value.ToLocalTime().ToString(Utility.Constants.DATETIME_FORMAT); } } else { _label_Selections.Text = string.Format(SelectionsFormat, Program.gController.PolicyUseBaselineSnapshots ? Display_Baseline : string.Empty); if (Program.gController.PolicyTime.HasValue) { _label_Selections.Text += "\nas of " + Program.gController.PolicyTime.Value.ToLocalTime().ToString(Utility.Constants.DATETIME_FORMAT); } } try { List <Sql.PolicyMetric> metrics = m_policy.GetPolicyMetrics(Program.gController.Repository.ConnectionString); int high = 0; int medium = 0; int low = 0; logX.loggerX.Verbose("Process Security Check Counts"); foreach (Sql.PolicyMetric metric in metrics) { if (metric.IsEnabled) { if (metric.Severity == (int)Policy.Severity.High) { high++; } if (metric.Severity == (int)Policy.Severity.Medium) { medium++; } if (metric.Severity == (int)Policy.Severity.Low) { low++; } } } logX.loggerX.Verbose("Load " + (m_policy.IsAssessment ? "Assessment" : "Policy") + " Description"); if (m_policy.IsAssessment) { _label_Description.Text = string.IsNullOrEmpty(m_policy.AssessmentDescription) ? m_policy.AssessmentName : m_policy.AssessmentDescription; _toolTip_Description.SetToolTip(_label_Description, string.Format("{0}\n{1}", m_policy.PolicyAssessmentName, m_policy.AssessmentDescription)); } else { _label_Description.Text = string.IsNullOrEmpty(m_policy.PolicyDescription) ? m_policy.PolicyName : m_policy.PolicyDescription; _toolTip_Description.SetToolTip(_label_Description, string.Format("{0}\n{1}", m_policy.PolicyName, m_policy.PolicyDescription)); } // Set the assessment statuses //High logX.loggerX.Verbose("Load " + (m_policy.IsAssessment ? "Assessment" : "Policy") + " High Status Bar"); _pictureBox_SecurityStatusHigh.Image = global::Idera.SQLsecure.UI.Console.Properties.Resources.HighRisk_32; _label_High.Text = string.Format(BarLabelDisplay, DescriptionHelper.GetEnumDescription(Policy.Severity.High)); _label_HighCount.Text = string.Format(BarHighCountDisplay, high); if (high > 0) { _label_HighMsg.Visible = false; _label_HighRiskCount.Text = _reportCard.Risks.RiskCountHigh.ToString(); if (_reportCard.Risks.RiskCountHigh > 0) { _label_HighRiskBar.Width = Convert.ToInt16(BarMax * _reportCard.Risks.RiskCountHigh / high); _label_HighBar.Left = BarLeft + _label_HighRiskBar.Width; _label_HighBar.Width = BarMax - _label_HighRiskBar.Width; } else { _label_HighRiskBar.Width = 0; _label_HighBar.Left = BarLeft; _label_HighBar.Width = BarMax; } _label_HighRiskBar.Visible = _label_HighBar.Visible = true; } else { _label_HighRiskCount.Text = string.Empty; _label_HighMsg.Text = NoMetrics; _label_HighMsg.Visible = true; _label_HighRiskBar.Visible = _label_HighBar.Visible = false; } //Medium logX.loggerX.Verbose("Load " + (m_policy.IsAssessment ? "Assessment" : "Policy") + " Medium Status Bar"); _pictureBox_SecurityStatusMedium.Image = global::Idera.SQLsecure.UI.Console.Properties.Resources.MediumRisk_32; _label_Medium.Text = string.Format(BarLabelDisplay, DescriptionHelper.GetEnumDescription(Policy.Severity.Medium)); _label_MediumCount.Text = string.Format(BarHighCountDisplay, medium); if (medium > 0) { _label_MediumMsg.Visible = false; _label_MediumRiskCount.Text = _reportCard.Risks.RiskCountMedium.ToString(); if (_reportCard.Risks.RiskCountMedium > 0) { _label_MediumRiskBar.Width = Convert.ToInt16(BarMax * _reportCard.Risks.RiskCountMedium / medium); _label_MediumBar.Left = BarLeft + _label_MediumRiskBar.Width; _label_MediumBar.Width = BarMax - _label_MediumRiskBar.Width; } else { _label_MediumRiskBar.Width = 0; _label_MediumBar.Left = BarLeft; _label_MediumBar.Width = BarMax; } _label_MediumRiskBar.Visible = _label_MediumBar.Visible = true; } else { _label_MediumRiskCount.Text = string.Empty; _label_MediumMsg.Text = NoMetrics; _label_MediumMsg.Visible = true; _label_MediumRiskBar.Visible = _label_MediumBar.Visible = false; } //Low logX.loggerX.Verbose("Load " + (m_policy.IsAssessment ? "Assessment" : "Policy") + " Low Status Bar"); _pictureBox_SecurityStatusLow.Image = global::Idera.SQLsecure.UI.Console.Properties.Resources.LowRisk_32; _label_Low.Text = string.Format(BarLabelDisplay, DescriptionHelper.GetEnumDescription(Policy.Severity.Low)); _label_LowCount.Text = string.Format(BarHighCountDisplay, low); if (low > 0) { _label_LowMsg.Visible = false; _label_LowRiskCount.Text = _reportCard.Risks.RiskCountLow.ToString(); if (_reportCard.Risks.RiskCountLow > 0) { _label_LowRiskBar.Width = Convert.ToInt16(BarMax * _reportCard.Risks.RiskCountLow / low); _label_LowBar.Left = BarLeft + _label_LowRiskBar.Width; _label_LowBar.Width = BarMax - _label_LowRiskBar.Width; } else { _label_LowRiskBar.Width = 0; _label_LowBar.Left = BarLeft; _label_LowBar.Width = BarMax; } _label_LowRiskBar.Visible = _label_LowBar.Visible = true; } else { _label_LowRiskCount.Text = string.Empty; _label_LowMsg.Text = NoMetrics; _label_LowMsg.Visible = true; _label_LowRiskBar.Visible = _label_LowBar.Visible = false; } if (m_server == null) { _grid_Servers.SuspendLayout(); m_serverTable.Clear(); logX.loggerX.Verbose("Load " + (m_policy.IsAssessment ? "Assessment" : "Policy") + " Server Counts"); foreach (KeyValuePair <string, ReportCard.RiskCounts> server in _reportCard.ServerRisks) { if (server.Key.Length > 0) { logX.loggerX.Verbose("Loading Server " + server.Key); DataRow row = m_serverTable.NewRow(); row[colSeverity] = server.Value.HighestRiskImage; row[colServer] = server.Key; row[colHigh] = server.Value.RiskCountHigh; row[colMedium] = server.Value.RiskCountMedium; row[colLow] = server.Value.RiskCountLow; row[colStatus] = server.Value.AllRisksText; m_serverTable.Rows.Add(row); } } DataView dv = m_serverTable.DefaultView; dv.Sort = colServer; _grid_Servers.SetDataBinding(m_serverTable.DefaultView, null); _label_Servers.Text = string.Format(HeaderDisplay, dv.Count, dv.Count == 1 ? string.Empty : "s"); _grid_Servers.ResumeLayout(); _viewSection_ServerSummary.Visible = true; _viewSection_ServerInfo.Visible = false; } else { logX.loggerX.Verbose("Load " + (m_policy.IsAssessment ? "Assessment" : "Policy") + " Server Info"); _label_Server.Text = m_server.ConnectionName; _label_Version.Text = m_server.VersionFriendlyLong; _label_Edition.Text = m_server.Edition; _label_Os.Text = m_server.OS; Dictionary <int, int> snapshots = m_policy.PolicySnapshotList; int snapshotId; snapshots.TryGetValue(m_server.RegisteredServerId, out snapshotId); Sql.Snapshot snap = null; if (snapshotId > 0) { snap = Sql.Snapshot.GetSnapShot(snapshotId); } if (snap != null) { _label_Audited.Text = snap.StartTime.ToLocalTime().ToString(Utility.Constants.DATETIME_FORMAT); } else { _label_Audited.Text = @"Unknown"; } _viewSection_ServerInfo.Visible = true; _viewSection_ServerSummary.Visible = false; _grid_Servers.DataSource = null; } } catch (Exception ex) { logX.loggerX.Error(@"Error - Unable to retrieve " + (m_policy.IsAssessment ? "Assessment" : "Policy") + (m_server == null ? string.Empty : " Server") + " summary info", ex); MsgBox.ShowError(string.Format(ErrorMsgs.CantGetPolicyInfoMsg, (m_policy.IsAssessment ? "Assessment" : "Policy") + " Summary Info"), ErrorMsgs.ErrorProcessPolicyInfo, ex); initDataSource(); _grid_Servers.ResumeLayout(); } _viewSection_PolicyStatus.ResumeLayout(); }