MX + Domain expiration tasks fixes

This commit is contained in:
vfedosevich 2014-12-11 05:58:59 -08:00
parent 9ddd934ff5
commit f3ceabf4cc
13 changed files with 617 additions and 329 deletions

View file

@ -6518,12 +6518,10 @@ INSERT [dbo].[UserSettings] ([UserID], [SettingsName], [PropertyName], [Property
MX and NS Changes Information
=================================
<ad:if test="#user#">
<p>
Hello #user.FirstName#,
</p>
</ad:if>
Please, find below details of your domain expiration information.
Please, find below MX and NS Changes Information.
@ -6542,6 +6540,70 @@ Please, find below details of your domain expiration information.
If you have any questions regarding your hosting account, feel free to contact our support department at any time.
Best regards
')
END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[UserSettings] WHERE [UserID] = 1 AND [SettingsName]= N'DomainLookupLetter' AND [PropertyName]= N'NoChangesHtmlBody' )
BEGIN
INSERT [dbo].[UserSettings] ([UserID], [SettingsName], [PropertyName], [PropertyValue]) VALUES (1, N'DomainLookupLetter', N'NoChangesHtmlBody', N'<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MX and NS Changes Information</title>
<style type="text/css">
.Summary { background-color: ##ffffff; padding: 5px; }
.Summary .Header { padding: 10px 0px 10px 10px; font-size: 16pt; background-color: ##E5F2FF; color: ##1F4978; border-bottom: solid 2px ##86B9F7; }
.Summary A { color: ##0153A4; }
.Summary { font-family: Tahoma; font-size: 9pt; }
.Summary H1 { font-size: 1.7em; color: ##1F4978; border-bottom: dotted 3px ##efefef; }
.Summary H2 { font-size: 1.3em; color: ##1F4978; }
.Summary TABLE { border: solid 1px ##e5e5e5; }
.Summary TH,
.Summary TD.Label { padding: 5px; font-size: 8pt; font-weight: bold; background-color: ##f5f5f5; }
.Summary TD { padding: 8px; font-size: 9pt; }
.Summary UL LI { font-size: 1.1em; font-weight: bold; }
.Summary UL UL LI { font-size: 0.9em; font-weight: normal; }
</style>
</head>
<body>
<div class="Summary">
<a name="top"></a>
<div class="Header">
MX and NS Changes Information
</div>
<ad:if test="#user#">
<p>
Hello #user.FirstName#,
</p>
</ad:if>
<p>
No MX and NS changes have been founded.
</p>
<p>
If you have any questions regarding your hosting account, feel free to contact our support department at any time.
</p>
<p>
Best regards
</p>')
END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[UserSettings] WHERE [UserID] = 1 AND [SettingsName]= N'DomainLookupLetter' AND [PropertyName]= N'NoChangesTextBody' )
BEGIN
INSERT [dbo].[UserSettings] ([UserID], [SettingsName], [PropertyName], [PropertyValue]) VALUES (1, N'DomainLookupLetter', N'NoChangesTextBody', N'=================================
MX and NS Changes Information
=================================
<ad:if test="#user#">
Hello #user.FirstName#,
</ad:if>
No MX and NS changes have been founded.
If you have any questions regarding your hosting account, feel free to contact our support department at any time.
Best regards

View file

@ -6,6 +6,7 @@ using System.Net.Mail;
using System.Text;
using WebsitePanel.Providers.DNS;
using WebsitePanel.Providers.DomainLookup;
using WebsitePanel.Server;
namespace WebsitePanel.EnterpriseServer
{
@ -48,13 +49,14 @@ namespace WebsitePanel.EnterpriseServer
var packages = ObjectUtils.CreateListFromDataReader<PackageInfo>(DataProvider.GetAllPackages());
foreach (var package in packages)
{
var domains = ServerController.GetDomains(package.PackageId);
domains = domains.Where(x => !x.IsSubDomain && !x.IsDomainPointer).ToList(); //Selecting top-level domains
domains = domains.Where(x => x.ZoneItemId > 0).ToList(); //Selecting only dns enabled domains
//domains = domains.Where(x => x.ZoneItemId > 0).ToList(); //Selecting only dns enabled domains
foreach (var domain in domains)
{
@ -86,12 +88,11 @@ namespace WebsitePanel.EnterpriseServer
}
}
TaskManager.Write(string.Format("Domains checked: {0}", domainsChanges.Count));
var changedDomains = FindDomainsWithChangedRecords(domainsChanges);
if (changedDomains.Any())
{
SendMailMessage(user,changedDomains);
}
SendMailMessage(user, changedDomains);
}
@ -208,8 +209,6 @@ namespace WebsitePanel.EnterpriseServer
var bcc = settings["CC"];
string subject = settings["Subject"];
string body = user.HtmlMail ? settings["HtmlBody"] : settings["TextBody"];
bool isHtml = user.HtmlMail;
MailPriority priority = MailPriority.Normal;
if (!String.IsNullOrEmpty(settings["Priority"]))
@ -218,6 +217,18 @@ namespace WebsitePanel.EnterpriseServer
// input parameters
string mailTo = (string)topTask.GetParamValue("MAIL_TO");
string body = string.Empty;
bool isHtml = user.HtmlMail;
if (domainsChanges.Any())
{
body = user.HtmlMail ? settings["HtmlBody"] : settings["TextBody"];
}
else
{
body = user.HtmlMail ? settings["NoChangesHtmlBody"] : settings["NoChangesTextBody"];
}
Hashtable items = new Hashtable();
items["user"] = user;

View file

@ -41,6 +41,7 @@ using WebsitePanel.Providers.Web;
using WebsitePanel.Providers.HostedSolution;
using Whois.NET;
using System.Text.RegularExpressions;
using WebsitePanel.Providers.DomainLookup;
namespace WebsitePanel.EnterpriseServer
{
@ -1633,6 +1634,21 @@ namespace WebsitePanel.EnterpriseServer
#endregion
#region Domains
public static List<DnsRecordInfo> GetDomainDnsRecords(int domainId)
{
var result = new List<DnsRecordInfo>();
var mxRecords = ObjectUtils.CreateListFromDataReader<DnsRecordInfo>(DataProvider.GetDomainDnsRecords(domainId, DnsRecordType.MX));
var nsRecords = ObjectUtils.CreateListFromDataReader<DnsRecordInfo>(DataProvider.GetDomainDnsRecords(domainId, DnsRecordType.NS));
result.AddRange(mxRecords);
result.AddRange(nsRecords);
return result;
}
public static int CheckDomain(string domainName)
{
int checkDomainResult = DataProvider.CheckDomain(-10, domainName, false);
@ -2693,10 +2709,18 @@ namespace WebsitePanel.EnterpriseServer
public static DomainInfo UpdateDomainRegistrationData(DomainInfo domain, DateTime? creationDate, DateTime? expirationDate)
{
domain.CreationDate = creationDate;
DataProvider.UpdateDomainCreationDate(domain.DomainId, creationDate.Value);
domain.ExpirationDate = expirationDate;
DataProvider.UpdateDomainExpirationDate(domain.DomainId, expirationDate.Value);
if (creationDate != null)
{
domain.CreationDate = creationDate;
DataProvider.UpdateDomainCreationDate(domain.DomainId, creationDate.Value);
}
if (expirationDate != null)
{
domain.ExpirationDate = expirationDate;
DataProvider.UpdateDomainExpirationDate(domain.DomainId, expirationDate.Value);
}
DataProvider.UpdateDomainLastUpdateDate(domain.DomainId, DateTime.Now);
return domain;

View file

@ -43,6 +43,7 @@ using WebsitePanel.Providers.DNS;
using WebsitePanel.Server;
using WebsitePanel.Providers.ResultObjects;
using WebsitePanel.Providers;
using WebsitePanel.Providers.DomainLookup;
namespace WebsitePanel.EnterpriseServer
{
@ -521,6 +522,13 @@ namespace WebsitePanel.EnterpriseServer
#endregion
#region Domains
[WebMethod]
public List<DnsRecordInfo> GetDomainDnsRecords(int domainId)
{
return ServerController.GetDomainDnsRecords(domainId);
}
[WebMethod]
public List<DomainInfo> GetDomains(int packageId)
{

View file

@ -36,6 +36,8 @@ using WebsitePanel.Server.Utils;
using WebsitePanel.Providers.Utils;
using WebsitePanel.Providers.DomainLookup;
using WebsitePanel.Providers.DNS;
using System.Text.RegularExpressions;
using System.Linq;
namespace WebsitePanel.Providers.OS
{
@ -55,6 +57,9 @@ namespace WebsitePanel.Providers.OS
private const string MSACCESS_DRIVER = "Microsoft Access Driver (*.mdb)";
private const string MSEXCEL_DRIVER = "Microsoft Excel Driver (*.xls)";
private const string TEXT_DRIVER = "Microsoft Text Driver (*.txt; *.csv)";
private const string MXRECORDPATTERN = @"mail exchanger = (.+)";
private const string NSRECORDPATTERN = @"nameserver = (.+)";
#endregion
#region Properties
@ -746,9 +751,61 @@ namespace WebsitePanel.Providers.OS
}
#endregion
public virtual DnsRecordInfo[] GetDomainDnsRecords(string domain, string dnsServer, DnsRecordType recordType)
{
return new DnsRecordInfo[0];
//nslookup -type=mx google.com 195.46.39.39
var command = "nslookup";
var args = string.Format("-type={0} {1} {2}", recordType, domain, dnsServer);
var raw = FileUtils.ExecuteSystemCommand(command, args);
var records = ParseNsLookupResult(raw, dnsServer, recordType);
return records.ToArray();
}
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", "").Trim() : null,
RecordType = recordType,
DnsServer = dnsServer
};
records.Add(dnsRecord);
}
return records;
}
public override bool IsInstalled()

View file

@ -301,54 +301,54 @@ namespace WebsitePanel.Providers.OS
#region Domain LookUp
public override DnsRecordInfo[] GetDomainDnsRecords(string domain, string dnsServer, DnsRecordType recordType)
{
List<DnsRecordInfo> records = new List<DnsRecordInfo>();
//public override DnsRecordInfo[] GetDomainDnsRecords(string domain, string dnsServer, DnsRecordType recordType)
//{
// List<DnsRecordInfo> records = new List<DnsRecordInfo>();
Runspace runSpace = null;
// Runspace runSpace = null;
try
{
runSpace = OpenRunspace();
// try
// {
// runSpace = OpenRunspace();
Command cmd = new Command("Resolve-DnsName");
cmd.Parameters.Add("Name", domain);
cmd.Parameters.Add("Server", dnsServer);
cmd.Parameters.Add("Type", recordType.ToString());
// Command cmd = new Command("Resolve-DnsName");
// cmd.Parameters.Add("Name", domain);
// cmd.Parameters.Add("Server", dnsServer);
// cmd.Parameters.Add("Type", recordType.ToString());
var dnsRecordsPs = ExecuteShellCommand(runSpace, cmd, false);
// var dnsRecordsPs = ExecuteShellCommand(runSpace, cmd, false);
if (dnsRecordsPs != null)
{
foreach (var dnsRecordPs in dnsRecordsPs)
{
DnsRecordInfo newRecord = null;
// if (dnsRecordsPs != null)
// {
// foreach (var dnsRecordPs in dnsRecordsPs)
// {
// DnsRecordInfo newRecord = null;
switch (recordType)
{
case DnsRecordType.MX: { newRecord = CreateDnsRecordFromPsObject(dnsRecordPs, "NameExchange"); break; }
case DnsRecordType.NS: { newRecord = CreateDnsRecordFromPsObject(dnsRecordPs, "NameHost"); break; }
default: continue;
}
// switch (recordType)
// {
// case DnsRecordType.MX: { newRecord = CreateDnsRecordFromPsObject(dnsRecordPs, "NameExchange"); break; }
// case DnsRecordType.NS: { newRecord = CreateDnsRecordFromPsObject(dnsRecordPs, "NameHost"); break; }
// default: continue;
// }
if (newRecord != null)
{
newRecord.DnsServer = dnsServer;
newRecord.RecordType = recordType;
// if (newRecord != null)
// {
// newRecord.DnsServer = dnsServer;
// newRecord.RecordType = recordType;
records.Add(newRecord);
}
}
// records.Add(newRecord);
// }
// }
}
}
finally
{
CloseRunspace(runSpace);
}
// }
// }
// finally
// {
// CloseRunspace(runSpace);
// }
return records.ToArray();
}
// return records.ToArray();
//}
private DnsRecordInfo CreateDnsRecordFromPsObject(PSObject psObject, string valueName)
{

View file

@ -135,6 +135,12 @@
<data name="lblHtmlBody.Text" xml:space="preserve">
<value>HTML Body:</value>
</data>
<data name="lblNoChangesHtmlBody" xml:space="preserve">
<value>No Changes HTML Body:</value>
</data>
<data name="lblNoChangesTextBody.Text" xml:space="preserve">
<value>No Changes Text Body:</value>
</data>
<data name="lblPriority.Text" xml:space="preserve">
<value>Priority:</value>
</data>

View file

@ -41,6 +41,10 @@
<ItemStyle Width="15%"></ItemStyle>
<ItemTemplate>
<%# GetDomainExpirationDate(Eval("ExpirationDate"), Eval("LastUpdateDate"))%>
<div style="display:inline-block" runat="server" Visible='<%# !(bool)Eval("IsSubDomain") && !(bool)Eval("IsInstantAlias") && !(bool)Eval("IsDomainPointer") %>'>
<img style="border-width: 0px;" src="App_Themes/Default/Images/information_icon_small.gif" title="<%# GetDomainDnsRecords((int)Eval("DomainId")) %>">
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="gvDomainsType">

View file

@ -36,6 +36,7 @@ using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Linq;
using WebsitePanel.EnterpriseServer;
@ -123,6 +124,18 @@ namespace WebsitePanel.Portal
}
}
public string GetDomainDnsRecords(int domainId)
{
var records = ES.Services.Servers.GetDomainDnsRecords(domainId);
if (!records.Any())
{
return "No Dns Records";
}
return string.Join("\r\n", records.Select(x=>string.Format("{0}: {1}", x.RecordType, x.Value)));
}
protected void odsDomainsPaged_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.Exception != null)

View file

@ -39,4 +39,20 @@
<td class="Normal" colspan="2">
<asp:TextBox ID="txtTextBody" runat="server" Rows="15" TextMode="MultiLine" Width="680px" CssClass="NormalTextBox" Wrap="false"></asp:TextBox></td>
</tr>
<tr>
<td class="SubHead" colspan="2"><br /><br /><asp:Label ID="Label1" runat="server" meta:resourcekey="lblNoChangesHtmlBody" Text="No Changes HTML Body:"></asp:Label></td>
</tr>
<tr>
<td class="Normal" colspan="2">
<asp:TextBox ID="txtNoChangesHtmlBody" runat="server" Rows="15" TextMode="MultiLine" Width="680px" CssClass="NormalTextBox" Wrap="false"></asp:TextBox></td>
</tr>
<tr>
<td class="SubHead" colspan="2"><br /><br /><asp:Label ID="Label2" runat="server" meta:resourcekey="lblNoChangesTextBody" Text="No Changes Text Body:"></asp:Label></td>
</tr>
<tr>
<td class="Normal" colspan="2">
<asp:TextBox ID="txtNoChangesTextBody" runat="server" Rows="15" TextMode="MultiLine" Width="680px" CssClass="NormalTextBox" Wrap="false"></asp:TextBox></td>
</tr>
</table>

View file

@ -18,6 +18,9 @@ namespace WebsitePanel.Portal
Utils.SelectListItem(ddlPriority, settings["Priority"]);
txtHtmlBody.Text = settings["HtmlBody"];
txtTextBody.Text = settings["TextBody"];
txtNoChangesHtmlBody.Text = settings["NoChangesHtmlBody"];
txtNoChangesTextBody.Text = settings["NoChangesTextBody"];
}
public void SaveSettings(UserSettings settings)
@ -28,6 +31,9 @@ namespace WebsitePanel.Portal
settings["Priority"] = ddlPriority.SelectedValue;
settings["HtmlBody"] = txtHtmlBody.Text;
settings["TextBody"] = txtTextBody.Text;
settings["NoChangesHtmlBody"] = txtNoChangesHtmlBody.Text;
settings["NoChangesTextBody"] = txtNoChangesTextBody.Text;
}
}
}

View file

@ -119,5 +119,41 @@ namespace WebsitePanel.Portal {
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.TextBox txtTextBody;
/// <summary>
/// Label1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label Label1;
/// <summary>
/// txtNoChangesHtmlBody control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.TextBox txtNoChangesHtmlBody;
/// <summary>
/// Label2 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label Label2;
/// <summary>
/// txtNoChangesTextBody control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.TextBox txtNoChangesTextBody;
}
}