示例#1
0
        /*==============================================================================
        * ActionResult Upload(int groupId)
        * Upload
        *
        * Default action, makes list of available plugins. User has access to all group plugins
        * ==============================================================================*/
        public ActionResult Upload(int groupId)
        {
            Entities db = new Entities();
            UserProfile user = db.UserProfiles.Single(u => u.UserId == WebSecurity.CurrentUserId);
            Group query = user.GroupsIn.Single(g => g.GroupId == groupId);

            //Creates a list of plugins available to the user, from the plugin databse
            ScanUploadModel model = new ScanUploadModel()
            {
                PluginList = query.Plugins.Union(db.Plugins.Where(p => p.OwnerID == 1)),
                GroupId = groupId
            };

            return View(model);
        }
示例#2
0
        public ActionResult Upload(ScanUploadModel model)
        {
            if (ModelState.IsValid)
            {

                Entities db = new Entities();
                UserProfile user = db.UserProfiles.Single(u => u.UserId == WebSecurity.CurrentUserId);
                Group group = user.GroupsIn.Single(g => g.GroupId == model.GroupId);
                Plugin plugin = db.Plugins.Single(p => p.PluginID == model.selectedPluginId);

                string newId = Guid.NewGuid().ToString();
                string path = Server.MapPath("~/Groups/" + model.GroupId + "/Scans/" + newId);
                model.file.SaveAs(path);

                //TODO: Check validity of scan against DTD
                //Currently assuming that the scan is valid.
                //if (ParseScan(path, model))
                {
                    if (model.strParseError != "" || model.strParseError != null)
                    {
                        group.Scans.Add(new Scan()
                        {
                            OriginalFilename = model.file.FileName,
                            GeneratedFilename = newId,
                            ProcessorType = plugin.PluginID,
                            IsProcessed = false,
                            DateUploaded = DateTime.Now
                        });

                        db.SaveChanges();

                        return RedirectToAction("Index");
                    }
                }
            }

            return View(model);
        }
示例#3
0
        public bool ParseScan(string path, ScanUploadModel model)
        {
            string strValidationError = "";

            //Validate File path, assume valid DTD
            if (HasFile(model.file))
            {
                //Call ReportValidate(Filepath, DTD?)
                //Needs to save report in order to verify, if report is valid, keep on file server. Delete if invalid
                Entities db = new Entities();
                UserProfile user = db.UserProfiles.Single(u => u.UserId == WebSecurity.CurrentUserId);
                Group group = user.GroupsIn.Single(g => g.GroupId == model.GroupId);

                strValidationError = ScanVerifier(path);

                //Print out error results
                model.strParseError = strValidationError;

                return true;
            }
            else
                return false;
        }