1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

Added .net core Piwik library.

Removed unused stats charts.
This commit is contained in:
Uncled1023 2018-06-17 21:57:44 -07:00
parent 7bc180164a
commit 0a9ba75dcb
31 changed files with 404 additions and 403 deletions

View File

@ -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
[HttpPost]
[AllowAnonymous]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public IActionResult Paste(APIv1PasteModel model)
{
try
@ -242,7 +242,7 @@ namespace Teknik.Areas.API.Controllers
[HttpPost]
[AllowAnonymous]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public IActionResult Shorten(APIv1ShortenModel model)
{
try

View File

@ -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;

View File

@ -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()
{

View File

@ -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
}
[HttpGet]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public ActionResult UserSearch()
{
UserSearchViewModel model = new UserSearchViewModel();
@ -43,7 +43,7 @@ namespace Teknik.Areas.Admin.Controllers
}
[HttpGet]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public ActionResult UserInfo(string username)
{
if (UserHelper.UserExists(_dbContext, username))

View File

@ -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
}
#region Posts
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Post(string username, int id)
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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
return View(model);
}
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult API(string version, string service)
{
@ -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
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
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
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
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
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
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
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
return View("~/Areas/Help/Views/Help/Tools.cshtml", model);
}
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Upload()
{

View File

@ -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()
{

View File

@ -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
return View(model);
}
[TrackDownload]
[ServiceFilter(typeof(TrackDownload))]
[AllowAnonymous]
public IActionResult ViewPaste(string type, string url, string password)
{

View File

@ -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
}
#region Podcasts
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult View(int episode)
{
@ -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)

View File

@ -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()
{

View File

@ -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">

View File

@ -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
}
}
[TrackDownload]
[ServiceFilter(typeof(TrackDownload))]
[AllowAnonymous]
public async Task Blog(string username)
{
@ -155,7 +155,7 @@ namespace Teknik.Areas.RSS.Controllers
}
}
[TrackDownload]
[ServiceFilter(typeof(TrackDownload))]
[AllowAnonymous]
public async Task Podcast()
{

View File

@ -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
return View(model);
}
[TrackLink]
[ServiceFilter(typeof(TrackLink))]
[AllowAnonymous]
public IActionResult RedirectToUrl(string url)
{

View File

@ -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()
{

View File

@ -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">

View File

@ -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()
{

View File

@ -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
// User did not supply key
[HttpGet]
[TrackDownload]
[ServiceFilter(typeof(TrackDownload))]
[AllowAnonymous]
[ResponseCache(Duration = 31536000, Location = ResponseCacheLocation.Any)]
public IActionResult Download(string file)

View File

@ -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
}
// GET: Profile/Profile
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult ViewProfile(string username)
{
@ -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
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
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
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
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
}
[HttpGet]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult ViewRawPGP(string username)
{
@ -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
}
[HttpGet]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult Register(string inviteCode, string ReturnUrl)
{

View File

@ -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
}
[HttpGet]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
[AllowAnonymous]
public IActionResult NewVault()
{
@ -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
}
[HttpGet]
[TrackPageView]
[ServiceFilter(typeof(TrackPageView))]
public IActionResult EditVault(string url, string type, string items)
{
ViewBag.Title = "Edit Vault";

View File

@ -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
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);
}
}
}
}

View File

@ -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
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);
}
}
}
}

View File

@ -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
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);
}
}
}
}

View File

@ -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 () {
});
// 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());
// });
});

View File

@ -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
// 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()

View File

@ -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"

View File

@ -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
{
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
{
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);
//tracker.setPlugins(new BrowserPlugins {java = hasJava});
// Get Referral
if (!string.IsNullOrEmpty(urlReferrer))
tracker.SetUrlReferrer(urlReferrer);
//// Get Referral
//if (!string.IsNullOrEmpty(urlReferrer))
// tracker.setUrlReferrer(urlReferrer);
if (!string.IsNullOrEmpty(url))
tracker.SetUrl(url);
//if (!string.IsNullOrEmpty(url))
// tracker.setUrl(url);
//// Send the tracking request
//tracker.doTrackPageView(string.Format("{0}/{1}", sub, title));
// Send the tracking request
tracker.DoTrackPageView(string.Format("{0}/{1}", sub, title));
}
}
catch (Exception)
@ -51,43 +52,43 @@ namespace Teknik.Tracking
}
}
public static void TrackDownload(Config config, string userAgent, string clientIp, string url, string urlReferrer)
public static void TrackDownload(HttpContext context, Config config, string userAgent, string clientIp, string url, string urlReferrer)
{
//TrackAction(config. PiwikTracker.ActionType.download, userAgent, clientIp, url, urlReferrer);
TrackAction(context, config, ActionType.Download, userAgent, clientIp, url, urlReferrer);
}
public static void TrackLink(Config config, string userAgent, string clientIp, string url, string urlReferrer)
public static void TrackLink(HttpContext context, Config config, string userAgent, string clientIp, string url, string urlReferrer)
{
//TrackAction(config.PiwikTracker.ActionType.link, userAgent, clientIp, url, urlReferrer);
TrackAction(context, config, ActionType.Link, userAgent, clientIp, url, urlReferrer);
}
//private static void TrackAction(Config config, PiwikTracker.ActionType type, string userAgent, string clientIp, string url, string urlReferrer)
//{
// try
// {
// if (config.PiwikConfig.Enabled)
// {
// PiwikTracker tracker = new PiwikTracker(config.PiwikConfig.SiteId, config.PiwikConfig.Url);
private static void TrackAction(HttpContext context, Config config, ActionType type, string userAgent, string clientIp, string url, string urlReferrer)
{
try
{
if (config.PiwikConfig.Enabled)
{
PiwikTracker tracker = new PiwikTracker(config.PiwikConfig.SiteId, config.PiwikConfig.Url, context);
// tracker.setUserAgent(userAgent);
tracker.SetUserAgent(userAgent);
// tracker.setIp(clientIp);
// tracker.setTokenAuth(config.PiwikConfig.TokenAuth);
tracker.SetIp(clientIp);
tracker.SetTokenAuth(config.PiwikConfig.TokenAuth);
// // Get Referral
// if (!string.IsNullOrEmpty(urlReferrer))
// tracker.setUrlReferrer(urlReferrer);
// Get Referral
if (!string.IsNullOrEmpty(urlReferrer))
tracker.SetUrlReferrer(urlReferrer);
// if (!string.IsNullOrEmpty(url))
// tracker.setUrl(url);
if (!string.IsNullOrEmpty(url))
tracker.SetUrl(url);
// tracker.doTrackAction(url, type);
// }
// }
// catch (Exception ex)
// {
tracker.DoTrackAction(url, type);
}
}
catch (Exception ex)
{
// }
//}
}
}
}
}

View File

@ -11,4 +11,10 @@
<ProjectReference Include="..\Configuration\Configuration.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="Piwik.Tracker.NetStandard1.4">
<HintPath>lib\Piwik.Tracker.NetStandard1.4.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

Binary file not shown.