diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Exchange2007.cs b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Exchange2007.cs index efa526fd..a056c350 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Exchange2007.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Exchange2007.cs @@ -67,6 +67,7 @@ namespace WebsitePanel.Providers.HostedSolution #region Constants private const string CONFIG_CLEAR_QUERYBASEDN = "WebsitePanel.Exchange.ClearQueryBaseDN"; + private const string CONFIG_ENABLESP2ABP = "WebsitePanel.Exchange.enableSP2abp"; #endregion #region Properties @@ -754,6 +755,7 @@ namespace WebsitePanel.Providers.HostedSolution info.GlobalAddressList = galId; info.OrganizationId = organizationId; info.Database = databaseId; + } catch (Exception ex) { @@ -838,7 +840,21 @@ namespace WebsitePanel.Providers.HostedSolution transaction.RegisterNewOfflineAddressBook(oabId); UpdateOfflineAddressBook(runSpace, oabId, securityGroupId); info.OfflineAddressBook = oabId; - } + + //create ABP + + bool enableSP2abp = false; + if (ConfigurationManager.AppSettings[CONFIG_ENABLESP2ABP] != null) + enableSP2abp = Boolean.Parse(ConfigurationManager.AppSettings[CONFIG_ENABLESP2ABP]); + Version exchangeVersion = GetExchangeVersion(); + + if (enableSP2abp && (exchangeVersion >= new Version(14, 2))) + { + string abpId = CreateAddressPolicy(runSpace, organizationId); + transaction.RegisterNewAddressPolicy(abpId); + ExchangeLog.LogInfo(" Address Policy: {0}", abpId); + } + } catch (Exception ex) { ExchangeLog.LogError("CreateOrganizationOfflineAddressBookInternal", ex); @@ -851,6 +867,8 @@ namespace WebsitePanel.Providers.HostedSolution CloseRunspace(runSpace); } ExchangeLog.LogEnd("CreateOrganizationOfflineAddressBookInternal"); + + return info; } @@ -919,6 +937,30 @@ namespace WebsitePanel.Providers.HostedSolution if (!DeleteOrganizationPublicFolders(runSpace, organizationId)) ret = false; + //delete ABP + + bool enableSP2abp = false; + if (ConfigurationManager.AppSettings[CONFIG_ENABLESP2ABP] != null) + enableSP2abp = Boolean.Parse(ConfigurationManager.AppSettings[CONFIG_ENABLESP2ABP]); + Version exchangeVersion = GetExchangeVersion(); + + if (enableSP2abp && (exchangeVersion >= new Version(14, 2))) + { + + + string adpstring = GetAddressPolicyName(organizationId); + + try + { + if (!string.IsNullOrEmpty(adpstring)) + DeleteAddressPolicy(runSpace, adpstring); + } + catch (Exception ex) + { + ret = false; + ExchangeLog.LogError("Could not delete Address Policy " + globalAddressList, ex); + } + } //delete OAB try @@ -1748,6 +1790,7 @@ namespace WebsitePanel.Providers.HostedSolution int attempts = 0; string id = null; + Version exchangeVersion = GetExchangeVersion(); try @@ -1795,6 +1838,7 @@ namespace WebsitePanel.Providers.HostedSolution //transaction.RegisterNewMailbox(id); string windowsEmailAddress = ObjToString(GetPSObjectProperty(result[0], "WindowsEmailAddress")); + string adpstring = GetAddressPolicyName(organizationId); //update mailbox cmd = new Command("Set-Mailbox"); @@ -1805,6 +1849,12 @@ namespace WebsitePanel.Providers.HostedSolution cmd.Parameters.Add("CustomAttribute3", windowsEmailAddress); cmd.Parameters.Add("PrimarySmtpAddress", upn); cmd.Parameters.Add("WindowsEmailAddress", upn); + + bool enableSP2abp = false; + if (ConfigurationManager.AppSettings[CONFIG_ENABLESP2ABP] != null) + enableSP2abp = Boolean.Parse(ConfigurationManager.AppSettings[CONFIG_ENABLESP2ABP]); + if (enableSP2abp && (exchangeVersion >= new Version(14, 2))) + cmd.Parameters.Add("AddressBookPolicy", adpstring); cmd.Parameters.Add("UseDatabaseQuotaDefaults", new bool?(false)); cmd.Parameters.Add("UseDatabaseRetentionDefaults", false); @@ -1814,6 +1864,8 @@ namespace WebsitePanel.Providers.HostedSolution cmd.Parameters.Add("RetainDeletedItemsFor", ConvertDaysToEnhancedTimeSpan(keepDeletedItemsDays)); ExecuteShellCommand(runSpace, cmd); + + //update AD object string globalAddressListName = this.GetGlobalAddressListName(organizationId); string globalAddressListDN = this.GetGlobalAddressListDN(runSpace, globalAddressListName); @@ -1824,7 +1876,6 @@ namespace WebsitePanel.Providers.HostedSolution bool clearQueryBaseDN = false; if (ConfigurationManager.AppSettings[CONFIG_CLEAR_QUERYBASEDN] != null) clearQueryBaseDN = Boolean.Parse(ConfigurationManager.AppSettings[CONFIG_CLEAR_QUERYBASEDN]); - Version exchangeVersion = GetExchangeVersion(); if (!(clearQueryBaseDN && (exchangeVersion >= new Version(14, 1)))) SetADObjectPropertyValue(mailbox, "msExchQueryBaseDN", globalAddressListDN); @@ -1885,6 +1936,8 @@ namespace WebsitePanel.Providers.HostedSolution ExchangeTransaction transaction = StartTransaction(); Runspace runSpace = null; + Version exchangeVersion = GetExchangeVersion(); + try { runSpace = OpenRunspace(); @@ -1916,6 +1969,7 @@ namespace WebsitePanel.Providers.HostedSolution transaction.RegisterNewMailbox(id); string windowsEmailAddress = ObjToString(GetPSObjectProperty(result[0], "WindowsEmailAddress")); + string adpstring = GetAddressPolicyName(organizationId); //update mailbox cmd = new Command("Set-Mailbox"); @@ -1926,6 +1980,12 @@ namespace WebsitePanel.Providers.HostedSolution cmd.Parameters.Add("CustomAttribute3", windowsEmailAddress); cmd.Parameters.Add("PrimarySmtpAddress", upn); cmd.Parameters.Add("WindowsEmailAddress", upn); + + bool enableSP2abp = false; + if (ConfigurationManager.AppSettings[CONFIG_ENABLESP2ABP] != null) + enableSP2abp = Boolean.Parse(ConfigurationManager.AppSettings[CONFIG_ENABLESP2ABP]); + if (enableSP2abp && (exchangeVersion >= new Version(14, 2))) + cmd.Parameters.Add("AddressBookPolicy", adpstring); cmd.Parameters.Add("UseDatabaseQuotaDefaults", new bool?(false)); cmd.Parameters.Add("UseDatabaseRetentionDefaults", false); @@ -1944,7 +2004,6 @@ namespace WebsitePanel.Providers.HostedSolution bool clearQueryBaseDN = false; if (ConfigurationManager.AppSettings[CONFIG_CLEAR_QUERYBASEDN] != null) clearQueryBaseDN = Boolean.Parse(ConfigurationManager.AppSettings[CONFIG_CLEAR_QUERYBASEDN]); - Version exchangeVersion = GetExchangeVersion(); if (!(clearQueryBaseDN && (exchangeVersion >= new Version(14, 1)))) SetADObjectPropertyValue(mailbox, "msExchQueryBaseDN", globalAddressListDN); @@ -4671,7 +4730,7 @@ namespace WebsitePanel.Providers.HostedSolution #endregion - #region Address Lists (GAL, AL, OAB) + #region Address Lists (GAL, AL, OAB, ABP) private string GetAddressListDN(Runspace runSpace, string id) { @@ -4755,7 +4814,6 @@ namespace WebsitePanel.Providers.HostedSolution ExchangeLog.LogEnd("UpdateAddressList"); } - private void DeleteAddressList(Runspace runSpace, string id) { ExchangeLog.LogStart("DeleteAddressList"); @@ -4814,7 +4872,6 @@ namespace WebsitePanel.Providers.HostedSolution ExchangeLog.LogEnd("UpdateGlobalAddressList"); } - private void DeleteGlobalAddressList(Runspace runSpace, string id) { ExchangeLog.LogStart("DeleteGlobalAddressList"); @@ -4880,6 +4937,41 @@ namespace WebsitePanel.Providers.HostedSolution ExchangeLog.LogEnd("DeleteOfflineAddressBook"); } + private string CreateAddressPolicy(Runspace runSpace, string organizationId) + { + ExchangeLog.LogStart("CreateAddressPolicy"); + + string ABP = GetAddressPolicyName(organizationId); + string AL = GetAddressListName(organizationId); + string GAL = GetGlobalAddressListName(organizationId); + string OAB = GetOfflineAddressBookName(organizationId); + string RL = "All Rooms"; + + Command cmd = new Command("New-AddressBookPolicy"); + cmd.Parameters.Add("Name", ABP); + cmd.Parameters.Add("GlobalAddressList", GAL); + cmd.Parameters.Add("OfflineAddressBook", OAB); + cmd.Parameters.Add("AddressLists", AL); + cmd.Parameters.Add("RoomList", RL); + + + Collection result = ExecuteShellCommand(runSpace, cmd); + string id = GetResultObjectDN(result); + + ExchangeLog.LogEnd("CreateAddressPolicy"); + return id; + } + + private void DeleteAddressPolicy(Runspace runSpace, string id) + { + ExchangeLog.LogStart("DeleteAddressPolicy"); + Command cmd = new Command("Remove-AddressBookPolicy"); + cmd.Parameters.Add("Identity", id); + cmd.Parameters.Add("Confirm", false); + ExecuteShellCommand(runSpace, cmd); + ExchangeLog.LogEnd("DeleteAddressPolicy"); + } + private string GetAddressListName(string orgName) { return orgName + " Address List"; @@ -4894,6 +4986,10 @@ namespace WebsitePanel.Providers.HostedSolution { return orgName + " Offline Address Book"; } + private string GetAddressPolicyName(string orgName) + { + return orgName + " Address Policy"; + } #endregion diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/ExchangeTransaction.cs b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/ExchangeTransaction.cs index 503d1343..7708ca78 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/ExchangeTransaction.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/ExchangeTransaction.cs @@ -84,6 +84,14 @@ namespace WebsitePanel.Providers.HostedSolution action.Id = id; Actions.Add(action); } + internal void RegisterNewAddressPolicy(string id) + { + TransactionAction action = new TransactionAction(); + action.ActionType = TransactionAction.TransactionActionTypes.CreateAddressPolicy; + action.Id = id; + Actions.Add(action); + } + internal void RegisterNewOfflineAddressBook(string id) { @@ -220,6 +228,7 @@ namespace WebsitePanel.Providers.HostedSolution CreateOrganizationUnit, CreateGlobalAddressList, CreateAddressList, + CreateAddressPolicy, CreateOfflineAddressBook, CreateDistributionGroup, EnableDistributionGroup, diff --git a/WebsitePanel/Sources/WebsitePanel.Server/Web.config b/WebsitePanel/Sources/WebsitePanel.Server/Web.config index 0006cf32..dace3aed 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server/Web.config +++ b/WebsitePanel/Sources/WebsitePanel.Server/Web.config @@ -8,6 +8,8 @@ + +