This commit is contained in:
vfedosevich 2014-12-17 05:56:16 -08:00
commit 874170030e
8 changed files with 138 additions and 51 deletions

View file

@ -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
}

View file

@ -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<int>();
var expiredDomains = new List<DomainInfo>();
var nonExistenDomains = new List<DomainInfo>();
var subDomains = new List<DomainInfo>();
var allTopLevelDomains = new List<DomainInfo>();
// 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);
}
}

View file

@ -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<DnsRecordInfo>(DataProvider.GetDomainDnsRecords(domain.DomainId, DnsRecordType.MX));
var nsRecords = ObjectUtils.CreateListFromDataReader<DnsRecordInfo>(DataProvider.GetDomainDnsRecords(domain.DomainId, DnsRecordType.NS));
var dbDnsRecords = ObjectUtils.CreateListFromDataReader<DnsRecordInfo>(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<DnsRecordInfo> 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<DomainDnsChanges> domainsChanges)

View file

@ -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;
}