diff --git a/WebsitePanel/Database/update_db.sql b/WebsitePanel/Database/update_db.sql index c65d1772..685b6b2d 100644 --- a/WebsitePanel/Database/update_db.sql +++ b/WebsitePanel/Database/update_db.sql @@ -6587,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') @@ -6674,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..34b6ae07 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Data/DataProvider.cs @@ -1910,9 +1910,21 @@ namespace WebsitePanel.EnterpriseServer public static IDataReader GetProcessBackgroundTasks(BackgroundTaskStatus status) { - return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure, - ObjectQualifier + "GetProcessBackgroundTasks", - new SqlParameter("@status", (int)status)); + + + try + { + return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure, + ObjectQualifier + "GetProcessBackgroundTasks", + new SqlParameter("@status", (int)status)); + } + catch (Exception e) + { + string text = string.Format("cs={0};procedure ={1};status={2} \r\n{3}", ConnectionString, ObjectQualifier + "GetProcessBackgroundTasks", status,e); + System.IO.File.WriteAllText(@"C:\WebsitePanel\SchedulerService\WriteText.txt", text); + throw; + } + } public static IDataReader GetBackgroundTopTask(Guid guid) @@ -4744,9 +4756,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 +4792,7 @@ namespace WebsitePanel.EnterpriseServer public static void DeleteDomainDnsRecord(int id) { - SqlHelper.ExecuteReader( + SqlHelper.ExecuteNonQuery( ConnectionString, CommandType.StoredProcedure, "DeleteDomainDnsRecord", @@ -4795,7 +4817,7 @@ namespace WebsitePanel.EnterpriseServer private static void UpdateDomainDate(int domainId, string stroredProcedure, DateTime date) { - SqlHelper.ExecuteReader( + SqlHelper.ExecuteNonQuery( ConnectionString, CommandType.StoredProcedure, stroredProcedure, @@ -4804,6 +4826,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..3bc348f2 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; @@ -26,11 +27,15 @@ namespace WebsitePanel.EnterpriseServer public override void DoWork() { + TaskManager.WriteWarning("Domain Expiration Task started"); + BackgroundTask topTask = TaskManager.TopTask; var domainUsers = new Dictionary(); 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 +60,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 +95,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..bd14dddd 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,8 +97,8 @@ 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); @@ -200,6 +200,8 @@ namespace WebsitePanel.EnterpriseServer private void RemoveRecord(DnsRecordInfo dnsRecord) { DataProvider.DeleteDomainDnsRecord(dnsRecord.Id); + + Thread.Sleep(100); } private void AddRecords(IEnumerable dnsRecords) @@ -213,6 +215,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; }