mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
- Moved TeknikEntities from global field to disposed local instances.
- Added additional logging/handling of errors. - Added processed/total bytes for uploads, downloads, and encryption/decryption. - Fixed paste CSS bundle using a script handler. - Fixed bad js when viewing a vault
This commit is contained in:
parent
1058b040a4
commit
e163e0ca8c
@ -47,56 +47,57 @@ namespace ServerMaint
|
||||
if (Directory.Exists(configPath))
|
||||
{
|
||||
Config config = Config.Load(configPath);
|
||||
TeknikEntities db = new TeknikEntities();
|
||||
|
||||
Output(string.Format("[{0}] Started Server Maintenance Process.", DateTime.Now));
|
||||
|
||||
// Scan all the uploads for viruses, and remove the bad ones
|
||||
if (options.ScanUploads && config.UploadConfig.VirusScanEnable)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
ScanUploads(config, db);
|
||||
}
|
||||
// Scan all the uploads for viruses, and remove the bad ones
|
||||
if (options.ScanUploads && config.UploadConfig.VirusScanEnable)
|
||||
{
|
||||
ScanUploads(config, db);
|
||||
}
|
||||
|
||||
// Warns all the invalid accounts via email
|
||||
if (options.WarnAccounts)
|
||||
{
|
||||
WarnInvalidAccounts(config, db);
|
||||
}
|
||||
// Warns all the invalid accounts via email
|
||||
if (options.WarnAccounts)
|
||||
{
|
||||
WarnInvalidAccounts(config, db);
|
||||
}
|
||||
|
||||
// Cleans all inactive users
|
||||
if (options.CleanUsers)
|
||||
{
|
||||
CleanAccounts(config, db, options.DaysBeforeDeletion);
|
||||
}
|
||||
// Cleans all inactive users
|
||||
if (options.CleanUsers)
|
||||
{
|
||||
CleanAccounts(config, db, options.DaysBeforeDeletion);
|
||||
}
|
||||
|
||||
// Cleans the email for unused accounts
|
||||
if (options.CleanEmails)
|
||||
{
|
||||
CleanEmail(config, db);
|
||||
}
|
||||
// Cleans the email for unused accounts
|
||||
if (options.CleanEmails)
|
||||
{
|
||||
CleanEmail(config, db);
|
||||
}
|
||||
|
||||
// Cleans all the git accounts that are unused
|
||||
if (options.CleanGit)
|
||||
{
|
||||
CleanGit(config, db);
|
||||
}
|
||||
// Cleans all the git accounts that are unused
|
||||
if (options.CleanGit)
|
||||
{
|
||||
CleanGit(config, db);
|
||||
}
|
||||
|
||||
// Generates a file for all of the user's last seen dates
|
||||
if (options.GenerateLastSeen)
|
||||
{
|
||||
GenerateLastSeen(config, db, options.LastSeenFile);
|
||||
}
|
||||
// Generates a file for all of the user's last seen dates
|
||||
if (options.GenerateLastSeen)
|
||||
{
|
||||
GenerateLastSeen(config, db, options.LastSeenFile);
|
||||
}
|
||||
|
||||
// Generates a file for all of the invalid accounts
|
||||
if (options.GenerateInvalid)
|
||||
{
|
||||
GenerateInvalidAccounts(config, db, options.InvalidFile);
|
||||
}
|
||||
// Generates a file for all of the invalid accounts
|
||||
if (options.GenerateInvalid)
|
||||
{
|
||||
GenerateInvalidAccounts(config, db, options.InvalidFile);
|
||||
}
|
||||
|
||||
// Generates a file for all of the accounts to be cleaned
|
||||
if (options.GenerateCleaning)
|
||||
{
|
||||
GenerateCleaningList(config, db, options.CleaningFile, options.DaysBeforeDeletion);
|
||||
// Generates a file for all of the accounts to be cleaned
|
||||
if (options.GenerateCleaning)
|
||||
{
|
||||
GenerateCleaningList(config, db, options.CleaningFile, options.DaysBeforeDeletion);
|
||||
}
|
||||
}
|
||||
|
||||
Output(string.Format("[{0}] Finished Server Maintenance Process.", DateTime.Now));
|
||||
|
@ -16,8 +16,6 @@ namespace Teknik.Areas.API.Controllers
|
||||
[TeknikAuthorize]
|
||||
public class APIController : DefaultController
|
||||
{
|
||||
private TeknikEntities db = new TeknikEntities();
|
||||
|
||||
[AllowAnonymous]
|
||||
public ActionResult Index()
|
||||
{
|
||||
|
@ -24,8 +24,6 @@ namespace Teknik.Areas.API.Controllers
|
||||
[TeknikAuthorize(AuthType.Basic)]
|
||||
public class APIv1Controller : DefaultController
|
||||
{
|
||||
private TeknikEntities db = new TeknikEntities();
|
||||
|
||||
[AllowAnonymous]
|
||||
public ActionResult Index()
|
||||
{
|
||||
@ -81,49 +79,52 @@ namespace Teknik.Areas.API.Controllers
|
||||
if (model.blockSize <= 0)
|
||||
model.blockSize = Config.UploadConfig.BlockSize;
|
||||
|
||||
// Save the file data
|
||||
Upload.Models.Upload upload = Uploader.SaveFile(db, Config, model.file.InputStream, model.contentType, contentLength, model.encrypt, fileExt, model.iv, model.key, model.keySize, model.blockSize);
|
||||
|
||||
if (upload != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
// Associate this with the user if they provided an auth key
|
||||
if (User.Identity.IsAuthenticated)
|
||||
// Save the file data
|
||||
Upload.Models.Upload upload = Uploader.SaveFile(db, Config, model.file.InputStream, model.contentType, contentLength, model.encrypt, fileExt, model.iv, model.key, model.keySize, model.blockSize);
|
||||
|
||||
if (upload != null)
|
||||
{
|
||||
User foundUser = UserHelper.GetUser(db, User.Identity.Name);
|
||||
if (foundUser != null)
|
||||
// Associate this with the user if they provided an auth key
|
||||
if (User.Identity.IsAuthenticated)
|
||||
{
|
||||
upload.UserId = foundUser.UserId;
|
||||
User foundUser = UserHelper.GetUser(db, User.Identity.Name);
|
||||
if (foundUser != null)
|
||||
{
|
||||
upload.UserId = foundUser.UserId;
|
||||
db.Entry(upload).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
// Generate delete key only if asked to
|
||||
if (!model.genDeletionKey)
|
||||
{
|
||||
upload.DeleteKey = string.Empty;
|
||||
db.Entry(upload).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
// Pull all the information together
|
||||
string fullUrl = Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Url });
|
||||
var returnData = new
|
||||
{
|
||||
url = (model.saveKey || string.IsNullOrEmpty(model.key)) ? fullUrl : fullUrl + "#" + model.key,
|
||||
fileName = upload.Url,
|
||||
contentType = model.contentType,
|
||||
contentLength = contentLength,
|
||||
key = model.key,
|
||||
keySize = model.keySize,
|
||||
iv = model.iv,
|
||||
blockSize = model.blockSize,
|
||||
deletionKey = upload.DeleteKey
|
||||
|
||||
};
|
||||
return Json(new { result = returnData });
|
||||
}
|
||||
|
||||
// Generate delete key only if asked to
|
||||
if (!model.genDeletionKey)
|
||||
{
|
||||
upload.DeleteKey = string.Empty;
|
||||
db.Entry(upload).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
// Pull all the information together
|
||||
string fullUrl = Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Url });
|
||||
var returnData = new
|
||||
{
|
||||
url = (model.saveKey || string.IsNullOrEmpty(model.key)) ? fullUrl : fullUrl + "#" + model.key,
|
||||
fileName = upload.Url,
|
||||
contentType = model.contentType,
|
||||
contentLength = contentLength,
|
||||
key = model.key,
|
||||
keySize = model.keySize,
|
||||
iv = model.iv,
|
||||
blockSize = model.blockSize,
|
||||
deletionKey = upload.DeleteKey
|
||||
|
||||
};
|
||||
return Json(new { result = returnData });
|
||||
return Json(new { error = new { message = "Unable to save file" } });
|
||||
}
|
||||
return Json(new { error = new { message = "Unable to save file" } });
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -149,33 +150,36 @@ namespace Teknik.Areas.API.Controllers
|
||||
{
|
||||
if (model != null && model.code != null)
|
||||
{
|
||||
Paste.Models.Paste paste = PasteHelper.CreatePaste(model.code, model.title, model.syntax, model.expireUnit, model.expireLength, model.password, model.hide);
|
||||
|
||||
// Associate this with the user if they are logged in
|
||||
if (User.Identity.IsAuthenticated)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
User foundUser = UserHelper.GetUser(db, User.Identity.Name);
|
||||
if (foundUser != null)
|
||||
Paste.Models.Paste paste = PasteHelper.CreatePaste(db, model.code, model.title, model.syntax, model.expireUnit, model.expireLength, model.password, model.hide);
|
||||
|
||||
// Associate this with the user if they are logged in
|
||||
if (User.Identity.IsAuthenticated)
|
||||
{
|
||||
paste.UserId = foundUser.UserId;
|
||||
User foundUser = UserHelper.GetUser(db, User.Identity.Name);
|
||||
if (foundUser != null)
|
||||
{
|
||||
paste.UserId = foundUser.UserId;
|
||||
}
|
||||
}
|
||||
|
||||
db.Pastes.Add(paste);
|
||||
db.SaveChanges();
|
||||
|
||||
return Json(new
|
||||
{
|
||||
result = new
|
||||
{
|
||||
id = paste.Url,
|
||||
url = Url.SubRouteUrl("p", "Paste.View", new { type = "Full", url = paste.Url, password = model.password }),
|
||||
title = paste.Title,
|
||||
syntax = paste.Syntax,
|
||||
expiration = paste.ExpireDate,
|
||||
password = model.password
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
db.Pastes.Add(paste);
|
||||
db.SaveChanges();
|
||||
|
||||
return Json(new
|
||||
{
|
||||
result = new
|
||||
{
|
||||
id = paste.Url,
|
||||
url = Url.SubRouteUrl("p", "Paste.View", new { type = "Full", url = paste.Url, password = model.password }),
|
||||
title = paste.Title,
|
||||
syntax = paste.Syntax,
|
||||
expiration = paste.ExpireDate,
|
||||
password = model.password
|
||||
}
|
||||
});
|
||||
}
|
||||
return Json(new { error = new { message = "Invalid Paste Request" } });
|
||||
}
|
||||
@ -194,35 +198,38 @@ namespace Teknik.Areas.API.Controllers
|
||||
{
|
||||
if (model.url.IsValidUrl())
|
||||
{
|
||||
ShortenedUrl newUrl = Shortener.Shortener.ShortenUrl(model.url, Config.ShortenerConfig.UrlLength);
|
||||
|
||||
// Associate this with the user if they are logged in
|
||||
if (User.Identity.IsAuthenticated)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
User foundUser = UserHelper.GetUser(db, User.Identity.Name);
|
||||
if (foundUser != null)
|
||||
ShortenedUrl newUrl = Shortener.Shortener.ShortenUrl(db, model.url, Config.ShortenerConfig.UrlLength);
|
||||
|
||||
// Associate this with the user if they are logged in
|
||||
if (User.Identity.IsAuthenticated)
|
||||
{
|
||||
newUrl.UserId = foundUser.UserId;
|
||||
User foundUser = UserHelper.GetUser(db, User.Identity.Name);
|
||||
if (foundUser != null)
|
||||
{
|
||||
newUrl.UserId = foundUser.UserId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
db.ShortenedUrls.Add(newUrl);
|
||||
db.SaveChanges();
|
||||
db.ShortenedUrls.Add(newUrl);
|
||||
db.SaveChanges();
|
||||
|
||||
string shortUrl = string.Format("{0}://{1}/{2}", HttpContext.Request.Url.Scheme, Config.ShortenerConfig.ShortenerHost, newUrl.ShortUrl);
|
||||
if (Config.DevEnvironment)
|
||||
{
|
||||
shortUrl = Url.SubRouteUrl("shortened", "Shortener.View", new { url = newUrl.ShortUrl });
|
||||
}
|
||||
|
||||
return Json(new
|
||||
{
|
||||
result = new
|
||||
string shortUrl = string.Format("{0}://{1}/{2}", HttpContext.Request.Url.Scheme, Config.ShortenerConfig.ShortenerHost, newUrl.ShortUrl);
|
||||
if (Config.DevEnvironment)
|
||||
{
|
||||
shortUrl = shortUrl,
|
||||
originalUrl = model.url
|
||||
shortUrl = Url.SubRouteUrl("shortened", "Shortener.View", new { url = newUrl.ShortUrl });
|
||||
}
|
||||
});
|
||||
|
||||
return Json(new
|
||||
{
|
||||
result = new
|
||||
{
|
||||
shortUrl = shortUrl,
|
||||
originalUrl = model.url
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return Json(new { error = new { message = "Must be a valid Url" } });
|
||||
}
|
||||
|
@ -17,8 +17,6 @@ namespace Teknik.Areas.Contact.Controllers
|
||||
[TeknikAuthorize]
|
||||
public class ContactController : DefaultController
|
||||
{
|
||||
private TeknikEntities db = new TeknikEntities();
|
||||
|
||||
// GET: Contact/Contact
|
||||
[TrackPageView]
|
||||
[AllowAnonymous]
|
||||
@ -40,15 +38,18 @@ namespace Teknik.Areas.Contact.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
// Insert the message into the DB
|
||||
Models.Contact newContact = db.Contact.Create();
|
||||
newContact.Name = model.Name;
|
||||
newContact.Email = model.Email;
|
||||
newContact.Subject = model.Subject;
|
||||
newContact.Message = model.Message;
|
||||
newContact.DateAdded = DateTime.Now;
|
||||
db.Contact.Add(newContact);
|
||||
db.SaveChanges();
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
// Insert the message into the DB
|
||||
Models.Contact newContact = db.Contact.Create();
|
||||
newContact.Name = model.Name;
|
||||
newContact.Email = model.Email;
|
||||
newContact.Subject = model.Subject;
|
||||
newContact.Message = model.Message;
|
||||
newContact.DateAdded = DateTime.Now;
|
||||
db.Contact.Add(newContact);
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
// Let's also email the message to support
|
||||
SmtpClient client = new SmtpClient();
|
||||
|
@ -10,8 +10,6 @@ namespace Teknik.Areas.Contact.ViewModels
|
||||
{
|
||||
public class ContactViewModel : ViewModelBase
|
||||
{
|
||||
private TeknikEntities db = new TeknikEntities();
|
||||
|
||||
[Required]
|
||||
[Display(Name = "Name")]
|
||||
public string Name { get; set; }
|
||||
@ -27,27 +25,5 @@ namespace Teknik.Areas.Contact.ViewModels
|
||||
[Required]
|
||||
[Display(Name = "Message")]
|
||||
public string Message { get; set; }
|
||||
|
||||
public bool Insert()
|
||||
{
|
||||
bool success = true;
|
||||
try
|
||||
{
|
||||
Models.Contact newContact = db.Contact.Create();
|
||||
newContact.Name = Name;
|
||||
newContact.Email = Email;
|
||||
newContact.Subject = Subject;
|
||||
newContact.Message = Message;
|
||||
newContact.DateAdded = DateTime.Now;
|
||||
db.Contact.Add(newContact);
|
||||
db.SaveChanges();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
}
|
||||
}
|
@ -21,8 +21,6 @@ namespace Teknik.Areas.Paste.Controllers
|
||||
[TeknikAuthorize]
|
||||
public class PasteController : DefaultController
|
||||
{
|
||||
private TeknikEntities db = new TeknikEntities();
|
||||
|
||||
[TrackPageView]
|
||||
[AllowAnonymous]
|
||||
public ActionResult Index()
|
||||
@ -37,6 +35,7 @@ namespace Teknik.Areas.Paste.Controllers
|
||||
[AllowAnonymous]
|
||||
public ActionResult ViewPaste(string type, string url, string password)
|
||||
{
|
||||
TeknikEntities db = new TeknikEntities();
|
||||
Models.Paste paste = db.Pastes.Where(p => p.Url == url).FirstOrDefault();
|
||||
if (paste != null)
|
||||
{
|
||||
@ -156,26 +155,29 @@ namespace Teknik.Areas.Paste.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
Models.Paste paste = PasteHelper.CreatePaste(model.Content, model.Title, model.Syntax, model.ExpireUnit, model.ExpireLength ?? 1, model.Password, model.Hide);
|
||||
|
||||
if (model.ExpireUnit == "view")
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
paste.Views = -1;
|
||||
}
|
||||
Models.Paste paste = PasteHelper.CreatePaste(db, model.Content, model.Title, model.Syntax, model.ExpireUnit, model.ExpireLength ?? 1, model.Password, model.Hide);
|
||||
|
||||
if (User.Identity.IsAuthenticated)
|
||||
{
|
||||
Users.Models.User user = UserHelper.GetUser(db, User.Identity.Name);
|
||||
if (user != null)
|
||||
if (model.ExpireUnit == "view")
|
||||
{
|
||||
paste.UserId = user.UserId;
|
||||
paste.Views = -1;
|
||||
}
|
||||
|
||||
if (User.Identity.IsAuthenticated)
|
||||
{
|
||||
Users.Models.User user = UserHelper.GetUser(db, User.Identity.Name);
|
||||
if (user != null)
|
||||
{
|
||||
paste.UserId = user.UserId;
|
||||
}
|
||||
}
|
||||
|
||||
db.Pastes.Add(paste);
|
||||
db.SaveChanges();
|
||||
|
||||
return Redirect(Url.SubRouteUrl("p", "Paste.View", new { type = "Full", url = paste.Url }));
|
||||
}
|
||||
|
||||
db.Pastes.Add(paste);
|
||||
db.SaveChanges();
|
||||
|
||||
return Redirect(Url.SubRouteUrl("p", "Paste.View", new { type = "Full", url = paste.Url }));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -86,7 +86,7 @@ namespace Teknik.Areas.Paste
|
||||
BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/highlight", config.CdnHost).Include(
|
||||
"~/Scripts/Highlight/highlight.pack.js"));
|
||||
// Register Style Bundles
|
||||
BundleTable.Bundles.Add(new CdnScriptBundle("~/Content/paste", config.CdnHost).Include(
|
||||
BundleTable.Bundles.Add(new CdnStyleBundle("~/Content/paste", config.CdnHost).Include(
|
||||
"~/Content/Highlight/github-gist.css",
|
||||
"~/Areas/Paste/Content/Paste.css"));
|
||||
}
|
||||
|
@ -11,9 +11,8 @@ namespace Teknik.Areas.Paste
|
||||
{
|
||||
public static class PasteHelper
|
||||
{
|
||||
public static Models.Paste CreatePaste(string content, string title = "", string syntax = "text", string expireUnit = "never", int expireLength = 1, string password = "", bool hide = false)
|
||||
public static Models.Paste CreatePaste(TeknikEntities db, string content, string title = "", string syntax = "text", string expireUnit = "never", int expireLength = 1, string password = "", bool hide = false)
|
||||
{
|
||||
TeknikEntities db = new TeknikEntities();
|
||||
Config config = Config.Load();
|
||||
Models.Paste paste = db.Pastes.Create();
|
||||
paste.DatePosted = DateTime.Now;
|
||||
|
@ -19,8 +19,6 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
[TeknikAuthorize]
|
||||
public class PodcastController : DefaultController
|
||||
{
|
||||
private TeknikEntities db = new TeknikEntities();
|
||||
|
||||
[TrackPageView]
|
||||
[AllowAnonymous]
|
||||
public ActionResult Index()
|
||||
@ -33,15 +31,18 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
ViewBag.Title = Config.PodcastConfig.Title + " - " + Config.Title;
|
||||
ViewBag.Description = Config.PodcastConfig.Description;
|
||||
bool editor = User.IsInRole("Podcast");
|
||||
var foundPodcasts = db.Podcasts.Where(p => (p.Published || editor)).FirstOrDefault();
|
||||
if (foundPodcasts != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
model.HasPodcasts = (foundPodcasts != null);
|
||||
}
|
||||
else
|
||||
{
|
||||
model.Error = true;
|
||||
model.ErrorMessage = "No Podcasts Available";
|
||||
var foundPodcasts = db.Podcasts.Where(p => (p.Published || editor)).FirstOrDefault();
|
||||
if (foundPodcasts != null)
|
||||
{
|
||||
model.HasPodcasts = (foundPodcasts != null);
|
||||
}
|
||||
else
|
||||
{
|
||||
model.Error = true;
|
||||
model.ErrorMessage = "No Podcasts Available";
|
||||
}
|
||||
}
|
||||
|
||||
return View("~/Areas/Podcast/Views/Podcast/Main.cshtml", model);
|
||||
@ -63,13 +64,16 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
PodcastViewModel model = new PodcastViewModel();
|
||||
// find the podcast specified
|
||||
bool editor = User.IsInRole("Podcast");
|
||||
var foundPodcast = db.Podcasts.Where(p => ((p.Published || editor) && p.Episode == episode)).FirstOrDefault();
|
||||
if (foundPodcast != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
model = new PodcastViewModel(foundPodcast);
|
||||
var foundPodcast = db.Podcasts.Where(p => ((p.Published || editor) && p.Episode == episode)).FirstOrDefault();
|
||||
if (foundPodcast != null)
|
||||
{
|
||||
model = new PodcastViewModel(foundPodcast);
|
||||
|
||||
ViewBag.Title = model.Title + " - Teknikast - " + Config.Title;
|
||||
return View("~/Areas/Podcast/Views/Podcast/ViewPodcast.cshtml", model);
|
||||
ViewBag.Title = model.Title + " - Teknikast - " + Config.Title;
|
||||
return View("~/Areas/Podcast/Views/Podcast/ViewPodcast.cshtml", model);
|
||||
}
|
||||
}
|
||||
model.Error = true;
|
||||
model.ErrorMessage = "No Podcasts Available";
|
||||
@ -79,112 +83,130 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
[AllowAnonymous]
|
||||
public ActionResult Download(int episode, string fileName)
|
||||
{
|
||||
// find the podcast specified
|
||||
var foundPodcast = db.Podcasts.Where(p => (p.Published && p.Episode == episode)).FirstOrDefault();
|
||||
if (foundPodcast != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
PodcastFile file = foundPodcast.Files.Where(f => f.FileName == fileName).FirstOrDefault();
|
||||
if (file != null)
|
||||
// find the podcast specified
|
||||
var foundPodcast = db.Podcasts.Where(p => (p.Published && p.Episode == episode)).FirstOrDefault();
|
||||
if (foundPodcast != null)
|
||||
{
|
||||
if (System.IO.File.Exists(file.Path))
|
||||
PodcastFile file = foundPodcast.Files.Where(f => f.FileName == fileName).FirstOrDefault();
|
||||
if (file != null)
|
||||
{
|
||||
FileStream fileStream = new FileStream(file.Path, FileMode.Open, FileAccess.Read);
|
||||
|
||||
Response.AddHeader("Content-Length", file.ContentLength.ToString());
|
||||
|
||||
var cd = new System.Net.Mime.ContentDisposition
|
||||
if (System.IO.File.Exists(file.Path))
|
||||
{
|
||||
FileName = file.FileName,
|
||||
Inline = true
|
||||
};
|
||||
FileStream fileStream = new FileStream(file.Path, FileMode.Open, FileAccess.Read);
|
||||
|
||||
Response.AppendHeader("Content-Disposition", cd.ToString());
|
||||
Response.AddHeader("Content-Length", file.ContentLength.ToString());
|
||||
|
||||
return new FileGenerateResult(file.FileName, file.ContentType, (response) => ResponseHelper.StreamToOutput(response, true, fileStream, file.ContentLength, 4 * 1024), false);
|
||||
//return File(data, file.ContentType);
|
||||
var cd = new System.Net.Mime.ContentDisposition
|
||||
{
|
||||
FileName = file.FileName,
|
||||
Inline = true
|
||||
};
|
||||
|
||||
Response.AppendHeader("Content-Disposition", cd.ToString());
|
||||
|
||||
return new FileGenerateResult(file.FileName, file.ContentType, (response) => ResponseHelper.StreamToOutput(response, true, fileStream, file.ContentLength, 4 * 1024), false);
|
||||
//return File(data, file.ContentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
|
||||
}
|
||||
return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public ActionResult GetPodcasts(int startPodcastID, int count)
|
||||
{
|
||||
bool editor = User.IsInRole("Podcast");
|
||||
var podcasts = db.Podcasts.Where(p => p.Published || editor).OrderByDescending(p => p.DatePosted).Skip(startPodcastID).Take(count).ToList();
|
||||
List<PodcastViewModel> podcastViews = new List<PodcastViewModel>();
|
||||
if (podcasts != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
foreach (Models.Podcast podcast in podcasts)
|
||||
bool editor = User.IsInRole("Podcast");
|
||||
var podcasts = db.Podcasts.Where(p => p.Published || editor).OrderByDescending(p => p.DatePosted).Skip(startPodcastID).Take(count).ToList();
|
||||
List<PodcastViewModel> podcastViews = new List<PodcastViewModel>();
|
||||
if (podcasts != null)
|
||||
{
|
||||
podcastViews.Add(new PodcastViewModel(podcast));
|
||||
foreach (Models.Podcast podcast in podcasts)
|
||||
{
|
||||
podcastViews.Add(new PodcastViewModel(podcast));
|
||||
}
|
||||
}
|
||||
return PartialView("~/Areas/Podcast/Views/Podcast/Podcasts.cshtml", podcastViews);
|
||||
}
|
||||
return PartialView("~/Areas/Podcast/Views/Podcast/Podcasts.cshtml", podcastViews);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public ActionResult GetPodcastEpisode(int podcastId)
|
||||
{
|
||||
bool editor = User.IsInRole("Podcast");
|
||||
var foundPodcast = db.Podcasts.Where(p => ((p.Published || editor) && p.PodcastId == podcastId)).FirstOrDefault();
|
||||
if (foundPodcast != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
return Json(new { result = foundPodcast.Episode });
|
||||
bool editor = User.IsInRole("Podcast");
|
||||
var foundPodcast = db.Podcasts.Where(p => ((p.Published || editor) && p.PodcastId == podcastId)).FirstOrDefault();
|
||||
if (foundPodcast != null)
|
||||
{
|
||||
return Json(new { result = foundPodcast.Episode });
|
||||
}
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public ActionResult GetPodcastTitle(int podcastId)
|
||||
{
|
||||
bool editor = User.IsInRole("Podcast");
|
||||
var foundPodcast = db.Podcasts.Where(p => ((p.Published || editor) && p.PodcastId == podcastId)).FirstOrDefault();
|
||||
if (foundPodcast != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
return Json(new { result = foundPodcast.Title });
|
||||
bool editor = User.IsInRole("Podcast");
|
||||
var foundPodcast = db.Podcasts.Where(p => ((p.Published || editor) && p.PodcastId == podcastId)).FirstOrDefault();
|
||||
if (foundPodcast != null)
|
||||
{
|
||||
return Json(new { result = foundPodcast.Title });
|
||||
}
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public ActionResult GetPodcastDescription(int podcastId)
|
||||
{
|
||||
bool editor = User.IsInRole("Podcast");
|
||||
var foundPodcast = db.Podcasts.Where(p => ((p.Published || editor) && p.PodcastId == podcastId)).FirstOrDefault();
|
||||
if (foundPodcast != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
return Json(new { result = foundPodcast.Description });
|
||||
bool editor = User.IsInRole("Podcast");
|
||||
var foundPodcast = db.Podcasts.Where(p => ((p.Published || editor) && p.PodcastId == podcastId)).FirstOrDefault();
|
||||
if (foundPodcast != null)
|
||||
{
|
||||
return Json(new { result = foundPodcast.Description });
|
||||
}
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public ActionResult GetPodcastFiles(int podcastId)
|
||||
{
|
||||
bool editor = User.IsInRole("Podcast");
|
||||
var foundPodcast = db.Podcasts.Where(p => ((p.Published || editor) && p.PodcastId == podcastId)).FirstOrDefault();
|
||||
if (foundPodcast != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
List<object> files = new List<object>();
|
||||
foreach (PodcastFile file in foundPodcast.Files)
|
||||
bool editor = User.IsInRole("Podcast");
|
||||
var foundPodcast = db.Podcasts.Where(p => ((p.Published || editor) && p.PodcastId == podcastId)).FirstOrDefault();
|
||||
if (foundPodcast != null)
|
||||
{
|
||||
object fileObj = new
|
||||
List<object> files = new List<object>();
|
||||
foreach (PodcastFile file in foundPodcast.Files)
|
||||
{
|
||||
name = file.FileName,
|
||||
id = file.PodcastFileId
|
||||
};
|
||||
files.Add(fileObj);
|
||||
object fileObj = new
|
||||
{
|
||||
name = file.FileName,
|
||||
id = file.PodcastFileId
|
||||
};
|
||||
files.Add(fileObj);
|
||||
}
|
||||
return Json(new { result = new { files = files } });
|
||||
}
|
||||
return Json(new { result = new { files = files } });
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -194,25 +216,28 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
{
|
||||
if (User.IsInRole("Podcast"))
|
||||
{
|
||||
// Grab the next episode number
|
||||
Models.Podcast lastPod = db.Podcasts.Where(p => p.Episode == episode).FirstOrDefault();
|
||||
if (lastPod == null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
// Create the podcast object
|
||||
Models.Podcast podcast = db.Podcasts.Create();
|
||||
podcast.Episode = episode;
|
||||
podcast.Title = title;
|
||||
podcast.Description = description;
|
||||
podcast.DatePosted = DateTime.Now;
|
||||
podcast.DatePublished = DateTime.Now;
|
||||
podcast.DateEdited = DateTime.Now;
|
||||
podcast.Files = SaveFiles(Request.Files, episode);
|
||||
// Grab the next episode number
|
||||
Models.Podcast lastPod = db.Podcasts.Where(p => p.Episode == episode).FirstOrDefault();
|
||||
if (lastPod == null)
|
||||
{
|
||||
// Create the podcast object
|
||||
Models.Podcast podcast = db.Podcasts.Create();
|
||||
podcast.Episode = episode;
|
||||
podcast.Title = title;
|
||||
podcast.Description = description;
|
||||
podcast.DatePosted = DateTime.Now;
|
||||
podcast.DatePublished = DateTime.Now;
|
||||
podcast.DateEdited = DateTime.Now;
|
||||
podcast.Files = SaveFiles(Request.Files, episode);
|
||||
|
||||
db.Podcasts.Add(podcast);
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
db.Podcasts.Add(podcast);
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
}
|
||||
return Json(new { error = "That episode already exists" });
|
||||
}
|
||||
return Json(new { error = "That episode already exists" });
|
||||
}
|
||||
return Json(new { error = "You don't have permission to create a podcast" });
|
||||
}
|
||||
@ -226,49 +251,52 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
{
|
||||
if (User.IsInRole("Podcast"))
|
||||
{
|
||||
Models.Podcast podcast = db.Podcasts.Where(p => p.PodcastId == podcastId).FirstOrDefault();
|
||||
if (podcast != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
if (db.Podcasts.Where(p => p.Episode != episode).FirstOrDefault() == null || podcast.Episode == episode)
|
||||
Models.Podcast podcast = db.Podcasts.Where(p => p.PodcastId == podcastId).FirstOrDefault();
|
||||
if (podcast != null)
|
||||
{
|
||||
podcast.Episode = episode;
|
||||
podcast.Title = title;
|
||||
podcast.Description = description;
|
||||
podcast.DateEdited = DateTime.Now;
|
||||
// Remove any files not in fileIds
|
||||
List<string> fileIdList = new List<string>();
|
||||
if (!string.IsNullOrEmpty(fileIds))
|
||||
if (db.Podcasts.Where(p => p.Episode != episode).FirstOrDefault() == null || podcast.Episode == episode)
|
||||
{
|
||||
fileIdList = fileIds.Split(',').ToList();
|
||||
}
|
||||
for (int i = 0; i < podcast.Files.Count; i++)
|
||||
{
|
||||
PodcastFile curFile = podcast.Files.ElementAt(i);
|
||||
if (!fileIdList.Exists(id => id == curFile.PodcastFileId.ToString()))
|
||||
podcast.Episode = episode;
|
||||
podcast.Title = title;
|
||||
podcast.Description = description;
|
||||
podcast.DateEdited = DateTime.Now;
|
||||
// Remove any files not in fileIds
|
||||
List<string> fileIdList = new List<string>();
|
||||
if (!string.IsNullOrEmpty(fileIds))
|
||||
{
|
||||
if (System.IO.File.Exists(curFile.Path))
|
||||
{
|
||||
System.IO.File.Delete(curFile.Path);
|
||||
}
|
||||
db.PodcastFiles.Remove(curFile);
|
||||
podcast.Files.Remove(curFile);
|
||||
fileIdList = fileIds.Split(',').ToList();
|
||||
}
|
||||
for (int i = 0; i < podcast.Files.Count; i++)
|
||||
{
|
||||
PodcastFile curFile = podcast.Files.ElementAt(i);
|
||||
if (!fileIdList.Exists(id => id == curFile.PodcastFileId.ToString()))
|
||||
{
|
||||
if (System.IO.File.Exists(curFile.Path))
|
||||
{
|
||||
System.IO.File.Delete(curFile.Path);
|
||||
}
|
||||
db.PodcastFiles.Remove(curFile);
|
||||
podcast.Files.Remove(curFile);
|
||||
}
|
||||
}
|
||||
// Add any new files
|
||||
List<PodcastFile> newFiles = SaveFiles(Request.Files, episode);
|
||||
foreach (PodcastFile file in newFiles)
|
||||
{
|
||||
podcast.Files.Add(file);
|
||||
}
|
||||
}
|
||||
// Add any new files
|
||||
List<PodcastFile> newFiles = SaveFiles(Request.Files, episode);
|
||||
foreach (PodcastFile file in newFiles)
|
||||
{
|
||||
podcast.Files.Add(file);
|
||||
}
|
||||
|
||||
// Save podcast
|
||||
db.Entry(podcast).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
// Save podcast
|
||||
db.Entry(podcast).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
}
|
||||
return Json(new { error = "That episode already exists" });
|
||||
}
|
||||
return Json(new { error = "That episode already exists" });
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
return Json(new { error = "You don't have permission to edit this podcast" });
|
||||
}
|
||||
@ -282,17 +310,20 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
{
|
||||
if (User.IsInRole("Podcast"))
|
||||
{
|
||||
Models.Podcast podcast = db.Podcasts.Find(podcastId);
|
||||
if (podcast != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
podcast.Published = publish;
|
||||
if (publish)
|
||||
podcast.DatePublished = DateTime.Now;
|
||||
db.Entry(podcast).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
Models.Podcast podcast = db.Podcasts.Find(podcastId);
|
||||
if (podcast != null)
|
||||
{
|
||||
podcast.Published = publish;
|
||||
if (publish)
|
||||
podcast.DatePublished = DateTime.Now;
|
||||
db.Entry(podcast).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
}
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
return Json(new { error = "You don't have permission to publish this podcast" });
|
||||
}
|
||||
@ -306,18 +337,21 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
{
|
||||
if (User.IsInRole("Podcast"))
|
||||
{
|
||||
Models.Podcast podcast = db.Podcasts.Where(p => p.PodcastId == podcastId).FirstOrDefault();
|
||||
if (podcast != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
foreach (PodcastFile file in podcast.Files)
|
||||
Models.Podcast podcast = db.Podcasts.Where(p => p.PodcastId == podcastId).FirstOrDefault();
|
||||
if (podcast != null)
|
||||
{
|
||||
System.IO.File.Delete(file.Path);
|
||||
foreach (PodcastFile file in podcast.Files)
|
||||
{
|
||||
System.IO.File.Delete(file.Path);
|
||||
}
|
||||
db.Podcasts.Remove(podcast);
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
}
|
||||
db.Podcasts.Remove(podcast);
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
return Json(new { error = "You don't have permission to delete this podcast" });
|
||||
}
|
||||
@ -330,28 +364,34 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
[AllowAnonymous]
|
||||
public ActionResult GetComments(int podcastId, int startCommentID, int count)
|
||||
{
|
||||
var comments = db.PodcastComments.Where(p => (p.PodcastId == podcastId)).OrderByDescending(p => p.DatePosted).Skip(startCommentID).Take(count).ToList();
|
||||
List<CommentViewModel> commentViews = new List<CommentViewModel>();
|
||||
if (comments != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
foreach (PodcastComment comment in comments)
|
||||
var comments = db.PodcastComments.Where(p => (p.PodcastId == podcastId)).OrderByDescending(p => p.DatePosted).Skip(startCommentID).Take(count).ToList();
|
||||
List<CommentViewModel> commentViews = new List<CommentViewModel>();
|
||||
if (comments != null)
|
||||
{
|
||||
commentViews.Add(new CommentViewModel(comment));
|
||||
foreach (PodcastComment comment in comments)
|
||||
{
|
||||
commentViews.Add(new CommentViewModel(comment));
|
||||
}
|
||||
}
|
||||
return PartialView("~/Areas/Podcast/Views/Podcast/Comments.cshtml", commentViews);
|
||||
}
|
||||
return PartialView("~/Areas/Podcast/Views/Podcast/Comments.cshtml", commentViews);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public ActionResult GetCommentArticle(int commentID)
|
||||
{
|
||||
PodcastComment comment = db.PodcastComments.Where(p => (p.PodcastCommentId == commentID)).FirstOrDefault();
|
||||
if (comment != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
return Json(new { result = comment.Article });
|
||||
PodcastComment comment = db.PodcastComments.Where(p => (p.PodcastCommentId == commentID)).FirstOrDefault();
|
||||
if (comment != null)
|
||||
{
|
||||
return Json(new { result = comment.Article });
|
||||
}
|
||||
return Json(new { error = "No article found" });
|
||||
}
|
||||
return Json(new { error = "No article found" });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -359,20 +399,23 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
if (db.Podcasts.Where(p => p.PodcastId == podcastId).FirstOrDefault() != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
PodcastComment comment = db.PodcastComments.Create();
|
||||
comment.PodcastId = podcastId;
|
||||
comment.UserId = UserHelper.GetUser(db, User.Identity.Name).UserId;
|
||||
comment.Article = article;
|
||||
comment.DatePosted = DateTime.Now;
|
||||
comment.DateEdited = DateTime.Now;
|
||||
if (db.Podcasts.Where(p => p.PodcastId == podcastId).FirstOrDefault() != null)
|
||||
{
|
||||
PodcastComment comment = db.PodcastComments.Create();
|
||||
comment.PodcastId = podcastId;
|
||||
comment.UserId = UserHelper.GetUser(db, User.Identity.Name).UserId;
|
||||
comment.Article = article;
|
||||
comment.DatePosted = DateTime.Now;
|
||||
comment.DateEdited = DateTime.Now;
|
||||
|
||||
db.PodcastComments.Add(comment);
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
db.PodcastComments.Add(comment);
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
}
|
||||
return Json(new { error = "That podcast does not exist" });
|
||||
}
|
||||
return Json(new { error = "That podcast does not exist" });
|
||||
}
|
||||
return Json(new { error = "Invalid Parameters" });
|
||||
}
|
||||
@ -382,20 +425,23 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
PodcastComment comment = db.PodcastComments.Where(c => c.PodcastCommentId == commentID).FirstOrDefault();
|
||||
if (comment != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
if (comment.User.Username == User.Identity.Name || User.IsInRole("Admin"))
|
||||
PodcastComment comment = db.PodcastComments.Where(c => c.PodcastCommentId == commentID).FirstOrDefault();
|
||||
if (comment != null)
|
||||
{
|
||||
comment.Article = article;
|
||||
comment.DateEdited = DateTime.Now;
|
||||
db.Entry(comment).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
if (comment.User.Username == User.Identity.Name || User.IsInRole("Admin"))
|
||||
{
|
||||
comment.Article = article;
|
||||
comment.DateEdited = DateTime.Now;
|
||||
db.Entry(comment).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
}
|
||||
return Json(new { error = "You don't have permission to edit this comment" });
|
||||
}
|
||||
return Json(new { error = "You don't have permission to edit this comment" });
|
||||
return Json(new { error = "No comment found" });
|
||||
}
|
||||
return Json(new { error = "No comment found" });
|
||||
}
|
||||
return Json(new { error = "Invalid Parameters" });
|
||||
}
|
||||
@ -405,18 +451,21 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
PodcastComment comment = db.PodcastComments.Where(c => c.PodcastCommentId == commentID).FirstOrDefault();
|
||||
if (comment != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
if (comment.User.Username == User.Identity.Name || User.IsInRole("Admin"))
|
||||
PodcastComment comment = db.PodcastComments.Where(c => c.PodcastCommentId == commentID).FirstOrDefault();
|
||||
if (comment != null)
|
||||
{
|
||||
db.PodcastComments.Remove(comment);
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
if (comment.User.Username == User.Identity.Name || User.IsInRole("Admin"))
|
||||
{
|
||||
db.PodcastComments.Remove(comment);
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
}
|
||||
return Json(new { error = "You don't have permission to delete this comment" });
|
||||
}
|
||||
return Json(new { error = "You don't have permission to delete this comment" });
|
||||
return Json(new { error = "No comment found" });
|
||||
}
|
||||
return Json(new { error = "No comment found" });
|
||||
}
|
||||
return Json(new { error = "Invalid Parameters" });
|
||||
}
|
||||
|
@ -19,8 +19,6 @@ namespace Teknik.Areas.RSS.Controllers
|
||||
[TeknikAuthorize(AuthType.Basic)]
|
||||
public class RSSController : DefaultController
|
||||
{
|
||||
private TeknikEntities db = new TeknikEntities();
|
||||
|
||||
[AllowAnonymous]
|
||||
public ActionResult Index()
|
||||
{
|
||||
@ -33,102 +31,108 @@ namespace Teknik.Areas.RSS.Controllers
|
||||
[AllowAnonymous]
|
||||
public ActionResult Blog(string username)
|
||||
{
|
||||
// If empty, grab the main blog
|
||||
List<BlogPost> posts = new List<BlogPost>();
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
// If empty, grab the main blog
|
||||
List<BlogPost> posts = new List<BlogPost>();
|
||||
|
||||
string blogUrl = Url.SubRouteUrl("blog", "Blog.Blog");
|
||||
string title = string.Empty;
|
||||
string description = string.Empty;
|
||||
bool isSystem = string.IsNullOrEmpty(username);
|
||||
if (isSystem)
|
||||
{
|
||||
posts = db.BlogPosts.Where(p => (p.System && p.Published)).ToList();
|
||||
blogUrl = Url.SubRouteUrl("blog", "Blog.Blog");
|
||||
}
|
||||
else
|
||||
{
|
||||
Blog.Models.Blog blog = db.Blogs.Where(p => p.User.Username == username && p.BlogId != Config.BlogConfig.ServerBlogId).FirstOrDefault();
|
||||
posts = db.BlogPosts.Where(p => (p.BlogId == blog.BlogId && !p.System) && p.Published).ToList();
|
||||
blogUrl = Url.SubRouteUrl("blog", "Blog.Blog", new { username = username });
|
||||
}
|
||||
if (posts.Any())
|
||||
{
|
||||
string blogUrl = Url.SubRouteUrl("blog", "Blog.Blog");
|
||||
string title = string.Empty;
|
||||
string description = string.Empty;
|
||||
bool isSystem = string.IsNullOrEmpty(username);
|
||||
if (isSystem)
|
||||
{
|
||||
title = Config.BlogConfig.Title;
|
||||
description = Config.BlogConfig.Description;
|
||||
posts = db.BlogPosts.Where(p => (p.System && p.Published)).ToList();
|
||||
blogUrl = Url.SubRouteUrl("blog", "Blog.Blog");
|
||||
}
|
||||
else
|
||||
{
|
||||
Users.Models.User user = UserHelper.GetUser(db, username);
|
||||
if (user != null)
|
||||
Blog.Models.Blog blog = db.Blogs.Where(p => p.User.Username == username && p.BlogId != Config.BlogConfig.ServerBlogId).FirstOrDefault();
|
||||
posts = db.BlogPosts.Where(p => (p.BlogId == blog.BlogId && !p.System) && p.Published).ToList();
|
||||
blogUrl = Url.SubRouteUrl("blog", "Blog.Blog", new { username = username });
|
||||
}
|
||||
if (posts.Any())
|
||||
{
|
||||
if (isSystem)
|
||||
{
|
||||
title = user.BlogSettings.Title;
|
||||
description = user.BlogSettings.Description;
|
||||
title = Config.BlogConfig.Title;
|
||||
description = Config.BlogConfig.Description;
|
||||
}
|
||||
else
|
||||
{
|
||||
SyndicationFeed badUserFeed = new SyndicationFeed("No Blog Available", "The specified user does not exist", new Uri(blogUrl));
|
||||
Users.Models.User user = UserHelper.GetUser(db, username);
|
||||
if (user != null)
|
||||
{
|
||||
title = user.BlogSettings.Title;
|
||||
description = user.BlogSettings.Description;
|
||||
}
|
||||
else
|
||||
{
|
||||
SyndicationFeed badUserFeed = new SyndicationFeed("No Blog Available", "The specified user does not exist", new Uri(blogUrl));
|
||||
|
||||
return new RssResult(badUserFeed);
|
||||
return new RssResult(badUserFeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<SyndicationItem> items = new List<SyndicationItem>();
|
||||
List<SyndicationItem> items = new List<SyndicationItem>();
|
||||
|
||||
foreach (BlogPost post in posts.OrderByDescending(p => p.BlogPostId))
|
||||
{
|
||||
if (post.Published && post.System == isSystem)
|
||||
foreach (BlogPost post in posts.OrderByDescending(p => p.BlogPostId))
|
||||
{
|
||||
items.Add(new SyndicationItem(
|
||||
post.Title,
|
||||
MarkdownHelper.Markdown(post.Article).ToHtmlString(),
|
||||
new Uri(Url.SubRouteUrl("blog", "Blog.Post", new { username = post.Blog.User.Username, id = post.BlogPostId })),
|
||||
post.BlogPostId.ToString(),
|
||||
post.DateEdited
|
||||
));
|
||||
if (post.Published && post.System == isSystem)
|
||||
{
|
||||
items.Add(new SyndicationItem(
|
||||
post.Title,
|
||||
MarkdownHelper.Markdown(post.Article).ToHtmlString(),
|
||||
new Uri(Url.SubRouteUrl("blog", "Blog.Post", new { username = post.Blog.User.Username, id = post.BlogPostId })),
|
||||
post.BlogPostId.ToString(),
|
||||
post.DateEdited
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
SyndicationFeed feed = new SyndicationFeed(title, description, new Uri(blogUrl), items);
|
||||
|
||||
return new RssResult(feed);
|
||||
}
|
||||
SyndicationFeed badFeed = new SyndicationFeed("No Blog Available", "The specified blog does not exist", new Uri(blogUrl));
|
||||
|
||||
SyndicationFeed feed = new SyndicationFeed(title, description, new Uri(blogUrl), items);
|
||||
|
||||
return new RssResult(feed);
|
||||
return new RssResult(badFeed);
|
||||
}
|
||||
SyndicationFeed badFeed = new SyndicationFeed("No Blog Available", "The specified blog does not exist", new Uri(blogUrl));
|
||||
|
||||
return new RssResult(badFeed);
|
||||
}
|
||||
|
||||
[TrackDownload]
|
||||
[AllowAnonymous]
|
||||
public ActionResult Podcast()
|
||||
{
|
||||
List<SyndicationItem> items = new List<SyndicationItem>();
|
||||
List<Podcast.Models.Podcast> podcasts = db.Podcasts.Where(p => p.Published).OrderByDescending(p => p.Episode).ToList();
|
||||
if (podcasts != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
foreach (Podcast.Models.Podcast podcast in podcasts)
|
||||
List<SyndicationItem> items = new List<SyndicationItem>();
|
||||
List<Podcast.Models.Podcast> podcasts = db.Podcasts.Where(p => p.Published).OrderByDescending(p => p.Episode).ToList();
|
||||
if (podcasts != null)
|
||||
{
|
||||
SyndicationItem item = new SyndicationItem(
|
||||
podcast.Title,
|
||||
MarkdownHelper.Markdown(podcast.Description).ToHtmlString(),
|
||||
new Uri(Url.SubRouteUrl("podcast", "Podcast.View", new { episode = podcast.Episode })),
|
||||
podcast.Episode.ToString(),
|
||||
podcast.DateEdited
|
||||
);
|
||||
foreach (Podcast.Models.PodcastFile file in podcast.Files)
|
||||
foreach (Podcast.Models.Podcast podcast in podcasts)
|
||||
{
|
||||
SyndicationLink enclosure = SyndicationLink.CreateMediaEnclosureLink(new Uri(Url.SubRouteUrl("podcast", "Podcast.Download", new { episode = podcast.Episode, fileName = file.FileName })), file.ContentType, file.ContentLength);
|
||||
item.Links.Add(enclosure);
|
||||
SyndicationItem item = new SyndicationItem(
|
||||
podcast.Title,
|
||||
MarkdownHelper.Markdown(podcast.Description).ToHtmlString(),
|
||||
new Uri(Url.SubRouteUrl("podcast", "Podcast.View", new { episode = podcast.Episode })),
|
||||
podcast.Episode.ToString(),
|
||||
podcast.DateEdited
|
||||
);
|
||||
foreach (Podcast.Models.PodcastFile file in podcast.Files)
|
||||
{
|
||||
SyndicationLink enclosure = SyndicationLink.CreateMediaEnclosureLink(new Uri(Url.SubRouteUrl("podcast", "Podcast.Download", new { episode = podcast.Episode, fileName = file.FileName })), file.ContentType, file.ContentLength);
|
||||
item.Links.Add(enclosure);
|
||||
}
|
||||
|
||||
items.Add(item);
|
||||
}
|
||||
|
||||
items.Add(item);
|
||||
}
|
||||
|
||||
SyndicationFeed feed = new SyndicationFeed(Config.PodcastConfig.Title, Config.PodcastConfig.Description, new Uri(Url.SubRouteUrl("podcast", "Podcast.Index")), items);
|
||||
|
||||
return new RssResult(feed);
|
||||
}
|
||||
|
||||
SyndicationFeed feed = new SyndicationFeed(Config.PodcastConfig.Title, Config.PodcastConfig.Description, new Uri(Url.SubRouteUrl("podcast", "Podcast.Index")), items);
|
||||
|
||||
return new RssResult(feed);
|
||||
}
|
||||
}
|
||||
}
|
@ -17,8 +17,6 @@ namespace Teknik.Areas.Shortener.Controllers
|
||||
[TeknikAuthorize]
|
||||
public class ShortenerController : DefaultController
|
||||
{
|
||||
private TeknikEntities db = new TeknikEntities();
|
||||
|
||||
[TrackPageView]
|
||||
[AllowAnonymous]
|
||||
public ActionResult Index()
|
||||
@ -31,15 +29,18 @@ namespace Teknik.Areas.Shortener.Controllers
|
||||
[AllowAnonymous]
|
||||
public ActionResult RedirectToUrl(string url)
|
||||
{
|
||||
ShortenedUrl shortUrl = db.ShortenedUrls.Where(s => s.ShortUrl == url).FirstOrDefault();
|
||||
if (shortUrl != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
shortUrl.Views += 1;
|
||||
db.Entry(shortUrl).State = System.Data.Entity.EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return Redirect(shortUrl.OriginalUrl);
|
||||
ShortenedUrl shortUrl = db.ShortenedUrls.Where(s => s.ShortUrl == url).FirstOrDefault();
|
||||
if (shortUrl != null)
|
||||
{
|
||||
shortUrl.Views += 1;
|
||||
db.Entry(shortUrl).State = System.Data.Entity.EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return Redirect(shortUrl.OriginalUrl);
|
||||
}
|
||||
return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
|
||||
}
|
||||
return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -48,27 +49,30 @@ namespace Teknik.Areas.Shortener.Controllers
|
||||
{
|
||||
if (url.IsValidUrl())
|
||||
{
|
||||
ShortenedUrl newUrl = Shortener.ShortenUrl(url, Config.ShortenerConfig.UrlLength);
|
||||
|
||||
if (User.Identity.IsAuthenticated)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
Users.Models.User foundUser = UserHelper.GetUser(db, User.Identity.Name);
|
||||
if (foundUser != null)
|
||||
ShortenedUrl newUrl = Shortener.ShortenUrl(db, url, Config.ShortenerConfig.UrlLength);
|
||||
|
||||
if (User.Identity.IsAuthenticated)
|
||||
{
|
||||
newUrl.UserId = foundUser.UserId;
|
||||
Users.Models.User foundUser = UserHelper.GetUser(db, User.Identity.Name);
|
||||
if (foundUser != null)
|
||||
{
|
||||
newUrl.UserId = foundUser.UserId;
|
||||
}
|
||||
}
|
||||
|
||||
db.ShortenedUrls.Add(newUrl);
|
||||
db.SaveChanges();
|
||||
|
||||
string shortUrl = string.Format("{0}://{1}/{2}", HttpContext.Request.Url.Scheme, Config.ShortenerConfig.ShortenerHost, newUrl.ShortUrl);
|
||||
if (Config.DevEnvironment)
|
||||
{
|
||||
shortUrl = Url.SubRouteUrl("shortened", "Shortener.View", new { url = newUrl.ShortUrl });
|
||||
}
|
||||
|
||||
return Json(new { result = new { shortUrl = shortUrl, originalUrl = url } });
|
||||
}
|
||||
|
||||
db.ShortenedUrls.Add(newUrl);
|
||||
db.SaveChanges();
|
||||
|
||||
string shortUrl = string.Format("{0}://{1}/{2}", HttpContext.Request.Url.Scheme, Config.ShortenerConfig.ShortenerHost, newUrl.ShortUrl);
|
||||
if (Config.DevEnvironment)
|
||||
{
|
||||
shortUrl = Url.SubRouteUrl("shortened", "Shortener.View", new { url = newUrl.ShortUrl });
|
||||
}
|
||||
|
||||
return Json(new { result = new { shortUrl = shortUrl, originalUrl = url } });
|
||||
}
|
||||
return Json(new { error = "Must be a valid Url" });
|
||||
}
|
||||
|
@ -11,10 +11,8 @@ namespace Teknik.Areas.Shortener
|
||||
{
|
||||
public static class Shortener
|
||||
{
|
||||
public static ShortenedUrl ShortenUrl(string url, int length)
|
||||
public static ShortenedUrl ShortenUrl(TeknikEntities db, string url, int length)
|
||||
{
|
||||
TeknikEntities db = new TeknikEntities();
|
||||
|
||||
// Generate the shortened url
|
||||
string shortUrl = StringHelper.RandomString(length);
|
||||
while (db.ShortenedUrls.Where(s => s.ShortUrl == shortUrl).FirstOrDefault() != null)
|
||||
|
@ -19,8 +19,6 @@ namespace Teknik.Areas.Status.Controllers
|
||||
[TeknikAuthorize]
|
||||
public class StatusController : DefaultController
|
||||
{
|
||||
private TeknikEntities db = new TeknikEntities();
|
||||
|
||||
[TrackPageView]
|
||||
[AllowAnonymous]
|
||||
public ActionResult Index()
|
||||
@ -30,134 +28,136 @@ namespace Teknik.Areas.Status.Controllers
|
||||
|
||||
StatusViewModel model = new StatusViewModel();
|
||||
|
||||
// Load initial status info
|
||||
#region Statistics
|
||||
Upload.Models.Upload upload = db.Uploads.OrderByDescending(u => u.UploadId).FirstOrDefault();
|
||||
model.UploadCount = (upload != null) ? upload.UploadId : 0;
|
||||
model.UploadSize = (upload != null) ? db.Uploads.Sum(u => (long)u.ContentLength) : 0;
|
||||
|
||||
Paste.Models.Paste paste = db.Pastes.OrderByDescending(p => p.PasteId).FirstOrDefault();
|
||||
model.PasteCount = (paste != null) ? paste.PasteId : 0;
|
||||
|
||||
Users.Models.User user = db.Users.OrderByDescending(u => u.UserId).FirstOrDefault();
|
||||
model.UserCount = (user != null) ? user.UserId : 0;
|
||||
|
||||
Shortener.Models.ShortenedUrl url = db.ShortenedUrls.OrderByDescending(s => s.ShortenedUrlId).FirstOrDefault();
|
||||
model.ShortenedUrlCount = (url != null) ? url.ShortenedUrlId : 0;
|
||||
|
||||
Vault.Models.Vault vault = db.Vaults.OrderByDescending(v => v.VaultId).FirstOrDefault();
|
||||
model.VaultCount = (url != null) ? vault.VaultId : 0;
|
||||
#endregion
|
||||
|
||||
// Get Transaction Inforomation
|
||||
#region Transactions
|
||||
DateTime curTime = DateTime.Now;
|
||||
|
||||
var billSums = db.Transactions.OfType<Bill>().GroupBy(b => new { b.Currency, b.DateSent.Month, b.DateSent.Year}).Select(b => new { month = b.Key.Month, year = b.Key.Year, currency = b.Key.Currency, total = b.Sum(c => c.Amount) }).ToList();
|
||||
foreach (var sum in billSums)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
decimal exchangeRate = CurrencyHelper.GetExchangeRate(sum.currency);
|
||||
decimal realValue = sum.total * exchangeRate;
|
||||
model.Transactions.TotalBills += realValue;
|
||||
model.Transactions.TotalNet += realValue;
|
||||
if (curTime.Month == sum.month && curTime.Year == sum.year)
|
||||
// Load initial status info
|
||||
#region Statistics
|
||||
Upload.Models.Upload upload = db.Uploads.OrderByDescending(u => u.UploadId).FirstOrDefault();
|
||||
model.UploadCount = (upload != null) ? upload.UploadId : 0;
|
||||
model.UploadSize = (upload != null) ? db.Uploads.Sum(u => (long)u.ContentLength) : 0;
|
||||
|
||||
Paste.Models.Paste paste = db.Pastes.OrderByDescending(p => p.PasteId).FirstOrDefault();
|
||||
model.PasteCount = (paste != null) ? paste.PasteId : 0;
|
||||
|
||||
Users.Models.User user = db.Users.OrderByDescending(u => u.UserId).FirstOrDefault();
|
||||
model.UserCount = (user != null) ? user.UserId : 0;
|
||||
|
||||
Shortener.Models.ShortenedUrl url = db.ShortenedUrls.OrderByDescending(s => s.ShortenedUrlId).FirstOrDefault();
|
||||
model.ShortenedUrlCount = (url != null) ? url.ShortenedUrlId : 0;
|
||||
|
||||
Vault.Models.Vault vault = db.Vaults.OrderByDescending(v => v.VaultId).FirstOrDefault();
|
||||
model.VaultCount = (url != null) ? vault.VaultId : 0;
|
||||
#endregion
|
||||
|
||||
// Get Transaction Inforomation
|
||||
#region Transactions
|
||||
DateTime curTime = DateTime.Now;
|
||||
|
||||
var billSums = db.Transactions.OfType<Bill>().GroupBy(b => new { b.Currency, b.DateSent.Month, b.DateSent.Year }).Select(b => new { month = b.Key.Month, year = b.Key.Year, currency = b.Key.Currency, total = b.Sum(c => c.Amount) }).ToList();
|
||||
foreach (var sum in billSums)
|
||||
{
|
||||
model.Transactions.CurrentMonthBills += Math.Abs(realValue);
|
||||
decimal exchangeRate = CurrencyHelper.GetExchangeRate(sum.currency);
|
||||
decimal realValue = sum.total * exchangeRate;
|
||||
model.Transactions.TotalBills += realValue;
|
||||
model.Transactions.TotalNet += realValue;
|
||||
if (curTime.Month == sum.month && curTime.Year == sum.year)
|
||||
{
|
||||
model.Transactions.CurrentMonthBills += Math.Abs(realValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var oneSums = db.Transactions.OfType<OneTime>().GroupBy(b => new { b.Currency, b.DateSent.Month, b.DateSent.Year }).Select(b => new { month = b.Key.Month, year = b.Key.Year, currency = b.Key.Currency, total = b.Sum(c => c.Amount) }).ToList();
|
||||
foreach (var sum in oneSums)
|
||||
{
|
||||
decimal exchangeRate = CurrencyHelper.GetExchangeRate(sum.currency);
|
||||
decimal realValue = sum.total * exchangeRate;
|
||||
model.Transactions.TotalOneTimes += realValue;
|
||||
model.Transactions.TotalNet += realValue;
|
||||
if (curTime.Month == sum.month && curTime.Year == sum.year)
|
||||
var oneSums = db.Transactions.OfType<OneTime>().GroupBy(b => new { b.Currency, b.DateSent.Month, b.DateSent.Year }).Select(b => new { month = b.Key.Month, year = b.Key.Year, currency = b.Key.Currency, total = b.Sum(c => c.Amount) }).ToList();
|
||||
foreach (var sum in oneSums)
|
||||
{
|
||||
model.Transactions.CurrentMonthBills += Math.Abs(realValue);
|
||||
decimal exchangeRate = CurrencyHelper.GetExchangeRate(sum.currency);
|
||||
decimal realValue = sum.total * exchangeRate;
|
||||
model.Transactions.TotalOneTimes += realValue;
|
||||
model.Transactions.TotalNet += realValue;
|
||||
if (curTime.Month == sum.month && curTime.Year == sum.year)
|
||||
{
|
||||
model.Transactions.CurrentMonthBills += Math.Abs(realValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var donationSums = db.Transactions.OfType<Donation>().GroupBy(b => new { b.Currency, b.DateSent.Month, b.DateSent.Year }).Select(b => new { month = b.Key.Month, year = b.Key.Year, currency = b.Key.Currency, total = b.Sum(c => c.Amount) }).ToList();
|
||||
foreach (var sum in donationSums)
|
||||
{
|
||||
decimal exchangeRate = CurrencyHelper.GetExchangeRate(sum.currency);
|
||||
decimal realValue = sum.total * exchangeRate;
|
||||
model.Transactions.TotalDonations += realValue;
|
||||
model.Transactions.TotalNet += realValue;
|
||||
if (curTime.Month == sum.month && curTime.Year == sum.year)
|
||||
var donationSums = db.Transactions.OfType<Donation>().GroupBy(b => new { b.Currency, b.DateSent.Month, b.DateSent.Year }).Select(b => new { month = b.Key.Month, year = b.Key.Year, currency = b.Key.Currency, total = b.Sum(c => c.Amount) }).ToList();
|
||||
foreach (var sum in donationSums)
|
||||
{
|
||||
model.Transactions.CurrentMonthIncome += Math.Abs(realValue);
|
||||
decimal exchangeRate = CurrencyHelper.GetExchangeRate(sum.currency);
|
||||
decimal realValue = sum.total * exchangeRate;
|
||||
model.Transactions.TotalDonations += realValue;
|
||||
model.Transactions.TotalNet += realValue;
|
||||
if (curTime.Month == sum.month && curTime.Year == sum.year)
|
||||
{
|
||||
model.Transactions.CurrentMonthIncome += Math.Abs(realValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Bill> bills = db.Transactions.OfType<Bill>().OrderByDescending(b => b.DateSent).ToList();
|
||||
if (bills != null)
|
||||
{
|
||||
foreach (Bill bill in bills)
|
||||
List<Bill> bills = db.Transactions.OfType<Bill>().OrderByDescending(b => b.DateSent).ToList();
|
||||
if (bills != null)
|
||||
{
|
||||
BillViewModel billModel = new BillViewModel();
|
||||
billModel.Amount = bill.Amount;
|
||||
billModel.Currency = bill.Currency;
|
||||
billModel.Reason = bill.Reason;
|
||||
billModel.DateSent = bill.DateSent;
|
||||
billModel.Recipient = bill.Recipient;
|
||||
model.Transactions.Bills.Add(billModel);
|
||||
foreach (Bill bill in bills)
|
||||
{
|
||||
BillViewModel billModel = new BillViewModel();
|
||||
billModel.Amount = bill.Amount;
|
||||
billModel.Currency = bill.Currency;
|
||||
billModel.Reason = bill.Reason;
|
||||
billModel.DateSent = bill.DateSent;
|
||||
billModel.Recipient = bill.Recipient;
|
||||
model.Transactions.Bills.Add(billModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<OneTime> oneTimes = db.Transactions.OfType<OneTime>().OrderByDescending(b => b.DateSent).ToList();
|
||||
if (oneTimes != null)
|
||||
{
|
||||
foreach (OneTime oneTime in oneTimes)
|
||||
List<OneTime> oneTimes = db.Transactions.OfType<OneTime>().OrderByDescending(b => b.DateSent).ToList();
|
||||
if (oneTimes != null)
|
||||
{
|
||||
OneTimeViewModel oneTimeModel = new OneTimeViewModel();
|
||||
oneTimeModel.Amount = oneTime.Amount;
|
||||
oneTimeModel.Currency = oneTime.Currency;
|
||||
oneTimeModel.Reason = oneTime.Reason;
|
||||
oneTimeModel.DateSent = oneTime.DateSent;
|
||||
oneTimeModel.Recipient = oneTime.Recipient;
|
||||
model.Transactions.OneTimes.Add(oneTimeModel);
|
||||
foreach (OneTime oneTime in oneTimes)
|
||||
{
|
||||
OneTimeViewModel oneTimeModel = new OneTimeViewModel();
|
||||
oneTimeModel.Amount = oneTime.Amount;
|
||||
oneTimeModel.Currency = oneTime.Currency;
|
||||
oneTimeModel.Reason = oneTime.Reason;
|
||||
oneTimeModel.DateSent = oneTime.DateSent;
|
||||
oneTimeModel.Recipient = oneTime.Recipient;
|
||||
model.Transactions.OneTimes.Add(oneTimeModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Donation> donations = db.Transactions.OfType<Donation>().OrderByDescending(b => b.DateSent).ToList();
|
||||
if (donations != null)
|
||||
{
|
||||
foreach (Donation donation in donations)
|
||||
List<Donation> donations = db.Transactions.OfType<Donation>().OrderByDescending(b => b.DateSent).ToList();
|
||||
if (donations != null)
|
||||
{
|
||||
DonationViewModel donationModel = new DonationViewModel();
|
||||
donationModel.Amount = donation.Amount;
|
||||
donationModel.Currency = donation.Currency;
|
||||
donationModel.Reason = donation.Reason;
|
||||
donationModel.DateSent = donation.DateSent;
|
||||
donationModel.Sender = donation.Sender;
|
||||
model.Transactions.Donations.Add(donationModel);
|
||||
foreach (Donation donation in donations)
|
||||
{
|
||||
DonationViewModel donationModel = new DonationViewModel();
|
||||
donationModel.Amount = donation.Amount;
|
||||
donationModel.Currency = donation.Currency;
|
||||
donationModel.Reason = donation.Reason;
|
||||
donationModel.DateSent = donation.DateSent;
|
||||
donationModel.Sender = donation.Sender;
|
||||
model.Transactions.Donations.Add(donationModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
// Takedown information
|
||||
#region Takedowns
|
||||
List<Takedown> takedowns = db.Takedowns.OrderByDescending(b => b.DateRequested).ToList();
|
||||
if (takedowns != null)
|
||||
{
|
||||
foreach (Takedown takedown in takedowns)
|
||||
// Takedown information
|
||||
#region Takedowns
|
||||
List<Takedown> takedowns = db.Takedowns.OrderByDescending(b => b.DateRequested).ToList();
|
||||
if (takedowns != null)
|
||||
{
|
||||
TakedownViewModel takedownModel = new TakedownViewModel();
|
||||
takedownModel.Requester = takedown.Requester;
|
||||
takedownModel.RequesterContact = takedown.RequesterContact;
|
||||
takedownModel.Reason = takedown.Reason;
|
||||
takedownModel.ActionTaken = takedown.ActionTaken;
|
||||
takedownModel.DateRequested = takedown.DateRequested;
|
||||
takedownModel.DateActionTaken = takedown.DateActionTaken;
|
||||
foreach (Takedown takedown in takedowns)
|
||||
{
|
||||
TakedownViewModel takedownModel = new TakedownViewModel();
|
||||
takedownModel.Requester = takedown.Requester;
|
||||
takedownModel.RequesterContact = takedown.RequesterContact;
|
||||
takedownModel.Reason = takedown.Reason;
|
||||
takedownModel.ActionTaken = takedown.ActionTaken;
|
||||
takedownModel.DateRequested = takedown.DateRequested;
|
||||
takedownModel.DateActionTaken = takedown.DateActionTaken;
|
||||
|
||||
model.Takedowns.Add(takedownModel);
|
||||
model.Takedowns.Add(takedownModel);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,6 @@ namespace Teknik.Areas.Upload.Controllers
|
||||
[TeknikAuthorize]
|
||||
public class UploadController : DefaultController
|
||||
{
|
||||
private TeknikEntities db = new TeknikEntities();
|
||||
|
||||
// GET: Upload/Upload
|
||||
[HttpGet]
|
||||
[TrackPageView]
|
||||
@ -37,15 +35,18 @@ namespace Teknik.Areas.Upload.Controllers
|
||||
ViewBag.Title = "Teknik Upload - End to End Encryption";
|
||||
UploadViewModel model = new UploadViewModel();
|
||||
model.CurrentSub = Subdomain;
|
||||
Users.Models.User user = UserHelper.GetUser(db, User.Identity.Name);
|
||||
if (user != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
model.Encrypt = user.UploadSettings.Encrypt;
|
||||
model.Vaults = user.Vaults.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
model.Encrypt = false;
|
||||
Users.Models.User user = UserHelper.GetUser(db, User.Identity.Name);
|
||||
if (user != null)
|
||||
{
|
||||
model.Encrypt = user.UploadSettings.Encrypt;
|
||||
model.Vaults = user.Vaults.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
model.Encrypt = false;
|
||||
}
|
||||
}
|
||||
return View(model);
|
||||
}
|
||||
@ -82,23 +83,26 @@ namespace Teknik.Areas.Upload.Controllers
|
||||
return Json(new { error = new { message = string.Format("Unknown result while scanning the file upload for viruses. {0}", scanResult.RawResult) } });
|
||||
}
|
||||
}
|
||||
|
||||
Models.Upload upload = Uploader.SaveFile(db, Config, data.InputStream, fileType, contentLength, encrypt, fileExt, iv, null, keySize, blockSize);
|
||||
if (upload != null)
|
||||
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
if (User.Identity.IsAuthenticated)
|
||||
Models.Upload upload = Uploader.SaveFile(db, Config, data.InputStream, fileType, contentLength, encrypt, fileExt, iv, null, keySize, blockSize);
|
||||
if (upload != null)
|
||||
{
|
||||
Users.Models.User user = UserHelper.GetUser(db, User.Identity.Name);
|
||||
if (user != null)
|
||||
if (User.Identity.IsAuthenticated)
|
||||
{
|
||||
upload.UserId = user.UserId;
|
||||
db.Entry(upload).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
Users.Models.User user = UserHelper.GetUser(db, User.Identity.Name);
|
||||
if (user != null)
|
||||
{
|
||||
upload.UserId = user.UserId;
|
||||
db.Entry(upload).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
return Json(new { result = new { name = upload.Url, url = Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Url }), contentType = upload.ContentType, contentLength = StringHelper.GetBytesReadable(upload.ContentLength), deleteUrl = Url.SubRouteUrl("u", "Upload.Delete", new { file = upload.Url, key = upload.DeleteKey }) } }, "text/plain");
|
||||
}
|
||||
return Json(new { result = new { name = upload.Url, url = Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Url }), contentType = upload.ContentType, contentLength = StringHelper.GetBytesReadable(upload.ContentLength), deleteUrl = Url.SubRouteUrl("u", "Upload.Delete", new { file = upload.Url, key = upload.DeleteKey }) } }, "text/plain");
|
||||
return Json(new { error = new { message = "Unable to upload file" } });
|
||||
}
|
||||
return Json(new { error = new { message = "Unable to upload file" } });
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -122,98 +126,108 @@ namespace Teknik.Areas.Upload.Controllers
|
||||
if (Config.UploadConfig.DownloadEnabled)
|
||||
{
|
||||
ViewBag.Title = "Teknik Download - " + file;
|
||||
Models.Upload upload = db.Uploads.Where(up => up.Url == file).FirstOrDefault();
|
||||
if (upload != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
upload.Downloads += 1;
|
||||
db.Entry(upload).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
|
||||
// We don't have the key, so we need to decrypt it client side
|
||||
if (string.IsNullOrEmpty(upload.Key) && !string.IsNullOrEmpty(upload.IV))
|
||||
Models.Upload upload = db.Uploads.Where(up => up.Url == file).FirstOrDefault();
|
||||
if (upload != null)
|
||||
{
|
||||
DownloadViewModel model = new DownloadViewModel();
|
||||
model.FileName = file;
|
||||
model.ContentType = upload.ContentType;
|
||||
model.ContentLength = upload.ContentLength;
|
||||
model.IV = upload.IV;
|
||||
upload.Downloads += 1;
|
||||
db.Entry(upload).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
|
||||
return View(model);
|
||||
}
|
||||
else // We have the key, so that means server side decryption
|
||||
{
|
||||
// Are they downloading it by range?
|
||||
bool byRange = !string.IsNullOrEmpty(Request.ServerVariables["HTTP_RANGE"]); // We do not support ranges
|
||||
// Check to see if they have a cache
|
||||
bool isCached = !string.IsNullOrEmpty(Request.Headers["If-Modified-Since"]);
|
||||
|
||||
if (isCached)
|
||||
// We don't have the key, so we need to decrypt it client side
|
||||
if (string.IsNullOrEmpty(upload.Key) && !string.IsNullOrEmpty(upload.IV))
|
||||
{
|
||||
// The file is cached, let's just 304 this
|
||||
Response.StatusCode = 304;
|
||||
Response.StatusDescription = "Not Modified";
|
||||
Response.AddHeader("Content-Length", "0");
|
||||
return Content(string.Empty);
|
||||
DownloadViewModel model = new DownloadViewModel();
|
||||
model.FileName = file;
|
||||
model.ContentType = upload.ContentType;
|
||||
model.ContentLength = upload.ContentLength;
|
||||
model.IV = upload.IV;
|
||||
|
||||
return View(model);
|
||||
}
|
||||
else
|
||||
else // We have the key, so that means server side decryption
|
||||
{
|
||||
string subDir = upload.FileName[0].ToString();
|
||||
string filePath = Path.Combine(Config.UploadConfig.UploadDirectory, subDir, upload.FileName);
|
||||
if (System.IO.File.Exists(filePath))
|
||||
// Are they downloading it by range?
|
||||
bool byRange = !string.IsNullOrEmpty(Request.ServerVariables["HTTP_RANGE"]); // We do not support ranges
|
||||
// Check to see if they have a cache
|
||||
bool isCached = !string.IsNullOrEmpty(Request.Headers["If-Modified-Since"]);
|
||||
|
||||
if (isCached)
|
||||
{
|
||||
// Add cache parameters
|
||||
Response.Cache.SetCacheability(HttpCacheability.Public);
|
||||
Response.Cache.SetMaxAge(new TimeSpan(365, 0, 0, 0));
|
||||
Response.Cache.SetLastModified(upload.DateUploaded);
|
||||
|
||||
// Notify the client the content length we'll be outputting
|
||||
Response.AddHeader("Content-Length", upload.ContentLength.ToString());
|
||||
|
||||
// Create content disposition
|
||||
var cd = new System.Net.Mime.ContentDisposition
|
||||
// The file is cached, let's just 304 this
|
||||
Response.StatusCode = 304;
|
||||
Response.StatusDescription = "Not Modified";
|
||||
Response.AddHeader("Content-Length", "0");
|
||||
return Content(string.Empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
string subDir = upload.FileName[0].ToString();
|
||||
string filePath = Path.Combine(Config.UploadConfig.UploadDirectory, subDir, upload.FileName);
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
FileName = upload.Url,
|
||||
Inline = true
|
||||
};
|
||||
// Add cache parameters
|
||||
Response.Cache.SetCacheability(HttpCacheability.Public);
|
||||
Response.Cache.SetMaxAge(new TimeSpan(365, 0, 0, 0));
|
||||
Response.Cache.SetLastModified(upload.DateUploaded);
|
||||
|
||||
Response.AddHeader("Content-Disposition", cd.ToString());
|
||||
// Notify the client the content length we'll be outputting
|
||||
Response.AddHeader("Content-Length", upload.ContentLength.ToString());
|
||||
|
||||
string contentType = upload.ContentType;
|
||||
// We need to prevent html (make cleaner later)
|
||||
if (contentType == "text/html")
|
||||
{
|
||||
contentType = "text/plain";
|
||||
}
|
||||
// Create content disposition
|
||||
var cd = new System.Net.Mime.ContentDisposition
|
||||
{
|
||||
FileName = upload.Url,
|
||||
Inline = true
|
||||
};
|
||||
|
||||
// Read in the file
|
||||
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
|
||||
Response.AddHeader("Content-Disposition", cd.ToString());
|
||||
|
||||
// If the IV is set, and Key is set, then decrypt it while sending
|
||||
if (!string.IsNullOrEmpty(upload.Key) && !string.IsNullOrEmpty(upload.IV))
|
||||
{
|
||||
byte[] keyBytes = Encoding.UTF8.GetBytes(upload.Key);
|
||||
byte[] ivBytes = Encoding.UTF8.GetBytes(upload.IV);
|
||||
string contentType = upload.ContentType;
|
||||
// We need to prevent html (make cleaner later)
|
||||
if (contentType == "text/html")
|
||||
{
|
||||
contentType = "text/plain";
|
||||
}
|
||||
|
||||
return new FileGenerateResult(upload.Url,
|
||||
contentType,
|
||||
(response) => ResponseHelper.StreamToOutput(response, true, new AESCryptoStream(fs, false, keyBytes, ivBytes, "CTR", "NoPadding"), (int)upload.ContentLength, Config.UploadConfig.ChunkSize),
|
||||
false);
|
||||
}
|
||||
else // Otherwise just send it
|
||||
{
|
||||
// Don't buffer the response
|
||||
Response.Buffer = false;
|
||||
// Send the file
|
||||
return new FileGenerateResult(upload.Url,
|
||||
contentType,
|
||||
(response) => ResponseHelper.StreamToOutput(response, true, fs, (int)upload.ContentLength, Config.UploadConfig.ChunkSize),
|
||||
false);
|
||||
// Read in the file
|
||||
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
|
||||
|
||||
try
|
||||
{
|
||||
// If the IV is set, and Key is set, then decrypt it while sending
|
||||
if (!string.IsNullOrEmpty(upload.Key) && !string.IsNullOrEmpty(upload.IV))
|
||||
{
|
||||
byte[] keyBytes = Encoding.UTF8.GetBytes(upload.Key);
|
||||
byte[] ivBytes = Encoding.UTF8.GetBytes(upload.IV);
|
||||
|
||||
return new FileGenerateResult(upload.Url,
|
||||
contentType,
|
||||
(response) => ResponseHelper.StreamToOutput(response, true, new AESCryptoStream(fs, false, keyBytes, ivBytes, "CTR", "NoPadding"), (int)upload.ContentLength, Config.UploadConfig.ChunkSize),
|
||||
false);
|
||||
}
|
||||
else // Otherwise just send it
|
||||
{
|
||||
// Don't buffer the response
|
||||
Response.Buffer = false;
|
||||
// Send the file
|
||||
return new FileGenerateResult(upload.Url,
|
||||
contentType,
|
||||
(response) => ResponseHelper.StreamToOutput(response, true, fs, (int)upload.ContentLength, Config.UploadConfig.ChunkSize),
|
||||
false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Logger.WriteEntry(Logging.LogLevel.Warning, "Error in Download", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
|
||||
}
|
||||
return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
|
||||
}
|
||||
return Redirect(Url.SubRouteUrl("error", "Error.Http403"));
|
||||
}
|
||||
@ -224,19 +238,22 @@ namespace Teknik.Areas.Upload.Controllers
|
||||
{
|
||||
if (Config.UploadConfig.DownloadEnabled)
|
||||
{
|
||||
Models.Upload upload = db.Uploads.Where(up => up.Url == file).FirstOrDefault();
|
||||
if (upload != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
string subDir = upload.FileName[0].ToString();
|
||||
string filePath = Path.Combine(Config.UploadConfig.UploadDirectory, subDir, upload.FileName);
|
||||
if (System.IO.File.Exists(filePath))
|
||||
Models.Upload upload = db.Uploads.Where(up => up.Url == file).FirstOrDefault();
|
||||
if (upload != null)
|
||||
{
|
||||
FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
|
||||
return File(fileStream, System.Net.Mime.MediaTypeNames.Application.Octet, file);
|
||||
string subDir = upload.FileName[0].ToString();
|
||||
string filePath = Path.Combine(Config.UploadConfig.UploadDirectory, subDir, upload.FileName);
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
|
||||
return File(fileStream, System.Net.Mime.MediaTypeNames.Application.Octet, file);
|
||||
}
|
||||
}
|
||||
Redirect(Url.SubRouteUrl("error", "Error.Http404"));
|
||||
return null;
|
||||
}
|
||||
Redirect(Url.SubRouteUrl("error", "Error.Http404"));
|
||||
return null;
|
||||
}
|
||||
Redirect(Url.SubRouteUrl("error", "Error.Http403"));
|
||||
return null;
|
||||
@ -246,52 +263,58 @@ namespace Teknik.Areas.Upload.Controllers
|
||||
[AllowAnonymous]
|
||||
public ActionResult Delete(string file, string key)
|
||||
{
|
||||
ViewBag.Title = "File Delete - " + file + " - " + Config.Title;
|
||||
Models.Upload upload = db.Uploads.Where(up => up.Url == file).FirstOrDefault();
|
||||
if (upload != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
DeleteViewModel model = new DeleteViewModel();
|
||||
model.File = file;
|
||||
if (!string.IsNullOrEmpty(upload.DeleteKey) && upload.DeleteKey == key)
|
||||
ViewBag.Title = "File Delete - " + file + " - " + Config.Title;
|
||||
Models.Upload upload = db.Uploads.Where(up => up.Url == file).FirstOrDefault();
|
||||
if (upload != null)
|
||||
{
|
||||
string filePath = upload.FileName;
|
||||
// Delete from the DB
|
||||
db.Uploads.Remove(upload);
|
||||
db.SaveChanges();
|
||||
|
||||
// Delete the File
|
||||
if (System.IO.File.Exists(filePath))
|
||||
DeleteViewModel model = new DeleteViewModel();
|
||||
model.File = file;
|
||||
if (!string.IsNullOrEmpty(upload.DeleteKey) && upload.DeleteKey == key)
|
||||
{
|
||||
System.IO.File.Delete(filePath);
|
||||
string filePath = upload.FileName;
|
||||
// Delete from the DB
|
||||
db.Uploads.Remove(upload);
|
||||
db.SaveChanges();
|
||||
|
||||
// Delete the File
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
System.IO.File.Delete(filePath);
|
||||
}
|
||||
model.Deleted = true;
|
||||
}
|
||||
model.Deleted = true;
|
||||
else
|
||||
{
|
||||
model.Deleted = false;
|
||||
}
|
||||
return View(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
model.Deleted = false;
|
||||
}
|
||||
return View(model);
|
||||
return RedirectToRoute("Error.Http404");
|
||||
}
|
||||
return RedirectToRoute("Error.Http404");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult GenerateDeleteKey(string file)
|
||||
{
|
||||
Models.Upload upload = db.Uploads.Where(up => up.Url == file).FirstOrDefault();
|
||||
if (upload != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
if (upload.User.Username == User.Identity.Name)
|
||||
Models.Upload upload = db.Uploads.Where(up => up.Url == file).FirstOrDefault();
|
||||
if (upload != null)
|
||||
{
|
||||
string delKey = StringHelper.RandomString(Config.UploadConfig.DeleteKeyLength);
|
||||
upload.DeleteKey = delKey;
|
||||
db.Entry(upload).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return Json(new { result = new { url = Url.SubRouteUrl("u", "Upload.Delete", new { file = file, key = delKey }) } });
|
||||
if (upload.User.Username == User.Identity.Name)
|
||||
{
|
||||
string delKey = StringHelper.RandomString(Config.UploadConfig.DeleteKeyLength);
|
||||
upload.DeleteKey = delKey;
|
||||
db.Entry(upload).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return Json(new { result = new { url = Url.SubRouteUrl("u", "Upload.Delete", new { file = file, key = delKey }) } });
|
||||
}
|
||||
return Json(new { error = new { message = "You do not own this upload" } });
|
||||
}
|
||||
return Json(new { error = new { message = "You do not own this upload" } });
|
||||
return Json(new { error = new { message = "Invalid URL" } });
|
||||
}
|
||||
return Json(new { error = new { message = "Invalid URL" } });
|
||||
}
|
||||
}
|
||||
}
|
@ -46,7 +46,7 @@ function processDownload(key) {
|
||||
lastTime = curTime;
|
||||
lastData = e.data.processed;
|
||||
var percentComplete = Math.round(e.data.processed * 100 / e.data.total);
|
||||
setProgress(percentComplete, 'progress-bar-success progress-bar-striped active', percentComplete + '%', 'Decrypting [' + getReadableBandwidthString(speed * 8) + ']');
|
||||
setProgress(percentComplete, 'progress-bar-success progress-bar-striped active', percentComplete + '%', 'Decrypting [' + getReadableFileSizeString(e.data.processed) + ' / ' + getReadableFileSizeString(e.data.total) + ' @ ' + getReadableBandwidthString(speed * 8) + ']');
|
||||
}
|
||||
break;
|
||||
case 'finish':
|
||||
@ -92,7 +92,7 @@ function processDownload(key) {
|
||||
lastTime = curTime;
|
||||
lastData = e.loaded;
|
||||
var percentComplete = Math.round(e.loaded * 100 / e.total);
|
||||
setProgress(percentComplete, 'progress-bar-success progress-bar-striped active', percentComplete + '%', 'Downloading File [' + getReadableBandwidthString(speed * 8) + ']');
|
||||
setProgress(percentComplete, 'progress-bar-success progress-bar-striped active', percentComplete + '%', 'Downloading File [' + getReadableFileSizeString(e.loaded) + ' / ' + getReadableFileSizeString(e.total) + ' @ ' + getReadableBandwidthString(speed * 8) + ']');
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -217,7 +217,7 @@ function encryptFile(file, callback) {
|
||||
lastTime = curTime;
|
||||
lastData = e.data.processed;
|
||||
var percentComplete = Math.round(e.data.processed * 100 / e.data.total);
|
||||
setProgress(fileID, percentComplete, 'progress-bar-success progress-bar-striped active', percentComplete + '%', 'Encrypting [' + getReadableBandwidthString(speed * 8) + ']');
|
||||
setProgress(fileID, percentComplete, 'progress-bar-success progress-bar-striped active', percentComplete + '%', 'Encrypting [' + getReadableFileSizeString(e.data.processed) + ' / ' + getReadableFileSizeString(e.data.total) + ' @ ' + getReadableBandwidthString(speed * 8) + ']');
|
||||
}
|
||||
break;
|
||||
case 'finish':
|
||||
@ -306,7 +306,7 @@ function uploadProgress(fileID, lastTime, lastData, evt) {
|
||||
setProgress(fileID, 100, 'progress-bar-success progress-bar-striped active', '', 'Processing Upload');
|
||||
}
|
||||
else {
|
||||
setProgress(fileID, percentComplete, 'progress-bar-success progress-bar-striped active', percentComplete + '%', 'Uploading to Server [' + getReadableBandwidthString(speed * 8) + ']');
|
||||
setProgress(fileID, percentComplete, 'progress-bar-success progress-bar-striped active', percentComplete + '%', 'Uploading to Server [' + getReadableFileSizeString(evt.loaded) + ' / ' + getReadableFileSizeString(evt.total) + ' @ ' + getReadableBandwidthString(speed * 8) + ']');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -20,82 +20,83 @@ namespace Teknik.Areas.Vault.Controllers
|
||||
[TeknikAuthorize]
|
||||
public class VaultController : DefaultController
|
||||
{
|
||||
private TeknikEntities db = new TeknikEntities();
|
||||
|
||||
[AllowAnonymous]
|
||||
public ActionResult ViewVault(string id)
|
||||
{
|
||||
Models.Vault foundVault = db.Vaults.Where(v => v.Url == id).FirstOrDefault();
|
||||
if (foundVault != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
// Update view count
|
||||
foundVault.Views += 1;
|
||||
db.Entry(foundVault).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
|
||||
ViewBag.Title = foundVault.Title + " - Teknik Vault";
|
||||
|
||||
VaultViewModel model = new VaultViewModel();
|
||||
model.CurrentSub = Subdomain;
|
||||
|
||||
model.Url = foundVault.Url;
|
||||
model.UserId = foundVault.UserId;
|
||||
model.User = foundVault.User;
|
||||
model.Title = foundVault.Title;
|
||||
model.Description = foundVault.Description;
|
||||
model.DateCreated = foundVault.DateCreated;
|
||||
model.DateEdited = foundVault.DateEdited;
|
||||
|
||||
if (foundVault.VaultItems.Any())
|
||||
Models.Vault foundVault = db.Vaults.Where(v => v.Url == id).FirstOrDefault();
|
||||
if (foundVault != null)
|
||||
{
|
||||
foreach (VaultItem item in foundVault.VaultItems)
|
||||
// Update view count
|
||||
foundVault.Views += 1;
|
||||
db.Entry(foundVault).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
|
||||
ViewBag.Title = foundVault.Title + " - Teknik Vault";
|
||||
|
||||
VaultViewModel model = new VaultViewModel();
|
||||
model.CurrentSub = Subdomain;
|
||||
|
||||
model.Url = foundVault.Url;
|
||||
model.UserId = foundVault.UserId;
|
||||
model.User = foundVault.User;
|
||||
model.Title = foundVault.Title;
|
||||
model.Description = foundVault.Description;
|
||||
model.DateCreated = foundVault.DateCreated;
|
||||
model.DateEdited = foundVault.DateEdited;
|
||||
|
||||
if (foundVault.VaultItems.Any())
|
||||
{
|
||||
if (item.GetType().BaseType == typeof(UploadVaultItem))
|
||||
foreach (VaultItem item in foundVault.VaultItems)
|
||||
{
|
||||
UploadVaultItem upload = (UploadVaultItem)item;
|
||||
// Increment Views
|
||||
upload.Upload.Downloads += 1;
|
||||
db.Entry(upload.Upload).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
|
||||
UploadItemViewModel uploadModel = new UploadItemViewModel();
|
||||
upload.VaultItemId = item.VaultItemId;
|
||||
uploadModel.Title = item.Title;
|
||||
uploadModel.Description = item.Description;
|
||||
uploadModel.DateAdded = item.DateAdded;
|
||||
uploadModel.Upload = upload.Upload;
|
||||
model.Items.Add(uploadModel);
|
||||
}
|
||||
else if (item.GetType().BaseType == typeof(PasteVaultItem))
|
||||
{
|
||||
PasteVaultItem paste = (PasteVaultItem)item;
|
||||
// Increment Views
|
||||
paste.Paste.Views += 1;
|
||||
db.Entry(paste.Paste).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
|
||||
// Check Expiration
|
||||
if (PasteHelper.CheckExpiration(paste.Paste))
|
||||
if (item.GetType().BaseType == typeof(UploadVaultItem))
|
||||
{
|
||||
db.Pastes.Remove(paste.Paste);
|
||||
UploadVaultItem upload = (UploadVaultItem)item;
|
||||
// Increment Views
|
||||
upload.Upload.Downloads += 1;
|
||||
db.Entry(upload.Upload).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
break;
|
||||
}
|
||||
|
||||
PasteItemViewModel pasteModel = new PasteItemViewModel();
|
||||
pasteModel.VaultItemId = item.VaultItemId;
|
||||
pasteModel.Title = item.Title;
|
||||
pasteModel.Description = item.Description;
|
||||
pasteModel.DateAdded = item.DateAdded;
|
||||
pasteModel.Paste = paste.Paste;
|
||||
model.Items.Add(pasteModel);
|
||||
UploadItemViewModel uploadModel = new UploadItemViewModel();
|
||||
uploadModel.VaultItemId = item.VaultItemId;
|
||||
uploadModel.Title = item.Title;
|
||||
uploadModel.Description = item.Description;
|
||||
uploadModel.DateAdded = item.DateAdded;
|
||||
uploadModel.Upload = upload.Upload;
|
||||
model.Items.Add(uploadModel);
|
||||
}
|
||||
else if (item.GetType().BaseType == typeof(PasteVaultItem))
|
||||
{
|
||||
PasteVaultItem paste = (PasteVaultItem)item;
|
||||
// Increment Views
|
||||
paste.Paste.Views += 1;
|
||||
db.Entry(paste.Paste).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
|
||||
// Check Expiration
|
||||
if (PasteHelper.CheckExpiration(paste.Paste))
|
||||
{
|
||||
db.Pastes.Remove(paste.Paste);
|
||||
db.SaveChanges();
|
||||
break;
|
||||
}
|
||||
|
||||
PasteItemViewModel pasteModel = new PasteItemViewModel();
|
||||
pasteModel.VaultItemId = item.VaultItemId;
|
||||
pasteModel.Title = item.Title;
|
||||
pasteModel.Description = item.Description;
|
||||
pasteModel.DateAdded = item.DateAdded;
|
||||
pasteModel.Paste = paste.Paste;
|
||||
model.Items.Add(pasteModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return View(model);
|
||||
return View(model);
|
||||
}
|
||||
return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
|
||||
}
|
||||
return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -148,85 +149,88 @@ namespace Teknik.Areas.Vault.Controllers
|
||||
[HttpGet]
|
||||
public ActionResult EditVault(string url, string type, string items)
|
||||
{
|
||||
ViewBag.Title = "Edit Vault";
|
||||
Vault.Models.Vault foundVault = db.Vaults.Where(v => v.Url == url).FirstOrDefault();
|
||||
if (foundVault != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
if (foundVault.User.Username == User.Identity.Name)
|
||||
ViewBag.Title = "Edit Vault";
|
||||
Vault.Models.Vault foundVault = db.Vaults.Where(v => v.Url == url).FirstOrDefault();
|
||||
if (foundVault != null)
|
||||
{
|
||||
ViewBag.Title = "Edit Vault - " + foundVault.Title;
|
||||
|
||||
ModifyVaultViewModel model = new ModifyVaultViewModel();
|
||||
model.CurrentSub = Subdomain;
|
||||
model.isEdit = true;
|
||||
model.vaultId = foundVault.VaultId;
|
||||
model.title = foundVault.Title;
|
||||
model.description = foundVault.Description;
|
||||
|
||||
int index = 0;
|
||||
// Add all their existing items for the vault
|
||||
foreach (VaultItem item in foundVault.VaultItems)
|
||||
if (foundVault.User.Username == User.Identity.Name)
|
||||
{
|
||||
ModifyVaultItemViewModel itemModel = new ModifyVaultItemViewModel();
|
||||
itemModel.index = index;
|
||||
itemModel.isTemplate = false;
|
||||
ViewBag.Title = "Edit Vault - " + foundVault.Title;
|
||||
|
||||
if (item.GetType().BaseType == typeof(UploadVaultItem))
|
||||
{
|
||||
UploadVaultItem upload = (UploadVaultItem)item;
|
||||
itemModel.title = upload.Title;
|
||||
itemModel.description = upload.Description;
|
||||
itemModel.type = "Upload";
|
||||
itemModel.url = upload.Upload.Url;
|
||||
model.items.Add(itemModel);
|
||||
index++;
|
||||
}
|
||||
else if (item.GetType().BaseType == typeof(PasteVaultItem))
|
||||
{
|
||||
PasteVaultItem paste = (PasteVaultItem)item;
|
||||
itemModel.title = paste.Title;
|
||||
itemModel.description = paste.Description;
|
||||
itemModel.type = "Paste";
|
||||
itemModel.url = paste.Paste.Url;
|
||||
model.items.Add(itemModel);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
ModifyVaultViewModel model = new ModifyVaultViewModel();
|
||||
model.CurrentSub = Subdomain;
|
||||
model.isEdit = true;
|
||||
model.vaultId = foundVault.VaultId;
|
||||
model.title = foundVault.Title;
|
||||
model.description = foundVault.Description;
|
||||
|
||||
// If they passed any new items in via the parameters, let's add them
|
||||
if (!string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(items))
|
||||
{
|
||||
string decodedItems = HttpUtility.UrlDecode(items);
|
||||
string[] allItems = decodedItems.Split(',');
|
||||
foreach (string newItem in allItems)
|
||||
int index = 0;
|
||||
// Add all their existing items for the vault
|
||||
foreach (VaultItem item in foundVault.VaultItems)
|
||||
{
|
||||
string[] urlInfo = newItem.Split(':');
|
||||
string itemId = urlInfo[0];
|
||||
string title = string.Empty;
|
||||
if (urlInfo.GetUpperBound(0) >= 1)
|
||||
ModifyVaultItemViewModel itemModel = new ModifyVaultItemViewModel();
|
||||
itemModel.index = index;
|
||||
itemModel.isTemplate = false;
|
||||
|
||||
if (item.GetType().BaseType == typeof(UploadVaultItem))
|
||||
{
|
||||
// They also passed in the original filename, so let's use it as our title
|
||||
title = urlInfo[1];
|
||||
UploadVaultItem upload = (UploadVaultItem)item;
|
||||
itemModel.title = upload.Title;
|
||||
itemModel.description = upload.Description;
|
||||
itemModel.type = "Upload";
|
||||
itemModel.url = upload.Upload.Url;
|
||||
model.items.Add(itemModel);
|
||||
index++;
|
||||
}
|
||||
if (IsValidItem(type, itemId))
|
||||
else if (item.GetType().BaseType == typeof(PasteVaultItem))
|
||||
{
|
||||
ModifyVaultItemViewModel item = new ModifyVaultItemViewModel();
|
||||
item.isTemplate = false;
|
||||
item.index = index;
|
||||
item.title = title;
|
||||
item.url = itemId;
|
||||
item.type = type;
|
||||
model.items.Add(item);
|
||||
PasteVaultItem paste = (PasteVaultItem)item;
|
||||
itemModel.title = paste.Title;
|
||||
itemModel.description = paste.Description;
|
||||
itemModel.type = "Paste";
|
||||
itemModel.url = paste.Paste.Url;
|
||||
model.items.Add(itemModel);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return View("~/Areas/Vault/Views/Vault/ModifyVault.cshtml", model);
|
||||
// If they passed any new items in via the parameters, let's add them
|
||||
if (!string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(items))
|
||||
{
|
||||
string decodedItems = HttpUtility.UrlDecode(items);
|
||||
string[] allItems = decodedItems.Split(',');
|
||||
foreach (string newItem in allItems)
|
||||
{
|
||||
string[] urlInfo = newItem.Split(':');
|
||||
string itemId = urlInfo[0];
|
||||
string title = string.Empty;
|
||||
if (urlInfo.GetUpperBound(0) >= 1)
|
||||
{
|
||||
// They also passed in the original filename, so let's use it as our title
|
||||
title = urlInfo[1];
|
||||
}
|
||||
if (IsValidItem(type, itemId))
|
||||
{
|
||||
ModifyVaultItemViewModel item = new ModifyVaultItemViewModel();
|
||||
item.isTemplate = false;
|
||||
item.index = index;
|
||||
item.title = title;
|
||||
item.url = itemId;
|
||||
item.type = type;
|
||||
model.items.Add(item);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return View("~/Areas/Vault/Views/Vault/ModifyVault.cshtml", model);
|
||||
}
|
||||
return Redirect(Url.SubRouteUrl("error", "Error.Http403"));
|
||||
}
|
||||
return Redirect(Url.SubRouteUrl("error", "Error.Http403"));
|
||||
return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
|
||||
}
|
||||
return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -238,97 +242,27 @@ namespace Teknik.Areas.Vault.Controllers
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.title))
|
||||
{
|
||||
Vault.Models.Vault newVault = db.Vaults.Create();
|
||||
// Create a new ID
|
||||
string url = StringHelper.RandomString(Config.VaultConfig.UrlLength);
|
||||
while (db.Vaults.Where(v => v.Url == url).FirstOrDefault() != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
url = StringHelper.RandomString(Config.VaultConfig.UrlLength);
|
||||
}
|
||||
newVault.Url = url;
|
||||
newVault.DateCreated = DateTime.Now;
|
||||
newVault.Title = model.title;
|
||||
newVault.Description = model.description;
|
||||
if (User.Identity.IsAuthenticated)
|
||||
{
|
||||
User user = UserHelper.GetUser(db, User.Identity.Name);
|
||||
if (user != null)
|
||||
Vault.Models.Vault newVault = db.Vaults.Create();
|
||||
// Create a new ID
|
||||
string url = StringHelper.RandomString(Config.VaultConfig.UrlLength);
|
||||
while (db.Vaults.Where(v => v.Url == url).FirstOrDefault() != null)
|
||||
{
|
||||
newVault.UserId = user.UserId;
|
||||
url = StringHelper.RandomString(Config.VaultConfig.UrlLength);
|
||||
}
|
||||
}
|
||||
|
||||
// Add/Verify items
|
||||
if (model.items.Any())
|
||||
{
|
||||
foreach (ModifyVaultItemViewModel item in model.items)
|
||||
newVault.Url = url;
|
||||
newVault.DateCreated = DateTime.Now;
|
||||
newVault.Title = model.title;
|
||||
newVault.Description = model.description;
|
||||
if (User.Identity.IsAuthenticated)
|
||||
{
|
||||
if (IsValidItem(item.type, item.url))
|
||||
User user = UserHelper.GetUser(db, User.Identity.Name);
|
||||
if (user != null)
|
||||
{
|
||||
switch (item.type.ToLower())
|
||||
{
|
||||
case "upload":
|
||||
UploadVaultItem newUpload = new UploadVaultItem();
|
||||
newUpload.DateAdded = DateTime.Now;
|
||||
newUpload.Title = item.title;
|
||||
newUpload.Description = item.description;
|
||||
newUpload.UploadId = db.Uploads.Where(u => u.Url == item.url).FirstOrDefault().UploadId;
|
||||
newVault.VaultItems.Add(newUpload);
|
||||
break;
|
||||
case "paste":
|
||||
PasteVaultItem newPaste = new PasteVaultItem();
|
||||
newPaste.DateAdded = DateTime.Now;
|
||||
newPaste.Title = item.title;
|
||||
newPaste.Description = item.description;
|
||||
newPaste.PasteId = db.Pastes.Where(p => p.Url == item.url).FirstOrDefault().PasteId;
|
||||
newVault.VaultItems.Add(newPaste);
|
||||
break;
|
||||
default:
|
||||
return Json(new { error = new { message = "You have an invalid item type: " + item.type } });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new { error = new { message = "You have an invalid item URL: " + item.url } });
|
||||
newVault.UserId = user.UserId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add and save the new vault
|
||||
db.Vaults.Add(newVault);
|
||||
db.SaveChanges();
|
||||
return Json(new { result = new { url = Url.SubRouteUrl("v", "Vault.ViewVault", new { id = url }) } });
|
||||
}
|
||||
return Json(new { error = new { message = "You must supply a Title" } });
|
||||
}
|
||||
return Json(new { error = new { message = "Invalid Parameters" } });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult EditVault(ModifyVaultViewModel model)
|
||||
{
|
||||
if (model != null)
|
||||
{
|
||||
Vault.Models.Vault foundVault = db.Vaults.Where(v => v.VaultId == model.vaultId).FirstOrDefault();
|
||||
if (foundVault != null)
|
||||
{
|
||||
if (foundVault.User.Username == User.Identity.Name)
|
||||
{
|
||||
foundVault.DateEdited = DateTime.Now;
|
||||
foundVault.Title = model.title;
|
||||
foundVault.Description = model.description;
|
||||
|
||||
// Clear previous items
|
||||
List<VaultItem> vaultItems = db.VaultItems.Where(v => v.VaultId == foundVault.VaultId).ToList();
|
||||
if (vaultItems != null)
|
||||
{
|
||||
foreach (VaultItem item in vaultItems)
|
||||
{
|
||||
db.VaultItems.Remove(item);
|
||||
}
|
||||
}
|
||||
foundVault.VaultItems.Clear();
|
||||
|
||||
// Add/Verify items
|
||||
if (model.items.Any())
|
||||
@ -345,7 +279,7 @@ namespace Teknik.Areas.Vault.Controllers
|
||||
newUpload.Title = item.title;
|
||||
newUpload.Description = item.description;
|
||||
newUpload.UploadId = db.Uploads.Where(u => u.Url == item.url).FirstOrDefault().UploadId;
|
||||
foundVault.VaultItems.Add(newUpload);
|
||||
newVault.VaultItems.Add(newUpload);
|
||||
break;
|
||||
case "paste":
|
||||
PasteVaultItem newPaste = new PasteVaultItem();
|
||||
@ -353,7 +287,7 @@ namespace Teknik.Areas.Vault.Controllers
|
||||
newPaste.Title = item.title;
|
||||
newPaste.Description = item.description;
|
||||
newPaste.PasteId = db.Pastes.Where(p => p.Url == item.url).FirstOrDefault().PasteId;
|
||||
foundVault.VaultItems.Add(newPaste);
|
||||
newVault.VaultItems.Add(newPaste);
|
||||
break;
|
||||
default:
|
||||
return Json(new { error = new { message = "You have an invalid item type: " + item.type } });
|
||||
@ -366,14 +300,90 @@ namespace Teknik.Areas.Vault.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
db.Entry(foundVault).State = EntityState.Modified;
|
||||
// Add and save the new vault
|
||||
db.Vaults.Add(newVault);
|
||||
db.SaveChanges();
|
||||
|
||||
return Json(new { result = new { url = Url.SubRouteUrl("v", "Vault.ViewVault", new { id = foundVault.Url }) } });
|
||||
return Json(new { result = new { url = Url.SubRouteUrl("v", "Vault.ViewVault", new { id = url }) } });
|
||||
}
|
||||
return Json(new { error = new { message = "You do not have permission to edit this Vault" } });
|
||||
}
|
||||
return Json(new { error = new { message = "That Vault does not exist" } });
|
||||
return Json(new { error = new { message = "You must supply a Title" } });
|
||||
}
|
||||
return Json(new { error = new { message = "Invalid Parameters" } });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult EditVault(ModifyVaultViewModel model)
|
||||
{
|
||||
if (model != null)
|
||||
{
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
Vault.Models.Vault foundVault = db.Vaults.Where(v => v.VaultId == model.vaultId).FirstOrDefault();
|
||||
if (foundVault != null)
|
||||
{
|
||||
if (foundVault.User.Username == User.Identity.Name)
|
||||
{
|
||||
foundVault.DateEdited = DateTime.Now;
|
||||
foundVault.Title = model.title;
|
||||
foundVault.Description = model.description;
|
||||
|
||||
// Clear previous items
|
||||
List<VaultItem> vaultItems = db.VaultItems.Where(v => v.VaultId == foundVault.VaultId).ToList();
|
||||
if (vaultItems != null)
|
||||
{
|
||||
foreach (VaultItem item in vaultItems)
|
||||
{
|
||||
db.VaultItems.Remove(item);
|
||||
}
|
||||
}
|
||||
foundVault.VaultItems.Clear();
|
||||
|
||||
// Add/Verify items
|
||||
if (model.items.Any())
|
||||
{
|
||||
foreach (ModifyVaultItemViewModel item in model.items)
|
||||
{
|
||||
if (IsValidItem(item.type, item.url))
|
||||
{
|
||||
switch (item.type.ToLower())
|
||||
{
|
||||
case "upload":
|
||||
UploadVaultItem newUpload = new UploadVaultItem();
|
||||
newUpload.DateAdded = DateTime.Now;
|
||||
newUpload.Title = item.title;
|
||||
newUpload.Description = item.description;
|
||||
newUpload.UploadId = db.Uploads.Where(u => u.Url == item.url).FirstOrDefault().UploadId;
|
||||
foundVault.VaultItems.Add(newUpload);
|
||||
break;
|
||||
case "paste":
|
||||
PasteVaultItem newPaste = new PasteVaultItem();
|
||||
newPaste.DateAdded = DateTime.Now;
|
||||
newPaste.Title = item.title;
|
||||
newPaste.Description = item.description;
|
||||
newPaste.PasteId = db.Pastes.Where(p => p.Url == item.url).FirstOrDefault().PasteId;
|
||||
foundVault.VaultItems.Add(newPaste);
|
||||
break;
|
||||
default:
|
||||
return Json(new { error = new { message = "You have an invalid item type: " + item.type } });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new { error = new { message = "You have an invalid item URL: " + item.url } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
db.Entry(foundVault).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
|
||||
return Json(new { result = new { url = Url.SubRouteUrl("v", "Vault.ViewVault", new { id = foundVault.Url }) } });
|
||||
}
|
||||
return Json(new { error = new { message = "You do not have permission to edit this Vault" } });
|
||||
}
|
||||
return Json(new { error = new { message = "That Vault does not exist" } });
|
||||
}
|
||||
}
|
||||
return Json(new { error = new { message = "Invalid Parameters" } });
|
||||
}
|
||||
@ -381,19 +391,22 @@ namespace Teknik.Areas.Vault.Controllers
|
||||
[HttpPost]
|
||||
public ActionResult DeleteVault(string url)
|
||||
{
|
||||
Vault.Models.Vault foundVault = db.Vaults.Where(v => v.Url == url).FirstOrDefault();
|
||||
if (foundVault != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
if (foundVault.User.Username == User.Identity.Name)
|
||||
Vault.Models.Vault foundVault = db.Vaults.Where(v => v.Url == url).FirstOrDefault();
|
||||
if (foundVault != null)
|
||||
{
|
||||
db.Vaults.Remove(foundVault);
|
||||
db.SaveChanges();
|
||||
if (foundVault.User.Username == User.Identity.Name)
|
||||
{
|
||||
db.Vaults.Remove(foundVault);
|
||||
db.SaveChanges();
|
||||
|
||||
return Json(new { result = new { url = Url.SubRouteUrl("vault", "Vault.CreateVault") } });
|
||||
return Json(new { result = new { url = Url.SubRouteUrl("vault", "Vault.CreateVault") } });
|
||||
}
|
||||
return Json(new { error = new { message = "You do not have permission to edit this Vault" } });
|
||||
}
|
||||
return Json(new { error = new { message = "You do not have permission to edit this Vault" } });
|
||||
return Json(new { error = new { message = "That Vault does not exist" } });
|
||||
}
|
||||
return Json(new { error = new { message = "That Vault does not exist" } });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -416,22 +429,25 @@ namespace Teknik.Areas.Vault.Controllers
|
||||
bool valid = false;
|
||||
if (!string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(url))
|
||||
{
|
||||
switch (type.ToLower())
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
case "upload":
|
||||
Upload.Models.Upload foundUpload = db.Uploads.Where(u => u.Url == url).FirstOrDefault();
|
||||
if (foundUpload != null)
|
||||
{
|
||||
valid = true;
|
||||
}
|
||||
break;
|
||||
case "paste":
|
||||
Paste.Models.Paste foundPaste = db.Pastes.Where(p => p.Url == url).FirstOrDefault();
|
||||
if (foundPaste != null)
|
||||
{
|
||||
valid = true;
|
||||
}
|
||||
break;
|
||||
switch (type.ToLower())
|
||||
{
|
||||
case "upload":
|
||||
Upload.Models.Upload foundUpload = db.Uploads.Where(u => u.Url == url).FirstOrDefault();
|
||||
if (foundUpload != null)
|
||||
{
|
||||
valid = true;
|
||||
}
|
||||
break;
|
||||
case "paste":
|
||||
Paste.Models.Paste foundPaste = db.Pastes.Where(p => p.Url == url).FirstOrDefault();
|
||||
if (foundPaste != null)
|
||||
{
|
||||
valid = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
|
@ -7,6 +7,9 @@
|
||||
@Styles.Render("~/Content/vault")
|
||||
|
||||
<script type="text/javascript">
|
||||
var helpURL = '@Url.SubRouteUrl("help", "Help.Markdown")';
|
||||
var validateItemURL = '@Url.SubRouteUrl(Model.CurrentSub, "Vault.Action", new { action = "ValidateItem" })';
|
||||
var modifyVaultURL = '@Url.SubRouteUrl(Model.CurrentSub, "Vault.Action", new { action = "EditVault" })';
|
||||
var deleteVaultURL = '@Url.SubRouteUrl(Model.CurrentSub, "Vault.DeleteVault")';
|
||||
</script>
|
||||
|
||||
|
@ -144,81 +144,98 @@ namespace Teknik
|
||||
|
||||
protected void Application_Error(object sender, EventArgs e)
|
||||
{
|
||||
// Get the last exception
|
||||
Exception exception = Server.GetLastError();
|
||||
|
||||
// Clear the response
|
||||
Response.Clear();
|
||||
|
||||
HttpException httpException = exception as HttpException;
|
||||
|
||||
RouteData routeData = new RouteData();
|
||||
routeData.DataTokens.Add("namespaces", new[] { typeof(ErrorController).Namespace });
|
||||
routeData.DataTokens.Add("area", "Error");
|
||||
routeData.Values.Add("controller", "Error");
|
||||
|
||||
if (httpException == null)
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
routeData.Values.Add("action", "Exception");
|
||||
}
|
||||
else //It's an Http Exception, Let's handle it.
|
||||
{
|
||||
switch (httpException.GetHttpCode())
|
||||
{
|
||||
case 401:
|
||||
// Unauthorized.
|
||||
routeData.Values.Add("action", "Http401");
|
||||
break;
|
||||
case 403:
|
||||
// Forbidden.
|
||||
routeData.Values.Add("action", "Http403");
|
||||
break;
|
||||
case 404:
|
||||
// Page not found.
|
||||
routeData.Values.Add("action", "Http404");
|
||||
break;
|
||||
case 500:
|
||||
// Server error.
|
||||
routeData.Values.Add("action", "Http500");
|
||||
break;
|
||||
// Get the last exception
|
||||
exception = Server.GetLastError();
|
||||
|
||||
// Here you can handle Views to other error codes.
|
||||
// I choose a General error template
|
||||
default:
|
||||
routeData.Values.Add("action", "General");
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Clear the response
|
||||
Response.Clear();
|
||||
|
||||
// Pass exception details to the target error View.
|
||||
routeData.Values.Add("exception", exception);
|
||||
HttpException httpException = exception as HttpException;
|
||||
|
||||
// Clear the error on server.
|
||||
Server.ClearError();
|
||||
RouteData routeData = new RouteData();
|
||||
routeData.DataTokens.Add("namespaces", new[] { typeof(ErrorController).Namespace });
|
||||
routeData.DataTokens.Add("area", "Error");
|
||||
routeData.Values.Add("controller", "Error");
|
||||
|
||||
// Avoid IIS7 getting in the middle
|
||||
Response.TrySkipIisCustomErrors = true;
|
||||
|
||||
// If it is an Ajax request, we should respond with Json data, otherwise redirect
|
||||
if (new HttpRequestWrapper(Request).IsAjaxRequest())
|
||||
{
|
||||
string jsonResult = string.Empty;
|
||||
if (httpException == null)
|
||||
{
|
||||
jsonResult = Json.Encode(new { error = new { type = "Exception", message = exception.GetFullMessage(true) } });
|
||||
routeData.Values.Add("action", "Exception");
|
||||
}
|
||||
else //It's an Http Exception, Let's handle it.
|
||||
{
|
||||
switch (httpException.GetHttpCode())
|
||||
{
|
||||
case 401:
|
||||
// Unauthorized.
|
||||
routeData.Values.Add("action", "Http401");
|
||||
break;
|
||||
case 403:
|
||||
// Forbidden.
|
||||
routeData.Values.Add("action", "Http403");
|
||||
break;
|
||||
case 404:
|
||||
// Page not found.
|
||||
routeData.Values.Add("action", "Http404");
|
||||
break;
|
||||
case 500:
|
||||
// Server error.
|
||||
routeData.Values.Add("action", "Http500");
|
||||
break;
|
||||
|
||||
// Here you can handle Views to other error codes.
|
||||
// I choose a General error template
|
||||
default:
|
||||
routeData.Values.Add("action", "General");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Pass exception details to the target error View.
|
||||
routeData.Values.Add("exception", exception);
|
||||
|
||||
// Clear the error on server.
|
||||
Server.ClearError();
|
||||
|
||||
// Avoid IIS7 getting in the middle
|
||||
Response.TrySkipIisCustomErrors = true;
|
||||
|
||||
// If it is an Ajax request, we should respond with Json data, otherwise redirect
|
||||
if (new HttpRequestWrapper(Request).IsAjaxRequest())
|
||||
{
|
||||
string jsonResult = string.Empty;
|
||||
if (httpException == null)
|
||||
{
|
||||
jsonResult = Json.Encode(new { error = new { type = "Exception", message = exception.GetFullMessage(true) } });
|
||||
}
|
||||
else
|
||||
{
|
||||
jsonResult = Json.Encode(new { error = new { type = "Http", statuscode = httpException.GetHttpCode(), message = exception.GetFullMessage(true) } });
|
||||
}
|
||||
Response.Write(jsonResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
jsonResult = Json.Encode(new { error = new { type = "Http", statuscode = httpException.GetHttpCode(), message = exception.GetFullMessage(true) } });
|
||||
// Call target Controller and pass the routeData.
|
||||
IController errorController = new ErrorController();
|
||||
errorController.Execute(new RequestContext(
|
||||
new HttpContextWrapper(Context), routeData));
|
||||
}
|
||||
Response.Write(jsonResult);
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Call target Controller and pass the routeData.
|
||||
IController errorController = new ErrorController();
|
||||
errorController.Execute(new RequestContext(
|
||||
new HttpContextWrapper(Context), routeData));
|
||||
// Unable to display error, so try to log it
|
||||
try
|
||||
{
|
||||
Logging.Logger.WriteEntry(Logging.LogLevel.Warning, "Error in Application_Error", ex);
|
||||
if (exception != null)
|
||||
{
|
||||
Logging.Logger.WriteEntry(Logging.LogLevel.Error, "Exception Thrown", exception);
|
||||
}
|
||||
}
|
||||
catch(Exception) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,16 +68,18 @@ namespace Teknik.Hubs
|
||||
// If the password is supplied, verify the password
|
||||
if (!string.IsNullOrEmpty(password))
|
||||
{
|
||||
TeknikEntities db = new TeknikEntities();
|
||||
User user = UserHelper.GetUser(db, username);
|
||||
if (user != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
Config config = Config.Load();
|
||||
success = UserHelper.UserPasswordCorrect(db, config, user, password);
|
||||
}
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
User user = UserHelper.GetUser(db, username);
|
||||
if (user != null)
|
||||
{
|
||||
Config config = Config.Load();
|
||||
success = UserHelper.UserPasswordCorrect(db, config, user, password);
|
||||
}
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,6 +234,18 @@ function getReadableBandwidthString(bandwidth) {
|
||||
return Math.max(bandwidth, 0.1).toFixed(1) + byteUnits[i];
|
||||
}
|
||||
|
||||
function getReadableFileSizeString(fileSizeInBytes) {
|
||||
|
||||
var i = -1;
|
||||
var byteUnits = [' KB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
do {
|
||||
fileSizeInBytes = fileSizeInBytes / 1024;
|
||||
i++;
|
||||
} while (fileSizeInBytes > 1024);
|
||||
|
||||
return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i];
|
||||
};
|
||||
|
||||
function moveUp(item) {
|
||||
var prev = item.prev();
|
||||
if (prev.length == 0)
|
||||
|
@ -11,8 +11,6 @@ namespace Teknik.Security
|
||||
{
|
||||
public class TeknikPrincipal : ITeknikPrincipal
|
||||
{
|
||||
TeknikEntities entities = new TeknikEntities();
|
||||
|
||||
private IIdentity _Identity;
|
||||
public IIdentity Identity
|
||||
{
|
||||
@ -29,7 +27,8 @@ namespace Teknik.Security
|
||||
{
|
||||
if (m_Info == null && Identity != null && Identity.IsAuthenticated)
|
||||
{
|
||||
m_Info = UserHelper.GetUser(entities, Identity.Name);
|
||||
TeknikEntities db = new TeknikEntities();
|
||||
m_Info = UserHelper.GetUser(db, Identity.Name);
|
||||
}
|
||||
return m_Info;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@
|
||||
<forms domain=".teknik.io" protection="All" enableCrossAppRedirects="true" name="TeknikAuth" />
|
||||
</authentication>
|
||||
<compilation debug="true" targetFramework="4.6.2" />
|
||||
<httpRuntime targetFramework="4.6.2" maxRequestLength="1048576" executionTimeout="3600" relaxedUrlToFileSystemMapping="true" />
|
||||
<httpRuntime targetFramework="4.6.2" maxRequestLength="5242880" executionTimeout="3600" relaxedUrlToFileSystemMapping="true" />
|
||||
<pages buffer="true" enableViewState="false" />
|
||||
</system.web>
|
||||
<system.webServer>
|
||||
@ -123,7 +123,7 @@
|
||||
<customHeaders>
|
||||
<add name="Access-Control-Allow-Credentials" value="true" />
|
||||
<add name="Access-Control-Allow-Methods" value="GET, PUT, POST, DELETE, OPTIONS" />
|
||||
<add name="Access-Control-Allow-Headers" value="Authorization, Accept, Origin, Content-Type, X-Requested-With" />
|
||||
<add name="Access-Control-Allow-Headers" value="Authorization, Accept, Origin, Content-Type, X-Requested-With, Connection, Transfer-Encoding" />
|
||||
<add name="strict-transport-security" value="max-age=31536000; includeSubdomains" />
|
||||
</customHeaders>
|
||||
</httpProtocol>
|
||||
|
@ -39,15 +39,16 @@ namespace TeknikStreaming
|
||||
|
||||
private void LoadStreams()
|
||||
{
|
||||
TeknikEntities db = new TeknikEntities();
|
||||
|
||||
List<User> users = db.Users.ToList();
|
||||
if (users != null)
|
||||
using (TeknikEntities db = new TeknikEntities())
|
||||
{
|
||||
foreach (User user in users)
|
||||
List<User> users = db.Users.ToList();
|
||||
if (users != null)
|
||||
{
|
||||
RtspSource source = new RtspSource(string.Format("TeknikLiveStream_{0}", user.Username), string.Format("rtsp://localhost/live/{0}/stream.amp", user.Username));
|
||||
foreach (User user in users)
|
||||
{
|
||||
RtspSource source = new RtspSource(string.Format("TeknikLiveStream_{0}", user.Username), string.Format("rtsp://localhost/live/{0}/stream.amp", user.Username));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ namespace Teknik.Utilities
|
||||
protected override void WriteFile(System.Web.HttpResponseBase response)
|
||||
{
|
||||
response.Buffer = bufferOutput;
|
||||
response.BufferOutput = bufferOutput;
|
||||
responseDelegate(response);
|
||||
}
|
||||
}
|
||||
|
@ -49,26 +49,18 @@ namespace Teknik.Utilities
|
||||
}
|
||||
while (processedBytes > 0 && bytesRemaining > 0);
|
||||
}
|
||||
catch (HttpException httpEx)
|
||||
{
|
||||
// If we lost connection, that's fine
|
||||
if (httpEx.ErrorCode == -2147023667)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
//throw httpEx;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Don't bother
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// dispose of file stream
|
||||
stream.Dispose();
|
||||
if (stream != null)
|
||||
{
|
||||
stream.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user