/// <summary> /// Set IP(s)|Domain(s) into SMTP Server /// This method is used to insert multiple IPs or DNS entries into the Relay Restriction List in IIS /// </summary> /// <param name="sMetabasePath">IIS://localhost/smtpsvc/1</param> /// <param name="sMethodName">Get|Put</param> /// <param name="sMethodArgument">IPSecurity|RelayIPList</param> /// <param name="sMember">IPGrant|IPDeny|DomainGrant|DomainDeny</param> /// <param name="list">List of IP(s)\Domain(s)</param> /// public static Result SetIpSecurityPropertyArray(String sMetabasePath, String sMethodName, String sMethodArgument, String sMember, List <EntityIpDomain> list) { List <EntityIpDomain> relayList = IisIntegration.GetIpSecurityPropertyArray(IisIntegration.METABASE, MethodName.Get, MethodArgument.IPSecurity, Member.IPGrant); using (DirectoryEntry directoryEntry = new DirectoryEntry(sMetabasePath)) { try { directoryEntry.RefreshCache(); _oIpSecurity = directoryEntry.Invoke(sMethodName, new[] { sMethodArgument }); Type typeIpSecurityType = _oIpSecurity.GetType(); Object[] newList = new object[list.Count + relayList.Count]; Int32 iCounter = 0; foreach (EntityIpDomain item in list) { newList[iCounter] = item.IpDomain; iCounter++; } foreach (EntityIpDomain item in relayList) { newList[iCounter] = item.IpDomain; iCounter++; } // add the updated list back to the IPSecurity object typeIpSecurityType.InvokeMember(sMember, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null, _oIpSecurity, new object[] { newList }); directoryEntry.Properties[sMethodArgument][0] = _oIpSecurity; // commit the changes directoryEntry.CommitChanges(); directoryEntry.RefreshCache(); return(Result.OK); } catch (Exception ex) { log.Error(string.Format("Błąd podczas importowania listy adresów z serwera SMTP: \"{0}\"", ex.Message)); return(Result.Failure); } } }
static int Main(string[] args) { if (args.Length == 1) { switch (Environment.GetCommandLineArgs()[1].ToLower()) { case "--status": { IisIntegration.PrintSmtpServerStatus(METABASE); break; } case "--stop": { IisIntegration.StopSmtpServer(METABASE); break; } case "--start": { IisIntegration.StartSmtpServer(METABASE); break; } case "--restart": { IisIntegration.RestartSmtpServer(METABASE); break; } case "--synchronize": { FileSupport.Synchronize(); break; } case "--help": { PrintHelp(); break; } default: { PrintHelp(); return(0); } } } else if (args.Length == 2) { switch (Environment.GetCommandLineArgs()[1].ToLower()) { case "--exportfromims": { List <EntityIpDomain> imsList = Ims.GetList(); FileSupport.ExportToFile(Environment.GetCommandLineArgs()[2].Trim(), imsList, true); break; } case "--export": { List <EntityIpDomain> relayList = IisIntegration.GetIpSecurityPropertyArray(IisIntegration.METABASE, MethodName.Get, MethodArgument.IPSecurity, Member.IPGrant); FileSupport.ExportToFile(Environment.GetCommandLineArgs()[2].Trim(), relayList, true); break; } case "--import": { FileSupport.ImportFromFile(Environment.GetCommandLineArgs()[2].Trim()); break; } case "--add": { FileSupport.AddFromArg(Environment.GetCommandLineArgs()[2].Trim()); break; } case "--compareimstorelay": { List <EntityIpDomain> diffList = Lists.GetDifference(Ims.GetList(), IisIntegration.GetIpSecurityPropertyArray(IisIntegration.METABASE, MethodName.Get, MethodArgument.IPSecurity, Member.IPGrant)); FileSupport.ExportToFile(Environment.GetCommandLineArgs()[2].Trim(), diffList, true); break; } case "--comparerelaytoims": { List <EntityIpDomain> diffList = Lists.GetDifference(IisIntegration.GetIpSecurityPropertyArray(IisIntegration.METABASE, MethodName.Get, MethodArgument.IPSecurity, Member.IPGrant), Ims.GetList()); FileSupport.ExportToFile(Environment.GetCommandLineArgs()[2].Trim(), diffList, true); break; } default: { PrintHelp(); return(0); } } } else { PrintHelp(); return(0); } return(0); }