@@ -216,17 +216,17 @@ namespace ServerMaint | |||
string email = UserHelper.GetUserEmailAddress(config, account); | |||
SmtpClient client = new SmtpClient(); | |||
client.Host = config.ContactConfig.Host; | |||
client.Port = config.ContactConfig.Port; | |||
client.EnableSsl = config.ContactConfig.SSL; | |||
client.Host = config.ContactConfig.EmailAccount.Host; | |||
client.Port = config.ContactConfig.EmailAccount.Port; | |||
client.EnableSsl = config.ContactConfig.EmailAccount.SSL; | |||
client.DeliveryMethod = SmtpDeliveryMethod.Network; | |||
client.UseDefaultCredentials = true; | |||
client.Credentials = new NetworkCredential(config.ContactConfig.Username, config.ContactConfig.Password); | |||
client.Credentials = new NetworkCredential(config.ContactConfig.EmailAccount.Username, config.ContactConfig.EmailAccount.Password); | |||
client.Timeout = 5000; | |||
try | |||
{ | |||
MailMessage mail = new MailMessage(config.SupportEmail, email); | |||
MailMessage mail = new MailMessage(config.ContactConfig.EmailAccount.EmailAddress, email); | |||
mail.Subject = "Invalid Account Notice"; | |||
mail.Body = string.Format(@" | |||
The account {0} does not meet the requirements for a valid username. |
@@ -15,7 +15,6 @@ using Teknik.Areas.Shortener.Models; | |||
using nClam; | |||
using Teknik.Filters; | |||
using Teknik.Areas.API.Models; | |||
using Teknik.Utilities; | |||
namespace Teknik.Areas.API.Controllers | |||
{ |
@@ -14,7 +14,6 @@ using Teknik.Controllers; | |||
using Teknik.Filters; | |||
using Teknik.Utilities; | |||
using Teknik.Models; | |||
using Teknik.Utilities; | |||
namespace Teknik.Areas.Blog.Controllers | |||
{ |
@@ -50,15 +50,15 @@ namespace Teknik.Areas.Contact.Controllers | |||
// Let's also email the message to support | |||
SmtpClient client = new SmtpClient(); | |||
client.Host = Config.ContactConfig.Host; | |||
client.Port = Config.ContactConfig.Port; | |||
client.EnableSsl = Config.ContactConfig.SSL; | |||
client.Host = Config.ContactConfig.EmailAccount.Host; | |||
client.Port = Config.ContactConfig.EmailAccount.Port; | |||
client.EnableSsl = Config.ContactConfig.EmailAccount.SSL; | |||
client.DeliveryMethod = SmtpDeliveryMethod.Network; | |||
client.UseDefaultCredentials = true; | |||
client.Credentials = new System.Net.NetworkCredential(Config.ContactConfig.Username, Config.ContactConfig.Password); | |||
client.Credentials = new System.Net.NetworkCredential(Config.ContactConfig.EmailAccount.Username, Config.ContactConfig.EmailAccount.Password); | |||
client.Timeout = 5000; | |||
MailMessage mail = new MailMessage(Config.SupportEmail, Config.SupportEmail); | |||
MailMessage mail = new MailMessage(Config.ContactConfig.EmailAccount.EmailAddress, Config.SupportEmail); | |||
mail.Subject = string.Format("Support Message from: {0} <{1}>", model.Name, model.Email); | |||
mail.Body = string.Format(@" | |||
New Support Message from: {0} <{1}> |
@@ -27,11 +27,6 @@ namespace Teknik.Areas.Error.Controllers | |||
Response.TrySkipIisCustomErrors = true; | |||
} | |||
if (exception != null) | |||
{ | |||
SendErrorEmail(exception); | |||
} | |||
ErrorViewModel model = new ErrorViewModel(); | |||
model.Exception = exception; | |||
@@ -51,11 +46,6 @@ namespace Teknik.Areas.Error.Controllers | |||
Response.TrySkipIisCustomErrors = true; | |||
} | |||
if (exception != null) | |||
{ | |||
SendErrorEmail(exception); | |||
} | |||
ErrorViewModel model = new ErrorViewModel(); | |||
model.Description = exception.Message; | |||
model.Exception = exception; | |||
@@ -75,11 +65,6 @@ namespace Teknik.Areas.Error.Controllers | |||
Response.TrySkipIisCustomErrors = true; | |||
} | |||
if (exception != null) | |||
{ | |||
SendErrorEmail(exception); | |||
} | |||
ErrorViewModel model = new ErrorViewModel(); | |||
model.Exception = exception; | |||
@@ -117,49 +102,12 @@ namespace Teknik.Areas.Error.Controllers | |||
Response.TrySkipIisCustomErrors = true; | |||
} | |||
if (exception != null) | |||
{ | |||
SendErrorEmail(exception); | |||
} | |||
ErrorViewModel model = new ErrorViewModel(); | |||
model.Exception = exception; | |||
return View("/Areas/Error/Views/Error/Http500.cshtml", model); | |||
} | |||
private void SendErrorEmail(Exception ex) | |||
{ | |||
try | |||
{ | |||
// Let's also email the message to support | |||
SmtpClient client = new SmtpClient(); | |||
client.Host = Config.ContactConfig.Host; | |||
client.Port = Config.ContactConfig.Port; | |||
client.EnableSsl = Config.ContactConfig.SSL; | |||
client.DeliveryMethod = SmtpDeliveryMethod.Network; | |||
client.UseDefaultCredentials = true; | |||
client.Credentials = new System.Net.NetworkCredential(Config.ContactConfig.Username, Config.ContactConfig.Password); | |||
client.Timeout = 5000; | |||
MailMessage mail = new MailMessage(Config.SupportEmail, Config.SupportEmail); | |||
mail.Subject = string.Format("Exception Occured on: {0}", Request.Url.AbsoluteUri); | |||
mail.Body = string.Format(@" | |||
Message: {0} | |||
Source: {1} | |||
IP Address: {2} | |||
Referer Address: {3} | |||
Stack Trace: {4}", ex.GetFullMessage(true), ex.Source, GetIPAddress(), Request.UrlReferrer != null ? Request.UrlReferrer.AbsoluteUri : string.Empty, ex.StackTrace); | |||
mail.BodyEncoding = UTF8Encoding.UTF8; | |||
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.Never; | |||
client.Send(mail); | |||
} | |||
catch (Exception) { /* don't handle something in the handler */ } | |||
} | |||
private string GetIPAddress() | |||
{ | |||
string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; |
@@ -14,7 +14,6 @@ using Teknik.Controllers; | |||
using Teknik.Filters; | |||
using Teknik.Utilities; | |||
using Teknik.Models; | |||
using Teknik.Utilities; | |||
namespace Teknik.Areas.Paste.Controllers | |||
{ |
@@ -6,7 +6,6 @@ using System.Web; | |||
using Teknik.Configuration; | |||
using Teknik.Utilities; | |||
using Teknik.Models; | |||
using Teknik.Utilities; | |||
namespace Teknik.Areas.Paste | |||
{ |
@@ -11,7 +11,6 @@ using Teknik.Controllers; | |||
using Teknik.Filters; | |||
using Teknik.Utilities; | |||
using Teknik.Models; | |||
using Teknik.Utilities; | |||
namespace Teknik.Areas.RSS.Controllers | |||
{ |
@@ -6,7 +6,6 @@ using System.Threading.Tasks; | |||
using Teknik.Areas.Shortener.Models; | |||
using Teknik.Utilities; | |||
using Teknik.Models; | |||
using Teknik.Utilities; | |||
namespace Teknik.Areas.Shortener | |||
{ |
@@ -6,7 +6,6 @@ using System.IO; | |||
using Teknik.Configuration; | |||
using Teknik.Models; | |||
using Teknik.Utilities; | |||
using Teknik.Utilities; | |||
namespace Teknik.Areas.Upload | |||
{ |
@@ -12,7 +12,6 @@ using Teknik.Utilities; | |||
using Teknik.Models; | |||
using Teknik.Areas.Users.Utility; | |||
using Teknik.Filters; | |||
using Teknik.Utilities; | |||
using QRCoder; | |||
using TwoStepsAuthenticator; | |||
using System.Drawing; |
@@ -17,7 +17,6 @@ using Teknik.Areas.Users.Models; | |||
using Teknik.Configuration; | |||
using Teknik.Utilities; | |||
using Teknik.Models; | |||
using Teknik.Utilities; | |||
namespace Teknik.Areas.Users.Utility | |||
{ | |||
@@ -452,15 +451,15 @@ namespace Teknik.Areas.Users.Utility | |||
public static void SendRecoveryEmailVerification(Config config, string username, string email, string resetUrl, string verifyUrl) | |||
{ | |||
SmtpClient client = new SmtpClient(); | |||
client.Host = config.ContactConfig.Host; | |||
client.Port = config.ContactConfig.Port; | |||
client.EnableSsl = config.ContactConfig.SSL; | |||
client.Host = config.ContactConfig.EmailAccount.Host; | |||
client.Port = config.ContactConfig.EmailAccount.Port; | |||
client.EnableSsl = config.ContactConfig.EmailAccount.SSL; | |||
client.DeliveryMethod = SmtpDeliveryMethod.Network; | |||
client.UseDefaultCredentials = true; | |||
client.Credentials = new NetworkCredential(config.NoReplyEmail, config.ContactConfig.Password); | |||
client.Credentials = new NetworkCredential(config.ContactConfig.EmailAccount.Username, config.ContactConfig.EmailAccount.Password); | |||
client.Timeout = 5000; | |||
MailMessage mail = new MailMessage(config.NoReplyEmail, email); | |||
MailMessage mail = new MailMessage(config.ContactConfig.EmailAccount.EmailAddress, email); | |||
mail.Subject = "Recovery Email Validation"; | |||
mail.Body = string.Format(@"Hello {0}, | |||
@@ -533,15 +532,15 @@ Thank you and enjoy! | |||
public static void SendResetPasswordVerification(Config config, string username, string email, string resetUrl) | |||
{ | |||
SmtpClient client = new SmtpClient(); | |||
client.Host = config.ContactConfig.Host; | |||
client.Port = config.ContactConfig.Port; | |||
client.EnableSsl = config.ContactConfig.SSL; | |||
client.Host = config.ContactConfig.EmailAccount.Host; | |||
client.Port = config.ContactConfig.EmailAccount.Port; | |||
client.EnableSsl = config.ContactConfig.EmailAccount.SSL; | |||
client.DeliveryMethod = SmtpDeliveryMethod.Network; | |||
client.UseDefaultCredentials = true; | |||
client.Credentials = new NetworkCredential(config.NoReplyEmail, config.ContactConfig.Password); | |||
client.Credentials = new NetworkCredential(config.ContactConfig.EmailAccount.Username, config.ContactConfig.EmailAccount.Password); | |||
client.Timeout = 5000; | |||
MailMessage mail = new MailMessage(config.NoReplyEmail, email); | |||
MailMessage mail = new MailMessage(config.ContactConfig.EmailAccount.EmailAddress, email); | |||
mail.Subject = "Password Reset Request"; | |||
mail.Body = string.Format(@"Hello {0}, | |||
@@ -51,6 +51,7 @@ | |||
<Compile Include="Config.cs" /> | |||
<Compile Include="ContactConfig.cs" /> | |||
<Compile Include="DatabaseConfig.cs" /> | |||
<Compile Include="EmailAccount.cs" /> | |||
<Compile Include="EmailConfig.cs" /> | |||
<Compile Include="GitConfig.cs" /> | |||
<Compile Include="LoggingConfig.cs" /> |
@@ -10,11 +10,7 @@ namespace Teknik.Configuration | |||
public class ContactConfig | |||
{ | |||
public bool Enabled { get; set; } | |||
public string Host { get; set; } | |||
public int Port { get; set; } | |||
public string Username { get; set; } | |||
public string Password { get; set; } | |||
public bool SSL { get; set; } | |||
public EmailAccount EmailAccount { get; set; } | |||
public ContactConfig() | |||
{ | |||
@@ -24,11 +20,7 @@ namespace Teknik.Configuration | |||
public void SetDefaults() | |||
{ | |||
Enabled = true; | |||
Host = string.Empty; | |||
Port = 25; | |||
Username = string.Empty; | |||
Password = string.Empty; | |||
SSL = false; | |||
EmailAccount = new EmailAccount(); | |||
} | |||
} | |||
} |
@@ -0,0 +1,33 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace Teknik.Configuration | |||
{ | |||
public class EmailAccount | |||
{ | |||
public string EmailAddress { get; set; } | |||
public string Host { get; set; } | |||
public int Port { get; set; } | |||
public string Username { get; set; } | |||
public string Password { get; set; } | |||
public bool SSL { get; set; } | |||
public EmailAccount() | |||
{ | |||
SetDefaults(); | |||
} | |||
public void SetDefaults() | |||
{ | |||
EmailAddress = string.Empty; | |||
Host = string.Empty; | |||
Port = 25; | |||
Username = string.Empty; | |||
Password = string.Empty; | |||
SSL = false; | |||
} | |||
} | |||
} |
@@ -19,6 +19,14 @@ namespace Teknik.Configuration | |||
public int MaxCount { get; set; } | |||
public bool SendEmail { get; set; } | |||
public string EmailLevel { get; set; } | |||
public EmailAccount SenderAccount { get; set; } | |||
public string RecipientEmailAddress { get; set; } | |||
public LoggingConfig() | |||
{ | |||
SetDefaults(); | |||
@@ -32,6 +40,10 @@ namespace Teknik.Configuration | |||
RotateLogs = false; | |||
MaxSize = -1; | |||
MaxCount = -1; | |||
SendEmail = false; | |||
EmailLevel = "Error"; | |||
SenderAccount = new EmailAccount(); | |||
RecipientEmailAddress = string.Empty; | |||
} | |||
} | |||
} |
@@ -1,25 +1,59 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Net.Mail; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using Teknik.Configuration; | |||
namespace Teknik.Logging | |||
{ | |||
public class Logger | |||
{ | |||
public Logger() | |||
{ | |||
private Config m_Config; | |||
public Logger(Config config) | |||
{ | |||
m_Config = config; | |||
} | |||
public void WriteEntry(Exception ex) | |||
{ | |||
// write an entry to the logs | |||
} | |||
public void WriteEntry(string message, LogLevel level) | |||
{ | |||
if (m_Config.LoggingConfig.Enabled) | |||
{ | |||
} | |||
} | |||
private void SendErrorEmail(string subject, string message) | |||
{ | |||
try | |||
{ | |||
// Let's also email the message to support | |||
SmtpClient client = new SmtpClient(); | |||
client.Host = m_Config.LoggingConfig.SenderAccount.Host; | |||
client.Port = m_Config.LoggingConfig.SenderAccount.Port; | |||
client.EnableSsl = m_Config.LoggingConfig.SenderAccount.SSL; | |||
client.DeliveryMethod = SmtpDeliveryMethod.Network; | |||
client.UseDefaultCredentials = true; | |||
client.Credentials = new System.Net.NetworkCredential(m_Config.LoggingConfig.SenderAccount.Username, m_Config.LoggingConfig.SenderAccount.Password); | |||
client.Timeout = 5000; | |||
MailMessage mail = new MailMessage(m_Config.LoggingConfig.SenderAccount.EmailAddress, m_Config.LoggingConfig.RecipientEmailAddress); | |||
mail.Subject = subject; | |||
mail.Body = message; | |||
mail.BodyEncoding = UTF8Encoding.UTF8; | |||
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.Never; | |||
client.Send(mail); | |||
} | |||
catch (Exception) { /* don't handle something in the handler */ } | |||
} | |||
} | |||
} |
@@ -3,27 +3,24 @@ using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using Teknik.Configuration; | |||
namespace Teknik.Logging | |||
{ | |||
public static class Logging | |||
{ | |||
private static Logger m_Logger { get; set; } | |||
public static Logger Logger | |||
{ | |||
get | |||
{ | |||
if (m_Logger == null) | |||
{ | |||
Create(); | |||
} | |||
return m_Logger; | |||
return Create(); | |||
} | |||
} | |||
public static void Create() | |||
public static Logger Create() | |||
{ | |||
m_Logger = new Logger(); | |||
Config curConfig = Config.Load(); | |||
return new Logger(curConfig); | |||
} | |||
} | |||
} |
@@ -51,6 +51,16 @@ | |||
<ItemGroup> | |||
<None Include="packages.config" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\Configuration\Configuration.csproj"> | |||
<Project>{f0da1b67-af92-4b4a-8669-7e81645ff996}</Project> | |||
<Name>Configuration</Name> | |||
</ProjectReference> | |||
<ProjectReference Include="..\Utilities\Utilities.csproj"> | |||
<Project>{f45de6fc-3754-4954-a20a-4277362cc6c1}</Project> | |||
<Name>Utilities</Name> | |||
</ProjectReference> | |||
</ItemGroup> | |||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | |||
<Import Project="..\..\packages\GitVersionTask.3.6.5\build\dotnet\GitVersionTask.targets" Condition="Exists('..\..\packages\GitVersionTask.3.6.5\build\dotnet\GitVersionTask.targets')" /> | |||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> |