@@ -11,7 +11,6 @@ namespace Teknik | |||
//filters.Add(new HandleErrorAttribute()); | |||
filters.Add(new AuthorizeAttribute()); | |||
filters.Add(new RequireHttpsAttribute()); | |||
filters.Add(new TrackingFilterAttribute()); | |||
} | |||
} | |||
} |
@@ -13,6 +13,7 @@ using Teknik.Models; | |||
using System.Text; | |||
using Teknik.Areas.Shortener.Models; | |||
using nClam; | |||
using Teknik.Filters; | |||
namespace Teknik.Areas.API.Controllers | |||
{ | |||
@@ -28,10 +29,12 @@ namespace Teknik.Areas.API.Controllers | |||
[HttpPost] | |||
[AllowAnonymous] | |||
[TrackPageView] | |||
public ActionResult Upload(HttpPostedFileWrapper file, string contentType = null, bool encrypt = false, bool saveKey = false, string key = null, int keySize = 0, string iv = null, int blockSize = 0, bool genDeletionKey = false, bool doNotTrack = false) | |||
{ | |||
try | |||
{ | |||
ViewBag.Title = "Upload"; | |||
if (file != null) | |||
{ | |||
if (file.ContentLength <= Config.UploadConfig.MaxUploadSize) | |||
@@ -158,10 +161,12 @@ namespace Teknik.Areas.API.Controllers | |||
[HttpPost] | |||
[AllowAnonymous] | |||
[TrackPageView] | |||
public ActionResult Paste(string code, string title = "", string syntax = "auto", string expireUnit = "never", int expireLength = 1, string password = "", bool hide = false, bool doNotTrack = false) | |||
{ | |||
try | |||
{ | |||
ViewBag.Title = "Paste"; | |||
Paste.Models.Paste paste = PasteHelper.CreatePaste(code, title, syntax, expireUnit, expireLength, password, hide); | |||
db.Pastes.Add(paste); | |||
@@ -188,10 +193,12 @@ namespace Teknik.Areas.API.Controllers | |||
[HttpPost] | |||
[AllowAnonymous] | |||
[TrackPageView] | |||
public ActionResult Shorten(string url, bool doNotTrack = false) | |||
{ | |||
try | |||
{ | |||
ViewBag.Title = "Shorten"; | |||
if (url.IsValidUrl()) | |||
{ | |||
ShortenedUrl newUrl = Shortener.Shortener.ShortenUrl(url, Config.ShortenerConfig.UrlLength); |
@@ -5,12 +5,14 @@ using System.Web; | |||
using System.Web.Mvc; | |||
using Teknik.Areas.About.ViewModels; | |||
using Teknik.Controllers; | |||
using Teknik.Filters; | |||
namespace Teknik.Areas.About.Controllers | |||
{ | |||
public class AboutController : DefaultController | |||
{ | |||
[AllowAnonymous] | |||
[TrackPageView] | |||
public ActionResult Index() | |||
{ | |||
ViewBag.Title = "About - " + Config.Title; |
@@ -10,6 +10,7 @@ using Teknik.Areas.Blog.Models; | |||
using Teknik.Areas.Blog.ViewModels; | |||
using Teknik.Areas.Users.Models; | |||
using Teknik.Controllers; | |||
using Teknik.Filters; | |||
using Teknik.Helpers; | |||
using Teknik.Models; | |||
@@ -20,6 +21,7 @@ namespace Teknik.Areas.Blog.Controllers | |||
private TeknikEntities db = new TeknikEntities(); | |||
// GET: Blogs/Details/5 | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Blog(string username) | |||
{ | |||
@@ -74,6 +76,7 @@ namespace Teknik.Areas.Blog.Controllers | |||
} | |||
#region Posts | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Post(string username, int id) | |||
{ |
@@ -9,6 +9,7 @@ using Teknik.Areas.Contact.ViewModels; | |||
using Teknik.Areas.Contact.Models; | |||
using Teknik.Models; | |||
using System.Text; | |||
using Teknik.Filters; | |||
namespace Teknik.Areas.Contact.Controllers | |||
{ | |||
@@ -17,6 +18,7 @@ namespace Teknik.Areas.Contact.Controllers | |||
private TeknikEntities db = new TeknikEntities(); | |||
// GET: Contact/Contact | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Index() | |||
{ |
@@ -4,11 +4,13 @@ using System.Linq; | |||
using System.Web; | |||
using System.Web.Mvc; | |||
using Teknik.Controllers; | |||
using Teknik.Filters; | |||
namespace Teknik.Areas.Dev.Controllers | |||
{ | |||
public class DevController : DefaultController | |||
{ | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
// GET: Dev | |||
public ActionResult Index() |
@@ -5,11 +5,13 @@ using System.Web; | |||
using System.Web.Mvc; | |||
using Teknik.Areas.Error.ViewModels; | |||
using Teknik.Controllers; | |||
using Teknik.Filters; | |||
namespace Teknik.Areas.Error.Controllers | |||
{ | |||
public class ErrorController : DefaultController | |||
{ | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Exception(Exception exception) | |||
{ | |||
@@ -25,6 +27,7 @@ namespace Teknik.Areas.Error.Controllers | |||
return View(model); | |||
} | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult General(Exception exception) | |||
{ | |||
@@ -38,6 +41,7 @@ namespace Teknik.Areas.Error.Controllers | |||
return View(model); | |||
} | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Http403(Exception exception) | |||
{ | |||
@@ -50,6 +54,7 @@ namespace Teknik.Areas.Error.Controllers | |||
return View(model); | |||
} | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Http404(Exception exception) | |||
{ | |||
@@ -62,6 +67,7 @@ namespace Teknik.Areas.Error.Controllers | |||
return View(model); | |||
} | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Http500(Exception exception) | |||
{ |
@@ -5,12 +5,14 @@ using System.Web; | |||
using System.Web.Mvc; | |||
using Teknik.Areas.Help.ViewModels; | |||
using Teknik.Controllers; | |||
using Teknik.Filters; | |||
namespace Teknik.Areas.Help.Controllers | |||
{ | |||
public class HelpController : DefaultController | |||
{ | |||
// GET: Help/Help | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Index() | |||
{ | |||
@@ -19,6 +21,7 @@ namespace Teknik.Areas.Help.Controllers | |||
return View(model); | |||
} | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult API(string version, string service) | |||
{ | |||
@@ -36,6 +39,7 @@ namespace Teknik.Areas.Help.Controllers | |||
return RedirectToRoute("*.Error.Http404"); | |||
} | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Blog() | |||
{ | |||
@@ -44,6 +48,7 @@ namespace Teknik.Areas.Help.Controllers | |||
return View("~/Areas/Help/Views/Help/Blog.cshtml", model); | |||
} | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Git() | |||
{ | |||
@@ -52,6 +57,7 @@ namespace Teknik.Areas.Help.Controllers | |||
return View("~/Areas/Help/Views/Help/Git.cshtml", model); | |||
} | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult IRC() | |||
{ | |||
@@ -60,6 +66,7 @@ namespace Teknik.Areas.Help.Controllers | |||
return View("~/Areas/Help/Views/Help/IRC.cshtml", model); | |||
} | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Mail() | |||
{ | |||
@@ -68,6 +75,7 @@ namespace Teknik.Areas.Help.Controllers | |||
return View("~/Areas/Help/Views/Help/Mail.cshtml", model); | |||
} | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Mumble() | |||
{ | |||
@@ -76,6 +84,7 @@ namespace Teknik.Areas.Help.Controllers | |||
return View("~/Areas/Help/Views/Help/Mumble.cshtml", model); | |||
} | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult RSS() | |||
{ | |||
@@ -84,6 +93,7 @@ namespace Teknik.Areas.Help.Controllers | |||
return View("~/Areas/Help/Views/Help/RSS.cshtml", model); | |||
} | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Upload() | |||
{ |
@@ -9,6 +9,7 @@ using Teknik.Areas.Home.ViewModels; | |||
using Teknik.Controllers; | |||
using Teknik.Helpers; | |||
using Teknik.Models; | |||
using Teknik.Filters; | |||
namespace Teknik.Areas.Home.Controllers | |||
{ | |||
@@ -17,6 +18,7 @@ namespace Teknik.Areas.Home.Controllers | |||
// GET: Home/Home | |||
private TeknikEntities db = new TeknikEntities(); | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Index() | |||
{ |
@@ -9,6 +9,7 @@ using System.Web.Mvc; | |||
using Teknik.Areas.Error.Controllers; | |||
using Teknik.Areas.Paste.ViewModels; | |||
using Teknik.Controllers; | |||
using Teknik.Filters; | |||
using Teknik.Helpers; | |||
using Teknik.Models; | |||
@@ -19,6 +20,7 @@ namespace Teknik.Areas.Paste.Controllers | |||
{ | |||
private TeknikEntities db = new TeknikEntities(); | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Index() | |||
{ | |||
@@ -28,6 +30,7 @@ namespace Teknik.Areas.Paste.Controllers | |||
return View(model); | |||
} | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult ViewPaste(string type, string url, string password) | |||
{ |
@@ -8,6 +8,7 @@ using System.Web.Mvc; | |||
using Teknik.Areas.Podcast.Models; | |||
using Teknik.Areas.Podcast.ViewModels; | |||
using Teknik.Controllers; | |||
using Teknik.Filters; | |||
using Teknik.Models; | |||
namespace Teknik.Areas.Podcast.Controllers | |||
@@ -15,7 +16,8 @@ namespace Teknik.Areas.Podcast.Controllers | |||
public class PodcastController : DefaultController | |||
{ | |||
private TeknikEntities db = new TeknikEntities(); | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Index() | |||
{ | |||
@@ -50,6 +52,7 @@ namespace Teknik.Areas.Podcast.Controllers | |||
} | |||
#region Podcasts | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult View(int episode) | |||
{ |
@@ -5,12 +5,14 @@ using System.Web; | |||
using System.Web.Mvc; | |||
using Teknik.Areas.Privacy.ViewModels; | |||
using Teknik.Controllers; | |||
using Teknik.Filters; | |||
namespace Teknik.Areas.Privacy.Controllers | |||
{ | |||
public class PrivacyController : DefaultController | |||
{ | |||
// GET: Privacy/Privacy | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Index() | |||
{ |
@@ -8,6 +8,7 @@ using System.Web.Mvc; | |||
using System.Xml.Linq; | |||
using Teknik.Areas.Blog.Models; | |||
using Teknik.Controllers; | |||
using Teknik.Filters; | |||
using Teknik.Helpers; | |||
using Teknik.Models; | |||
@@ -17,6 +18,7 @@ namespace Teknik.Areas.RSS.Controllers | |||
{ | |||
private TeknikEntities db = new TeknikEntities(); | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Index() | |||
{ | |||
@@ -25,6 +27,7 @@ namespace Teknik.Areas.RSS.Controllers | |||
return new RssResult(feed); | |||
} | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Blog(string username) | |||
{ | |||
@@ -82,6 +85,7 @@ namespace Teknik.Areas.RSS.Controllers | |||
return new RssResult(badFeed); | |||
} | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Podcast() | |||
{ |
@@ -6,6 +6,7 @@ using System.Web.Mvc; | |||
using Teknik.Areas.Shortener.Models; | |||
using Teknik.Areas.Shortener.ViewModels; | |||
using Teknik.Controllers; | |||
using Teknik.Filters; | |||
using Teknik.Models; | |||
namespace Teknik.Areas.Shortener.Controllers | |||
@@ -14,6 +15,7 @@ namespace Teknik.Areas.Shortener.Controllers | |||
{ | |||
private TeknikEntities db = new TeknikEntities(); | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Index() | |||
{ |
@@ -6,11 +6,13 @@ using System.Web; | |||
using System.Web.Mvc; | |||
using Teknik.Areas.Stream.ViewModels; | |||
using Teknik.Controllers; | |||
using Teknik.Filters; | |||
namespace Teknik.Areas.Stream.Controllers | |||
{ | |||
public class StreamController : DefaultController | |||
{ | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Index() | |||
{ |
@@ -5,12 +5,14 @@ using System.Web; | |||
using System.Web.Mvc; | |||
using Teknik.Areas.TOS.ViewModels; | |||
using Teknik.Controllers; | |||
using Teknik.Filters; | |||
namespace Teknik.Areas.TOS.Controllers | |||
{ | |||
public class TOSController : DefaultController | |||
{ | |||
// GET: Privacy/Privacy | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Index() | |||
{ |
@@ -6,6 +6,7 @@ using System.Web.Mvc; | |||
using Teknik.Areas.Transparency.Models; | |||
using Teknik.Areas.Transparency.ViewModels; | |||
using Teknik.Controllers; | |||
using Teknik.Filters; | |||
using Teknik.Models; | |||
namespace Teknik.Areas.Transparency.Controllers | |||
@@ -14,6 +15,7 @@ namespace Teknik.Areas.Transparency.Controllers | |||
{ | |||
private TeknikEntities db = new TeknikEntities(); | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Index() | |||
{ |
@@ -11,6 +11,7 @@ using Teknik.Areas.Error.ViewModels; | |||
using Teknik.Areas.Upload.Models; | |||
using Teknik.Areas.Upload.ViewModels; | |||
using Teknik.Controllers; | |||
using Teknik.Filters; | |||
using Teknik.Helpers; | |||
using Teknik.Models; | |||
@@ -22,6 +23,7 @@ namespace Teknik.Areas.Upload.Controllers | |||
// GET: Upload/Upload | |||
[HttpGet] | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Index() | |||
{ |
@@ -19,6 +19,7 @@ using Teknik.ViewModels; | |||
using System.Windows; | |||
using System.Net; | |||
using Teknik.Areas.Users.Utility; | |||
using Teknik.Filters; | |||
namespace Teknik.Areas.Users.Controllers | |||
{ | |||
@@ -27,6 +28,7 @@ namespace Teknik.Areas.Users.Controllers | |||
private TeknikEntities db = new TeknikEntities(); | |||
// GET: Profile/Profile | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Index(string username) | |||
{ | |||
@@ -79,7 +81,8 @@ namespace Teknik.Areas.Users.Controllers | |||
} | |||
return View(model); | |||
} | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Settings() | |||
{ | |||
@@ -114,6 +117,7 @@ namespace Teknik.Areas.Users.Controllers | |||
} | |||
[HttpGet] | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult ViewRawPGP(string username) | |||
{ | |||
@@ -132,6 +136,7 @@ namespace Teknik.Areas.Users.Controllers | |||
} | |||
[HttpGet] | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Login(string ReturnUrl) | |||
{ | |||
@@ -201,6 +206,7 @@ namespace Teknik.Areas.Users.Controllers | |||
} | |||
[HttpGet] | |||
[TrackPageView] | |||
[AllowAnonymous] | |||
public ActionResult Register(string ReturnUrl) | |||
{ |
@@ -0,0 +1,36 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Web; | |||
using System.Web.Mvc; | |||
using System.Web.UI; | |||
using Teknik.Configuration; | |||
using Teknik.Helpers; | |||
namespace Teknik.Filters | |||
{ | |||
public class TrackDownload : ActionFilterAttribute | |||
{ | |||
public override void OnActionExecuting(ActionExecutingContext filterContext) | |||
{ | |||
base.OnActionExecuting(filterContext); | |||
} | |||
public override void OnActionExecuted(ActionExecutedContext filterContext) | |||
{ | |||
HttpRequestBase request = filterContext.HttpContext.Request; | |||
// Fire and forget. Don't need to wait for it. | |||
Task.Run(() => AsyncTrackDownload(request, request.Url.ToString())); | |||
base.OnActionExecuted(filterContext); | |||
} | |||
private void AsyncTrackDownload(HttpRequestBase request, string url) | |||
{ | |||
Config config = Config.Load(); | |||
Tracking.TrackDownload(request, config, url); | |||
} | |||
} | |||
} |
@@ -0,0 +1,36 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Web; | |||
using System.Web.Mvc; | |||
using System.Web.UI; | |||
using Teknik.Configuration; | |||
using Teknik.Helpers; | |||
namespace Teknik.Filters | |||
{ | |||
public class TrackLink : ActionFilterAttribute | |||
{ | |||
public override void OnActionExecuting(ActionExecutingContext filterContext) | |||
{ | |||
base.OnActionExecuting(filterContext); | |||
} | |||
public override void OnActionExecuted(ActionExecutedContext filterContext) | |||
{ | |||
HttpRequestBase request = filterContext.HttpContext.Request; | |||
// Fire and forget. Don't need to wait for it. | |||
Task.Run(() => AsyncTrackLink(request, request.Url.ToString())); | |||
base.OnActionExecuted(filterContext); | |||
} | |||
private void AsyncTrackLink(HttpRequestBase request, string url) | |||
{ | |||
Config config = Config.Load(); | |||
Tracking.TrackLink(request, config, url); | |||
} | |||
} | |||
} |
@@ -11,7 +11,7 @@ using Teknik.Helpers; | |||
namespace Teknik.Filters | |||
{ | |||
public class TrackingFilterAttribute : ActionFilterAttribute | |||
public class TrackPageView : ActionFilterAttribute | |||
{ | |||
public override void OnActionExecuting(ActionExecutingContext filterContext) | |||
{ |
@@ -20,7 +20,7 @@ namespace Teknik.Helpers | |||
{ | |||
// Follow Do Not Track | |||
string doNotTrack = request.Headers["DNT"]; | |||
if (!string.IsNullOrEmpty(doNotTrack) && doNotTrack != "1") | |||
if (string.IsNullOrEmpty(doNotTrack) || doNotTrack != "1") | |||
{ | |||
string sub = request.RequestContext.RouteData.Values["sub"].ToString(); | |||
if (string.IsNullOrEmpty(sub)) | |||
@@ -67,25 +67,39 @@ namespace Teknik.Helpers | |||
} | |||
} | |||
public static void TrackAction(HttpRequestBase request, string url) | |||
public static void TrackDownload(HttpRequestBase request, Config config, string url) | |||
{ | |||
TrackAction(request, config, url, PiwikTracker.ActionType.download); | |||
} | |||
public static void TrackLink(HttpRequestBase request, Config config, string url) | |||
{ | |||
TrackAction(request, config, url, PiwikTracker.ActionType.link); | |||
} | |||
private static void TrackAction(HttpRequestBase request, Config config, string url, PiwikTracker.ActionType type) | |||
{ | |||
Config config = Config.Load(); | |||
// Handle Piwik Tracking if enabled | |||
if (config.PiwikConfig.Enabled) | |||
{ | |||
try | |||
{ | |||
PiwikTracker.URL = config.PiwikConfig.Url; | |||
PiwikTracker tracker = new PiwikTracker(config.PiwikConfig.SiteId); | |||
// Follow Do Not Track | |||
string doNotTrack = request.Headers["DNT"]; | |||
if (string.IsNullOrEmpty(doNotTrack) || doNotTrack != "1") | |||
{ | |||
PiwikTracker.URL = config.PiwikConfig.Url; | |||
PiwikTracker tracker = new PiwikTracker(config.PiwikConfig.SiteId); | |||
tracker.setUserAgent(request.UserAgent); | |||
tracker.setUserAgent(request.UserAgent); | |||
string ipAddress = request.ClientIPFromRequest(true); | |||
string ipAddress = request.ClientIPFromRequest(true); | |||
tracker.setIp(ipAddress); | |||
tracker.setTokenAuth(config.PiwikConfig.TokenAuth); | |||
tracker.setIp(ipAddress); | |||
tracker.setTokenAuth(config.PiwikConfig.TokenAuth); | |||
tracker.doTrackAction(url, PiwikTracker.ActionType.download); | |||
tracker.doTrackAction(url, type); | |||
} | |||
} | |||
catch (Exception ex) | |||
{ |
@@ -262,7 +262,9 @@ | |||
<Compile Include="Configuration\UserConfig.cs" /> | |||
<Compile Include="Controllers\DefaultController.cs" /> | |||
<Compile Include="Areas\Dev\Controllers\DevController.cs" /> | |||
<Compile Include="Filters\TrackingFilterAttribute.cs" /> | |||
<Compile Include="Filters\TrackLink.cs" /> | |||
<Compile Include="Filters\TrackDownload.cs" /> | |||
<Compile Include="Filters\TrackPageView.cs" /> | |||
<Compile Include="Global.asax.cs"> | |||
<DependentUpon>Global.asax</DependentUpon> | |||
</Compile> |