diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Web.config b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Web.config index 3766094f..6c7d9d64 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Web.config +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Web.config @@ -5,11 +5,19 @@ - + + - - + + + diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/ActiveDirectoryUtils.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/ActiveDirectoryUtils.cs index 3c460dbb..ac11cdef 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/ActiveDirectoryUtils.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/ActiveDirectoryUtils.cs @@ -159,6 +159,14 @@ namespace WebsitePanel.Providers.HostedSolution collection.Value = value; } + public static void SetADObjectPropertyValue(DirectoryEntry oDE, string name, string[] values) + { + PropertyValueCollection collection = oDE.Properties[name]; + collection.Value = values; + } + + + public static void SetADObjectPropertyValue(DirectoryEntry oDE, string name, Guid value) { PropertyValueCollection collection = oDE.Properties[name]; @@ -177,6 +185,19 @@ namespace WebsitePanel.Providers.HostedSolution return entry.Properties.Contains(name) ? entry.Properties[name][0] : null; } + public static string[] GetADObjectPropertyMultiValue(DirectoryEntry entry, string name) + { + if (!entry.Properties.Contains(name)) + return null; + + List returnList = new List(); + for (int i = 0; i < entry.Properties[name].Count; i++) + returnList.Add(entry.Properties[name][i].ToString()); + + return returnList.ToArray(); + } + + public static string GetADObjectStringProperty(DirectoryEntry entry, string name) { object ret = GetADObjectProperty(entry, name); diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Exchange2007.cs b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Exchange2007.cs index 8f2f63e1..a338e30c 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Exchange2007.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Exchange2007.cs @@ -2591,7 +2591,7 @@ namespace WebsitePanel.Providers.HostedSolution Command cmd = new Command("Set-Mailbox"); cmd.Parameters.Add("Identity", accountName); cmd.Parameters.Add("PrimarySmtpAddress", primaryEmail); - cmd.Parameters.Add("UserPrincipalName", primaryEmail); + //cmd.Parameters.Add("UserPrincipalName", primaryEmail); cmd.Parameters.Add("WindowsEmailAddress", primaryEmail); ExecuteShellCommand(runSpace, cmd); diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Lync2010.cs b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Lync2010.cs index 33c56efe..944788a5 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Lync2010.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Lync2010.cs @@ -288,11 +288,14 @@ namespace WebsitePanel.Providers.HostedSolution Guid tenantId = (Guid)GetPSObjectProperty(result[0], "TenantId"); // create sip domain - DeleteSipDomain(runSpace, sipDomain); - - //clear the msRTCSIP-Domains, TenantID, ObjectID string path = AddADPrefix(GetOrganizationPath(organizationId)); DirectoryEntry ou = ActiveDirectoryUtils.GetADObject(path); + string[] sipDs = (string[])ActiveDirectoryUtils.GetADObjectPropertyMultiValue(ou, "msRTCSIP-Domains"); + + foreach (string sipD in sipDs) + DeleteSipDomain(runSpace, sipD); + + //clear the msRTCSIP-Domains, TenantID, ObjectID ActiveDirectoryUtils.ClearADObjectPropertyValue(ou, "msRTCSIP-Domains"); ActiveDirectoryUtils.ClearADObjectPropertyValue(ou, "msRTCSIP-TenantId"); ActiveDirectoryUtils.ClearADObjectPropertyValue(ou, "msRTCSIP-ObjectId"); @@ -383,11 +386,56 @@ namespace WebsitePanel.Providers.HostedSolution { tenantId = (Guid)GetPSObjectProperty(result[0], "TenantId"); + string[] tmp = userUpn.Split('@'); + if (tmp.Length < 2) return false; + + // Get SipDomains and verify existence + bool bSipDomainExists = false; + cmd = new Command("Get-CsSipDomain"); + Collection sipDomains = ExecuteShellCommand(runSpace, cmd, false); + + foreach (PSObject domain in sipDomains) + { + string d = (string)GetPSObjectProperty(domain, "Name"); + if (d.ToLower() == tmp[1].ToLower()) + { + bSipDomainExists = true; + break; + } + } + + string path = string.Empty; + + if (!bSipDomainExists) + { + // Create Sip Domain + cmd = new Command("New-CsSipDomain"); + cmd.Parameters.Add("Identity", tmp[1].ToLower()); + ExecuteShellCommand(runSpace, cmd, false); + + transaction.RegisterNewSipDomain(tmp[1].ToLower()); + + + path = AddADPrefix(GetOrganizationPath(organizationId)); + DirectoryEntry ou = ActiveDirectoryUtils.GetADObject(path); + string[] sipDs = (string[])ActiveDirectoryUtils.GetADObjectPropertyMultiValue(ou, "msRTCSIP-Domains"); + List listSipDs = new List(); + listSipDs.AddRange(sipDs); + listSipDs.Add(tmp[1]); + + ActiveDirectoryUtils.SetADObjectPropertyValue(ou, "msRTCSIP-Domains", listSipDs.ToArray()); + ou.CommitChanges(); + + //Create simpleurls + CreateSimpleUrl(runSpace, tmp[1].ToLower(), tenantId); + transaction.RegisterNewSimpleUrl(tmp[1].ToLower(), tenantId.ToString()); + } + //enable for lync cmd = new Command("Enable-CsUser"); cmd.Parameters.Add("Identity", userUpn); cmd.Parameters.Add("RegistrarPool", PoolFQDN); - cmd.Parameters.Add("SipAddressType", "UserPrincipalName"); + cmd.Parameters.Add("SipAddressType", "EmailAddress"); ExecuteShellCommand(runSpace, cmd); transaction.RegisterNewCsUser(userUpn); @@ -397,13 +445,11 @@ namespace WebsitePanel.Providers.HostedSolution cmd.Parameters.Add("Identity", userUpn); result = ExecuteShellCommand(runSpace, cmd); - - string path = AddADPrefix(GetResultObjectDN(result)); + path = AddADPrefix(GetResultObjectDN(result)); DirectoryEntry user = ActiveDirectoryUtils.GetADObject(path); ActiveDirectoryUtils.SetADObjectPropertyValue(user, "msRTCSIP-GroupingID", tenantId); ActiveDirectoryUtils.SetADObjectPropertyValue(user, "msRTCSIP-TenantId", tenantId); - string[] tmp = userUpn.Split('@'); if (tmp.Length > 0) { string Url = SimpleUrlRoot + tmp[1];