Esempio n. 1
0
        private static List <EntityIpDomain> GetListFromFile(string myFileName)
        {
            List <EntityIpDomain> list = new List <EntityIpDomain>();
            string line;

            try
            {
                using (System.IO.StreamReader file = new System.IO.StreamReader(myFileName))
                {
                    while ((line = file.ReadLine()) != null)
                    {
                        string ip = ParseAddress.GetLine(line.Replace("\"", "").Replace(" ", ""));

                        if (!string.IsNullOrEmpty(ip))
                        {
                            list.Add(new EntityIpDomain {
                                IpDomain = ip
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string ErrorDescription = string.Format("\nBłąd podczas odczytu pliku!!!\n{0}", ex.Message);
                Console.WriteLine(ErrorDescription);
                log.Error(ErrorDescription);
                Mail.Send("*****@*****.**", "", "", string.Format("ERROR!!! Błąd podczas pobierania listy z pliku {0}.", myFileName), string.Format("Błąd podczas pobierania listy z pliku {0}.\n{1}", myFileName, ex.Message));
            }

            return(list);
        }
Esempio n. 2
0
        internal static void AddFromArg(string hostIp)
        {
            try
            {
                ErrorDescription = string.Empty;
                List <EntityIpDomain> newList     = new List <EntityIpDomain>();
                List <EntityIpDomain> currentList = IisIntegration.GetIpSecurityPropertyArray(IisIntegration.METABASE, MethodName.Get, MethodArgument.IPSecurity, Member.IPGrant);

                string ip = ParseAddress.GetLine(hostIp.Replace("\"", "").Replace(" ", ""));

                if (!string.IsNullOrEmpty(ip))
                {
                    Result result = IisIntegration.SetIpSecurityPropertySingle(IisIntegration.METABASE, MethodName.Get, MethodArgument.IPSecurity, Member.IPGrant, ip, out currentList, out newList);

                    switch (result)
                    {
                    case Result.Failure:
                        Console.WriteLine(ErrorDescription = string.Format("Błąd podczas importu adresu IP: {0}", ip));
                        log.Error(ErrorDescription);
                        break;

                    case Result.NotExist:
                        break;

                    case Result.Exist:
                        Console.WriteLine(ErrorDescription = string.Format("Adres IP: \"{0}\" już jest dodany do listy relay.", ip));
                        log.Info(ErrorDescription);
                        break;

                    case Result.OK:
                        Console.WriteLine(ErrorDescription = string.Format("Zaimportowano adres IP: \"{0}\"", ip));
                        log.Info(ErrorDescription);
                        break;
                    }
                }
                else
                {
                    Console.WriteLine(ErrorDescription = string.Format("Nieprawidłowy format adresu: \"{0}\"", ip));
                    log.Error(ErrorDescription);
                }
            }
            catch (Exception ex)
            {
                ErrorDescription = string.Format("Nie udało się dodać adresu IP: {0}", ex.Message);
                Console.WriteLine(ErrorDescription);
                log.Error(ErrorDescription);
            }
        }
Esempio n. 3
0
        internal static List <EntityIpDomain> Zip(List <EntityIpDomain> baseList, List <EntityIpDomain> toCmpList)
        {
            Array baseArray = ToArray(baseList);
            Array imsArray  = ToArray(toCmpList);

            foreach (string ip in imsArray)
            {
                if (Array.IndexOf(baseArray, ip) < 0)
                {
                    if (!string.IsNullOrEmpty(ParseAddress.GetLine(ip)))
                    {
                        baseList.Add(new EntityIpDomain {
                            IpDomain = ip
                        });
                    }
                }
            }

            return(baseList);
        }