Esempio n. 1
0
 public string GetSIDFilteringStatus(MigrationChecker migrationChecker)
 {
     if (migrationChecker != null)
     {
         if (migrationChecker.IsMigrationTrust(Source.ReferenceDate, Source.Domain, Destination.Domain))
         {
             return("Migration");
         }
     }
     if (TrustDirection == 1)
     {
         return("Remote");
     }
     return(TrustAnalyzer.GetSIDFiltering(TrustDirection, TrustAttributes));
 }
Esempio n. 2
0
        public bool IsEquivalentToReverseEdge(MigrationChecker migrationChecker)
        {
            if (TrustDirection != 3)
            {
                return(false);
            }
            // when there is a bidirectional trust, there are two GraphEdge
            // one starting from source and one starting from the other domain
            GraphEdge reverseEdge = Destination.Trusts[Source.Domain];

            if (reverseEdge.TrustAttributes == TrustAttributes &&
                GetSIDFilteringStatus(migrationChecker) == reverseEdge.GetSIDFilteringStatus(migrationChecker))
            {
                return(true);
            }
            return(false);
        }
Esempio n. 3
0
        /// <summary>
        ///     Проверяет установленные миграции исходя из параметров командной строки
        /// </summary>
        /// <param name="options">Опции командной строки</param>
        /// <returns>Результат проверки миграций</returns>
        private static string Check(DbManagerOptions options)
        {
            Logger.Info("Проверка установленных миграций : ");

            var migrationChecker = new MigrationChecker <TContext>(new TMigrationConfig());

            if (!string.IsNullOrEmpty(options.Migration))
            {
                return(migrationChecker.CheckByMigrationName(options.Migration));
            }

            if (!string.IsNullOrEmpty(options.Version))
            {
                return(migrationChecker.CheckByVersion(options.Version));
            }

            return(migrationChecker.CheckLastMigration());
        }
Esempio n. 4
0
        public string GenerateJsonFileChordDiagram(MigrationChecker migrationChecker)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("[");
            bool firstnode = true;

            foreach (GraphNode node in Nodes)
            {
                if (!firstnode)
                {
                    sb.AppendLine(",");
                }
                else
                {
                    firstnode = false;
                }
                sb.Append("    {");
                sb.Append("      \"name\": \"" + ReportHelper.EscapeJsonString(node.Domain.DomainName) + "\"");
                if (node.IsPotentiallyRemoved)
                {
                    sb.Append("      ,\"potentiallyremoved\": 1");
                }
                var entity = node.Entity;
                if (entity != null)
                {
                    sb.Append(entity.GetJasonOutput());
                }
                HealthcheckData data = node.HealthCheckData;
                if (data != null)
                {
                    sb.Append("      ,\"score\": " + data.GlobalScore);
                    sb.Append("      ,\"maturityLevel\": " + data.MaturityLevel);
                    sb.Append("      ,\"staleObjectsScore\": " + data.StaleObjectsScore);
                    sb.Append("      ,\"privilegiedGroupScore\": " + data.PrivilegiedGroupScore);
                    sb.Append("      ,\"trustScore\": " + data.TrustScore);
                    sb.Append("      ,\"anomalyScore\": " + data.AnomalyScore);
                    if (data.UserAccountData != null)
                    {
                        sb.Append("      ,\"activeusers\": " + data.UserAccountData.NumberActive);
                    }
                    if (data.ComputerAccountData != null)
                    {
                        sb.Append("      ,\"activecomputers\": " + data.ComputerAccountData.NumberActive);
                    }
                }
                sb.Append("      ,\"trusts\": [");
                bool firstTrust = true;
                foreach (var edge in node.Trusts.Values)
                {
                    var destination = edge.Destination;
                    if (!firstTrust)
                    {
                        sb.Append(",");
                    }
                    else
                    {
                        firstTrust = false;
                    }
                    sb.Append("    {");
                    sb.Append("\"name\": \"");
                    sb.Append(ReportHelper.EscapeJsonString(destination.Domain.DomainName));
                    sb.Append("\"");
                    var entity2 = destination.Entity;
                    if (entity2 != null)
                    {
                        sb.Append(entity2.GetJasonOutput());
                    }
                    sb.Append("}");
                }
                sb.Append("]");
                sb.Append("}");
            }

            sb.AppendLine("]");
            return(sb.ToString());
        }
Esempio n. 5
0
        public string GenerateJsonFileFull(MigrationChecker migrationChecker)
        {
            Dictionary <int, int> idconversiontable = new Dictionary <int, int>();
            StringBuilder         sb = new StringBuilder();

            sb.Append("{");
            // START OF NODES

            sb.Append("  \"nodes\": [");
            // it is important to put the root node as the first node for correct display
            int  nodenumber = 0;
            bool firstnode  = true;

            foreach (GraphNode node in Nodes)
            {
                if (!firstnode)
                {
                    sb.Append("    },");
                }
                else
                {
                    firstnode = false;
                }
                sb.Append("    {");
                sb.Append("      \"id\": " + nodenumber + ",");
                var nodeShortName = !string.IsNullOrEmpty(node.Domain.DomainNetBIOS) ? node.Domain.DomainNetBIOS : (node.Domain.DomainName.Split('.')[0]);
                sb.Append("      \"shortname\": \"" + ReportHelper.EscapeJsonString(nodeShortName) + "\"");
                if (node.IsPartOfARealForest())
                {
                    sb.Append("      ,\"forest\": \"" + ReportHelper.EscapeJsonString(node.Forest.DomainName) + "\"");
                }
                if (node.IsPotentiallyRemoved)
                {
                    sb.Append("      ,\"potentiallyremoved\": 1");
                }
                var entity = node.Entity;
                if (entity != null)
                {
                    sb.Append(entity.GetJasonOutput());
                }
                HealthcheckData data = node.HealthCheckData;
                sb.Append("      ,\"name\": \"" + ReportHelper.EscapeJsonString(node.Domain.DomainName) + "\"");
                if (data != null)
                {
                    sb.Append("      ,\"score\": " + data.GlobalScore);
                    sb.Append("      ,\"maturityLevel\": " + data.MaturityLevel);
                    sb.Append("      ,\"staleObjectsScore\": " + data.StaleObjectsScore);
                    sb.Append("      ,\"privilegiedGroupScore\": " + data.PrivilegiedGroupScore);
                    sb.Append("      ,\"trustScore\": " + data.TrustScore);
                    sb.Append("      ,\"anomalyScore\": " + data.AnomalyScore);
                    if (data.UserAccountData != null)
                    {
                        sb.Append("      ,\"activeusers\": " + data.UserAccountData.NumberActive);
                    }
                    if (data.ComputerAccountData != null)
                    {
                        sb.Append("      ,\"activecomputers\": " + data.ComputerAccountData.NumberActive);
                    }
                }
                sb.Append("      ,\"dist\": null");
                idconversiontable[node.Id] = nodenumber++;
            }
            if (Nodes.Count > 0)
            {
                sb.Append("    }");
            }
            sb.Append("  ],");
            // END OF NODES
            // START LINKS
            sb.Append("  \"links\": [");
            // avoid a final ","
            bool absenceOfLinks = true;
            // subtility: try to regroup 2 links at one if all the properties match
            // SkipLink contains the edge to ignore
            List <GraphEdge> SkipLink = new List <GraphEdge>();

            // foreach edge
            foreach (GraphNode node in Nodes)
            {
                foreach (GraphEdge edge in node.Trusts.Values)
                {
                    if (SkipLink.Contains(edge))
                    {
                        continue;
                    }
                    // for unidirectional trusts
                    // keep only the remote part of the trust. SID Filtering is unknown (avoid evaluating SID Filtering when no value is available)
                    if (edge.TrustDirection == 2 && edge.IsAuthoritative == false)
                    {
                        continue;
                    }
                    // keep only the reception of the trust. SID Filtering status is sure
                    if (edge.TrustDirection == 1 && edge.Destination.Trusts[edge.Source.Domain].IsAuthoritative == true)
                    {
                        continue;
                    }
                    // trying to simplify bidirectional trusts
                    bool isBidirectional = false;
                    if (edge.IsEquivalentToReverseEdge(migrationChecker))
                    {
                        GraphEdge reverseEdge = edge.Destination.Trusts[edge.Source.Domain];
                        // keep only one of the two part of the bidirectional trust
                        SkipLink.Add(reverseEdge);
                        isBidirectional = true;
                    }
                    if (!absenceOfLinks)
                    {
                        sb.Append("    },");
                    }
                    else
                    {
                        absenceOfLinks = false;
                    }
                    sb.Append("    {");
                    if (edge.TrustDirection == 2)
                    {
                        sb.Append("      \"source\": " + idconversiontable[edge.Destination.Id] + ",");
                        sb.Append("      \"target\": " + idconversiontable[edge.Source.Id] + ",");
                    }
                    else
                    {
                        sb.Append("      \"source\": " + idconversiontable[edge.Source.Id] + ",");
                        sb.Append("      \"target\": " + idconversiontable[edge.Destination.Id] + ",");
                    }
                    // blue: 25AEE4
                    // orange: FA9426
                    string sidFiltering = edge.GetSIDFilteringStatus(migrationChecker);
                    if (!edge.IsActive)
                    {
                        // purple
                        sb.Append("      \"color\": \"#A856AA\",");
                    }
                    else
                    {
                        switch (sidFiltering)
                        {
                        case "Remote":
                            // yellow
                            sb.Append("      \"color\": \"#FDC334\",");
                            break;

                        case "Migration":
                            // blue
                            sb.Append("      \"color\": \"#25AEE4\",");
                            break;

                        case "No":
                            // red
                            sb.Append("      \"color\": \"#E75351\",");
                            break;

                        case "Yes":
                            // green
                            sb.Append("      \"color\": \"#74C25C\",");
                            break;
                        }
                    }
                    if (isBidirectional)
                    {
                        sb.Append("      \"type\": \"double\",");
                    }
                    sb.Append("      \"rels\": [\"");
                    sb.Append("Attributes=" + edge.GetTrustAttributes() + ",");
                    if (edge.CreationDate != DateTime.MinValue)
                    {
                        sb.Append("CreationDate=" + edge.CreationDate.ToString("yyyy-MM-dd") + ",");
                    }
                    sb.Append("SIDFiltering=" + sidFiltering);
                    sb.Append((edge.IsActive ? null : ",Inactive"));
                    sb.Append("\"]");
                }
            }
            if (!absenceOfLinks)
            {
                sb.Append("    }");
            }
            sb.Append("  ]");
            // END OF LINKS
            sb.Append("}");
            return(sb.ToString());
        }