Browse Source

Added .net core Piwik library.

Removed unused stats charts.
core
Teknikode 4 years ago
parent
commit
0a9ba75dcb
  1. 6
      Teknik/Areas/API/Controllers/APIv1Controller.cs
  2. 2
      Teknik/Areas/About/Controllers/AboutController.cs
  3. 2
      Teknik/Areas/Abuse/Controllers/AbuseController.cs
  4. 6
      Teknik/Areas/Admin/Controllers/AdminController.cs
  5. 4
      Teknik/Areas/Blog/Controllers/BlogController.cs
  6. 2
      Teknik/Areas/Contact/Controllers/ContactController.cs
  7. 2
      Teknik/Areas/Dev/Controllers/DevController.cs
  8. 2
      Teknik/Areas/FAQ/Controllers/FAQController.cs
  9. 22
      Teknik/Areas/Help/Controllers/HelpController.cs
  10. 2
      Teknik/Areas/Home/Controllers/HomeController.cs
  11. 4
      Teknik/Areas/Paste/Controllers/PasteController.cs
  12. 6
      Teknik/Areas/Podcast/Controllers/PodcastController.cs
  13. 2
      Teknik/Areas/Privacy/Controllers/PrivacyController.cs
  14. 2
      Teknik/Areas/Privacy/Views/Privacy/Index.cshtml
  15. 6
      Teknik/Areas/RSS/Controllers/RSSController.cs
  16. 4
      Teknik/Areas/Shortener/Controllers/ShortenerController.cs
  17. 2
      Teknik/Areas/Stats/Controllers/StatsController.cs
  18. 24
      Teknik/Areas/Stats/Views/Stats/Index.cshtml
  19. 2
      Teknik/Areas/TOS/Controllers/TOSController.cs
  20. 4
      Teknik/Areas/Upload/Controllers/UploadController.cs
  21. 22
      Teknik/Areas/User/Controllers/UserController.cs
  22. 8
      Teknik/Areas/Vault/Controllers/VaultController.cs
  23. 28
      Teknik/Filters/TrackDownload.cs
  24. 28
      Teknik/Filters/TrackLink.cs
  25. 50
      Teknik/Filters/TrackPageView.cs
  26. 456
      Teknik/Scripts/Stats/Stats.js
  27. 6
      Teknik/Startup.cs
  28. 2
      Teknik/bundleconfig.json
  29. 95
      Tracking/Tracking.cs
  30. 6
      Tracking/Tracking.csproj
  31. BIN
      Tracking/lib/Piwik.Tracker.NetStandard1.4.dll

6
Teknik/Areas/API/Controllers/APIv1Controller.cs

@ -44,7 +44,7 @@ namespace Teknik.Areas.API.Controllers @@ -44,7 +44,7 @@ namespace Teknik.Areas.API.Controllers
[HttpPost]
[AllowAnonymous]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public async Task<IActionResult> UploadAsync(APIv1UploadModel model)
{
try
@ -197,7 +197,7 @@ namespace Teknik.Areas.API.Controllers @@ -197,7 +197,7 @@ namespace Teknik.Areas.API.Controllers
[HttpPost]
[AllowAnonymous]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public IActionResult Paste(APIv1PasteModel model)
{
try
@ -242,7 +242,7 @@ namespace Teknik.Areas.API.Controllers @@ -242,7 +242,7 @@ namespace Teknik.Areas.API.Controllers
[HttpPost]
[AllowAnonymous]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public IActionResult Shorten(APIv1ShortenModel model)
{
try

2
Teknik/Areas/About/Controllers/AboutController.cs

@ -22,7 +22,7 @@ namespace Teknik.Areas.About.Controllers @@ -22,7 +22,7 @@ namespace Teknik.Areas.About.Controllers
public AboutController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
[AllowAnonymous]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public IActionResult Index([FromServices] Config config)
{
ViewBag.Title = "About - " + config.Title;

2
Teknik/Areas/Abuse/Controllers/AbuseController.cs

@ -21,7 +21,7 @@ namespace Teknik.Areas.Abuse.Controllers @@ -21,7 +21,7 @@ namespace Teknik.Areas.Abuse.Controllers
{
public AbuseController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Index()
{

6
Teknik/Areas/Admin/Controllers/AdminController.cs

@ -27,7 +27,7 @@ namespace Teknik.Areas.Admin.Controllers @@ -27,7 +27,7 @@ namespace Teknik.Areas.Admin.Controllers
public AdminController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base (logger, config, dbContext) { }
[HttpGet]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public ActionResult Dashboard()
{
DashboardViewModel model = new DashboardViewModel();
@ -35,7 +35,7 @@ namespace Teknik.Areas.Admin.Controllers @@ -35,7 +35,7 @@ namespace Teknik.Areas.Admin.Controllers
}
[HttpGet]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public ActionResult UserSearch()
{
UserSearchViewModel model = new UserSearchViewModel();
@ -43,7 +43,7 @@ namespace Teknik.Areas.Admin.Controllers @@ -43,7 +43,7 @@ namespace Teknik.Areas.Admin.Controllers
}
[HttpGet]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public ActionResult UserInfo(string username)
{
if (UserHelper.UserExists(_dbContext, username))

4
Teknik/Areas/Blog/Controllers/BlogController.cs

@ -29,7 +29,7 @@ namespace Teknik.Areas.Blog.Controllers @@ -29,7 +29,7 @@ namespace Teknik.Areas.Blog.Controllers
{
public BlogController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Blog(string username)
{
@ -119,7 +119,7 @@ namespace Teknik.Areas.Blog.Controllers @@ -119,7 +119,7 @@ namespace Teknik.Areas.Blog.Controllers
}
#region Posts
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Post(string username, int id)
{

2
Teknik/Areas/Contact/Controllers/ContactController.cs

@ -25,7 +25,7 @@ namespace Teknik.Areas.Contact.Controllers @@ -25,7 +25,7 @@ namespace Teknik.Areas.Contact.Controllers
{
public ContactController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Index()
{

2
Teknik/Areas/Dev/Controllers/DevController.cs

@ -17,7 +17,7 @@ namespace Teknik.Areas.Dev.Controllers @@ -17,7 +17,7 @@ namespace Teknik.Areas.Dev.Controllers
{
public DevController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Index()
{

2
Teknik/Areas/FAQ/Controllers/FAQController.cs

@ -17,7 +17,7 @@ namespace Teknik.Areas.FAQ.Controllers @@ -17,7 +17,7 @@ namespace Teknik.Areas.FAQ.Controllers
{
public FAQController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Index()
{

22
Teknik/Areas/Help/Controllers/HelpController.cs

@ -17,7 +17,7 @@ namespace Teknik.Areas.Help.Controllers @@ -17,7 +17,7 @@ namespace Teknik.Areas.Help.Controllers
{
public HelpController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Index()
{
@ -26,7 +26,7 @@ namespace Teknik.Areas.Help.Controllers @@ -26,7 +26,7 @@ namespace Teknik.Areas.Help.Controllers
return View(model);
}
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult API(string version, string service)
{
@ -44,7 +44,7 @@ namespace Teknik.Areas.Help.Controllers @@ -44,7 +44,7 @@ namespace Teknik.Areas.Help.Controllers
return RedirectToRoute("Error.Http404");
}
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Blog()
{
@ -53,7 +53,7 @@ namespace Teknik.Areas.Help.Controllers @@ -53,7 +53,7 @@ namespace Teknik.Areas.Help.Controllers
return View("~/Areas/Help/Views/Help/Blog.cshtml", model);
}
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Git()
{
@ -62,7 +62,7 @@ namespace Teknik.Areas.Help.Controllers @@ -62,7 +62,7 @@ namespace Teknik.Areas.Help.Controllers
return View("~/Areas/Help/Views/Help/Git.cshtml", model);
}
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult IRC()
{
@ -71,7 +71,7 @@ namespace Teknik.Areas.Help.Controllers @@ -71,7 +71,7 @@ namespace Teknik.Areas.Help.Controllers
return View("~/Areas/Help/Views/Help/IRC.cshtml", model);
}
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Mail()
{
@ -80,7 +80,7 @@ namespace Teknik.Areas.Help.Controllers @@ -80,7 +80,7 @@ namespace Teknik.Areas.Help.Controllers
return View("~/Areas/Help/Views/Help/Mail.cshtml", model);
}
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Markdown()
{
@ -89,7 +89,7 @@ namespace Teknik.Areas.Help.Controllers @@ -89,7 +89,7 @@ namespace Teknik.Areas.Help.Controllers
return View("~/Areas/Help/Views/Help/Markdown.cshtml", model);
}
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Mumble()
{
@ -98,7 +98,7 @@ namespace Teknik.Areas.Help.Controllers @@ -98,7 +98,7 @@ namespace Teknik.Areas.Help.Controllers
return View("~/Areas/Help/Views/Help/Mumble.cshtml", model);
}
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult RSS()
{
@ -107,7 +107,7 @@ namespace Teknik.Areas.Help.Controllers @@ -107,7 +107,7 @@ namespace Teknik.Areas.Help.Controllers
return View("~/Areas/Help/Views/Help/RSS.cshtml", model);
}
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Tools()
{
@ -116,7 +116,7 @@ namespace Teknik.Areas.Help.Controllers @@ -116,7 +116,7 @@ namespace Teknik.Areas.Help.Controllers
return View("~/Areas/Help/Views/Help/Tools.cshtml", model);
}
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Upload()
{

2
Teknik/Areas/Home/Controllers/HomeController.cs

@ -22,7 +22,7 @@ namespace Teknik.Areas.Home.Controllers @@ -22,7 +22,7 @@ namespace Teknik.Areas.Home.Controllers
{
public HomeController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Index()
{

4
Teknik/Areas/Paste/Controllers/PasteController.cs

@ -27,7 +27,7 @@ namespace Teknik.Areas.Paste.Controllers @@ -27,7 +27,7 @@ namespace Teknik.Areas.Paste.Controllers
{
public PasteController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Index()
{
@ -37,7 +37,7 @@ namespace Teknik.Areas.Paste.Controllers @@ -37,7 +37,7 @@ namespace Teknik.Areas.Paste.Controllers
return View(model);
}
[TrackDownload]
[ServiceFilter(typeof(TrackDownload))]
[AllowAnonymous]
public IActionResult ViewPaste(string type, string url, string password)
{

6
Teknik/Areas/Podcast/Controllers/PodcastController.cs

@ -28,7 +28,7 @@ namespace Teknik.Areas.Podcast.Controllers @@ -28,7 +28,7 @@ namespace Teknik.Areas.Podcast.Controllers
{
public PodcastController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Index()
{
@ -63,7 +63,7 @@ namespace Teknik.Areas.Podcast.Controllers @@ -63,7 +63,7 @@ namespace Teknik.Areas.Podcast.Controllers
}
#region Podcasts
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult View(int episode)
{
@ -84,7 +84,7 @@ namespace Teknik.Areas.Podcast.Controllers @@ -84,7 +84,7 @@ namespace Teknik.Areas.Podcast.Controllers
}
[HttpGet]
[TrackDownload]
[ServiceFilter(typeof(TrackDownload))]
[AllowAnonymous]
[ResponseCache(Duration = 31536000, Location = ResponseCacheLocation.Any)]
public IActionResult Download(int episode, string fileName)

2
Teknik/Areas/Privacy/Controllers/PrivacyController.cs

@ -17,7 +17,7 @@ namespace Teknik.Areas.Privacy.Controllers @@ -17,7 +17,7 @@ namespace Teknik.Areas.Privacy.Controllers
{
public PrivacyController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Index()
{

2
Teknik/Areas/Privacy/Views/Privacy/Index.cshtml

@ -52,7 +52,7 @@ @@ -52,7 +52,7 @@
<p>
We use <a href="http://piwik.org/">Piwik</a> to track user interaction with the site. We keep it hosted on the server locally, so no analytic data is leaving the server. This will store the first 2 bytes of your IP Address (e.g. 192.168.xxx.xxx) as an identifier. If you do not want to be tracked, enable Do Not Track in your browser (Recommended), or by unchecking below.
</p>
<iframe style="border: 0; height: 200px; width: 600px;" src="https://stats.teknik.io/index.php?module=CoreAdminHome&action=optOut&language=en"></iframe>
<iframe style="border: 0; height: 200px; width: 600px;" src="@(Config.PiwikConfig.API)index.php?module=CoreAdminHome&action=optOut&language=en"></iframe>
</div>
</div>
<div class="row">

6
Teknik/Areas/RSS/Controllers/RSSController.cs

@ -31,7 +31,7 @@ namespace Teknik.Areas.RSS.Controllers @@ -31,7 +31,7 @@ namespace Teknik.Areas.RSS.Controllers
{
public RSSController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
[TrackDownload]
[ServiceFilter(typeof(TrackDownload))]
[AllowAnonymous]
public async Task Index()
{
@ -49,7 +49,7 @@ namespace Teknik.Areas.RSS.Controllers @@ -49,7 +49,7 @@ namespace Teknik.Areas.RSS.Controllers
}
}
[TrackDownload]
[ServiceFilter(typeof(TrackDownload))]
[AllowAnonymous]
public async Task Blog(string username)
{
@ -155,7 +155,7 @@ namespace Teknik.Areas.RSS.Controllers @@ -155,7 +155,7 @@ namespace Teknik.Areas.RSS.Controllers
}
}
[TrackDownload]
[ServiceFilter(typeof(TrackDownload))]
[AllowAnonymous]
public async Task Podcast()
{

4
Teknik/Areas/Shortener/Controllers/ShortenerController.cs

@ -22,7 +22,7 @@ namespace Teknik.Areas.Shortener.Controllers @@ -22,7 +22,7 @@ namespace Teknik.Areas.Shortener.Controllers
{
public ShortenerController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Index()
{
@ -31,7 +31,7 @@ namespace Teknik.Areas.Shortener.Controllers @@ -31,7 +31,7 @@ namespace Teknik.Areas.Shortener.Controllers
return View(model);
}
[TrackLink]
[ServiceFilter(typeof(TrackLink))]
[AllowAnonymous]
public IActionResult RedirectToUrl(string url)
{

2
Teknik/Areas/Stats/Controllers/StatsController.cs

@ -23,7 +23,7 @@ namespace Teknik.Areas.Stats.Controllers @@ -23,7 +23,7 @@ namespace Teknik.Areas.Stats.Controllers
{
public StatsController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Index()
{

24
Teknik/Areas/Stats/Views/Stats/Index.cshtml

@ -14,42 +14,22 @@ @@ -14,42 +14,22 @@
@if (Config.StatsConfig.Enabled)
{
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#realtime-stats" role="tab" data-toggle="tab">Realtime Server Usage</a></li>
<li role="presentation"><a href="#site-stats" role="tab" data-toggle="tab">Site Statistics</a></li>
<li role="presentation"><a href="#transactions" role="tab" data-toggle="tab">Transactions</a></li>
<li role="presentation"><a href="#takedowns" role="tab" data-toggle="tab">Takedowns</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="realtime-stats">
<h2 class="text-center"><b>Realtime Server Usage</b></h2>
<hr>
<div class="row">
<div class="col-sm-12">
<div id="cpu-usage-chart"></div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div id="mem-usage-chart"></div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div id="network-usage-chart"></div>
</div>
</div>
</div>
<div role="tabpanel" class="tab-pane" id="site-stats">
<h2 class="text-center"><b>Site Statistics</b></h2>
<hr>
@if (Config.PiwikConfig.Enabled)
{
<div class="row">
@*<div class="row">
<div class="col-sm-12">
<div id="visitor-chart"></div>
</div>
</div>
</div>*@
}
<div class="row">
<div class="col-sm-3 text-center">

2
Teknik/Areas/TOS/Controllers/TOSController.cs

@ -17,7 +17,7 @@ namespace Teknik.Areas.TOS.Controllers @@ -17,7 +17,7 @@ namespace Teknik.Areas.TOS.Controllers
{
public TOSController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Index()
{

4
Teknik/Areas/Upload/Controllers/UploadController.cs

@ -32,7 +32,7 @@ namespace Teknik.Areas.Upload.Controllers @@ -32,7 +32,7 @@ namespace Teknik.Areas.Upload.Controllers
public UploadController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
[HttpGet]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Index()
{
@ -142,7 +142,7 @@ namespace Teknik.Areas.Upload.Controllers @@ -142,7 +142,7 @@ namespace Teknik.Areas.Upload.Controllers
// User did not supply key
[HttpGet]
[TrackDownload]
[ServiceFilter(typeof(TrackDownload))]
[AllowAnonymous]
[ResponseCache(Duration = 31536000, Location = ResponseCacheLocation.Any)]
public IActionResult Download(string file)

22
Teknik/Areas/User/Controllers/UserController.cs

@ -36,7 +36,7 @@ namespace Teknik.Areas.Users.Controllers @@ -36,7 +36,7 @@ namespace Teknik.Areas.Users.Controllers
private static readonly UsedCodesManager usedCodesManager = new UsedCodesManager();
private const string _AuthSessionKey = "AuthenticatedUser";
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult GetPremium()
{
@ -48,7 +48,7 @@ namespace Teknik.Areas.Users.Controllers @@ -48,7 +48,7 @@ namespace Teknik.Areas.Users.Controllers
}
// GET: Profile/Profile
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult ViewProfile(string username)
{
@ -107,13 +107,13 @@ namespace Teknik.Areas.Users.Controllers @@ -107,13 +107,13 @@ namespace Teknik.Areas.Users.Controllers
return View(model);
}
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public IActionResult Settings()
{
return Redirect(Url.SubRouteUrl("user", "User.SecuritySettings"));
}
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public IActionResult ProfileSettings()
{
string username = User.Identity.Name;
@ -140,7 +140,7 @@ namespace Teknik.Areas.Users.Controllers @@ -140,7 +140,7 @@ namespace Teknik.Areas.Users.Controllers
return Redirect(Url.SubRouteUrl("error", "Error.Http403"));
}
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public IActionResult SecuritySettings()
{
string username = User.Identity.Name;
@ -182,7 +182,7 @@ namespace Teknik.Areas.Users.Controllers @@ -182,7 +182,7 @@ namespace Teknik.Areas.Users.Controllers
return Redirect(Url.SubRouteUrl("error", "Error.Http403"));
}
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public IActionResult InviteSettings()
{
string username = User.Identity.Name;
@ -230,7 +230,7 @@ namespace Teknik.Areas.Users.Controllers @@ -230,7 +230,7 @@ namespace Teknik.Areas.Users.Controllers
return Redirect(Url.SubRouteUrl("error", "Error.Http403"));
}
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public IActionResult BlogSettings()
{
string username = User.Identity.Name;
@ -256,7 +256,7 @@ namespace Teknik.Areas.Users.Controllers @@ -256,7 +256,7 @@ namespace Teknik.Areas.Users.Controllers
return Redirect(Url.SubRouteUrl("error", "Error.Http403"));
}
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public IActionResult UploadSettings()
{
string username = User.Identity.Name;
@ -282,7 +282,7 @@ namespace Teknik.Areas.Users.Controllers @@ -282,7 +282,7 @@ namespace Teknik.Areas.Users.Controllers
}
[HttpGet]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult ViewRawPGP(string username)
{
@ -301,7 +301,7 @@ namespace Teknik.Areas.Users.Controllers @@ -301,7 +301,7 @@ namespace Teknik.Areas.Users.Controllers
}
[HttpGet]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Login(string ReturnUrl)
{
@ -412,7 +412,7 @@ namespace Teknik.Areas.Users.Controllers @@ -412,7 +412,7 @@ namespace Teknik.Areas.Users.Controllers
}
[HttpGet]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Register(string inviteCode, string ReturnUrl)
{

8
Teknik/Areas/Vault/Controllers/VaultController.cs

@ -29,7 +29,7 @@ namespace Teknik.Areas.Vault.Controllers @@ -29,7 +29,7 @@ namespace Teknik.Areas.Vault.Controllers
{
public VaultController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult ViewVault(string id)
{
@ -107,7 +107,7 @@ namespace Teknik.Areas.Vault.Controllers @@ -107,7 +107,7 @@ namespace Teknik.Areas.Vault.Controllers
}
[HttpGet]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult NewVault()
{
@ -118,7 +118,7 @@ namespace Teknik.Areas.Vault.Controllers @@ -118,7 +118,7 @@ namespace Teknik.Areas.Vault.Controllers
}
[HttpGet]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult NewVaultFromService(string type, string items)
{
@ -156,7 +156,7 @@ namespace Teknik.Areas.Vault.Controllers @@ -156,7 +156,7 @@ namespace Teknik.Areas.Vault.Controllers
}
[HttpGet]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public IActionResult EditVault(string url, string type, string items)
{
ViewBag.Title = "Edit Vault";

28
Teknik/Filters/TrackDownload.cs

@ -15,9 +15,11 @@ namespace Teknik.Filters @@ -15,9 +15,11 @@ namespace Teknik.Filters
{
public class TrackDownload : ActionFilterAttribute
{
public TrackDownload()
private readonly Config _config;
public TrackDownload(Config config)
{
//_config = config;
_config = config;
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
@ -26,22 +28,22 @@ namespace Teknik.Filters @@ -26,22 +28,22 @@ namespace Teknik.Filters
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
//HttpRequest request = filterContext.HttpContext.Request;
HttpRequest request = filterContext.HttpContext.Request;
//string doNotTrack = request.Headers["DNT"];
//if (string.IsNullOrEmpty(doNotTrack) || doNotTrack != "1")
//{
// string userAgent = request.Headers["User-Agent"].ToString();
string doNotTrack = request.Headers["DNT"];
if (string.IsNullOrEmpty(doNotTrack) || doNotTrack != "1")
{
string userAgent = request.Headers["User-Agent"].ToString();
// string clientIp = request.ClientIPFromRequest(true);
string clientIp = request.ClientIPFromRequest(true);
// string urlReferrer = request.Headers["Referer"].ToString();
string urlReferrer = request.Headers["Referer"].ToString();
// string url = UriHelper.GetEncodedUrl(request);
string url = UriHelper.GetEncodedUrl(request);
// // Fire and forget. Don't need to wait for it.
// Tracking.TrackDownload(_config, userAgent, clientIp, url, urlReferrer);
//}
// Fire and forget. Don't need to wait for it.
Tracking.Tracking.TrackDownload(filterContext.HttpContext, _config, userAgent, clientIp, url, urlReferrer);
}
}
}
}

28
Teknik/Filters/TrackLink.cs

@ -15,9 +15,11 @@ namespace Teknik.Filters @@ -15,9 +15,11 @@ namespace Teknik.Filters
{
public class TrackLink : ActionFilterAttribute
{
public TrackLink()
private readonly Config _config;
public TrackLink(Config config)
{
//_config = config;
_config = config;
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
@ -26,22 +28,22 @@ namespace Teknik.Filters @@ -26,22 +28,22 @@ namespace Teknik.Filters
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
//HttpRequest request = filterContext.HttpContext.Request;
HttpRequest request = filterContext.HttpContext.Request;
//string doNotTrack = request.Headers["DNT"];
//if (string.IsNullOrEmpty(doNotTrack) || doNotTrack != "1")
//{
// string userAgent = request.Headers["User-Agent"].ToString();
string doNotTrack = request.Headers["DNT"];
if (string.IsNullOrEmpty(doNotTrack) || doNotTrack != "1")
{
string userAgent = request.Headers["User-Agent"].ToString();
// string clientIp = request.ClientIPFromRequest(true);
string clientIp = request.ClientIPFromRequest(true);
// string urlReferrer = request.Headers["Referer"].ToString();
string urlReferrer = request.Headers["Referer"].ToString();
// string url = UriHelper.GetEncodedUrl(request);
string url = UriHelper.GetEncodedUrl(request);
// // Fire and forget. Don't need to wait for it.
// Tracking.TrackLink(_config, userAgent, clientIp, url, urlReferrer);
//}
// Fire and forget. Don't need to wait for it.
Tracking.Tracking.TrackLink(filterContext.HttpContext, _config, userAgent, clientIp, url, urlReferrer);
}
}
}
}

50
Teknik/Filters/TrackPageView.cs

@ -10,13 +10,17 @@ using Teknik.Tracking; @@ -10,13 +10,17 @@ using Teknik.Tracking;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc;
namespace Teknik.Filters
{
public class TrackPageView : ActionFilterAttribute
{
public TrackPageView()
private readonly Config _config;
public TrackPageView(Config config)
{
_config = config;
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
@ -25,39 +29,39 @@ namespace Teknik.Filters @@ -25,39 +29,39 @@ namespace Teknik.Filters
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
//HttpRequest request = filterContext.HttpContext.Request;
HttpRequest request = filterContext.HttpContext.Request;
//string doNotTrack = request.Headers["DNT"];
//if (string.IsNullOrEmpty(doNotTrack) || doNotTrack != "1")
//{
// string title = filterContext.Controller?.ViewBag?.Title;
string doNotTrack = request.Headers["DNT"];
if (string.IsNullOrEmpty(doNotTrack) || doNotTrack != "1")
{
string title = (filterContext.Controller as Controller)?.ViewBag?.Title;
// string sub = filterContext.RouteData.Values["sub"].ToString();
// if (string.IsNullOrEmpty(sub))
// {
// sub = request.Host.ToUriComponent().GetSubdomain();
// }
string sub = filterContext.RouteData.Values["sub"].ToString();
if (string.IsNullOrEmpty(sub))
{
sub = request.Host.ToUriComponent().GetSubdomain();
}
// string clientIp = request.ClientIPFromRequest(true);
string clientIp = request.ClientIPFromRequest(true);
// string url = UriHelper.GetEncodedUrl(request);
string url = UriHelper.GetEncodedUrl(request);
// string urlReferrer = request.Headers["Referer"].ToString();
string urlReferrer = request.Headers["Referer"].ToString();
// string userAgent = request.Headers["User-Agent"].ToString();
string userAgent = request.Headers["User-Agent"].ToString();
// int pixelWidth = request.Browser.ScreenPixelsWidth;
// int pixelHeight = request.Browser.ScreenPixelsHeight;
int pixelWidth = 0;
int pixelHeight = 0;
// bool hasCookies = request.Browser.Cookies;
bool hasCookies = false;
// string acceptLang = request.Headers["Accept-Language"];
string acceptLang = request.Headers["Accept-Language"];
// bool hasJava = request.Browser.JavaApplets;
bool hasJava = false;
// // Fire and forget. Don't need to wait for it.
// Tracking.TrackPageView(_config, title, sub, clientIp, url, urlReferrer, userAgent, pixelWidth, pixelHeight, hasCookies, acceptLang, hasJava);
//}
// Fire and forget. Don't need to wait for it.
Tracking.Tracking.TrackPageView(filterContext.HttpContext, _config, title, sub, clientIp, url, urlReferrer, userAgent, pixelWidth, pixelHeight, hasCookies, acceptLang, hasJava);
}
}
}
}

456
Teknik/Scripts/Stats/Stats.js

@ -8,232 +8,232 @@ $(document).ready(function () { @@ -8,232 +8,232 @@ $(document).ready(function () {
$('#donations-section').collapse('hide');
$('#takedowns-section').collapse('hide');
/* ----------------------------------------
CPU Usage
-----------------------------------------*/
cpuUsageChart = new Highcharts.chart({
chart: {
useUTC: false,
renderTo: 'cpu-usage-chart',
type: 'line',
marginRight: 10
},
title: {
text: 'CPU Usage'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
title: {
text: 'Percentage'
},
max: 100,
min: 0,
labels: {
format: '{value}%'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
shared: true,
crosshairs: true,
pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.y:.2f}%</b><br/>'
},
plotOptions: {
line: {
marker: {
enabled: false,
symbol: 'circle',
radius: 2,
states: {
hover: {
enabled: true
}
}
}
}
},
credits: {
enabled: false
},
series: [
{
name: 'Total',
data: []
}
]
});
///* ----------------------------------------
// CPU Usage
//-----------------------------------------*/
//cpuUsageChart = new Highcharts.chart({
// chart: {
// useUTC: false,
// renderTo: 'cpu-usage-chart',
// type: 'line',
// marginRight: 10
// },
// title: {
// text: 'CPU Usage'
// },
// xAxis: {
// type: 'datetime',
// tickPixelInterval: 150
// },
// yAxis: {
// title: {
// text: 'Percentage'
// },
// max: 100,
// min: 0,
// labels: {
// format: '{value}%'
// },
// plotLines: [{
// value: 0,
// width: 1,
// color: '#808080'
// }]
// },
// tooltip: {
// shared: true,
// crosshairs: true,
// pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.y:.2f}%</b><br/>'
// },
// plotOptions: {
// line: {
// marker: {
// enabled: false,
// symbol: 'circle',
// radius: 2,
// states: {
// hover: {
// enabled: true
// }
// }
// }
// }
// },
// credits: {
// enabled: false
// },
// series: [
// {
// name: 'Total',
// data: []
// }
// ]
//});
/* ----------------------------------------
Memory usage
-----------------------------------------*/
memUsageChart = new Highcharts.chart({
chart: {
useUTC: false,
renderTo: 'mem-usage-chart',
type: 'line',
marginRight: 10
},
title: {
text: 'Memory Usage'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
title: {
text: 'Memory'
},
min: 0,
max: totalMemory,
tickInterval: tickInterval,
labels: {
formatter: function () {
return filesize(this.value);
}
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
shared: true,
crosshairs: true,
pointFormatter: function () {
var yVal = filesize(this.y);
///* ----------------------------------------
// Memory usage
//-----------------------------------------*/
//memUsageChart = new Highcharts.chart({
// chart: {
// useUTC: false,
// renderTo: 'mem-usage-chart',
// type: 'line',
// marginRight: 10
// },
// title: {
// text: 'Memory Usage'
// },
// xAxis: {
// type: 'datetime',
// tickPixelInterval: 150
// },
// yAxis: {
// title: {
// text: 'Memory'
// },
// min: 0,
// max: totalMemory,
// tickInterval: tickInterval,
// labels: {
// formatter: function () {
// return filesize(this.value);
// }
// },
// plotLines: [{
// value: 0,
// width: 1,
// color: '#808080'
// }]
// },
// tooltip: {
// shared: true,
// crosshairs: true,
// pointFormatter: function () {
// var yVal = filesize(this.y);
return '<span style="color:' + this.color + '">\u25CF</span> ' + this.series.name + ': <b>' + yVal + '</b><br/>';
}
},
plotOptions: {
line: {
marker: {
enabled: false,
symbol: 'circle',
radius: 2,
states: {
hover: {
enabled: true
}
}
}
}
},
credits: {
enabled: false
},
series: [
{
name: 'Total',
data: []
},
{
name: 'Website',
data: []
},
{
name: 'Database',
data: []
}
]
});
// return '<span style="color:' + this.color + '">\u25CF</span> ' + this.series.name + ': <b>' + yVal + '</b><br/>';
// }
// },
// plotOptions: {
// line: {
// marker: {
// enabled: false,
// symbol: 'circle',
// radius: 2,
// states: {
// hover: {
// enabled: true
// }
// }
// }
// }
// },
// credits: {
// enabled: false
// },
// series: [
// {
// name: 'Total',
// data: []
// },
// {
// name: 'Website',
// data: []
// },
// {
// name: 'Database',
// data: []
// }
// ]
//});
/* ----------------------------------------
Network Usage
-----------------------------------------*/
networkUsageChart = new Highcharts.chart({
chart: {
useUTC: false,
renderTo: 'network-usage-chart',
marginRight: 10
},
title: {
text: 'Network Usage'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
title: {
text: 'Speed'
},
min: 0,
labels: {
formatter: function () {
return getReadableBandwidthString(this.value);
}
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
shared: true,
crosshairs: true,
pointFormatter: function () {
var yVal = getReadableBandwidthString(this.y);
///* ----------------------------------------
// Network Usage
//-----------------------------------------*/
//networkUsageChart = new Highcharts.chart({
// chart: {
// useUTC: false,
// renderTo: 'network-usage-chart',
// marginRight: 10
// },
// title: {
// text: 'Network Usage'
// },
// xAxis: {
// type: 'datetime',
// tickPixelInterval: 150
// },
// yAxis: {
// title: {
// text: 'Speed'
// },
// min: 0,
// labels: {
// formatter: function () {
// return getReadableBandwidthString(this.value);
// }
// },
// plotLines: [{
// value: 0,
// width: 1,
// color: '#808080'
// }]
// },
// tooltip: {
// shared: true,
// crosshairs: true,
// pointFormatter: function () {
// var yVal = getReadableBandwidthString(this.y);
return '<span style="color:' + this.color + '">\u25CF</span> ' + this.series.name + ': <b>' + yVal + '</b><br/>';
}
},
plotOptions: {
area: {
marker: {
enabled: false,
symbol: 'circle',
radius: 2,
states: {
hover: {
enabled: true
}
}
}
},
line: {
marker: {
enabled: false,
symbol: 'circle',
radius: 2,
states: {
hover: {
enabled: true
}
}
}
}
},
credits: {
enabled: false
},
series: [
{
type: 'line',
name: 'Sent',
dashStyle: 'Dash',
color: '#7cb5ec',
data: []
},
{
type: 'area',
name: 'Received',
color: '#7cb5ec',
fillOpacity: 0.3,
data: []
}
]
});
// return '<span style="color:' + this.color + '">\u25CF</span> ' + this.series.name + ': <b>' + yVal + '</b><br/>';
// }
// },
// plotOptions: {
// area: {
// marker: {
// enabled: false,
// symbol: 'circle',
// radius: 2,
// states: {
// hover: {
// enabled: true
// }
// }
// }
// },
// line: {
// marker: {
// enabled: false,
// symbol: 'circle',
// radius: 2,
// states: {
// hover: {
// enabled: true
// }
// }
// }
// }
// },
// credits: {
// enabled: false
// },
// series: [
// {
// type: 'line',
// name: 'Sent',
// dashStyle: 'Dash',
// color: '#7cb5ec',
// data: []
// },
// {
// type: 'area',
// name: 'Received',
// color: '#7cb5ec',
// fillOpacity: 0.3,
// data: []
// }
// ]
//});
/* ----------------------------------------
Visitor History
@ -321,10 +321,10 @@ $(document).ready(function () { @@ -321,10 +321,10 @@ $(document).ready(function () {
});
// Resize the chart when viewing the tab (initial width is wrong due to chart being hidden)
$('a[href="#realtime-stats"]').on('shown.bs.tab',
function(e) {
cpuUsageChart.setSize($('#cpu-usage-chart').width(), $('#cpu-usage-chart').height());
memUsageChart.setSize($('#mem-usage-chart').width(), $('#mem-usage-chart').height());
networkUsageChart.setSize($('#network-usage-chart').width(), $('#network-usage-chart').height());
});
//$('a[href="#realtime-stats"]').on('shown.bs.tab',
// function(e) {
// cpuUsageChart.setSize($('#cpu-usage-chart').width(), $('#cpu-usage-chart').height());
// memUsageChart.setSize($('#mem-usage-chart').width(), $('#mem-usage-chart').height());
// networkUsageChart.setSize($('#network-usage-chart').width(), $('#network-usage-chart').height());
// });
});

6
Teknik/Startup.cs

@ -27,6 +27,7 @@ using Teknik.Areas.Accounts; @@ -27,6 +27,7 @@ using Teknik.Areas.Accounts;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Teknik.Security;
using Teknik.Attributes;
using Teknik.Filters;
namespace Teknik
{
@ -61,6 +62,11 @@ namespace Teknik @@ -61,6 +62,11 @@ namespace Teknik
// Create Configuration Singleton
services.AddScoped<Config, Config>(opt => Config.Load(dataDir));
// Add Tracking Filter scopes
services.AddScoped<TrackDownload>();
services.AddScoped<TrackLink>();
services.AddScoped<TrackPageView>();
// Create the Database Context
services.AddDbContext<TeknikEntities>(options => options
.UseLazyLoadingProxies()

2
Teknik/bundleconfig.json

@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
{
"outputFileName": "./wwwroot/js/blog.min.js",
"inputFiles": [
"././wwwroot/lib/bootbox/js/bootbox.js",
"./wwwroot/lib/bootbox/js/bootbox.js",
"./wwwroot/lib/marked/js/marked.js",
"./wwwroot/lib/sanitize-html/js/sanitize-html.js",
"./wwwroot/js/app/Blog/Blog.js"

95
Tracking/Tracking.cs

@ -1,3 +1,5 @@ @@ -1,3 +1,5 @@
using Microsoft.AspNetCore.Http;
using Piwik.Tracker;
using System;
using System.Web;
using Teknik.Configuration;
@ -7,7 +9,7 @@ namespace Teknik.Tracking @@ -7,7 +9,7 @@ namespace Teknik.Tracking
{
public static class Tracking
{
public static void TrackPageView(Config config, string title, string sub, string clientIp, string url, string urlReferrer, string userAgent, int pixelWidth, int pixelHeight, bool hasCookies, string acceptLang, bool hasJava)
public static void TrackPageView(HttpContext context, Config config, string title, string sub, string clientIp, string url, string urlReferrer, string userAgent, int pixelWidth, int pixelHeight, bool hasCookies, string acceptLang, bool hasJava)
{
try
{
@ -17,32 +19,31 @@ namespace Teknik.Tracking @@ -17,32 +19,31 @@ namespace Teknik.Tracking
{
sub = "dev - " + sub;
}
PiwikTracker tracker = new PiwikTracker(config.PiwikConfig.SiteId, config.PiwikConfig.Url, context);
//PiwikTracker.URL = config.PiwikConfig.Url;
//PiwikTracker tracker = new PiwikTracker(config.PiwikConfig.SiteId, config.PiwikConfig.Url);
// Set Request Info
tracker.SetIp(clientIp);
tracker.SetTokenAuth(config.PiwikConfig.TokenAuth);
//// Set Request Info
//tracker.setIp(clientIp);
//tracker.setTokenAuth(config.PiwikConfig.TokenAuth);
tracker.SetUserAgent(userAgent);
//tracker.setUserAgent(userAgent);
// Set browser info
tracker.SetResolution(pixelWidth, pixelHeight);
tracker.SetBrowserHasCookies(hasCookies);
if (!string.IsNullOrEmpty(acceptLang))
tracker.SetBrowserLanguage(acceptLang);
tracker.SetPlugins(new BrowserPlugins { Java = hasJava });
//// Set browser info
//tracker.setResolution(pixelWidth, pixelHeight);
//tracker.setBrowserHasCookies(hasCookies);
//if (!string.IsNullOrEmpty(acceptLang))
// tracker.setBrowserLanguage(acceptLang);