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

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