DOmain Pointers adjusted:
When creating a new website the GlobalDNSRecord configuration defines the hostheaders/websitepointer to be created Various forms updated where the hostname field is set to www GlobalDNSRecord allows empty recordData field To create related dns records when creating a hostheader/website pointer with the specification of a hostname a 'A' or 'CNAME' globalDNSRecord definition of '[host_name]' is required to create the the dns record.
This commit is contained in:
parent
b54e810508
commit
9c9337ab94
14 changed files with 217 additions and 237 deletions
|
@ -240,13 +240,12 @@ namespace WebsitePanel.EnterpriseServer
|
|||
ipAddr = !String.IsNullOrEmpty(ip.InternalIP) ? ip.InternalIP : ip.ExternalIP;
|
||||
|
||||
// load domain instant alias
|
||||
/*
|
||||
/*
|
||||
string instantAlias = ServerController.GetDomainAlias(packageId, domainName);
|
||||
DomainInfo instantDomain = ServerController.GetDomain(instantAlias);
|
||||
if (instantDomain == null || instantDomain.WebSiteId > 0)
|
||||
instantAlias = "";
|
||||
*/
|
||||
|
||||
*/
|
||||
// load web DNS records
|
||||
List<GlobalDnsRecord> dnsRecords = ServerController.GetDnsRecordsByService(serviceId);
|
||||
|
||||
|
@ -257,17 +256,18 @@ namespace WebsitePanel.EnterpriseServer
|
|||
{
|
||||
// SHARED IP
|
||||
// fill main domain bindings
|
||||
/*
|
||||
FillWebServerBindings(bindings, dnsRecords, ipAddr, domain.DomainName);
|
||||
FillWebServerBindings(bindings, dnsRecords, ipAddr, hostName, domain.DomainName, false);
|
||||
|
||||
// fill alias bindings if required
|
||||
/*
|
||||
if (addInstantAlias && !String.IsNullOrEmpty(instantAlias))
|
||||
{
|
||||
// fill bindings from DNS "A" records
|
||||
FillWebServerBindings(bindings, dnsRecords, ipAddr, instantAlias);
|
||||
FillWebServerBindings(bindings, dnsRecords, ipAddr, "", instantAlias);
|
||||
}
|
||||
*/
|
||||
bindings.Add(new ServerBinding(ipAddr, "80", siteName));
|
||||
|
||||
//bindings.Add(new ServerBinding(ipAddr, "80", siteName));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -396,9 +396,9 @@ namespace WebsitePanel.EnterpriseServer
|
|||
// add instant pointer
|
||||
/*
|
||||
if (addInstantAlias && !String.IsNullOrEmpty(instantAlias))
|
||||
AddWebSitePointer(siteItemId, instantDomain.DomainId, false);
|
||||
*/
|
||||
|
||||
AddWebSitePointer(siteItemId, "", instantDomain.DomainId, false);
|
||||
*/
|
||||
|
||||
// add parking page
|
||||
// load package
|
||||
if (webPolicy["AddParkingPage"] != null)
|
||||
|
@ -573,12 +573,12 @@ namespace WebsitePanel.EnterpriseServer
|
|||
// remove all web site pointers
|
||||
List<DomainInfo> pointers = GetWebSitePointers(siteItemId);
|
||||
foreach (DomainInfo pointer in pointers)
|
||||
DeleteWebSitePointer(siteItemId, pointer.DomainId, false);
|
||||
DeleteWebSitePointer(siteItemId, pointer.DomainId, false, true);
|
||||
|
||||
// remove web site main pointer
|
||||
DomainInfo domain = ServerController.GetDomain(siteItem.Name);
|
||||
if(domain != null)
|
||||
DeleteWebSitePointer(siteItemId, domain.DomainId, false);
|
||||
DeleteWebSitePointer(siteItemId, domain.DomainId, false, true);
|
||||
|
||||
// delete web site
|
||||
WebServer web = new WebServer();
|
||||
|
@ -611,7 +611,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
}
|
||||
|
||||
private static void FillWebServerBindings(List<ServerBinding> bindings, List<GlobalDnsRecord> dnsRecords,
|
||||
string ipAddr, string hostName, string domainName)
|
||||
string ipAddr, string hostName, string domainName, bool ignoreGlobalDNSRecords)
|
||||
// TODO test if IPv6 works
|
||||
{
|
||||
int bindingsCount = bindings.Count;
|
||||
|
@ -628,25 +628,52 @@ namespace WebsitePanel.EnterpriseServer
|
|||
*/
|
||||
|
||||
string tmpName = string.Empty;
|
||||
if (!String.IsNullOrEmpty(hostName))
|
||||
tmpName = Utils.ReplaceStringVariable(dnsRecord.RecordName, "host_name", hostName);
|
||||
|
||||
string recordData = string.Empty;
|
||||
if (tmpName.Contains("."))
|
||||
recordData = hostName;
|
||||
else
|
||||
recordData = tmpName + ((tmpName != "") ? "." : "") + domainName;
|
||||
tmpName = Utils.ReplaceStringVariable(dnsRecord.RecordName, "host_name", hostName);
|
||||
|
||||
bindings.Add(new ServerBinding(ipAddr, "80", recordData));
|
||||
if (!(tmpName== "[host_name]"))
|
||||
{
|
||||
string recordData = string.Empty;
|
||||
if (tmpName.Contains("."))
|
||||
recordData = hostName;
|
||||
else
|
||||
recordData = tmpName + ((tmpName != "") ? "." : "") + domainName;
|
||||
|
||||
|
||||
if (ignoreGlobalDNSRecords)
|
||||
{
|
||||
if (dnsRecord.RecordName == "[host_name]")
|
||||
{
|
||||
AddBinding(bindings, new ServerBinding(ipAddr, "80", recordData));
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AddBinding(bindings, new ServerBinding(ipAddr, "80", recordData));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(bindings.Count == bindingsCount)
|
||||
|
||||
if ((bindings.Count == bindingsCount) | (bindings.Count == 0))
|
||||
{
|
||||
bindings.Add(new ServerBinding(ipAddr, "80", string.IsNullOrEmpty(hostName) ? domainName : hostName + "." + domainName));
|
||||
AddBinding(bindings, new ServerBinding(ipAddr, "80", string.IsNullOrEmpty(hostName) ? domainName : hostName + "." + domainName));
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddBinding(List<ServerBinding> bindings, ServerBinding binding)
|
||||
{
|
||||
foreach (ServerBinding b in bindings)
|
||||
{
|
||||
if (string.Compare(b.Host, binding.Host, true) == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
bindings.Add(binding);
|
||||
}
|
||||
|
||||
|
||||
private static string GetWebSiteUsername(UserSettings webPolicy, string domainName)
|
||||
{
|
||||
UsernamePolicy policy = new UsernamePolicy(webPolicy["AnonymousAccountPolicy"]);
|
||||
|
@ -732,10 +759,15 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
public static int AddWebSitePointer(int siteItemId, string hostName, int domainId)
|
||||
{
|
||||
return AddWebSitePointer(siteItemId, hostName, domainId, true);
|
||||
return AddWebSitePointer(siteItemId, hostName, domainId, true, true);
|
||||
}
|
||||
|
||||
internal static int AddWebSitePointer(int siteItemId, string hostName, int domainId, bool updateWebSite)
|
||||
{
|
||||
return AddWebSitePointer(siteItemId, hostName, domainId, updateWebSite, false);
|
||||
}
|
||||
|
||||
internal static int AddWebSitePointer(int siteItemId, string hostName, int domainId, bool updateWebSite, bool ignoreGlobalDNSRecords)
|
||||
{
|
||||
// check account
|
||||
int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
|
||||
|
@ -772,14 +804,39 @@ namespace WebsitePanel.EnterpriseServer
|
|||
{
|
||||
// load appropriate zone
|
||||
DnsZone zone = (DnsZone)PackageController.GetPackageItem(domain.ZoneItemId);
|
||||
|
||||
|
||||
if (zone != null)
|
||||
{
|
||||
// change DNS zone
|
||||
List<GlobalDnsRecord> tmpDnsRecords = new List<GlobalDnsRecord>();
|
||||
|
||||
string serviceIp = (ip != null) ? ip.ExternalIP : null;
|
||||
|
||||
if (ignoreGlobalDNSRecords)
|
||||
{
|
||||
foreach (GlobalDnsRecord r in dnsRecords)
|
||||
{
|
||||
if (r.RecordName == "[host_name]")
|
||||
tmpDnsRecords.Add(r);
|
||||
}
|
||||
}
|
||||
else
|
||||
tmpDnsRecords = dnsRecords;
|
||||
|
||||
|
||||
List<DnsRecord> resourceRecords = DnsServerController.BuildDnsResourceRecords(
|
||||
dnsRecords, hostName, domain.DomainName, serviceIp);
|
||||
tmpDnsRecords, hostName, domain.DomainName, serviceIp);
|
||||
|
||||
foreach (DnsRecord r in resourceRecords)
|
||||
{
|
||||
if (r.RecordName != "*")
|
||||
{
|
||||
// check if the web site already exists
|
||||
if (DataProvider.CheckDomain(domain.PackageId, string.IsNullOrEmpty(r.RecordName) ? domain.DomainName : r.RecordName + "." + domain.DomainName, true) != 0)
|
||||
return BusinessErrorCodes.ERROR_WEB_SITE_ALREADY_EXISTS;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -796,56 +853,57 @@ namespace WebsitePanel.EnterpriseServer
|
|||
}
|
||||
|
||||
// update host headers
|
||||
if (updateWebSite)
|
||||
List<ServerBinding> bindings = new List<ServerBinding>();
|
||||
|
||||
// get existing web site bindings
|
||||
WebServer web = new WebServer();
|
||||
ServiceProviderProxy.Init(web, siteItem.ServiceId);
|
||||
|
||||
bindings.AddRange(web.GetSiteBindings(siteItem.SiteId));
|
||||
|
||||
// check if web site has dedicated IP assigned
|
||||
bool dedicatedIp = bindings.Exists(binding => { return String.IsNullOrEmpty(binding.Host) && binding.IP != "*"; });
|
||||
|
||||
// update binding only for "shared" ip addresses
|
||||
if (!dedicatedIp)
|
||||
{
|
||||
// get existing web site bindings
|
||||
WebServer web = new WebServer();
|
||||
ServiceProviderProxy.Init(web, siteItem.ServiceId);
|
||||
// add new host headers
|
||||
string ipAddr = "*";
|
||||
if (ip != null)
|
||||
ipAddr = !String.IsNullOrEmpty(ip.InternalIP) ? ip.InternalIP : ip.ExternalIP;
|
||||
|
||||
List<ServerBinding> bindings = new List<ServerBinding>();
|
||||
bindings.AddRange(web.GetSiteBindings(siteItem.SiteId));
|
||||
// fill bindings
|
||||
FillWebServerBindings(bindings, dnsRecords, ipAddr, hostName, domain.DomainName, ignoreGlobalDNSRecords);
|
||||
|
||||
// check if web site has dedicated IP assigned
|
||||
bool dedicatedIp = bindings.Exists(binding => { return String.IsNullOrEmpty(binding.Host) && binding.IP != "*"; });
|
||||
|
||||
// update binding only for "shared" ip addresses
|
||||
if (!dedicatedIp)
|
||||
foreach (ServerBinding b in bindings)
|
||||
{
|
||||
// add new host headers
|
||||
string ipAddr = "*";
|
||||
if (ip != null)
|
||||
ipAddr = !String.IsNullOrEmpty(ip.InternalIP) ? ip.InternalIP : ip.ExternalIP;
|
||||
|
||||
// fill bindings
|
||||
FillWebServerBindings(bindings, dnsRecords, ipAddr, hostName, domain.DomainName);
|
||||
|
||||
foreach (ServerBinding b in bindings)
|
||||
{
|
||||
string header = string.Format("{0} {1} {2}", b.Host, b.IP, b.Port);
|
||||
TaskManager.WriteParameter("Add Binding", header);
|
||||
}
|
||||
|
||||
// update bindings
|
||||
web.UpdateSiteBindings(siteItem.SiteId, bindings.ToArray());
|
||||
string header = string.Format("{0} {1} {2}", b.Host, b.IP, b.Port);
|
||||
TaskManager.WriteParameter("Add Binding", header);
|
||||
}
|
||||
|
||||
// update bindings
|
||||
if (updateWebSite)
|
||||
web.UpdateSiteBindings(siteItem.SiteId, bindings.ToArray());
|
||||
}
|
||||
|
||||
|
||||
// update domain
|
||||
domain.WebSiteId = siteItemId;
|
||||
//ServerController.UpdateDomain(domain);
|
||||
if (!String.IsNullOrEmpty(hostName))
|
||||
domain.DomainName = hostName + "." + domain.DomainName;
|
||||
else
|
||||
domain.DomainName = domain.DomainName;
|
||||
domain.IsDomainPointer = true;
|
||||
int domainID = ServerController.AddDomain(domain);
|
||||
|
||||
DomainInfo domainTmp = ServerController.GetDomain(domainID);
|
||||
if (domainTmp != null)
|
||||
foreach (ServerBinding b in bindings)
|
||||
{
|
||||
domainTmp.WebSiteId = siteItemId;
|
||||
domainTmp.ZoneItemId = domain.ZoneItemId;
|
||||
ServerController.UpdateDomain(domainTmp);
|
||||
domain.DomainName = b.Host;
|
||||
domain.IsDomainPointer = true;
|
||||
int domainID = ServerController.AddDomain(domain);
|
||||
|
||||
DomainInfo domainTmp = ServerController.GetDomain(domainID);
|
||||
if (domainTmp != null)
|
||||
{
|
||||
domainTmp.WebSiteId = siteItemId;
|
||||
domainTmp.ZoneItemId = domain.ZoneItemId;
|
||||
ServerController.UpdateDomain(domainTmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -863,10 +921,10 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
public static int DeleteWebSitePointer(int siteItemId, int domainId)
|
||||
{
|
||||
return DeleteWebSitePointer(siteItemId, domainId, true);
|
||||
return DeleteWebSitePointer(siteItemId, domainId, true, true);
|
||||
}
|
||||
|
||||
public static int DeleteWebSitePointer(int siteItemId, int domainId, bool updateWebSite)
|
||||
public static int DeleteWebSitePointer(int siteItemId, int domainId, bool updateWebSite, bool ignoreGlobalDNSRecords)
|
||||
{
|
||||
// check account
|
||||
int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
|
||||
|
@ -895,16 +953,29 @@ namespace WebsitePanel.EnterpriseServer
|
|||
TaskManager.StartTask("WEB_SITE", "DELETE_POINTER", siteItem.Name);
|
||||
TaskManager.ItemId = siteItemId;
|
||||
TaskManager.WriteParameter("Domain pointer", domain.DomainName);
|
||||
TaskManager.WriteParameter("updateWebSite", updateWebSite.ToString());
|
||||
|
||||
try
|
||||
{
|
||||
if (zone != null)
|
||||
{
|
||||
// change DNS zone
|
||||
List<GlobalDnsRecord> tmpDnsRecords = new List<GlobalDnsRecord>();
|
||||
|
||||
string serviceIp = (ip != null) ? ip.ExternalIP : null;
|
||||
|
||||
if (ignoreGlobalDNSRecords)
|
||||
{
|
||||
foreach (GlobalDnsRecord r in dnsRecords)
|
||||
{
|
||||
if (r.RecordName == "[host_name]")
|
||||
tmpDnsRecords.Add(r);
|
||||
}
|
||||
}
|
||||
else tmpDnsRecords = dnsRecords;
|
||||
|
||||
List<DnsRecord> resourceRecords = DnsServerController.BuildDnsResourceRecords(
|
||||
dnsRecords, domain.DomainName, "", serviceIp);
|
||||
tmpDnsRecords, domain.DomainName, "", serviceIp);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -918,36 +989,34 @@ namespace WebsitePanel.EnterpriseServer
|
|||
}
|
||||
}
|
||||
|
||||
if (updateWebSite)
|
||||
// get existing web site bindings
|
||||
WebServer web = new WebServer();
|
||||
ServiceProviderProxy.Init(web, siteItem.ServiceId);
|
||||
|
||||
List<ServerBinding> bindings = new List<ServerBinding>();
|
||||
bindings.AddRange(web.GetSiteBindings(siteItem.SiteId));
|
||||
|
||||
// check if web site has dedicated IP assigned
|
||||
bool dedicatedIp = bindings.Exists(binding => { return String.IsNullOrEmpty(binding.Host) && binding.IP != "*"; });
|
||||
|
||||
// update binding only for "shared" ip addresses
|
||||
if (!dedicatedIp)
|
||||
{
|
||||
// get existing web site bindings
|
||||
WebServer web = new WebServer();
|
||||
ServiceProviderProxy.Init(web, siteItem.ServiceId);
|
||||
// remove host headers
|
||||
List<ServerBinding> domainBindings = new List<ServerBinding>();
|
||||
FillWebServerBindings(domainBindings, dnsRecords, "", domain.DomainName, "", ignoreGlobalDNSRecords);
|
||||
|
||||
List<ServerBinding> bindings = new List<ServerBinding>();
|
||||
bindings.AddRange(web.GetSiteBindings(siteItem.SiteId));
|
||||
// fill to remove list
|
||||
List<string> headersToRemove = new List<string>();
|
||||
foreach (ServerBinding domainBinding in domainBindings)
|
||||
headersToRemove.Add(domainBinding.Host);
|
||||
|
||||
// check if web site has dedicated IP assigned
|
||||
bool dedicatedIp = bindings.Exists(binding => { return String.IsNullOrEmpty(binding.Host) && binding.IP != "*"; });
|
||||
// remove bndings
|
||||
bindings.RemoveAll(b => { return headersToRemove.Contains(b.Host) && b.Port == "80"; } );
|
||||
|
||||
// update binding only for "shared" ip addresses
|
||||
if (!dedicatedIp)
|
||||
{
|
||||
// remove host headers
|
||||
List<ServerBinding> domainBindings = new List<ServerBinding>();
|
||||
FillWebServerBindings(domainBindings, dnsRecords, "", domain.DomainName, "");
|
||||
|
||||
// fill to remove list
|
||||
List<string> headersToRemove = new List<string>();
|
||||
foreach (ServerBinding domainBinding in domainBindings)
|
||||
headersToRemove.Add(domainBinding.Host);
|
||||
|
||||
// remove bndings
|
||||
bindings.RemoveAll(b => { return headersToRemove.Contains(b.Host) && b.Port == "80"; } );
|
||||
|
||||
// update bindings
|
||||
// update bindings
|
||||
if (updateWebSite)
|
||||
web.UpdateSiteBindings(siteItem.SiteId, bindings.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
// update domain
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue