Merge
This commit is contained in:
commit
2e6ab84cd4
18 changed files with 159 additions and 257 deletions
|
@ -813,24 +813,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Domain DNS Records lookup
|
||||
|
||||
public static List<DnsRecordInfo> GetDomainRecords(int packageId, string domain, string dnsServer, DnsRecordType recordType)
|
||||
{
|
||||
List<DnsRecordInfo> records = new List<DnsRecordInfo>();
|
||||
|
||||
// load OS service
|
||||
int serviceId = PackageController.GetPackageServiceId(packageId, ResourceGroups.Os);
|
||||
|
||||
var os = GetOS(serviceId);
|
||||
|
||||
records = os.GetDomainDnsRecords(domain, dnsServer, recordType).ToList();
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
foreach (var subDomain in subDomains)
|
||||
{
|
||||
var mainDomain = topLevelDomains.Where(x => subDomain.DomainName.Contains(x.DomainName)).OrderByDescending(s => s.DomainName.Length).FirstOrDefault(); ;
|
||||
var mainDomain = topLevelDomains.Where(x => subDomain.DomainName.ToLowerInvariant().Contains(x.DomainName.ToLowerInvariant())).OrderByDescending(s => s.DomainName.Length).FirstOrDefault(); ;
|
||||
|
||||
if (mainDomain != null)
|
||||
{
|
||||
|
@ -182,5 +182,8 @@ namespace WebsitePanel.EnterpriseServer
|
|||
// send mail message
|
||||
MailHelper.SendMessage(from, mailTo, bcc, subject, body, priority, isHtml);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using WebsitePanel.Providers.DNS;
|
||||
using WebsitePanel.Providers.DomainLookup;
|
||||
using WebsitePanel.Server;
|
||||
|
@ -20,6 +21,10 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
private static readonly string MailBodyTemplateParameter = "MAIL_BODY";
|
||||
private static readonly string MailBodyDomainRecordTemplateParameter = "MAIL_DOMAIN_RECORD";
|
||||
private static readonly string ServerNameParameter = "SERVER_NAME";
|
||||
|
||||
private const string MxRecordPattern = @"mail exchanger = (.+)";
|
||||
private const string NsRecordPattern = @"nameserver = (.+)";
|
||||
|
||||
public override void DoWork()
|
||||
{
|
||||
|
@ -29,6 +34,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
// get input parameters
|
||||
string dnsServersString = (string)topTask.GetParamValue(DnsServersParameter);
|
||||
string serverName = (string)topTask.GetParamValue(ServerNameParameter);
|
||||
|
||||
// check input parameters
|
||||
if (String.IsNullOrEmpty(dnsServersString))
|
||||
|
@ -43,6 +49,17 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return;
|
||||
}
|
||||
|
||||
// find server by name
|
||||
ServerInfo server = ServerController.GetServerByName(serverName);
|
||||
if (server == null)
|
||||
{
|
||||
TaskManager.WriteWarning(String.Format("Server with the name '{0}' was not found", serverName));
|
||||
return;
|
||||
}
|
||||
|
||||
WindowsServer winServer = new WindowsServer();
|
||||
ServiceProviderProxy.ServerInit(winServer, server.ServerId);
|
||||
|
||||
var user = UserController.GetUser(topTask.UserId);
|
||||
|
||||
var dnsServers = dnsServersString.Split(';');
|
||||
|
@ -74,8 +91,8 @@ namespace WebsitePanel.EnterpriseServer
|
|||
//execute server
|
||||
foreach (var dnsServer in dnsServers)
|
||||
{
|
||||
var dnsMxRecords = OperatingSystemController.GetDomainRecords(domain.PackageId, domain.DomainName, dnsServer, DnsRecordType.MX);
|
||||
var dnsNsRecords = OperatingSystemController.GetDomainRecords(domain.PackageId, domain.DomainName, dnsServer, DnsRecordType.NS);
|
||||
var dnsMxRecords = GetDomainDnsRecords(winServer, domain.DomainName, dnsServer, DnsRecordType.MX);
|
||||
var dnsNsRecords = GetDomainDnsRecords(winServer, domain.DomainName, dnsServer, DnsRecordType.NS);
|
||||
|
||||
FillRecordData(dnsMxRecords, domain, dnsServer);
|
||||
FillRecordData(dnsNsRecords, domain, dnsServer);
|
||||
|
@ -123,7 +140,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return changedDomains;
|
||||
}
|
||||
|
||||
private IEnumerable<DnsRecordInfoChange> ApplyDomainRecordsChanges(List<DnsRecordInfo> dbRecords, List<DnsRecordInfo> dnsRecords, string dnsServer)
|
||||
private IEnumerable<DnsRecordInfoChange> ApplyDomainRecordsChanges(IEnumerable<DnsRecordInfo> dbRecords, List<DnsRecordInfo> dnsRecords, string dnsServer)
|
||||
{
|
||||
var dnsRecordChanges = new List<DnsRecordInfoChange>();
|
||||
|
||||
|
@ -240,6 +257,62 @@ namespace WebsitePanel.EnterpriseServer
|
|||
MailHelper.SendMessage(from, mailTo, bcc, subject, body, priority, isHtml);
|
||||
}
|
||||
|
||||
public List<DnsRecordInfo> GetDomainDnsRecords(WindowsServer winServer, string domain, string dnsServer, DnsRecordType recordType)
|
||||
{
|
||||
//nslookup -type=mx google.com 195.46.39.39
|
||||
var command = "nslookup";
|
||||
var args = string.Format("-type={0} {1} {2}", recordType, domain, dnsServer);
|
||||
|
||||
// execute system command
|
||||
var raw = winServer.ExecuteSystemCommand(command, args);
|
||||
|
||||
var records = ParseNsLookupResult(raw, dnsServer, recordType);
|
||||
|
||||
return records.ToList();
|
||||
}
|
||||
|
||||
private IEnumerable<DnsRecordInfo> ParseNsLookupResult(string raw, string dnsServer, DnsRecordType recordType)
|
||||
{
|
||||
var records = new List<DnsRecordInfo>();
|
||||
|
||||
var recordTypePattern = string.Empty;
|
||||
|
||||
switch (recordType)
|
||||
{
|
||||
case DnsRecordType.NS:
|
||||
{
|
||||
recordTypePattern = NsRecordPattern;
|
||||
break;
|
||||
}
|
||||
case DnsRecordType.MX:
|
||||
{
|
||||
recordTypePattern = MxRecordPattern;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var regex = new Regex(recordTypePattern, RegexOptions.IgnoreCase);
|
||||
|
||||
foreach (Match match in regex.Matches(raw))
|
||||
{
|
||||
if (match.Groups.Count != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var dnsRecord = new DnsRecordInfo
|
||||
{
|
||||
Value = match.Groups[1].Value != null ? match.Groups[1].Value.Replace("\r\n", "").Replace("\r", "").Replace("\n", "").ToLowerInvariant().Trim() : null,
|
||||
RecordType = recordType,
|
||||
DnsServer = dnsServer
|
||||
};
|
||||
|
||||
records.Add(dnsRecord);
|
||||
}
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,12 +54,14 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
private static List<string> _createdDatePatterns = new List<string> { @"Creation Date:(.+)", // base
|
||||
@"created:(.+)",
|
||||
@"Created On:(.+) UTC",
|
||||
@"Created On:(.+)",
|
||||
@"Domain Registration Date:(.+)",
|
||||
@"Domain Create Date:(.+)",
|
||||
@"Registered on:(.+)"};
|
||||
|
||||
private static List<string> _expiredDatePatterns = new List<string> { @"Expiration Date:(.+)", // base
|
||||
private static List<string> _expiredDatePatterns = new List<string> { @"Expiration Date:(.+) UTC", //base UTC
|
||||
@"Expiration Date:(.+)", // base
|
||||
@"Registry Expiry Date:(.+)", //.org
|
||||
@"paid-till:(.+)", //.ru
|
||||
@"Expires On:(.+)", //.name
|
||||
|
@ -2682,7 +2684,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
{
|
||||
DataProvider.UpdateDomainLastUpdateDate(domain.DomainId, DateTime.Now);
|
||||
|
||||
var whoisResult = WhoisClient.Query(domain.DomainName);
|
||||
var whoisResult = WhoisClient.Query(domain.DomainName.ToLowerInvariant());
|
||||
|
||||
var createdDate = GetDomainInfoDate(whoisResult.Raw, _createdDatePatterns);
|
||||
var expiredDate = GetDomainInfoDate(whoisResult.Raw, _expiredDatePatterns);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue