The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StatusController.cs 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Threading;
  6. using System.Web;
  7. using System.Web.Mvc;
  8. using Teknik.Areas.Status.ViewModels;
  9. using Teknik.Attributes;
  10. using Teknik.Controllers;
  11. using Teknik.Filters;
  12. using Teknik.Models;
  13. using Teknik.Piwik;
  14. using Teknik.Utilities;
  15. namespace Teknik.Areas.Status.Controllers
  16. {
  17. [TeknikAuthorize]
  18. public class StatusController : DefaultController
  19. {
  20. private TeknikEntities db = new TeknikEntities();
  21. [TrackPageView]
  22. [AllowAnonymous]
  23. public ActionResult Index()
  24. {
  25. ViewBag.Title = "Status Information - " + Config.Title;
  26. ViewBag.Description = "Current status information for the server and resources.";
  27. StatusViewModel model = new StatusViewModel();
  28. // Load initial status info
  29. Upload.Models.Upload upload = db.Uploads.OrderByDescending(u => u.UploadId).FirstOrDefault();
  30. model.UploadCount = (upload != null) ? upload.UploadId : 0;
  31. model.UploadSize = (upload != null) ? db.Uploads.Sum(u => (long)u.ContentLength) : 0;
  32. Paste.Models.Paste paste = db.Pastes.OrderByDescending(p => p.PasteId).FirstOrDefault();
  33. model.PasteCount = (paste != null) ? paste.PasteId : 0;
  34. Users.Models.User user = db.Users.OrderByDescending(u => u.UserId).FirstOrDefault();
  35. model.UserCount = (user != null) ? user.UserId : 0;
  36. Shortener.Models.ShortenedUrl url = db.ShortenedUrls.OrderByDescending(s => s.ShortenedUrlId).FirstOrDefault();
  37. model.ShortenedUrlCount = (url != null) ? url.ShortenedUrlId : 0;
  38. Vault.Models.Vault vault = db.Vaults.OrderByDescending(v => v.VaultId).FirstOrDefault();
  39. model.VaultCount = (url != null) ? vault.VaultId : 0;
  40. return View(model);
  41. }
  42. [HttpGet]
  43. [AllowAnonymous]
  44. public ActionResult GetVisitorData()
  45. {
  46. // Get the data from the Piwik
  47. if (!string.IsNullOrEmpty(Config.PiwikConfig.API))
  48. {
  49. List<VisitorData> dataList = Reporting.GetVisitSummaryByDays(Config, 31);
  50. List<object> uniqueData = new List<object>();
  51. List<object> totalData = new List<object>();
  52. foreach (VisitorData data in dataList.OrderBy(d => d.Date))
  53. {
  54. object uniqueDay = new { x = Convert.ToInt64((data.Date.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds), y = data.UniqueVisitors };
  55. uniqueData.Add(uniqueDay);
  56. object totalDay = new { x = Convert.ToInt64((data.Date.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds), y = data.Visits };
  57. totalData.Add(totalDay);
  58. }
  59. return Json(new { result = new { uniqueVisitors = uniqueData.ToArray(), totalVisitors = totalData.ToArray() } }, JsonRequestBehavior.AllowGet);
  60. }
  61. return Json(new { error = new { message = "Piwik not configured" } }, JsonRequestBehavior.AllowGet);
  62. }
  63. }
  64. }