//GET: Handles uploading file action public ActionResult Analyze(string filename) { //Flag unavailable file ViewBag.ReadyToAnalyze = false; try { var path = Path.Combine(Server.MapPath("~/App_Data/UploadedLogFiles"), filename); //Parse Uploaded file data ViewBag.UploadedFilePath = path; ViewBag.ReadyToAnalyze = true; var ParsedData = new GraphController().Parse(ViewBag.UploadedFilePath); ViewBag.FiletypesGraphData = ParsedData.Data.FiletypesGraphData; //ViewBag.ResponsesGraphData = ParsedData.Data.ResponsesGraphData; ViewBag.DailyTransfersGraphData = ParsedData.Data.DailyTransfersGraphData; ViewBag.SuccessResponsesPerDay = ParsedData.Data.SuccessResponsesPerDay; } catch (Exception ex) { //Return special case exception ViewBag.Message = "ERROR:" + ex.Message.ToString(); } return(View("Index")); }
public ActionResult Index(HttpPostedFileBase file) { //Flag unavailable file ViewBag.ReadyToAnalyze = false; //Validate Uploaded File if (file != null && file.ContentLength > 0) { try { //Get filename var fileName = Path.GetFileName(file.FileName); //Store tmpFile for extra checks var tmpPath = Path.Combine(Server.MapPath("~/App_Data/tmp"), "tmp" + fileName + DateTime.Now.ToString("yyyyMMddHHmmssfff")); file.SaveAs(tmpPath); //Detect malicious file if (DetectExecutable(tmpPath)) { ViewBag.Message = "MALICIOUS FILE"; System.IO.File.Delete(tmpPath); return(View("Index")); } else { //Validate file contains logs if (ValidateLog(tmpPath)) { System.IO.File.Delete(tmpPath); //Store File with unique name var path = Path.Combine(Server.MapPath("~/App_Data/UploadedLogFiles"), DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + fileName); file.SaveAs(path); ViewBag.Message = "File uploaded successfully"; ViewBag.UploadedFilePath = path; ViewBag.ReadyToAnalyze = true; //Parse Uploaded file data var ParsedData = new GraphController().Parse(ViewBag.UploadedFilePath); ViewBag.FiletypesGraphData = ParsedData.Data.FiletypesGraphData; //ViewBag.ResponsesGraphData = ParsedData.Data.ResponsesGraphData; ViewBag.DailyTransfersGraphData = ParsedData.Data.DailyTransfersGraphData; ViewBag.SuccessResponsesPerDay = ParsedData.Data.SuccessResponsesPerDay; } else { ViewBag.Message = "Invalid Log file"; System.IO.File.Delete(tmpPath); return(View("Index")); } } } catch (Exception ex) { //Return special case exception ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } else { ViewBag.Message = "You have not specified a file."; } return(View("Index")); }