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.

TransparencyController.cs 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Teknik.Areas.Transparency.Models;
  7. using Teknik.Areas.Transparency.ViewModels;
  8. using Teknik.Attributes;
  9. using Teknik.Controllers;
  10. using Teknik.Filters;
  11. using Teknik.Models;
  12. namespace Teknik.Areas.Transparency.Controllers
  13. {
  14. [TeknikAuthorize]
  15. public class TransparencyController : DefaultController
  16. {
  17. private TeknikEntities db = new TeknikEntities();
  18. [TrackPageView]
  19. [AllowAnonymous]
  20. public ActionResult Index()
  21. {
  22. ViewBag.Title = "Transparency - " + Config.Title;
  23. ViewBag.Description = "Teknik transparency and statistics.";
  24. TransparencyViewModel model = new TransparencyViewModel();
  25. if (Config.TransparencyConfig.Enabled)
  26. {
  27. Upload.Models.Upload upload = db.Uploads.OrderByDescending(u => u.UploadId).FirstOrDefault();
  28. model.UploadCount = (upload != null) ? upload.UploadId : 0;
  29. model.UploadSize = (upload != null) ? db.Uploads.Sum(u => (long)u.ContentLength) : 0;
  30. Paste.Models.Paste paste = db.Pastes.OrderByDescending(p => p.PasteId).FirstOrDefault();
  31. model.PasteCount = (paste != null) ? paste.PasteId : 0;
  32. Users.Models.User user = db.Users.OrderByDescending(u => u.UserId).FirstOrDefault();
  33. model.UserCount = (user != null) ? user.UserId : 0;
  34. Shortener.Models.ShortenedUrl url = db.ShortenedUrls.OrderByDescending(s => s.ShortenedUrlId).FirstOrDefault();
  35. model.ShortenedUrlCount = (url != null) ? url.ShortenedUrlId : 0;
  36. model.TotalNet = new Dictionary<string, double>();
  37. var billSums = db.Transactions.OfType<Bill>().GroupBy(b => b.Currency).Select(b => new { currency = b.Key, total = b.Sum(c => c.Amount) }).ToList();
  38. model.TotalBills = new Dictionary<string, double>();
  39. foreach (var sum in billSums)
  40. {
  41. model.TotalBills.Add(sum.currency, sum.total);
  42. if (model.TotalNet.ContainsKey(sum.currency))
  43. {
  44. model.TotalNet[sum.currency] += sum.total;
  45. }
  46. else
  47. {
  48. model.TotalNet.Add(sum.currency, sum.total);
  49. }
  50. }
  51. var oneSums = db.Transactions.OfType<OneTime>().GroupBy(b => b.Currency).Select(b => new { currency = b.Key, total = b.Sum(c => c.Amount) }).ToList();
  52. model.TotalOneTimes = new Dictionary<string, double>();
  53. foreach (var sum in oneSums)
  54. {
  55. model.TotalOneTimes.Add(sum.currency, sum.total);
  56. if (model.TotalNet.ContainsKey(sum.currency))
  57. {
  58. model.TotalNet[sum.currency] += sum.total;
  59. }
  60. else
  61. {
  62. model.TotalNet.Add(sum.currency, sum.total);
  63. }
  64. }
  65. var donationSums = db.Transactions.OfType<Donation>().GroupBy(b => b.Currency).Select(b => new { currency = b.Key, total = b.Sum(c => c.Amount) }).ToList();
  66. model.TotalDonations = new Dictionary<string, double>();
  67. foreach (var sum in donationSums)
  68. {
  69. model.TotalDonations.Add(sum.currency, sum.total);
  70. if (model.TotalNet.ContainsKey(sum.currency))
  71. {
  72. model.TotalNet[sum.currency] += sum.total;
  73. }
  74. else
  75. {
  76. model.TotalNet.Add(sum.currency, sum.total);
  77. }
  78. }
  79. List<Bill> bills = db.Transactions.OfType<Bill>().OrderByDescending(b => b.DateSent).ToList();
  80. model.Bills = (bills != null) ? bills : new List<Bill>();
  81. List<OneTime> oneTimes = db.Transactions.OfType<OneTime>().OrderByDescending(b => b.DateSent).ToList();
  82. model.OneTimes = (oneTimes != null) ? oneTimes : new List<OneTime>();
  83. List<Donation> donations = db.Transactions.OfType<Donation>().OrderByDescending(b => b.DateSent).ToList();
  84. model.Donations = (donations != null) ? donations : new List<Donation>();
  85. List<Takedown> takedowns = db.Takedowns.OrderByDescending(b => b.DateRequested).ToList();
  86. model.Takedowns = (takedowns != null) ? takedowns : new List<Takedown>();
  87. // Grab canary file
  88. if (System.IO.File.Exists(Config.TransparencyConfig.CanaryPath))
  89. {
  90. model.Canary = System.IO.File.ReadAllText(Config.TransparencyConfig.CanaryPath);
  91. }
  92. else
  93. {
  94. model.Canary = string.Empty;
  95. }
  96. }
  97. return View(model);
  98. }
  99. }
  100. }