Work item 175

Exchange Accepted Domain can be switched
between Authoritative and InternalRelay
This commit is contained in:
rdolezel 2012-09-11 22:09:03 +02:00
parent e1c7c4b18f
commit 7bc0cc88fa
18 changed files with 382 additions and 16 deletions

View file

@ -6508,6 +6508,7 @@ CREATE TABLE [dbo].[ExchangeOrganizationDomains](
[ItemID] [int] NOT NULL,
[DomainID] [int] NULL,
[IsHost] [bit] NULL,
[DomainTypeID] [int] NOT NULL,
CONSTRAINT [PK_ExchangeOrganizationDomains] PRIMARY KEY CLUSTERED
(
[OrganizationDomainID] ASC
@ -6634,7 +6635,8 @@ AS
SELECT
ED.DomainID,
D.DomainName,
ED.IsHost
ED.IsHost,
ED.DomainTypeID
FROM
ExchangeOrganizationDomains AS ED
INNER JOIN Domains AS D ON ED.DomainID = D.DomainID
@ -45799,6 +45801,29 @@ GO
CREATE PROCEDURE [dbo].ChangeExchangeAcceptedDomainType
(
@ItemID int,
@DomainID int,
@DomainTypeID int
)
AS
UPDATE ExchangeOrganizationDomains
SET DomainTypeID=@DomainTypeID
WHERE ItemID=ItemID AND DomainID=@DomainID
RETURN
GO
@ -46064,6 +46089,8 @@ ALTER TABLE [dbo].[ExchangeOrganizationDomains] CHECK CONSTRAINT [FK_ExchangeOrg
GO
ALTER TABLE [dbo].[ExchangeOrganizationDomains] ADD CONSTRAINT [DF_ExchangeOrganizationDomains_IsHost] DEFAULT ((0)) FOR [IsHost]
GO
ALTER TABLE [dbo].[ExchangeOrganizationDomains] ADD CONSTRAINT [DF_ExchangeOrganizationDomains_DomainTypeID] DEFAULT ((0)) FOR [DomainTypeID]
GO
ALTER TABLE [dbo].[PrivateIPAddresses] WITH CHECK ADD CONSTRAINT [FK_PrivateIPAddresses_ServiceItems] FOREIGN KEY([ItemID])
REFERENCES [dbo].[ServiceItems] ([ItemID])
ON DELETE CASCADE

View file

@ -5211,6 +5211,66 @@ GO
IF NOT EXISTS(select 1 from sys.columns COLS INNER JOIN sys.objects OBJS ON OBJS.object_id=COLS.object_id and OBJS.type='U' AND OBJS.name='ExchangeOrganizationDomains' AND COLS.name='DomainTypeID')
BEGIN
ALTER TABLE [dbo].[ExchangeOrganizationDomains] ADD
[DomainTypeID] [int] NOT NULL CONSTRAINT DF_ExchangeOrganizationDomains_DomainTypeID DEFAULT 0
END
GO
ALTER PROCEDURE [dbo].[GetExchangeOrganizationDomains]
(
@ItemID int
)
AS
SELECT
ED.DomainID,
D.DomainName,
ED.IsHost,
ED.DomainTypeID
FROM
ExchangeOrganizationDomains AS ED
INNER JOIN Domains AS D ON ED.DomainID = D.DomainID
WHERE ED.ItemID = @ItemID
RETURN
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE type_desc = N'SQL_STORED_PROCEDURE' AND name = N'ChangeExchangeAcceptedDomainType')
BEGIN
EXEC sp_executesql N'
CREATE PROCEDURE [dbo].ChangeExchangeAcceptedDomainType
(
@ItemID int,
@DomainID int,
@DomainTypeID int
)
AS
UPDATE ExchangeOrganizationDomains
SET DomainTypeID=@DomainTypeID
WHERE ItemID=ItemID AND DomainID=@DomainID
RETURN'
END
GO
ALTER PROCEDURE [dbo].[GetPackages]
(
@ActorID int,

View file

@ -736,6 +736,17 @@ namespace WebsitePanel.EnterpriseServer.HostedSolution {
return ((int)(results[0]));
}
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/ChangeOrganizationDomainType", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public int ChangeOrganizationDomainType(int itemId, int domainId, ExchangeAcceptedDomainType newDomainType)
{
object[] results = this.Invoke("ChangeOrganizationDomainType", new object[] {
itemId,
domainId,
newDomainType});
return ((int)(results[0]));
}
/// <remarks/>
public System.IAsyncResult BeginDeleteOrganizationDomain(int itemId, int domainId, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("DeleteOrganizationDomain", new object[] {

View file

@ -2152,6 +2152,18 @@ namespace WebsitePanel.EnterpriseServer
);
}
public static void ChangeExchangeAcceptedDomainType(int itemId, int domainId, int domainTypeId)
{
SqlHelper.ExecuteNonQuery(
ConnectionString,
CommandType.StoredProcedure,
"ChangeExchangeAcceptedDomainType",
new SqlParameter("@ItemID", itemId),
new SqlParameter("@DomainID", domainId),
new SqlParameter("@DomainTypeID", domainTypeId)
);
}
public static IDataReader GetExchangeOrganizationStatistics(int itemId)
{
return SqlHelper.ExecuteReader(

View file

@ -446,6 +446,10 @@ namespace WebsitePanel.EnterpriseServer
{
hubTransportRole.AddAuthoritativeDomain(domain.DomainName);
}
if (domain.DomainType != ExchangeAcceptedDomainType.Authoritative)
{
hubTransportRole.ChangeAcceptedDomainType(domain.DomainName, domain.DomainType);
}
}
authDomainCreated = true;
break;
@ -1424,7 +1428,63 @@ namespace WebsitePanel.EnterpriseServer
}
}
public static int ChangeAcceptedDomainType(int itemId, int domainId, ExchangeAcceptedDomainType domainType)
{
// check account
int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
if (accountCheck < 0) return accountCheck;
// place log record
TaskManager.StartTask("EXCHANGE", "CHANGE_DOMAIN_TYPE");
TaskManager.TaskParameters["Domain ID"] = domainId;
TaskManager.TaskParameters["Domain Type"] = domainType.ToString();
TaskManager.ItemId = itemId;
try
{
// load organization
Organization org = (Organization)PackageController.GetPackageItem(itemId);
if (org == null)
return -1;
// load domain
DomainInfo domain = ServerController.GetDomain(domainId);
if (domain == null)
return -1;
int[] hubTransportServiceIds;
int[] clientAccessServiceIds;
int exchangeServiceId = GetExchangeServiceID(org.PackageId);
GetExchangeServices(exchangeServiceId, out hubTransportServiceIds, out clientAccessServiceIds);
foreach (int id in hubTransportServiceIds)
{
ExchangeServer hubTransportRole = null;
try
{
hubTransportRole = GetExchangeServer(id, org.ServiceId);
}
catch (Exception ex)
{
TaskManager.WriteError(ex);
continue;
}
hubTransportRole.ChangeAcceptedDomainType(domain.DomainName, domainType);
break;
}
return 0;
}
catch (Exception ex)
{
throw TaskManager.WriteError(ex);
}
finally
{
TaskManager.CompleteTask();
}
}
public static int DeleteAuthoritativeDomain(int itemId, int domainId)
{

View file

@ -1042,6 +1042,37 @@ namespace WebsitePanel.EnterpriseServer
}
}
public static int ChangeOrganizationDomainType(int itemId, int domainId, ExchangeAcceptedDomainType newDomainType)
{
// check account
int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
if (accountCheck < 0) return accountCheck;
// place log record
TaskManager.StartTask("ORGANIZATION", "CHANGE_DOMAIN_TYPE", domainId);
TaskManager.ItemId = itemId;
try
{
// change accepted domain type on Exchange
int checkResult = ExchangeServerController.ChangeAcceptedDomainType(itemId, domainId, newDomainType);
// change accepted domain type in DB
int domainTypeId= (int) newDomainType;
DataProvider.ChangeExchangeAcceptedDomainType(itemId, domainId, domainTypeId);
return checkResult;
}
catch (Exception ex)
{
throw TaskManager.WriteError(ex);
}
finally
{
TaskManager.CompleteTask();
}
}
public static int AddOrganizationDomain(int itemId, string domainName)
{

View file

@ -122,6 +122,12 @@ namespace WebsitePanel.EnterpriseServer
return OrganizationController.AddOrganizationDomain(itemId, domainName);
}
[WebMethod]
public int ChangeOrganizationDomainType(int itemId, int domainId, ExchangeAcceptedDomainType newDomainType)
{
return OrganizationController.ChangeOrganizationDomainType(itemId, domainId, newDomainType);
}
[WebMethod]
public List<OrganizationDomainName> GetOrganizationDomains(int itemId)
{

View file

@ -0,0 +1,37 @@
// Copyright (c) 2012, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace WebsitePanel.Providers.HostedSolution
{
public enum ExchangeAcceptedDomainType
{
Authoritative = 0,
InternalRelay = 1,
ExternalRelay = 2
}
}

View file

@ -53,6 +53,7 @@ namespace WebsitePanel.Providers.HostedSolution
// Domains
void AddAuthoritativeDomain(string domain);
void DeleteAuthoritativeDomain(string domain);
void ChangeAcceptedDomainType(string domain, ExchangeAcceptedDomainType domainType);
string[] GetAuthoritativeDomains();
// Mailboxes

View file

@ -26,6 +26,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
namespace WebsitePanel.Providers.HostedSolution
{
public class OrganizationDomainName
@ -33,6 +34,7 @@ namespace WebsitePanel.Providers.HostedSolution
int organizationDomainId;
int itemId;
int domainId;
int domainTypeId;
string domainName;
bool isHost;
bool isDefault;
@ -55,6 +57,21 @@ namespace WebsitePanel.Providers.HostedSolution
set { domainId = value; }
}
public int DomainTypeId
{
get { return domainTypeId; }
set { domainTypeId = value; }
}
public ExchangeAcceptedDomainType DomainType
{
get
{
ExchangeAcceptedDomainType type = (ExchangeAcceptedDomainType)domainTypeId;
return type;
}
}
public int OrganizationDomainId
{
get { return organizationDomainId; }

View file

@ -80,6 +80,7 @@
<Compile Include="HostedSolution\BlackBerryErrorsCodes.cs" />
<Compile Include="HostedSolution\BlackBerryStatsItem.cs" />
<Compile Include="HostedSolution\BlackBerryUserDeleteState.cs" />
<Compile Include="HostedSolution\ExchangeAcceptedDomainType.cs" />
<Compile Include="HostedSolution\ExchangeMailboxPlanType.cs" />
<Compile Include="HostedSolution\ExchangeMailboxPlan.cs" />
<Compile Include="HostedSolution\ILyncServer.cs" />

View file

@ -230,6 +230,11 @@ namespace WebsitePanel.Providers.HostedSolution
{
DeleteAuthoritativeDomainInternal(domain);
}
public void ChangeAcceptedDomainType(string domainName, ExchangeAcceptedDomainType domainType)
{
ChangeAcceptedDomainTypeInternal(domainName, domainType);
}
#endregion
#region Mailboxes
@ -5916,6 +5921,31 @@ namespace WebsitePanel.Providers.HostedSolution
ExchangeLog.LogEnd("CreateAuthoritativeDomainInternal");
}
private void ChangeAcceptedDomainTypeInternal(string domainName, ExchangeAcceptedDomainType domainType)
{
ExchangeLog.LogStart("ChangeAcceptedDomainType");
Runspace runSpace = null;
try
{
runSpace = OpenRunspace();
SetAcceptedDomainType(runSpace, domainName,domainType);
}
catch (Exception ex)
{
ExchangeLog.LogError("ChangeAcceptedDomainType", ex);
throw;
}
finally
{
CloseRunspace(runSpace);
}
ExchangeLog.LogEnd("ChangeAcceptedDomainType");
}
private void DeleteAcceptedDomain(string domainName)
{
ExchangeLog.LogStart("DeleteAcceptedDomain");
@ -5980,6 +6010,17 @@ namespace WebsitePanel.Providers.HostedSolution
ExchangeLog.LogEnd("RemoveAcceptedDomain");
}
private void SetAcceptedDomainType(Runspace runSpace, string id, ExchangeAcceptedDomainType domainType)
{
ExchangeLog.LogStart("SetAcceptedDomainType");
Command cmd = new Command("Set-AcceptedDomain");
cmd.Parameters.Add("Identity", id);
cmd.Parameters.Add("DomainType", domainType.ToString());
cmd.Parameters.Add("Confirm", false);
ExecuteShellCommand(runSpace, cmd);
ExchangeLog.LogEnd("SetAcceptedDomainType");
}
#endregion
#region ActiveSync

View file

@ -1033,6 +1033,16 @@ namespace WebsitePanel.Providers.Exchange
domain});
}
/// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/ChangeAcceptedDomainType", RequestNamespace = "http://smbsaas/websitepanel/server/", ResponseNamespace = "http://smbsaas/websitepanel/server/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public void ChangeAcceptedDomainType(string domain, ExchangeAcceptedDomainType domainType)
{
this.Invoke("ChangeAcceptedDomainType", new object[] {
domain,
domainType});
}
/// <remarks/>
public System.IAsyncResult BeginAddAuthoritativeDomain(string domain, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("AddAuthoritativeDomain", new object[] {

View file

@ -265,6 +265,21 @@ namespace WebsitePanel.Server
}
}
[WebMethod, SoapHeader("settings")]
public void ChangeAcceptedDomainType(string domain, ExchangeAcceptedDomainType domainType)
{
try
{
LogStart("ChangeAcceptedDomainType");
ES.ChangeAcceptedDomainType(domain, domainType);
LogEnd("ChangeAcceptedDomainType");
}
catch (Exception ex)
{
LogError("ChangeAcceptedDomainType", ex);
throw;
}
}
[WebMethod, SoapHeader("settings")]
public string[] GetAuthoritativeDomains()

View file

@ -33,7 +33,7 @@
Width="100%" EmptyDataText="gvDomains" CssSelectorClass="NormalGridView" OnRowCommand="gvDomains_RowCommand">
<Columns>
<asp:TemplateField HeaderText="gvDomainsName">
<ItemStyle Width="70%"></ItemStyle>
<ItemStyle Width="50%"></ItemStyle>
<ItemTemplate>
<asp:hyperlink id="lnkEditZone" runat="server" EnableViewState="false"
NavigateUrl='<%# GetDomainRecordsEditUrl(Eval("DomainID").ToString()) %>' Enabled='<%# !(bool)Eval("IsHost") %>'>
@ -41,6 +41,20 @@
</asp:hyperlink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="gvDomainsType">
<ItemTemplate>
<div style="text-align:center">
<asp:Label ID="Label1" Text='<%# Eval("DomainType") %>' runat="server"/>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="gvDomainsTypeChange">
<ItemTemplate>
<div style="text-align:center">
<asp:Button ID="btnChange" text="Change" meta:resourcekey="cmdChange" runat="server" CommandName="Change" CommandArgument='<%# Eval("DomainId") + "|" + Eval("DomainType") %>'/>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="gvDomainsDefault">
<ItemTemplate>
<div style="text-align:center">

View file

@ -117,6 +117,37 @@ namespace WebsitePanel.Portal.ExchangeServer
ShowErrorMessage("EXCHANGE_DELETE_DOMAIN", ex);
}
}
else if (e.CommandName == "Change")
{
string[] commandArgument = e.CommandArgument.ToString().Split('|');
int domainId = Utils.ParseInt(commandArgument[0].ToString(), 0);
ExchangeAcceptedDomainType acceptedDomainType = (ExchangeAcceptedDomainType)Enum.Parse(typeof(ExchangeAcceptedDomainType), commandArgument[1]);
try
{
ExchangeAcceptedDomainType newDomainType = ExchangeAcceptedDomainType.Authoritative;
if (acceptedDomainType == ExchangeAcceptedDomainType.Authoritative)
newDomainType = ExchangeAcceptedDomainType.InternalRelay;
int result = ES.Services.Organizations.ChangeOrganizationDomainType(PanelRequest.ItemID, domainId, newDomainType);
if (result < 0)
{
messageBox.ShowResultMessage(result);
return;
}
// rebind domains
BindDomainNames();
BindStats();
}
catch (Exception ex)
{
ShowErrorMessage("EXCHANGE_CHANGE_DOMAIN", ex);
}
}
}
protected void btnSetDefaultDomain_Click(object sender, EventArgs e)
@ -143,5 +174,6 @@ namespace WebsitePanel.Portal.ExchangeServer
ShowErrorMessage("EXCHANGE_SET_DEFAULT_DOMAIN", ex);
}
}
}
}

View file

@ -110,14 +110,5 @@ namespace WebsitePanel.Portal.ExchangeServer {
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::WebsitePanel.Portal.QuotaViewer domainsQuota;
/// <summary>
/// FormComments control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Localize FormComments;
}
}