示例#1
0
        private static void GatherConfiguredDirectories(List <DirectorySearchInfo> searchDirectories, List <string> toIgnore, string[] searchDirList, bool full)
        {
            if (searchDirList.Count() > 0)
            {
                foreach (string dir in searchDirList)
                {
                    string[] parts = dir.Split('|');
                    string   d     = parts[0];

                    //Get the file types to search for as configured for the directory
                    List <string> fTypes = ExtractFileTypesFromSearchDirs(parts);

                    //Add configured directory
                    if (IgnoreMethods.IgnorePath(toIgnore, d) == false)
                    {
                        Console.ForegroundColor = ConsoleColor.Gray;
                        Console.WriteLine(d);
                        Console.ResetColor();
                        AddSearchDirectory(searchDirectories, d, fTypes, toIgnore);
                    }

                    if (full == true)
                    {
                        //Get all the subdirectories
                        List <string> subDirs = new List <string>();
                        GetSubDirs(d, toIgnore, subDirs);
                        foreach (string subD in subDirs)
                        {
                            AddSearchDirectory(searchDirectories, subD, fTypes, toIgnore);
                        }
                    }
                }
            }
        }
示例#2
0
 private static void AddSearchDirectory(List <DirectorySearchInfo> searchDirectories, string dir, List <string> fTypes, List <string> toIgnore)
 {
     if (IgnoreMethods.IgnorePath(toIgnore, dir) == false)
     {
         searchDirectories.Add(new DirectorySearchInfo
         {
             DirPath   = dir,
             FileTypes = fTypes
         });
     }
 }
示例#3
0
        public static List <string> GatherFilesToAnalyze()
        {
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine();
            Console.WriteLine("Searching for files in the following directories...");
            Console.ResetColor();

            List <string> searchFiles = new List <string>();

            List <DirectorySearchInfo> searchDirList = GatherDirectoriesToSearch();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine();
            Console.WriteLine(searchDirList.Count() + " directories found");
            Console.ResetColor();

            //Get a list of files to ignore from the config file
            List <string> toIgnore = IgnoreMethods.GetIgnoreFiles();

            foreach (DirectorySearchInfo dir in searchDirList)
            {
                foreach (string fType in dir.FileTypes)
                {
                    try
                    {
                        foreach (string f in Directory.GetFiles(dir.DirPath, "*" + fType, SearchOption.TopDirectoryOnly))
                        {
                            FileInfo fi = new FileInfo(f);
                            if (IgnoreMethods.IgnorePath(toIgnore, fi.Name) == false)
                            {
                                searchFiles.Add(f);
                            }
                        }
                    }
                    catch (System.UnauthorizedAccessException ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine(ex.Message);
                        Console.ResetColor();

                        Program.Report.UnauthorizedDirectories.Add(ex.Message);
                    }
                }
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine();
            Console.WriteLine(searchFiles.Count() + " files found.");
            Console.WriteLine();
            Console.ResetColor();

            return(searchFiles);
        }
示例#4
0
        private static List <DirectorySearchInfo> GatherDirectoriesToSearch()
        {
            List <DirectorySearchInfo> searchDirectories = new List <DirectorySearchInfo>();

            //Get a list of directories to ignore from the config file
            List <string> toIgnore = IgnoreMethods.GetIgnoreDirectories();

            toIgnore.Add("FileContentChecks");
            toIgnore.Add("ConfigCopPages");

            //Get the file types to search for as configured for the directory
            List <string> fTypes = HelperMethods.CheckConfiguration("fileTypes").Split(',').ToList <string>();

            //Add passed directory or working directory if none was passed
            if (IgnoreMethods.IgnorePath(toIgnore, Program.SearchDir) == false)
            {
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine(Program.SearchDir);
                Console.ResetColor();
                AddSearchDirectory(searchDirectories, Program.SearchDir, fTypes, toIgnore);
            }

            //Get all the subdirectories
            List <string> subDirs = new List <string>();

            GetSubDirs(Program.SearchDir, toIgnore, subDirs);
            foreach (string subD in subDirs)
            {
                AddSearchDirectory(searchDirectories, subD, fTypes, toIgnore);
            }

            //Get all the additional directories to search from the config file
            string fullSearchDirs = HelperMethods.CheckConfiguration("searchDirsFull");

            if (!string.IsNullOrEmpty(fullSearchDirs))
            {
                string[] searchDirListFull = fullSearchDirs.Split(';');
                GatherConfiguredDirectories(searchDirectories, toIgnore, searchDirListFull, true);
            }
            string topSearchDirs = HelperMethods.CheckConfiguration("searchDirsTopOnly");

            if (!string.IsNullOrEmpty(topSearchDirs))
            {
                string[] searchDirListTop = topSearchDirs.Split(';');
                GatherConfiguredDirectories(searchDirectories, toIgnore, searchDirListTop, false);
            }

            return(searchDirectories);
        }
示例#5
0
        private static List <string> GetSubDirs(string parent, List <string> toIgnore, List <string> subDirs)
        {
            if (IgnoreMethods.IgnorePath(toIgnore, parent) == false)
            {
                try
                {
                    //Get all the subdirectories
                    var dirList = Directory.EnumerateDirectories(parent, "*", SearchOption.AllDirectories);
                    foreach (string d in dirList)
                    {
                        if (IgnoreMethods.IgnorePath(toIgnore, d) == false)
                        {
                            try
                            {
                                var test = Directory.GetDirectories(d, "*", SearchOption.TopDirectoryOnly);
                                subDirs.Add(d);
                                GetSubDirs(d, toIgnore, subDirs);
                            }
                            catch (System.UnauthorizedAccessException ex)
                            {
                                Console.ForegroundColor = ConsoleColor.Yellow;
                                Console.WriteLine(ex.Message);
                                Console.ResetColor();

                                Program.Report.UnauthorizedDirectories.Add(ex.Message);
                            }
                        }
                    }
                }
                catch (System.UnauthorizedAccessException ex)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine(ex.Message);
                    Console.ResetColor();

                    Program.Report.UnauthorizedDirectories.Add(ex.Message);
                }
                catch (DirectoryNotFoundException ex)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine(ex.Message);
                    Console.ResetColor();

                    Program.Report.UnauthorizedDirectories.Add(ex.Message);
                }
            }

            return(subDirs);
        }
示例#6
0
        public static void CheckForDatabaseServerDiscrepancies(string line, int lineNumber)
        {
            List <DBServerInfo> dbServers = GetAllDatabaseServers();

            foreach (DBServerInfo dbi in dbServers)
            {
                if (IgnoreMethods.Ignore(dbi.Name) == false || IgnoreMethods.Ignore(dbi.Port) == false || IgnoreMethods.Ignore(dbi.Region) == false)
                {
                    if (line.ToUpper().Contains(dbi.Name.ToUpper()))
                    {
                        TestServerRegion(lineNumber, dbi, line);
                        TestDBServerConnection(line, lineNumber, dbi);
                    }
                }
            }
        }
示例#7
0
        public static void CheckForRegionDiscrepancies(string line, int lineNumber)
        {
            bool error = false;

            string[] regions = HelperMethods.CheckConfiguration("regions").Split(',');
            foreach (string r in regions)
            {
                if (IgnoreMethods.Ignore(r) == false)
                {
                    error = LineContainsRegion(line, error, r);

                    if (error == true)
                    {
                        Errors.RegionDiscrepancy(lineNumber, r, line);
                    }
                }
            }
        }
示例#8
0
        static void Main(string[] args)
        {
            IgnoreMethods.GetIgnores();
            EndpointMethods.GetBrowseObjects();
            AppSettingsCollection = new List <AppSettingInfo>();
            InstantiateReport();

            SearchDir = "";
            Region    = "";
            //Testing
            //args = ".,dev2".Split(',');
            //SearchDir = ".";
            //Region = "dev2";
            SetArgs(args);
            StartAnalysis();
            WriteReport();
            //Console.ReadLine();
        }
示例#9
0
        private static void StartAnalysis()
        {
            List <string> searchFiles = FileCollectionMethods.GatherFilesToAnalyze();

            if (searchFiles != null && searchFiles.Count() > 0)
            {
                foreach (string f in searchFiles)
                {
                    FileInfo fi = new FileInfo(f);
                    if (!fi.Name.ToUpper().StartsWith("CONFIGCOP"))
                    {
                        InstantiateCurrentFile(fi);

                        FileContentCompareMethods.CompareFileContents(fi);

                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.WriteLine();
                        Console.WriteLine("Analyzing " + f);
                        Console.ForegroundColor = ConsoleColor.Gray;
                        Console.WriteLine("Last Modified: " + fi.LastWriteTime);
                        Console.WriteLine();
                        Console.ResetColor();

                        IgnoreMethods.GetIgnoresForFile(fi.FullName);

                        if (HelperMethods.ValidateXML(fi) == true)
                        {
                            ExtractLinesXML(fi);
                        }
                        else
                        {
                            ExtractLinesStd(fi);
                        }

                        Report.AlalyzedFiles.Add(CurrentFile);
                    }
                }
            }

            GeneralConfigCheckMethods.CheckForDuplicateKeys();
        }
示例#10
0
        private static void TestConnection(string line, int lineNumber, string p)
        {
            string endpoint = ExtractEndpoint(line, p);

            if (IgnoreMethods.Ignore(endpoint) == false)
            {
                TestedConnection tc = HelperMethods.ConnectionTested(endpoint);
                if (tc != null)
                {
                    Errors.ConnectivityError(lineNumber, endpoint, tc.Reason, tc.StatusCode, tc.ConType);
                }
                else
                {
                    try
                    {
                        WebRequest request = WebRequest.Create(endpoint);
                        request.UseDefaultCredentials = true;
                        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                        int    sc;
                        string reason;
                        switch (response.StatusCode)
                        {
                        case HttpStatusCode.OK:
                            sc     = Errors.GetStatusCode("HttpStatusCode.OK");
                            reason = "Request succeeded.  HTTP status 200.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.Accepted:
                            sc     = Errors.GetStatusCode("HttpStatusCode.Accepted");
                            reason = "Request has been accepted for further processing.  HTTP status 202.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.Continue:
                            sc     = Errors.GetStatusCode("HttpStatusCode.Continue");
                            reason = "Client can continue with request.  HTTP status 100.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.Created:
                            sc     = Errors.GetStatusCode("HttpStatusCode.Created");
                            reason = "New resource was created before the response was sent.  HTTP status 201.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.Redirect:
                            sc     = Errors.GetStatusCode("HttpStatusCode.Redirect");
                            reason = "Requested information was found but redirected.  HTTP status 302.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.Unauthorized:
                            sc     = Errors.GetStatusCode("HttpStatusCode.Unauthorized");
                            reason = Environment.UserName + " isn't authorized to access this url.  HTTP status 401.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.ServiceUnavailable:
                            sc     = Errors.GetStatusCode("HttpStatusCode.ServiceUnavailable");
                            reason = "Service Unavailable.  HTTP status 503.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.RequestUriTooLong:
                            sc     = Errors.GetStatusCode("HttpStatusCode.RequestUriTooLong");
                            reason = "Url is too long.  HTTP status 414.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.RequestEntityTooLarge:
                            sc     = Errors.GetStatusCode("HttpStatusCode.RequestEntityTooLarge");
                            reason = "Request entity is too large.  HTTP status 413.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.ProxyAuthenticationRequired:
                            sc     = Errors.GetStatusCode("HttpStatusCode.ProxyAuthenticationRequired");
                            reason = "Authentication is required.  Manually verify that " + Environment.UserName + " can access this endpoint.  HTTP status 407.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.Moved:
                            sc     = Errors.GetStatusCode("HttpStatusCode.Moved");
                            reason = "The endpoint has moved.  Contact NOG for the correct url.  HTTP status 301.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.Ambiguous:
                            sc     = Errors.GetStatusCode("HttpStatusCode.Ambiguous");
                            reason = "The request has multiple representtions.  Setting the defualt document for this endpoint may resolve the issue.  HTTP status 300.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.BadGateway:
                            sc     = Errors.GetStatusCode("HttpStatusCode.BadGateway");
                            reason = "Bad Gateway.  HTTP status 502.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.BadRequest:
                            sc     = Errors.GetStatusCode("HttpStatusCode.BadRequest");
                            reason = "Bad request.  HTTP status 400.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.Conflict:
                            sc     = Errors.GetStatusCode("HttpStatusCode.Conflict");
                            reason = "Conflict on the server.  HTTP status 409.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.ExpectationFailed:
                            sc     = Errors.GetStatusCode("HttpStatusCode.ExpectationFailed");
                            reason = "Expectation given in the Expect header could not be met by the server.  HTTP status 417.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.Forbidden:
                            sc     = Errors.GetStatusCode("HttpStatusCode.Forbidden");
                            reason = "Forbidden.  HTTP status 403.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.GatewayTimeout:
                            sc     = Errors.GetStatusCode("HttpStatusCode.GatewayTimeout");
                            reason = "Proxy server timed out while waiting for a response.  HTTP status 504.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.Gone:
                            sc     = Errors.GetStatusCode("HttpStatusCode.Gone");
                            reason = "Requested resource is no longer available.  HTTP status 410.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.HttpVersionNotSupported:
                            sc     = Errors.GetStatusCode("HttpStatusCode.HttpVersionNotSupported");
                            reason = "HTTP version not supported.  HTTP status 505.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.InternalServerError:
                            sc     = Errors.GetStatusCode("HttpStatusCode.InternalServerError");
                            reason = "Internal server error.  HTTP status 500.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.LengthRequired:
                            sc     = Errors.GetStatusCode("HttpStatusCode.LengthRequired");
                            reason = "Content Length header is missing.  HTTP status 411.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.MethodNotAllowed:
                            sc     = Errors.GetStatusCode("HttpStatusCode.MethodNotAllowed");
                            reason = "Request method not allowed.  HTTP status 405.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.NoContent:
                            sc     = Errors.GetStatusCode("HttpStatusCode.NoContent");
                            reason = "Response is intentionally blank.  HTTP status 204.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.NonAuthoritativeInformation:
                            sc     = Errors.GetStatusCode("HttpStatusCode.NonAuthoritativeInformation");
                            reason = "Response may be from a chached copy and not from the origin server.  HTTP status 203.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.NotAcceptable:
                            sc     = Errors.GetStatusCode("HttpStatusCode.NotAcceptable");
                            reason = "Client's Accept headers will not accept any available representations of the resource.  HTTP status 406.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.NotFound:
                            sc     = Errors.GetStatusCode("HttpStatusCode.NotFound");
                            reason = "Requested resource could not be found.  HTTP status 404.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.NotImplemented:
                            sc     = Errors.GetStatusCode("HttpStatusCode.NotImplemented");
                            reason = "Server does not support the requested function.  HTTP status 501.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.NotModified:
                            sc     = Errors.GetStatusCode("HttpStatusCode.NotModified");
                            reason = "Cached copy is up to date, endpoint response wasn't transferred.  HTTP status 304.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.PartialContent:
                            sc     = Errors.GetStatusCode("HttpStatusCode.PartialContent");
                            reason = "Received partial response.  HTTP status 206.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.PaymentRequired:
                            sc     = Errors.GetStatusCode("HttpStatusCode.PaymentRequired");
                            reason = "Payment Required.  HTTP status 402.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.PreconditionFailed:
                            sc     = Errors.GetStatusCode("HttpStatusCode.PreconditionFailed");
                            reason = "Precondition failed.  HTTP status 412.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.RedirectKeepVerb:
                            sc     = Errors.GetStatusCode("HttpStatusCode.RedirectKeepVerb");
                            reason = "Resource was found but was redirected with the same method.  HTTP status 307.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.RedirectMethod:
                            sc     = Errors.GetStatusCode("HttpStatusCode.RedirectMethod");
                            reason = "Redirected as a result of the POST.  HTTP status 303.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.RequestedRangeNotSatisfiable:
                            sc     = Errors.GetStatusCode("HttpStatusCode.RequestedRangeNotSatisfiable");
                            reason = "Range of data requested could not be returned.  HTTP status 416.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.RequestTimeout:
                            sc     = Errors.GetStatusCode("HttpStatusCode.RequestTimeout");
                            reason = "Request timed out.  HTTP status 408.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.ResetContent:
                            sc     = Errors.GetStatusCode("HttpStatusCode.ResetContent");
                            reason = "Client should reset the current resource.  HTTP status 205.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.SwitchingProtocols:
                            sc     = Errors.GetStatusCode("HttpStatusCode.SwitchingProtocols");
                            reason = "Protocol was changed.  HTTP status 101.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.UnsupportedMediaType:
                            sc     = Errors.GetStatusCode("HttpStatusCode.UnsupportedMediaType");
                            reason = "Response was an unsupported media type.  HTTP status 415.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.Unused:
                            sc     = Errors.GetStatusCode("HttpStatusCode.Unused");
                            reason = "Unspecified error.  HTTP status 306.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        case HttpStatusCode.UseProxy:
                            sc     = Errors.GetStatusCode("HttpStatusCode.UseProxy");
                            reason = "Request should use proxy server located in the Location header.  HTTP status 305.";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;

                        default:
                            sc     = Errors.GetStatusCode("HttpStatusCode.Default");
                            reason = "Connection Failed";
                            ReportConnectivityError(lineNumber, endpoint, sc, reason);
                            break;
                        }

                        response.Close();
                    }
                    catch (WebException ex)
                    {
                        int    sc     = Errors.GetStatusCode("HttpStatusCode.Default");
                        string reason = ex.Message;
                        ReportConnectivityError(lineNumber, endpoint, sc, reason);
                    }
                }
            }
        }