diff --git a/WebsitePanel/Database/update_db.sql b/WebsitePanel/Database/update_db.sql index f9247f44..685b6b2d 100644 --- a/WebsitePanel/Database/update_db.sql +++ b/WebsitePanel/Database/update_db.sql @@ -6085,7 +6085,13 @@ GO IF NOT EXISTS (SELECT * FROM [dbo].[ScheduleTaskParameters] WHERE [TaskID] = N'SCHEDULE_TASK_DOMAIN_LOOKUP' AND [ParameterID]= N'SERVER_NAME' ) BEGIN -INSERT [dbo].[ScheduleTaskParameters] ([TaskID], [ParameterID], [DataTypeID], [DefaultValue], [ParameterOrder]) VALUES (N'SCHEDULE_TASK_DOMAIN_LOOKUP', N'SERVER_NAME', N'String', NULL, 3) +INSERT [dbo].[ScheduleTaskParameters] ([TaskID], [ParameterID], [DataTypeID], [DefaultValue], [ParameterOrder]) VALUES (N'SCHEDULE_TASK_DOMAIN_LOOKUP', N'SERVER_NAME', N'String', N'', 3) +END +GO + +IF EXISTS (SELECT * FROM [dbo].[ScheduleTaskParameters] WHERE [TaskID] = N'SCHEDULE_TASK_DOMAIN_LOOKUP' AND [ParameterID]= N'SERVER_NAME' ) +BEGIN +UPDATE [dbo].[ScheduleTaskParameters] SET [DefaultValue] = N'' WHERE [TaskID] = N'SCHEDULE_TASK_DOMAIN_LOOKUP' AND [ParameterID]= N'SERVER_NAME' END GO @@ -6581,6 +6587,24 @@ SELECT WHERE [DomainId] = @DomainId AND [RecordType] = @RecordType GO +IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'GetDomainAllDnsRecords') +DROP PROCEDURE GetDomainAllDnsRecords +GO +CREATE PROCEDURE [dbo].GetDomainAllDnsRecords +( + @DomainId INT +) +AS +SELECT + ID, + DomainId, + DnsServer, + RecordType, + Value, + Date + FROM [dbo].[DomainDnsRecords] + WHERE [DomainId] = @DomainId +GO IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'AddDomainDnsRecord') @@ -6668,6 +6692,20 @@ AS UPDATE [dbo].[Domains] SET [LastUpdateDate] = @Date WHERE [DomainID] = @DomainId GO +IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'UpdateDomainDates') +DROP PROCEDURE UpdateDomainDates +GO +CREATE PROCEDURE [dbo].UpdateDomainDates +( + @DomainId INT, + @DomainCreationDate DateTime, + @DomainExpirationDate DateTime, + @DomainLastUpdateDate DateTime +) +AS +UPDATE [dbo].[Domains] SET [CreationDate] = @DomainCreationDate, [ExpirationDate] = @DomainExpirationDate, [LastUpdateDate] = @DomainLastUpdateDate WHERE [DomainID] = @DomainId +GO + --Updating Domain procedures diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs index b7e2acf0..bab3c724 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs @@ -1910,9 +1910,9 @@ namespace WebsitePanel.EnterpriseServer public static IDataReader GetProcessBackgroundTasks(BackgroundTaskStatus status) { - return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure, - ObjectQualifier + "GetProcessBackgroundTasks", - new SqlParameter("@status", (int)status)); + return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure, + ObjectQualifier + "GetProcessBackgroundTasks", + new SqlParameter("@status", (int)status)); } public static IDataReader GetBackgroundTopTask(Guid guid) @@ -4744,9 +4744,19 @@ namespace WebsitePanel.EnterpriseServer ); } + public static IDataReader GetDomainAllDnsRecords(int domainId) + { + return SqlHelper.ExecuteReader( + ConnectionString, + CommandType.StoredProcedure, + "GetDomainAllDnsRecords", + new SqlParameter("@DomainId", domainId) + ); + } + public static void AddDomainDnsRecord(DnsRecordInfo domainDnsRecord) { - SqlHelper.ExecuteReader( + SqlHelper.ExecuteNonQuery( ConnectionString, CommandType.StoredProcedure, "AddDomainDnsRecord", @@ -4770,7 +4780,7 @@ namespace WebsitePanel.EnterpriseServer public static void DeleteDomainDnsRecord(int id) { - SqlHelper.ExecuteReader( + SqlHelper.ExecuteNonQuery( ConnectionString, CommandType.StoredProcedure, "DeleteDomainDnsRecord", @@ -4795,7 +4805,7 @@ namespace WebsitePanel.EnterpriseServer private static void UpdateDomainDate(int domainId, string stroredProcedure, DateTime date) { - SqlHelper.ExecuteReader( + SqlHelper.ExecuteNonQuery( ConnectionString, CommandType.StoredProcedure, stroredProcedure, @@ -4804,6 +4814,19 @@ namespace WebsitePanel.EnterpriseServer ); } + public static void UpdateDomainDates(int domainId, DateTime? domainCreationDate, DateTime? domainExpirationDate, DateTime? domainLastUpdateDate) + { + SqlHelper.ExecuteNonQuery( + ConnectionString, + CommandType.StoredProcedure, + "UpdateDomainDates", + new SqlParameter("@DomainId", domainId), + new SqlParameter("@DomainCreationDate", domainCreationDate), + new SqlParameter("@DomainExpirationDate", domainExpirationDate), + new SqlParameter("@DomainLastUpdateDate", domainLastUpdateDate) + ); + } + #endregion } diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/SchedulerTasks/DomainExpirationTask.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/SchedulerTasks/DomainExpirationTask.cs index 3c08a751..34468cbf 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/SchedulerTasks/DomainExpirationTask.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/SchedulerTasks/DomainExpirationTask.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Net.Mail; using System.Text; using System.Text.RegularExpressions; +using System.Threading; using WebsitePanel.Providers.DomainLookup; using Whois.NET; @@ -31,6 +32,8 @@ namespace WebsitePanel.EnterpriseServer var checkedDomains = new List(); var expiredDomains = new List(); var nonExistenDomains = new List(); + var subDomains = new List(); + var allTopLevelDomains = new List(); // get input parameters int daysBeforeNotify; @@ -55,10 +58,12 @@ namespace WebsitePanel.EnterpriseServer { var domains = ServerController.GetDomains(package.PackageId); - var subDomains = domains.Where(x => x.IsSubDomain).ToList(); + subDomains.AddRange(domains.Where(x => x.IsSubDomain)); var topLevelDomains = domains = domains.Where(x => !x.IsSubDomain && !x.IsDomainPointer).ToList(); //Selecting top-level domains + allTopLevelDomains.AddRange(topLevelDomains); + domains = topLevelDomains.Where(x => x.CreationDate == null || x.ExpirationDate == null ? true : CheckDomainExpiration(x.ExpirationDate, daysBeforeNotify)).ToList(); // selecting expired or with empty expire date domains var domainUser = UserController.GetUser(package.UserId); @@ -88,16 +93,23 @@ namespace WebsitePanel.EnterpriseServer { nonExistenDomains.Add(domain); } + + Thread.Sleep(100); } + } - foreach (var subDomain in subDomains) + subDomains = subDomains.GroupBy(p => p.DomainId).Select(g => g.First()).ToList(); + allTopLevelDomains = allTopLevelDomains.GroupBy(p => p.DomainId).Select(g => g.First()).ToList(); + + foreach (var subDomain in subDomains) + { + var mainDomain = allTopLevelDomains.Where(x => subDomain.DomainName.ToLowerInvariant().Contains(x.DomainName.ToLowerInvariant())).OrderByDescending(s => s.DomainName.Length).FirstOrDefault(); ; + + if (mainDomain != null) { - var mainDomain = topLevelDomains.Where(x => subDomain.DomainName.ToLowerInvariant().Contains(x.DomainName.ToLowerInvariant())).OrderByDescending(s => s.DomainName.Length).FirstOrDefault(); ; + ServerController.UpdateDomainRegistrationData(subDomain, mainDomain.CreationDate, mainDomain.ExpirationDate); - if (mainDomain != null) - { - ServerController.UpdateDomainRegistrationData(subDomain, mainDomain.CreationDate, mainDomain.ExpirationDate); - } + Thread.Sleep(100); } } diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/SchedulerTasks/DomainLookupViewTask.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/SchedulerTasks/DomainLookupViewTask.cs index a1a49534..b5a7c8ee 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/SchedulerTasks/DomainLookupViewTask.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/SchedulerTasks/DomainLookupViewTask.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Net.Mail; using System.Text; using System.Text.RegularExpressions; +using System.Threading; using WebsitePanel.Providers.DNS; using WebsitePanel.Providers.DomainLookup; using WebsitePanel.Server; @@ -85,8 +86,7 @@ namespace WebsitePanel.EnterpriseServer DomainDnsChanges domainChanges = new DomainDnsChanges(); domainChanges.DomainName = domain.DomainName; - var mxRecords = ObjectUtils.CreateListFromDataReader(DataProvider.GetDomainDnsRecords(domain.DomainId, DnsRecordType.MX)); - var nsRecords = ObjectUtils.CreateListFromDataReader(DataProvider.GetDomainDnsRecords(domain.DomainId, DnsRecordType.NS)); + var dbDnsRecords = ObjectUtils.CreateListFromDataReader(DataProvider.GetDomainAllDnsRecords(domain.DomainId)); //execute server foreach (var dnsServer in dnsServers) @@ -97,16 +97,14 @@ namespace WebsitePanel.EnterpriseServer FillRecordData(dnsMxRecords, domain, dnsServer); FillRecordData(dnsNsRecords, domain, dnsServer); - domainChanges.DnsChanges.AddRange(ApplyDomainRecordsChanges(mxRecords, dnsMxRecords, dnsServer)); - domainChanges.DnsChanges.AddRange(ApplyDomainRecordsChanges(nsRecords, dnsNsRecords, dnsServer)); + domainChanges.DnsChanges.AddRange(ApplyDomainRecordsChanges(dbDnsRecords.Where(x => x.RecordType == DnsRecordType.MX), dnsMxRecords, dnsServer)); + domainChanges.DnsChanges.AddRange(ApplyDomainRecordsChanges(dbDnsRecords.Where(x => x.RecordType == DnsRecordType.NS), dnsNsRecords, dnsServer)); } domainsChanges.Add(domainChanges); } } - TaskManager.Write(string.Format("Domains checked: {0}", domainsChanges.Count)); - var changedDomains = FindDomainsWithChangedRecords(domainsChanges); SendMailMessage(user, changedDomains); @@ -200,6 +198,8 @@ namespace WebsitePanel.EnterpriseServer private void RemoveRecord(DnsRecordInfo dnsRecord) { DataProvider.DeleteDomainDnsRecord(dnsRecord.Id); + + Thread.Sleep(100); } private void AddRecords(IEnumerable dnsRecords) @@ -213,6 +213,8 @@ namespace WebsitePanel.EnterpriseServer private void AddRecord(DnsRecordInfo dnsRecord) { DataProvider.AddDomainDnsRecord(dnsRecord); + + Thread.Sleep(100); } private void SendMailMessage(UserInfo user, IEnumerable domainsChanges) diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Servers/ServerController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Servers/ServerController.cs index 507ae075..47444aeb 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Servers/ServerController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Servers/ServerController.cs @@ -2680,26 +2680,20 @@ namespace WebsitePanel.EnterpriseServer public static DomainInfo UpdateDomainRegistrationData(DomainInfo domain) { + DateTime? createdDate = null; + DateTime? expiredDate = null; + try { - DataProvider.UpdateDomainLastUpdateDate(domain.DomainId, DateTime.Now); - var whoisResult = WhoisClient.Query(domain.DomainName.ToLowerInvariant()); - var createdDate = GetDomainInfoDate(whoisResult.Raw, _createdDatePatterns); - var expiredDate = GetDomainInfoDate(whoisResult.Raw, _expiredDatePatterns); + createdDate = GetDomainInfoDate(whoisResult.Raw, _createdDatePatterns); + expiredDate = GetDomainInfoDate(whoisResult.Raw, _expiredDatePatterns); - if (createdDate != null) - { - domain.CreationDate = createdDate; - DataProvider.UpdateDomainCreationDate(domain.DomainId, createdDate.Value); - } + domain.CreationDate = createdDate; + domain.ExpirationDate = expiredDate; - if (expiredDate != null) - { - domain.ExpirationDate = expiredDate; - DataProvider.UpdateDomainExpirationDate(domain.DomainId, expiredDate.Value); - } + DataProvider.UpdateDomainDates(domain.DomainId, createdDate, expiredDate, DateTime.Now); } catch (Exception e) { @@ -2711,19 +2705,10 @@ namespace WebsitePanel.EnterpriseServer public static DomainInfo UpdateDomainRegistrationData(DomainInfo domain, DateTime? creationDate, DateTime? expirationDate) { - if (creationDate != null) - { - domain.CreationDate = creationDate; - DataProvider.UpdateDomainCreationDate(domain.DomainId, creationDate.Value); - } + DataProvider.UpdateDomainDates(domain.DomainId, creationDate, expirationDate, DateTime.Now); - if (expirationDate != null) - { - domain.ExpirationDate = expirationDate; - DataProvider.UpdateDomainExpirationDate(domain.DomainId, expirationDate.Value); - } - - DataProvider.UpdateDomainLastUpdateDate(domain.DomainId, DateTime.Now); + domain.CreationDate = creationDate; + domain.ExpirationDate = expirationDate; return domain; } diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ScheduleTaskControls/DomainLookupView.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ScheduleTaskControls/DomainLookupView.ascx index 7034bce6..8655355c 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ScheduleTaskControls/DomainLookupView.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ScheduleTaskControls/DomainLookupView.ascx @@ -6,7 +6,8 @@ Server Name: - + + diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ScheduleTaskControls/DomainLookupView.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ScheduleTaskControls/DomainLookupView.ascx.cs index 8e6dc106..e03b5a49 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ScheduleTaskControls/DomainLookupView.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ScheduleTaskControls/DomainLookupView.ascx.cs @@ -30,7 +30,33 @@ namespace WebsitePanel.Portal.ScheduleTaskControls this.SetParameter(this.txtDnsServers, DnsServersParameter); this.SetParameter(this.txtMailTo, MailToParameter); - this.SetParameter(this.txtServerName, ServerNameParameter); + this.SetParameter(this.ddlServers, ServerNameParameter); + + var servers = ES.Services.Servers.GetAllServers(); + + var osGroup = ES.Services.Servers.GetResourceGroups().First(x => x.GroupName == ResourceGroups.Os); + var osProviders = ES.Services.Servers.GetProvidersByGroupId(osGroup.GroupId); + + var osServers = new List(); + + foreach (var server in servers) + { + var services = ES.Services.Servers.GetServicesByServerId(server.ServerId); + + if (services.Any(x => osProviders.Any(p=>p.ProviderId == x.ProviderId))) + { + osServers.Add(server); + } + } + + ddlServers.DataSource = osServers.Select(x => new { Id = x.ServerName, Name = x.ServerName }); + ddlServers.DataTextField = "Name"; + ddlServers.DataValueField = "Id"; + ddlServers.DataBind(); + + ScheduleTaskParameterInfo parameter = this.FindParameterById(ServerNameParameter); + + ddlServers.SelectedValue = parameter.ParameterValue; } /// @@ -41,7 +67,7 @@ namespace WebsitePanel.Portal.ScheduleTaskControls { ScheduleTaskParameterInfo dnsServers = this.GetParameter(this.txtDnsServers, DnsServersParameter); ScheduleTaskParameterInfo mailTo = this.GetParameter(this.txtMailTo, MailToParameter); - ScheduleTaskParameterInfo serverName = this.GetParameter(this.txtServerName, ServerNameParameter); + ScheduleTaskParameterInfo serverName = this.GetParameter(this.ddlServers, ServerNameParameter); return new ScheduleTaskParameterInfo[3] { dnsServers, mailTo, serverName }; } diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ScheduleTaskControls/DomainLookupView.ascx.designer.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ScheduleTaskControls/DomainLookupView.ascx.designer.cs index cfc285be..df689cac 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ScheduleTaskControls/DomainLookupView.ascx.designer.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ScheduleTaskControls/DomainLookupView.ascx.designer.cs @@ -22,13 +22,13 @@ namespace WebsitePanel.Portal.ScheduleTaskControls { protected global::System.Web.UI.WebControls.Label lblServerName; /// - /// txtServerName control. + /// ddlServers control. /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// - protected global::System.Web.UI.WebControls.TextBox txtServerName; + protected global::System.Web.UI.WebControls.DropDownList ddlServers; /// /// lblDnsServers control.