diff --git a/ServerMaint/Program.cs b/ServerMaint/Program.cs
index 687ac2d..f7a2612 100644
--- a/ServerMaint/Program.cs
+++ b/ServerMaint/Program.cs
@@ -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.
diff --git a/Teknik/Areas/API/Controllers/APIv1Controller.cs b/Teknik/Areas/API/Controllers/APIv1Controller.cs
index c6c0cc0..674475d 100644
--- a/Teknik/Areas/API/Controllers/APIv1Controller.cs
+++ b/Teknik/Areas/API/Controllers/APIv1Controller.cs
@@ -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
{
diff --git a/Teknik/Areas/Blog/Controllers/BlogController.cs b/Teknik/Areas/Blog/Controllers/BlogController.cs
index 8f03ee3..71cd74a 100644
--- a/Teknik/Areas/Blog/Controllers/BlogController.cs
+++ b/Teknik/Areas/Blog/Controllers/BlogController.cs
@@ -14,7 +14,6 @@ using Teknik.Controllers;
using Teknik.Filters;
using Teknik.Utilities;
using Teknik.Models;
-using Teknik.Utilities;
namespace Teknik.Areas.Blog.Controllers
{
diff --git a/Teknik/Areas/Contact/Controllers/ContactController.cs b/Teknik/Areas/Contact/Controllers/ContactController.cs
index 696dafb..cd3ad72 100644
--- a/Teknik/Areas/Contact/Controllers/ContactController.cs
+++ b/Teknik/Areas/Contact/Controllers/ContactController.cs
@@ -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}>
diff --git a/Teknik/Areas/Error/Controllers/ErrorController.cs b/Teknik/Areas/Error/Controllers/ErrorController.cs
index 9d214f0..126e295 100644
--- a/Teknik/Areas/Error/Controllers/ErrorController.cs
+++ b/Teknik/Areas/Error/Controllers/ErrorController.cs
@@ -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"];
diff --git a/Teknik/Areas/Paste/Controllers/PasteController.cs b/Teknik/Areas/Paste/Controllers/PasteController.cs
index ea459bf..b0f9d22 100644
--- a/Teknik/Areas/Paste/Controllers/PasteController.cs
+++ b/Teknik/Areas/Paste/Controllers/PasteController.cs
@@ -14,7 +14,6 @@ using Teknik.Controllers;
using Teknik.Filters;
using Teknik.Utilities;
using Teknik.Models;
-using Teknik.Utilities;
namespace Teknik.Areas.Paste.Controllers
{
diff --git a/Teknik/Areas/Paste/PasteHelper.cs b/Teknik/Areas/Paste/PasteHelper.cs
index 15b4478..3cbe7ba 100644
--- a/Teknik/Areas/Paste/PasteHelper.cs
+++ b/Teknik/Areas/Paste/PasteHelper.cs
@@ -6,7 +6,6 @@ using System.Web;
using Teknik.Configuration;
using Teknik.Utilities;
using Teknik.Models;
-using Teknik.Utilities;
namespace Teknik.Areas.Paste
{
diff --git a/Teknik/Areas/RSS/Controllers/RSSController.cs b/Teknik/Areas/RSS/Controllers/RSSController.cs
index 1abe2e1..20ec42a 100644
--- a/Teknik/Areas/RSS/Controllers/RSSController.cs
+++ b/Teknik/Areas/RSS/Controllers/RSSController.cs
@@ -11,7 +11,6 @@ using Teknik.Controllers;
using Teknik.Filters;
using Teknik.Utilities;
using Teknik.Models;
-using Teknik.Utilities;
namespace Teknik.Areas.RSS.Controllers
{
diff --git a/Teknik/Areas/Shortener/Shortener.cs b/Teknik/Areas/Shortener/Shortener.cs
index e0eb8a9..7198a92 100644
--- a/Teknik/Areas/Shortener/Shortener.cs
+++ b/Teknik/Areas/Shortener/Shortener.cs
@@ -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
{
diff --git a/Teknik/Areas/Upload/Uploader.cs b/Teknik/Areas/Upload/Uploader.cs
index 4f4337b..0877fa7 100644
--- a/Teknik/Areas/Upload/Uploader.cs
+++ b/Teknik/Areas/Upload/Uploader.cs
@@ -6,7 +6,6 @@ using System.IO;
using Teknik.Configuration;
using Teknik.Models;
using Teknik.Utilities;
-using Teknik.Utilities;
namespace Teknik.Areas.Upload
{
diff --git a/Teknik/Areas/User/Controllers/UserController.cs b/Teknik/Areas/User/Controllers/UserController.cs
index b613f33..0cccf34 100644
--- a/Teknik/Areas/User/Controllers/UserController.cs
+++ b/Teknik/Areas/User/Controllers/UserController.cs
@@ -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;
diff --git a/Teknik/Areas/User/Utility/UserHelper.cs b/Teknik/Areas/User/Utility/UserHelper.cs
index 1612f24..bdef846 100644
--- a/Teknik/Areas/User/Utility/UserHelper.cs
+++ b/Teknik/Areas/User/Utility/UserHelper.cs
@@ -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},
diff --git a/Utilities/Configuration/Configuration.csproj b/Utilities/Configuration/Configuration.csproj
index 4ffcfbe..2ae1b40 100644
--- a/Utilities/Configuration/Configuration.csproj
+++ b/Utilities/Configuration/Configuration.csproj
@@ -51,6 +51,7 @@
+
diff --git a/Utilities/Configuration/ContactConfig.cs b/Utilities/Configuration/ContactConfig.cs
index 16539a8..05a28b9 100644
--- a/Utilities/Configuration/ContactConfig.cs
+++ b/Utilities/Configuration/ContactConfig.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();
}
}
}
diff --git a/Utilities/Configuration/EmailAccount.cs b/Utilities/Configuration/EmailAccount.cs
new file mode 100644
index 0000000..37cf81a
--- /dev/null
+++ b/Utilities/Configuration/EmailAccount.cs
@@ -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;
+ }
+ }
+}
diff --git a/Utilities/Configuration/LoggingConfig.cs b/Utilities/Configuration/LoggingConfig.cs
index f744204..0fd5563 100644
--- a/Utilities/Configuration/LoggingConfig.cs
+++ b/Utilities/Configuration/LoggingConfig.cs
@@ -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;
}
}
}
\ No newline at end of file
diff --git a/Utilities/Logging/Logger.cs b/Utilities/Logging/Logger.cs
index 8a98041..4bcb796 100644
--- a/Utilities/Logging/Logger.cs
+++ b/Utilities/Logging/Logger.cs
@@ -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 */ }
}
}
}
diff --git a/Utilities/Logging/Logging.cs b/Utilities/Logging/Logging.cs
index 7017bbc..e5490f2 100644
--- a/Utilities/Logging/Logging.cs
+++ b/Utilities/Logging/Logging.cs
@@ -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);
}
}
}
diff --git a/Utilities/Logging/Logging.csproj b/Utilities/Logging/Logging.csproj
index af368a8..68d71b3 100644
--- a/Utilities/Logging/Logging.csproj
+++ b/Utilities/Logging/Logging.csproj
@@ -51,6 +51,16 @@
+
+
+ {f0da1b67-af92-4b4a-8669-7e81645ff996}
+ Configuration
+
+
+ {f45de6fc-3754-4954-a20a-4277362cc6c1}
+ Utilities
+
+